Changeset - r14765:fd229ecdbf78
[Not reviewed]
master
0 1 0
alberth - 15 years ago 2010-03-07 14:00:53
alberth@openttd.org
(svn r19363) -Codechange: Remove use of _error_message global from TerraformTile_Track.
1 file changed with 7 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/rail_cmd.cpp
Show inline comments
 
@@ -2714,72 +2714,73 @@ static VehicleEnterTileStatus VehicleEnt
 
 * Tests if autoslope is allowed.
 
 *
 
 * @param tile The tile.
 
 * @param flags Terraform command flags.
 
 * @param z_old Old TileZ.
 
 * @param tileh_old Old TileSlope.
 
 * @param z_new New TileZ.
 
 * @param tileh_new New TileSlope.
 
 * @param rail_bits Trackbits.
 
 */
 
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);
 
	z_new += ApplyFoundationToSlope(GetRailFoundation(tileh_new, rail_bits), &tileh_new);
 

	
 
	Corner track_corner;
 
	switch (rail_bits) {
 
		case TRACK_BIT_LEFT:  track_corner = CORNER_W; break;
 
		case TRACK_BIT_LOWER: track_corner = CORNER_S; break;
 
		case TRACK_BIT_RIGHT: track_corner = CORNER_E; break;
 
		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 */
 
	if (tileh_old != tileh_new) {
 
		/* If there is flat water on the lower halftile add the cost for clearing it */
 
		if (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh_old)) cost.AddCost(_price[PR_CLEAR_WATER]);
 
		if ((flags & DC_EXEC) != 0) SetRailGroundType(tile, RAIL_GROUND_BARREN);
 
	}
 
	return  cost;
 
}
 

	
 
static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
 
{
 
	uint z_old;
 
	Slope tileh_old = GetTileSlope(tile, &z_old);
 
	if (IsPlainRail(tile)) {
 
		TrackBits rail_bits = GetTrackBits(tile);
 
		/* 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;
 
		switch (rail_bits) {
 
			case TRACK_BIT_RIGHT: allowed_corner = CORNER_W; break;
 
			case TRACK_BIT_UPPER: allowed_corner = CORNER_S; break;
 
			case TRACK_BIT_LEFT:  allowed_corner = CORNER_E; break;
 
			case TRACK_BIT_LOWER: allowed_corner = CORNER_N; break;
 
			default: return autoslope_result;
 
		}
 

	
 
		Foundation f_old = GetRailFoundation(tileh_old, rail_bits);
0 comments (0 inline, 0 general)