2017-06-06 13:17:26 -05:00
|
|
|
let buildparts=require('bodypartbuilder')
|
2016-09-28 08:37:28 -05:00
|
|
|
let roleHauler = {
|
2016-09-23 00:12:42 -05:00
|
|
|
run: function(creep) {
|
2017-06-06 13:17:26 -05:00
|
|
|
let spawntargets = creep.pos.findClosestByPath(FIND_STRUCTURES, {
|
|
|
|
filter: (structure) => {
|
|
|
|
return (((structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && structure.energy < structure.energyCapacity))
|
|
|
|
}
|
|
|
|
});
|
|
|
|
let containertargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
|
|
|
filter: (structure) => {
|
|
|
|
return ((structure.structureType == STRUCTURE_CONTAINER ) && _.sum(structure.store) < structure.storeCapacity) ;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
|
|
|
filter: (structure) => {
|
|
|
|
return ((structure.structureType == STRUCTURE_STORAGE || structure.structureType == STRUCTURE_TERMINAL ) && _.sum(structure.store) < structure.storeCapacity) ;
|
|
|
|
}
|
|
|
|
});
|
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}
|
2017-06-06 13:17:26 -05:00
|
|
|
if(creep.memory.hauling && _.sum(creep.carry) == 0) {
|
2016-09-23 00:12:42 -05:00
|
|
|
creep.memory.destsource=undefined
|
2016-09-15 01:40:56 -05:00
|
|
|
creep.memory.hauling = false;
|
|
|
|
creep.say('gathering');
|
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
if(!creep.memory.hauling && _.sum(creep.carry) == creep.carryCapacity) {
|
2016-09-15 01:40:56 -05:00
|
|
|
creep.memory.hauling = true;
|
|
|
|
creep.say('hauling');
|
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
let sources = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: {resourceType: RESOURCE_ENERGY}} || STRUCTURE_TERMINAL );
|
2016-09-15 01:40:56 -05:00
|
|
|
if(creep.memory.hauling==false){
|
2016-09-23 00:12:42 -05:00
|
|
|
if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined}
|
2016-09-28 08:37:28 -05:00
|
|
|
let mysource=Game.getObjectById(creep.memory.destsource.id)
|
2017-06-06 13:17:26 -05:00
|
|
|
if(creep.pickup(mysource) == ERR_NOT_IN_RANGE && creep.carryCapacity > _.sum(creep.carry)) {
|
2016-09-23 00:12:42 -05:00
|
|
|
creep.moveTo(mysource);
|
2017-06-06 13:17:26 -05:00
|
|
|
}
|
2016-09-28 08:37:28 -05:00
|
|
|
} else {
|
2017-06-06 13:17:26 -05:00
|
|
|
if(sources != undefined ) {
|
2016-09-23 00:12:42 -05:00
|
|
|
if(spawntargets) {
|
|
|
|
if(creep.transfer(spawntargets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
|
|
creep.moveTo(spawntargets);
|
|
|
|
}
|
|
|
|
} else if (containertargets) {
|
|
|
|
if(creep.transfer(containertargets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
|
|
creep.moveTo(containertargets);
|
2016-09-15 00:30:24 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
} else {
|
2016-09-23 00:12:42 -05:00
|
|
|
if(creep.transfer(storagetargets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
|
|
creep.moveTo(storagetargets);
|
2017-06-06 13:17:26 -05:00
|
|
|
}
|
2016-09-15 00:30:24 -05:00
|
|
|
}
|
2016-09-23 00:12:42 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
if(creep.carry.RESOURCE_ZYNTHIUM > 0){
|
|
|
|
if(creep.transfer(storagetargets, RESOURCE_ZYNTHIUM) == ERR_NOT_IN_RANGE) {
|
|
|
|
creep.moveTo(storagetargets);
|
2016-09-23 00:12:42 -05:00
|
|
|
}
|
2016-09-15 00:30:24 -05:00
|
|
|
}
|
2017-06-06 13:17:26 -05:00
|
|
|
}
|
2016-09-23 00:12:42 -05:00
|
|
|
}
|
2016-09-15 00:30:24 -05:00
|
|
|
};
|
|
|
|
module.exports = roleHauler;
|