2016-09-28 08:37:28 -05:00
'use strict' ;
let roleBuilder = require ( 'role.builder' ) ;
let roleMiner = require ( 'role.miner' ) ;
let roleHauler = require ( 'role.hauler' )
let roleHauler2 = require ( 'role.hauler2' )
let roleUpgrader = require ( 'role.upgrader' )
let roleTowerrecharger = require ( 'role.recharger' )
let runSources = require ( 'sourceprocessing' )
let roleRepairbot = require ( 'role.repairbot' )
let runTower = require ( 'tower' ) ;
let assignMiners = require ( 'sproc' )
let buildparts = require ( 'bodypartbuilder' )
2016-09-15 00:30:24 -05:00
module . exports . loop = function ( ) {
2016-09-28 08:37:28 -05:00
console . log ( '---START---' )
for ( let name in Memory . creeps ) {
2016-09-15 00:30:24 -05:00
if ( ! Game . creeps [ name ] ) {
delete Memory . creeps [ name ] ;
console . log ( 'Clearing non-existing creep memory:' , name ) ;
}
}
2016-09-28 08:37:28 -05:00
for ( let myroom of _ . filter ( Game . rooms , 'controller.my' ) ) {
let name = myroom . name
console . log ( name )
buildparts . tick ( name , 'builder' )
console . log ( '---' + name + '---' )
2016-09-23 00:12:42 -05:00
runTower . tick ( name ) ;
2016-09-28 08:37:28 -05:00
assignMiners . tick ( name )
runSources . tick ( name )
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
for ( let i = 0 ; i < allstorage . length ; i ++ ) {
2016-09-23 00:12:42 -05:00
usedstorage += _ . sum ( allstorage [ i ] . store )
mycapacity += allstorage [ i ] . storeCapacity
2016-09-15 00:30:24 -05:00
}
2016-09-23 00:12:42 -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
/ * *
var allstoragecontainers = Game . rooms [ name ] . find ( FIND _STRUCTURES , { filter : ( s ) => { return ( s . structureType == STRUCTURE _STORAGE ) } } )
var storagecontainerusedstorage = 0
var storagecontainercapacity = 0
for ( var i = 0 ; i < allcontainers . length ; i ++ ) {
storagecontainerusedstorage += _ . sum ( allstoragecontainers [ i ] . store )
storagecontainercapacity += allstoragecontainers [ i ] . storeCapacity
}
if ( )
console . log ( storagecontainerusedstorage + ':' + storagecontainercapacity )
* * /
Game . rooms [ name ] . memory . storagepercent = usedstorage / mycapacity
2016-09-23 00:12:42 -05:00
Game . rooms [ name ] . memory . containerstoragepercent = containerusedstorage / containercapacity
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' )
2016-09-28 08:37:28 -05:00
} catch ( e ) { }
2016-09-23 00:12:42 -05:00
if ( Game . rooms [ name ] . memory . maxbuilders == undefined ) { Game . rooms [ name ] . memory . maxbuilders = 0 }
if ( Game . rooms [ name ] . memory . maxupgraders == undefined ) { Game . rooms [ name ] . memory . maxupgraders = 0 }
if ( Game . rooms [ name ] . memory . maxminers == undefined ) { Game . rooms [ name ] . memory . maxminers = 0 }
if ( Game . rooms [ name ] . memory . maxhaulers == undefined ) { Game . rooms [ name ] . memory . maxhaulers = 0 }
if ( Game . rooms [ name ] . memory . maxhauler2s == undefined ) { Game . rooms [ name ] . memory . maxhauler2s = 0 }
if ( Game . rooms [ name ] . memory . maxwarriors == undefined ) { Game . rooms [ name ] . memory . maxwarriors = 0 }
if ( Game . rooms [ name ] . memory . maxtowerrechargers == undefined ) { Game . rooms [ name ] . memory . maxtowerrechargers = 0 }
if ( Game . rooms [ name ] . memory . maxharvesters == undefined ) { Game . rooms [ name ] . memory . maxharvesters = 0 }
if ( Game . rooms [ name ] . memory . maxharvester2s == undefined ) { Game . rooms [ name ] . memory . maxharvester2s = 0 }
if ( Game . rooms [ name ] . memory . maxrepairbots == undefined ) { Game . rooms [ name ] . memory . maxrepairbots = 0 }
if ( Game . rooms [ name ] . memory . minworkenergypct == undefined ) { Game . rooms [ name ] . memory . minworkenergypct = 0.3 }
if ( Game . rooms [ name ] . memory . builderparkx == undefined ) { Game . rooms [ name ] . memory . builderparkx = 24 }
if ( Game . rooms [ name ] . memory . builderparky == undefined ) { Game . rooms [ name ] . memory . builderparky = 24 }
if ( Game . rooms [ name ] . memory . hauler2parkx == undefined ) { Game . rooms [ name ] . memory . hauler2parkx = 24 }
if ( Game . rooms [ name ] . memory . hauler2parky == undefined ) { Game . rooms [ name ] . memory . hauler2parky = 24 }
if ( Game . rooms [ name ] . memory . upgraderparkx == undefined ) { Game . rooms [ name ] . memory . upgraderparkx = 24 }
if ( Game . rooms [ name ] . memory . upgraderparky == undefined ) { Game . rooms [ name ] . memory . upgraderparky = 24 }
2016-09-28 08:37:28 -05:00
2016-09-23 00:12:42 -05:00
roleBuilder . spawn ( name )
roleMiner . spawn ( name )
roleHauler . spawn ( name )
roleHauler2 . spawn ( name )
roleUpgrader . spawn ( name )
roleTowerrecharger . spawn ( name )
roleRepairbot . spawn ( name )
2016-09-28 08:37:28 -05:00
let mycreeps = Game . rooms [ name ] . find ( FIND _MY _CREEPS )
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 ]
2016-09-23 00:12:42 -05:00
if ( creep . memory . role == 'miner' ) {
roleMiner . run ( creep )
}
if ( creep . memory . role == 'hauler' ) {
roleHauler . run ( creep )
}
if ( creep . memory . role == 'hauler2' ) {
roleHauler2 . run ( creep )
}
if ( creep . memory . role == 'builder' ) {
roleBuilder . run ( creep )
}
if ( creep . memory . role == 'upgrader' ) {
roleUpgrader . run ( creep )
}
if ( creep . memory . role == 'towerrecharger' ) {
roleTowerrecharger . run ( creep )
}
if ( creep . memory . role == 'repairbot' ) {
roleRepairbot . run ( creep )
}
} catch ( e ) {
//console.log(e.toString)
}
2016-09-28 08:37:28 -05:00
2016-09-15 01:02:53 -05:00
}
2016-09-28 08:37:28 -05:00
2016-09-15 00:30:24 -05:00
}
2016-09-28 08:37:28 -05:00
console . log ( '----END---' )
2016-09-15 00:30:24 -05:00
}