-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreep.general.js
More file actions
51 lines (45 loc) · 1.35 KB
/
creep.general.js
File metadata and controls
51 lines (45 loc) · 1.35 KB
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
var utilities = require('utilities');
Creep.prototype.isDangerous = function () {
for (let j in this.body) {
let type = this.body[j].type;
if (type != WORK && type != MOVE && type != CARRY && type != TOUGH) {
return true;
}
}
return false;
}
module.exports = {
getCreepsWithOrder: function(type, target) {
return _.filter(Game.creeps, (creep) => {
if (creep.memory.order) {
if (creep.memory.order.type == type && creep.memory.order.target == target) {
return true;
}
}
return false;
})
},
renew: function (creep, spawner) {
var cost = utilities.getBodyCost(creep);
if (cost < spawner.room.energyCapacityAvailable * 0.75) {
// Do not renew cheap creeps, they should be replaced with better ones.
return false;
}
if (creep.memory.renewing || creep.ticksToLive < CREEP_LIFE_TIME * 0.2) {
creep.memory.renewing = true;
var result = spawner.renewCreep(creep);
if (result == ERR_NOT_IN_RANGE) {
creep.moveTo(spawner);
}
if (creep.ticksToLive >= CREEP_LIFE_TIME * 0.9) {
delete creep.memory.renewing;
}
else if (creep.ticksToLive > CREEP_LIFE_TIME * 0.3 && spawner.room.energyAvailable < spawner.room.energyCapacityAvailable * 0.1) {
// If there is not much energy left in the spawner, return to work prematurely.
delete creep.memory.renewing;
}
return true;
}
return false;
},
}