summaryrefslogtreecommitdiff
path: root/src/role.builder.js
blob: f243eacd014cb9c550b81f332b32bdaa67789d15 (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
26
27
28
29
30
31
const util = require('creep');

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) {
            util.move(creep, targets[0]);
          }
        }
      } 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.withdraw(spawn, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
          util.move(creep, spawn);
        }
      } else {
        // just finished filling up
        creep.memory.state = "building";
      }
    }
  }
};