MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / SetStartingYear

Function SetStartingYear

src/toolbar_gui.cpp:1133–1148  ·  view source on GitHub ↗

* Set the starting year for a scenario. * @param year New starting year. */

Source from the content-addressed store, hash-verified

1131 * @param year New starting year.
1132 */
1133void SetStartingYear(TimerGameCalendar::Year year)
1134{
1135 _settings_game.game_creation.starting_year = Clamp(year, CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR);
1136 TimerGameCalendar::Date new_calendar_date = TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1);
1137 TimerGameEconomy::Date new_economy_date{new_calendar_date.base()};
1138
1139 /* We must set both Calendar and Economy dates to keep them in sync. Calendar first. */
1140 TimerGameCalendar::SetDate(new_calendar_date, 0);
1141
1142 /* If you open a savegame as a scenario, there may already be link graphs and/or vehicles. These use economy date. */
1143 LinkGraphSchedule::instance.ShiftDates(new_economy_date - TimerGameEconomy::date);
1144 for (auto v : Vehicle::Iterate()) v->ShiftDates(new_economy_date - TimerGameEconomy::date);
1145
1146 /* Only change the date after changing cached values above. */
1147 TimerGameEconomy::SetDate(new_economy_date, 0);
1148}
1149
1150/**
1151 * Choose the proper callback function for the main toolbar's help menu.

Callers 3

ToolbarScenDateBackwardFunction · 0.85
ToolbarScenDateForwardFunction · 0.85
OnQueryTextFinishedMethod · 0.85

Calls 3

ClampFunction · 0.85
baseMethod · 0.45
ShiftDatesMethod · 0.45

Tested by

no test coverage detected