# 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 typedef int64 DateTicks;
    00020 typedef int32  Minutes;
    00021
    00022 typedef int32  Year;
    00023 typedef uint8  Month;
    00024 typedef uint8  Day;
    00025
    00032 static const int ORIG_DAY_TICKS    =  74;
    00033 static const int DAYS_IN_YEAR      = 365;
    00034 static const int DAYS_IN_LEAP_YEAR = 366;
    00035
    00039 extern uint8 _date_daylength_factor;
    00040
    00044 #define DAY_TICKS (ORIG_DAY_TICKS * _date_daylength_factor)
    00045
    00046 #define DATE_UNIT_SIZE (_settings_client.gui.time_in_minutes ? _settings_client.gui.ticks_per_minute : DAY_TICKS)
    00047
    00048 static const int STATION_RATING_TICKS     = 185;
    00049 static const int STATION_ACCEPTANCE_TICKS = 250;
    00050 static const int CARGO_AGING_TICKS        = 185;
    00051 static const int INDUSTRY_PRODUCE_TICKS   = 256;
    00052 static const int INDUSTRY_CUT_TREE_TICKS  = INDUSTRY_PRODUCE_TICKS * 2;
    00053
    00054 #define TOWN_GROWTH_TICKS (70 * _date_daylength_factor)  ///< cycle duration for towns trying to grow. (this originates from the size of the town array in TTD
    00055
    00056 /*
    00057  * ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR and DAYS_TILL_ORIGINAL_BASE_YEAR are
    00058  * primarily used for loading newgrf and savegame data and returning some
    00059  * newgrf (callback) functions that were in the original (TTD) inherited
    00060  * format, where '_date == 0' meant that it was 1920-01-01.
    00061  */
    00062
    00064 static const Year ORIGINAL_BASE_YEAR = 1920;
    00066 static const Year ORIGINAL_END_YEAR  = 2051;
    00068 static const Year ORIGINAL_MAX_YEAR  = 2090;
    00069
    00082 #define LEAP_YEARS_TILL(year) ((year) == 0 ? 0 : ((year) - 1) / 4 - ((year) - 1) / 100 + ((year) - 1) / 400 + 1)
    00083
    00089 #define DAYS_TILL(year) (DAYS_IN_YEAR * (year) + LEAP_YEARS_TILL(year))
    00090
    00095 #define DAYS_TILL_ORIGINAL_BASE_YEAR DAYS_TILL(ORIGINAL_BASE_YEAR)
    00096
    00098 static const Year MIN_YEAR = 0;
    00099
    00101 static const Year DEF_START_YEAR = 1950;
    00102
    00107 static const Year MAX_YEAR  = 5000000;
    00108
    00110 #define MAX_DAY (DAYS_TILL(MAX_YEAR + 1) - 1)
    00111
    00113 #define MINUTES_DAY(minutes) (minutes / 1440)
    00114
    00116 #define MINUTES_HOUR(minutes) ((minutes / 60) % 24)
    00117
    00119 #define MINUTES_MINUTE(minutes) (minutes % 60)
    00120
    00122 #define MINUTES_DATE(day, hour, minute) ((day * 1440) + (hour * 60) + minute)
    00123
    00125 #define CURRENT_MINUTE ((((DateTicks)_date * DAY_TICKS) + _date_fract) / _settings_client.gui.ticks_per_minute)
    00126
    00131 struct YearMonthDay {
    00132   Year  year;
    00133   Month month;
    00134   Day   day;
    00135 };
    00136
    00137 static const Year  INVALID_YEAR  = -1;
    00138 static const Date  INVALID_DATE  = -1;
    00139 static const Ticks INVALID_TICKS = -1;
    00140
    00141 #endif /* DATE_TYPE_H */