Changeset - r27090:1ea30951c0f3
[Not reviewed]
master
0 25 0
Patric Stout - 20 months ago 2023-04-13 11:56:00
truebrain@openttd.org
Codechange: migrate all game-time-related timers to the new framework
25 files changed with 168 insertions and 147 deletions:
0 comments (0 inline, 0 general)
src/airport_gui.cpp
Show inline comments
 
@@ -28,12 +28,14 @@
 
#include "vehicle_func.h"
 
#include "gui.h"
 
#include "command_func.h"
 
#include "airport_cmd.h"
 
#include "station_cmd.h"
 
#include "zoom_func.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include "widgets/airport_widget.h"
 

	
 
#include "safeguards.h"
 

	
 

	
 
@@ -578,12 +580,16 @@ public:
 
	}
 

	
 
	void OnRealtimeTick(uint delta_ms) override
 
	{
 
		CheckRedrawStationCoverage(this);
 
	}
 

	
 
	IntervalTimer<TimerGameCalendar> yearly_interval = {{TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [this](auto) {
 
		this->InvalidateData();
 
	}};
 
};
 

	
 
static const NWidgetPart _nested_build_airport_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
 
		NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_AIRPORT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
src/cheat_gui.cpp
Show inline comments
 
@@ -27,12 +27,14 @@
 
#include "map_func.h"
 
#include "tile_map.h"
 
#include "newgrf.h"
 
#include "error.h"
 
#include "misc_cmd.h"
 
#include "core/geometry_func.hpp"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include "widgets/cheat_widget.h"
 

	
 
#include "table/sprites.h"
 

	
 
#include "safeguards.h"
 
@@ -414,12 +416,16 @@ struct CheatWindow : Window {
 
		*ce->been_used = true;
 
		value = ce->proc(value, value - oldvalue);
 

	
 
		if (value != oldvalue) WriteValue(ce->variable, ce->type, (int64)value);
 
		this->SetDirty();
 
	}
 

	
 
	IntervalTimer<TimerGameCalendar> daily_interval = {{TimerGameCalendar::MONTH, TimerGameCalendar::Priority::NONE}, [this](auto) {
 
		this->SetDirty();
 
	}};
 
};
 

	
 
/** Window description of the cheats GUI. */
 
static WindowDesc _cheats_desc(
 
	WDP_AUTO, "cheats", 0, 0,
 
	WC_CHEATS, WC_NONE,
src/company_cmd.cpp
Show inline comments
 
@@ -33,12 +33,14 @@
 
#include "smallmap_gui.h"
 
#include "game/game.hpp"
 
#include "goal_base.h"
 
#include "story_base.h"
 
#include "widgets/statusbar_widget.h"
 
#include "company_cmd.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "safeguards.h"
 

	
 
void ClearEnginesHiddenFlagOfCompany(CompanyID cid);
 
@@ -740,13 +742,13 @@ 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.
 
 */
 
void CompaniesYearlyLoop()
 
static IntervalTimer<TimerGameCalendar> _companies_yearly({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::COMPANY}, [](auto)
 
{
 
	/* Copy statistics */
 
	for (Company *c : Company::Iterate()) {
 
		memmove(&c->yearly_expenses[1], &c->yearly_expenses[0], sizeof(c->yearly_expenses) - sizeof(c->yearly_expenses[0]));
 
		memset(&c->yearly_expenses[0], 0, sizeof(c->yearly_expenses[0]));
 
		SetWindowDirty(WC_FINANCES, c->index);
 
@@ -758,13 +760,13 @@ void CompaniesYearlyLoop()
 
		if (c->num_valid_stat_ent > 5 && c->old_economy[0].performance_history < c->old_economy[4].performance_history) {
 
			if (_settings_client.sound.new_year) SndPlayFx(SND_01_BAD_YEAR);
 
		} else {
 
			if (_settings_client.sound.new_year) SndPlayFx(SND_00_GOOD_YEAR);
 
		}
 
	}
 
}
 
});
 

	
 
/**
 
 * Fill the CompanyNewsInformation struct with the required data.
 
 * @param c the current company.
 
 * @param other the other company (use \c nullptr if not relevant).
 
 */
src/currency.cpp
Show inline comments
 
@@ -12,12 +12,14 @@
 

	
 
#include "currency.h"
 
#include "news_func.h"
 
