-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprototype.room.js
59 lines (51 loc) · 1.48 KB
/
prototype.room.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
let spawnStrategies = {
E42N15: {
"miner": 2,
"collector": 2,
"repairer": 2,
"builder": 2,
"upgrader": 4,
},
E41N16: {
"miner": 2,
"collector": 2,
"repairer": 2,
"builder": 4,
"upgrader": 4,
},
};
/**
* Execute actions according to strategy of this room
*/
function run() {
let name = this.name;
modules.memory.room.handle(this);
if (this.controller.my) {
// For owned rooms
// Spawn creeps according to this room's spawn strategy
let spawnStrategy = spawnStrategies[name];
for (let role in spawnStrategy) {
let numNow = _.sum(Game.creeps, c => c.memory.home === name && c.memory.role === role);
if (numNow < spawnStrategy[role]) {
let spawns = this.find(FIND_MY_SPAWNS, {filter: s => !s.spawning});
if (spawns.length > 0) {
spawns[0].spawnRole(role);
}
break;
}
}
// Order towers to attack if enemy is present
let towers = this.find(FIND_MY_STRUCTURES, {filter: s => s.structureType === STRUCTURE_TOWER});
for (let i in towers) {
let tower = towers[i];
let target = tower.pos.findClosestByPath(FIND_HOSTILE_CREEPS);
if (target) {
tower.attack(target);
}
}
} else {
}
}
module.exports = function() {
Room.prototype.run = run;
};