|
OpenTTD Source 20260206-master-g4d4e37dbf1
|
Template class for all TimerGame based timers. More...
#include <timer_game_common.h>
Data Structures | |
| struct | DateTag |
| The type to store our dates in. More... | |
| struct | YearTag |
| Type for the year, note: 0 based, i.e. More... | |
| struct | YearMonthDay |
| Data structure to convert between Date and triplet (year, month, and day). More... | |
| struct | TPeriod |
| struct | TStorage |
Public Types | |
| enum class | Trigger : uint8_t { Day , Week , Month , Quarter , Year } |
| Trigger reasons for the timer based triggers. More... | |
| enum class | Priority : uint8_t { None , Company , Disaster , Engine , Industry , Station , Subsidy , Town , Vehicle } |
| Different levels of priority to run the timers in. More... | |
| using | Date = StrongType::Typedef<int32_t, DateTag<T>, StrongType::Compare, StrongType::Integer> |
| using | DateFract = uint16_t |
| The fraction of a date we're in, i.e. | |
| using | Year = StrongType::Typedef<int32_t, struct YearTag<T>, StrongType::Compare, StrongType::Integer> |
| using | Month = uint8_t |
| Type for the month, note: 0 based, i.e. | |
| using | Day = uint8_t |
| Type for the day of the month, note: 1 based, first day of a month is 1. | |
| using | TElapsed = Trigger |
Static Public Member Functions | |
| static constexpr bool | IsLeapYear (Year year) |
| Checks whether the given year is a leap year or not. | |
| static YearMonthDay | CalendarConvertDateToYMD (Date date) |
| Converts a Date to a Year, Month & Day. | |
| static Date | CalendarConvertYMDToDate (Year year, Month month, Day day) |
| Converts a tuple of Year, Month and Day to a Date. | |
| static constexpr Year | DateToYear (Date date) |
| Calculate the year of a given date. | |
| static constexpr Date | DateAtStartOfYear (Year year) |
| Calculate the date of the first day of a given year. | |
Template class for all TimerGame based timers.
As Calendar and Economy are very similar, this class is used to share code between them.
IntervalTimer and TimeoutTimer based on this Timer are a bit unusual, as their count is always one. You create those timers based on a transition: a new day, a new month or a new year.
Additionally, you need to set a priority. To ensure deterministic behaviour, events are executed in priority. It is important that if you assign NONE, you do not use Random() in your callback. Other than that, make sure you only set one callback per priority.
For example: IntervalTimer<TimerGameCalendar>({TimerGameCalendar::Trigger::Day, TimerGameCalendar::Priority::None}, [](uint count) {});
Definition at line 31 of file timer_game_common.h.
| using TimerGame< T >::Date = StrongType::Typedef<int32_t, DateTag<T>, StrongType::Compare, StrongType::Integer> |
Definition at line 35 of file timer_game_common.h.
| using TimerGame< T >::DateFract = uint16_t |
The fraction of a date we're in, i.e.
the number of ticks since the last date changeover.
Definition at line 38 of file timer_game_common.h.
| using TimerGame< T >::Day = uint8_t |
Type for the day of the month, note: 1 based, first day of a month is 1.
Definition at line 46 of file timer_game_common.h.
| using TimerGame< T >::Month = uint8_t |
Type for the month, note: 0 based, i.e.
0 = January, 11 = December.
Definition at line 44 of file timer_game_common.h.
Definition at line 142 of file timer_game_common.h.
| using TimerGame< T >::Year = StrongType::Typedef<int32_t, struct YearTag<T>, StrongType::Compare, StrongType::Integer> |
Definition at line 42 of file timer_game_common.h.
|
strong |
Different levels of priority to run the timers in.
| Enumerator | |
|---|---|
| None | These timers can be executed in any order; there is no Random() in them, so order is not relevant. |
| Company | Changes to companies. |
| Disaster | Running disaster logic. |
| Engine | Running engine availability updates. |
| Industry | Running industry production changes. |
| Station | Processing of goods statistics. |
| Subsidy | Creating new subsidies. |
| Town | Town growth and rating management. |
| Vehicle | Income and profit warnings. |
Definition at line 107 of file timer_game_common.h.
|
strong |
Trigger reasons for the timer based triggers.
Definition at line 98 of file timer_game_common.h.
|
static |
Converts a Date to a Year, Month & Day.
| date | the date to convert from |
Definition at line 61 of file timer_game_common.cpp.
References TimerGameConst< T >::DAYS_IN_YEAR.
|
static |
Converts a tuple of Year, Month and Day to a Date.
| year | is a number between 0..MAX_YEAR |
| month | is a number between 0..11 |
| day | is a number between 1..31 |
Definition at line 119 of file timer_game_common.cpp.
References _accum_days_for_month, DateAtStartOfYear(), and IsLeapYear().
|
inlinestaticconstexpr |
Calculate the date of the first day of a given year.
| year | the year to get the first day of. |
Definition at line 88 of file timer_game_common.h.
Referenced by CalendarConvertYMDToDate().
|
inlinestaticconstexpr |
Calculate the year of a given date.
| date | The date to consider. |
Definition at line 77 of file timer_game_common.h.
|
inlinestaticconstexpr |
Checks whether the given year is a leap year or not.
| year | The year to check. |
year is a leap year, otherwise false. Definition at line 63 of file timer_game_common.h.
Referenced by CalendarConvertYMDToDate().