#include "settings_type.h"
 
#include "date_func.h"
 
#include "string_type.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "safeguards.h"
 

	
 
	/*   exchange rate    prefix                         symbol_pos
 
@@ -135,21 +137,21 @@ uint64 GetMaskOfAllowedCurrencies()
 
	return mask;
 
}
 

	
 
/**
 
 * Verify if the currency chosen by the user is about to be converted to Euro
 
 */
 
void CheckSwitchToEuro()
 
static IntervalTimer<TimerGameCalendar> _check_switch_to_euro({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [](auto)
 
{
 
	if (_currency_specs[_settings_game.locale.currency].to_euro != CF_NOEURO &&
 
			_currency_specs[_settings_game.locale.currency].to_euro != CF_ISEURO &&
 
			_cur_year >= _currency_specs[_settings_game.locale.currency].to_euro) {
 
		_settings_game.locale.currency = 2; // this is the index of euro above.
 
		AddNewsItem(STR_NEWS_EURO_INTRODUCTION, NT_ECONOMY, NF_NORMAL);
 
	}
 
}
 
});
 

	
 
/**
 
 * Will fill _currency_specs array with
 
 * default values from origin_currency_specs
 
 * Called only from newgrf.cpp and settings.cpp.
 
 * @param preserve_custom will not reset custom currency
src/currency.h
Show inline comments
 
@@ -99,12 +99,11 @@ extern CurrencySpec _currency_specs[CURR
 

	
 
/* XXX small hack, but makes the rest of the code a bit nicer to read */
 
#define _custom_currency (_currency_specs[CURRENCY_CUSTOM])
 
#define _currency ((const CurrencySpec*)&_currency_specs[GetGameSettings().locale.currency])
 

	
 
uint64 GetMaskOfAllowedCurrencies();
 
void CheckSwitchToEuro();
 
void ResetCurrencies(bool preserve_custom = true);
 
StringID *BuildCurrencyDropdown();
 
byte GetNewgrfCurrencyIdConverted(byte grfcurr_id);
 

	
 
#endif /* CURRENCY_H */
src/date.cpp
Show inline comments
 
@@ -155,114 +155,6 @@ Date ConvertYMDToDate(Year year, Month m
 

	
 
	/* Account for the missing of the 29th of February in non-leap years */
 
	if (!IsLeapYear(year) && days >= ACCUM_MAR) days--;
 

	
 
	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);
 
});
src/disaster_vehicle.cpp
Show inline comments
 
@@ -44,12 +44,14 @@
 
#include "ai/ai.hpp"
 
#include "game/game.hpp"
 
#include "company_base.h"
 
#include "core/random_func.hpp"
 
#include "core/backup_type.hpp"
 
#include "landscape_cmd.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "safeguards.h"
 

	
 
/** Delay counter for considering the next disaster. */
 
@@ -932,20 +934,20 @@ static void DoDisaster()
 

	
 
static void ResetDisasterDelay()
 
{
 
	_disaster_delay = GB(Random(), 0, 9) + 730;
 
}
 

	
 
void DisasterDailyLoop()
 
static IntervalTimer<TimerGameCalendar> _disaster_daily({TimerGameCalendar::DAY, TimerGameCalendar::Priority::DISASTER}, [](auto)
 
{
 
	if (--_disaster_delay != 0) return;
 

	
 
	ResetDisasterDelay();
 

	
 
	if (_settings_game.difficulty.disasters != 0) DoDisaster();
 
}
 
});
 

	
 
void StartupDisasters()
 
{
 
	ResetDisasterDelay();
 
}
 

	
src/dock_gui.cpp
Show inline comments
 
@@ -27,12 +27,14 @@
 
#include "zoom_func.h"
 
#include "tunnelbridge_cmd.h"
 
#include "dock_cmd.h"
 
#include "station_cmd.h"
 
#include "water_cmd.h"
 
#include "waypoint_cmd.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include "widgets/dock_widget.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 

	
 
@@ -474,12 +476,16 @@ public:
 
	}
 

	
 
	void OnRealtimeTick(uint delta_ms) override
 
	{
 
		CheckRedrawStationCoverage(this);
 
	}
 

	
 
	IntervalTimer<TimerGameCalendar> yearly_interval = {{TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [this](auto) {
 
		this->InvalidateData();
 
	}};
 
};
 

	
 
