OpenTTD Source: TimerGameEconomy Class Reference

OpenTTD Source 15.0-RC2

Static Public Member Functions | Static Public Attributes
TimerGameEconomy Class Reference

Timer that is increased every 27ms, and counts towards economy time units, expressed in days / months / years. More...

`#include <timer_game_economy.h>`

Inheritance diagram for TimerGameEconomy:

## 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 bool | UsingWallclockUnits (bool newgame=false)
| Check if we are using wallclock units.
Static Public Member Functions inherited from TimerGame< struct Economy >
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 uint | days_since_last_month = {}
| Number of days that have elapsed since the last month.

## Additional Inherited Members
Public Types inherited from TimerGame< struct Economy >
enum | Trigger
enum | Priority
using | Date = StrongType::Typedef< int32_t, DateTag< struct Economy >, 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 Economy >, 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 economy time units, expressed in days / months / years.

For now, this is kept in sync with the calendar date, so 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).

Economy time is used for the regular pace of the game, including:

- Industry and house production/consumption
- Industry production changes, closure, and spawning
- Town growth
- Company age and periodical finance stats
- Vehicle age and profit statistics, both individual and group
- Vehicle aging, depreciation, reliability, and renewal
- Payment intervals for running and maintenance costs, loan interest, etc.
- Cargo payment "time" calculation
- Local authority and station ratings change intervals

Definition at line 32 of file timer_game_economy.h.

## Member Function Documentation

## ◆ ConvertDateToYMD()

TimerGameEconomy::YearMonthDay TimerGameEconomy::ConvertDateToYMD | ( | Date | date | ) |
| static

Converts a Date to a Year, Month & Day.

Parameters

  date | the date to convert from

Returns
  YearMonthDay representation of the Date.

Definition at line 47 of file timer_game_economy.cpp.

References TimerGame< struct Economy >::CalendarConvertDateToYMD(), date, EconomyTime::DAYS_IN_ECONOMY_MONTH, EconomyTime::DAYS_IN_ECONOMY_YEAR, and UsingWallclockUnits().

Referenced by SubsidyListWindow::DrawWidget(), SetDate(), SetDateWindow::SetDateWindow(), and SurveyTimers().

## ◆ ConvertYMDToDate()

TimerGameEconomy::Date TimerGameEconomy::ConvertYMDToDate | ( | Year | year,
|  | Month | month,
|  | Day | day
| ) |  |
| static

Converts a tuple of Year, Month and Day to a Date.

Parameters

  year | is a number between 0..MAX_YEAR
  month | is a number between 0..11
  day | is a number between 1..31

Returns
  The equivalent date.

Definition at line 67 of file timer_game_economy.cpp.

References TimerGame< struct Economy >::CalendarConvertYMDToDate(), EconomyTime::DAYS_IN_ECONOMY_MONTH, month, TimerGameConst< struct Economy >::MONTHS_IN_YEAR, UsingWallclockUnits(), and year.

Referenced by ChangeTimekeepingUnits(), LoadNewGRF(), and SetDateWindow::OnClick().

## ◆ SetDate()

void TimerGameEconomy::SetDate | ( | Date | date,
|  | DateFract | fract
| ) |  |
| static

Set the date.

Parameters

  date | The new date
  fract | The number of ticks that have passed on this date.

Definition at line 82 of file timer_game_economy.cpp.

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

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

## ◆ UsingWallclockUnits()

bool TimerGameEconomy::UsingWallclockUnits | ( | bool | newgame = `false` | ) |
| static

Check if we are using wallclock units.

Parameters

  newgame | Should we check the settings for a new game (since we are in the main menu)?

Returns
  True if the game is using wallclock units, or false if the game is using calendar units.

Definition at line 98 of file timer_game_economy.cpp.

References _settings_game, _settings_newgame, GameSettings::economy, and EconomySettings::timekeeping_units.

Referenced by CanChangeTimetableMode(), ChangeTimekeepingUnits(), ClickChangeDateCheat(), ConvertDateToYMD(), ConvertYMDToDate(), DrawAircraftPurchaseInfo(), StationViewWindow::DrawCargoRatings(), DrawCategories(), BaseGraphWindow::DrawGraph(), IndustryViewWindow::DrawInfo(), BaseVehicleListWindow::DrawVehicleListItems(), CompanyInfrastructureWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), TownViewWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), FormatString(), GenerateDefaultSaveName(), GetDefaultServiceInterval(), GetMaxCategoriesWidth(), GetPreviewRunningCostString(), GetServiceIntervalClamped(), GetVelocityUnits(), CompanyWindow::GetWidgetString(), MakePerformanceDetailPanels(), Vehicle::NeedsServicing(), VehicleDetailsWindow::OnClick(), IndustryProductionGraphWindow::OnInit(), TownCargoGraphWindow::OnInit(), BuildAirportWindow::OnPaint(), VehicleDetailsWindow::OnPaint(), VehicleDetailsWindow::OnTooltip(), ServiceIntervalSettingsValueText(), SettingHelpWallclock(), SettingsValueVelocityUnit(), SettingTitleWallclock(), TownActionBuyRights(), TownActionRoadRebuild(), UpdateAllServiceInterval(), CompanyInfrastructureWindow::UpdateWidgetSize(), and VehicleDetailsWindow::UpdateWidgetSize().

