MCPcopy Create free account
hub / github.com/Blizzard/s2client-api / TryBuildUnit

Method TryBuildUnit

examples/common/bot_examples.cc:445–466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

443}
444
445bool MultiplayerBot::TryBuildUnit(AbilityID ability_type_for_unit, UnitTypeID unit_type) {
446 const ObservationInterface* observation = Observation();
447
448 //If we are at supply cap, don't build anymore units, unless its an overlord.
449 if (observation->GetFoodUsed() >= observation->GetFoodCap() && ability_type_for_unit != ABILITY_ID::TRAIN_OVERLORD) {
450 return false;
451 }
452 Unit unit;
453 if (!GetRandomUnit(unit, observation, unit_type)) {
454 return false;
455 }
456 if (!unit.orders.empty()) {
457 return false;
458 }
459
460 if (unit.build_progress != 1) {
461 return false;
462 }
463
464 Actions()->UnitCommand(unit.tag, ability_type_for_unit);
465 return true;
466}
467
468// Mine the nearest mineral to Town hall.
469// If we don't do this, probes may mine from other patches if they stray too far from the base after building.

Callers

nothing calls this directly

Calls 5

ObservationClass · 0.85
GetRandomUnitFunction · 0.85
GetFoodUsedMethod · 0.80
GetFoodCapMethod · 0.80
UnitCommandMethod · 0.80

Tested by

no test coverage detected