Fix possible incorrect tile index in FindNearestHangar

See also: https://github.com/OpenTTD/OpenTTD/issues/7619
This commit is contained in:
Jonathan G Rennison
2019-11-13 22:16:02 +00:00
parent bbd487a2a7
commit b07a1f8426
2 changed files with 15 additions and 4 deletions

View File

@@ -197,6 +197,19 @@ static inline TileIndex TileVirtXY(uint x, uint y)
return (y >> 4 << MapLogX()) + (x >> 4);
}
/**
* Get a tile from the virtual XY-coordinate.
* This is clamped to be within the map bounds.
* @param x The virtual x coordinate of the tile.
* @param y The virtual y coordinate of the tile.
* @return The TileIndex calculated by the coordinate.
*/
static inline TileIndex TileVirtXYClampedToMap(int x, int y)
{
int safe_x = Clamp<int>(x, 0, MapMaxX() * TILE_SIZE);
int safe_y = Clamp<int>(y, 0, MapMaxY() * TILE_SIZE);
return TileVirtXY((uint) safe_x, (uint) safe_y);
}
/**
* Get the X component of a tile