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

Method TryBuildAddOn

examples/common/bot_examples.cc:2507–2542  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2505}
2506
2507bool TerranMultiplayerBot::TryBuildAddOn(AbilityID ability_type_for_structure, Tag base_structure) {
2508 float rx = GetRandomScalar();
2509 float ry = GetRandomScalar();
2510 const Unit* unit = Observation()->GetUnit(base_structure);
2511
2512 if (unit->build_progress != 1) {
2513 return false;
2514 }
2515
2516 Point2D build_location = Point2D(unit->pos.x + rx * 15, unit->pos.y + ry * 15);
2517
2518 Units units = Observation()->GetUnits(Unit::Self, IsStructure(Observation()));
2519
2520 if (Query()->Placement(ability_type_for_structure, unit->pos, unit->tag)) {
2521 Actions()->UnitCommand(base_structure, ability_type_for_structure);
2522 return true;
2523 }
2524
2525 float distance = std::numeric_limits<float>::max();
2526 for (const auto& u : units) {
2527 float d = Distance2D(u.pos, build_location);
2528 if (d < distance) {
2529 distance = d;
2530 }
2531 }
2532 if (distance < 6) {
2533 return false;
2534 }
2535
2536 if(Query()->Placement(ability_type_for_structure,build_location,unit->tag)){
2537 Actions()->UnitCommand(base_structure, ability_type_for_structure, build_location);
2538 return true;
2539 }
2540 return false;
2541
2542}
2543
2544bool TerranMultiplayerBot::TryBuildStructureRandom(AbilityID ability_type_for_structure, UnitTypeID unit_type) {
2545 float rx = GetRandomScalar();

Callers

nothing calls this directly

Calls 9

GetRandomScalarFunction · 0.85
ObservationClass · 0.85
Point2DClass · 0.85
IsStructureClass · 0.85
Distance2DFunction · 0.85
GetUnitMethod · 0.80
GetUnitsMethod · 0.80
PlacementMethod · 0.80
UnitCommandMethod · 0.80

Tested by

no test coverage detected