2023-04-13 17:16:48 +02:00
/*
* This file is part of OpenTTD .
* 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.
* 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 .
* 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/>.
*/
/** @file timer_game_calendar.h Definition of the game-calendar-timer */
# ifndef TIMER_GAME_CALENDAR_H
# define TIMER_GAME_CALENDAR_H
2023-10-04 18:02:16 +02:00
# include "../stdafx.h"
2023-08-12 20:14:21 +02:00
# include "../core/strong_typedef_type.hpp"
2024-01-22 15:04:34 +01:00
# include "timer_game_common.h"
2023-04-24 17:56:01 +02:00
2023-04-13 17:16:48 +02:00
/**
* Timer that is increased every 27 ms , and counts towards ticks / days / months / years .
*
* The amount of days in a month depends on the month and year ( leap - years ) .
* There are always 74 ticks in a day ( and with 27 ms , this makes 1 day 1.998 seconds ) .
*
2024-01-22 15:04:34 +01:00
* Calendar time is used for technology and time - of - year changes , including :
* - Vehicle , airport , station , object introduction and obsolescence
* - NewGRF variables for visual styles or behavior based on year or time of year ( e . g . variable snow line )
* - Inflation , since it is tied to original game years . One interpretation of inflation is that it compensates for faster and higher capacity vehicles ,
* 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
* so we follow a previous decision to tie inflation to original TTD game years .
2023-04-13 17:16:48 +02:00
*/
2024-01-22 15:04:34 +01:00
class TimerGameCalendar : public TimerGame < struct Calendar > {
2023-04-13 17:16:48 +02:00
public :
2023-04-24 17:56:01 +02:00
static Year year ; ///< Current year, starting at 0.
static Month month ; ///< Current month (0..11).
static Date date ; ///< Current date in days (day counter).
static DateFract date_fract ; ///< Fractional part of the day.
2024-01-24 00:33:54 +01:00
static uint16_t sub_date_fract ; ///< Subpart of date_fract that we use when calendar days are slower than economy days.
2024-01-22 15:04:34 +01:00
2024-01-23 17:36:09 +01:00
static YearMonthDay ConvertDateToYMD ( Date date ) ;
static Date ConvertYMDToDate ( Year year , Month month , Day day ) ;
2024-01-22 15:04:34 +01:00
static void SetDate ( Date date , DateFract fract ) ;
2023-04-13 17:16:48 +02:00
} ;
2023-08-16 15:43:31 +02:00
/**
* Storage class for Calendar time constants .
*/
2024-01-24 00:33:54 +01:00
class CalendarTime : public TimerGameConst < struct Calendar > {
public :
static constexpr int DEF_MINUTES_PER_YEAR = 12 ;
static constexpr int FROZEN_MINUTES_PER_YEAR = 0 ;
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.
} ;
2023-08-16 15:43:31 +02:00
2023-04-13 17:16:48 +02:00
# endif /* TIMER_GAME_CALENDAR_H */