static const TimerGameCalendar::Year PROCESSING_INDUSTRY_ABANDONMENT_YEARS = 5; ///< If a processing industry doesn't produce for this many consecutive years, it may close.
static const TimerGameEconomy::Year PROCESSING_INDUSTRY_ABANDONMENT_YEARS = 5; ///< If a processing industry doesn't produce for this many consecutive economy years, it may close.
/**
* Production level maximum, minimum and default values.
@@ -86,7 +87,7 @@ struct Industry : IndustryPool::PoolItem
struct AcceptedCargo {
CargoID cargo; ///< Cargo type
uint16_t waiting; ///< Amount of cargo waiting to processed
TimerGameCalendar::Date last_accepted; ///< Last day cargo was accepted by this industry
TimerGameEconomy::Date last_accepted; ///< Last day cargo was accepted by this industry
};
using ProducedCargoArray = std::array<ProducedCargo, INDUSTRY_NUM_OUTPUTS>;
@@ -103,7 +104,7 @@ struct Industry : IndustryPool::PoolItem
IndustryType type; ///< type of industry.
Owner owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE
Colours random_colour; ///< randomized colour of the industry, for display purpose
TimerGameCalendar::Year last_prod_year; ///< last year of production
TimerGameEconomy::Year last_prod_year; ///< last economy year of production
byte was_cargo_delivered; ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry
IndustryControlFlags ctlflags; ///< flags overriding standard behaviours
case 0xB3: return this->industry->construction_type; // Construction type
case 0xB4: {
auto it = std::max_element(std::begin(this->industry->accepted), std::end(this->industry->accepted), [](const auto &a, const auto &b) { return a.last_accepted < b.last_accepted; });
return ClampTo<uint16_t>(it->last_accepted - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date last cargo accepted since 1920 (in days)
return ClampTo<uint16_t>(it->last_accepted - EconomyTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date last cargo accepted since 1920 (in days)
* This file implements the timer logic for the game-calendar-timer.
*/
/**
* Calendar time is used for technology and time-of-year changes, including:
* - Vehicle, airport, station, object introduction and obsolescence
* - Vehicle and engine age
* - 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.
* @note Callbacks are executed in the game-thread.
* 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.
*/
class TimerGameCalendar {
class TimerGameCalendar : public TimerGame<struct Calendar> {
public:
/** The type to store our dates in. */
using Date = StrongType::Typedef<int32_t, struct DateTag, StrongType::Compare, StrongType::Integer>;
/** The fraction of a date we're in, i.e. the number of ticks since the last date changeover. */
using DateFract = uint16_t;
/** Type for the year, note: 0 based, i.e. starts at the year 0. */
using Year = StrongType::Typedef<int32_t, struct YearTag, StrongType::Compare, StrongType::Integer>;
/** Type for the month, note: 0 based, i.e. 0 = January, 11 = December. */
using Month = uint8_t;
/** Type for the day of the month, note: 1 based, first day of a month is 1. */
using Day = uint8_t;
/**
* Data structure to convert between Date and triplet (year, month, and day).
static constexpr TimerGameCalendar::Year INVALID_YEAR = -1; ///< Representation of an invalid year
static constexpr TimerGameCalendar::Date INVALID_DATE = -1; ///< Representation of an invalid date
};
class CalendarTime : public TimerGameConst<struct Calendar> {};
#endif /* TIMER_GAME_CALENDAR_H */
src/timer/timer_game_common.cpp
➞
Show inline comments
new file 100644
/*
* 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_common.cpp
* This file implements the common timer logic for the game-calendar timers.
template TimerGame<struct Calendar>::Date TimerGame<struct Calendar>::ConvertYMDToDate(Year year, Month month, Day day);
template TimerGame<struct Economy>::Date TimerGame<struct Economy>::ConvertYMDToDate(Year year, Month month, Day day);
src/timer/timer_game_common.h
➞
Show inline comments
new file 100644
/*
* 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_common.h Definition of the common class inherited by both calendar and economy timers. */
#ifndef TIMER_GAME_COMMON_H
#define TIMER_GAME_COMMON_H
#include "../core/strong_typedef_type.hpp"
/**
* Template class for all TimerGame based timers. As Calendar and Economy are very similar, this class is used to share code between them.
*
* IntervalTimer and TimeoutTimer based on this Timer are a bit unusual, as their count is always one.
* You create those timers based on a transition: a new day, a new month or a new year.
*
* Additionally, you need to set a priority. To ensure deterministic behaviour, events are executed
* in priority. It is important that if you assign NONE, you do not use Random() in your callback.
* Other than that, make sure you only set one callback per priority.
static constexpr typename TimerGame<T>::Year INVALID_YEAR = -1; ///< Representation of an invalid year
static constexpr typename TimerGame<T>::Date INVALID_DATE = -1; ///< Representation of an invalid date
};
#endif /* TIMER_GAME_COMMON_H */
src/timer/timer_game_economy.cpp
➞
Show inline comments
new file 100644
/*
* 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_economy.cpp
* This file implements the timer logic for the game-economy-timer.
*/
/**
* Economy time is used for the regular pace of the game, including:
* - Industry and house production/consumption
* - Industry production changes, closure, and spawning
* - Town growth
* - Company age and financial statistics
* - Vehicle financial statistics
* - Vehicle aging, depreciation, reliability, and renewal
* - Payment intervals for running and maintenance costs, loan interest, etc.
* - Cargo payment "time" calculation
* - Local authority and station ratings change intervals
* 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_economy.h Definition of the game-economy-timer */
#ifndef TIMER_GAME_ECONOMY_H
#define TIMER_GAME_ECONOMY_H
#include "../core/strong_typedef_type.hpp"
#include "timer_game_common.h"
/**
* Timer that is increased every 27ms, and counts towards economy time units, expressed in days / months / years.
*
* For now, this is kept in sync with the calendar date, so 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 27ms, this makes 1 day 1.998 seconds).
*
* Economy time is used for the regular pace of the game, including:
* - Industry and house production/consumption
* - Industry production changes, closure, and spawning
* - Town growth
* - Company age and periodical finance stats
* - Vehicle age and profit statistics, both individual and group
* - Vehicle aging, depreciation, reliability, and renewal
* - Payment intervals for running and maintenance costs, loan interest, etc.
* - Cargo payment "time" calculation
* - Local authority and station ratings change intervals
*/
class TimerGameEconomy : public TimerGame<struct Economy> {
public:
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.
static void SetDate(Date date, DateFract fract);
};
/**
* Storage class for Economy time constants.
*/
class EconomyTime : public TimerGameConst<struct Economy> {};
#endif /* TIMER_GAME_ECONOMY_H */
src/timetable.h
➞
Show inline comments
@@ -11,10 +11,10 @@
#define TIMETABLE_H
#include "timer/timer_game_tick.h"
#include "timer/timer_game_calendar.h"
#include "timer/timer_game_economy.h"
#include "vehicle_type.h"
static const TimerGameCalendar::Year MAX_TIMETABLE_START_YEARS = 15; ///< The maximum start date offset, in years.
static const TimerGameEconomy::Year MAX_TIMETABLE_START_YEARS = 15; ///< The maximum start date offset, in economy years.
enum class TimetableMode : uint8_t {
Days,
@@ -22,8 +22,8 @@ enum class TimetableMode : uint8_t {
TimerGameCalendar::Year build_year; ///< Year the vehicle has been built.
TimerGameCalendar::Date age; ///< Age in days
TimerGameCalendar::Date max_age; ///< Maximum age
TimerGameCalendar::Date date_of_last_service; ///< Last date the vehicle had a service at a depot.
TimerGameCalendar::Date date_of_last_service_newgrf; ///< Last date the vehicle had a service at a depot, unchanged by the date cheat to protect against unsafe NewGRF behavior.
TimerGameEconomy::Date date_of_last_service; ///< Last economy date the vehicle had a service at a depot.
TimerGameCalendar::Date date_of_last_service_newgrf; ///< Last calendar date the vehicle had a service at a depot, unchanged by the date cheat to protect against unsafe NewGRF behavior.