summaryrefslogtreecommitdiff
path: root/src/tile_map.h
diff options
context:
space:
mode:
authorzuu <zuu@openttd.org>2013-10-12 22:03:13 +0000
committerzuu <zuu@openttd.org>2013-10-12 22:03:13 +0000
commitb35b8aa5bb38f9e47ca04ccd9302dd82546de0cd (patch)
tree071b2d96066a605c5bf65ede95945ea8738a2171 /src/tile_map.h
parentd90889791826633d9f18301ead41a5d4bc77e215 (diff)
downloadopenttd-b35b8aa5bb38f9e47ca04ccd9302dd82546de0cd.tar.xz
(svn r25848) -Codechange: Refactor check for if a tile is not an edge tile to new IsInnerTile method (cirdan, LordAro)
Diffstat (limited to 'src/tile_map.h')
-rw-r--r--src/tile_map.h19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/tile_map.h b/src/tile_map.h
index 2c5cfffbf..f9c7a2ac9 100644
--- a/src/tile_map.h
+++ b/src/tile_map.h
@@ -78,6 +78,23 @@ static inline TileType GetTileType(TileIndex tile)
}
/**
+ * Check if a tile is within the map (not a border)
+ *
+ * @param tile The tile to check
+ * @return Whether the tile is in the interior of the map
+ * @pre tile < MapSize()
+ */
+static inline bool IsInnerTile(TileIndex tile)
+{
+ assert(tile < MapSize());
+
+ uint x = TileX(tile);
+ uint y = TileY(tile);
+
+ return x < MapMaxX() && y < MapMaxY() && ((x > 0 && y > 0) || !_settings_game.construction.freeform_edges);
+}
+
+/**
* Set the type of a tile
*
* This functions sets the type of a tile. If the type
@@ -95,7 +112,7 @@ static inline void SetTileType(TileIndex tile, TileType type)
/* VOID tiles (and no others) are exactly allowed at the lower left and right
* edges of the map. If _settings_game.construction.freeform_edges is true,
* the upper edges of the map are also VOID tiles. */
- assert((TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY() || (_settings_game.construction.freeform_edges && (TileX(tile) == 0 || TileY(tile) == 0))) == (type == MP_VOID));
+ assert(IsInnerTile(tile) == (type != MP_VOID));
SB(_m[tile].type_height, 4, 4, type);
}