OpenTTD Source  1.11.0-beta2
date_type.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef DATE_TYPE_H
11 #define DATE_TYPE_H
12 
13 
14 typedef int32 Date;
15 typedef uint16 DateFract;
16 typedef int32 Ticks;
17 
18 typedef int32 Year;
19 typedef uint8 Month;
20 typedef uint8 Day;
21 
28 static const int DAY_TICKS = 74;
29 static const int DAYS_IN_YEAR = 365;
30 static const int DAYS_IN_LEAP_YEAR = 366;
31 
32 static const int STATION_RATING_TICKS = 185;
33 static const int STATION_ACCEPTANCE_TICKS = 250;
34 static const int STATION_LINKGRAPH_TICKS = 504;
35 static const int CARGO_AGING_TICKS = 185;
36 static const int INDUSTRY_PRODUCE_TICKS = 256;
37 static const int TOWN_GROWTH_TICKS = 70;
39 
40 
41 /*
42  * ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR and DAYS_TILL_ORIGINAL_BASE_YEAR are
43  * primarily used for loading newgrf and savegame data and returning some
44  * newgrf (callback) functions that were in the original (TTD) inherited
45  * format, where '_date == 0' meant that it was 1920-01-01.
46  */
47 
49 static const Year ORIGINAL_BASE_YEAR = 1920;
51 static const Year ORIGINAL_END_YEAR = 2051;
53 static const Year ORIGINAL_MAX_YEAR = 2090;
54 
67 #define LEAP_YEARS_TILL(year) ((year) == 0 ? 0 : ((year) - 1) / 4 - ((year) - 1) / 100 + ((year) - 1) / 400 + 1)
68 
74 #define DAYS_TILL(year) (DAYS_IN_YEAR * (year) + LEAP_YEARS_TILL(year))
75 
80 #define DAYS_TILL_ORIGINAL_BASE_YEAR DAYS_TILL(ORIGINAL_BASE_YEAR)
81 
83 static const Year MIN_YEAR = 0;
84 
86 static const Year DEF_START_YEAR = 1950;
88 static const Year DEF_END_YEAR = ORIGINAL_END_YEAR - 1;
89 
94 static const Year MAX_YEAR = 5000000;
95 
97 #define MAX_DAY (DAYS_TILL(MAX_YEAR + 1) - 1)
98 
103 struct YearMonthDay {
107 };
108 
109 static const Year INVALID_YEAR = -1;
110 static const Date INVALID_DATE = -1;
111 static const Ticks INVALID_TICKS = -1;
112 
113 #endif /* DATE_TYPE_H */
YearMonthDay::day
Day day
Day (1..31)
Definition: date_type.h:106
STATION_RATING_TICKS
static const int STATION_RATING_TICKS
cycle duration for updating station rating
Definition: date_type.h:32
TOWN_GROWTH_TICKS
static const int TOWN_GROWTH_TICKS
cycle duration for towns trying to grow. (this originates from the size of the town array in TTD
Definition: date_type.h:37
INVALID_YEAR
static const Year INVALID_YEAR
Representation of an invalid year.
Definition: date_type.h:109
Year
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:18
ORIGINAL_END_YEAR
static const Year ORIGINAL_END_YEAR
The original ending year.
Definition: date_type.h:51
ORIGINAL_BASE_YEAR
static const Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
Definition: date_type.h:49
STATION_ACCEPTANCE_TICKS
static const int STATION_ACCEPTANCE_TICKS
cycle duration for updating station acceptance
Definition: date_type.h:33
MIN_YEAR
static const Year MIN_YEAR
The absolute minimum & maximum years in OTTD.
Definition: date_type.h:83
CARGO_AGING_TICKS
static const int CARGO_AGING_TICKS
cycle duration for aging cargo
Definition: date_type.h:35
YearMonthDay::month
Month month
Month (0..11)
Definition: date_type.h:105
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:14
Ticks
int32 Ticks
The type to store ticks in.
Definition: date_type.h:16
STATION_LINKGRAPH_TICKS
static const int STATION_LINKGRAPH_TICKS
cycle duration for cleaning dead links
Definition: date_type.h:34
DAYS_IN_LEAP_YEAR
static const int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
Definition: date_type.h:30
Month
uint8 Month
Type for the month, note: 0 based, i.e. 0 = January, 11 = December.
Definition: date_type.h:19
INVALID_TICKS
static const Ticks INVALID_TICKS
Representation of an invalid number of ticks.
Definition: date_type.h:111
YearMonthDay::year
Year year
Year (0...)
Definition: date_type.h:104
ORIGINAL_MAX_YEAR
static const Year ORIGINAL_MAX_YEAR
The maximum year of the original TTD.
Definition: date_type.h:53
INVALID_DATE
static const Date INVALID_DATE
Representation of an invalid date.
Definition: date_type.h:110
DAYS_IN_YEAR
static const int DAYS_IN_YEAR
days per year
Definition: date_type.h:29
DEF_START_YEAR
static const Year DEF_START_YEAR
The default starting year.
Definition: date_type.h:86
DEF_END_YEAR
static const Year DEF_END_YEAR
The default scoring end year.
Definition: date_type.h:88
YearMonthDay
Data structure to convert between Date and triplet (year, month, and day).
Definition: date_type.h:103
INDUSTRY_CUT_TREE_TICKS
static const int INDUSTRY_CUT_TREE_TICKS
cycle duration for lumber mill's extra action
Definition: date_type.h:38
Day
uint8 Day
Type for the day of the month, note: 1 based, first day of a month is 1.
Definition: date_type.h:20
DateFract
uint16 DateFract
The fraction of a date we're in, i.e. the number of ticks since the last date changeover.
Definition: date_type.h:15
DAY_TICKS
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
Definition: date_type.h:28
MAX_YEAR
static const Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
Definition: date_type.h:94
INDUSTRY_PRODUCE_TICKS
static const int INDUSTRY_PRODUCE_TICKS
cycle duration for industry production
Definition: date_type.h:36