date_type.h

Go to the documentation of this file.
00001 /* $Id: date_type.h 18585 2009-12-21 16:13:30Z rubidium $ */
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 
00021 enum {
00022   DAY_TICKS = 74,          
00023   DAYS_IN_YEAR = 365,      
00024   DAYS_IN_LEAP_YEAR = 366, 
00025 };
00026 
00027 /*
00028  * ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR and DAYS_TILL_ORIGINAL_BASE_YEAR are
00029  * primarily used for loading newgrf and savegame data and returning some
00030  * newgrf (callback) functions that were in the original (TTD) inherited
00031  * format, where '_date == 0' meant that it was 1920-01-01.
00032  */
00033 
00035 #define ORIGINAL_BASE_YEAR 1920
00036 
00037 #define ORIGINAL_END_YEAR 2051
00038 
00039 #define ORIGINAL_MAX_YEAR 2090
00040 
00053 #define LEAP_YEARS_TILL(year) ((year) == 0 ? 0 : ((year) - 1) / 4 - ((year) - 1) / 100 + ((year) - 1) / 400 + 1)
00054 
00060 #define DAYS_TILL(year) (DAYS_IN_YEAR * (year) + LEAP_YEARS_TILL(year))
00061 
00066 #define DAYS_TILL_ORIGINAL_BASE_YEAR DAYS_TILL(ORIGINAL_BASE_YEAR)
00067 
00069 #define MIN_YEAR 0
00070 
00072 #define DEF_START_YEAR 1950
00073 
00078 #define MAX_YEAR 5000000
00079 
00081 #define MAX_DAY (DAYS_TILL(MAX_YEAR + 1) - 1)
00082 
00083 typedef int32  Date;      
00084 typedef uint16 DateFract; 
00085 typedef int32  Ticks;     
00086 
00087 typedef int32  Year;  
00088 typedef uint8  Month; 
00089 typedef uint8  Day;   
00090 
00095 struct YearMonthDay {
00096   Year  year;   
00097   Month month;  
00098   Day   day;    
00099 };
00100 
00101 static const Year  INVALID_YEAR  = -1; 
00102 static const Date  INVALID_DATE  = -1; 
00103 static const Ticks INVALID_TICKS = -1; 
00104 
00105 #endif /* DATE_TYPE_H */

Generated on Sat Nov 20 20:59:02 2010 for OpenTTD by  doxygen 1.6.1