From f8a7b766752fbde59b9b01ba741db7863678430e Mon Sep 17 00:00:00 2001 From: Nicolas Chappe <74881848+nchappe@users.noreply.github.com> Date: Sat, 13 Nov 2021 20:09:05 +0100 Subject: [PATCH] Fix #9665: [Linkgraph] Fix travel times of non-direct journeys --- src/saveload/afterload.cpp | 7 +++++++ src/saveload/saveload.h | 1 + src/saveload/vehicle_sl.cpp | 1 + src/vehicle.cpp | 3 ++- src/vehicle_base.h | 1 + 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index acc16a1781..a68a6accc6 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -3148,6 +3148,13 @@ bool AfterLoadGame() } } + /* Use current order time to approximate last loading time */ + if (IsSavegameVersionBefore(SLV_LAST_LOADING_TICK)) { + for (Vehicle *v : Vehicle::Iterate()) { + v->last_loading_tick = std::max(_tick_counter, static_cast(v->current_order_time)) - v->current_order_time; + } + } + /* Compute station catchment areas. This is needed here in case UpdateStationAcceptance is called below. */ Station::RecomputeCatchmentForAll(); diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index c189407f67..19e1089430 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -341,6 +341,7 @@ enum SaveLoadVersion : uint16 { SLV_DOCK_DOCKINGTILES, ///< 298 PR#9578 All tiles around docks may be docking tiles. SLV_REPAIR_OBJECT_DOCKING_TILES, ///< 299 PR#9594 v12.0 Fixing issue with docking tiles overlapping objects. SLV_U64_TICK_COUNTER, ///< 300 PR#10035 Make _tick_counter 64bit to avoid wrapping. + SLV_LAST_LOADING_TICK, ///< 301 PR#9693 Store tick of last loading for vehicles. SL_MAX_VERSION, ///< Highest possible saveload version }; diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index 178275f54a..5254f94d21 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -705,6 +705,7 @@ public: SLE_CONDVAR(Vehicle, group_id, SLE_UINT16, SLV_60, SL_MAX_VERSION), SLE_CONDVAR(Vehicle, current_order_time, SLE_UINT32, SLV_67, SL_MAX_VERSION), + SLE_CONDVAR(Vehicle, last_loading_tick, SLE_UINT64, SLV_LAST_LOADING_TICK, SL_MAX_VERSION), SLE_CONDVAR(Vehicle, lateness_counter, SLE_INT32, SLV_67, SL_MAX_VERSION), }; #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916) diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 3673337058..af4d4d9ff1 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2114,7 +2114,7 @@ void Vehicle::BeginLoading() { assert(IsTileType(this->tile, MP_STATION) || this->type == VEH_SHIP); - uint32 travel_time = this->current_order_time; + Ticks travel_time = _tick_counter - this->last_loading_tick; if (this->current_order.IsType(OT_GOTO_STATION) && this->current_order.GetDestination() == this->last_station_visited) { this->DeleteUnreachedImplicitOrders(); @@ -2279,6 +2279,7 @@ void Vehicle::LeaveStation() /* if the vehicle could load here or could stop with cargo loaded set the last loading station */ this->last_loading_station = this->last_station_visited; + this->last_loading_tick = _tick_counter; } else { /* if the vehicle couldn't load and had to unload or transfer everything * set the last loading station to invalid as it will leave empty. */ diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 96dcfa2247..9316a76477 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -315,6 +315,7 @@ public: StationID last_station_visited; ///< The last station we stopped at. StationID last_loading_station; ///< Last station the vehicle has stopped at and could possibly leave from with any cargo loaded. + uint64_t last_loading_tick; ///< Last time (relative to _tick_counter) the vehicle has stopped at a station and could possibly leave with any cargo loaded. CargoID cargo_type; ///< type of cargo this vehicle is carrying byte cargo_subtype; ///< Used for livery refits (NewGRF variations)