changeset 16562:63647faa5876 draft

(svn r21290) -Codechange: Add HasTileWaterGround() to deduplicate some tests.
author frosch <frosch@openttd.org>
date Sun, 21 Nov 2010 18:38:45 +0000
parents 7ca019b56d4e
children 8e0848deda46
files src/object_cmd.cpp src/water_cmd.cpp src/water_map.h src/waypoint_cmd.cpp
diffstat 4 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/object_cmd.cpp
+++ b/src/object_cmd.cpp
@@ -187,7 +187,7 @@
 		bool allow_water = (spec->flags & (OBJECT_FLAG_BUILT_ON_WATER | OBJECT_FLAG_NOT_ON_LAND)) != 0;
 		bool allow_ground = (spec->flags & OBJECT_FLAG_NOT_ON_LAND) == 0;
 		TILE_AREA_LOOP(t, ta) {
-			if (HasTileWaterClass(t) && IsTileOnWater(t) && !IsCoastTile(t)) {
+			if (HasTileWaterGround(t)) {
 				if (!allow_water) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
 				if (!IsWaterTile(t)) {
 					/* Normal water tiles don't have to be cleared. For all other tile types clear
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -100,7 +100,7 @@
 
 	TileIndex tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
 
-	if (!HasTileWaterClass(tile) || !IsTileOnWater(tile) || !HasTileWaterClass(tile2) || !IsTileOnWater(tile2)) {
+	if (!HasTileWaterGround(tile) || !HasTileWaterGround(tile2)) {
 		return_cmd_error(STR_ERROR_MUST_BE_BUILT_ON_WATER);
 	}
 
--- a/src/water_map.h
+++ b/src/water_map.h
@@ -284,6 +284,17 @@
 	return _m[t].m4;
 }
 
+/**
+ * Checks whether the tile has water at the ground.
+ * That is, it is either some plain water tile, or a object/industry/station/... with water under it.
+ * @return true iff the tile has water at the ground.
+ * @note Coast tiles are not considered waterish, even if there is water on a halftile.
+ */
+static inline bool HasTileWaterGround(TileIndex t)
+{
+	return HasTileWaterClass(t) && IsTileOnWater(t) && !IsCoastTile(t);
+}
+
 
 /**
  * Helper function to make a coast tile.
--- a/src/waypoint_cmd.cpp
+++ b/src/waypoint_cmd.cpp
@@ -282,7 +282,7 @@
  */
 CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 {
-	if (!HasTileWaterClass(tile) || !IsTileOnWater(tile) || tile == 0) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
+	if (tile == 0 || !HasTileWaterGround(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 
 	if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);