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