MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / circularRegion

Method circularRegion

source/gamemap/TileContainer.cpp:503–607  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

501}
502
503std::vector<Tile*> TileContainer::circularRegion(int x, int y, int radius)
504{
505 // To compute the tiles within this region, we use the symmetry of the square. That's why we mix tile x/y coordinate
506 // with tileDist diffX/diffY. More explanation can be found in the buildTileDistance function
507 std::vector<Tile*> returnList;
508
509 if(radius > mTileDistanceComputed)
510 buildTileDistance(radius);
511
512 int radiusSquared = radius * radius;
513 for(const TileDistance& tileDist : mTileDistance)
514 {
515 if(tileDist.getDistSquared() > radiusSquared)
516 break;
517
518 switch(tileDist.getType())
519 {
520 case TileDistance::TileDistanceType::Horizontal:
521 {
522 // We take the 4 tiles at this distance
523 if(tileDist.getDiffX() == 0)
524 {
525 // We only add the current tile
526 Tile* tile = getTile(x, y);
527 if(tile != nullptr)
528 returnList.push_back(tile);
529
530 continue;
531 }
532
533 // We add the 4 tiles
534 Tile* tile;
535 tile = getTile(x + tileDist.getDiffX(), y);
536 if(tile != nullptr)
537 returnList.push_back(tile);
538 tile = getTile(x - tileDist.getDiffX(), y);
539 if(tile != nullptr)
540 returnList.push_back(tile);
541 tile = getTile(x, y + tileDist.getDiffX());
542 if(tile != nullptr)
543 returnList.push_back(tile);
544 tile = getTile(x, y - tileDist.getDiffX());
545 if(tile != nullptr)
546 returnList.push_back(tile);
547
548 break;
549 }
550
551 case TileDistance::TileDistanceType::Diagonal:
552 {
553 // We add the 4 tiles
554 Tile* tile;
555 tile = getTile(x + tileDist.getDiffX(), y + tileDist.getDiffY());
556 if(tile != nullptr)
557 returnList.push_back(tile);
558 tile = getTile(x + tileDist.getDiffX(), y - tileDist.getDiffY());
559 if(tile != nullptr)
560 returnList.push_back(tile);

Callers 2

computeVisibleTilesMethod · 0.80
updateTilesInSightMethod · 0.80

Calls 4

getDistSquaredMethod · 0.80
getDiffXMethod · 0.80
getDiffYMethod · 0.80
getTypeMethod · 0.45

Tested by

no test coverage detected