forked from mirror/OpenTTD
Codechange: Replace duplicated code with TileArea::Expand() (#7467)
This commit is contained in:
@@ -117,6 +117,27 @@ bool OrthogonalTileArea::Contains(TileIndex tile) const
|
||||
return IsInsideBS(tile_x, left, this->w) && IsInsideBS(tile_y, top, this->h);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user