/** Nested widget parts of a build dock station window. */
 
static const NWidgetPart _nested_build_dock_station_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
src/economy.cpp
Show inline comments
 
@@ -49,12 +49,14 @@
 
#include "goal_base.h"
 
#include "story_base.h"
 
#include "linkgraph/refresh.h"
 
#include "company_cmd.h"
 
#include "economy_cmd.h"
 
#include "vehicle_cmd.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include "table/strings.h"
 
#include "table/pricebase.h"
 

	
 
#include "safeguards.h"
 

	
 
@@ -1980,22 +1982,22 @@ void LoadUnloadStation(Station *st)
 
	_cargo_delivery_destinations.clear();
 
}
 

	
 
/**
 
 * Monthly update of the economic data (of the companies as well as economic fluctuations).
 
 */
 
void CompaniesMonthlyLoop()
 
static IntervalTimer<TimerGameCalendar> _companies_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::COMPANY}, [](auto)
 
{
 
	CompaniesGenStatistics();
 
	if (_settings_game.economy.inflation) {
 
		AddInflation();
 
		RecomputePrices();
 
	}
 
	CompaniesPayInterest();
 
	HandleEconomyFluctuations();
 
}
 
});
 

	
 
static void DoAcquireCompany(Company *c)
 
{
 
	CompanyID ci = c->index;
 

	
 
	CompanyNewsInformation *cni = new CompanyNewsInformation(c, Company::Get(_current_company));
src/engine.cpp
Show inline comments
 
@@ -27,12 +27,14 @@
 
#include "engine_base.h"
 
#include "company_base.h"
 
#include "vehicle_func.h"
 
#include "articulated_vehicles.h"
 
#include "error.h"
 
#include "engine_base.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include "table/strings.h"
 
#include "table/engines.h"
 

	
 
#include "safeguards.h"
 

	
 
@@ -875,13 +877,13 @@ static bool IsVehicleTypeDisabled(Vehicl
 

	
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
/** Daily check to offer an exclusive engine preview to the companies. */
 
void EnginesDailyLoop()
 
static IntervalTimer<TimerGameCalendar> _engines_daily({TimerGameCalendar::DAY, TimerGameCalendar::Priority::ENGINE}, [](auto)
 
{
 
	for (Company *c : Company::Iterate()) {
 
		c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes, _date);
 
		c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes, _date);
 
	}
 

	
 
@@ -912,13 +914,13 @@ void EnginesDailyLoop()
 
				 * cannot build the vehicle. */
 
				if (!IsVehicleTypeDisabled(e->type, true)) AI::NewEvent(e->preview_company, new ScriptEventEnginePreview(i));
 
				if (IsInteractiveCompany(e->preview_company)) ShowEnginePreviewWindow(i);
 
			}
 
		}
 
	}
 
}
 
});
 

	
 
/**
 
 * Clear the 'hidden' flag for all engines of a new company.
 
 * @param cid Company being created.
 
 */
 
void ClearEnginesHiddenFlagOfCompany(CompanyID cid)
 
@@ -1107,12 +1109,17 @@ void EnginesMonthlyLoop()
 
			SetWindowClassesDirty(WC_BUILD_VEHICLE);
 
			SetWindowClassesDirty(WC_REPLACE_VEHICLE);
 
		}
 
	}
 
}
 

	
 
static IntervalTimer<TimerGameCalendar> _engines_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::ENGINE}, [](auto)
 
{
 
	EnginesMonthlyLoop();
 
});
 

	
 
/**
 
 * Is \a name still free as name for an engine?
 
 * @param name New name of an engine.
 
 * @return \c false if the name is being used already, else \c true.
 
 */
 
static bool IsUniqueEngineName(const std::string &name)
src/highscore_gui.cpp
Show inline comments
 
@@ -19,12 +19,15 @@
 
#include "company_func.h"
 
#include "company_base.h"
 
#include "strings_func.h"
 
#include "hotkeys.h"
 
#include "zoom_func.h"
 
#include "misc_cmd.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 
#include "date_func.h"
 

	
 
#include "widgets/highscore_widget.h"
 

	
 
#include "safeguards.h"
 

	
 
struct EndGameHighScoreBaseWindow : Window {
 
@@ -247,6 +250,17 @@ void ShowEndGameChart()
 
	if (_network_dedicated || (!_networking && !Company::IsValidID(_local_company))) return;
 

	
 
