Try build structure given a location. This is used most of the time
| 316 | |
| 317 | //Try build structure given a location. This is used most of the time |
| 318 | bool 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" |
| 361 | bool MultiplayerBot::TryBuildStructure(AbilityID ability_type_for_structure, UnitTypeID unit_type, Tag location_tag) { |
nothing calls this directly
no test coverage detected