-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.wallRepairer.js
43 lines (40 loc) · 1.49 KB
/
role.wallRepairer.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
33
34
35
36
37
38
39
40
41
42
43
var roleBuilder = require('role.builder');
module.exports = {
// a function to run the logic for this role
run: function (creep) {
// if creep is trying to repair something 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 repair something
if (creep.memory.working == true) {
// find all walls in the room
var percentage = 0.0003;
var target = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (s) => s.structureType == STRUCTURE_WALL
// || s.structureType == STRUCTURE_RAMPART
&& s.hits / s.hitsMax < percentage
});
if (!target == 0) {
if (creep.repair(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target, { maxRooms: 1 });
}
}
// if we can't fine one
else {
// look for construction sites
roleBuilder.run(creep);
}
}
// if creep is supposed to harvest energy from source
else {
creep.getEnergy(false, false, true, false);
}
}
};