Codechange: migrate all game-time-related timers to the new framework
This commit is contained in:
committed by
Patric Stout
parent
1ba4dcc924
commit
3ebc7ad16e
-108
@@ -158,111 +158,3 @@ Date ConvertYMDToDate(Year year, Month month, Day day)
|
||||
|
||||
return DAYS_TILL(year) + days;
|
||||
}
|
||||
|
||||
/** Functions used by the IncreaseDate function */
|
||||
|
||||
extern void EnginesDailyLoop();
|
||||
extern void DisasterDailyLoop();
|
||||
extern void IndustryDailyLoop();
|
||||
|
||||
extern void CompaniesMonthlyLoop();
|
||||
extern void EnginesMonthlyLoop();
|
||||
extern void TownsMonthlyLoop();
|
||||
extern void IndustryMonthlyLoop();
|
||||
extern void StationMonthlyLoop();
|
||||
extern void SubsidyMonthlyLoop();
|
||||
|
||||
extern void CompaniesYearlyLoop();
|
||||
extern void VehiclesYearlyLoop();
|
||||
extern void TownsYearlyLoop();
|
||||
|
||||
extern void ShowEndGameChart();
|
||||
|
||||
|
||||
/** Available settings for autosave intervals. */
|
||||
static const Month _autosave_months[] = {
|
||||
0, ///< never
|
||||
1, ///< every month
|
||||
3, ///< every 3 months
|
||||
6, ///< every 6 months
|
||||
12, ///< every 12 months
|
||||
};
|
||||
|
||||
/**
|
||||
* Runs various procedures that have to be done yearly
|
||||
*/
|
||||
static IntervalTimer<TimerGameCalendar> _on_new_year({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [](auto)
|
||||
{
|
||||
CompaniesYearlyLoop();
|
||||
VehiclesYearlyLoop();
|
||||
TownsYearlyLoop();
|
||||
InvalidateWindowClassesData(WC_BUILD_STATION);
|
||||
InvalidateWindowClassesData(WC_BUS_STATION);
|
||||
InvalidateWindowClassesData(WC_TRUCK_STATION);
|
||||
if (_network_server) NetworkServerYearlyLoop();
|
||||
|
||||
if (_cur_year == _settings_client.gui.semaphore_build_before) ResetSignalVariant();
|
||||
|
||||
/* check if we reached end of the game (end of ending year); 0 = never */
|
||||
if (_cur_year == _settings_game.game_creation.ending_year + 1 && _settings_game.game_creation.ending_year != 0) {
|
||||
ShowEndGameChart();
|
||||
}
|
||||
|
||||
/* check if we reached the maximum year, decrement dates by a year */
|
||||
if (_cur_year == MAX_YEAR + 1) {
|
||||
int days_this_year;
|
||||
|
||||
_cur_year--;
|
||||
days_this_year = IsLeapYear(_cur_year) ? DAYS_IN_LEAP_YEAR : DAYS_IN_YEAR;
|
||||
_date -= days_this_year;
|
||||
for (Vehicle *v : Vehicle::Iterate()) v->ShiftDates(-days_this_year);
|
||||
for (LinkGraph *lg : LinkGraph::Iterate()) lg->ShiftDates(-days_this_year);
|
||||
|
||||
/* Because the _date wraps here, and text-messages expire by game-days, we have to clean out
|
||||
* all of them if the date is set back, else those messages will hang for ever */
|
||||
NetworkInitChatMessage();
|
||||
}
|
||||
|
||||
if (_settings_client.gui.auto_euro) CheckSwitchToEuro();
|
||||
});
|
||||
|
||||
/**
|
||||
* Runs various procedures that have to be done monthly
|
||||
*/
|
||||
static IntervalTimer<TimerGameCalendar> _on_new_month({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::NONE}, [](auto)
|
||||
{
|
||||
if (_settings_client.gui.autosave != 0 && (_cur_month % _autosave_months[_settings_client.gui.autosave]) == 0) {
|
||||
_do_autosave = true;
|
||||
SetWindowDirty(WC_STATUS_BAR, 0);
|
||||
}
|
||||
|
||||
SetWindowClassesDirty(WC_CHEATS);
|
||||
CompaniesMonthlyLoop();
|
||||
EnginesMonthlyLoop();
|
||||
TownsMonthlyLoop();
|
||||
IndustryMonthlyLoop();
|
||||
SubsidyMonthlyLoop();
|
||||
StationMonthlyLoop();
|
||||
if (_network_server) NetworkServerMonthlyLoop();
|
||||
});
|
||||
|
||||
/**
|
||||
* Runs various procedures that have to be done daily
|
||||
*/
|
||||
static IntervalTimer<TimerGameCalendar> _on_new_day({TimerGameCalendar::DAY, TimerGameCalendar::Priority::NONE}, [](auto)
|
||||
{
|
||||
if (!_newgrf_profilers.empty() && _newgrf_profile_end_date <= _date) {
|
||||
NewGRFProfiler::FinishAll();
|
||||
}
|
||||
|
||||
if (_network_server) NetworkServerDailyLoop();
|
||||
|
||||
DisasterDailyLoop();
|
||||
IndustryDailyLoop();
|
||||
|
||||
SetWindowWidgetDirty(WC_STATUS_BAR, 0, WID_S_LEFT);
|
||||
EnginesDailyLoop();
|
||||
|
||||
/* Refresh after possible snowline change */
|
||||
SetWindowClassesDirty(WC_TOWN_VIEW);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user