00001 /* $Id$ */ 00002 00003 /* 00004 * This file is part of OpenTTD. 00005 * 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. 00006 * 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. 00007 * 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/>. 00008 */ 00009 00012 #ifndef DATE_TYPE_H 00013 #define DATE_TYPE_H 00014 00015 00016 typedef int32 Date; 00017 typedef uint16 DateFract; 00018 typedef int32 Ticks; 00019 00020 typedef int32 Year; 00021 typedef uint8 Month; 00022 typedef uint8 Day; 00023 00030 static const int DAY_TICKS = 74; 00031 static const int DAYS_IN_YEAR = 365; 00032 static const int DAYS_IN_LEAP_YEAR = 366; 00033 00034 static const int STATION_RATING_TICKS = 185; 00035 static const int STATION_ACCEPTANCE_TICKS = 250; 00036 static const int CARGO_AGING_TICKS = 185; 00037 static const int INDUSTRY_PRODUCE_TICKS = 256; 00038 static const int TOWN_GROWTH_TICKS = 70; 00039 00040 00041 /* 00042 * ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR and DAYS_TILL_ORIGINAL_BASE_YEAR are 00043 * primarily used for loading newgrf and savegame data and returning some 00044 * newgrf (callback) functions that were in the original (TTD) inherited 00045 * format, where '_date == 0' meant that it was 1920-01-01. 00046 */ 00047 00049 static const Year ORIGINAL_BASE_YEAR = 1920; 00051 static const Year ORIGINAL_END_YEAR = 2051; 00053 static const Year ORIGINAL_MAX_YEAR = 2090; 00054 00067 #define LEAP_YEARS_TILL(year) ((year) == 0 ? 0 : ((year) - 1) / 4 - ((year) - 1) / 100 + ((year) - 1) / 400 + 1) 00068 00074 #define DAYS_TILL(year) (DAYS_IN_YEAR * (year) + LEAP_YEARS_TILL(year)) 00075 00080 #define DAYS_TILL_ORIGINAL_BASE_YEAR DAYS_TILL(ORIGINAL_BASE_YEAR) 00081 00083 static const Year MIN_YEAR = 0; 00084 00086 static const Year DEF_START_YEAR = 1950; 00087 00092 static const Year MAX_YEAR = 5000000; 00093 00095 #define MAX_DAY (DAYS_TILL(MAX_YEAR + 1) - 1) 00096 00101 struct YearMonthDay { 00102 Year year; 00103 Month month; 00104 Day day; 00105 }; 00106 00107 static const Year INVALID_YEAR = -1; 00108 static const Date INVALID_DATE = -1; 00109 static const Ticks INVALID_TICKS = -1; 00110 00111 #endif /* DATE_TYPE_H */