From 5a355daa5b10d5bb07475c3d3b376c3fffd9018c Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 21 Nov 2010 18:38:45 +0000 Subject: [PATCH] (svn r21290) -Codechange: Add HasTileWaterGround() to deduplicate some tests. --- src/object_cmd.cpp | 2 +- src/water_cmd.cpp | 2 +- src/water_map.h | 11 +++++++++++ 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 a3af4eb590..eab4ac0758 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 15e847e1d3..9f803fc89e 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 41a903dd34..f768a7d782 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 c7095673a1..510119c7ee 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);