-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheal_package.js
62 lines (57 loc) · 1.89 KB
/
heal_package.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* healing functionality */
module.exports = {
/* healing creep */
healer: function(creep) {
var closest_needy_creep = creep.pos.findNearest(Game.MY_CREEPS, {
filter: function(patient_candidate_creep) {
return patient_candidate_creep.hits < patient_candidate_creep.hitsMax;
}
});
if (closest_needy_creep) {
creep.moveTo(closest_needy_creep);
creep.heal(closest_needy_creep);
} else {
// if no creeps are hurt, move to a fighting creep, or rally
var closest_fighting_creep = creep.pos.findNearest(Game.MY_CREEPS, {
filter: function(rally_candidate_creep) {
return [
'guarding',
'ranged_guarding'
].indexOf(rally_candidate_creep.memory.job) > -1;
}
});
if (closest_fighting_creep) {
creep.moveTo(closest_fighting_creep);
} else {
var rally_point = Game.flags.RallyPoint;
if (!rally_point) {
rally_point = creep.pos.findNearest(Game.MY_SPAWNS);
}
if (rally_point) {
creep.moveTo(rally_point);
}
}
}
},
/* list of healing creeps */
get_healers: function() {
var healers = [];
for (var i in Game.creeps) {
var creep = Game.creeps[i];
if (creep.memory.job == 'healing') {
healers.push(creep);
}
}
return healers;
},
/* initialize a new healing creep */
spawn_healer: function(spawn) {
return spawn.createCreep([
Game.TOUGH,
Game.TOUGH,
Game.TOUGH,
Game.HEAL,
Game.MOVE
], undefined, {job: 'healing'});
}
}