|
|
|
let common = require('common')
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'remoteHarvester',
|
|
|
|
prio: 10,
|
|
|
|
minRcl: 3,
|
|
|
|
bodies: [
|
|
|
|
[WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE, MOVE],
|
|
|
|
[WORK, WORK, WORK, WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE],
|
|
|
|
[WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE],
|
|
|
|
],
|
|
|
|
tick (creep) {
|
|
|
|
let dropped = creep.pos.findInRange(FIND_DROPPED_RESOURCES, 1);
|
|
|
|
if (dropped.length > 0) {
|
|
|
|
creep.pickup(dropped[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
let repairTargets = creep.pos.findInRange(
|
|
|
|
FIND_STRUCTURES,
|
|
|
|
3,
|
|
|
|
{filter: s => s.structureType === STRUCTURE_CONTAINER && s.hits + creep.getActiveBodyparts(WORK) * 100 <= s.hitsMax});
|
|
|
|
if (repairTargets.length > 0) {
|
|
|
|
if (creep.store[RESOURCE_ENERGY] >= creep.getActiveBodyparts(WORK) * 10 && creep.repair(repairTargets[0]) === OK) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let targetCreeps = creep.pos.findInRange(FIND_MY_CREEPS, 1, {
|
|
|
|
filter: tc => tc.store.getFreeCapacity(RESOURCE_ENERGY) && tc.memory.role !== 'remoteHarvester'
|
|
|
|
});
|
|
|
|
if (targetCreeps.length > 0) {
|
|
|
|
creep.transfer(targetCreeps[0], RESOURCE_ENERGY)
|
|
|
|
} else {
|
|
|
|
let targets = creep.pos.findInRange(FIND_STRUCTURES, 1, {
|
|
|
|
filter: (structure) => structure.store && structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0
|
|
|
|
});
|
|
|
|
if (targets.length > 0) {
|
|
|
|
creep.transfer(_.min(targets, el => el.store[RESOURCE_ENERGY]), RESOURCE_ENERGY)
|
|
|
|
} else {
|
|
|
|
if (creep.store[RESOURCE_ENERGY] >= creep.getActiveBodyparts(WORK) * 5) {
|
|
|
|
let buildTargets = creep.pos.findInRange(FIND_MY_CONSTRUCTION_SITES, 1);
|
|
|
|
if (buildTargets.length > 0 && creep.build(buildTargets[0]) === OK) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let target = Game.getObjectById(creep.memory.source)
|
|
|
|
let actionResult = creep.harvest(target)
|
|
|
|
if (actionResult === ERR_NOT_IN_RANGE) {
|
|
|
|
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffaa00'}});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|