2016-09-28 08:37:28 -05:00
let runSources = {
2016-09-23 00:12:42 -05:00
tick : function ( roomname ) {
2016-09-28 08:37:28 -05:00
let sources = Game . rooms [ roomname ] . find ( FIND _DROPPED _ENERGY ) ;
for ( let source of sources ) {
try {
let allhaulers = _ . filter ( Game . rooms [ roomname ] . find ( FIND _MY _CREEPS ) , ( creep ) => creep . memory . role == 'hauler' ) ;
let unassignedhaulers = _ . filter ( allhaulers , ( creep ) => ( creep . memory . destsource == undefined && creep . memory . role == 'hauler' ) ) ;
let assignedhaulers = _ . filter ( allhaulers , ( creep ) => ( creep . memory . destsource != undefined && creep . memory . role == 'hauler' ) ) ;
let myhaulers = _ . filter ( allhaulers , ( creep ) => ( creep . memory . destsource != undefined && creep . memory . destsource . id == source . id && creep . memory . role == 'hauler' ) ) ;
let sourcecount = sources . length
let persrc = allhaulers . length / sourcecount
console . log ( 'My Assigned Haulers: ' + myhaulers . length + ' Max per source:' + persrc + ' Total Haulers:' + allhaulers . length + ' Total Sources:' + sourcecount + ' Unassigned Haulers:' + unassignedhaulers . length )
2016-09-23 00:12:42 -05:00
if ( unassignedhaulers . length > 0 ) {
2016-09-28 08:37:28 -05:00
if ( myhaulers . length < persrc ) {
unassignedhaulers [ 0 ] . memory . destsource = source
} else { }
2016-09-23 00:12:42 -05:00
}
2016-09-28 08:37:28 -05:00
} catch ( e ) { }
2016-09-23 00:12:42 -05:00
}
}
} ;
module . exports = runSources ;