diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/date.cpp | 163 |
1 files changed, 93 insertions, 70 deletions
diff --git a/src/date.cpp b/src/date.cpp index 4420043ef..b9c47bfa2 100644 --- a/src/date.cpp +++ b/src/date.cpp @@ -180,6 +180,88 @@ static const Month _autosave_months[] = { }; /** + * Runs various procedures that have to be done yearly + */ +static void OnNewYear() +{ + CompaniesYearlyLoop(); + VehiclesYearlyLoop(); + TownsYearlyLoop(); + InvalidateWindowClassesData(WC_BUILD_STATION); +#ifdef ENABLE_NETWORK + if (_network_server) NetworkServerYearlyLoop(); +#endif /* ENABLE_NETWORK */ + + if (_cur_year == _settings_client.gui.semaphore_build_before) ResetSignalVariant(); + + /* check if we reached end of the game */ + if (_cur_year == ORIGINAL_END_YEAR) { + ShowEndGameChart(); + /* check if we reached the maximum year, decrement dates by a year */ + } else if (_cur_year == MAX_YEAR + 1) { + Vehicle *v; + uint days_this_year; + + _cur_year--; + days_this_year = IsLeapYear(_cur_year) ? DAYS_IN_LEAP_YEAR : DAYS_IN_YEAR; + _date -= days_this_year; + FOR_ALL_VEHICLES(v) v->date_of_last_service -= days_this_year; + +#ifdef ENABLE_NETWORK + /* 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(); +#endif /* ENABLE_NETWORK */ + } + + if (_settings_client.gui.auto_euro) CheckSwitchToEuro(); +} + +/** + * Runs various procedures that have to be done monthly + */ +static void OnNewMonth() +{ + if (_debug_desync_level > 2) { + char name[MAX_PATH]; + snprintf(name, lengthof(name), "dmp_cmds_%08x_%08x.sav", _settings_game.game_creation.generation_seed, _date); + SaveOrLoad(name, SL_SAVE, AUTOSAVE_DIR); + } + + if (_settings_client.gui.autosave != 0 && (_cur_month % _autosave_months[_settings_client.gui.autosave]) == 0) { + _do_autosave = true; + RedrawAutosave(); + } + + InvalidateWindowClasses(WC_CHEATS); + CompaniesMonthlyLoop(); + SubsidyMonthlyLoop(); + EnginesMonthlyLoop(); + TownsMonthlyLoop(); + IndustryMonthlyLoop(); + StationMonthlyLoop(); +#ifdef ENABLE_NETWORK + if (_network_server) NetworkServerMonthlyLoop(); +#endif /* ENABLE_NETWORK */ +} + +/** + * Runs various procedures that have to be done daily + */ +static void OnNewDay() +{ +#ifdef ENABLE_NETWORK + NetworkChatMessageDailyLoop(); +#endif /* ENABLE_NETWORK */ + + DisasterDailyLoop(); + IndustryDailyLoop(); + + InvalidateWindowWidget(WC_STATUS_BAR, 0, 0); + EnginesDailyLoop(); +} + +/** * Runs the day_proc for every DAY_TICKS vehicle starting at daytick. */ static void RunVehicleDayProc(uint daytick) @@ -195,10 +277,12 @@ static void RunVehicleDayProc(uint daytick) } } +/** + * Increases the tick counter, increases date and possibly calls + * procedures that have to be called daily, monthly or yearly. + */ void IncreaseDate() { - YearMonthDay ymd; - if (_game_mode == GM_MENU) { _tick_counter++; return; @@ -213,85 +297,24 @@ void IncreaseDate() if (_date_fract < DAY_TICKS) return; _date_fract = 0; - /* yeah, increase day counter and call various daily loops */ + /* increase day counter and call various daily loops */ _date++; + OnNewDay(); -#ifdef ENABLE_NETWORK - NetworkChatMessageDailyLoop(); -#endif /* ENABLE_NETWORK */ - - DisasterDailyLoop(); - IndustryDailyLoop(); - - if (_game_mode != GM_MENU) { - InvalidateWindowWidget(WC_STATUS_BAR, 0, 0); - EnginesDailyLoop(); - } + YearMonthDay ymd; /* check if we entered a new month? */ ConvertDateToYMD(_date, &ymd); if (ymd.month == _cur_month) return; - _cur_month = ymd.month; /* yes, call various monthly loops */ - if (_game_mode != GM_MENU) { - if (_debug_desync_level > 2) { - char name[MAX_PATH]; - snprintf(name, lengthof(name), "dmp_cmds_%08x_%08x.sav", _settings_game.game_creation.generation_seed, _date); - SaveOrLoad(name, SL_SAVE, AUTOSAVE_DIR); - } - - if (_settings_client.gui.autosave != 0 && (_cur_month % _autosave_months[_settings_client.gui.autosave]) == 0) { - _do_autosave = true; - RedrawAutosave(); - } - - InvalidateWindowClasses(WC_CHEATS); - CompaniesMonthlyLoop(); - SubsidyMonthlyLoop(); - EnginesMonthlyLoop(); - TownsMonthlyLoop(); - IndustryMonthlyLoop(); - StationMonthlyLoop(); -#ifdef ENABLE_NETWORK - if (_network_server) NetworkServerMonthlyLoop(); -#endif /* ENABLE_NETWORK */ - } + _cur_month = ymd.month; + OnNewMonth(); /* check if we entered a new year? */ if (ymd.year == _cur_year) return; - _cur_year = ymd.year; /* yes, call various yearly loops */ - CompaniesYearlyLoop(); - VehiclesYearlyLoop(); - TownsYearlyLoop(); - InvalidateWindowClassesData(WC_BUILD_STATION); -#ifdef ENABLE_NETWORK - if (_network_server) NetworkServerYearlyLoop(); -#endif /* ENABLE_NETWORK */ - - if (_cur_year == _settings_client.gui.semaphore_build_before) ResetSignalVariant(); - - /* check if we reached end of the game */ - if (_cur_year == ORIGINAL_END_YEAR) { - ShowEndGameChart(); - /* check if we reached the maximum year, decrement dates by a year */ - } else if (_cur_year == MAX_YEAR + 1) { - Vehicle *v; - uint days_this_year; - - _cur_year--; - days_this_year = IsLeapYear(_cur_year) ? DAYS_IN_LEAP_YEAR : DAYS_IN_YEAR; - _date -= days_this_year; - FOR_ALL_VEHICLES(v) v->date_of_last_service -= days_this_year; - -#ifdef ENABLE_NETWORK - /* 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(); -#endif /* ENABLE_NETWORK */ - } - - if (_settings_client.gui.auto_euro) CheckSwitchToEuro(); + _cur_year = ymd.year; + OnNewYear(); } |