From 52a2dd339c2be3fbd66bf2cb372b4c34f6c41aa6 Mon Sep 17 00:00:00 2001 From: keldorkatarn Date: Sun, 22 Apr 2018 06:23:02 +0200 Subject: [PATCH] FIX: Timetable updating and automating didn't work properly for load times. --- src/base_consist.cpp | 1 + src/base_consist.h | 2 +- src/saveload/saveload.cpp | 3 ++- src/saveload/saveload.h | 1 + src/saveload/vehicle_sl.cpp | 1 + src/timetable_cmd.cpp | 8 +++----- src/vehicle.cpp | 7 ++++++- 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/base_consist.cpp b/src/base_consist.cpp index 1ae7cf225..0a05e062e 100644 --- a/src/base_consist.cpp +++ b/src/base_consist.cpp @@ -33,6 +33,7 @@ void BaseConsist::CopyConsistPropertiesFrom(const BaseConsist *src) this->name = src->name != NULL ? stredup(src->name) : NULL; this->current_order_time = src->current_order_time; + this->current_loading_time = src->current_loading_time; this->lateness_counter = src->lateness_counter; this->timetable_start = src->timetable_start; diff --git a/src/base_consist.h b/src/base_consist.h index 5c20598e2..6502d40bc 100644 --- a/src/base_consist.h +++ b/src/base_consist.h @@ -21,7 +21,7 @@ struct BaseConsist { /* Used for timetabling. */ uint32 current_order_time; ///< How many ticks have passed since this order started. - uint32 current_loading_time; ///< (outdated. Only for backwards compatibility) + uint32 current_loading_time; ///< Used for timetabling int32 lateness_counter; ///< How many ticks late (or early if negative) this vehicle is. Date timetable_start; ///< When the vehicle is supposed to start the timetable. diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 28ecebbe4..c84bd61b4 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -300,8 +300,9 @@ * 279 SL_PATCH_PACK_1_20 * 280 SL_PATCH_PACK_1_21 * 281 SL_PATCH_PACK_1_22 + * 282 SL_PATCH_PACK_1_23 */ -extern const uint16 SAVEGAME_VERSION = SL_PATCH_PACK_1_22; ///< Current savegame version of OpenTTD. +extern const uint16 SAVEGAME_VERSION = SL_PATCH_PACK_1_23; ///< Current savegame version of OpenTTD. SavegameType _savegame_type; ///< type of savegame we are loading FileToSaveLoad _file_to_saveload; ///< File to save or load in the openttd loop. diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 29337f207..8c4a3c287 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -123,6 +123,7 @@ enum SLRefType { #define SL_PATCH_PACK_1_20 279 #define SL_PATCH_PACK_1_21 280 #define SL_PATCH_PACK_1_22 281 +#define SL_PATCH_PACK_1_23 282 /** Flags of a chunk. */ enum ChunkType { diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index 69496ff81..c1daccca4 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -713,6 +713,7 @@ const SaveLoad *GetVehicleDescription(VehicleType vt) SLE_CONDVAR(Vehicle, current_order_time, SLE_UINT32, 67, SL_MAX_VERSION), SLE_CONDVAR(Vehicle, current_loading_time, SLE_UINT32, SL_PATCH_PACK, SL_PATCH_PACK_1_5), + SLE_CONDVAR(Vehicle, current_loading_time, SLE_UINT32, SL_PATCH_PACK_1_23, SL_MAX_VERSION), SLE_CONDVAR(Vehicle, lateness_counter, SLE_INT32, 67, SL_MAX_VERSION), SLE_CONDNULL(10, 2, 143), // old reserved space diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index cb0942c3f..8db7a090a 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -559,19 +559,17 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling) /* Before modifying waiting times, check whether we want to preserve bigger ones. */ if (!real_current_order->IsType(OT_CONDITIONAL) && - (travelling || time_taken > real_current_order->GetWaitTime() || remeasure_wait_time)) { + (travelling || time_loading > real_current_order->GetWaitTime() || remeasure_wait_time)) { /* For trains/aircraft multiple movement cycles are done in one * tick. This makes it possible to leave the station and process * e.g. a depot order in the same tick, causing it to not fill * the timetable entry like is done for road vehicles/ships. * Thus always make sure at least one tick is used between the * processing of different orders when filling the timetable. */ - uint time_to_set = max(time_taken, 1U); - if (travelling && !real_current_order->IsTravelTimetabled()) { - ChangeTimetable(v, v->cur_real_order_index, time_to_set, MTF_TRAVEL_TIME, false); + ChangeTimetable(v, v->cur_real_order_index, max(time_taken, 1U), MTF_TRAVEL_TIME, false); } else if (!travelling && !real_current_order->IsWaitTimetabled()) { - ChangeTimetable(v, v->cur_real_order_index, time_to_set, MTF_WAIT_TIME, false); + ChangeTimetable(v, v->cur_real_order_index, max(time_loading, 1U), MTF_WAIT_TIME, false); } } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index dd7fdecd7..d38f5abbb 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2653,7 +2653,12 @@ void Vehicle::HandleLoading(bool mode) switch (current_order_type) { case OT_LOADING: { - uint wait_time = max(this->current_order.GetTimetabledWait() - this->lateness_counter, 0); + uint wait_time = max(this->current_order.GetTimetabledWait() - this->lateness_counter, 0); + + /* Save time just loading took since that is what goes into the timetable */ + if (!HasBit(this->vehicle_flags, VF_LOADING_FINISHED)) { + this->current_loading_time = this->current_order_time; + } bool has_manual_depot_order = (HasBit(this->vehicle_flags, VF_SHOULD_GOTO_DEPOT) || HasBit(this->vehicle_flags, VF_SHOULD_SERVICE_AT_DEPOT)); -- 2.11.4.GIT