2020-11-09 19:31:39 -06:00
|
|
|
let assignMiners = {
|
|
|
|
tick: function(roomname) {
|
2022-05-16 13:26:51 -05:00
|
|
|
let sources = Game.rooms[roomname].find(FIND_SOURCES);
|
2020-11-09 19:31:39 -06:00
|
|
|
for(let source of sources){
|
2020-11-14 02:42:45 -06:00
|
|
|
let allminers = Game.rooms[roomname].find(FIND_MY_CREEPS, {filter: (creep) =>{return ( creep.memory.role=='sourceminer'|| creep.memory.role == ("phase" + Game.rooms[roomname].memory.phase + "worker") )}});
|
2020-11-09 19:31:39 -06:00
|
|
|
//let allstorage = Game.rooms[name].find(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_STORAGE)}})
|
|
|
|
let unassignedminers = _.filter(allminers, (creep) => (creep.memory.destsource == undefined ));
|
|
|
|
let sourcecount = sources.length
|
|
|
|
let persrc = allminers.length / sourcecount
|
|
|
|
if(unassignedminers.length > 0){
|
|
|
|
let myminers = _.filter(allminers, (creep) => (creep.memory.destsource != undefined && creep.memory.destsource.id==source.id ));
|
|
|
|
if(myminers.length >= persrc){
|
|
|
|
//break;
|
|
|
|
} else {
|
|
|
|
unassignedminers[0].memory.destsource = source
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
module.exports = assignMiners;
|