	HideVitalWindows();
 
	CloseWindowByClass(WC_ENDSCREEN);
 
	new EndGameWindow(&_endgame_desc);
 
}
 

	
 
static IntervalTimer<TimerGameCalendar> _check_end_game({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [](auto)
 
{
 
	/* 0 = never */
 
	if (_settings_game.game_creation.ending_year == 0) return;
 

	
 
	/* Show the end-game chart at the end of the ending year (hence the + 1). */
 
	if (_cur_year == _settings_game.game_creation.ending_year + 1) {
 
		ShowEndGameChart();
 
	}
 
});
src/industry_cmd.cpp
Show inline comments
 
@@ -41,12 +41,14 @@
 
#include "game/game.hpp"
 
#include "error.h"
 
#include "string_func.h"
 
#include "industry_cmd.h"
 
#include "landscape_cmd.h"
 
#include "terraform_cmd.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include "table/strings.h"
 
#include "table/industry_land.h"
 
#include "table/build_industry.h"
 

	
 
#include "safeguards.h"
 
@@ -2944,13 +2946,13 @@ static void ChangeIndustryProduction(Ind
 
 * Daily 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.
 
 */
 
void IndustryDailyLoop()
 
static IntervalTimer<TimerGameCalendar> _industries_daily({TimerGameCalendar::DAY, TimerGameCalendar::Priority::INDUSTRY}, [](auto)
 
{
 
	_economy.industry_daily_change_counter += _economy.industry_daily_increment;
 

	
 
	/* Bits 16-31 of industry_construction_counter contain the number of industries to change/create today,
 
	 * the lower 16 bit are a fractional part that might accumulate over several days until it
 
	 * is sufficient for an industry. */
 
@@ -2984,15 +2986,15 @@ void IndustryDailyLoop()
 
	}
 

	
 
	cur_company.Restore();
 

	
 
	/* production-change */
 
	InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_PRODUCTION_CHANGE);
 
}
 

	
 
void IndustryMonthlyLoop()
 
});
 

	
 
static IntervalTimer<TimerGameCalendar> _industries_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::INDUSTRY}, [](auto)
 
{
 
	Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 

	
 
	_industry_builder.MonthlyLoop();
 

	
 
	for (Industry *i : Industry::Iterate()) {
 
@@ -3006,13 +3008,13 @@ void IndustryMonthlyLoop()
 
	}
 

	
 
	cur_company.Restore();
 

	
 
	/* production-change */
 
	InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_PRODUCTION_CHANGE);
 
}
 
});
 

	
 

	
 
void InitializeIndustries()
 
{
 
	Industry::ResetIndustryCounts();
 
	_industry_sound_tile = 0;
src/network/network_func.h
Show inline comments
 
@@ -62,15 +62,12 @@ bool NetworkCompanyIsPassworded(CompanyI
 
uint NetworkMaxCompaniesAllowed();
 
bool NetworkMaxCompaniesReached();
 
void NetworkPrintClients();
 
void NetworkHandlePauseChange(PauseMode prev_mode, PauseMode changed_mode);
 

	
 
/*** Commands ran by the server ***/
 
void NetworkServerDailyLoop();
 
void NetworkServerMonthlyLoop();
 
void NetworkServerYearlyLoop();
 
void NetworkServerSendConfigUpdate();
 
void NetworkServerUpdateGameInfo();
 
void NetworkServerShowStatusToConsole();
 
bool NetworkServerStart();
 
void NetworkServerNewCompany(const Company *company, NetworkClientInfo *ci);
 
bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_name);
src/network/network_server.cpp
Show inline comments
 
@@ -28,12 +28,14 @@
 
#include "../roadveh.h"
 
#include "../order_backup.h"
 
#include "../core/pool_func.hpp"
 
#include "../core/random_func.hpp"
 
#include "../company_cmd.h"
 
#include "../rev.h"
 
#include "../timer/timer.h"
 
#include "../timer/timer_game_calendar.h"
 
#include <mutex>
 
#include <condition_variable>
 

	
 
#include "../safeguards.h"
 

	
 

	
 
@@ -1809,32 +1811,38 @@ void NetworkServer_Tick(bool send_frame)
 
#endif
 
		}
 
	}
 
}
 

	
 
/** Yearly "callback". Called whenever the year changes. */
 
