diff options
| author | Tom Harley | 2019-10-15 02:28:12 +0100 |
|---|---|---|
| committer | Tom Harley | 2019-10-15 02:28:12 +0100 |
| commit | 9b28c28286cc312da6b8f084f74cabed0e08a596 (patch) | |
| tree | 2496d384e7230dcc6f844e89c2d33d9c803aa697 /src/role/upgrader.js | |
| parent | Various changes to pathfinding (diff) | |
| download | screeps-ai-9b28c28286cc312da6b8f084f74cabed0e08a596.tar.gz screeps-ai-9b28c28286cc312da6b8f084f74cabed0e08a596.zip | |
Rearrange role files
Diffstat (limited to 'src/role/upgrader.js')
| -rw-r--r-- | src/role/upgrader.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/role/upgrader.js b/src/role/upgrader.js new file mode 100644 index 0000000..baf8ffd --- /dev/null +++ b/src/role/upgrader.js @@ -0,0 +1,25 @@ +// vim: tw=80 ts=2 sw=2 et + +const util = require('creep'); + +module.exports = { + run: (creep) => { + if (creep.memory.state === "withdrawing") { + const source = Game.spawns[creep.memory.spawned_from]; + 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"; + } + } + } +}; |
