2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
8 /** @file timer_game_calendar.h Definition of the game-calendar-timer */
10 #ifndef TIMER_GAME_CALENDAR_H
11 #define TIMER_GAME_CALENDAR_H
13 #include "../stdafx.h"
14 #include "../core/strong_typedef_type.hpp"
15 #include "timer_game_common.h"
18 * Timer that is increased every 27ms, and counts towards ticks / days / months / years.
20 * The amount of days in a month depends on the month and year (leap-years).
21 * There are always 74 ticks in a day (and with 27ms, this makes 1 day 1.998 seconds).
23 * Calendar time is used for technology and time-of-year changes, including:
24 * - Vehicle, airport, station, object introduction and obsolescence
25 * - NewGRF variables for visual styles or behavior based on year or time of year (e.g. variable snow line)
26 * - Inflation, since it is tied to original game years. One interpretation of inflation is that it compensates for faster and higher capacity vehicles,
27 * another is that it compensates for more established companies. Each of these point to a different choice of calendar versus economy time, but we have to pick one
28 * so we follow a previous decision to tie inflation to original TTD game years.
30 class TimerGameCalendar
: public TimerGame
<struct Calendar
> {
32 static Year year
; ///< Current year, starting at 0.
33 static Month month
; ///< Current month (0..11).
34 static Date date
; ///< Current date in days (day counter).
35 static DateFract date_fract
; ///< Fractional part of the day.
36 static uint16_t sub_date_fract
; ///< Subpart of date_fract that we use when calendar days are slower than economy days.
38 static YearMonthDay
ConvertDateToYMD(Date date
);
39 static Date
ConvertYMDToDate(Year year
, Month month
, Day day
);
40 static void SetDate(Date date
, DateFract fract
);
44 * Storage class for Calendar time constants.
46 class CalendarTime
: public TimerGameConst
<struct Calendar
> {
48 static constexpr int DEF_MINUTES_PER_YEAR
= 12;
49 static constexpr int FROZEN_MINUTES_PER_YEAR
= 0;
50 static constexpr int MAX_MINUTES_PER_YEAR
= 10080; // One week of real time. The actual max that doesn't overflow TimerGameCalendar::sub_date_fract is 10627, but this is neater.
53 #endif /* TIMER_GAME_CALENDAR_H */