date_type.h

Go to the documentation of this file.
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 STATION_LINKGRAPH_TICKS  = 504; 
00037 static const int CARGO_AGING_TICKS        = 185; 
00038 static const int INDUSTRY_PRODUCE_TICKS   = 256; 
00039 static const int TOWN_GROWTH_TICKS        = 70;  
00040 static const int INDUSTRY_CUT_TREE_TICKS  = INDUSTRY_PRODUCE_TICKS * 2; 
00041 
00042 
00043 /*
00044  * ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR and DAYS_TILL_ORIGINAL_BASE_YEAR are
00045  * primarily used for loading newgrf and savegame data and returning some
00046  * newgrf (callback) functions that were in the original (TTD) inherited
00047  * format, where '_date == 0' meant that it was 1920-01-01.
00048  */
00049 
00051 static const Year ORIGINAL_BASE_YEAR = 1920;
00053 static const Year ORIGINAL_END_YEAR  = 2051;
00055 static const Year ORIGINAL_MAX_YEAR  = 2090;
00056 
00069 #define LEAP_YEARS_TILL(year) ((year) == 0 ? 0 : ((year) - 1) / 4 - ((year) - 1) / 100 + ((year) - 1) / 400 + 1)
00070 
00076 #define DAYS_TILL(year) (DAYS_IN_YEAR * (year) + LEAP_YEARS_TILL(year))
00077 
00082 #define DAYS_TILL_ORIGINAL_BASE_YEAR DAYS_TILL(ORIGINAL_BASE_YEAR)
00083 
00085 static const Year MIN_YEAR = 0;
00086 
00088 static const Year DEF_START_YEAR = 1950;
00089 
00094 static const Year MAX_YEAR  = 5000000;
00095 
00097 #define MAX_DAY (DAYS_TILL(MAX_YEAR + 1) - 1)
00098 
00103 struct YearMonthDay {
00104   Year  year;   
00105   Month month;  
00106   Day   day;    
00107 };
00108 
00109 static const Year  INVALID_YEAR  = -1; 
00110 static const Date  INVALID_DATE  = -1; 
00111 static const Ticks INVALID_TICKS = -1; 
00112 
00113 #endif /* DATE_TYPE_H */