diff options
Diffstat (limited to 'src/tile_map.cpp')
-rw-r--r-- | src/tile_map.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/tile_map.cpp b/src/tile_map.cpp index 86670c88a..1e30ba0d9 100644 --- a/src/tile_map.cpp +++ b/src/tile_map.cpp @@ -59,6 +59,30 @@ Slope GetTileSlope(TileIndex tile, int *h) } /** + * Check if a given tile is flat + * @param tile Tile to check + * @param h If not \c NULL, pointer to storage of z height (only if tile is flat) + * @return Whether the tile is flat + */ +bool IsTileFlat(TileIndex tile, int *h) +{ + assert(tile < MapSize()); + + if (!IsInnerTile(tile)) { + if (h != NULL) *h = TileHeight(tile); + return true; + } + + uint z = TileHeight(tile); + if (TileHeight(tile + TileDiffXY(1, 0)) != z) return false; + if (TileHeight(tile + TileDiffXY(0, 1)) != z) return false; + if (TileHeight(tile + TileDiffXY(1, 1)) != z) return false; + + if (h != NULL) *h = z; + return true; +} + +/** * Get bottom height of the tile * @param tile Tile to compute height of * @return Minimum height of the tile |