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

Function GetRandomUnit

examples/common/bot_examples.cc:134–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134bool GetRandomUnit(Unit& unit_out, const ObservationInterface* observation, UnitTypeID unit_type) {
135 Units my_units = observation->GetUnits(Unit::Alliance::Self);
136 std::random_shuffle(my_units.begin(), my_units.end()); // Doesn't work, or doesn't work well.
137 for (const Unit& unit : my_units) {
138 if (unit.unit_type == unit_type) {
139 unit_out = unit;
140 return true;
141 }
142 }
143 return false;
144}
145
146void MultiplayerBot::PrintStatus(std::string msg) {
147 int64_t bot_identifier = int64_t(this) & 0xFFFLL;

Callers 2

TryBuildUnitMethod · 0.85
TryBuildStructureMethod · 0.85

Calls 1

GetUnitsMethod · 0.80

Tested by

no test coverage detected