diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index 14d04549ac..1d120c2a28 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -92,7 +92,7 @@ static int32_t ClickSetProdCheat(int32_t new_value, int32_t) return _cheats.setup_prod.value; } -extern void EnginesMonthlyLoop(); +extern void CalendarEnginesMonthlyLoop(); /** * Handle changing of the current year. @@ -119,7 +119,7 @@ static int32_t ClickChangeDateCheat(int32_t new_value, int32_t) TimerGameCalendar::SetDate(new_calendar_date, TimerGameCalendar::date_fract); TimerGameEconomy::SetDate(new_economy_date, TimerGameEconomy::date_fract); - EnginesMonthlyLoop(); + CalendarEnginesMonthlyLoop(); SetWindowDirty(WC_STATUS_BAR, 0); InvalidateWindowClassesData(WC_BUILD_STATION, 0); InvalidateWindowClassesData(WC_BUS_STATION, 0); diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 0e13ea05e5..b3f3db23d6 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -36,7 +36,7 @@ #include "widgets/statusbar_widget.h" #include "company_cmd.h" #include "timer/timer.h" -#include "timer/timer_game_calendar.h" +#include "timer/timer_game_economy.h" #include "timer/timer_game_tick.h" #include "table/strings.h" @@ -746,7 +746,7 @@ void OnTick_Companies() * A year has passed, update the economic data of all companies, and perhaps show the * financial overview window of the local company. */ -static IntervalTimer _companies_yearly({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::COMPANY}, [](auto) +static IntervalTimer _economy_companies_yearly({TimerGameEconomy::YEAR, TimerGameEconomy::Priority::COMPANY}, [](auto) { /* Copy statistics */ for (Company *c : Company::Iterate()) { diff --git a/src/disaster_vehicle.cpp b/src/disaster_vehicle.cpp index 6d3ffc9e75..208dd85fc8 100644 --- a/src/disaster_vehicle.cpp +++ b/src/disaster_vehicle.cpp @@ -47,7 +47,7 @@ #include "core/backup_type.hpp" #include "landscape_cmd.h" #include "timer/timer.h" -#include "timer/timer_game_calendar.h" +#include "timer/timer_game_economy.h" #include "table/strings.h" @@ -936,7 +936,7 @@ static void ResetDisasterDelay() _disaster_delay = GB(Random(), 0, 9) + 730; } -static IntervalTimer _disaster_daily({TimerGameCalendar::DAY, TimerGameCalendar::Priority::DISASTER}, [](auto) +static IntervalTimer _economy_disaster_daily({TimerGameEconomy::DAY, TimerGameEconomy::Priority::DISASTER}, [](auto) { if (--_disaster_delay != 0) return; diff --git a/src/economy.cpp b/src/economy.cpp index ddd2cf9e4c..09de4a20ed 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -54,6 +54,7 @@ #include "vehicle_cmd.h" #include "timer/timer.h" #include "timer/timer_game_calendar.h" +#include "timer/timer_game_economy.h" #include "table/strings.h" #include "table/pricebase.h" @@ -1980,16 +1981,23 @@ void LoadUnloadStation(Station *st) } /** - * Monthly update of the economic data (of the companies as well as economic fluctuations). + * Every calendar month update of inflation. */ -static IntervalTimer _companies_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::COMPANY}, [](auto) +static IntervalTimer _calendar_inflation_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::COMPANY}, [](auto) { - CompaniesPayInterest(); - CompaniesGenStatistics(); if (_settings_game.economy.inflation) { AddInflation(); RecomputePrices(); } +}); + +/** + * Every economy month update of company economic data, plus economy fluctuations. + */ +static IntervalTimer _economy_companies_monthly({ TimerGameEconomy::MONTH, TimerGameEconomy::Priority::COMPANY }, [](auto) +{ + CompaniesGenStatistics(); + CompaniesPayInterest(); HandleEconomyFluctuations(); }); diff --git a/src/engine.cpp b/src/engine.cpp index bbccfa6ffd..de16911048 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -904,7 +904,7 @@ static bool IsVehicleTypeDisabled(VehicleType type, bool ai) } /** Daily check to offer an exclusive engine preview to the companies. */ -static IntervalTimer _engines_daily({TimerGameCalendar::DAY, TimerGameCalendar::Priority::ENGINE}, [](auto) +static IntervalTimer _calendar_engines_daily({TimerGameCalendar::DAY, TimerGameCalendar::Priority::ENGINE}, [](auto) { for (Company *c : Company::Iterate()) { c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes, TimerGameCalendar::date); @@ -1089,7 +1089,7 @@ static void NewVehicleAvailable(Engine *e) } /** Monthly update of the availability, reliability, and preview offers of the engines. */ -void EnginesMonthlyLoop() +void CalendarEnginesMonthlyLoop() { if (TimerGameCalendar::year < _year_engine_aging_stops) { bool refresh = false; @@ -1136,9 +1136,9 @@ void EnginesMonthlyLoop() } } -static IntervalTimer _engines_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::ENGINE}, [](auto) +static IntervalTimer _calendar_engines_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::ENGINE}, [](auto) { - EnginesMonthlyLoop(); + CalendarEnginesMonthlyLoop(); }); /** diff --git a/src/industry.h b/src/industry.h index bc6f79bb23..780dbec000 100644 --- a/src/industry.h +++ b/src/industry.h @@ -296,7 +296,7 @@ struct IndustryBuildData { void SetupTargetCount(); void TryBuildNewIndustry(); - void MonthlyLoop(); + void EconomyMonthlyLoop(); }; extern IndustryBuildData _industry_builder; diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index ebbc316dba..1e79ad78e6 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -45,6 +45,7 @@ #include "terraform_cmd.h" #include "timer/timer.h" #include "timer/timer_game_calendar.h" +#include "timer/timer_game_economy.h" #include "timer/timer_game_tick.h" #include "table/strings.h" @@ -2393,7 +2394,7 @@ void IndustryBuildData::Reset() } /** Monthly update of industry build data. */ -void IndustryBuildData::MonthlyLoop() +void IndustryBuildData::EconomyMonthlyLoop() { static const int NEWINDS_PER_MONTH = 0x38000 / (10 * 12); // lower 16 bits is a float fraction, 3.5 industries per decade, divided by 10 * 12 months. if (_settings_game.difficulty.industry_density == ID_FUND_ONLY) return; // 'no industries' setting. @@ -2970,13 +2971,13 @@ static void ChangeIndustryProduction(Industry *i, bool monthly) } /** - * Daily handler for the industry changes + * Every economy day handler for the industry changes * Taking the original map size of 256*256, the number of random changes was always of just one unit. * But it cannot be the same on smaller or bigger maps. That number has to be scaled up or down. * For small maps, it implies that less than one change per month is required, while on bigger maps, * it would be way more. The daily loop handles those changes. */ -static IntervalTimer _industries_daily({TimerGameCalendar::DAY, TimerGameCalendar::Priority::INDUSTRY}, [](auto) +static IntervalTimer _economy_industries_daily({TimerGameEconomy::DAY, TimerGameEconomy::Priority::INDUSTRY}, [](auto) { _economy.industry_daily_change_counter += _economy.industry_daily_increment; @@ -3018,11 +3019,11 @@ static IntervalTimer _industries_daily({TimerGameCalendar::DA InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_PRODUCTION_CHANGE); }); -static IntervalTimer _industries_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::INDUSTRY}, [](auto) +static IntervalTimer _economy_industries_monthly({TimerGameEconomy::MONTH, TimerGameEconomy::Priority::INDUSTRY}, [](auto) { Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); - _industry_builder.MonthlyLoop(); + _industry_builder.EconomyMonthlyLoop(); for (Industry *i : Industry::Iterate()) { UpdateIndustryStatistics(i); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 8a4960425e..91439d71eb 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -32,6 +32,7 @@ #include "../rev.h" #include "../timer/timer.h" #include "../timer/timer_game_calendar.h" +#include "../timer/timer_game_economy.h" #include #include @@ -1813,17 +1814,23 @@ void NetworkServer_Tick(bool send_frame) } } -/** Yearly "callback". Called whenever the year changes. */ -static IntervalTimer _network_yearly({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [](auto) -{ +/** Calendar yearly "callback". Called whenever the calendar year changes. */ +static IntervalTimer _calendar_network_yearly({ TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE }, [](auto) { if (!_network_server) return; NetworkCheckRestartMap(); +}); + +/** Economy yearly "callback". Called whenever the economy year changes. */ +static IntervalTimer _economy_network_yearly({TimerGameEconomy::YEAR, TimerGameEconomy::Priority::NONE}, [](auto) +{ + if (!_network_server) return; + NetworkAdminUpdate(ADMIN_FREQUENCY_ANUALLY); }); -/** Quarterly "callback". Called whenever the quarter changes. */ -static IntervalTimer _network_quarterly({TimerGameCalendar::QUARTER, TimerGameCalendar::Priority::NONE}, [](auto) +/** Quarterly "callback". Called whenever the economy quarter changes. */ +static IntervalTimer _network_quarterly({TimerGameEconomy::QUARTER, TimerGameEconomy::Priority::NONE}, [](auto) { if (!_network_server) return; @@ -1831,8 +1838,8 @@ static IntervalTimer _network_quarterly({TimerGameCalendar::Q NetworkAdminUpdate(ADMIN_FREQUENCY_QUARTERLY); }); -/** Monthly "callback". Called whenever the month changes. */ -static IntervalTimer _network_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::NONE}, [](auto) +/** Economy monthly "callback". Called whenever the economy month changes. */ +static IntervalTimer _network_monthly({TimerGameEconomy::MONTH, TimerGameEconomy::Priority::NONE}, [](auto) { if (!_network_server) return; @@ -1840,16 +1847,16 @@ static IntervalTimer _network_monthly({TimerGameCalendar::MON NetworkAdminUpdate(ADMIN_FREQUENCY_MONTHLY); }); -/** Weekly "callback". Called whenever the week changes. */ -static IntervalTimer _network_weekly({TimerGameCalendar::WEEK, TimerGameCalendar::Priority::NONE}, [](auto) +/** Economy weekly "callback". Called whenever the economy week changes. */ +static IntervalTimer _network_weekly({TimerGameEconomy::WEEK, TimerGameEconomy::Priority::NONE}, [](auto) { if (!_network_server) return; NetworkAdminUpdate(ADMIN_FREQUENCY_WEEKLY); }); -/** Daily "callback". Called whenever the date changes. */ -static IntervalTimer _network_daily({TimerGameCalendar::DAY, TimerGameCalendar::Priority::NONE}, [](auto) +/** Daily "callback". Called whenever the economy date changes. */ +static IntervalTimer _economy_network_daily({TimerGameEconomy::DAY, TimerGameEconomy::Priority::NONE}, [](auto) { if (!_network_server) return; diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 619bf02aea..834eae276b 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -63,6 +63,7 @@ #include "newgrf_roadstop.h" #include "timer/timer.h" #include "timer/timer_game_calendar.h" +#include "timer/timer_game_economy.h" #include "timer/timer_game_tick.h" #include "cheat_type.h" @@ -4002,8 +4003,8 @@ void OnTick_Station() } } -/** Monthly loop for stations. */ -static IntervalTimer _stations_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::STATION}, [](auto) +/** Economy monthly loop for stations. */ +static IntervalTimer _economy_stations_monthly({TimerGameEconomy::MONTH, TimerGameEconomy::Priority::STATION}, [](auto) { for (Station *st : Station::Iterate()) { for (GoodsEntry &ge : st->goods) { diff --git a/src/subsidy.cpp b/src/subsidy.cpp index 620a5c30be..3d9a60408e 100644 --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -27,7 +27,7 @@ #include "tile_cmd.h" #include "subsidy_cmd.h" #include "timer/timer.h" -#include "timer/timer_game_calendar.h" +#include "timer/timer_game_economy.h" #include "table/strings.h" @@ -474,8 +474,8 @@ bool FindSubsidyCargoDestination(CargoID cid, SourceType src_type, SourceID src) return true; } -/** Perform the monthly update of open subsidies, and try to create a new one. */ -static IntervalTimer _subsidies_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::SUBSIDY}, [](auto) +/** Perform the economy monthly update of open subsidies, and try to create a new one. */ +static IntervalTimer _economy_subsidies_monthly({TimerGameEconomy::MONTH, TimerGameEconomy::Priority::SUBSIDY}, [](auto) { bool modified = false; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 48fbf03940..fbb40c3b02 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -54,6 +54,7 @@ #include "tunnelbridge_cmd.h" #include "timer/timer.h" #include "timer/timer_game_calendar.h" +#include "timer/timer_game_economy.h" #include "timer/timer_game_tick.h" #include "table/strings.h" @@ -3837,7 +3838,7 @@ CommandCost CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType return CommandCost(); } -static IntervalTimer _towns_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::TOWN}, [](auto) +static IntervalTimer _economy_towns_monthly({TimerGameEconomy::MONTH, TimerGameEconomy::Priority::TOWN}, [](auto) { for (Town *t : Town::Iterate()) { /* Check for active town actions and decrement their counters. */ @@ -3864,7 +3865,7 @@ static IntervalTimer _towns_monthly({TimerGameCalendar::MONTH } }); -static IntervalTimer _towns_yearly({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::TOWN}, [](auto) +static IntervalTimer _economy_towns_yearly({TimerGameEconomy::YEAR, TimerGameEconomy::Priority::TOWN}, [](auto) { /* Increment house ages */ for (TileIndex t = 0; t < Map::Size(); t++) { diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 386b956b4f..0bf1e4a163 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -58,6 +58,7 @@ #include "newgrf_roadstop.h" #include "timer/timer.h" #include "timer/timer_game_calendar.h" +#include "timer/timer_game_economy.h" #include "timer/timer_game_tick.h" #include "table/strings.h" @@ -2800,7 +2801,7 @@ void Vehicle::RemoveFromShared() this->previous_shared = nullptr; } -static IntervalTimer _vehicles_yearly({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::VEHICLE}, [](auto) +static IntervalTimer _economy_vehicles_yearly({TimerGameEconomy::YEAR, TimerGameEconomy::Priority::VEHICLE}, [](auto) { for (Vehicle *v : Vehicle::Iterate()) { if (v->IsPrimaryVehicle()) {