From 68fd949a52840f24e50dc32ab1338df7977fa953 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 4 Apr 2025 18:11:19 +0100 Subject: [PATCH] Fix 44984f8410: Changing ownership of a tunnel/bridge did not check for road transport type. (#13963) Changing ownership changed ownership of road components without checking if the tunnel/bridge is actually a road tunnel/bridge. --- src/tunnelbridge_cmd.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index ce2199076a..67ad64b83e 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -1795,18 +1795,22 @@ static void ChangeTileOwner_TunnelBridge(TileIndex tile, Owner old_owner, Owner * don't want to update the infrastructure counts twice. */ uint num_pieces = tile < other_end ? (GetTunnelBridgeLength(tile, other_end) + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR : 0; - for (RoadTramType rtt : _roadtramtypes) { - /* Update all roadtypes, no matter if they are present */ - if (GetRoadOwner(tile, rtt) == old_owner) { - RoadType rt = GetRoadType(tile, rtt); - if (rt != INVALID_ROADTYPE) { - /* Update company infrastructure counts. A full diagonal road tile has two road bits. - * No need to dirty windows here, we'll redraw the whole screen anyway. */ - Company::Get(old_owner)->infrastructure.road[rt] -= num_pieces * 2; - if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.road[rt] += num_pieces * 2; - } + TransportType tt = GetTunnelBridgeTransportType(tile); - SetRoadOwner(tile, rtt, new_owner == INVALID_OWNER ? OWNER_NONE : new_owner); + if (tt == TRANSPORT_ROAD) { + for (RoadTramType rtt : _roadtramtypes) { + /* Update all roadtypes, no matter if they are present */ + if (GetRoadOwner(tile, rtt) == old_owner) { + RoadType rt = GetRoadType(tile, rtt); + if (rt != INVALID_ROADTYPE) { + /* Update company infrastructure counts. A full diagonal road tile has two road bits. + * No need to dirty windows here, we'll redraw the whole screen anyway. */ + Company::Get(old_owner)->infrastructure.road[rt] -= num_pieces * 2; + if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.road[rt] += num_pieces * 2; + } + + SetRoadOwner(tile, rtt, new_owner == INVALID_OWNER ? OWNER_NONE : new_owner); + } } } @@ -1814,7 +1818,6 @@ static void ChangeTileOwner_TunnelBridge(TileIndex tile, Owner old_owner, Owner /* Update company infrastructure counts for rail and water as well. * No need to dirty windows here, we'll redraw the whole screen anyway. */ - TransportType tt = GetTunnelBridgeTransportType(tile); Company *old = Company::Get(old_owner); if (tt == TRANSPORT_RAIL) { old->infrastructure.rail[GetRailType(tile)] -= num_pieces;