mirror of
https://github.com/paradizelost/screeps.git
synced 2024-11-25 02:14:44 -06:00
19 lines
1.2 KiB
JavaScript
19 lines
1.2 KiB
JavaScript
var runSources = {
|
|
tick: function(roomname) {
|
|
var sources = Game.rooms[roomname].find(FIND_DROPPED_ENERGY );
|
|
for(var source of sources){
|
|
var allhaulers = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => creep.memory.role=='hauler' );
|
|
var unassignedhaulers = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => (creep.memory.destsource == undefined && creep.memory.role=='hauler'));
|
|
var assignedhaulers = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => (creep.memory.destsource != undefined && creep.memory.role=='hauler'));
|
|
var myhaulers = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => (creep.memory.destsource != undefined && creep.memory.destsource.id==source.id && creep.memory.role=='hauler'));
|
|
var sourcecount = sources.length
|
|
var persrc = allhaulers.length / sourcecount
|
|
if(myhaulers.length >=persrc){break;} else{
|
|
if(unassignedhaulers.length > 0){
|
|
unassignedhaulers[0].memory.destsource = source
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
module.exports = runSources; |