screeps/role.upgrader.js

57 lines
2.6 KiB
JavaScript
Raw Normal View History

2016-09-28 08:37:28 -05:00
let roleUpgrader = {
2016-09-23 00:12:42 -05:00
run: function(creep) {
2016-09-28 08:37:28 -05:00
if(creep.memory.originroom === undefined){
creep.memory.originroom = creep.room.name
}
2016-09-23 00:12:42 -05:00
if(creep.memory.upgrading==undefined){creep.memory.upgrading=true}
if(creep.memory.upgrading && creep.carry.energy == 0) {
2016-09-15 00:30:24 -05:00
creep.memory.upgrading = false;
creep.say('harvesting');
}
if(!creep.memory.upgrading && creep.carry.energy == creep.carryCapacity) {
creep.memory.upgrading = true;
creep.say('upgrading');
}
if(creep.memory.upgrading) {
2016-09-23 00:12:42 -05:00
if(creep.room.memory.containerstoragepercent>.6){
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.say('MTRC')
creep.moveTo(creep.room.controller);
}
2016-09-23 00:12:42 -05:00
} else { creep.moveTo(creep.room.memory.upgraderparkx,creep.room.memory.upgraderparky,creep.room.roomName) }
} else {
2016-09-28 08:37:28 -05:00
let container = creep.pos.findClosestByRange(FIND_STRUCTURES, {
2016-09-23 00:12:42 -05:00
filter: (structure) => {
return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ;
}});
if(container){
if(creep.withdraw(container,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.say("MTSC");
creep.moveTo(container);
}
}else{
2016-09-28 08:37:28 -05:00
let droppedenergy = creep.room.find(FIND_DROPPED_ENERGY );
2016-09-15 00:30:24 -05:00
if(creep.pickup(droppedenergy[0]) == ERR_NOT_IN_RANGE) {
2016-09-23 00:12:42 -05:00
creep.say("MTDE");
creep.moveTo(droppedenergy[0]);
}
2016-09-15 00:30:24 -05:00
}
}
2016-09-23 00:12:42 -05:00
},
spawn: function(roomname){
2016-09-28 08:37:28 -05:00
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
let myroom = Game.rooms[roomname]
for(let spawn of myspawns){
let myrole='upgrader';
let myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole && creep.memory.originroom == roomname);
2016-09-23 00:12:42 -05:00
console.log(myrole + 's: ' + myroles.length + ' Needed: ' + Game.rooms[roomname].memory['max'+myrole+'s']);
if(myroles.length < Game.rooms[roomname].memory['max'+myrole+'s']) {
2016-09-28 08:37:28 -05:00
let newName = spawn.createCreep([MOVE,MOVE,WORK,WORK,WORK,CARRY,CARRY,CARRY], undefined, {role: myrole});
2016-09-23 00:12:42 -05:00
console.log('Spawning new ' + myrole + ': ' + newName);
}
2016-09-15 00:30:24 -05:00
}
2016-09-23 00:12:42 -05:00
}
2016-09-15 00:30:24 -05:00
};
module.exports = roleUpgrader;