MCPcopy Create free account
hub / github.com/bwapi/bwapi / getClosestUnitInRectangle

Method getClosestUnitInRectangle

bwapi/BWAPI/Source/BWAPI/GameImpl.cpp:293–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

291 return unitFinderResults;
292 }
293 Unit GameImpl::getClosestUnitInRectangle(Position center, const UnitFilter &pred, int left, int top, int right, int bottom) const
294 {
295 // cppcheck-suppress variableScope
296 int bestDistance = 99999999;
297 Unit pBestUnit = nullptr;
298
299 Templates::iterateUnitFinder<BW::unitFinder>( BW::BWDATA::UnitOrderingX.data(),
300 BW::BWDATA::UnitOrderingY.data(),
301 BW::BWDATA::UnitOrderingCount,
302 left,
303 top,
304 right,
305 bottom,
306 [&](Unit u){ if ( !pred.isValid() || pred(u) )
307 {
308 int newDistance = u->getDistance(center);
309 if ( newDistance < bestDistance )
310 {
311 pBestUnit = u;
312 bestDistance = newDistance;
313 }
314 } } );
315 return pBestUnit;
316 }
317 Unit GameImpl::getBestUnit(const BestUnitFilter &best, const UnitFilter &pred, Position center, int radius) const
318 {
319 Unit pBestUnit = nullptr;

Callers 2

getClosestUnitMethod · 0.45
getClosestUnitMethod · 0.45

Calls 2

isValidMethod · 0.45
getDistanceMethod · 0.45

Tested by

no test coverage detected