summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Harley2018-06-26 06:32:12 +0100
committerTom Harley2018-06-26 06:32:12 +0100
commitc76b4926b02598693df1b9ca0b416315da2b79b0 (patch)
tree6d79839643c09a057c49c97e083b3c62afcc51de
parentUse workaround for pathfinding (diff)
downloadscreeps-ai-c76b4926b02598693df1b9ca0b416315da2b79b0.tar.gz
screeps-ai-c76b4926b02598693df1b9ca0b416315da2b79b0.zip

Use findClosestByPath

-rw-r--r--src/role.harvester.js13
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);
}
}
}