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

Function ClickChangeDateCheat

src/cheat_gui.cpp:106–139  ·  view source on GitHub ↗

* Handle changing of the current year. * @param new_value The chosen year to change to. * @return New year. */

Source from the content-addressed store, hash-verified

104 * @return New year.
105 */
106static int32_t ClickChangeDateCheat(int32_t new_value, int32_t)
107{
108 /* Don't allow changing to an invalid year, or the current year. */
109 auto new_year = Clamp(TimerGameCalendar::Year(new_value), CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR);
110 if (new_year == TimerGameCalendar::year) return TimerGameCalendar::year.base();
111
112 TimerGameCalendar::YearMonthDay ymd = TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date);
113 TimerGameCalendar::Date new_calendar_date = TimerGameCalendar::ConvertYMDToDate(new_year, ymd.month, ymd.day);
114
115 TimerGameCalendar::SetDate(new_calendar_date, TimerGameCalendar::date_fract);
116
117 /* If not using wallclock units, we keep economy date in sync with calendar date and must change it also. */
118 if (!TimerGameEconomy::UsingWallclockUnits()) {
119 /* Keep economy and calendar dates synced. */
120 TimerGameEconomy::Date new_economy_date{new_calendar_date.base()};
121
122 /* Shift cached dates before we change the date. */
123 for (auto v : Vehicle::Iterate()) v->ShiftDates(new_economy_date - TimerGameEconomy::date);
124 LinkGraphSchedule::instance.ShiftDates(new_economy_date - TimerGameEconomy::date);
125
126 /* Now it's safe to actually change the date. */
127 TimerGameEconomy::SetDate(new_economy_date, TimerGameEconomy::date_fract);
128 }
129
130 CalendarEnginesMonthlyLoop();
131 SetWindowDirty(WC_STATUS_BAR, 0);
132 InvalidateWindowClassesData(WC_BUILD_STATION, 0);
133 InvalidateWindowClassesData(WC_BUS_STATION, 0);
134 InvalidateWindowClassesData(WC_TRUCK_STATION, 0);
135 InvalidateWindowClassesData(WC_BUILD_OBJECT, 0);
136 InvalidateWindowClassesData(WC_FINANCES, 0);
137 ResetSignalVariant();
138 return TimerGameCalendar::year.base();
139}
140
141/**
142 * Allow (or disallow) a change of the maximum allowed heightlevel.

Callers

nothing calls this directly

Calls 7

ClampFunction · 0.85
SetWindowDirtyFunction · 0.85
ResetSignalVariantFunction · 0.85
baseMethod · 0.45
ShiftDatesMethod · 0.45

Tested by

no test coverage detected