(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
authorglx
Thu, 28 Feb 2008 00:10:08 +0000
changeset 9147 54271cd8f27f
parent 9146 2c8c94a75544
child 9148 778a53fe72f3
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
src/landscape.cpp
src/landscape.h
src/tile_map.h
--- a/src/landscape.cpp	Wed Feb 27 21:46:57 2008 +0000
+++ b/src/landscape.cpp	Thu Feb 28 00:10:08 2008 +0000
@@ -919,8 +919,3 @@
 		TileY(a) + (GB(r, 8, 8) * rn * 2 >> 8) - rn
 	));
 }
-
-bool IsValidTile(TileIndex tile)
-{
-	return (tile < MapSizeX() * MapMaxY() && TileX(tile) != MapMaxX());
-}
--- a/src/landscape.h	Wed Feb 27 21:46:57 2008 +0000
+++ b/src/landscape.h	Thu Feb 28 00:10:08 2008 +0000
@@ -26,8 +26,6 @@
 byte HighestSnowLine(void);
 void ClearSnowLine(void);
 
-bool IsValidTile(TileIndex tile);
-
 uint GetPartialZ(int x, int y, Slope corners);
 uint GetSlopeZ(int x, int y);
 void GetSlopeZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2);
--- a/src/tile_map.h	Wed Feb 27 21:46:57 2008 +0000
+++ b/src/tile_map.h	Thu Feb 28 00:10:08 2008 +0000
@@ -107,6 +107,17 @@
 }
 
 /**
+ * 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 @@
  *
  * @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 @@
  *
  * @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 @@
  * 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 @@
 /**
  * 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)