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

Function ChangeTimekeepingUnits

src/settings_table.cpp:595–631  ·  view source on GitHub ↗

* Callback for when the player changes the timekeeping units. * @param Unused. */

Source from the content-addressed store, hash-verified

593 * @param Unused.
594 */
595static void ChangeTimekeepingUnits(int32_t)
596{
597 /* If service intervals are in time units (calendar days or real-world minutes), reset them to the correct defaults. */
598 if (!_settings_client.company.vehicle.servint_ispercent) {
599 UpdateAllServiceInterval(0);
600 }
601
602 /* If we are using calendar timekeeping, "minutes per year" must be default. */
603 if (!TimerGameEconomy::UsingWallclockUnits(true)) {
604 _settings_newgame.economy.minutes_per_calendar_year = CalendarTime::DEF_MINUTES_PER_YEAR;
605 }
606
607 InvalidateWindowClassesData(WC_GAME_OPTIONS, 0);
608
609 /* It is possible to change these units in Scenario Editor. We must set the economy date appropriately. */
610 if (_game_mode == GM_EDITOR) {
611 TimerGameEconomy::Date new_economy_date;
612 TimerGameEconomy::DateFract new_economy_date_fract;
613
614 if (TimerGameEconomy::UsingWallclockUnits()) {
615 /* If the new mode is wallclock units, set the economy year back to 1. */
616 new_economy_date = TimerGameEconomy::ConvertYMDToDate(TimerGameEconomy::Year{1}, 0, 1);
617 new_economy_date_fract = 0;
618 } else {
619 /* If the new mode is calendar units, sync the economy year with the calendar year. */
620 new_economy_date = TimerGameEconomy::Date{TimerGameCalendar::date.base()};
621 new_economy_date_fract = TimerGameCalendar::date_fract;
622 }
623
624 /* If you open a savegame as a scenario, there may already be link graphs and/or vehicles. These use economy date. */
625 LinkGraphSchedule::instance.ShiftDates(new_economy_date - TimerGameEconomy::date);
626 for (auto v : Vehicle::Iterate()) v->ShiftDates(new_economy_date - TimerGameEconomy::date);
627
628 /* Only change the date after changing cached values above. */
629 TimerGameEconomy::SetDate(new_economy_date, new_economy_date_fract);
630 }
631}
632
633/**
634 * Callback after the player changes the minutes per year.

Callers 1

ChangeMinutesPerYearFunction · 0.85

Calls 4

UpdateAllServiceIntervalFunction · 0.85
baseMethod · 0.45
ShiftDatesMethod · 0.45

Tested by

no test coverage detected