diff options
author | PeterN <peter@fuzzle.org> | 2019-04-13 14:12:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-13 14:12:34 +0100 |
commit | abe8cf4985da211ad70c6232a3c737f15574f5de (patch) | |
tree | b391f3da8a64d9534f56f22d492bb6095b113343 /src/tilearea.cpp | |
parent | 801cbea9cce1e04e6921bb087add8206cffe1fe1 (diff) | |
download | openttd-abe8cf4985da211ad70c6232a3c737f15574f5de.tar.xz |
Codechange: Replace duplicated code with TileArea::Expand() (#7467)
Diffstat (limited to 'src/tilearea.cpp')
-rw-r--r-- | src/tilearea.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/tilearea.cpp b/src/tilearea.cpp index ec3b9aafb..33850c720 100644 --- a/src/tilearea.cpp +++ b/src/tilearea.cpp @@ -118,6 +118,27 @@ bool OrthogonalTileArea::Contains(TileIndex tile) const } /** + * 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() |