summaryrefslogtreecommitdiff
path: root/src/role.harvester.js
blob: e372ba4f0530b9efb88c1f08e995161780cd192d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module.exports = {
  run: (creep) => {
    if (creep.carry.energy < creep.carryCapacity) {
      // just use the first sourrce for now
      const source = creep.room.find(FIND_SOURCES)[0];
      if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
        creep.moveTo(source, { range: 1 });
      }
    } else {
      const spawn = Game.spawns['Initial'];
      if (creep.transfer(spawn, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
        creep.moveTo(spawn, { range: 1 });
      }
    }
  }
};