changeset 17856:182eebeb857e draft

(svn r22647) -Codechange: Enhance MP_WATER map accessors with assertions. (adf88)
author frosch <frosch@openttd.org>
date Sun, 10 Jul 2011 13:21:21 +0000
parents a35585431755
children 79ef73bc37d5
files src/water_map.h
diffstat 1 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/water_map.h
+++ b/src/water_map.h
@@ -136,6 +136,7 @@
  * Is it a plain water tile?
  * @param t Water tile to query.
  * @return \c true if any type of clear water like ocean, river, or canal.
+ * @pre IsTileType(t, MP_WATER)
  */
 static inline bool IsWater(TileIndex t)
 {
@@ -146,6 +147,7 @@
  * Is it a sea water tile?
  * @param t Water tile to query.
  * @return \c true if it is a sea water tile.
+ * @pre IsTileType(t, MP_WATER)
  */
 static inline bool IsSea(TileIndex t)
 {
@@ -156,6 +158,7 @@
  * Is it a canal tile?
  * @param t Water tile to query.
  * @return \c true if it is a canal tile.
+ * @pre IsTileType(t, MP_WATER)
  */
 static inline bool IsCanal(TileIndex t)
 {
@@ -166,6 +169,7 @@
  * Is it a river water tile?
  * @param t Water tile to query.
  * @return \c true if it is a river water tile.
+ * @pre IsTileType(t, MP_WATER)
  */
 static inline bool IsRiver(TileIndex t)
 {
@@ -186,6 +190,7 @@
  * Is it a coast tile?
  * @param t Water tile to query.
  * @return \c true if it is a sea water tile.
+ * @pre IsTileType(t, MP_WATER)
  */
 static inline bool IsCoast(TileIndex t)
 {
@@ -206,6 +211,7 @@
  * Is it a water tile with a ship depot on it?
  * @param t Water tile to query.
  * @return \c true if it is a ship depot tile.
+ * @pre IsTileType(t, MP_WATER)
  */
 static inline bool IsShipDepot(TileIndex t)
 {
@@ -226,9 +232,11 @@
  * Get the axis of the ship depot.
  * @param t Water tile to query.
  * @return Axis of the depot.
+ * @pre IsShipDepotTile(t)
  */
 static inline Axis GetShipDepotAxis(TileIndex t)
 {
+	assert(IsShipDepotTile(t));
 	return (Axis)GB(_m[t].m5, WBL_DEPOT_AXIS, 1);
 }
 
@@ -248,6 +256,7 @@
  * Get the direction of the ship depot.
  * @param t Water tile to query.
  * @return Direction of the depot.
+ * @pre IsShipDepotTile(t)
  */
 static inline DiagDirection GetShipDepotDirection(TileIndex t)
 {
@@ -258,6 +267,7 @@
  * Get the other tile of the ship depot.
  * @param t Tile to query, containing one section of a ship depot.
  * @return Tile containing the other section of the depot.
+ * @pre IsShipDepotTile(t)
  */
 static inline TileIndex GetOtherShipDepotTile(TileIndex t)
 {
@@ -268,6 +278,7 @@
  * Get the most northern tile of a ship depot.
  * @param t One of the tiles of the ship depot.
  * @return The northern tile of the depot.
+ * @pre IsShipDepotTile(t)
  */
 static inline TileIndex GetShipDepotNorthTile(TileIndex t)
 {
@@ -278,9 +289,10 @@
 }
 
 /**
- * Is it a water lock tile?
+ * Is there a lock on a given water tile?
  * @param t Water tile to query.
  * @return \c true if it is a water lock tile.
+ * @pre IsTileType(t, MP_WATER)
  */
 static inline bool IsLock(TileIndex t)
 {
@@ -291,9 +303,11 @@
  * Get the direction of the water lock.
  * @param t Water tile to query.
  * @return Direction of the lock.
+ * @pre IsTileType(t, MP_WATER) && IsLock(t)
  */
 static inline DiagDirection GetLockDirection(TileIndex t)
 {
+	assert(IsLock(t));
 	return (DiagDirection)GB(_m[t].m5, WBL_LOCK_ORIENT_BEGIN, WBL_LOCK_ORIENT_COUNT);
 }
 
@@ -301,10 +315,11 @@
  * Get the part of a lock.
  * @param t Water tile to query.
  * @return The part.
+ * @pre IsTileType(t, MP_WATER) && IsLock(t)
  */
 static inline byte GetLockPart(TileIndex t)
 {
-	assert(GetWaterTileType(t) == WATER_TILE_LOCK);
+	assert(IsLock(t));
 	return GB(_m[t].m5, WBL_LOCK_PART_BEGIN, WBL_LOCK_PART_COUNT);
 }
 
@@ -312,9 +327,11 @@
  * Get the random bits of the water tile.
  * @param t Water tile to query.
  * @return Random bits of the tile.
+ * @pre IsTileType(t, MP_WATER)
  */
 static inline byte GetWaterTileRandomBits(TileIndex t)
 {
+	assert(IsTileType(t, MP_WATER));
 	return _m[t].m4;
 }