-
Notifications
You must be signed in to change notification settings - Fork 4
/
AssignJobs.js
646 lines (635 loc) · 37.3 KB
/
AssignJobs.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
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
let Util = require('Util');
const AssignJobs = {
run: function () {
// assign jobs to creeps or create the creeps like this:
// look for idle creep with correct type in room
// if failed then create that creep in room
// if that failed and there are no spawns present then create it in the closest room with enough energy at its disposal
// different creep types for different jobs
/*creep types:
* [H] harvester only one CARRY
* [T] transporter no WORK
* [B] builder equal WORK and CARRY
* [E] extractor only one CARRY and maxed out WORK
* [S] scout just a MOVE
* [C] claimer CLAIM - one CLAIM
* [R] reserver CLAIM - many CLAIM when reserving
* [W] warrior ATTACK and MOVE
* [G] gunner RANGED_ATTACK and MOVE - needs clever attack pattern to avoid creeps with ATTACK body parts
* [M] medic HEAL
* [D] distantHarvester equal WORK and MOVE
*/
AssignOrSpawnCreeps();
// loop through vacant jobs per room and see if an idle creep could be assigned or a new creep should be spawned
function AssignOrSpawnCreeps() {
const idleCreeps = _.filter(Game.creeps, function (creep) {
if (creep.memory.JobName) {
return creep.memory.JobName.startsWith('idle');
} else {
return false;
}
});
const availableSpawns = _.filter(Game.spawns, function (spawn) {
return spawn.spawning === null && spawn.room.energyAvailable >= Util.MINIMUM_ENERGY_REQUIRED;
});
for (const memRoomKey in Memory.MemRooms) {
const memRoom = Memory.MemRooms[memRoomKey];
if (!memRoom) {
continue;
}
for (const roomJobKey in memRoom.RoomJobs) {
const roomJob = memRoom.RoomJobs[roomJobKey];
if (roomJob && roomJob.Creep === 'vacant') {
let creepFound = AssignCreep(roomJob, idleCreeps, roomJobKey, memRoomKey); // first try and assign a creep from the room the job is in
if (!creepFound) {
creepFound = AssignCreepOtherRoom(roomJob, idleCreeps, roomJobKey, memRoomKey); // then see if there are nearby idle creep in other room
if (!creepFound) {
creepFound = SpawnCreep(roomJob, availableSpawns, roomJobKey, memRoomKey);
}
}
}
}
}
}
/**@return {boolean}*/
function AssignCreep(roomJob, idleCreeps, roomJobKey, memRoomKey) {
for (const idleCreepCounter in idleCreeps) {
const idleCreep = idleCreeps[idleCreepCounter];
if (idleCreep.pos.roomName === memRoomKey && idleCreep.name.startsWith(roomJob.CreepType)) {
// idle creep is in memory room with vacant job and matching job type
idleCreep.memory.JobName = roomJobKey;
for (const memoryElementKey in idleCreep.memory) {
if (memoryElementKey !== 'JobName' && memoryElementKey !== 'Boost' ) { // creep.memory that should not be deleted
idleCreep.memory[memoryElementKey] = undefined;
}
}
roomJob.Creep = idleCreep.name;
//Util.Info('AssignJobs', 'AssignCreeps', idleCreep.name + ' assigned to ' + roomJobKey + ' in ' + memRoomKey);
delete idleCreeps[idleCreepCounter];
return true;
}
}
return false;
}
/**@return {boolean}*/
function AssignCreepOtherRoom(roomJob, idleCreeps, roomJobKey, memRoomKey) {
if (roomJob.JobType === Util.FLAG_JOB
&& (Game.rooms[memRoomKey] && Game.rooms[memRoomKey].controller && Game.rooms[memRoomKey].controller.my && Game.rooms[memRoomKey].controller.level < 8
|| !Game.rooms[memRoomKey]
|| !Game.rooms[memRoomKey].controller
|| !Game.rooms[memRoomKey].controller.my)) {
// loop through all creeps of desired creepType and assign the nearest one to the job
let nearestCreep;
let bestRange = Number.MAX_SAFE_INTEGER;
let bestIdleCreepCounter;
for (const idleCreepCounter in idleCreeps) {
const idleCreep = idleCreeps[idleCreepCounter];
if (idleCreep.name.startsWith(roomJob.CreepType)) {
const linearDistance = Game.map.getRoomLinearDistance(memRoomKey, idleCreep.pos.roomName);
if (bestRange > linearDistance) {
bestRange = linearDistance;
nearestCreep = idleCreep;
bestIdleCreepCounter = idleCreepCounter;
}
}
}
if (nearestCreep) {
nearestCreep.memory.JobName = roomJobKey;
roomJob.Creep = nearestCreep.name;
delete idleCreeps[bestIdleCreepCounter];
return true;
}
}
return false; // for now, do not assign creeps of type OBJECT_JOB to other rooms
}
/**@return {boolean}*/
function SpawnCreep(roomJob, availableSpawns, roomJobKey, memRoomKey) {
// if idle creep not found for vacant job then look if spawn is possible
if (ShouldSpawnCreep(roomJob.CreepType, memRoomKey)) {
const availableName = GetAvailableName(roomJob.CreepType);
let bestLinearDistance = 1; // normally creeps should only be spawned in the room they are needed
let spawnLargeVersion = false;
// job in another room
if (Game.rooms[memRoomKey]) { // job in invisible room
const gameRoom = Game.rooms[memRoomKey];
if (gameRoom.controller) { // flag in controller-less room
if (gameRoom.controller.my) { // only use my room
if (gameRoom.find(FIND_MY_SPAWNS).length === 0) { // no spawn in my room
Util.Info('AssignJobs', 'SpawnCreep', 'job in another room, no spawns ' + roomJobKey);
bestLinearDistance = Number.MAX_SAFE_INTEGER;
} else if (roomJob.CreepType === 'H' && gameRoom.storage) { // logic only relevant for harvester
const source = gameRoom.find(FIND_SOURCES)[0];
for (const effectKey in source.effects) {
if (source.effects[effectKey].effect === PWR_REGEN_SOURCE) {
Util.Info('AssignJobs', 'SpawnCreep', 'Harvester spawning uses large version because of PWR_REGEN_SOURCE ' + source.effects[effectKey].effect + ' ' + memRoomKey);
spawnLargeVersion = true;
break;
}
}
} else if (roomJob.CreepType === 'B' && roomJobKey.startsWith('Ctrl') && gameRoom.storage && gameRoom.storage.store.getUsedCapacity(RESOURCE_ENERGY) > Util.STORAGE_ENERGY_MEDIUM/*large builders are only allowed when the room has the required energy - the drawback is that upgrade controller takes alot of energy*/) {
spawnLargeVersion = true;
}
} else {
Util.Info('AssignJobs', 'SpawnCreep', 'job in another room, not my room ' + roomJobKey);
bestLinearDistance = Number.MAX_SAFE_INTEGER;
}
} else {
Util.Info('AssignJobs', 'SpawnCreep', 'job in another room, no controller ' + roomJobKey);
bestLinearDistance = Number.MAX_SAFE_INTEGER;
}
} else {
Util.Info('AssignJobs', 'SpawnCreep', 'job in another room, invisible room ' + roomJobKey);
bestLinearDistance = Number.MAX_SAFE_INTEGER;
}
let bestAvailableSpawn;
let bestAvailableSpawnCounter;
for (const availableSpawnCounter in availableSpawns) { // find closest spawn
const availableSpawn = availableSpawns[availableSpawnCounter];
const linearDistance = Game.map.getRoomLinearDistance(availableSpawn.pos.roomName, memRoomKey);
let energyAvailableModifier = 0;
if (roomJob.JobType === Util.FLAG_JOB) { // on flag jobs one wants to share the load between rooms with more energy
switch (true) {
case !availableSpawn.room.storage || availableSpawn.room.storage.store.getUsedCapacity(RESOURCE_ENERGY) < Util.STORAGE_ENERGY_MEDIUM: // do not spawn for a flag job when the storage has under STORAGE_ENERGY_MEDIUM
energyAvailableModifier = Number.MAX_SAFE_INTEGER;
break;
case availableSpawn.room.energyAvailable < 500:
energyAvailableModifier = -1;
break;
case availableSpawn.room.energyAvailable < 1000:
energyAvailableModifier = -2;
break;
case availableSpawn.room.energyAvailable < 2000:
energyAvailableModifier = -3;
break;
case availableSpawn.room.energyAvailable < 3000:
energyAvailableModifier = -4;
break;
case availableSpawn.room.energyAvailable < 4000:
energyAvailableModifier = -5;
break;
case availableSpawn.room.energyAvailable < 5000:
energyAvailableModifier = -6;
break;
case availableSpawn.room.energyAvailable < 6000:
energyAvailableModifier = -7;
break;
case availableSpawn.room.energyAvailable < 7000:
energyAvailableModifier = -8;
break;
case availableSpawn.room.energyAvailable < 8000:
energyAvailableModifier = -9;
break;
case availableSpawn.room.energyAvailable < 9000:
energyAvailableModifier = -10;
break;
case availableSpawn.room.energyAvailable < 10000:
energyAvailableModifier = -11;
break;
case availableSpawn.room.energyAvailable > 10000:
energyAvailableModifier = -12;
break;
}
}
if ((energyAvailableModifier + linearDistance) < bestLinearDistance && energyAvailableModifier !== Number.MAX_SAFE_INTEGER) {
bestLinearDistance = energyAvailableModifier + linearDistance;
bestAvailableSpawn = availableSpawn;
bestAvailableSpawnCounter = availableSpawnCounter;
}
// get on with it if a spawn in room is found or if the primary room is found
if (bestLinearDistance === 0) {
break;
}
}
if (bestAvailableSpawn) { // the closest spawn is found
const spawnResult = bestAvailableSpawn.spawnCreep(GetCreepBody(roomJob.CreepType, Game.rooms[bestAvailableSpawn.pos.roomName].energyAvailable, spawnLargeVersion), availableName);
if (spawnResult === OK) {
Game.creeps[availableName].memory.JobName = roomJobKey;
roomJob.Creep = availableName;
if (Memory.MemRooms[memRoomKey].MaxCreeps[availableName.substring(0, 1)]) {
Memory.MemRooms[memRoomKey].MaxCreeps[availableName.substring(0, 1)][availableName] = availableName;
}
Util.Info('AssignJobs', 'SpawnCreep', 'OK ' + availableName + ' assigned to ' + roomJobKey + ' in ' + memRoomKey + ' spawn ' + bestAvailableSpawn.name);
delete availableSpawns[bestAvailableSpawnCounter];
return true;
} else {
Util.Info('AssignJobs', 'SpawnCreep', 'failed ' + availableName + ' assigned to ' + roomJobKey + ' in ' + memRoomKey + ' spawnResult ' + spawnResult + ' spawn ' + bestAvailableSpawn.name + ' room energy: ' + Game.rooms[bestAvailableSpawn.pos.roomName].energyAvailable);
return false;
}
}
}
}
/**@return {boolean}*/
function ShouldSpawnCreep(creepType, roomKey) {
const memRoom = Memory.MemRooms[roomKey];
let maxCreepsInRoom = 3;
if (memRoom.MaxCreeps[creepType] && memRoom.MaxCreeps[creepType].M) {
maxCreepsInRoom = memRoom.MaxCreeps[creepType].M;
} else { // this code should only run when a reset happens
switch (creepType) {
case 'T': // transporter
if (memRoom.SourceNumber === 0) {
maxCreepsInRoom = 4;
} else {
maxCreepsInRoom = memRoom.SourceNumber;
}
break;
case 'H': // harvester
if (memRoom.SourceNumber === 0) {
maxCreepsInRoom = 3;
} else {
maxCreepsInRoom = memRoom.SourceNumber;
}
if (memRoom.RoomLevel < 3) {
maxCreepsInRoom += memRoom.SourceNumber;
}
break;
case 'B': // builder
maxCreepsInRoom = 2;
if (memRoom.RoomLevel < 8) {
maxCreepsInRoom += 1;
if (memRoom.RoomLevel < 3) {
maxCreepsInRoom += 1;
}
}
break;
case 'E': // extractor
maxCreepsInRoom = 1;
break;
case 'W': // warrior
case 'G': // gunner
case 'M': // medic
case 'S': // scout
if (!Game.rooms[roomKey] || !Game.rooms[roomKey].controller || Game.rooms[roomKey].controller.level <= 6) {
maxCreepsInRoom = 3;
} else {
maxCreepsInRoom = 0;
}
break;
case 'C': // claimer
case 'R': // reserver
if (!Game.rooms[roomKey] || Game.rooms[roomKey].controller && Game.rooms[roomKey].controller.level === 0) {
maxCreepsInRoom = 1;
} else {
maxCreepsInRoom = 0;
}
break;
case 'D': // distantHarvester
if (!Game.rooms[roomKey] || !Game.rooms[roomKey].controller || Game.rooms[roomKey].controller && Game.rooms[roomKey].controller.level === 0) {
maxCreepsInRoom = 6;
} else {
maxCreepsInRoom = 0;
}
break;
default:
Util.ErrorLog('AssignJobs', 'ShouldSpawnCreep', 'creep type not found ' + creepType);
}
if(!memRoom.MaxCreeps[creepType]){
memRoom.MaxCreeps[creepType] = {};
}
memRoom.MaxCreeps[creepType]['M'] = maxCreepsInRoom;
}
return (Object.keys(memRoom.MaxCreeps[creepType]).length - 1) < maxCreepsInRoom;
}
/**@return {array}*/
function GetCreepBody(creepType, energyAvailable, spawnLargeVersion) {
let body = [];
switch (creepType) {
// harvester
case 'H':
switch (true) {
case (energyAvailable >= 2300 && spawnLargeVersion):
body = [
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
CARRY, CARRY,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE
];
break;
case (energyAvailable >= 800): // energyCapacityAvailable: 12900, 5600, 2300, 1800, 1300
body = [WORK, WORK, WORK, WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 450): // energyCapacityAvailable: 550
body = [WORK, WORK, WORK, CARRY, MOVE, MOVE];
break;
case (energyAvailable >= 200): // energyCapacityAvailable: 300
body = [WORK, CARRY, MOVE];
break;
}
break;
// transporter
case 'T':
switch (true) {
case (energyAvailable >= 1500): // energyCapacityAvailable: 12900
body = [
CARRY, CARRY, CARRY, CARRY, CARRY,
CARRY, CARRY, CARRY, CARRY, CARRY,
CARRY, CARRY, CARRY, CARRY, CARRY,
CARRY, CARRY, CARRY, CARRY, CARRY,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE
];
break;
case (energyAvailable >= 1200): // energyCapacityAvailable: 5600
body = [CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 1050): // energyCapacityAvailable: 2300
body = [CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 900): // energyCapacityAvailable: 1800
body = [CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 600): // energyCapacityAvailable: 1300
body = [CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 300): // energyCapacityAvailable: 550
body = [CARRY, CARRY, CARRY, CARRY, MOVE, MOVE];
break;
case (energyAvailable >= 150): // energyCapacityAvailable: 300
body = [CARRY, CARRY, MOVE];
break;
}
break;
// builder
case 'B':
switch (true) {
case (energyAvailable >= 3250 && spawnLargeVersion): // energyCapacityAvailable: 12900
body = [
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
CARRY, CARRY, CARRY, CARRY, CARRY,
CARRY, CARRY, CARRY, CARRY, CARRY,
CARRY, CARRY, CARRY, CARRY, CARRY,
CARRY, CARRY,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 2000): // energyCapacityAvailable: 5600
body = [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 1800): // energyCapacityAvailable: 2300
body = [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 1400): // energyCapacityAvailable: 1800
body = [WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 1000): // energyCapacityAvailable: 1300
body = [WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 400): // energyCapacityAvailable: 550
body = [WORK, WORK, CARRY, CARRY, MOVE, MOVE];
break;
case (energyAvailable >= 200): // energyCapacityAvailable: 300
body = [WORK, CARRY, MOVE];
break;
}
break;
// extractor
case 'E':
switch (true) {
case (energyAvailable >= 2200): // energyCapacityAvailable: 12900
body = [WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 2050): // energyCapacityAvailable: 5600
body = [WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 1800): // energyCapacityAvailable: 2300
body = [WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 1300): // energyCapacityAvailable: 1800
body = [WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 800): // energyCapacityAvailable: 1300
body = [WORK, WORK, WORK, WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE];
break;
}
break;
// scout
case 'S':
body = [MOVE];
break;
// claimer
case 'C':
switch (true) {
case (energyAvailable >= 850): // energyCapacityAvailable: 1800
body = [MOVE, MOVE, MOVE, MOVE, MOVE, CLAIM];
break;
case (energyAvailable >= 650): // energyCapacityAvailable: 1300
body = [MOVE, CLAIM];
break;
}
break;
// reserver
case 'R':
switch (true) {
case (energyAvailable >= 2050): // energyCapacityAvailable: 5600
body = [MOVE, MOVE, MOVE, CLAIM, CLAIM, CLAIM];
break;
case (energyAvailable >= 1800): // energyCapacityAvailable: 2300
body = [MOVE, MOVE, CLAIM, CLAIM];
break;
case (energyAvailable >= 1300): // energyCapacityAvailable: 1800
body = [MOVE, MOVE, CLAIM, CLAIM];
break;
case (energyAvailable >= 800): // energyCapacityAvailable: 1300
body = [MOVE, CLAIM];
break;
}
break;
// warrior
case 'W':
switch (true) {
case (energyAvailable >= 2600): // energyCapacityAvailable: 12900
body = [
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
ATTACK, ATTACK, ATTACK, ATTACK, ATTACK,
ATTACK, ATTACK, ATTACK, ATTACK, ATTACK,
ATTACK, ATTACK, ATTACK, ATTACK, ATTACK,
ATTACK, ATTACK, ATTACK, ATTACK, ATTACK
];
break;
case (energyAvailable >= 2340): // energyCapacityAvailable: 5600
body = [
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE,
ATTACK, ATTACK, ATTACK, ATTACK, ATTACK,
ATTACK, ATTACK, ATTACK, ATTACK, ATTACK,
ATTACK, ATTACK, ATTACK, ATTACK, ATTACK,
ATTACK, ATTACK, ATTACK
];
break;
case (energyAvailable >= 2080): // energyCapacityAvailable: 2300
body = [
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE,
ATTACK, ATTACK, ATTACK, ATTACK, ATTACK,
ATTACK, ATTACK, ATTACK, ATTACK, ATTACK,
ATTACK, ATTACK, ATTACK, ATTACK, ATTACK,
ATTACK
];
break;
case (energyAvailable >= 1690): // energyCapacityAvailable: 1800
body = [
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE,
ATTACK, ATTACK, ATTACK, ATTACK, ATTACK,
ATTACK, ATTACK, ATTACK, ATTACK, ATTACK,
ATTACK, ATTACK, ATTACK
];
break;
case (energyAvailable >= 1300): // energyCapacityAvailable: 1300
body = [MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK];
break;
case (energyAvailable >= 520): // energyCapacityAvailable: 550
body = [MOVE, MOVE, MOVE, MOVE, ATTACK, ATTACK, ATTACK, ATTACK];
break;
case (energyAvailable >= 260): // energyCapacityAvailable: 300
body = [MOVE, MOVE, ATTACK, ATTACK];
break;
}
break;
// gunner
case 'G':
switch (true) {
case (energyAvailable >= 5000): // energyCapacityAvailable: 12900
body = [
RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK,
RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK,
RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK,
RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK,
RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE, RANGED_ATTACK];
break;
case (energyAvailable >= 3000): // energyCapacityAvailable: 5600
body = [RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK,
MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, RANGED_ATTACK];
break;
case (energyAvailable >= 2000): // energyCapacityAvailable: 2300
body = [RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK,
MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, RANGED_ATTACK];
break;
case (energyAvailable >= 1400): // energyCapacityAvailable: 1800
body = [RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, RANGED_ATTACK];
break;
case (energyAvailable >= 1000): // energyCapacityAvailable: 1300
body = [RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, RANGED_ATTACK, MOVE, MOVE, MOVE, MOVE, MOVE, RANGED_ATTACK];
break;
case (energyAvailable >= 400): // energyCapacityAvailable: 550
body = [RANGED_ATTACK, MOVE, MOVE, RANGED_ATTACK];
break;
case (energyAvailable >= 200): // energyCapacityAvailable: 300
body = [MOVE, RANGED_ATTACK];
break;
}
break;
// medic
case 'M':
switch (true) {
case (energyAvailable >= 7500): // energyCapacityAvailable: 12900
body = [
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
HEAL, HEAL, HEAL, HEAL, HEAL,
HEAL, HEAL, HEAL, HEAL, HEAL,
HEAL, HEAL, HEAL, HEAL, HEAL,
HEAL, HEAL, HEAL, HEAL, HEAL,
HEAL, HEAL, HEAL, HEAL, HEAL];
break;
case (energyAvailable >= 4800): // energyCapacityAvailable: 5600
body = [HEAL, HEAL, HEAL, HEAL, HEAL, HEAL, HEAL, HEAL, HEAL, HEAL, HEAL, HEAL, HEAL, HEAL, HEAL,
MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, HEAL];
break;
case (energyAvailable >= 2100): // energyCapacityAvailable: 2300
body = [HEAL, HEAL, HEAL, HEAL, HEAL, HEAL, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, HEAL];
break;
case (energyAvailable >= 1500): // energyCapacityAvailable: 1800
body = [HEAL, HEAL, HEAL, HEAL, MOVE, MOVE, MOVE, MOVE, MOVE, HEAL];
break;
case (energyAvailable >= 1200): // energyCapacityAvailable: 1300
body = [HEAL, HEAL, HEAL, MOVE, MOVE, MOVE, MOVE, HEAL];
break;
case (energyAvailable >= 480): // energyCapacityAvailable: 550
body = [TOUGH, TOUGH, TOUGH, MOVE, MOVE, MOVE, MOVE, HEAL];
break;
case (energyAvailable >= 300): // energyCapacityAvailable: 300
body = [MOVE, HEAL];
break;
}
break;
// distant harvester
case 'D':
switch (true) {
case (energyAvailable >= 3500): // energyCapacityAvailable: 12900
body = [
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
WORK, WORK, WORK, WORK, WORK,
CARRY, CARRY, CARRY, CARRY, CARRY,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE
];
break;
case (energyAvailable >= 1250): // energyCapacityAvailable: 5600
body = [WORK, WORK, WORK, WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 1000): // energyCapacityAvailable: 2300
body = [WORK, WORK, WORK, WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 750): // energyCapacityAvailable: 1800
body = [WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 500): // energyCapacityAvailable: 1300
body = [WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE];
break;
case (energyAvailable >= 300): // energyCapacityAvailable: 550
body = [WORK, CARRY, MOVE];
break;
case (energyAvailable >= 200): // energyCapacityAvailable: 300
body = [WORK, CARRY, MOVE];
break;
}
break;
default:
Util.ErrorLog('AssignJobs', 'GetCreepBody', 'creep type not found' + creepType);
}
return body;
}
/**@return {string}*/
function GetAvailableName(creepType) {
let availableCount = 1;
while (true) {
if (Memory.creeps[creepType + availableCount]) {
availableCount++;
} else {
break; // name is free
}
}
return creepType + availableCount;
}
}
};
module.exports = AssignJobs;