diff -p -up ./src/rail_cmd.cpp.CVE-2012-3436 ./src/rail_cmd.cpp --- ./src/rail_cmd.cpp.CVE-2012-3436 2011-02-07 22:37:22.000000000 +0000 +++ ./src/rail_cmd.cpp 2012-08-07 20:24:36.830989644 +0000 @@ -2527,7 +2527,7 @@ set_ground: static TrackStatus GetTileTrackStatus_Track(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) { /* Case of half tile slope with water. */ - if (mode == TRANSPORT_WATER && IsPlainRail(tile) && GetRailGroundType(tile) == RAIL_GROUND_WATER) { + if (mode == TRANSPORT_WATER && IsPlainRail(tile) && GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(GetTileSlope(tile, NULL))) { TrackBits tb = GetTrackBits(tile); switch (tb) { default: NOT_REACHED(); @@ -2831,6 +2831,14 @@ static CommandCost TestAutoslopeOnRailTi return cost; } +/** + * Test-procedure for HasVehicleOnPos to check for a ship. + */ +static Vehicle *EnsureNoShipProc(Vehicle *v, void *data) +{ + return v->type == VEH_SHIP ? v : NULL; +} + static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new) { uint z_old; @@ -2840,6 +2848,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)); + /* Allow clearing the water only if there is no ship */ + if (was_water && HasVehicleOnPos(tile, NULL, &EnsureNoShipProc)) return_cmd_error(STR_ERROR_SHIP_IN_THE_WAY); + /* 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);