-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloop.memoryManagement.js
More file actions
362 lines (350 loc) · 10 KB
/
loop.memoryManagement.js
File metadata and controls
362 lines (350 loc) · 10 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
var funcBuildOrders = require('func.buildOrders');
var funcHelpers = require('func.helpers');
var loopMemoryManagement =
{
start: function(currentRoom)
{
if((_.filter(Memory.rooms, (room) => room.name == currentRoom)).length > 0)
{
var thisRoom = Game.rooms[currentRoom]
var myRoom = Memory.rooms.find(element => element.name == currentRoom);
let buildList = thisRoom.find(FIND_CONSTRUCTION_SITES)
switch(myRoom.phase)
{
case 0:
{//Road From CityCenter to Spawn, Source, and Controller
if(buildList.length < 1)
{
funcBuildOrders.buildCenterToSpawn(currentRoom)
funcBuildOrders.buildCenterToController(currentRoom)
funcBuildOrders.buildCenterToSource(currentRoom)
//funcBuildOrders.buildSpawnStorage(currentRoom)
//Get the containers for the sources and controller
if(myRoom.controller.store && myRoom.sources[0].store && myRoom.spawnContainer &&
(
myRoom.sources[1].store
||
!myRoom.sources[1]
))
{
console.log(currentRoom,"Advancing to Phase", myRoom.phase+1)
myRoom.phase = 1
}
else
{
if(!myRoom.controller.store)
{//Missing Controller Store, find it
let foundStructures = thisRoom.lookForAtArea(LOOK_STRUCTURES
,myRoom.controller.pos.y-3
,myRoom.controller.pos.x-3
,myRoom.controller.pos.y+3
,myRoom.controller.pos.x+3
,true
)
console.log(JSON.stringify(foundStructures))
if(foundStructures.length > 1)
{
let foundContainer = foundStructures.find(element => element.structure.structureType == STRUCTURE_CONTAINER);
if(foundContainer)
{
myRoom.controller.store = foundContainer.structure.id
}
}
else
{
myRoom.controller.store = foundStructures.id
}
}
if(!myRoom.sources[0].store)
{
let foundStructures = thisRoom.lookForAtArea(LOOK_STRUCTURES
,myRoom.sources[0].pos.y-1
,myRoom.sources[0].pos.x-1
,myRoom.sources[0].pos.y+1
,myRoom.sources[0].pos.x+1
,true
)
console.log(JSON.stringify(foundStructures))
if(foundStructures.length > 0)
{
let foundContainer = foundStructures.find(element => element.structure.structureType == STRUCTURE_CONTAINER);
myRoom.sources[0].store = foundContainer.structure.id
}
else
{
myRoom.sources[0].store = foundContainer.id
}
}
if(myRoom.sources[1] &&!myRoom.sources[1].store)
{
let foundStructures = thisRoom.lookForAtArea(LOOK_STRUCTURES
,myRoom.sources[1].pos.y-1
,myRoom.sources[1].pos.x-1
,myRoom.sources[1].pos.y+1
,myRoom.sources[1].pos.x+1
,true
)
if(foundStructures.length > 0)
{
let foundContainer = foundStructures.find(element => element.structure.structureType == STRUCTURE_CONTAINER);
myRoom.sources[1].store = foundContainer.structure.id
}
else
{
myRoom.sources[1].store = foundStructures.id
}
}
if(!myRoom.spawnContainer)
{
if(thisRoom.controller.level > 3)
{
let thisStore = thisRoom.find(FIND_MY_STRUCTURES).find(element => element.structureType == STRUCTURE_STORAGE);
if(thisStore)
{
myRoom.spawnContainer = thisStore.id
}
}
else
{
let foundStructures = thisRoom.lookForAtArea(LOOK_STRUCTURES
,myRoom.spawns[0].pos.y-3
,myRoom.spawns[0].pos.x-3
,myRoom.spawns[0].pos.y+3
,myRoom.spawns[0].pos.x+3
,true
)
if(foundStructures.length > 0)
{
let foundContainer = foundStructures.find(element => element.structure.structureType == STRUCTURE_CONTAINER);
myRoom.spawnContainer = foundContainer.structure.id
}
else
{
console.log('No Structure Found Near Spawn')
}
}
}
}
}
else
{
console.log(currentRoom,"Not Ready For Advancement, Building")
}
break;
}
case 1:
{//Extensions first Round
if(buildList.length < 1)
{
funcBuildOrders.buildExtensions(thisRoom.name)
myRoom.phase = myRoom.phase+1
console.log(currentRoom,"Advancing to Phase", myRoom.phase+1)
}
else
{
console.log(currentRoom,"Not Ready For Advancement, Building")
}
}
case 2:
{//Build Spawn and Source Links
if(buildList.length < 1 && thisRoom.controller.level >= 6)
{
if(!myRoom.spawns[0].link)
{
let foundStructures = thisRoom.lookForAtArea(LOOK_STRUCTURES
,myRoom.spawns[0].pos.y-3
,myRoom.spawns[0].pos.x-3
,myRoom.spawns[0].pos.y+3
,myRoom.spawns[0].pos.x+3
,true
)
let foundLink = foundStructures.find(element => element.structure.structureType == STRUCTURE_LINK);
if(foundLink)
{
myRoom.spawns[0].link = foundLink.structure.id
}
}
if(!myRoom.sources[0].link)
{
let foundStructures = thisRoom.lookForAtArea(LOOK_STRUCTURES
,myRoom.sources[0].pos.y-2
,myRoom.sources[0].pos.x-2
,myRoom.sources[0].pos.y+2
,myRoom.sources[0].pos.x+2
,true
)
if(foundStructures.length > 0)
{
let foundLink = foundStructures.find(element => element.structure.structureType == STRUCTURE_LINK);
if(foundLink)
{
myRoom.sources[0].link = foundLink.structure.id
}
}
else
{
console.log('No Structure Found Near Spawn')
}
}
if(!myRoom.sources[1].link)
{
let foundStructures = thisRoom.lookForAtArea(LOOK_STRUCTURES
,myRoom.sources[1].pos.y-2
,myRoom.sources[1].pos.x-2
,myRoom.sources[1].pos.y+2
,myRoom.sources[1].pos.x+2
,true
)
if(foundStructures.length > 0)
{
let foundLink = foundStructures.find(element => element.structure.structureType == STRUCTURE_LINK);
myRoom.sources[1].link = foundLink.structure.id
}
else
{
console.log('No Structure Found Near Spawn')
}
}
if(myRoom.spawns[0].link && myRoom.sources[0].link && (!myRoom.sources[1] || myRoom.sources[1].link))
{
console.log(currentRoom,"Advancing to Phase", myRoom.phase + 1)
myRoom.phase = myRoom.phase + 1
}
else
{
console.log(myRoom.name)
funcBuildOrders.buildLinks(thisRoom.name)
}
}
else
{
console.log(currentRoom,"Not Ready For Advancement, Building or Under Level")
}
break;
}
case 3:
{//Build Spawn Storage if it doesnt exist
if(buildList.length < 1)
{
if(myRoom.spawnContainer)
{
myRoom.phase = myRoom.phase+1
console.log(currentRoom,"Advancing to Phase", myRoom.phase+1)
}
else
{
funcBuildOrders.buildSpawnStorage(thisRoom.name)
}
}
else
{
console.log(currentRoom,"Not Ready For Advancement, Building")
}
break;
}
case 4:
{//Build / Find Terminal
if(buildList.length < 1)
{
if(!myRoom.terminal)
{
let thisTerminal = thisRoom.find(FIND_MY_STRUCTURES, { filter: { structureType: STRUCTURE_TERMINAL } } )
console.log(JSON.stringify(thisTerminal))
if(thisTerminal)
{
myRoom.terminal = thisTerminal.id
console.log(currentRoom,"Advancing to Phase", myRoom.phase+1)
myRoom.phase = myRoom.phase+1
break
}
else
{
console.log(currentRoom,"Not Ready For Advancement, missing Terminal")
break
}
}
}
else
{
console.log(currentRoom,"Not Ready For Advancement, missing Building")
break
}
}
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
{
break;
}
}
}
},
add: function(currentRoom)
{
console.log(currentRoom)
let room = Game.rooms[currentRoom]
if(Memory.rooms == null)
{
Memory.rooms = []
}
let memRooms = Memory.rooms
var newRoom = {}
newRoom.name = currentRoom
newRoom.jobs = []
//Get CenterPoint of Room for CitySquare
var xSum = 0;
var xCount = 0;
var ySum = 0;
var yCount = 0;
//Find Spawns and Put it in
newRoom.spawns = []
var newSpawn = {}
newSpawn.id = Game.spawns[currentRoom].id
newSpawn.pos = Game.spawns[currentRoom].pos
newRoom.spawns.push(newSpawn)
xSum += Game.spawns[currentRoom].pos.x
xCount++
ySum += Game.spawns[currentRoom].pos.y
yCount++
//Find Controller and Put it in
newRoom.controller = {}
newRoom.controller.id = room.controller.id
newRoom.controller.pos = room.controller.pos
//Get CenterPoint of Room for CitySquare
xSum = newRoom.controller.pos.x;
xCount++;
ySum = newRoom.controller.pos.y;
yCount++;
//Find Sources and Put them in
let roomSources = _.map(room.find(FIND_SOURCES), function(source){return {id: source.id, pos: source.pos};});
newRoom.sources = []
for(var roomSource in roomSources)
{
var newSource = {}
console.log(roomSource)
newSource.id = roomSources[roomSource].id
newSource.pos = roomSources[roomSource].pos
newSource.harvestersMax = funcHelpers.findSourceLimit(roomSources[roomSource].pos)
newRoom.sources.push(newSource)
xSum += roomSources[roomSource].pos.x
xCount++
ySum += roomSources[roomSource].pos.y
yCount++
}
newRoom.cityCenter = {}
newRoom.cityCenter.pos = {}
newRoom.cityCenter.pos.x = Math.round(xSum / xCount)
newRoom.cityCenter.pos.y = Math.round(ySum / yCount)
newRoom.cityCenter.pos.roomName = currentRoom
newRoom.config = {}
newRoom.config.minWallHits = 2500
newRoom.config.minRampartHits = 2500
newRoom.phase = 0
memRooms.push(newRoom)
console.log("Ready For Stage 1")
}
};
module.exports = loopMemoryManagement;