-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoom.spawn.js
More file actions
55 lines (53 loc) · 2.14 KB
/
Room.spawn.js
File metadata and controls
55 lines (53 loc) · 2.14 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
52
53
54
55
var checkSpawns = function(room) {
var spawns = room.memory.found.mySpawns;
var activeSpawns = _.filter(spawns, function(spawn) {
if(spawn.spawning || spawn.memory.busy == Game.time) {
return false;
} else {
return true;
}
});
if(!activeSpawns.length) {
room.memory.spawns = [];
} else {
room.memory.spawns = activeSpawns;
}
};
var RoomSpawns = function() {
var harvesters = _.filter(this.memory.found.myCreeps, function(creep) {
if(creep.memory.role === 'harvester') {
return true;
}
});
var hostiles = this.memory.found.hostileCreeps;
var hostileFlags = _.filter(Game.flags, function(flag) {
if(flag.color === COLOR_RED) {
return true;
}
});
if(hostiles.length > 0) {
checkSpawns(this);
try {this.fighterSpawn();} catch(err) {console.log(err+" "+this+": Room.cycle.js this.fighterSpawn()");}
} else {
if(hostileFlags.length > 0) {
checkSpawns(this);
try {this.fighterSpawn();} catch(err) {console.log(err+" "+this+": Room.cycle.js this.fighterSpawn()");}
}
if(harvesters.length > 0) {
checkSpawns(this);
try {this.spawnKeeperSpawn();} catch(err) {console.log(err+" "+this+": Room.cycle.js this.spawnKeeperSpawn()");}
checkSpawns(this);
try {this.courierSpawn();} catch(err) {console.log(err+" "+this+": Room.cycle.js this.courierSpawn()");}
checkSpawns(this);
try {this.harvesterSpawn();} catch(err) {console.log(err+" "+this+": Room.cycle.js this.harvesterSpawn()");}
checkSpawns(this);
try {this.upgraderSpawn();} catch(err) {console.log(err+" "+this+": Room.cycle.js this.upgraderSpawn()");}
checkSpawns(this);
try {this.builderSpawn();} catch(err) {console.log(err+" "+this+": Room.cycle.js this.builderSpawn()");}
} else {
checkSpawns(this);
try {this.harvesterSpawn();} catch(err) {console.log(err+" "+this+": Room.cycle.js this.harvesterSpawn()");}
}
}
};
module.exports = RoomSpawns;