void NetworkServerYearlyLoop()
 
static IntervalTimer<TimerGameCalendar> _network_yearly({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [](auto)
 
{
 
	if (!_network_server) return;
 

	
 
	NetworkCheckRestartMap();
 
	NetworkAdminUpdate(ADMIN_FREQUENCY_ANUALLY);
 
}
 
});
 

	
 
/** Monthly "callback". Called whenever the month changes. */
 
void NetworkServerMonthlyLoop()
 
static IntervalTimer<TimerGameCalendar> _network_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::NONE}, [](auto)
 
{
 
	if (!_network_server) return;
 

	
 
	NetworkAutoCleanCompanies();
 
	NetworkAdminUpdate(ADMIN_FREQUENCY_MONTHLY);
 
	if ((_cur_month % 3) == 0) NetworkAdminUpdate(ADMIN_FREQUENCY_QUARTERLY);
 
}
 
});
 

	
 
/** Daily "callback". Called whenever the date changes. */
 
void NetworkServerDailyLoop()
 
static IntervalTimer<TimerGameCalendar> _network_daily({TimerGameCalendar::DAY, TimerGameCalendar::Priority::NONE}, [](auto)
 
{
 
	if (!_network_server) return;
 

	
 
	NetworkAdminUpdate(ADMIN_FREQUENCY_DAILY);
 
	if ((_date % 7) == 3) NetworkAdminUpdate(ADMIN_FREQUENCY_WEEKLY);
 
}
 
});
 

	
 
/**
 
 * Get the IP address/hostname of the connected client.
 
 * @return The IP address.
 
 */
 
const std::string &ServerNetworkGameSocketHandler::GetClientIP()
src/newgrf_profiling.cpp
Show inline comments
 
@@ -11,12 +11,14 @@
 
#include "date_func.h"
 
#include "fileio_func.h"
 
#include "string_func.h"
 
#include "console_func.h"
 
#include "spritecache.h"
 
#include "walltime_func.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include <chrono>
 

	
 

	
 
std::vector<NewGRFProfiler> _newgrf_profilers;
 
Date _newgrf_profile_end_date;
 
@@ -155,6 +157,16 @@ uint32 NewGRFProfiler::FinishAll()
 
	}
 

	
 
	_newgrf_profile_end_date = MAX_DAY;
 

	
 
	return total_microseconds;
 
}
 

	
 
/**
 
 * Check whether profiling is active and should be finished.
 
 */
 
static IntervalTimer<TimerGameCalendar> _check_profiling_finished({TimerGameCalendar::DAY, TimerGameCalendar::Priority::NONE}, [](auto)
 
{
 
	if (_newgrf_profilers.empty() || _newgrf_profile_end_date > _date) return;
 

	
 
	NewGRFProfiler::FinishAll();
 
});
src/openttd.cpp
Show inline comments
 
@@ -98,12 +98,21 @@ extern void ShowOSErrorBox(const char *b
 
extern std::string _config_file;
 

	
 
bool _save_config = false;
 
bool _request_newgrf_scan = false;
 
NewGRFScanCallback *_request_newgrf_scan_callback = nullptr;
 

	
 
/** 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
 
};
 

	
 
/**
 
 * Error handling for fatal user errors.
 
 * @param s the string to print.
 
 * @note Does NEVER return.
 
 */
 
void CDECL usererror(const char *s, ...)
 
@@ -1429,12 +1438,21 @@ void StateGameLoop()
 
		cur_company.Restore();
 
	}
 

	
 
	assert(IsLocalCompany());
 
}
 

	
 
static IntervalTimer<TimerGameCalendar> _autosave_interval({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::AUTOSAVE}, [](auto)
 
{
 
	if (_settings_client.gui.autosave == 0) return;
 
	if ((_cur_month % _autosave_months[_settings_client.gui.autosave]) != 0) return;
 

	
 
	_do_autosave = true;
 
	SetWindowDirty(WC_STATUS_BAR, 0);
 
});
 

	
 
/**
 
 * Create an autosave. The default name is "autosave#.sav". However with
 
 * the setting 'keep_all_autosave' the name defaults to company-name + date
 
 */
 
static void DoAutosave()
 
