mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Split daily/monthly/yearly timers into economy and calendar timers
parent
31352caba1
commit
feacf0c2fc
|
@ -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);
|
||||
|
|
|
@ -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<TimerGameCalendar> _companies_yearly({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::COMPANY}, [](auto)
|
||||
static IntervalTimer<TimerGameEconomy> _economy_companies_yearly({TimerGameEconomy::YEAR, TimerGameEconomy::Priority::COMPANY}, [](auto)
|
||||
{
|
||||
/* Copy statistics */
|
||||
for (Company *c : Company::Iterate()) {
|
||||
|
|
|
@ -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<TimerGameCalendar> _disaster_daily({TimerGameCalendar::DAY, TimerGameCalendar::Priority::DISASTER}, [](auto)
|
||||
static IntervalTimer<TimerGameEconomy> _economy_disaster_daily({TimerGameEconomy::DAY, TimerGameEconomy::Priority::DISASTER}, [](auto)
|
||||
{
|
||||
if (--_disaster_delay != 0) return;
|
||||
|
||||
|
|
|
@ -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<TimerGameCalendar> _companies_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::COMPANY}, [](auto)
|
||||
static IntervalTimer<TimerGameCalendar> _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<TimerGameEconomy> _economy_companies_monthly({ TimerGameEconomy::MONTH, TimerGameEconomy::Priority::COMPANY }, [](auto)
|
||||
{
|
||||
CompaniesGenStatistics();
|
||||
CompaniesPayInterest();
|
||||
HandleEconomyFluctuations();
|
||||
});
|
||||
|
||||
|
|
|
@ -904,7 +904,7 @@ static bool IsVehicleTypeDisabled(VehicleType type, bool ai)
|
|||
}
|
||||
|
||||
/** Daily check to offer an exclusive engine preview to the companies. */
|
||||
static IntervalTimer<TimerGameCalendar> _engines_daily({TimerGameCalendar::DAY, TimerGameCalendar::Priority::ENGINE}, [](auto)
|
||||
static IntervalTimer<TimerGameCalendar> _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<TimerGameCalendar> _engines_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::ENGINE}, [](auto)
|
||||
static IntervalTimer<TimerGameCalendar> _calendar_engines_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::ENGINE}, [](auto)
|
||||
{
|
||||
EnginesMonthlyLoop();
|
||||
CalendarEnginesMonthlyLoop();
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
|
@ -296,7 +296,7 @@ struct IndustryBuildData {
|
|||
void SetupTargetCount();
|
||||
void TryBuildNewIndustry();
|
||||
|
||||
void MonthlyLoop();
|
||||
void EconomyMonthlyLoop();
|
||||
};
|
||||
|
||||
extern IndustryBuildData _industry_builder;
|
||||
|
|
|
@ -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<TimerGameCalendar> _industries_daily({TimerGameCalendar::DAY, TimerGameCalendar::Priority::INDUSTRY}, [](auto)
|
||||
static IntervalTimer<TimerGameEconomy> _economy_industries_daily({TimerGameEconomy::DAY, TimerGameEconomy::Priority::INDUSTRY}, [](auto)
|
||||
{
|
||||
_economy.industry_daily_change_counter += _economy.industry_daily_increment;
|
||||
|
||||
|
@ -3018,11 +3019,11 @@ static IntervalTimer<TimerGameCalendar> _industries_daily({TimerGameCalendar::DA
|
|||
InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_PRODUCTION_CHANGE);
|
||||
});
|
||||
|
||||
static IntervalTimer<TimerGameCalendar> _industries_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::INDUSTRY}, [](auto)
|
||||
static IntervalTimer<TimerGameEconomy> _economy_industries_monthly({TimerGameEconomy::MONTH, TimerGameEconomy::Priority::INDUSTRY}, [](auto)
|
||||
{
|
||||
Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
|
||||
|
||||
_industry_builder.MonthlyLoop();
|
||||
_industry_builder.EconomyMonthlyLoop();
|
||||
|
||||
for (Industry *i : Industry::Iterate()) {
|
||||
UpdateIndustryStatistics(i);
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "../rev.h"
|
||||
#include "../timer/timer.h"
|
||||
#include "../timer/timer_game_calendar.h"
|
||||
#include "../timer/timer_game_economy.h"
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
|
@ -1813,17 +1814,23 @@ void NetworkServer_Tick(bool send_frame)
|
|||
}
|
||||
}
|
||||
|
||||
/** Yearly "callback". Called whenever the year changes. */
|
||||
static IntervalTimer<TimerGameCalendar> _network_yearly({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [](auto)
|
||||
{
|
||||
/** Calendar yearly "callback". Called whenever the calendar year changes. */
|
||||
static IntervalTimer<TimerGameCalendar> _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<TimerGameEconomy> _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<TimerGameCalendar> _network_quarterly({TimerGameCalendar::QUARTER, TimerGameCalendar::Priority::NONE}, [](auto)
|
||||
/** Quarterly "callback". Called whenever the economy quarter changes. */
|
||||
static IntervalTimer<TimerGameEconomy> _network_quarterly({TimerGameEconomy::QUARTER, TimerGameEconomy::Priority::NONE}, [](auto)
|
||||
{
|
||||
if (!_network_server) return;
|
||||
|
||||
|
@ -1831,8 +1838,8 @@ static IntervalTimer<TimerGameCalendar> _network_quarterly({TimerGameCalendar::Q
|
|||
NetworkAdminUpdate(ADMIN_FREQUENCY_QUARTERLY);
|
||||
});
|
||||
|
||||
/** Monthly "callback". Called whenever the month changes. */
|
||||
static IntervalTimer<TimerGameCalendar> _network_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::NONE}, [](auto)
|
||||
/** Economy monthly "callback". Called whenever the economy month changes. */
|
||||
static IntervalTimer<TimerGameEconomy> _network_monthly({TimerGameEconomy::MONTH, TimerGameEconomy::Priority::NONE}, [](auto)
|
||||
{
|
||||
if (!_network_server) return;
|
||||
|
||||
|
@ -1840,16 +1847,16 @@ static IntervalTimer<TimerGameCalendar> _network_monthly({TimerGameCalendar::MON
|
|||
NetworkAdminUpdate(ADMIN_FREQUENCY_MONTHLY);
|
||||
});
|
||||
|
||||
/** Weekly "callback". Called whenever the week changes. */
|
||||
static IntervalTimer<TimerGameCalendar> _network_weekly({TimerGameCalendar::WEEK, TimerGameCalendar::Priority::NONE}, [](auto)
|
||||
/** Economy weekly "callback". Called whenever the economy week changes. */
|
||||
static IntervalTimer<TimerGameEconomy> _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<TimerGameCalendar> _network_daily({TimerGameCalendar::DAY, TimerGameCalendar::Priority::NONE}, [](auto)
|
||||
/** Daily "callback". Called whenever the economy date changes. */
|
||||
static IntervalTimer<TimerGameEconomy> _economy_network_daily({TimerGameEconomy::DAY, TimerGameEconomy::Priority::NONE}, [](auto)
|
||||
{
|
||||
if (!_network_server) return;
|
||||
|
||||
|
|
|
@ -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<TimerGameCalendar> _stations_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::STATION}, [](auto)
|
||||
/** Economy monthly loop for stations. */
|
||||
static IntervalTimer<TimerGameEconomy> _economy_stations_monthly({TimerGameEconomy::MONTH, TimerGameEconomy::Priority::STATION}, [](auto)
|
||||
{
|
||||
for (Station *st : Station::Iterate()) {
|
||||
for (GoodsEntry &ge : st->goods) {
|
||||
|
|
|
@ -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<TimerGameCalendar> _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<TimerGameEconomy> _economy_subsidies_monthly({TimerGameEconomy::MONTH, TimerGameEconomy::Priority::SUBSIDY}, [](auto)
|
||||
{
|
||||
bool modified = false;
|
||||
|
||||
|
|
|
@ -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<TimerGameCalendar> _towns_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::TOWN}, [](auto)
|
||||
static IntervalTimer<TimerGameEconomy> _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<TimerGameCalendar> _towns_monthly({TimerGameCalendar::MONTH
|
|||
}
|
||||
});
|
||||
|
||||
static IntervalTimer<TimerGameCalendar> _towns_yearly({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::TOWN}, [](auto)
|
||||
static IntervalTimer<TimerGameEconomy> _economy_towns_yearly({TimerGameEconomy::YEAR, TimerGameEconomy::Priority::TOWN}, [](auto)
|
||||
{
|
||||
/* Increment house ages */
|
||||
for (TileIndex t = 0; t < Map::Size(); t++) {
|
||||
|
|
|
@ -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<TimerGameCalendar> _vehicles_yearly({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::VEHICLE}, [](auto)
|
||||
static IntervalTimer<TimerGameEconomy> _economy_vehicles_yearly({TimerGameEconomy::YEAR, TimerGameEconomy::Priority::VEHICLE}, [](auto)
|
||||
{
|
||||
for (Vehicle *v : Vehicle::Iterate()) {
|
||||
if (v->IsPrimaryVehicle()) {
|
||||
|
|
Loading…
Reference in New Issue