1 /* $Id$ */ |
|
2 |
|
3 /** @file date.h */ |
|
4 |
|
5 #ifndef DATE_H |
|
6 #define DATE_H |
|
7 |
|
8 #include "openttd.h" |
|
9 |
|
10 /** |
|
11 * 1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885. On |
|
12 * an overflow the new day begun and 65535 / 885 = 74. |
|
13 * 1 tick is approximately 30 ms. |
|
14 * 1 day is thus about 2 seconds (74 * 30 = 2220) on a machine that can run OpenTTD normally |
|
15 */ |
|
16 #define DAY_TICKS 74 |
|
17 |
|
18 /* |
|
19 * ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR and DAYS_TILL_ORIGINAL_BASE_YEAR are |
|
20 * primarily used for loading newgrf and savegame data and returning some |
|
21 * newgrf (callback) functions that were in the original (TTD) inherited |
|
22 * format, where '_date == 0' meant that it was 1920-01-01. |
|
23 */ |
|
24 |
|
25 /** The minimum starting year/base year of the original TTD */ |
|
26 #define ORIGINAL_BASE_YEAR 1920 |
|
27 /** The maximum year of the original TTD */ |
|
28 #define ORIGINAL_MAX_YEAR 2090 |
|
29 |
|
30 /** |
|
31 * The offset in days from the '_date == 0' till |
|
32 * 'ConvertYMDToDate(ORIGINAL_BASE_YEAR, 0, 1)' |
|
33 */ |
|
34 #define DAYS_TILL_ORIGINAL_BASE_YEAR (365 * ORIGINAL_BASE_YEAR + ORIGINAL_BASE_YEAR / 4 - ORIGINAL_BASE_YEAR / 100 + ORIGINAL_BASE_YEAR / 400) |
|
35 |
|
36 /* The absolute minimum & maximum years in OTTD */ |
|
37 #define MIN_YEAR 0 |
|
38 /* MAX_YEAR, nicely rounded value of the number of years that can |
|
39 * be encoded in a single 32 bits date, about 2^31 / 366 years. */ |
|
40 #define MAX_YEAR 5000000 |
|
41 |
|
42 /* Year and Date are defined elsewhere */ |
|
43 typedef uint8 Month; |
|
44 typedef uint8 Day; |
|
45 typedef uint16 DateFract; |
|
46 |
|
47 struct YearMonthDay { |
|
48 Year year; |
|
49 Month month; |
|
50 Day day; |
|
51 }; |
|
52 |
|
53 extern Year _cur_year; |
|
54 extern Month _cur_month; |
|
55 extern Date _date; |
|
56 extern DateFract _date_fract; |
|
57 |
|
58 |
|
59 void SetDate(Date date); |
|
60 void ConvertDateToYMD(Date date, YearMonthDay *ymd); |
|
61 Date ConvertYMDToDate(Year year, Month month, Day day); |
|
62 |
|
63 #endif /* DATE_H */ |
|