10 #ifndef TIMER_GAME_COMMON_H
11 #define TIMER_GAME_COMMON_H
13 #include "../core/strong_typedef_type.hpp"
65 int32_t year_as_int = year.base();
66 return year_as_int % 4 == 0 && (year_as_int % 100 != 0 || year_as_int % 400 == 0);
80 return date.base() / 366;
90 int32_t year_as_int = year.base();
91 uint number_of_leap_years = (year == 0) ? 0 : ((year_as_int - 1) / 4 - (year_as_int - 1) / 100 + (year_as_int - 1) / 400 + 1);
94 return (365 * year_as_int) + number_of_leap_years;
124 TPeriod(Trigger trigger,
Priority priority) : trigger(trigger), priority(priority)
127 bool operator < (
const TPeriod &other)
const
129 if (this->trigger != other.trigger)
return this->trigger < other.trigger;
130 return this->priority < other.priority;
133 bool operator == (
const TPeriod &other)
const
135 return this->trigger == other.trigger && this->priority == other.priority;
139 using TElapsed = uint;
Template class for time constants shared by both Calendar and Economy time.
static constexpr TimerGame< T >::Year DEF_START_YEAR
The default starting year.
static constexpr TimerGame< T >::Date MIN_DATE
The date on January 1, year 0.
static constexpr TimerGame< T >::Year DEF_END_YEAR
The default scoring end year.
static constexpr TimerGame< T >::Year ORIGINAL_MAX_YEAR
The maximum year of the original TTD.
static constexpr int MONTHS_IN_YEAR
months per year
static constexpr TimerGame< T >::Year ORIGINAL_END_YEAR
The original ending year.
static constexpr TimerGame< T >::Year INVALID_YEAR
Representation of an invalid year.
static constexpr TimerGame< T >::Year MIN_YEAR
The absolute minimum year in OTTD.
static constexpr TimerGame< T >::Date INVALID_DATE
Representation of an invalid date.
static constexpr int SECONDS_PER_DAY
approximate seconds per day, not for precise calculations
static constexpr TimerGame< T >::Date MAX_DATE
The date of the last day of the max year.
static constexpr int DAYS_IN_YEAR
days per year
static constexpr TimerGame< T >::Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
static constexpr TimerGame< T >::Date DAYS_TILL_ORIGINAL_BASE_YEAR
The date of the first day of the original base year.
static constexpr TimerGame< T >::Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
static constexpr int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
Template class for all TimerGame based timers.
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.
uint16_t DateFract
The fraction of a date we're in, i.e.
@ NONE
These timers can be executed in any order; there is no Random() in them, so order is not relevant.
uint8_t Day
Type for the day of the month, note: 1 based, first day of a month is 1.
static Date CalendarConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
uint8_t Month
Type for the month, note: 0 based, i.e.
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.
Mix-in which makes the new Typedef comparable with itself and its base type.
Mix-in which makes the new Typedef behave more like an integer.
Templated helper to make a type-safe 'typedef' representing a single POD value.
The type to store our dates in.
Data structure to convert between Date and triplet (year, month, and day).
Type for the year, note: 0 based, i.e.