summaryrefslogtreecommitdiff
path: root/src/tile_map.h
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2008-02-28 00:10:08 +0000
committerglx <glx@openttd.org>2008-02-28 00:10:08 +0000
commit35195bb2bc47a92c8fd6060bdc7de3a8444f3bb4 (patch)
tree8f346ea0968b32d22e1d885edda375a17c2dfe93 /src/tile_map.h
parent459fd42e1d8586b80be7adc4f07044c0265c80d4 (diff)
downloadopenttd-35195bb2bc47a92c8fd6060bdc7de3a8444f3bb4.tar.xz
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
Diffstat (limited to 'src/tile_map.h')
-rw-r--r--src/tile_map.h29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/tile_map.h b/src/tile_map.h
index 2723443fb..108cc5adb 100644
--- a/src/tile_map.h
+++ b/src/tile_map.h
@@ -107,6 +107,17 @@ static inline bool IsTileType(TileIndex tile, TileType type)
}
/**
+ * Checks if a tile is valid
+ *
+ * @param tile The tile to check
+ * @return True if the tile is on the map and not one of MP_VOID.
+ */
+static inline bool IsValidTile(TileIndex tile)
+{
+ return tile < MapSize() && !IsTileType(tile, MP_VOID);
+}
+
+/**
* Returns the owner of a tile
*
* This function returns the owner of a tile. This cannot used
@@ -115,14 +126,13 @@ static inline bool IsTileType(TileIndex tile, TileType type)
*
* @param tile The tile to check
* @return The owner of the tile
- * @pre tile < MapSize()
- * @pre The type of the tile must not be MP_HOUSE, MP_VOID and MP_INDUSTRY
+ * @pre IsValidTile(tile)
+ * @pre The type of the tile must not be MP_HOUSE and MP_INDUSTRY
*/
static inline Owner GetTileOwner(TileIndex tile)
{
- assert(tile < MapSize());
+ assert(IsValidTile(tile));
assert(!IsTileType(tile, MP_HOUSE));
- assert(!IsTileType(tile, MP_VOID));
assert(!IsTileType(tile, MP_INDUSTRY));
return (Owner)_m[tile].m1;
@@ -136,14 +146,13 @@ static inline Owner GetTileOwner(TileIndex tile)
*
* @param tile The tile to change the owner status.
* @param owner The new owner.
- * @pre tile < MapSize()
- * @pre The type of the tile must not be MP_HOUSE, MP_VOID and MP_INDUSTRY
+ * @pre IsValidTile(tile)
+ * @pre The type of the tile must not be MP_HOUSE and MP_INDUSTRY
*/
static inline void SetTileOwner(TileIndex tile, Owner owner)
{
- assert(tile < MapSize());
+ assert(IsValidTile(tile));
assert(!IsTileType(tile, MP_HOUSE));
- assert(!IsTileType(tile, MP_VOID));
assert(!IsTileType(tile, MP_INDUSTRY));
_m[tile].m1 = owner;
@@ -165,7 +174,7 @@ static inline bool IsTileOwner(TileIndex tile, Owner owner)
* Set the tropic zone
* @param tile the tile to set the zone of
* @param type the new type
- * @pre assert(tile < MapSize());
+ * @pre tile < MapSize()
*/
static inline void SetTropicZone(TileIndex tile, TropicZone type)
{
@@ -176,7 +185,7 @@ static inline void SetTropicZone(TileIndex tile, TropicZone type)
/**
* Get the tropic zone
* @param tile the tile to get the zone of
- * @pre assert(tile < MapSize());
+ * @pre tile < MapSize()
* @return the zone type
*/
static inline TropicZone GetTropicZone(TileIndex tile)