diff options
| -rw-r--r-- | src/role.harvester.js | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/role.harvester.js b/src/role.harvester.js index d0c4613..4d13dd7 100644 --- a/src/role.harvester.js +++ b/src/role.harvester.js @@ -1,20 +1,15 @@ -const move = (creep, target) => { - const path = creep.room.findPath(creep.pos, target.pos); - creep.move(path[0].direction); -} - module.exports = { run: (creep) => { if (creep.carry.energy < creep.carryCapacity) { - // just use the first sourrce for now - const source = creep.room.find(FIND_SOURCES)[0]; + // just use the first source for now + const source = creep.pos.findClosestByPath(FIND_SOURCES); if (creep.harvest(source) == ERR_NOT_IN_RANGE) { - move(creep, source); + creep.moveTo(source); } } else { const spawn = Game.spawns['Initial']; if (creep.transfer(spawn, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { - move(creep, spawn); + creep.moveTo(spawn); } } } |
