From c76b4926b02598693df1b9ca0b416315da2b79b0 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Tue, 26 Jun 2018 06:32:12 +0100 Subject: Use findClosestByPath --- src/role.harvester.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src') 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); } } } -- cgit v1.2.1