diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index f471af2..d3e8c94 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -1521,6 +1521,8 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 TrainList affected_trains; + SmallVector seen_tunnel_bridges; + CommandCost cost(EXPENSES_CONSTRUCTION); CommandCost error = CommandCost(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK); // by default, there is no track to convert. TileArea ta(tile, p1); @@ -1637,11 +1639,6 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 case MP_TUNNELBRIDGE: { TileIndex endtile = GetOtherTunnelBridgeEnd(tile); - /* If both ends of tunnel/bridge are in the range, do not try to convert twice - - * it would cause assert because of different test and exec runs */ - if (endtile < tile && TileX(endtile) >= TileX(ta.tile) && TileX(endtile) < TileX(ta.tile) + ta.w && - TileY(endtile) >= TileY(ta.tile) && TileY(endtile) < TileY(ta.tile) + ta.h) continue; - /* When not converting rail <-> el. rail, any vehicle cannot be in tunnel/bridge */ if (!IsCompatibleRail(GetRailType(tile), totype)) { CommandCost ret = TunnelBridgeIsFree(tile, endtile); @@ -1686,6 +1683,12 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 TileIndex t = tile + delta; for (; t != endtile; t += delta) MarkTileDirtyByTile(t); // TODO encapsulate this into a function } + } else { + /* If both ends of tunnel/bridge are in the range, do not try to convert twice - + * it would cause assert because of different test and exec runs */ + if (seen_tunnel_bridges.Contains(endtile)) + continue; + *(seen_tunnel_bridges.Append()) = tile; } cost.AddCost((GetTunnelBridgeLength(tile, endtile) + 2) * RailConvertCost(type, totype));