From eda4cfeabea022f887871dd0b40f6f6d47ae36a7 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 13 Jan 2013 13:17:12 +0000 Subject: [PATCH] (svn r24912) -Fix [FS#5389]: Upgrading bridges could steal road types. (adf88) --- src/bridge_map.h | 8 +++++--- src/tunnelbridge_cmd.cpp | 14 ++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/bridge_map.h b/src/bridge_map.h index 5ab4fd5527..8ee658ce75 100644 --- a/src/bridge_map.h +++ b/src/bridge_map.h @@ -161,15 +161,17 @@ static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, D * Make a bridge ramp for roads. * @param t the tile to make a bridge ramp * @param o the new owner of the bridge ramp + * @param owner_road the new owner of the road on the bridge + * @param owner_tram the new owner of the tram on the bridge * @param bridgetype the type of bridge this bridge ramp belongs to * @param d the direction this ramp must be facing * @param r the road type of the bridge */ -static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RoadTypes r) +static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, Owner owner_road, Owner owner_tram, BridgeType bridgetype, DiagDirection d, RoadTypes r) { MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD, 0); - SetRoadOwner(t, ROADTYPE_ROAD, o); - if (o != OWNER_TOWN) SetRoadOwner(t, ROADTYPE_TRAM, o); + SetRoadOwner(t, ROADTYPE_ROAD, owner_road); + if (owner_tram != OWNER_TOWN) SetRoadOwner(t, ROADTYPE_TRAM, owner_tram); SetRoadTypes(t, r); } diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 87edbc27d1..1bcbf7163d 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -455,18 +455,24 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u SetTunnelBridgeReservation(tile_end, pbs_reservation); break; - case TRANSPORT_ROAD: + case TRANSPORT_ROAD: { + RoadTypes prev_roadtypes = IsBridgeTile(tile_start) ? GetRoadTypes(tile_start) : ROADTYPES_NONE; if (c != NULL) { /* Add all new road types to the company infrastructure counter. */ RoadType new_rt; - FOR_EACH_SET_ROADTYPE(new_rt, roadtypes ^ (IsBridgeTile(tile_start) ? GetRoadTypes(tile_start) : ROADTYPES_NONE)) { + FOR_EACH_SET_ROADTYPE(new_rt, roadtypes ^ prev_roadtypes) { /* A full diagonal road tile has two road bits. */ Company::Get(owner)->infrastructure.road[new_rt] += (bridge_len + 2) * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR; } } - MakeRoadBridgeRamp(tile_start, owner, bridge_type, dir, roadtypes); - MakeRoadBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), roadtypes); + Owner owner_road = owner; + Owner owner_tram = owner; + if (HasBit(prev_roadtypes, ROADTYPE_ROAD)) owner_road = GetRoadOwner(tile_start, ROADTYPE_ROAD); + if (HasBit(prev_roadtypes, ROADTYPE_TRAM)) owner_tram = GetRoadOwner(tile_start, ROADTYPE_TRAM); + MakeRoadBridgeRamp(tile_start, owner, owner_road, owner_tram, bridge_type, dir, roadtypes); + MakeRoadBridgeRamp(tile_end, owner, owner_road, owner_tram, bridge_type, ReverseDiagDir(dir), roadtypes); break; + } case TRANSPORT_WATER: if (!IsBridgeTile(tile_start) && c != NULL) c->infrastructure.water += (bridge_len + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;