diff --git a/src/tilearea.cpp b/src/tilearea.cpp --- a/src/tilearea.cpp +++ b/src/tilearea.cpp @@ -118,6 +118,27 @@ bool OrthogonalTileArea::Contains(TileIn } /** + * Expand a tile area by rad tiles in each direction, keeping within map bounds. + * @param rad Number of tiles to expand + * @return The OrthogonalTileArea. + */ +OrthogonalTileArea &OrthogonalTileArea::Expand(int rad) +{ + int x = TileX(this->tile); + int y = TileY(this->tile); + + int sx = max(x - rad, 0); + int sy = max(y - rad, 0); + int ex = min(x + this->w + rad, MapSizeX()); + int ey = min(y + this->h + rad, MapSizeY()); + + this->tile = TileXY(sx, sy); + this->w = ex - sx; + this->h = ey - sy; + return *this; +} + +/** * Clamp the tile area to map borders. */ void OrthogonalTileArea::ClampToMap()