summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornchappe <74881848+nchappe@users.noreply.github.com>2021-11-19 00:04:22 +0000
committerGitHub <noreply@github.com>2021-11-19 00:04:22 +0000
commit2cb6351af596178ac3169baeffbc5a827f9aad5f (patch)
treee40780f85eb7ebb5d7e188626c9d6d82e6fd148d
parent0533b666b7036750ed0b004f22f933625391dd8e (diff)
downloadopenttd-2cb6351af596178ac3169baeffbc5a827f9aad5f.tar.xz
Fix: Update last servicing dates when using the date cheat (#9694)
-rw-r--r--src/cheat_gui.cpp2
-rw-r--r--src/date.cpp2
-rw-r--r--src/vehicle.cpp10
-rw-r--r--src/vehicle_base.h2
4 files changed, 15 insertions, 1 deletions
diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp
index 4821edbcc..a0ac5fab8 100644
--- a/src/cheat_gui.cpp
+++ b/src/cheat_gui.cpp
@@ -14,6 +14,7 @@
#include "company_func.h"
#include "date_func.h"
#include "saveload/saveload.h"
+#include "vehicle_base.h"
#include "textbuf_gui.h"
#include "window_gui.h"
#include "string_func.h"
@@ -106,6 +107,7 @@ static int32 ClickChangeDateCheat(int32 p1, int32 p2)
if (p1 == _cur_year) return _cur_year;
Date new_date = ConvertYMDToDate(p1, ymd.month, ymd.day);
+ for (auto v : Vehicle::Iterate()) v->ShiftDates(new_date - _date);
LinkGraphSchedule::instance.ShiftDates(new_date - _date);
SetDate(new_date, _date_fract);
EnginesMonthlyLoop();
diff --git a/src/date.cpp b/src/date.cpp
index 0fd98c42b..eac0c5f0b 100644
--- a/src/date.cpp
+++ b/src/date.cpp
@@ -211,7 +211,7 @@ static void OnNewYear()
_cur_year--;
days_this_year = IsLeapYear(_cur_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 (Vehicle *v : Vehicle::Iterate()) v->ShiftDates(-days_this_year);
for (LinkGraph *lg : LinkGraph::Iterate()) lg->ShiftDates(-days_this_year);
/* Because the _date wraps here, and text-messages expire by game-days, we have to clean out
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 9e2292751..30e1c477c 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -764,6 +764,16 @@ uint32 Vehicle::GetGRFID() const
}
/**
+ * Shift all dates by given interval.
+ * This is useful if the date has been modified with the cheat menu.
+ * @param interval Number of days to be added or substracted.
+ */
+void Vehicle::ShiftDates(int interval)
+{
+ this->date_of_last_service += interval;
+}
+
+/**
* Handle the pathfinding result, especially the lost status.
* If the vehicle is now lost and wasn't previously fire an
* event to the AIs and a news message to the user. If the
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index a5549b444..12acaa8ed 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -545,6 +545,8 @@ public:
*/
virtual void OnNewDay() {};
+ void ShiftDates(int interval);
+
/**
* Crash the (whole) vehicle chain.
* @param flooded whether the cause of the crash is flooding or not.