{
src/rail_gui.cpp
Show inline comments
 
@@ -37,12 +37,14 @@
 
#include "stringfilter_type.h"
 
#include "string_func.h"
 
#include "station_cmd.h"
 
#include "tunnelbridge_cmd.h"
 
#include "waypoint_cmd.h"
 
#include "rail_cmd.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include "station_map.h"
 
#include "tunnelbridge_map.h"
 

	
 
#include "widgets/rail_widget.h"
 

	
 
@@ -1502,12 +1504,16 @@ public:
 

	
 
	void OnRealtimeTick(uint delta_ms) override
 
	{
 
		CheckRedrawStationCoverage(this);
 
	}
 

	
 
	IntervalTimer<TimerGameCalendar> yearly_interval = {{TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [this](auto) {
 
		this->SetDirty();
 
	}};
 

	
 
	static HotkeyList hotkeys;
 
};
 

	
 
/**
 
 * Handler for global hotkeys of the BuildRailStationWindow.
 
 * @param hotkey Hotkey
 
@@ -2198,12 +2204,19 @@ void ResetSignalVariant(int32 new_value)
 
			w->RaiseWidget((_cur_signal_variant == SIG_ELECTRIC ? WID_BS_ELECTRIC_NORM : WID_BS_SEMAPHORE_NORM) + _cur_signal_type);
 
		}
 
		_cur_signal_variant = new_variant;
 
	}
 
}
 

	
 
static IntervalTimer<TimerGameCalendar> _check_reset_signal({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [](auto)
 
{
 
	if (_cur_year != _settings_client.gui.semaphore_build_before) return;
 

	
 
	ResetSignalVariant();
 
});
 

	
 
/**
 
 * Resets the rail GUI - sets default railtype to build
 
 * and resets the signal GUI
 
 */
 
void InitializeRailGUI()
 
{
src/road_gui.cpp
Show inline comments
 
@@ -36,12 +36,14 @@
 
#include "tunnelbridge_cmd.h"
 
#include "newgrf_roadstop.h"
 
#include "querystring_gui.h"
 
#include "sortlist_type.h"
 
#include "stringfilter_type.h"
 
#include "string_func.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include "widgets/road_widget.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "safeguards.h"
 
@@ -1583,12 +1585,16 @@ public:
 

	
 
	void OnRealtimeTick(uint delta_ms) override
 
	{
 
		CheckRedrawStationCoverage(this);
 
	}
 

	
 
	IntervalTimer<TimerGameCalendar> yearly_interval = {{TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [this](auto) {
 
		this->InvalidateData();
 
	}};
 

	
 
	static HotkeyList hotkeys;
 
};
 

	
 
static Hotkey buildroadstop_hotkeys[] = {
 
	Hotkey('F', "focus_filter_box", BROSHK_FOCUS_FILTER_BOX),
 
	HOTKEY_LIST_END
src/station_cmd.cpp
Show inline comments
 
@@ -57,12 +57,14 @@
 
#include "tunnelbridge_map.h"
 
#include "station_cmd.h"
 
#include "waypoint_cmd.h"
 
#include "landscape_cmd.h"
 
#include "rail_cmd.h"
 
#include "newgrf_roadstop.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "safeguards.h"
 

	
 
/**
 
@@ -4004,23 +4006,22 @@ void OnTick_Station()
 
			if (Station::IsExpected(st)) AirportAnimationTrigger(Station::From(st), AAT_STATION_250_TICKS);
 
		}
 
	}
 
}
 

	
 
/** Monthly loop for stations. */
 
void StationMonthlyLoop()
 
static IntervalTimer<TimerGameCalendar> _stations_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::STATION}, [](auto)
 
{
 
	for (Station *st : Station::Iterate()) {
 
		for (CargoID i = 0; i < NUM_CARGO; i++) {
 
			GoodsEntry *ge = &st->goods[i];
 
			SB(ge->status, GoodsEntry::GES_LAST_MONTH, 1, GB(ge->status, GoodsEntry::GES_CURRENT_MONTH, 1));
 
			ClrBit(ge->status, GoodsEntry::GES_CURRENT_MONTH);
 
		}
 
	}
 
}
 

	
 
});
 

	
 
void ModifyStationRatingAround(TileIndex tile, Owner owner, int amount, uint radius)
 
