2017-06-06 13:17:26 -05:00
|
|
|
let buildparts=require('bodypartbuilder')
|
2016-09-28 08:37:28 -05:00
|
|
|
let roleTowerrecharger = {
|
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.recharging && creep.carry.energy == 0) {
|
|
|
|
creep.memory.recharging = false;
|
|
|
|
creep.say('refilling');
|
|
|
|
}
|
|
|
|
if(!creep.memory.recharging && creep.carry.energy == creep.carryCapacity) {
|
|
|
|
creep.memory.recharging = true;
|
|
|
|
creep.say('building');
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!creep.memory.recharging) {
|
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] > 1000) ;
|
|
|
|
}});
|
|
|
|
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 spawntarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
2016-09-23 00:12:42 -05:00
|
|
|
filter: (structure) => {
|
|
|
|
return (structure.structureType == STRUCTURE_TOWER && structure.energy < structure.energyCapacity)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if(spawntarget != undefined) {
|
|
|
|
if(creep.transfer(spawntarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
|
|
creep.moveTo(spawntarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
}
|
2016-09-23 00:12:42 -05:00
|
|
|
};
|
|
|
|
module.exports = roleTowerrecharger;
|