Preserve signal simulation/reservation data when upgrading bridges.

Based on commit 301925f948c9b36966c9c668e1476c2485425338
This commit is contained in:
Jonathan G Rennison
2018-04-25 22:32:50 +01:00
parent df72bc6e09
commit c92a28a072
2 changed files with 20 additions and 11 deletions

View File

@@ -163,10 +163,24 @@ static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, Owner owner_road, Ow
* @param bridgetype the type of bridge this bridge ramp belongs to * @param bridgetype the type of bridge this bridge ramp belongs to
* @param d the direction this ramp must be facing * @param d the direction this ramp must be facing
* @param r the rail type of the bridge * @param r the rail type of the bridge
* @param upgrade whether the bridge is an upgrade instead of a totally new bridge
*/ */
static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r) static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r, bool upgrade)
{ {
// Backup bridge signal data.
auto m2_backup = _m[t].m2;
auto m5_backup = _m[t].m5;
auto m6_backup = _me[t].m6;
MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL, r); MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL, r);
// Restore bridge signal data if we're upgrading an existing bridge.
if (upgrade) {
_m[t].m2 = m2_backup;
SB(_m[t].m5, 4, 3, GB(m5_backup, 4, 3));
SB(_me[t].m6, 0, 2, GB(m6_backup, 0, 2));
SB(_me[t].m6, 6, 1, GB(m6_backup, 6, 1));
}
} }
/** /**

View File

@@ -339,7 +339,6 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
int z_end; int z_end;
Slope tileh_start = GetTileSlope(tile_start, &z_start); Slope tileh_start = GetTileSlope(tile_start, &z_start);
Slope tileh_end = GetTileSlope(tile_end, &z_end); Slope tileh_end = GetTileSlope(tile_end, &z_end);
bool pbs_reservation = false;
CommandCost terraform_cost_north = CheckBridgeSlopeNorth(direction, &tileh_start, &z_start); CommandCost terraform_cost_north = CheckBridgeSlopeNorth(direction, &tileh_start, &z_start);
CommandCost terraform_cost_south = CheckBridgeSlopeSouth(direction, &tileh_end, &z_end); CommandCost terraform_cost_south = CheckBridgeSlopeSouth(direction, &tileh_end, &z_end);
@@ -351,6 +350,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
CommandCost cost(EXPENSES_CONSTRUCTION); CommandCost cost(EXPENSES_CONSTRUCTION);
Owner owner; Owner owner;
bool is_new_owner; bool is_new_owner;
bool is_upgrade = false;
if (IsBridgeTile(tile_start) && IsBridgeTile(tile_end) && if (IsBridgeTile(tile_start) && IsBridgeTile(tile_end) &&
GetOtherBridgeEnd(tile_start) == tile_end && GetOtherBridgeEnd(tile_start) == tile_end &&
GetTunnelBridgeTransportType(tile_start) == transport_type) { GetTunnelBridgeTransportType(tile_start) == transport_type) {
@@ -393,11 +393,6 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
if (is_new_owner) owner = company; if (is_new_owner) owner = company;
switch (transport_type) { switch (transport_type) {
case TRANSPORT_RAIL:
/* Keep the reservation, the path stays valid. */
pbs_reservation = HasTunnelBridgeReservation(tile_start);
break;
case TRANSPORT_ROAD: case TRANSPORT_ROAD:
/* Do not remove road types when upgrading a bridge */ /* Do not remove road types when upgrading a bridge */
roadtypes |= GetRoadTypes(tile_start); roadtypes |= GetRoadTypes(tile_start);
@@ -405,6 +400,8 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
default: break; default: break;
} }
is_upgrade = true;
} else { } else {
/* Build a new bridge. */ /* Build a new bridge. */
@@ -518,10 +515,8 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
case TRANSPORT_RAIL: case TRANSPORT_RAIL:
/* Add to company infrastructure count if required. */ /* Add to company infrastructure count if required. */
if (is_new_owner && c != NULL) c->infrastructure.rail[railtype] += (bridge_len + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR; if (is_new_owner && c != NULL) c->infrastructure.rail[railtype] += (bridge_len + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
MakeRailBridgeRamp(tile_start, owner, bridge_type, dir, railtype); MakeRailBridgeRamp(tile_start, owner, bridge_type, dir, railtype, is_upgrade);
MakeRailBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), railtype); MakeRailBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), railtype, is_upgrade);
SetTunnelBridgeReservation(tile_start, pbs_reservation);
SetTunnelBridgeReservation(tile_end, pbs_reservation);
break; break;
case TRANSPORT_ROAD: { case TRANSPORT_ROAD: {