{
 
	ForAllStationsRadius(tile, radius, [&](Station *st) {
 
		if (st->owner == owner && DistanceManhattan(tile, st->xy) <= radius) {
 
			for (CargoID i = 0; i < NUM_CARGO; i++) {
src/statusbar_gui.cpp
Show inline comments
 
@@ -24,12 +24,13 @@
 
#include "window_func.h"
 
#include "statusbar_gui.h"
 
#include "toolbar_gui.h"
 
#include "core/geometry_func.hpp"
 
#include "zoom_func.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 
#include "timer/timer_window.h"
 

	
 
#include "widgets/statusbar_widget.h"
 

	
 
#include "table/strings.h"
 
#include "table/sprites.h"
 
@@ -230,12 +231,16 @@ struct StatusBarWindow : Window {
 
		}
 
	}};
 

	
 
	TimeoutTimer<TimerWindow> reminder_timeout = {REMINDER_START, [this]() {
 
		this->SetWidgetDirty(WID_S_MIDDLE);
 
	}};
 

	
 
	IntervalTimer<TimerGameCalendar> daily_interval = {{TimerGameCalendar::DAY, TimerGameCalendar::Priority::NONE}, [this](auto) {
 
		this->SetWidgetDirty(WID_S_LEFT);
 
	}};
 
};
 

	
 
static const NWidgetPart _nested_main_status_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_PANEL, COLOUR_GREY, WID_S_LEFT), SetMinimalSize(140, 12), EndContainer(),
 
		NWidget(WWT_PUSHBTN, COLOUR_GREY, WID_S_MIDDLE), SetMinimalSize(40, 12), SetDataTip(0x0, STR_STATUSBAR_TOOLTIP_SHOW_LAST_NEWS), SetResize(1, 0),
src/subsidy.cpp
Show inline comments
 
@@ -22,12 +22,14 @@
 
#include "core/random_func.hpp"
 
#include "game/game.hpp"
 
#include "command_func.h"
 
#include "string_func.h"
 
#include "tile_cmd.h"
 
#include "subsidy_cmd.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "safeguards.h"
 

	
 
SubsidyPool _subsidy_pool("Subsidy"); ///< Pool for the subsidies.
 
@@ -474,13 +476,13 @@ bool FindSubsidyCargoDestination(CargoID
 
	CreateSubsidy(cid, src_type, src, dst_type, dst);
 

	
 
	return true;
 
}
 

	
 
/** Perform the monthly update of open subsidies, and try to create a new one. */
 
void SubsidyMonthlyLoop()
 
static IntervalTimer<TimerGameCalendar> _subsidies_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::SUBSIDY}, [](auto)
 
{
 
	bool modified = false;
 

	
 
	for (Subsidy *s : Subsidy::Iterate()) {
 
		if (--s->remaining == 0) {
 
			if (!s->IsAwarded()) {
 
@@ -544,13 +546,13 @@ void SubsidyMonthlyLoop()
 
		} while (!industry_subsidy && n--);
 
	}
 

	
 
	modified |= passenger_subsidy || town_subsidy || industry_subsidy;
 

	
 
	if (modified) InvalidateWindowData(WC_SUBSIDIES_LIST, 0);
 
}
 
});
 

	
 
/**
 
 * Tests whether given delivery is subsidised and possibly awards the subsidy to delivering company
 
 * @param cargo_type type of cargo
 
 * @param company company delivering the cargo
 
 * @param src_type type of \a src
src/timer/timer_game_calendar.cpp
Show inline comments
 
@@ -83,7 +83,18 @@ void TimerManager<TimerGameCalendar>::El
 

	
 
	if (new_year) {
 
		for (auto timer : timers) {
 
			timer->Elapsed(TimerGameCalendar::YEAR);
 
		}
 
	}
 

	
 
	/* 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);
 
}
 
}
src/town_cmd.cpp
Show inline comments
 
@@ -49,12 +49,14 @@
 
#include "game/game.hpp"
 
#include "town_cmd.h"
 
#include "landscape_cmd.h"
 
#include "road_cmd.h"
 
#include "terraform_cmd.h"
 
#include "tunnelbridge_cmd.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include "table/strings.h"
 
#include "table/town_land.h"
 

	
 
#include "safeguards.h"
 

	
 
@@ -3753,13 +3755,13 @@ CommandCost CheckforTownRating(DoCommand
 
		return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
void TownsMonthlyLoop()
 
static IntervalTimer<TimerGameCalendar> _towns_monthly({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::TOWN}, [](auto)
 
{
 
	for (Town *t : Town::Iterate()) {
 
		if (t->road_build_months != 0) t->road_build_months--;
 

	
 
		if (t->exclusive_counter != 0) {
 
			if (--t->exclusive_counter == 0) t->exclusivity = INVALID_COMPANY;
 
@@ -3767,23 +3769,22 @@ void TownsMonthlyLoop()
 

	
 
		UpdateTownAmounts(t);
 
		UpdateTownGrowth(t);
 
		UpdateTownRating(t);
 
		UpdateTownUnwanted(t);
 
	}
 

	
 
}
 

	
 
void TownsYearlyLoop()
 
});
 

	
 
static IntervalTimer<TimerGameCalendar> _towns_yearly({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::TOWN}, [](auto)
 
{
 
	/* Increment house ages */
 
	for (TileIndex t = 0; t < Map::Size(); t++) {
 
		if (!IsTileType(t, MP_HOUSE)) continue;
 
		IncrementHouseAge(t);
 
	}
 
}
 
});
 

	
 
