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

Method TryBuildStructure

examples/common/bot_examples.cc:318–358  ·  view source on GitHub ↗

Try build structure given a location. This is used most of the time

Source from the content-addressed store, hash-verified

316
317//Try build structure given a location. This is used most of the time
318bool MultiplayerBot::TryBuildStructure(AbilityID ability_type_for_structure, UnitTypeID unit_type, Point2D location, bool isExpansion = false) {
319
320 const ObservationInterface* observation = Observation();
321 Units workers = observation->GetUnits(Unit::Alliance::Self, IsUnit(unit_type));
322
323 //if we have no workers Don't build
324 if (workers.empty()) {
325 return false;
326 }
327
328 // Check to see if there is already a worker heading out to build it
329 for (const auto& worker : workers) {
330 for (const auto& order : worker.orders) {
331 if (order.ability_id == ability_type_for_structure) {
332 return false;
333 }
334 }
335 }
336
337 // If no worker is already building one, get a random worker to build one
338 const Unit& unit = GetRandomEntry(workers);
339
340 // Check to see if unit can make it there
341 if (Query()->PathingDistance(unit.tag, location) < 0.1f) {
342 return false;
343 }
344 if (!isExpansion) {
345 for (const auto& expansion : expansions_) {
346 if (Distance2D(location, Point2D(expansion.x, expansion.y)) < 7) {
347 return false;
348 }
349 }
350 }
351 // Check to see if unit can build there
352 if (Query()->Placement(ability_type_for_structure, location)) {
353 Actions()->UnitCommand(unit.tag, ability_type_for_structure, location);
354 return true;
355 }
356 return false;
357
358}
359
360//Try to build a structure based on tag, Used mostly for Vespene, since the pathing check will fail even though the geyser is "Pathable"
361bool MultiplayerBot::TryBuildStructure(AbilityID ability_type_for_structure, UnitTypeID unit_type, Tag location_tag) {

Callers

nothing calls this directly

Calls 11

ObservationClass · 0.85
IsUnitClass · 0.85
Distance2DFunction · 0.85
Point2DClass · 0.85
GetRandomUnitFunction · 0.85
GetRandomScalarFunction · 0.85
GetUnitsMethod · 0.80
PathingDistanceMethod · 0.80
PlacementMethod · 0.80
UnitCommandMethod · 0.80
GetUnitMethod · 0.80

Tested by

no test coverage detected