Signals on tunnel/bridges are now added to infrastructure stats.

This commit is contained in:
Jonathan G Rennison
2017-01-30 21:37:17 +00:00
parent 08062096ab
commit d762835903
6 changed files with 59 additions and 3 deletions

View File

@@ -95,6 +95,16 @@ void MarkBridgeOrTunnelDirty(TileIndex tile)
}
}
/**
* Get number of signals on bridge or tunnel with signal simulation.
* @param length Length of bridge/tunnel middle
* @return Number of signals on signalled bridge/tunnel of this length
*/
uint GetTunnelBridgeSignalSimulationSignalCount(uint length)
{
return 2 + (length / _settings_game.construction.simulated_wormhole_signals);
}
/** Reset the data been eventually changed by the grf loaded. */
void ResetBridges()
{
@@ -854,6 +864,9 @@ static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags)
if (Company::IsValidID(owner)) {
Company::Get(owner)->infrastructure.rail[GetRailType(tile)] -= len * TUNNELBRIDGE_TRACKBIT_FACTOR;
if (IsTunnelBridgeWithSignalSimulation(tile)) { // handle tunnel/bridge signals.
Company::Get(GetTileOwner(tile))->infrastructure.signal -= GetTunnelBridgeSignalSimulationSignalCount(tile, endtile);
}
DirtyCompanyInfrastructureWindows(owner);
}
@@ -939,7 +952,12 @@ static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags)
/* Update company infrastructure counts. */
if (rail) {
if (Company::IsValidID(owner)) Company::Get(owner)->infrastructure.rail[GetRailType(tile)] -= len * TUNNELBRIDGE_TRACKBIT_FACTOR;
if (Company::IsValidID(owner)) {
Company::Get(owner)->infrastructure.rail[GetRailType(tile)] -= len * TUNNELBRIDGE_TRACKBIT_FACTOR;
if (IsTunnelBridgeWithSignalSimulation(tile)) { // handle tunnel/bridge signals.
Company::Get(GetTileOwner(tile))->infrastructure.signal -= GetTunnelBridgeSignalSimulationSignalCount(tile, endtile);
}
}
} else if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) {
RoadType rt;
FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
@@ -1860,6 +1878,12 @@ static void ChangeTileOwner_TunnelBridge(TileIndex tile, Owner old_owner, Owner
if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.water += num_pieces;
}
if (IsTunnelBridgeWithSignalSimulation(tile) && IsTunnelBridgeSignalSimulationEntrance(tile)) {
uint num_sigs = GetTunnelBridgeSignalSimulationSignalCount(tile, other_end);
Company::Get(old_owner)->infrastructure.signal -= num_sigs;
Company::Get(new_owner)->infrastructure.signal += num_sigs;
}
if (new_owner != INVALID_OWNER) {
SetTileOwner(tile, new_owner);
} else {