-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathrole.upgrader.js
32 lines (30 loc) · 1.22 KB
/
role.upgrader.js
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
32
module.exports = {
// a function to run the logic for this role
/** @param {Creep} creep */
run: function(creep) {
// if creep is bringing energy to the controller but has no energy left
if (creep.memory.working == true && creep.carry.energy == 0) {
// switch state
creep.memory.working = false;
}
// if creep is harvesting energy but is full
else if (creep.memory.working == false && creep.carry.energy == creep.carryCapacity) {
// switch state
creep.memory.working = true;
}
// if creep is supposed to transfer energy to the controller
if (creep.memory.working == true) {
// instead of upgraderController we could also use:
// if (creep.transfer(creep.room.controller, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
// try to upgrade the controller
if (creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
// if not in range, move towards the controller
creep.moveTo(creep.room.controller);
}
}
// if creep is supposed to get energy
else {
creep.getEnergy(true, true);
}
}
};