summaryrefslogtreecommitdiff
path: root/src/role.upgrader.js
blob: baf8ffd0743bc938bd5483741d2f15c51a7868f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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";
      }
    }
  }
};