2016-09-28 08:37:28 -05:00
let assignMiners = {
tick : function ( roomname ) {
let sources = Game . rooms [ roomname ] . find ( FIND _SOURCES ) ;
2017-06-06 13:17:26 -05:00
for ( let source of sources ) {
2016-09-28 08:37:28 -05:00
let allminers = _ . filter ( Game . rooms [ roomname ] . find ( FIND _MY _CREEPS ) , ( creep ) => creep . memory . role == 'miner' ) ;
let unassignedminers = _ . filter ( allminers , ( creep ) => ( creep . memory . destsource == undefined && creep . memory . role == 'miner' ) ) ;
let assignedminers = _ . filter ( allminers , ( creep ) => ( creep . memory . destsource != undefined && creep . memory . role == 'miner' ) ) ;
let myminers = _ . filter ( allminers , ( creep ) => ( creep . memory . destsource != undefined && creep . memory . destsource . id == source . id && creep . memory . role == 'miner' ) ) ;
let sourcecount = sources . length
let persrc = allminers . length / sourcecount
console . log ( 'My Assigned Miners: ' + myminers . length + ' Max per source:' + persrc + ' Total Miners:' + allminers . length + ' Total Sources:' + sourcecount + ' Unassigned Miners:' + unassignedminers . length )
if ( unassignedminers . length > 0 ) {
if ( myminers . length >= persrc ) {
//break;
} else {
unassignedminers [ 0 ] . memory . destsource = source
}
}
}
}
} ;
module . exports = assignMiners ;