Chunnel: Make error reporting consistent with tunnel length reporting at cursor.

Error reporting should be in tune with occurrence of events.
This commit is contained in:
HackaLittleBit
2017-03-31 01:54:33 +01:00
committed by Jonathan G Rennison
parent c882082467
commit eddd635f00
2 changed files with 15 additions and 13 deletions

View File

@@ -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_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_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_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_TUNNEL_TOO_MANY :{WHITE}... too many tunnels
STR_ERROR_NO_DRILLING_ABOVE_CHUNNEL :{WHITE}No oil rigs allowed above underwater 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. STR_ERROR_ANOTHER_TUNNEL_IN_THE_WAY_FOR_CHUNNEL :{WHITE}Three tiles are needed to pass under the other tunnel.

View File

@@ -613,8 +613,9 @@ static inline StringID IsRampBetweenLimits(TileIndex ramp_start, TileIndex tile,
{ {
uint min_length = 4; uint min_length = 4;
uint max_length = 7; uint max_length = 7;
if (Delta(ramp_start, tile) < (uint)abs(delta) * min_length || Delta(ramp_start, tile - delta) > (uint)abs(delta) * max_length) { if (Delta(ramp_start, tile) < (uint)abs(delta) * min_length || (uint)abs(delta) * max_length < Delta(ramp_start, tile)) {
SetDParam(0, max_length); /* Add 1 in message to have consistency with cursor count in game. */
SetDParam(0, max_length + 1);
return STR_ERROR_CHUNNEL_RAMP; return STR_ERROR_CHUNNEL_RAMP;
} }
@@ -643,17 +644,11 @@ static inline CommandCost CanBuildChunnel(TileIndex tile, DiagDirection directio
for (;;) { for (;;) {
tile += delta; tile += delta;
if (!IsValidTile(tile)) return_cmd_error(STR_ERROR_CHUNNEL_THROUGH_MAP_BORDER); if (!IsValidTile(tile)) return_cmd_error(STR_ERROR_CHUNNEL_THROUGH_MAP_BORDER);
_build_tunnel_endtile = tile;
int end_z; int end_z;
Slope end_tileh = GetTileSlope(tile, &end_z); Slope end_tileh = GetTileSlope(tile, &end_z);
if (start_z == 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. */ /* Handle chunnels only on sea level and only one time crossing. */
if (!crossed_sea && 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 /* Pass the water and find a proper shore tile that potentially
* could have a tunnel portal behind. */ * could have a tunnel portal behind. */
for (;;) { for (;;) {
if (!IsValidTile(tile)) return_cmd_error(STR_ERROR_CHUNNEL_THROUGH_MAP_BORDER);
_build_tunnel_endtile = tile;
end_tileh = GetTileSlope(tile); end_tileh = GetTileSlope(tile);
if (direction == DIAGDIR_NE && (end_tileh & SLOPE_NE) == SLOPE_NE) break; if (direction == DIAGDIR_NE && (end_tileh & SLOPE_NE) == SLOPE_NE) break;
if (direction == DIAGDIR_SE && (end_tileh & SLOPE_SE) == SLOPE_SE) 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 (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); if (!_cheats.crossing_tunnels.value && IsTunnelInWay(tile, start_z)) return_cmd_error(STR_ERROR_ANOTHER_TUNNEL_IN_THE_WAY);
tile += delta; tile += delta;
if (!IsValidTile(tile)) return_cmd_error(STR_ERROR_CHUNNEL_THROUGH_MAP_BORDER);
_build_tunnel_endtile = tile;
sea_tiles++; sea_tiles++;
} }
if (!crossed_sea) return_cmd_error(STR_ERROR_CHUNNEL_ONLY_OVER_SEA); if (!crossed_sea) return_cmd_error(STR_ERROR_CHUNNEL_ONLY_OVER_SEA);
ramp_start = tile; ramp_start = tile;
} else { } 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; break;
} }
} }
if (!_cheats.crossing_tunnels.value && IsTunnelInWay(tile, start_z)) return_cmd_error(STR_ERROR_ANOTHER_TUNNEL_IN_THE_WAY);
} }
is_chunnel = crossed_sea; is_chunnel = crossed_sea;