Move dual-use of load_unload_ticks for bridge/tun signals to new field

This commit is contained in:
Jonathan G Rennison
2018-03-26 18:40:05 +01:00
parent 38cb80872b
commit def3a3933b
5 changed files with 21 additions and 7 deletions

View File

@@ -2994,6 +2994,17 @@ bool AfterLoadGame()
} }
} }
} }
if (SlXvIsFeaturePresent(XSLFI_SIG_TUNNEL_BRIDGE, 1, 4)) {
/* load_unload_ticks --> tunnel_bridge_signal_num */
Train *t;
FOR_ALL_TRAINS(t) {
TileIndex tile = t->tile;
if (IsTileType(tile, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL && IsTunnelBridgeWithSignalSimulation(tile)) {
t->tunnel_bridge_signal_num = t->load_unload_ticks;
t->load_unload_ticks = 0;
}
}
}
/* Station acceptance is some kind of cache */ /* Station acceptance is some kind of cache */
if (IsSavegameVersionBefore(127)) { if (IsSavegameVersionBefore(127)) {

View File

@@ -45,7 +45,7 @@ std::vector<uint32> _sl_xv_discardable_chunk_ids; ///< list of chunks
static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version os SLXI chunk static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version os SLXI chunk
const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_SIG_TUNNEL_BRIDGE, XSCF_NULL, 4, 4, "signal_tunnel_bridge", NULL, NULL, "XBSS" }, { XSLFI_SIG_TUNNEL_BRIDGE, XSCF_NULL, 5, 5, "signal_tunnel_bridge", NULL, NULL, "XBSS" },
{ XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker { XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker
}; };

View File

@@ -720,6 +720,7 @@ const SaveLoad *GetVehicleDescription(VehicleType vt)
SLE_CONDNULL(2, 2, 59), SLE_CONDNULL(2, 2, 59),
SLE_CONDVAR(Train, wait_counter, SLE_UINT16, 136, SL_MAX_VERSION), SLE_CONDVAR(Train, wait_counter, SLE_UINT16, 136, SL_MAX_VERSION),
SLE_CONDVAR_X(Train, tunnel_bridge_signal_num, SLE_UINT16, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_SIG_TUNNEL_BRIDGE, 5)),
SLE_CONDNULL(2, 2, 19), SLE_CONDNULL(2, 2, 19),
SLE_CONDVAR(Train, gv_flags, SLE_UINT16, 139, SL_MAX_VERSION), SLE_CONDVAR(Train, gv_flags, SLE_UINT16, 139, SL_MAX_VERSION),

View File

@@ -102,6 +102,8 @@ struct Train FINAL : public GroundVehicle<Train, VEH_TRAIN> {
/** Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through signals. */ /** Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through signals. */
uint16 wait_counter; uint16 wait_counter;
uint16 tunnel_bridge_signal_num;
/** We don't want GCC to zero our struct! It already is zeroed and has an index! */ /** We don't want GCC to zero our struct! It already is zeroed and has an index! */
Train() : GroundVehicleBase() {} Train() : GroundVehicleBase() {}
/** We want to 'destruct' the right class. */ /** We want to 'destruct' the right class. */

View File

@@ -1881,7 +1881,7 @@ void ReverseTrainDirection(Train *v)
MarkTileDirtyByTile(v->tile); MarkTileDirtyByTile(v->tile);
/* Clear counters. */ /* Clear counters. */
v->wait_counter = 0; v->wait_counter = 0;
v->load_unload_ticks = 0; v->tunnel_bridge_signal_num = 0;
return; return;
} }
@@ -3603,7 +3603,7 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse)
if (v->IsFrontEngine() && v->force_proceed == 0 && IsTunnelBridgeSignalSimulationExit(v->tile)) goto invalid_rail; if (v->IsFrontEngine() && v->force_proceed == 0 && IsTunnelBridgeSignalSimulationExit(v->tile)) goto invalid_rail;
/* Entered wormhole set counters. */ /* Entered wormhole set counters. */
v->wait_counter = (TILE_SIZE * _settings_game.construction.simulated_wormhole_signals) - TILE_SIZE; v->wait_counter = (TILE_SIZE * _settings_game.construction.simulated_wormhole_signals) - TILE_SIZE;
v->load_unload_ticks = 0; v->tunnel_bridge_signal_num = 0;
} }
uint distance = v->wait_counter; uint distance = v->wait_counter;
@@ -3628,13 +3628,13 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse)
} }
/* flip signal in front to red on bridges*/ /* flip signal in front to red on bridges*/
if (distance == 0 && IsBridge(v->tile)) { if (distance == 0 && IsBridge(v->tile)) {
SetBridgeEntranceSimulatedSignalState(v->tile, v->load_unload_ticks, SIGNAL_STATE_RED); SetBridgeEntranceSimulatedSignalState(v->tile, v->tunnel_bridge_signal_num, SIGNAL_STATE_RED);
MarkTileDirtyByTile(gp.new_tile); MarkTileDirtyByTile(gp.new_tile);
} }
} }
} }
if (v->Next() == NULL) { if (v->Next() == NULL) {
if (v->load_unload_ticks > 0 && distance == (TILE_SIZE * _settings_game.construction.simulated_wormhole_signals) - TILE_SIZE) HandleSignalBehindTrain(v, v->load_unload_ticks - 2); if (v->tunnel_bridge_signal_num > 0 && distance == (TILE_SIZE * _settings_game.construction.simulated_wormhole_signals) - TILE_SIZE) HandleSignalBehindTrain(v, v->tunnel_bridge_signal_num - 2);
if (old_tile == v->tile) { if (old_tile == v->tile) {
/* We left ramp into wormhole. */ /* We left ramp into wormhole. */
v->x_pos = gp.x; v->x_pos = gp.x;
@@ -3643,13 +3643,13 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse)
UnreserveBridgeTunnelTile(old_tile); UnreserveBridgeTunnelTile(old_tile);
} }
} }
if (distance == 0) v->load_unload_ticks++; if (distance == 0) v->tunnel_bridge_signal_num++;
v->wait_counter -= TILE_SIZE; v->wait_counter -= TILE_SIZE;
if (leaving) { // Reset counters. if (leaving) { // Reset counters.
v->force_proceed = 0; v->force_proceed = 0;
v->wait_counter = 0; v->wait_counter = 0;
v->load_unload_ticks = 0; v->tunnel_bridge_signal_num = 0;
v->x_pos = gp.x; v->x_pos = gp.x;
v->y_pos = gp.y; v->y_pos = gp.y;
v->UpdatePosition(); v->UpdatePosition();