2017-06-06 13:17:26 -05:00
|
|
|
let buildparts=require('bodypartbuilder')
|
2016-09-28 08:37:28 -05:00
|
|
|
let roleHauler2 = {
|
2016-09-15 00:30:24 -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-15 01:40:56 -05:00
|
|
|
if(creep.memory.hauling == undefined){creep.memory.hauling=false}
|
|
|
|
if(creep.memory.hauling && creep.carry.energy == 0) {
|
|
|
|
creep.memory.hauling = false;
|
|
|
|
creep.say('gathering');
|
|
|
|
}
|
|
|
|
if(!creep.memory.hauling && creep.carry.energy == creep.carryCapacity) {
|
|
|
|
creep.memory.hauling = true;
|
|
|
|
creep.say('hauling');
|
|
|
|
}
|
|
|
|
if(creep.memory.hauling==false){
|
2016-09-15 00:30:24 -05:00
|
|
|
if(creep.carryCapacity > creep.carry.energy){
|
2016-09-28 08:37:28 -05:00
|
|
|
let container = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
2016-09-15 00:30:24 -05:00
|
|
|
filter: (structure) => {
|
2016-09-15 01:56:03 -05:00
|
|
|
return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ;
|
2016-09-15 00:30:24 -05:00
|
|
|
}});
|
|
|
|
if(creep.withdraw(container,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
|
|
creep.say("MTSC");
|
|
|
|
creep.moveTo(container);
|
|
|
|
}
|
2016-09-23 00:12:42 -05:00
|
|
|
}
|
2016-09-15 00:30:24 -05:00
|
|
|
} else {
|
2016-09-28 08:37:28 -05:00
|
|
|
let spawntarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
2016-09-15 00:30:24 -05:00
|
|
|
filter: (structure) => {
|
2017-06-06 13:17:26 -05:00
|
|
|
return ((structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && structure.energy < structure.energyCapacity)
|
2016-09-15 00:30:24 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
if(spawntarget != undefined) {
|
|
|
|
if(creep.transfer(spawntarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
|
|
creep.say('refilling')
|
|
|
|
creep.moveTo(spawntarget);
|
|
|
|
}
|
|
|
|
} else {
|
2016-09-23 00:12:42 -05:00
|
|
|
creep.say('NTD');
|
|
|
|
creep.moveTo(creep.room.memory.hauler2parkx,creep.room.memory.hauler2parky,creep.room.roomName)
|
2016-09-15 00:30:24 -05:00
|
|
|
}
|
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
}
|
2016-09-15 00:30:24 -05:00
|
|
|
};
|
|
|
|
module.exports = roleHauler2;
|