-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZergHell.cpp
597 lines (553 loc) · 21.1 KB
/
ZergHell.cpp
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
#include <BWAPI.h>
#include "ZergHell.h"
enum ClientInfoKeys {
morphingType,
buildingType,
buildX,
buildY,
firstGas,
secondGas,
thirdGas,
attackTime,
cooldown
};
void ZergHell::onFrame() {
assignIdleWorkers();
checkArmy();
checkBuildDrone();
checkBuildings();
checkScout();
checkEggs();
morphLarva();
checkEnemyBuildings();
debugDraws();
}
ZergHell::ZergHell() {
// Set the self pointer, which is used in place of always calling
// the BWAPI::Broodwar->self() function.
self = BWAPI::Broodwar->self();
// Add the start locations to the map tracking if we've scouted them or not.
for (auto& startLocation : BWAPI::Broodwar->getStartLocations()) {
if (startLocation == self->getStartLocation()) {
startLocations[startLocation] = true;
}
else {
startLocations[startLocation] = false;
}
}
defensePoint = (BWAPI::Position)self->getStartLocation();
// Group resources by their Resource ID for determining base locations.
std::map<int, std::vector<BWAPI::Unit>> resources;
// Loop through all mineral patches.
for (auto resource : BWAPI::Broodwar->getStaticMinerals()) {
// Ignore blocking minerals, we are assuming these are less than 40.
if (40 < resource->getResources()) {
resources[resource->getResourceGroup()].push_back(resource);
}
}
// Loop through all geysers.
for (auto resource : BWAPI::Broodwar->getStaticGeysers()) {
resources[resource->getResourceGroup()].push_back(resource);
}
// Figure out the Resource ID group for our start location by grabbing the closest
// mineral patch to our start location and using it's resource group ID.
auto startResource = BWAPI::Broodwar->getClosestUnit((BWAPI::Position)self->getStartLocation(), BWAPI::Filter::IsMineralField);
baseLocations[startResource->getResourceGroup()] = self->getStartLocation();
// Loop through the organized resources to calculate base locations.
for (auto& grouping : resources) {
if (armyResourceIDMax < grouping.first) {
armyResourceIDMax = grouping.first;
}
if (grouping.first != startResource->getResourceGroup()) {
BWAPI::TilePosition baseTile = { 0, 0 };
for (auto resource : grouping.second) {
baseTile += resource->getTilePosition();
}
baseTile.x /= grouping.second.size();
baseTile.y /= grouping.second.size();
baseLocations[grouping.first] = baseTile;
}
}
}
void ZergHell::assignIdleWorkers() {
// loop for idle workers and tell them to mine.
// also check if a worker needs to defend itself from attack.
for (auto& unit : BWAPI::Broodwar->self()->getUnits()) {
// ignore non-workers for this loop
if (!unit->getType().isWorker()) {
continue;
}
// ignore the scout
if (unit == scout) {
continue;
}
auto attackTime = unit->getClientInfo<int>(ClientInfoKeys::attackTime);
if (attackTime) {
attackTime--;
unit->setClientInfo<int>(attackTime, ClientInfoKeys::attackTime);
if (!attackTime) {
unit->stop();
}
}
if (unit->isUnderAttack()) {
auto enemy = unit->getClosestUnit(BWAPI::Filter::IsEnemy && !BWAPI::Filter::IsFlying);
if (enemy) {
unit->attack(enemy);
unit->setClientInfo<int>(420, ClientInfoKeys::attackTime);
}
}
else if (unit->isIdle()) {
auto resource = unit->getClosestUnit(BWAPI::Filter::IsMineralField);
if (!resource) {
continue;
}
unit->gather(resource);
}
}
}
void ZergHell::build(BWAPI::UnitType type) {
auto buildLocation = BWAPI::Broodwar->getBuildLocation(type, self->getStartLocation(), 64, true);
buildDrone = BWAPI::Broodwar->getClosestUnit((BWAPI::Position)buildLocation, (BWAPI::Filter::GetPlayer == self && BWAPI::Filter::IsWorker && BWAPI::Filter::GetRace == BWAPI::Races::Zerg && (BWAPI::Filter::IsGatheringGas || BWAPI::Filter::IsGatheringMinerals)));
if (buildDrone == scout) {
buildDrone = nullptr;
}
if (buildDrone) {
if (!buildDrone->build(type, buildLocation)) {
BWAPI::Broodwar->drawCircleMap(buildDrone->getPosition(), 10, BWAPI::Colors::Red, true);
buildDrone = nullptr;
clearBuildDroneCounter = 0;
}
else {
buildDrone->setClientInfo<int>(type, buildingType);
buildDrone->setClientInfo<int>(buildLocation.x, buildX);
buildDrone->setClientInfo<int>(buildLocation.y, buildY);
clearBuildDroneCounter = 840;
}
}
}
bool ZergHell::canAfford(BWAPI::UnitType type) {
auto race = type.getRace();
return self->supplyUsed(race) <= self->supplyTotal(race) - type.supplyRequired()
&& BWAPI::Broodwar->canMake(type)
&& type.mineralPrice() <= self->minerals()
&& type.gasPrice() <= self->gas();
}
bool ZergHell::canAfford(BWAPI::UpgradeType type) {
return type.mineralPrice() <= self->minerals()
&& type.gasPrice() <= self->gas();
}
void ZergHell::checkArmy() {
// Validate that detector is still valid.
if (detector
&& !detector->exists()) {
detector = nullptr;
}
if (attack) {
if (self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk) <= 15) {
attack = false;
return;
}
BWAPI::TilePosition target = BWAPI::TilePositions::None;
// Get closest visible enemy building.
auto enemy = BWAPI::Broodwar->getClosestUnit((BWAPI::Position)self->getStartLocation(), BWAPI::Filter::IsEnemy && BWAPI::Filter::IsBuilding);
if (!enemy) {
double closest = DBL_MAX;
// No enemy buildings are visible, check fog of war buildings.
for (auto& potentialTarget : fogOfWarBuildings) {
if (self->getStartLocation().getDistance(potentialTarget.first) < closest) {
target = potentialTarget.first;
}
}
}
else {
target = enemy->getTilePosition();
}
if (target != BWAPI::TilePositions::None) {
// Assign a detector if we do not have one.
if (!detector) {
detector = BWAPI::Broodwar->getClosestUnit((BWAPI::Position)target, BWAPI::Filter::GetType == BWAPI::UnitTypes::Zerg_Overlord && BWAPI::Filter::GetPlayer == self);
}
for (auto& unit : self->getUnits()) {
if (unit->getType() != BWAPI::UnitTypes::Zerg_Hydralisk
&& unit != detector) {
continue;
}
if (unit == detector) {
auto enemyCloaked = BWAPI::Broodwar->getClosestUnit((BWAPI::Position)target, (BWAPI::Filter::IsCloaked || BWAPI::Filter::IsBurrowed) && BWAPI::Filter::IsEnemy);
BWAPI::Unit followUnit = nullptr;
if (enemyCloaked) {
followUnit = BWAPI::Broodwar->getClosestUnit(enemyCloaked->getPosition(), BWAPI::Filter::GetType == BWAPI::UnitTypes::Zerg_Hydralisk && BWAPI::Filter::GetPlayer == self);
}
if (!followUnit) {
followUnit = BWAPI::Broodwar->getClosestUnit((BWAPI::Position)target, BWAPI::Filter::GetType == BWAPI::UnitTypes::Zerg_Hydralisk && BWAPI::Filter::GetPlayer == self);
}
if (followUnit) {
unit->move(followUnit->getPosition());
}
else {
unit->move((BWAPI::Position)defensePoint);
}
}
else {
if (unit->isIdle()) {
unit->attack((BWAPI::Position)target);
}
}
}
}
else {
auto looped = false;
while (BWAPI::Broodwar->isVisible(baseLocations[armyResourceID])) {
armyResourceID++;
if (armyResourceIDMax < armyResourceID) {
if (looped) {
break;
}
looped = true;
armyResourceID = 1;
}
}
target = baseLocations[armyResourceID];
// Assign a detector if we do not have one.
if (!detector) {
detector = BWAPI::Broodwar->getClosestUnit((BWAPI::Position)target, BWAPI::Filter::GetType == BWAPI::UnitTypes::Zerg_Overlord && BWAPI::Filter::GetPlayer == self);
}
for (auto& unit : self->getUnits()) {
if (unit->getType() != BWAPI::UnitTypes::Zerg_Hydralisk
&& unit != detector) {
continue;
}
if (unit == detector) {
unit->move((BWAPI::Position)target);
}
else if (unit->isIdle()) {
unit->attack((BWAPI::Position)target);
}
}
}
}
else if (!attack && self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk) >= 30) {
attack = true;
}
else {
// Assign a detector if we do not have one.
if (!detector) {
detector = BWAPI::Broodwar->getClosestUnit((BWAPI::Position)defensePoint, BWAPI::Filter::GetType == BWAPI::UnitTypes::Zerg_Overlord && BWAPI::Filter::GetPlayer == self);
}
// Loop units to have them attack to the defense point.
for (auto& unit : self->getUnits()) {
if (unit->getType() != BWAPI::UnitTypes::Zerg_Hydralisk
&& unit != detector) {
continue;
}
if (unit == detector) {
unit->move(defensePoint);
}
else if (unit->isIdle()) {
unit->attack(defensePoint);
}
}
}
}
void ZergHell::checkBuildDrone() {
// Check to see if a drone is already assigned to build something.
// We are limiting our building production to 1 at a time. Note that
// we could have more than one building actively morphing, but we are
// only sending one drone out at a time to build.
// If we don't have a build drone, lets see if we need to build anything.
if (!buildDrone) {
if (!self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Spawning_Pool)
&& canAfford(BWAPI::UnitTypes::Zerg_Spawning_Pool)) {
build(BWAPI::UnitTypes::Zerg_Spawning_Pool);
}
else if (self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Spawning_Pool)
&& self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Creep_Colony) + self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Sunken_Colony) < 4
&& canAfford(BWAPI::UnitTypes::Zerg_Creep_Colony)) {
build(BWAPI::UnitTypes::Zerg_Creep_Colony);
}
else if (self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Spawning_Pool)
&& self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Creep_Colony) + self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Sunken_Colony) >= 4
&& self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Extractor) < 1
&& canAfford(BWAPI::UnitTypes::Zerg_Extractor)) {
build(BWAPI::UnitTypes::Zerg_Extractor);
}
else if (self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Extractor)
&& self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk_Den) < 1
&& canAfford(BWAPI::UnitTypes::Zerg_Hydralisk_Den)) {
build(BWAPI::UnitTypes::Zerg_Hydralisk_Den);
}
else if (self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Hatchery) + self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Lair) < 5
&& canAfford(BWAPI::UnitTypes::Zerg_Hatchery)) {
build(BWAPI::UnitTypes::Zerg_Hatchery);
}
}
// We have a build drone, lets see if we need to do something with it or unassign it.
else {
if (clearBuildDroneCounter)
clearBuildDroneCounter--;
if (buildDrone->getType() != BWAPI::UnitTypes::Zerg_Drone
|| buildDrone->isIdle()
|| buildDrone->getOrder() == BWAPI::Orders::IncompleteBuilding
|| !buildDrone->exists()) {
clearBuildDroneCounter = 0;
}
if (!clearBuildDroneCounter) {
if (buildDrone->getType() == BWAPI::UnitTypes::Zerg_Drone) {
buildDrone->stop();
buildDrone = nullptr;
clearBuildDroneCounter = 0;
}
}
//else if (buildDrone->isGatheringMinerals() || buildDrone->isGatheringGas()) {
//if (!buildDrone->build(buildDrone->getClientInfo<int>(buildingType), BWAPI::TilePosition{ buildDrone->getClientInfo<int>(buildX), buildDrone->getClientInfo<int>(buildY) })) {
// buildDrone = nullptr;
//}
//}
}
}
void ZergHell::checkBuildings() {
// Loop for buildings.
double closestDistance = DBL_MAX;
for (auto& unit : self->getUnits()) {
if (!unit->getType().isBuilding()) {
continue;
}
// Calculate closest of my buildings to enemy buildings, so I can set the defense point
// later.
for (auto& enemyBuilding : fogOfWarBuildings) {
auto thisDistance = unit->getDistance((BWAPI::Position)enemyBuilding.first);
if ( thisDistance < closestDistance) {
closestDistance = thisDistance;
defensePoint = unit->getPosition();
}
}
for (auto& enemyUnit : BWAPI::Broodwar->getAllUnits()) {
// Ignore non-enemy units.
if (!self->isEnemy(enemyUnit->getPlayer())) {
continue;
}
auto thisDistance = unit->getDistance(enemyUnit->getPosition());
if (thisDistance < closestDistance) {
closestDistance = thisDistance;
defensePoint = unit->getPosition();
}
}
// lower cooldown if we need to
if (unit->getClientInfo<int>(ClientInfoKeys::cooldown)) {
auto cooldown = unit->getClientInfo<int>(ClientInfoKeys::cooldown);
cooldown--;
unit->setClientInfo<int>(cooldown, ClientInfoKeys::cooldown);
}
if (unit->getType() == BWAPI::UnitTypes::Zerg_Extractor) {
auto gasWorker = unit->getClientInfo<BWAPI::Unit>(firstGas);
if (!gasWorker) {
// Check first worker
auto worker = unit->getClosestUnit(BWAPI::Filter::IsWorker && BWAPI::Filter::GetPlayer == self && BWAPI::Filter::IsGatheringMinerals);
if (worker
&& worker != unit->getClientInfo<BWAPI::Unit>(secondGas)
&& worker != unit->getClientInfo<BWAPI::Unit>(thirdGas)) {
unit->setClientInfo<BWAPI::Unit>(worker, firstGas);
}
}
else if (!gasWorker->exists()
|| gasWorker == buildDrone) {
unit->setClientInfo<BWAPI::Unit>(nullptr, firstGas);
}
else if (gasWorker->isIdle() || gasWorker->isGatheringMinerals()) {
gasWorker->gather(unit);
}
gasWorker = unit->getClientInfo<BWAPI::Unit>(secondGas);
if (!gasWorker) {
// Check second worker
auto worker = unit->getClosestUnit(BWAPI::Filter::IsWorker && BWAPI::Filter::GetPlayer == self && BWAPI::Filter::IsGatheringMinerals);
if (worker
&& worker != unit->getClientInfo<BWAPI::Unit>(firstGas)
&& worker != unit->getClientInfo<BWAPI::Unit>(thirdGas)) {
unit->setClientInfo<BWAPI::Unit>(worker, secondGas);
}
}
else if (!gasWorker->exists()
|| gasWorker == buildDrone) {
unit->setClientInfo<BWAPI::Unit>(nullptr, secondGas);
}
else if (gasWorker->isIdle() || gasWorker->isGatheringMinerals()) {
gasWorker->gather(unit);
}
gasWorker = unit->getClientInfo<BWAPI::Unit>(thirdGas);
if (!gasWorker) {
// Check third worker
auto worker = unit->getClosestUnit(BWAPI::Filter::IsWorker && BWAPI::Filter::GetPlayer == self && BWAPI::Filter::IsGatheringMinerals);
if (worker
&& worker != unit->getClientInfo<BWAPI::Unit>(secondGas)
&& worker != unit->getClientInfo<BWAPI::Unit>(firstGas)) {
unit->setClientInfo<BWAPI::Unit>(worker, thirdGas);
}
}
else if (!gasWorker->exists()
|| gasWorker == buildDrone) {
unit->setClientInfo<BWAPI::Unit>(nullptr, thirdGas);
}
else if (gasWorker->isIdle() || gasWorker->isGatheringMinerals()) {
gasWorker->gather(unit);
}
}
else if (unit->getType() == BWAPI::UnitTypes::Zerg_Creep_Colony) {
if (canAfford(BWAPI::UnitTypes::Zerg_Sunken_Colony)) {
unit->morph(BWAPI::UnitTypes::Zerg_Sunken_Colony);
}
}
else if (unit->getType() == BWAPI::UnitTypes::Zerg_Hydralisk_Den) {
if (!self->getUpgradeLevel(BWAPI::UpgradeTypes::Muscular_Augments)
&& canAfford(BWAPI::UpgradeTypes::Muscular_Augments)) {
unit->upgrade(BWAPI::UpgradeTypes::Muscular_Augments);
}
else if (!self->getUpgradeLevel(BWAPI::UpgradeTypes::Grooved_Spines)
&& canAfford(BWAPI::UpgradeTypes::Grooved_Spines)) {
unit->upgrade(BWAPI::UpgradeTypes::Grooved_Spines);
}
}
else if (unit->getType() == BWAPI::UnitTypes::Zerg_Hatchery) {
if (self->completedUnitCount(BWAPI::UnitTypes::Zerg_Spawning_Pool)
&& !self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Lair)
&& 2 < self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Hatchery)
&& canAfford(BWAPI::UnitTypes::Zerg_Lair)) {
unit->morph(BWAPI::UnitTypes::Zerg_Lair);
}
// find a worker for defense if our hatchery is under attack and we have no Hydralisks, trying to keep starting buildings from dying or taking
// heavy damage from enemy scouts/workers.
if (unit->isUnderAttack()
&& !self->completedUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk)
&& !unit->getClientInfo<int>(ClientInfoKeys::cooldown)) {
unit->setClientInfo<int>(420, ClientInfoKeys::cooldown);
auto closestWorker = unit->getClosestUnit(BWAPI::Filter::IsWorker && BWAPI::Filter::GetPlayer == self && BWAPI::Filter::IsGatheringMinerals);
if (closestWorker) {
auto enemy = unit->getClosestUnit(BWAPI::Filter::IsEnemy && !BWAPI::Filter::IsFlying);
if (enemy) {
closestWorker->attack(enemy);
closestWorker->setClientInfo<int>(420, ClientInfoKeys::attackTime);
}
}
}
}
else if (unit->getType() == BWAPI::UnitTypes::Zerg_Lair) {
if (canAfford(BWAPI::UpgradeTypes::Pneumatized_Carapace)) {
unit->upgrade(BWAPI::UpgradeTypes::Pneumatized_Carapace);
}
}
}
}
void ZergHell::checkEggs() {
// Loop for eggs and set some client data regarding them, as some
// information is lost on the final frame they morph.
for (auto& unit : self->getUnits()) {
// Ignore non-eggs
if (unit->getType() != BWAPI::UnitTypes::Zerg_Egg) {
continue;
}
if (unit->getBuildType() != BWAPI::UnitTypes::None) {
unit->setClientInfo<int>(unit->getBuildType(), morphingType);
}
}
}
void ZergHell::checkEnemyBuildings() {
// Loop through our fog of war tracker to see if tiles are visible.
// If they are visible, we will clear them from the tracker, as
// they will get added again down below.
auto itr = fogOfWarBuildings.begin();
while (itr != fogOfWarBuildings.end()) {
if (BWAPI::Broodwar->isVisible(itr->first)) {
itr = fogOfWarBuildings.erase(itr);
}
else {
itr++;
}
}
// Loop through enemy buildings and store their position in fogOfWarBuildings
for (auto& unit : BWAPI::Broodwar->getAllUnits()) {
// Ignore non-enemies and non-buildings
if (!unit->getPlayer()->isEnemy(self) || !unit->getType().isBuilding())
continue;
fogOfWarBuildings[unit->getTilePosition()] = unit->getType();
}
}
void ZergHell::checkScout() {
// Check if we have a scout already.
if (!scout) {
// We don't have a scout, do we need a scout? Let's scout at 11 drones.
if (self->visibleUnitCount(BWAPI::UnitTypes::Zerg_Drone) >= 11) {
// Assign a scout.
for (auto& location : startLocations) {
if (!location.second) {
scout = BWAPI::Broodwar->getClosestUnit((BWAPI::Position)location.first, BWAPI::Filter::GetPlayer == self && BWAPI::Filter::IsWorker);
if (scout == buildDrone) {
scout = nullptr;
}
break;
}
}
}
}
else if (scout->exists()) {
for (auto& location : startLocations) {
if (!location.second) {
if (scout->getDistance((BWAPI::Position)location.first) <= 400) {
location.second = true;
return;
}
else {
scout->move((BWAPI::Position)location.first);
return;
}
}
}
scout->move((BWAPI::Position)self->getStartLocation());
scout = nullptr;
}
}
void ZergHell::debugDraws() {
if (buildDrone) {
BWAPI::Broodwar->drawCircleMap(buildDrone->getPosition(), 10, BWAPI::Colors::Green, false);
}
}
void ZergHell::morphLarva() {
// Loop for larva and check conditions for morphing.
for (auto& unit : BWAPI::Broodwar->self()->getUnits()) {
// Ignore non-larva.
if (unit->getType() != BWAPI::UnitTypes::Zerg_Larva) {
continue;
}
// If we need supply and can afford the overlord, make an Overlord.
if (needSupply()
&& canAfford(BWAPI::UnitTypes::Zerg_Overlord)) {
unit->morph(BWAPI::UnitTypes::Zerg_Overlord);
}
// If less than 20 drones, morph a drone. Will need to revise this later
// to be more sophisticated.
else if (self->completedUnitCount(BWAPI::UnitTypes::Zerg_Drone) < 20
&& canAfford(BWAPI::UnitTypes::Zerg_Drone)) {
unit->morph(BWAPI::UnitTypes::Zerg_Drone);
}
// If we can make and affor a Hydralisk, make it.
else if (canAfford(BWAPI::UnitTypes::Zerg_Hydralisk)) {
unit->morph(BWAPI::UnitTypes::Zerg_Hydralisk);
}
}
}
bool ZergHell::needSupply() {
// Verify if we need a supply provider.
// Loop for eggs and overlords, and manually count the expected
// supply total. Dealing with Overlords as they hatch is annoying.
int supplyTotal = 0;
for (auto& unit : BWAPI::Broodwar->self()->getUnits()) {
// Ignore non-eggs and non-Overlords.
if (unit->getType() != BWAPI::UnitTypes::Zerg_Egg
&& unit->getType() != BWAPI::UnitTypes::Zerg_Overlord) {
continue;
}
if (unit->getClientInfo<int>(morphingType) == BWAPI::UnitTypes::Zerg_Overlord
|| unit->getType() == BWAPI::UnitTypes::Zerg_Overlord) {
supplyTotal += BWAPI::UnitTypes::Zerg_Overlord.supplyProvided();
}
}
return self->supplyUsed() >= supplyTotal - 4;
}