1
0
Fork 0

Codechange: Sync economy and calendar dates when using date cheat

pull/11588/head
Tyler Trahan 2023-04-29 11:04:54 -04:00
parent 0a12ba9584
commit 308175d35a
1 changed files with 8 additions and 4 deletions

View File

@ -31,6 +31,7 @@
#include "core/geometry_func.hpp" #include "core/geometry_func.hpp"
#include "timer/timer.h" #include "timer/timer.h"
#include "timer/timer_game_calendar.h" #include "timer/timer_game_calendar.h"
#include "timer/timer_game_economy.h"
#include "widgets/cheat_widget.h" #include "widgets/cheat_widget.h"
@ -106,14 +107,17 @@ static int32_t ClickChangeDateCheat(int32_t new_value, int32_t)
TimerGameCalendar::YearMonthDay ymd; TimerGameCalendar::YearMonthDay ymd;
TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date, &ymd); TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date, &ymd);
TimerGameCalendar::Date new_date = TimerGameCalendar::ConvertYMDToDate(new_year, ymd.month, ymd.day); TimerGameCalendar::Date new_calendar_date = TimerGameCalendar::ConvertYMDToDate(new_year, ymd.month, ymd.day);
/* Keep economy and calendar dates synced. */
TimerGameEconomy::Date new_economy_date = new_calendar_date.base();
/* Shift cached dates before we change the date. */ /* Shift cached dates before we change the date. */
for (auto v : Vehicle::Iterate()) v->ShiftDates(new_date - TimerGameCalendar::date); for (auto v : Vehicle::Iterate()) v->ShiftDates(new_economy_date - TimerGameEconomy::date);
LinkGraphSchedule::instance.ShiftDates(new_date - TimerGameCalendar::date); LinkGraphSchedule::instance.ShiftDates(new_economy_date - TimerGameEconomy::date);
/* Now it's safe to actually change the date. */ /* Now it's safe to actually change the date. */
TimerGameCalendar::SetDate(new_date, TimerGameCalendar::date_fract); TimerGameCalendar::SetDate(new_calendar_date, TimerGameCalendar::date_fract);
TimerGameEconomy::SetDate(new_economy_date, TimerGameEconomy::date_fract);
EnginesMonthlyLoop(); EnginesMonthlyLoop();
SetWindowDirty(WC_STATUS_BAR, 0); SetWindowDirty(WC_STATUS_BAR, 0);