| 3041 | } |
| 3042 | |
| 3043 | static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new) |
| 3044 | { |
| 3045 | auto [tileh_old, z_old] = GetTileSlopeZ(tile); |
| 3046 | if (IsPlainRail(tile)) { |
| 3047 | TrackBits rail_bits = GetTrackBits(tile); |
| 3048 | /* Is there flat water on the lower halftile that must be cleared expensively? */ |
| 3049 | bool was_water = (GetRailGroundType(tile) == RailGroundType::HalfTileWater && IsSlopeWithOneCornerRaised(tileh_old)); |
| 3050 | |
| 3051 | /* Allow clearing the water only if there is no ship */ |
| 3052 | if (was_water && HasVehicleOnTile(tile, [](const Vehicle *v) { |
| 3053 | return v->type == VEH_SHIP; |
| 3054 | })) return CommandCost(STR_ERROR_SHIP_IN_THE_WAY); |
| 3055 | |
| 3056 | /* First test autoslope. However if it succeeds we still have to test the rest, because non-autoslope terraforming is cheaper. */ |
| 3057 | CommandCost autoslope_result = TestAutoslopeOnRailTile(tile, flags, z_old, tileh_old, z_new, tileh_new, rail_bits); |
| 3058 | |
| 3059 | /* When there is only a single horizontal/vertical track, one corner can be terraformed. */ |
| 3060 | Corner allowed_corner; |
| 3061 | switch (rail_bits) { |
| 3062 | case TRACK_BIT_RIGHT: allowed_corner = CORNER_W; break; |
| 3063 | case TRACK_BIT_UPPER: allowed_corner = CORNER_S; break; |
| 3064 | case TRACK_BIT_LEFT: allowed_corner = CORNER_E; break; |
| 3065 | case TRACK_BIT_LOWER: allowed_corner = CORNER_N; break; |
| 3066 | default: return autoslope_result; |
| 3067 | } |
| 3068 | |
| 3069 | Foundation f_old = GetRailFoundation(tileh_old, rail_bits); |
| 3070 | |
| 3071 | /* Do not allow terraforming if allowed_corner is part of anti-zig-zag foundations */ |
| 3072 | if (tileh_old != SLOPE_NS && tileh_old != SLOPE_EW && IsSpecialRailFoundation(f_old)) return autoslope_result; |
| 3073 | |
| 3074 | /* Everything is valid, which only changes allowed_corner */ |
| 3075 | for (Corner corner = (Corner)0; corner < CORNER_END; corner = (Corner)(corner + 1)) { |
| 3076 | if (allowed_corner == corner) continue; |
| 3077 | if (z_old + GetSlopeZInCorner(tileh_old, corner) != z_new + GetSlopeZInCorner(tileh_new, corner)) return autoslope_result; |
| 3078 | } |
| 3079 | |
| 3080 | /* Make the ground dirty */ |
| 3081 | if (flags.Test(DoCommandFlag::Execute)) SetRailGroundType(tile, RailGroundType::Barren); |
| 3082 | |
| 3083 | /* allow terraforming */ |
| 3084 | return CommandCost(EXPENSES_CONSTRUCTION, was_water ? _price[PR_CLEAR_WATER] : (Money)0); |
| 3085 | } else if (_settings_game.construction.build_on_slopes && AutoslopeEnabled() && |
| 3086 | AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRailDepotDirection(tile))) { |
| 3087 | return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); |
| 3088 | } |
| 3089 | return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile); |
| 3090 | } |
| 3091 | |
| 3092 | static CommandCost CheckBuildAbove_Track(TileIndex tile, DoCommandFlags flags, Axis, int) |
| 3093 | { |
nothing calls this directly
no test coverage detected