From eddd635f00bcc546014d30fe103e81996712a583 Mon Sep 17 00:00:00 2001 From: HackaLittleBit Date: Fri, 31 Mar 2017 01:54:33 +0100 Subject: [PATCH] Chunnel: Make error reporting consistent with tunnel length reporting at cursor. Error reporting should be in tune with occurrence of events. --- src/lang/english.txt | 2 +- src/tunnelbridge_cmd.cpp | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 5b326ea157..0c6a2c598a 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -5009,7 +5009,7 @@ STR_ERROR_TUNNEL_THROUGH_MAP_BORDER :{WHITE}Tunnel w STR_ERROR_CHUNNEL_THROUGH_MAP_BORDER :{WHITE}Tunnel under water would end out of the map STR_ERROR_UNABLE_TO_EXCAVATE_LAND :{WHITE}Unable to excavate land for other end of tunnel STR_ERROR_TUNNEL_TOO_LONG :{WHITE}... tunnel too long -STR_ERROR_CHUNNEL_RAMP :{WHITE}... only ramp length between 4 and {NUM} tiles is allowed for tunnels under water. +STR_ERROR_CHUNNEL_RAMP :{WHITE}... only ramp length between 5 and {NUM} tiles is allowed for tunnels under water. STR_ERROR_TUNNEL_TOO_MANY :{WHITE}... too many tunnels STR_ERROR_NO_DRILLING_ABOVE_CHUNNEL :{WHITE}No oil rigs allowed above underwater tunnels. STR_ERROR_ANOTHER_TUNNEL_IN_THE_WAY_FOR_CHUNNEL :{WHITE}Three tiles are needed to pass under the other tunnel. diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index cac04d08ff..15e02d17d3 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -613,8 +613,9 @@ static inline StringID IsRampBetweenLimits(TileIndex ramp_start, TileIndex tile, { uint min_length = 4; uint max_length = 7; - if (Delta(ramp_start, tile) < (uint)abs(delta) * min_length || Delta(ramp_start, tile - delta) > (uint)abs(delta) * max_length) { - SetDParam(0, max_length); + if (Delta(ramp_start, tile) < (uint)abs(delta) * min_length || (uint)abs(delta) * max_length < Delta(ramp_start, tile)) { + /* Add 1 in message to have consistency with cursor count in game. */ + SetDParam(0, max_length + 1); return STR_ERROR_CHUNNEL_RAMP; } @@ -643,17 +644,11 @@ static inline CommandCost CanBuildChunnel(TileIndex tile, DiagDirection directio for (;;) { tile += delta; if (!IsValidTile(tile)) return_cmd_error(STR_ERROR_CHUNNEL_THROUGH_MAP_BORDER); + _build_tunnel_endtile = tile; int end_z; Slope end_tileh = GetTileSlope(tile, &end_z); if (start_z == end_z) { - _build_tunnel_endtile = tile; - - /* Check if end ramp was too short or too long after crossing the sea. */ - if (crossed_sea) { - StringID err_msg = IsRampBetweenLimits(ramp_start, tile, delta); - if (err_msg > STR_NULL) return_cmd_error(err_msg); - } /* Handle chunnels only on sea level and only one time crossing. */ if (!crossed_sea && @@ -668,9 +663,6 @@ static inline CommandCost CanBuildChunnel(TileIndex tile, DiagDirection directio /* Pass the water and find a proper shore tile that potentially * could have a tunnel portal behind. */ for (;;) { - if (!IsValidTile(tile)) return_cmd_error(STR_ERROR_CHUNNEL_THROUGH_MAP_BORDER); - _build_tunnel_endtile = tile; - end_tileh = GetTileSlope(tile); if (direction == DIAGDIR_NE && (end_tileh & SLOPE_NE) == SLOPE_NE) break; if (direction == DIAGDIR_SE && (end_tileh & SLOPE_SE) == SLOPE_SE) break; @@ -685,15 +677,25 @@ static inline CommandCost CanBuildChunnel(TileIndex tile, DiagDirection directio if (IsTileType(tile, MP_WATER) && IsSea(tile)) crossed_sea = true; if (!_cheats.crossing_tunnels.value && IsTunnelInWay(tile, start_z)) return_cmd_error(STR_ERROR_ANOTHER_TUNNEL_IN_THE_WAY); + tile += delta; + if (!IsValidTile(tile)) return_cmd_error(STR_ERROR_CHUNNEL_THROUGH_MAP_BORDER); + _build_tunnel_endtile = tile; sea_tiles++; } if (!crossed_sea) return_cmd_error(STR_ERROR_CHUNNEL_ONLY_OVER_SEA); ramp_start = tile; } else { + /* Check if end ramp was too short or too long after crossing the sea. */ + if (crossed_sea) { + StringID err_msg = IsRampBetweenLimits(ramp_start, tile, delta); + if (err_msg > STR_NULL) return_cmd_error(err_msg); + } + break; } } + if (!_cheats.crossing_tunnels.value && IsTunnelInWay(tile, start_z)) return_cmd_error(STR_ERROR_ANOTHER_TUNNEL_IN_THE_WAY); } is_chunnel = crossed_sea;