From 3980cef6aff48e3749bbccbdd12f0b273a61a9f6 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Wed, 27 Jun 2018 02:32:07 +0100 Subject: Extension-aware harvester energy transportation --- src/role.harvester.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/role.harvester.js b/src/role.harvester.js index 126f575..31e05d1 100644 --- a/src/role.harvester.js +++ b/src/role.harvester.js @@ -3,13 +3,18 @@ const util = require('creep'); module.exports = { run: (creep) => { if (creep.carry.energy < creep.carryCapacity) { - // just use the first source for now const source = creep.pos.findClosestByPath(FIND_SOURCES); if (creep.harvest(source) == ERR_NOT_IN_RANGE) { util.move(creep, source); } } else { - const spawn = Game.spawns['Initial']; + const spawn = creep.pos.findClosestByPath(FIND_MY_STRUCTURES, { + filter: (structure) => { + return (structure.structureType == STRUCTURE_EXTENSION + || structure.structureType == STRUCTURE_SPAWN) + && structure.energy < structure.energyCapacity; + } + }); if (creep.transfer(spawn, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { util.move(creep, spawn); } -- cgit v1.2.1