From ca79a32890f4040be7da7d4c1109c15661d50d2f Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 20 Jun 2020 21:27:19 +0100 Subject: [PATCH] Scheduled dispatch: Fixup start dates when changing game date --- src/cheat_gui.cpp | 2 ++ src/date.cpp | 1 + src/order_base.h | 2 ++ src/order_cmd.cpp | 9 +++++++++ src/toolbar_gui.cpp | 1 + 5 files changed, 15 insertions(+) diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index bbfd2052eb..cbe1cd7e62 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -28,6 +28,7 @@ #include "newgrf.h" #include "error.h" #include "network/network.h" +#include "order_base.h" #include "widgets/cheat_widget.h" @@ -108,6 +109,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); SetDate(new_date, _date_fract); EnginesMonthlyLoop(); SetWindowDirty(WC_STATUS_BAR, 0); diff --git a/src/date.cpp b/src/date.cpp index 29c36dcb21..ef97a05289 100644 --- a/src/date.cpp +++ b/src/date.cpp @@ -231,6 +231,7 @@ static void OnNewYear() _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); /* 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/order_base.h b/src/order_base.h index 8e03a3f7d6..3fa8f3fffb 100644 --- a/src/order_base.h +++ b/src/order_base.h @@ -809,6 +809,8 @@ public: }; +void ShiftOrderDates(int interval); + #define FOR_VEHICLE_ORDERS(v, order) for (order = (v->orders.list == nullptr) ? nullptr : v->orders.list->GetFirstOrder(); order != nullptr; order = order->next) #endif /* ORDER_BASE_H */ diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index bfdee04b46..e895ca04b7 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -3004,3 +3004,12 @@ CommandCost CmdMassChangeOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, u } return CommandCost(); } + +void ShiftOrderDates(int interval) +{ + for (OrderList *orderlist : OrderList::Iterate()) { + if (orderlist->GetScheduledDispatchStartDatePart() >= 0) { + orderlist->SetScheduledDispatchStartDate(orderlist->GetScheduledDispatchStartDatePart() + interval, orderlist->GetScheduledDispatchStartDateFractPart()); + } + } +} diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index b32d14266b..ca0f3d8d74 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -1159,6 +1159,7 @@ void SetStartingYear(Year year) Date new_date = ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1); /* If you open a savegame as scenario there may already be link graphs.*/ LinkGraphSchedule::instance.ShiftDates(new_date - _date); + ShiftOrderDates(new_date - _date); SetDate(new_date, 0); }