## Field Documentation

## ◆ date

TimerGameEconomy::Date TimerGameEconomy::date = {}
| static

Current date in days (day counter).

Definition at line 38 of file timer_game_economy.h.

Referenced by _GenerateWorld(), LinkGraph::BaseNode::AddEdge(), AfterLoadGame(), AircraftEventHandler_AtTerminal(), ChangeTimekeepingUnits(), ClickChangeDateCheat(), CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoadVehicle(), CmdBuildShip(), CmdSetTimetableStart(), ConvertDateToYMD(), DeleteStaleLinks(), DeliverGoodsToIndustry(), TimetableWindow::DrawArrivalDeparturePanel(), SubsidyListWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), ClientNetworkGameSocketHandler::GameLoop(), GenerateDefaultSaveName(), GetDateFromStartTick(), GetStartTickFromDate(), LinkGraphJob::IsScheduledToBeJoined(), LoadNewGRF(), CommandHelperBase::LogCommandExecution(), LinkGraph::Merge(), LinkGraph::Monthly(), MoveToNextNewsItem(), MoveToNextTickerItem(), Vehicle::NeedsServicing(), NetworkUpdateClientInfo(), TimetableWindow::OnClick(), OnTick_LinkGraph(), ServerNetworkGameSocketHandler::Receive_CLIENT_IDENTIFY(), SaveOrLoad(), SetDate(), SetDateWindow::SetDateWindow(), SetStartingYear(), StateGameLoop(), StateGameLoop_LinkGraphPauseControl(), SurveyTimers(), LinkGraph::BaseEdge::Update(), LinkGraph::BaseNode::UpdateSupply(), and VehicleServiceInDepot().

## ◆ date_fract

TimerGameEconomy::DateFract TimerGameEconomy::date_fract = {}
| static

Fractional part of the day.

Definition at line 39 of file timer_game_economy.h.

Referenced by AfterLoadGame(), TimetableWindow::BuildArrivalDepartureList(), ClickChangeDateCheat(), ClientNetworkGameSocketHandler::GameLoop(), GetDateFromStartTick(), GetStartTickFromDate(), LoadNewGRF(), CommandHelperBase::LogCommandExecution(), NetworkUpdateClientInfo(), OnTick_LinkGraph(), ServerNetworkGameSocketHandler::Receive_CLIENT_IDENTIFY(), RunEconomyVehicleDayProc(), SaveOrLoad(), SetDate(), StateGameLoop(), StateGameLoop_LinkGraphPauseControl(), SurveyTimers(), and UpdateOrderDest().

## ◆ days_since_last_month

uint TimerGameEconomy::days_since_last_month = {}
| static

Number of days that have elapsed since the last month.

Definition at line 40 of file timer_game_economy.h.

Referenced by GetAndResetAccumulatedAverage().

## ◆ month

TimerGameEconomy::Month TimerGameEconomy::month = {}
| static

Current month (0..11).

Definition at line 37 of file timer_game_economy.h.

Referenced by CompaniesGenStatistics(), CompaniesPayInterest(), ConvertYMDToDate(), DoCreateNewIndustry(), GetHistory(), IsValidHistory(), SetDate(), UpdateIndustryStatistics(), and BaseCompanyGraphWindow::UpdateStatistics().

## ◆ year

TimerGameEconomy::Year TimerGameEconomy::year = {}
| static

Current year, starting at 0.

Economy time is used for the regular pace of the game, including:

- Industry and house production/consumption
- Industry production changes, closure, and spawning
- Town growth
- Company age and financial statistics
- Vehicle financial statistics
- Vehicle aging, depreciation, reliability, and renewal
- Payment intervals for running and maintenance costs, loan interest, etc.
- Cargo payment "time" calculation
- Local authority and station ratings change intervals

Definition at line 36 of file timer_game_economy.h.

Referenced by AfterLoadGame(), ChangeIndustryProduction(), ConvertYMDToDate(), DoCreateNewIndustry(), DoStartupNewCompany(), CompanyFinancesWindow::DrawWidget(), InitializeWindowsAndCaches(), LoadNewGRF(), TimetableWindow::OnClick(), OnStartScenario(), SetDate(), UpdateIndustryStatistics(), and BaseCompanyGraphWindow::UpdateStatistics().

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

- src/timer/timer_game_economy.h
- src/timer/timer_game_economy.cpp