Scheduled dispatch: Fixup start dates when changing game date

pull/161/head
Jonathan G Rennison 4 years ago
parent d160536315
commit ca79a32890

@ -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);

@ -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 */

@ -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 */

@ -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());
}
}
}

@ -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);
}

Loading…
Cancel
Save