OpenTTD: src/date_type.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

date_type.h
Go to the documentation of this file.
1 /* $Id: date_type.h 25260 2013-05-19 14:26:14Z rubidium $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef DATE_TYPE_H
13 #define DATE_TYPE_H
14
15
16 typedef int32 Date;
17 typedef uint16 DateFract;
18 typedef int32 Ticks;
19
20 typedef int32 Year;
21 typedef uint8 Month;
22 typedef uint8 Day;
23
30 static const int DAY_TICKS = 74;
31 static const int DAYS_IN_YEAR = 365;
32 static const int DAYS_IN_LEAP_YEAR = 366;
33
34 static const int STATION_RATING_TICKS = 185;
35 static const int STATION_ACCEPTANCE_TICKS = 250;
36 static const int STATION_LINKGRAPH_TICKS = 504;
37 static const int CARGO_AGING_TICKS = 185;
38 static const int INDUSTRY_PRODUCE_TICKS = 256;
39 static const int TOWN_GROWTH_TICKS = 70;
40 static const int INDUSTRY_CUT_TREE_TICKS = INDUSTRY_PRODUCE_TICKS * 2;
41
42
43 /*
44 * ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR and DAYS_TILL_ORIGINAL_BASE_YEAR are
45 * primarily used for loading newgrf and savegame data and returning some
46 * newgrf (callback) functions that were in the original (TTD) inherited
47 * format, where '_date == 0' meant that it was 1920-01-01.
48 */
49
51 static const Year ORIGINAL_BASE_YEAR = 1920;
53 static const Year ORIGINAL_END_YEAR = 2051;
55 static const Year ORIGINAL_MAX_YEAR = 2090;
56
69 #define LEAP_YEARS_TILL(year) ((year) == 0 ? 0 : ((year) - 1) / 4 - ((year) - 1) / 100 + ((year) - 1) / 400 + 1)
70
76 #define DAYS_TILL(year) (DAYS_IN_YEAR * (year) + LEAP_YEARS_TILL(year))
77
82 #define DAYS_TILL_ORIGINAL_BASE_YEAR DAYS_TILL(ORIGINAL_BASE_YEAR)
83
85 static const Year MIN_YEAR = 0;
86
88 static const Year DEF_START_YEAR = 1950;
89
94 static const Year MAX_YEAR = 5000000;
95
97 #define MAX_DAY (DAYS_TILL(MAX_YEAR + 1) - 1)
98
103 struct YearMonthDay {
104 Year year;
105 Month month;
106 Day day;
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 */