-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspawnMyCreeps.js
More file actions
145 lines (119 loc) · 5.29 KB
/
spawnMyCreeps.js
File metadata and controls
145 lines (119 loc) · 5.29 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
var creepPrimitives = require('creepPrimitives');
module.exports = {
spawnAllCreeps: function (minBasicCreeps, basicCreepsInTheRoom, roomName, census) {
this.spawnMyBasicCreeps(minBasicCreeps, basicCreepsInTheRoom, roomName, census);
this.spawnTowerTenders(roomName, census);
//this.spawnColorguard(roomName);
},
spawnMyBasicCreeps: function (minBasicCreeps, basicCreepsInTheRoom, roomName, census) {
var basicCreep = [MOVE, WORK, CARRY, MOVE, WORK, CARRY,
MOVE, WORK, CARRY, MOVE, WORK, CARRY,
MOVE, WORK, CARRY, MOVE, WORK, CARRY,
MOVE, WORK, CARRY, MOVE, WORK, CARRY,
MOVE, WORK, CARRY, MOVE, WORK, CARRY,
MOVE, WORK, CARRY, MOVE, WORK, CARRY];
var allSpawns = _.values(Game.spawns);
var modifiedBody = basicCreep;
var spawn,
creepsInTheRoom;
//console.log(JSON.stringify(roomName));
//basicCreepsInTheRoom = Game.rooms[roomName].find(FIND_MY_CREEPS).length;
//console.log(creepsInTheRoom.toString() + ' creeps in room ' + );
spawn = Game.rooms[roomName].find(FIND_MY_SPAWNS)[0];
modifiedBody = basicCreep;
//console.log(spawn.id);
//console.log(JSON.stringify(creepsInTheRoom));
//console.log(JSON.stringify(spawn));
var noHarvesters = true;
//if (census.propertyIsEnumerable(roomName)) {
if (census.propertyIsEnumerable("harvester")) {
noHarvesters = false;
}
// }
if (basicCreepsInTheRoom < minBasicCreeps) {
result = spawn.canCreateCreep(modifiedBody, null);
//console.log(JSON.stringify(census['harvester']));
//console.log(JSON.stringify(Game.rooms[roomName]));
if (noHarvesters || Game.rooms[roomName].energyAvailable === Game.rooms[roomName].energyCapacityAvailable) {
for (j = 1; j < basicCreep.length; j++) {
if (result === -6 && modifiedBody.length > 3) {
modifiedBody = modifiedBody.slice(0, modifiedBody.length - 1);
result = spawn.canCreateCreep(modifiedBody, null);
} else if (result === 0) {
j = basicCreep.length; // breaks outer loop
}
}
}
if (result === 0 && spawn.spawning === null) {
result = spawn.createCreep(modifiedBody, null, { role: 'harvester', basic: true });
console.log(result + ' is one of us.');
} else if (result === -6) {
console.log('We are waiting for energy to build the best creep ' + roomName + '.');
} else if (result !== -4) {
console.log('There was an error: ' + result);
}
}
},
spawnTowerTenders: function (roomName, census) {
var towersInTheRoom = _.values(Game.rooms[roomName].find(FIND_MY_STRUCTURES, { filter: (structure) => { return structure.structureType === STRUCTURE_TOWER; } }));
var towerTenderBuild = [MOVE, CARRY];
var desiredNumTowerTenders,
actualNumTowerTenders,
spawn;
desiredNumTowerTenders = Math.ceil(towersInTheRoom.length / 3.0);
spawn = Game.rooms[roomName].find(FIND_MY_SPAWNS)[0];
//console.log(desiredNumTowerTenders);
//console.log(JSON.stringify(census.propertyIsEnumerable(["towerTender"])));
if (towersInTheRoom.length === 0) {
return -1;
} else if (desiredNumTowerTenders.length === 0) {
return -2;
}
if (!census.propertyIsEnumerable("towerTender")) {
actualNumTowerTenders = 0;
} else {
actualNumTowerTenders = Game.rooms[roomName].find(FIND_MY_CREEPS, { filter: (creep) => { return creep.realMemory.role === 'towerTender'; } }).length;
//console.log(JSON.stringify(!!spawn.spawning));
//console.log(actualNumTowerTenders.length);
//actualNumTowerTenders = census["towerTender"].length;
}
//console.log('TT actual: ' + actualNumTowerTenders + ' TT desired: ' + desiredNumTowerTenders);
//console.log(JSON.stringify(spawn.spawning));
if (actualNumTowerTenders < desiredNumTowerTenders) {
result = creepPrimitives.spawnCreep(roomName, spawn, towerTenderBuild, { role: 'towerTender' }, 'We need energy to create a tower tender in room ' + roomName + '.');
//spawn.canCreateCreep(towerTenderBuild, null);
//if (result === 0 && spawn.spawning === null) {
// result = spawn.createCreep(towerTenderBuild, null, { role: 'towerTender' });
// console.log(result + ' is one of us.');
//} else if (result === -6) {
// console.log('We have not the energy for a Tower Tender in room ' + roomName + '.')
//} else if (result !== -4) {
// console.log('There was an error: ' + result);
//}
}
//console.log(actualNumTowerTenders);
//actualNumTowerTenders = census.role['towerTender'].members.length;
},
spawnColorguard: function (roomName) {
var colorguardBuild = [MOVE, WORK, CARRY, CLAIM];
var desiredNumColorguard,
actualNumColorGuard,
spawn;
spawn = Game.rooms[roomName].find(FIND_MY_SPAWNS)[0];
desiredNumColorguard = [Game.flags].length;//.length;
actualNumColorGuard = _(Game.creeps).filter({ memory: { role: 'color' } });
console.log(JSON.stringify(desiredNumColorguard));
console.log(JSON.stringify(actualNumColorGuard.length));
if (actualNumColorGuard < desiredNumColorguard || !actualNumColorGuard.length) {
result = spawn.canCreateCreep(colorguardBuild, null);
if (result === 0 && spawn.spawning === null) {
result = spawn.createCreep(colorguardBuild, null, { role: 'colorguard' });
console.log(result + ' is one of us.');
} else if (result === -6) {
console.log('We have not the energy for a colorguard in room ' + roomName + '.');
} else if (result !== -4) {
console.log('There was an error: ' + result);
}
}
}
};