screeps/role.miner2.js
2016-09-15 00:30:24 -05:00

22 lines
769 B
JavaScript

var roleMiner2 = {
/** @param {Creep} creep **/
run: function(creep) {
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[1]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[1]);
}
},
spawn: function(){
var myrole='miner2';
var nummyrole=1;
var myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole);
if(myroles.length < nummyrole) {
console.log('Miners: ' + myroles.length + ' Needed: ' + nummyrole);
var newName = Game.spawns['Spawn1'].createCreep([WORK,WORK,WORK,WORK,WORK,MOVE], undefined, {role: myrole});
console.log('Spawning new ' + myrole + ': ' + newName);
}
}
};
module.exports = roleMiner2;