1
0
Fork 0

Codechange: Update both calendar and economy dates when changing date in Scenario Editor

pull/11588/head
Tyler Trahan 2023-09-11 09:57:11 -04:00
parent 308175d35a
commit 31352caba1
1 changed files with 12 additions and 4 deletions

View File

@ -1103,10 +1103,18 @@ void ToggleWidgetOutlines()
void SetStartingYear(TimerGameCalendar::Year year) void SetStartingYear(TimerGameCalendar::Year year)
{ {
_settings_game.game_creation.starting_year = Clamp(year, CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR); _settings_game.game_creation.starting_year = Clamp(year, CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR);
TimerGameCalendar::Date new_date = TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1); TimerGameCalendar::Date new_calendar_date = TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1);
/* If you open a savegame as scenario there may already be link graphs.*/ TimerGameEconomy::Date new_economy_date = new_calendar_date.base();
LinkGraphSchedule::instance.ShiftDates(new_date - TimerGameCalendar::date);
TimerGameCalendar::SetDate(new_date, 0); /* We must set both Calendar and Economy dates to keep them in sync. Calendar first. */
TimerGameCalendar::SetDate(new_calendar_date, 0);
/* If you open a savegame as a scenario, there may already be link graphs and/or vehicles. These use economy date. */
LinkGraphSchedule::instance.ShiftDates(new_economy_date - TimerGameEconomy::date);
for (auto v : Vehicle::Iterate()) v->ShiftDates(new_economy_date - TimerGameEconomy::date);
/* Only change the date after changing cached values above. */
TimerGameEconomy::SetDate(new_economy_date, 0);
} }
/** /**