mirror of
https://github.com/paradizelost/screeps.git
synced 2024-11-25 02:14:44 -06:00
25 lines
1.5 KiB
JavaScript
25 lines
1.5 KiB
JavaScript
let runSources = {
|
|
tick: function(roomname) {
|
|
let sources = Game.rooms[roomname].find(
|
|
FIND_DROPPED_RESOURCES, {
|
|
filter: (mineral) => mineral.resourceType === RESOURCE_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)
|
|
if(unassignedhaulers.length > 0){
|
|
if(myhaulers.length < persrc){
|
|
unassignedhaulers[0].memory.destsource = source
|
|
} else {}
|
|
}
|
|
} catch(e){}
|
|
}
|
|
}
|
|
};
|
|
module.exports = runSources; |