screeps/role.miner.js
2016-09-23 00:12:42 -05:00

23 lines
1.0 KiB
JavaScript

var roleMiner = {
run: function(creep) {
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[0]);
}
},
spawn: function(roomname){
var myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
var myroom = Game.rooms[roomname]
for(var thisspawn in myspawns){
var spawn = myspawns[thisspawn]
var myrole='miner';
var myroles = _.filter(Game.rooms[roomname].find(FIND_MY_CREEPS), (creep) => creep.memory.role == myrole);
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
var newName = spawn.createCreep([WORK,WORK,WORK,WORK,WORK,MOVE], undefined, {role: myrole});
console.log('Spawning new ' + myrole + ': ' + newName);
}
}
}
};
module.exports = roleMiner;