diff options
author | frosch <frosch@openttd.org> | 2010-11-21 18:38:45 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2010-11-21 18:38:45 +0000 |
commit | 612516ff7631f427099c9850941202f2ef33e9ac (patch) | |
tree | 77d70b921f516acc12b5e12066fc05ead6c5ee77 | |
parent | 0fff26db9725b1c0ea414bb246e842375c5a3e31 (diff) | |
download | openttd-612516ff7631f427099c9850941202f2ef33e9ac.tar.xz |
(svn r21290) -Codechange: Add HasTileWaterGround() to deduplicate some tests.
-rw-r--r-- | src/object_cmd.cpp | 2 | ||||
-rw-r--r-- | src/water_cmd.cpp | 2 | ||||
-rw-r--r-- | src/water_map.h | 11 | ||||
-rw-r--r-- | src/waypoint_cmd.cpp | 2 |
4 files changed, 14 insertions, 3 deletions
diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index a3af4eb59..eab4ac075 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -187,7 +187,7 @@ CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 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 diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index 15e847e1d..9f803fc89 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -100,7 +100,7 @@ CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui 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); } diff --git a/src/water_map.h b/src/water_map.h index 41a903dd3..f768a7d78 100644 --- a/src/water_map.h +++ b/src/water_map.h @@ -284,6 +284,17 @@ static inline byte GetWaterTileRandomBits(TileIndex t) 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. diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index c7095673a..510119c7e 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -282,7 +282,7 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint */ 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); |