2016-09-28 08:37:28 -05:00
'use strict' ;
2017-06-06 13:17:26 -05:00
global . Empire = require ( "Empire" )
2017-07-13 23:24:42 -05:00
//let runTower = require('tower');
//let assignMiners=require('sproc')
//let processSpawns=require('spawnprocessing')
//let minerals=require('mineralprocessing')
//let minedproc = require('MinedMineralProc')
//let runSources=require('sourceprocessing')
global . verbosity = 0
2016-09-15 00:30:24 -05:00
module . exports . loop = function ( ) {
2017-07-13 23:24:42 -05:00
if ( global . verbosity > 0 ) {
console . log ( '---START---' )
}
2016-09-28 08:37:28 -05:00
for ( let name in Memory . creeps ) {
2016-09-15 00:30:24 -05:00
if ( ! Game . creeps [ name ] ) {
delete Memory . creeps [ name ] ;
2017-07-13 23:24:42 -05:00
if ( global . verbosity > 0 ) {
2016-09-15 00:30:24 -05:00
console . log ( 'Clearing non-existing creep memory:' , name ) ;
2017-07-13 23:24:42 -05:00
}
2016-09-15 00:30:24 -05:00
}
}
2016-09-28 08:37:28 -05:00
for ( let myroom of _ . filter ( Game . rooms , 'controller.my' ) ) {
let name = myroom . name
2017-07-13 23:24:42 -05:00
if ( global . verbosity > 0 ) {
2016-09-28 08:37:28 -05:00
console . log ( '---' + name + '---' )
2017-07-13 23:24:42 -05:00
}
if ( Game . rooms [ name ] . memory . hasbeeninited == undefined ) {
console . log ( 'initing' )
require ( 'initroom' ) . run ( name )
}
require ( 'tower' ) . tick ( name ) ;
require ( 'sproc' ) . tick ( name ) // assignMiners
require ( 'sourceprocessing' ) . tick ( name )
require ( 'MinedMineralProc' ) . tick ( name )
2016-09-28 08:37:28 -05:00
try {
let roomenergy = Game . rooms [ name ] . energyAvailable
let allstorage = Game . rooms [ name ] . find ( FIND _STRUCTURES , { filter : ( s ) => { return ( s . structureType == STRUCTURE _CONTAINER || s . structureType == STRUCTURE _STORAGE ) } } )
let usedstorage = 0
let mycapacity = 0
2017-06-06 13:17:26 -05:00
for ( let i of allstorage ) {
usedstorage += _ . sum ( i . store )
mycapacity += i . storeCapacity
2016-09-15 00:30:24 -05:00
}
2016-09-28 08:37:28 -05:00
let allcontainers = Game . rooms [ name ] . find ( FIND _STRUCTURES , { filter : ( s ) => { return ( s . structureType == STRUCTURE _CONTAINER ) } } )
let containerusedstorage = 0
let containercapacity = 0
for ( let i = 0 ; i < allcontainers . length ; i ++ ) {
2016-09-23 00:12:42 -05:00
containerusedstorage += _ . sum ( allcontainers [ i ] . store )
containercapacity += allcontainers [ i ] . storeCapacity
2016-09-15 00:30:24 -05:00
}
2016-09-28 08:37:28 -05:00
Game . rooms [ name ] . memory . storagepercent = usedstorage / mycapacity
2016-09-23 00:12:42 -05:00
Game . rooms [ name ] . memory . containerstoragepercent = containerusedstorage / containercapacity
2017-06-06 13:17:26 -05:00
if ( ! ( Game . rooms [ name ] . memory . containerstoragepercent > - . 1 ) ) { Game . rooms [ name ] . memory . containerstoragepercent = 0 }
2017-07-13 23:24:42 -05:00
if ( global . verbosity > 0 ) {
2016-09-23 00:12:42 -05:00
console . log ( '-------' )
console . log ( 'Room "' + name + '" has ' + roomenergy + ' energy : Using ' + usedstorage + ' of ' + mycapacity + ', ' + Game . rooms [ name ] . memory . storagepercent * 100 + '% Storage, ' + containerusedstorage + ' of ' + containercapacity + ':' + Game . rooms [ name ] . memory . containerstoragepercent * 100 + '% in containers' )
2017-07-13 23:24:42 -05:00
}
2016-09-28 08:37:28 -05:00
} catch ( e ) { }
2017-07-13 23:24:42 -05:00
require ( 'spawnprocessing' ) . tick ( name )
require ( 'mineralprocessing' ) . tick ( name )
2017-06-06 13:17:26 -05:00
}
let mycreeps = Game . creeps
2016-09-28 08:37:28 -05:00
for ( let mycreep in mycreeps ) {
2016-09-23 00:12:42 -05:00
try {
2016-09-28 08:37:28 -05:00
let creep = mycreeps [ mycreep ]
2017-07-13 23:24:42 -05:00
require ( 'role.' + creep . memory . role ) . run ( creep )
2016-09-23 00:12:42 -05:00
} catch ( e ) {
//console.log(e.toString)
}
2016-09-28 08:37:28 -05:00
2016-09-15 01:02:53 -05:00
}
2017-07-13 23:24:42 -05:00
if ( global . verbosity > 0 ) {
console . log ( '----END---' )
}
2016-09-15 00:30:24 -05:00
}