You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
8 months ago
|
const consts = {
|
||
|
FINISHED: 1,
|
||
|
HARVESTING: 2,
|
||
|
CONTINUE_ACTIVITY: 3,
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
consts,
|
||
|
harvestEnergy (creep) {
|
||
|
if (!creep.memory.harvestingEnergy && creep.store[RESOURCE_ENERGY] > 0) {
|
||
|
return consts.CONTINUE_ACTIVITY
|
||
|
}
|
||
|
creep.memory.harvestingEnergy = creep.store.getFreeCapacity() > 0
|
||
|
if (!creep.memory.harvestingEnergy) {
|
||
|
return consts.FINISHED
|
||
|
}
|
||
|
// if (creep.store[RESOURCE_ENERGY] === 0) {
|
||
|
// creep.say('🔄 fetch');
|
||
|
// }
|
||
|
let target
|
||
|
if (!target) {
|
||
|
target = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
||
|
filter: s => (s.structureType === STRUCTURE_CONTAINER || s.structureType === STRUCTURE_STORAGE)
|
||
|
&& s.store[RESOURCE_ENERGY] >= creep.store.getFreeCapacity(RESOURCE_ENERGY)
|
||
|
});
|
||
|
}
|
||
|
if(target) {
|
||
|
let result = creep.withdraw(target, RESOURCE_ENERGY)
|
||
|
if (result === ERR_NOT_IN_RANGE) {
|
||
|
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffaa00'}});
|
||
|
}
|
||
|
else if (result === OK) {
|
||
|
return consts.FINISHED
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
let target = creep.pos.findClosestByRange(FIND_MY_CREEPS, {
|
||
|
filter: creep => creep.memory.role === 'harvester' && creep.store[RESOURCE_ENERGY] > 0
|
||
|
});
|
||
|
if (target) {
|
||
|
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffaa00'}});
|
||
|
}
|
||
|
}
|
||
|
return consts.HARVESTING
|
||
|
}
|
||
|
}
|