OpenTTD Source: src/date_type.h Source File

OpenTTD Source 13.2.1

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 static const int MONTHS_IN_YEAR = 12;
32
33 static const int STATION_RATING_TICKS = 185;
34 static const int STATION_ACCEPTANCE_TICKS = 250;
35 static const int STATION_LINKGRAPH_TICKS = 504;
36 static const int CARGO_AGING_TICKS = 185;
37 static const int INDUSTRY_PRODUCE_TICKS = 256;
38 static const int TOWN_GROWTH_TICKS = 70;
39 static const int INDUSTRY_CUT_TREE_TICKS = INDUSTRY_PRODUCE_TICKS * 2;
40
41
42 /*
43 * ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR and DAYS_TILL_ORIGINAL_BASE_YEAR are
44 * primarily used for loading newgrf and savegame data and returning some
45 * newgrf (callback) functions that were in the original (TTD) inherited
46 * format, where '_date == 0' meant that it was 1920-01-01.
47 */
48
50 static const Year ORIGINAL_BASE_YEAR = 1920;
52 static const Year ORIGINAL_END_YEAR = 2051;
54 static const Year ORIGINAL_MAX_YEAR = 2090;
55
68 #define LEAP_YEARS_TILL(year) ((year) == 0 ? 0 : ((year) - 1) / 4 - ((year) - 1) / 100 + ((year) - 1) / 400 + 1)
69
75 #define DAYS_TILL(year) (DAYS_IN_YEAR * (year) + LEAP_YEARS_TILL(year))
76
81 #define DAYS_TILL_ORIGINAL_BASE_YEAR DAYS_TILL(ORIGINAL_BASE_YEAR)
82
84 static const Year MIN_YEAR = 0;
85
87 static const Year DEF_START_YEAR = 1950;
89 static const Year DEF_END_YEAR = ORIGINAL_END_YEAR - 1;
90
95 static const Year MAX_YEAR = 5000000;
96
98 #define MAX_DAY (DAYS_TILL(MAX_YEAR + 1) - 1)
99
104 struct YearMonthDay {
105 Year year;
106 Month month;
107 Day day;
108 };
109
110 static const Year INVALID_YEAR = -1;
111 static const Date INVALID_DATE = -1;
112 static const Ticks INVALID_TICKS = -1;
113
114 #endif /* DATE_TYPE_H */
YearMonthDay::day
Day day
Day (1..31)
Definition: date_type.h:107
STATION_RATING_TICKS
static const int STATION_RATING_TICKS
cycle duration for updating station rating
Definition: date_type.h:33
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:38
INVALID_YEAR
static const Year INVALID_YEAR
Representation of an invalid year.
Definition: date_type.h:110
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:52
ORIGINAL_BASE_YEAR
static const Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
Definition: date_type.h:50
STATION_ACCEPTANCE_TICKS
static const int STATION_ACCEPTANCE_TICKS
cycle duration for updating station acceptance
Definition: date_type.h:34
MIN_YEAR
static const Year MIN_YEAR
The absolute minimum & maximum years in OTTD.
Definition: date_type.h:84
CARGO_AGING_TICKS
static const int CARGO_AGING_TICKS
cycle duration for aging cargo
Definition: date_type.h:36
YearMonthDay::month
Month month
Month (0..11)
Definition: date_type.h:106
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:35
MONTHS_IN_YEAR
static const int MONTHS_IN_YEAR
months per year
Definition: date_type.h:31
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:112
YearMonthDay::year
Year year
Year (0...)
Definition: date_type.h:105
ORIGINAL_MAX_YEAR
static const Year ORIGINAL_MAX_YEAR
The maximum year of the original TTD.
Definition: date_type.h:54
INVALID_DATE
static const Date INVALID_DATE
Representation of an invalid date.
Definition: date_type.h:111
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:87
DEF_END_YEAR
static const Year DEF_END_YEAR
The default scoring end year.
Definition: date_type.h:89
YearMonthDay
Data structure to convert between Date and triplet (year, month, and day).
Definition: date_type.h:104
INDUSTRY_CUT_TREE_TICKS
static const int INDUSTRY_CUT_TREE_TICKS
cycle duration for lumber mill's extra action
Definition: date_type.h:39
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:95
INDUSTRY_PRODUCE_TICKS
static const int INDUSTRY_PRODUCE_TICKS
cycle duration for industry production
Definition: date_type.h:37