OpenTTD Source 20241222-master-gc72542431a
TimerGameCalendar Class Reference

Timer that is increased every 27ms, and counts towards ticks / days / months / years. More...

#include <timer_game_calendar.h>

Inheritance diagram for TimerGameCalendar:
TimerGame< struct Calendar >

Static Public Member Functions

static YearMonthDay ConvertDateToYMD (Date date)
 Converts a Date to a Year, Month & Day.
 
static Date ConvertYMDToDate (Year year, Month month, Day day)
 Converts a tuple of Year, Month and Day to a Date.
 
static void SetDate (Date date, DateFract fract)
 Set the date.
 
- Static Public Member Functions inherited from TimerGame< struct Calendar >
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.
 

Static Public Attributes

static Year year = {}
 Current year, starting at 0.
 
static Month month = {}
 Current month (0..11).
 
static Date date = {}
 Current date in days (day counter).
 
static DateFract date_fract = {}
 Fractional part of the day.
 
static uint16_t sub_date_fract = {}
 Subpart of date_fract that we use when calendar days are slower than economy days.
 

Additional Inherited Members

- Public Types inherited from TimerGame< struct Calendar >
enum  Trigger
 
enum  Priority
 
using Date = StrongType::Typedef< int32_t, DateTag< struct Calendar >, 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< struct Calendar >, 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 = uint
 

Detailed Description

Timer that is increased every 27ms, and counts towards ticks / days / months / years.

The amount of days in a month depends on the month and year (leap-years). There are always 74 ticks in a day (and with 27ms, this makes 1 day 1.998 seconds).

Calendar time is used for technology and time-of-year changes, including:

  • Vehicle, airport, station, object introduction and obsolescence
  • NewGRF variables for visual styles or behavior based on year or time of year (e.g. variable snow line)
  • Inflation, since it is tied to original game years. One interpretation of inflation is that it compensates for faster and higher capacity vehicles, another is that it compensates for more established companies. Each of these point to a different choice of calendar versus economy time, but we have to pick one so we follow a previous decision to tie inflation to original TTD game years.

Definition at line 30 of file timer_game_calendar.h.

Member Function Documentation

◆ ConvertDateToYMD()

TimerGameCalendar::YearMonthDay TimerGameCalendar::ConvertDateToYMD ( Date  date)
static

Converts a Date to a Year, Month & Day.

Parameters
datethe date to convert from
Returns
YearMonthDay representation of the Date.

Definition at line 42 of file timer_game_calendar.cpp.

References TimerGame< struct Calendar >::CalendarConvertDateToYMD(), and date.

Referenced by ClickChangeDateCheat(), NetworkGameWindow::DrawServerLine(), DrawVehiclePurchaseInfo(), FixTTOEngines(), GetGlobalVariable(), GetSnowLine(), SetDate(), SetYearEngineAgingStops(), StartupEngines(), StartupOneEngine(), SurveyRecentNews(), and SurveyTimers().

◆ ConvertYMDToDate()

◆ SetDate()

void TimerGameCalendar::SetDate ( Date  date,
DateFract  fract 
)
static

Set the date.

Parameters
dateNew date
fractThe number of ticks that have passed on this date.

Definition at line 66 of file timer_game_calendar.cpp.

References ConvertDateToYMD(), date, date_fract, Ticks::DAY_TICKS, month, and year.

Referenced by AfterLoadGame(), ClickChangeDateCheat(), and SetStartingYear().

Field Documentation

◆ date

◆ date_fract

TimerGameCalendar::DateFract TimerGameCalendar::date_fract = {}
static

◆ month

TimerGameCalendar::Month TimerGameCalendar::month = {}
static

Current month (0..11).

Definition at line 32 of file timer_game_calendar.h.

Referenced by ConvertYMDToDate(), and SetDate().

◆ sub_date_fract

uint16_t TimerGameCalendar::sub_date_fract = {}
static

Subpart of date_fract that we use when calendar days are slower than economy days.

Definition at line 35 of file timer_game_calendar.h.

◆ year

TimerGameCalendar::Year TimerGameCalendar::year = {}
static

Current year, starting at 0.

Calendar time is used for technology and time-of-year changes, including:

  • Vehicle, airport, station, object introduction and obsolescence
  • Vehicle and engine age
  • NewGRF variables for visual styles or behavior based on year or time of year (e.g. variable snow line)
  • Inflation, since it is tied to original game years. One interpretation of inflation is that it compensates for faster and higher capacity vehicles, another is that it compensates for more established companies. Each of these point to a different choice of calendar versus economy time, but we have to pick one so we follow a previous decision to tie inflation to original TTD game years.

Definition at line 31 of file timer_game_calendar.h.

Referenced by AfterLoadGame(), CalendarEnginesMonthlyLoop(), CheckBridgeAvailability(), ClickChangeDateCheat(), CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoadVehicle(), CmdBuildShip(), ConvertYMDToDate(), DoStartupNewCompany(), GenericPlaceSignals(), GetGlobalVariable(), GetIndustryGamePlayProbability(), GetMaskOfAllowedCurrencies(), VehicleScopeResolver::GetVariable(), HandleAutoSignalPlacement(), AirportSpec::IsAvailable(), LoadNewGRF(), LoadUnloadVehicle(), NetworkCheckRestartMapYear(), NewsItem::NewsItem(), ResetSignalVariant(), SetDate(), and TryBuildTownHouse().


The documentation for this class was generated from the following files: