summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/role.upgrader.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/role.upgrader.js b/src/role.upgrader.js
index 7c018d7..b5d49e2 100644
--- a/src/role.upgrader.js
+++ b/src/role.upgrader.js
@@ -1,15 +1,21 @@
module.exports = {
run: (creep) => {
- if (creep.carry.energy < creep.carryCapacity) {
+ if (creep.memory.state === "withdrawing") {
const source = Game.spawns['Initial'];
if (creep.withdraw(source, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(source);
}
+ if (creep.carry.energy == creep.carryCapacity) {
+ creep.memory.state = "upgrading";
+ }
} else {
const controller = creep.room.controller;
if (creep.upgradeController(controller) == ERR_NOT_IN_RANGE) {
creep.moveTo(controller, { range: 3 });
}
+ if (creep.carry.energy == 0) {
+ creep.memory.state = "withdrawing";
+ }
}
}
};