screeps/sourceprocessing.js

22 lines
1.4 KiB
JavaScript
Raw Normal View History

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;