From e6a858c0dc75dcb797e11d6882c6cb224fd43b70 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 24 Apr 2021 21:52:06 +0100 Subject: [PATCH] Fix date cheat/scenario load not adjusting vehicle date of last service --- src/cheat_gui.cpp | 2 ++ src/date.cpp | 2 +- src/toolbar_gui.cpp | 1 + src/vehicle.cpp | 7 +++++++ src/vehicle_base.h | 2 ++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index 301e5cab8b..7d7e3b0384 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -29,6 +29,7 @@ #include "error.h" #include "network/network.h" #include "order_base.h" +#include "vehicle_base.h" #include "currency.h" #include "widgets/cheat_widget.h" @@ -111,6 +112,7 @@ static int32 ClickChangeDateCheat(int32 p1, int32 p2) Date new_date = ConvertYMDToDate(p1, ymd.month, ymd.day); LinkGraphSchedule::instance.ShiftDates(new_date - _date); ShiftOrderDates(new_date - _date); + ShiftVehicleDates(new_date - _date); SetDate(new_date, _date_fract); EnginesMonthlyLoop(); InvalidateWindowClassesData(WC_BUILD_STATION, 0); diff --git a/src/date.cpp b/src/date.cpp index c3a3983baa..05cf97656f 100644 --- a/src/date.cpp +++ b/src/date.cpp @@ -228,9 +228,9 @@ static void OnNewYear() _cur_date_ymd.year--; days_this_year = IsLeapYear(_cur_date_ymd.year) ? DAYS_IN_LEAP_YEAR : DAYS_IN_YEAR; _date -= days_this_year; - for (Vehicle *v : Vehicle::Iterate()) v->date_of_last_service -= days_this_year; for (LinkGraph *lg : LinkGraph::Iterate()) lg->ShiftDates(-days_this_year); ShiftOrderDates(-days_this_year); + ShiftVehicleDates(-days_this_year); /* Because the _date wraps here, and text-messages expire by game-days, we have to clean out * all of them if the date is set back, else those messages will hang for ever */ diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 27e923400d..e8567f793e 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -1131,6 +1131,7 @@ void SetStartingYear(Year year) /* If you open a savegame as scenario there may already be link graphs.*/ LinkGraphSchedule::instance.ShiftDates(new_date - _date); ShiftOrderDates(new_date - _date); + ShiftVehicleDates(new_date - _date); SetDate(new_date, 0); } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 736ac3b26f..c81ff2e61f 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -4204,3 +4204,10 @@ void DumpVehicleStats(char *buffer, const char *last) buffer += seprintf(buffer, last, "\n"); } } + +void ShiftVehicleDates(int interval) +{ + for (Vehicle *v : Vehicle::Iterate()) { + v->date_of_last_service += interval; + } +} diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 375a86a879..1470679280 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -1427,4 +1427,6 @@ void ClearVehicleTickCaches(); void RemoveFromOtherVehicleTickCache(const Vehicle *v); void UpdateAllVehiclesIsDrawn(); +void ShiftVehicleDates(int interval); + #endif /* VEHICLE_BASE_H */