| 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; |
no test coverage detected