-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.boosting.js
45 lines (41 loc) · 1.57 KB
/
helper.boosting.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
44
45
module.exports = {
accept: function(creep) {
if(!creep.room.ai()) return false;
if(creep.memory.boosts === undefined) creep.memory.boosts = [];
if(!creep.memory.boosts) return false;
let resources = _.drop(arguments);
for(let resource of resources) {
if(creep.memory.boosts.includes(resource)) continue;
let booster = _.find(creep.room.ai().labs.boosters, (b) => b.resource === resource && b.isReady());
if(booster) {
if(creep.pos.isNearTo(booster.lab)) {
booster.lab.boostCreep(creep);
creep.memory.boosts.push(resource);
// TODO: verify that we get no problems when two boosters are in range
// or we move out of range because of a second boost
} else {
creep.goTo(booster.lab);
return true;
}
} else {
// giving up on that boost, because it is not available
creep.memory.boosts.push(resource);
}
}
return false;
},
decline: function(creep) {
if(creep.memory.boosts === undefined) creep.memory.boosts = [];
if(!creep.memory.boosts) return;
let resources = _.drop(arguments);
for(let resource of resources) {
if(!creep.memory.boosts.includes(resource)) {
creep.memory.boosts.push(resource);
}
}
},
disable: function(memory) {
memory.boosts = false;
return memory;
}
};