changeset 15943:56c14e4bdfb5 draft

(svn r20631) -Codechange: generalise IsIndustryTileOnWater + simplify so related code
author rubidium <rubidium@openttd.org>
date Thu, 26 Aug 2010 19:29:20 +0000
parents 39825d591a1f
children d1aa55b7ebcf
files src/industry_cmd.cpp src/industry_map.h src/newgrf_industrytiles.cpp src/water_cmd.cpp src/water_map.h
diffstat 5 files changed, 21 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -338,7 +338,7 @@
 
 	/* If the ground sprite is the default flat water sprite, draw also canal/river borders.
 	 * Do not do this if the tile's WaterClass is 'land'. */
-	if (image == SPR_FLAT_WATER_TILE && IsIndustryTileOnWater(ti->tile)) {
+	if (image == SPR_FLAT_WATER_TILE && IsTileOnWater(ti->tile)) {
 		DrawWaterClassGround(ti);
 	} else {
 		DrawGroundSprite(image, GroundSpritePaletteTransform(image, dits->ground.pal, GENERAL_SPRITE_COLOUR(ind->random_colour)));
@@ -791,7 +791,7 @@
 
 static void TileLoop_Industry(TileIndex tile)
 {
-	if (IsIndustryTileOnWater(tile)) TileLoop_Water(tile);
+	if (IsTileOnWater(tile)) TileLoop_Water(tile);
 
 	TriggerIndustryTile(tile, INDTILE_TRIGGER_TILE_LOOP);
 
--- a/src/industry_map.h
+++ b/src/industry_map.h
@@ -157,17 +157,6 @@
 }
 
 /**
- * Tests if the industry tile was built on water.
- * @param t the industry tile
- * @return true iff on water
- */
-static inline bool IsIndustryTileOnWater(TileIndex t)
-{
-	assert(IsTileType(t, MP_INDUSTRY));
-	return (GetWaterClass(t) != WATER_CLASS_INVALID);
-}
-
-/**
  * Returns this indutry tile's construction counter value
  * @param tile the tile to query
  * @pre IsTileType(tile, MP_INDUSTRY)
--- a/src/newgrf_industrytiles.cpp
+++ b/src/newgrf_industrytiles.cpp
@@ -190,7 +190,7 @@
 	if (GB(image, 0, SPRITE_WIDTH) != 0) {
 		/* If the ground sprite is the default flat water sprite, draw also canal/river borders
 		 * Do not do this if the tile's WaterClass is 'land'. */
-		if (image == SPR_FLAT_WATER_TILE && IsIndustryTileOnWater(ti->tile)) {
+		if (image == SPR_FLAT_WATER_TILE && IsTileOnWater(ti->tile)) {
 			DrawWaterClassGround(ti);
 		} else {
 			DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, GENERAL_SPRITE_COLOUR(rnd_colour)));
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -497,7 +497,7 @@
 			if ((IsTileType(src_tile, MP_STATION) && IsOilRig(src_tile)) ||
 			    (IsTileType(src_tile, MP_INDUSTRY) && GetIndustryIndex(src_tile) == GetIndustryIndex(tile))) return true;
 
-			return IsIndustryTileOnWater(tile);
+			return IsTileOnWater(tile);
 		}
 
 		case MP_TUNNELBRIDGE: return GetTunnelBridgeTransportType(tile) == TRANSPORT_WATER && ReverseDiagDir(GetTunnelBridgeDirection(tile)) == DirToDiagDir(from);
@@ -932,9 +932,11 @@
 			if (IsCoast(tile)) {
 				Slope tileh = GetTileSlope(tile, NULL);
 				return (IsSlopeWithOneCornerRaised(tileh) ? FLOOD_ACTIVE : FLOOD_DRYUP);
-			} else {
-				return (GetWaterClass(tile) == WATER_CLASS_SEA) ? FLOOD_ACTIVE : FLOOD_NONE;
 			}
+			/* FALL THROUGH */
+		case MP_STATION:
+		case MP_INDUSTRY:
+			return (GetWaterClass(tile) == WATER_CLASS_SEA) ? FLOOD_ACTIVE : FLOOD_NONE;
 
 		case MP_RAILWAY:
 			if (GetRailGroundType(tile) == RAIL_GROUND_WATER) {
@@ -945,15 +947,6 @@
 		case MP_TREES:
 			return (GetTreeGround(tile) == TREE_GROUND_SHORE ? FLOOD_DRYUP : FLOOD_NONE);
 
-		case MP_STATION:
-			if (IsBuoy(tile) || (IsDock(tile) && GetTileSlope(tile, NULL) == SLOPE_FLAT) || IsOilRig(tile)) {
-				return (GetWaterClass(tile) == WATER_CLASS_SEA ? FLOOD_ACTIVE : FLOOD_NONE);
-			}
-			return FLOOD_NONE;
-
-		case MP_INDUSTRY:
-			return ((IsIndustryTileOnWater(tile) && GetWaterClass(tile) == WATER_CLASS_SEA) ? FLOOD_ACTIVE : FLOOD_NONE);
-
 		default:
 			return FLOOD_NONE;
 	}
--- a/src/water_map.h
+++ b/src/water_map.h
@@ -68,6 +68,7 @@
 /**
  * Get the water class at a tile.
  * @param t Water tile to query.
+ * @pre IsTileType(t, MP_WATER) || IsTileType(t, MP_STATION) || IsTileType(t, MP_INDUSTRY) || IsTileType(t, MP_OBJECT)
  * @return Water class at the tile.
  */
 static inline WaterClass GetWaterClass(TileIndex t)
@@ -80,6 +81,7 @@
  * Set the water class at a tile.
  * @param t  Water tile to change.
  * @param wc New water class.
+ * @pre IsTileType(t, MP_WATER) || IsTileType(t, MP_STATION) || IsTileType(t, MP_INDUSTRY) || IsTileType(t, MP_OBJECT)
  */
 static inline void SetWaterClass(TileIndex t, WaterClass wc)
 {
@@ -88,6 +90,17 @@
 }
 
 /**
+ * Tests if the tile was built on water.
+ * @param t the tile to check
+ * @pre IsTileType(t, MP_WATER) || IsTileType(t, MP_STATION) || IsTileType(t, MP_INDUSTRY) || IsTileType(t, MP_OBJECT)
+ * @return true iff on water
+ */
+static inline bool IsTileOnWater(TileIndex t)
+{
+	return (GetWaterClass(t) != WATER_CLASS_INVALID);
+}
+
+/**
  * 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.