-
Notifications
You must be signed in to change notification settings - Fork 0
/
spawnManager.js
37 lines (33 loc) · 1.44 KB
/
spawnManager.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
module.exports = {
createExtensionsAndSpawn: function(roomName) {
const room = Game.rooms[roomName];
const extensions = room.find(FIND_STRUCTURES, {
filter: (structure) => structure.structureType === STRUCTURE_EXTENSION
});
const extensionsUnderConstruction = room.find(FIND_CONSTRUCTION_SITES, {
filter: (site) => site.structureType == STRUCTURE_EXTENSION
});
if (extensions.length === 0 && extensionsUnderConstruction.length < 5) {
console.log("Creating extensions...");
// Create construction sites for extensions
const spawnPos = Game.spawns["Spawn1"].pos;
const positions = [
[2, 0], [-2, 0], [4, 0], [-4, 0], [6, 0]
];
for (const position of positions) {
const x = spawnPos.x + position[0];
const y = spawnPos.y + position[1];
room.createConstructionSite(x, y, STRUCTURE_EXTENSION);
}
// Change roles of existing creeps
for (const name in Game.creeps) {
const creep = Game.creeps[name];
creep.memory.role = "builder";
}
// Spawn a new builder creep
Game.spawns["Spawn1"].spawnCreep([WORK, CARRY, MOVE], "builder" + Game.time, {
memory: { role: "builder" }
});
}
}
};