summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Harley2018-06-26 16:24:10 +0100
committerTom Harley2018-06-26 16:24:10 +0100
commit8f7e8fa40439b41582e408eede6e2e2eb7d3d600 (patch)
tree554d04cd4aadcab89060641a91957b18ff2e98d9 /src
parentActually include unified movement function (diff)
downloadscreeps-ai-8f7e8fa40439b41582e408eede6e2e2eb7d3d600.tar.gz
screeps-ai-8f7e8fa40439b41582e408eede6e2e2eb7d3d600.zip

Change builders to withdraw from spawner

Diffstat (limited to 'src')
-rw-r--r--src/role.builder.js5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/role.builder.js b/src/role.builder.js
index 8c7fc6b..f243eac 100644
--- a/src/role.builder.js
+++ b/src/role.builder.js
@@ -4,6 +4,7 @@ module.exports = {
run: (creep) => {
if (creep.memory.state === "building") {
if (creep.carry.energy > 0) {
+ // still building
const targets = creep.room.find(FIND_CONSTRUCTION_SITES);
if (targets.length) {
if (creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
@@ -11,16 +12,18 @@ module.exports = {
}
}
} else {
+ // just finished building
creep.memory.state = "collecting";
}
} else {
if (creep.carry.energy < creep.carryCapacity) {
// still filling up
const spawn = Game.spawns['Initial'];
- if (creep.transfer(spawn, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
+ if (creep.withdraw(spawn, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
util.move(creep, spawn);
}
} else {
+ // just finished filling up
creep.memory.state = "building";
}
}