static CommandCost TerraformTile_Town(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
 
{
 
	if (AutoslopeEnabled()) {
 
		HouseID house = GetHouseType(tile);
 
		GetHouseNorthPart(house); // modifies house to the ID of the north tile
src/town_gui.cpp
Show inline comments
 
@@ -32,12 +32,13 @@
 
#include "genworld.h"
 
#include "stringfilter_type.h"
 
#include "widgets/dropdown_func.h"
 
#include "town_kdtree.h"
 
#include "town_cmd.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 
#include "timer/timer_window.h"
 

	
 
#include "widgets/town_widget.h"
 

	
 
#include "table/strings.h"
 

	
 
@@ -593,12 +594,17 @@ public:
 
	void OnQueryTextFinished(char *str) override
 
	{
 
		if (str == nullptr) return;
 

	
 
		Command<CMD_RENAME_TOWN>::Post(STR_ERROR_CAN_T_RENAME_TOWN, this->window_number, str);
 
	}
 

	
 
	IntervalTimer<TimerGameCalendar> daily_interval = {{TimerGameCalendar::DAY, TimerGameCalendar::Priority::NONE}, [this](auto) {
 
		/* Refresh after possible snowline change */
 
		this->SetDirty();
 
	}};
 
};
 

	
 
static const NWidgetPart _nested_town_game_view_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
 
		NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_TV_CHANGE_NAME), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_TOWN_VIEW_RENAME_TOOLTIP),
src/vehicle.cpp
Show inline comments
 
@@ -53,12 +53,14 @@
 
#include "framerate_type.h"
 
#include "autoreplace_cmd.h"
 
#include "misc_cmd.h"
 
#include "train_cmd.h"
 
#include "vehicle_cmd.h"
 
#include "newgrf_roadstop.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "safeguards.h"
 

	
 
/* Number of bits in the hash to use from each vehicle coord */
 
@@ -2823,13 +2825,13 @@ void Vehicle::RemoveFromShared()
 
	}
 

	
 
	this->next_shared     = nullptr;
 
	this->previous_shared = nullptr;
 
}
 

	
 
void VehiclesYearlyLoop()
 
static IntervalTimer<TimerGameCalendar> _vehicles_yearly({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::VEHICLE}, [](auto)
 
{
 
	for (Vehicle *v : Vehicle::Iterate()) {
 
		if (v->IsPrimaryVehicle()) {
 
			/* show warning if vehicle is not generating enough income last 2 years (corresponds to a red icon in the vehicle list) */
 
			Money profit = v->GetDisplayProfitThisYear();
 
			if (v->age >= 730 && profit < 0) {
 
@@ -2848,14 +2850,13 @@ void VehiclesYearlyLoop()
 
	}
 
	GroupStatistics::UpdateProfits();
 
	SetWindowClassesDirty(WC_TRAINS_LIST);
 
	SetWindowClassesDirty(WC_SHIPS_LIST);
 
	SetWindowClassesDirty(WC_ROADVEH_LIST);
 
	SetWindowClassesDirty(WC_AIRCRAFT_LIST);
 
}
 

	
 
});
 

	
 
/**
 
 * Can this station be used by the given engine type?
 
 * @param engine_type the type of vehicles to test
 
 * @param st the station to test for
 
 * @return true if and only if the vehicle of the type can use this station.
0 comments (0 inline, 0 general)