# HG changeset patch # User alberth # Date 2010-03-07 14:00:53 # Node ID fd229ecdbf78067530bd65a4c5b21927cbbc9f05 # Parent 618888fa16c501b1b8305f2f043f5a1ffc6889dc (svn r19363) -Codechange: Remove use of _error_message global from TerraformTile_Track. diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -2723,10 +2723,10 @@ static VehicleEnterTileStatus VehicleEnt */ static CommandCost TestAutoslopeOnRailTile(TileIndex tile, uint flags, uint z_old, Slope tileh_old, uint z_new, Slope tileh_new, TrackBits rail_bits) { - if (!_settings_game.construction.build_on_slopes || !AutoslopeEnabled()) return CMD_ERROR; + if (!_settings_game.construction.build_on_slopes || !AutoslopeEnabled()) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK); /* Is the slope-rail_bits combination valid in general? I.e. is it safe to call GetRailFoundation() ? */ - if (CheckRailSlope(tileh_new, rail_bits, TRACK_BIT_NONE, tile).Failed()) return CMD_ERROR; + if (CheckRailSlope(tileh_new, rail_bits, TRACK_BIT_NONE, tile).Failed()) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK); /* Get the slopes on top of the foundations */ z_old += ApplyFoundationToSlope(GetRailFoundation(tileh_old, rail_bits), &tileh_old); @@ -2740,13 +2740,15 @@ static CommandCost TestAutoslopeOnRailTi case TRACK_BIT_UPPER: track_corner = CORNER_N; break; /* Surface slope must not be changed */ - default: return (((z_old != z_new) || (tileh_old != tileh_new)) ? CMD_ERROR : CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION])); + default: + if (z_old != z_new || tileh_old != tileh_new) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK); + return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); } /* The height of the track_corner must not be changed. The rest ensures GetRailFoundation() already. */ z_old += GetSlopeZInCorner(RemoveHalftileSlope(tileh_old), track_corner); z_new += GetSlopeZInCorner(RemoveHalftileSlope(tileh_new), track_corner); - if (z_old != z_new) return CMD_ERROR; + if (z_old != z_new) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK); CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); /* Make the ground dirty, if surface slope has changed */ @@ -2767,10 +2769,9 @@ static CommandCost TerraformTile_Track(T /* Is there flat water on the lower halftile, that must be cleared expensively? */ bool was_water = (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh_old)); - _error_message = STR_ERROR_MUST_REMOVE_RAILROAD_TRACK; - /* First test autoslope. However if it succeeds we still have to test the rest, because non-autoslope terraforming is cheaper. */ CommandCost autoslope_result = TestAutoslopeOnRailTile(tile, flags, z_old, tileh_old, z_new, tileh_new, rail_bits); + autoslope_result.SetGlobalErrorMessage(); /* When there is only a single horizontal/vertical track, one corner can be terraformed. */ Corner allowed_corner;