-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.role.js
43 lines (38 loc) · 1.13 KB
/
util.role.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
module.exports = {
DEFAULT_ROLE: 'default',
convert: function(creep, dst) {
var src = creep.memory.role;
var memory = {
build: creep.memory.build,
role: dst,
version: creep.memory.version,
};
creep.memory = memory;
console.log("Gave " + src + " " + creep.name + " role " + dst);
return creep.name;
},
convertAny: function(build, src, dst) {
var candidate = null;
for(var name in Game.creeps) {
var creep = Game.creeps[name];
if (creep.memory.build != build) {
continue;
}
if(!creep.memory.role) {
creep.memory.role = dst;
console.log("Gave unassigned " + creep.name + " role " + dst);
return creep.name;
}
if (creep.memory.role == src) {
candidate = creep;
}
}
if (!candidate) {
return null;
}
return this.convert(candidate, dst);
},
hasRole: function(creep, role) {
return role === creep.memory.role;
},
};