| 315 | return pBestUnit; |
| 316 | } |
| 317 | Unit GameImpl::getBestUnit(const BestUnitFilter &best, const UnitFilter &pred, Position center, int radius) const |
| 318 | { |
| 319 | Unit pBestUnit = nullptr; |
| 320 | Position rad(radius,radius); |
| 321 | |
| 322 | Position topLeft(center - rad); |
| 323 | Position botRight(center + rad); |
| 324 | |
| 325 | topLeft.makeValid(); |
| 326 | botRight.makeValid(); |
| 327 | |
| 328 | Templates::iterateUnitFinder<BW::unitFinder>( BW::BWDATA::UnitOrderingX.data(), |
| 329 | BW::BWDATA::UnitOrderingY.data(), |
| 330 | BW::BWDATA::UnitOrderingCount, |
| 331 | topLeft.x, |
| 332 | topLeft.y, |
| 333 | botRight.x, |
| 334 | botRight.y, |
| 335 | [&](Unit u){ if ( !pred.isValid() || pred(u) ) |
| 336 | { |
| 337 | if ( pBestUnit == nullptr ) |
| 338 | pBestUnit = u; |
| 339 | else |
| 340 | pBestUnit = best(pBestUnit,u); |
| 341 | } } ); |
| 342 | |
| 343 | return pBestUnit; |
| 344 | } |
| 345 | //----------------------------------------------- MAP WIDTH ------------------------------------------------ |
| 346 | int GameImpl::mapWidth() const |
| 347 | { |