summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Harley2018-06-27 02:32:07 +0100
committerTom Harley2018-06-27 02:32:07 +0100
commit3980cef6aff48e3749bbccbdd12f0b273a61a9f6 (patch)
treee0afb080ded13e10b110f750442af723f92345a9
parentEdit logging to use error logger (diff)
downloadscreeps-ai-3980cef6aff48e3749bbccbdd12f0b273a61a9f6.tar.gz
screeps-ai-3980cef6aff48e3749bbccbdd12f0b273a61a9f6.zip

Extension-aware harvester energy transportation

-rw-r--r--src/role.harvester.js9
1 files changed, 7 insertions, 2 deletions
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);
}