Changeset - r27166:64e04a3ef9b1
[Not reviewed]
master
! ! !
Tyler Trahan - 14 months ago 2023-04-24 18:33:18
tyler@tylertrahan.com
Codechange: Define Date/Year/Month/Day within TimerGameCalendar class
68 files changed with 216 insertions and 182 deletions:
0 comments (0 inline, 0 general)
src/base_consist.h
Show inline comments
 
@@ -8,23 +8,23 @@
 
/** @file base_consist.h Properties for front vehicles/consists. */
 

	
 
#ifndef BASE_CONSIST_H
 
#define BASE_CONSIST_H
 

	
 
#include "order_type.h"
 
#include "date_type.h"
 
#include "timer/timer_game_calendar.h"
 
#include <string>
 

	
 
/** Various front vehicle properties that are preserved when autoreplacing, using order-backup or switching front engines within a consist. */
 
struct BaseConsist {
 
	std::string name;                   ///< Name of vehicle
 

	
 
	/* Used for timetabling. */
 
	uint32 current_order_time;          ///< How many ticks have passed since this order started.
 
	int32 lateness_counter;             ///< How many ticks late (or early if negative) this vehicle is.
 
	Date timetable_start;               ///< When the vehicle is supposed to start the timetable.
 
	uint32 current_order_time;               ///< How many ticks have passed since this order started.
 
	int32 lateness_counter;                  ///< How many ticks late (or early if negative) this vehicle is.
 
	TimerGameCalendar::Date timetable_start; ///< When the vehicle is supposed to start the timetable.
 

	
 
	uint16 service_interval;            ///< The interval for (automatic) servicing; either in days or %.
 

	
 
	VehicleOrderID cur_real_order_index;///< The index to the current real (non-implicit) order
 
	VehicleOrderID cur_implicit_order_index;///< The index to the current implicit order
 

	
src/base_station_base.h
Show inline comments
 
@@ -11,12 +11,13 @@
 
#define BASE_STATION_BASE_H
 

	
 
#include "core/pool_type.hpp"
 
#include "command_type.h"
 
#include "viewport_type.h"
 
#include "station_map.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
typedef Pool<BaseStation, StationID, 32, 64000> StationPool;
 
extern StationPool _station_pool;
 

	
 
struct StationSpecList {
 
	const StationSpec *spec;
 
@@ -73,13 +74,13 @@ struct BaseStation : StationPool::PoolIt
 
	Owner owner;                    ///< The owner of this station
 
	StationFacility facilities;     ///< The facilities that this station has
 

	
 
	std::vector<StationSpecList> speclist;           ///< List of rail station specs of this station.
 
	std::vector<RoadStopSpecList> roadstop_speclist; ///< List of road stop specs of this station
 

	
 
	Date build_date;                ///< Date of construction
 
	TimerGameCalendar::Date build_date; ///< Date of construction
 

	
 
	uint16 random_bits;             ///< Random bits assigned to this station
 
	byte waiting_triggers;          ///< Waiting triggers (NewGRF) for this station
 
	uint8 cached_anim_triggers;                ///< NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen.
 
	uint8 cached_roadstop_anim_triggers;       ///< NOSAVE: Combined animation trigger bitmask for road stops, used to determine if trigger processing should happen.
 
	CargoTypes cached_cargo_triggers;          ///< NOSAVE: Combined cargo trigger bitmask
src/bridge.h
Show inline comments
 
@@ -9,12 +9,13 @@
 

	
 
#ifndef BRIDGE_H
 
#define BRIDGE_H
 

	
 
#include "gfx_type.h"
 
#include "tile_cmd.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
/**
 
 * This enum is related to the definition of bridge pieces,
 
 * which is used to determine the proper sprite table to use
 
 * while drawing a given bridge part.
 
 */
 
@@ -36,23 +37,23 @@ static const uint MAX_BRIDGES = 13; ///<
 
typedef uint BridgeType; ///< Bridge spec number.
 

	
 
/**
 
 * Struct containing information about a single bridge type
 
 */
 
struct BridgeSpec {
 
	Year avail_year;             ///< the year where it becomes available
 
	byte min_length;             ///< the minimum length (not counting start and end tile)
 
	uint16 max_length;           ///< the maximum length (not counting start and end tile)
 
	uint16 price;                ///< the price multiplier
 
	uint16 speed;                ///< maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
 
	SpriteID sprite;             ///< the sprite which is used in the GUI
 
	PaletteID pal;               ///< the palette which is used in the GUI
 
	StringID material;           ///< the string that contains the bridge description
 
	StringID transport_name[2];  ///< description of the bridge, when built for road or rail
 
	PalSpriteID **sprite_table;  ///< table of sprites for drawing the bridge
 
	byte flags;                  ///< bit 0 set: disable drawing of far pillars.
 
	TimerGameCalendar::Year avail_year; ///< the year where it becomes available
 
	byte min_length;                    ///< the minimum length (not counting start and end tile)
 
	uint16 max_length;                  ///< the maximum length (not counting start and end tile)
 
	uint16 price;                       ///< the price multiplier
 
	uint16 speed;                       ///< maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
 
	SpriteID sprite;                    ///< the sprite which is used in the GUI
 
	PaletteID pal;                      ///< the palette which is used in the GUI
 
	StringID material;                  ///< the string that contains the bridge description
 
	StringID transport_name[2];         ///< description of the bridge, when built for road or rail
 
	PalSpriteID **sprite_table;         ///< table of sprites for drawing the bridge
 
	byte flags;                         ///< bit 0 set: disable drawing of far pillars.
 
};
 

	
 
extern BridgeSpec _bridge[MAX_BRIDGES];
 

	
 
Foundation GetBridgeFoundation(Slope tileh, Axis axis);
 
bool HasBridgeFlatRamp(Slope tileh, Axis axis);
src/cheat_gui.cpp
Show inline comments
 
@@ -107,13 +107,13 @@ static int32 ClickChangeDateCheat(int32 
 
	/* Don't allow changing to an invalid year, or the current year. */
 
	new_value = Clamp(new_value, MIN_YEAR, MAX_YEAR);
 
	if (new_value == TimerGameCalendar::year) return TimerGameCalendar::year;
 

	
 
	YearMonthDay ymd;
 
	ConvertDateToYMD(TimerGameCalendar::date, &ymd);
 
	Date new_date = ConvertYMDToDate(new_value, ymd.month, ymd.day);
 
	TimerGameCalendar::Date new_date = ConvertYMDToDate(new_value, ymd.month, ymd.day);
 

	
 
	/* Shift cached dates before we change the date. */
 
	for (auto v : Vehicle::Iterate()) v->ShiftDates(new_date - TimerGameCalendar::date);
 
	LinkGraphSchedule::instance.ShiftDates(new_date - TimerGameCalendar::date);
 

	
 
	/* Now it's safe to actually change the date. */
src/company_base.h
Show inline comments
 
@@ -11,12 +11,13 @@
 
#define COMPANY_BASE_H
 

	
 
#include "road_type.h"
 
#include "livery.h"
 
#include "autoreplace_type.h"
 
#include "tile_type.h"
 
#include "timer/timer_game_calendar.h"
 
#include "settings_type.h"
 
#include "group.h"
 
#include <string>
 
#include <array>
 

	
 
/** Statistics about the economy. */
 
@@ -74,13 +75,13 @@ struct CompanyProperties {
 

	
 
	TileIndex location_of_HQ;        ///< Northern tile of HQ; #INVALID_TILE when there is none.
 
	TileIndex last_build_coordinate; ///< Coordinate of the last build thing by this company.
 

	
 
	std::array<Owner, MAX_COMPANY_SHARE_OWNERS> share_owners; ///< Owners of the shares of the company. #INVALID_OWNER if nobody has bought them yet.
 

	
 
	Year inaugurated_year;           ///< Year of starting the company.
 
	TimerGameCalendar::Year inaugurated_year; ///< Year of starting the company.
 

	
 
	byte months_of_bankruptcy;       ///< Number of months that the company is unable to pay its debts
 
	CompanyMask bankrupt_asked;      ///< which companies were asked about buying it?
 
	int16 bankrupt_timeout;          ///< If bigger than \c 0, amount of time to wait for an answer on an offer to buy this company.
 
	Money bankrupt_value;
 

	
src/currency.cpp
Show inline comments
 
@@ -123,13 +123,13 @@ byte GetNewgrfCurrencyIdConverted(byte g
 
uint64 GetMaskOfAllowedCurrencies()
 
{
 
	uint64 mask = 0LL;
 
	uint i;
 

	
 
	for (i = 0; i < CURRENCY_END; i++) {
 
		Year to_euro = _currency_specs[i].to_euro;
 
		TimerGameCalendar::Year to_euro = _currency_specs[i].to_euro;
 

	
 
		if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && TimerGameCalendar::year >= to_euro) continue;
 
		if (to_euro == CF_ISEURO && TimerGameCalendar::year < 2000) continue;
 
		SetBit(mask, i);
 
	}
 
	SetBit(mask, CURRENCY_CUSTOM); // always allow custom currency
src/currency.h
Show inline comments
 
@@ -7,13 +7,13 @@
 

	
 
/** @file currency.h Functions to handle different currencies. */
 

	
 
#ifndef CURRENCY_H
 
#define CURRENCY_H
 

	
 
#include "date_type.h"
 
#include "timer/timer_game_calendar.h"
 
#include "string_func.h"
 
#include "strings_type.h"
 

	
 
static const int CF_NOEURO = 0; ///< Currency never switches to the Euro (as far as known).
 
static const int CF_ISEURO = 1; ///< Currency _is_ the Euro.
 

	
 
@@ -69,13 +69,13 @@ enum Currencies {
 
};
 

	
 
/** Specification of a currency. */
 
struct CurrencySpec {
 
	uint16 rate;           ///< The conversion rate compared to the base currency.
 
	std::string separator; ///< The thousands separator for this currency.
 
	Year to_euro;          ///< %Year of switching to the Euro. May also be #CF_NOEURO or #CF_ISEURO.
 
	TimerGameCalendar::Year to_euro; ///< Year of switching to the Euro. May also be #CF_NOEURO or #CF_ISEURO.
 
	std::string prefix;    ///< Prefix to apply when formatting money in this currency.
 
	std::string suffix;    ///< Suffix to apply when formatting money in this currency.
 
	/**
 
	 * The currency symbol is represented by two possible values, prefix and suffix
 
	 * Usage of one or the other is determined by #symbol_pos.
 
	 * 0 = prefix
 
@@ -86,13 +86,13 @@ struct CurrencySpec {
 
	 */
 
	byte symbol_pos;
 
	StringID name;
 

	
 
	CurrencySpec() = default;
 

	
 
	CurrencySpec(uint16 rate, const char *separator, Year to_euro, const char *prefix, const char *suffix, byte symbol_pos, StringID name) :
 
	CurrencySpec(uint16 rate, const char *separator, TimerGameCalendar::Year to_euro, const char *prefix, const char *suffix, byte symbol_pos, StringID name) :
 
		rate(rate), separator(separator), to_euro(to_euro), prefix(prefix), suffix(suffix), symbol_pos(symbol_pos), name(name)
 
	{
 
	}
 
};
 

	
 
extern CurrencySpec _currency_specs[CURRENCY_END];
src/date.cpp
Show inline comments
 
@@ -66,20 +66,20 @@ static const uint16 _accum_days_for_mont
 

	
 
/**
 
 * Converts a Date to a Year, Month & Day.
 
 * @param date the date to convert from
 
 * @param ymd  the year, month and day to write to
 
 */
 
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
 
void ConvertDateToYMD(TimerGameCalendar::Date date, YearMonthDay *ymd)
 
{
 
	/* Year determination in multiple steps to account for leap
 
	 * years. First do the large steps, then the smaller ones.
 
	 */
 

	
 
	/* There are 97 leap years in 400 years */
 
	Year yr = 400 * (date / (DAYS_IN_YEAR * 400 + 97));
 
	TimerGameCalendar::Year yr = 400 * (date / (DAYS_IN_YEAR * 400 + 97));
 
	int rem = date % (DAYS_IN_YEAR * 400 + 97);
 
	uint16 x;
 

	
 
	if (rem >= DAYS_IN_YEAR * 100 + 25) {
 
		/* There are 25 leap years in the first 100 years after
 
		 * every 400th year, as every 400th year is a leap year */
 
@@ -121,13 +121,13 @@ void ConvertDateToYMD(Date date, YearMon
 
/**
 
 * Converts a tuple of Year, Month and Day to a Date.
 
 * @param year  is a number between 0..MAX_YEAR
 
 * @param month is a number between 0..11
 
 * @param day   is a number between 1..31
 
 */
 
Date ConvertYMDToDate(Year year, Month month, Day day)
 
TimerGameCalendar::Date ConvertYMDToDate(TimerGameCalendar::Year year, TimerGameCalendar::Month month, TimerGameCalendar::Day day)
 
{
 
	/* Day-offset in a leap year */
 
	int days = _accum_days_for_month[month] + day - 1;
 

	
 
	/* Account for the missing of the 29th of February in non-leap years */
 
	if (!IsLeapYear(year) && days >= ACCUM_MAR) days--;
src/date_func.h
Show inline comments
 
@@ -9,20 +9,20 @@
 

	
 
#ifndef DATE_FUNC_H
 
#define DATE_FUNC_H
 

	
 
#include "date_type.h"
 

	
 
void ConvertDateToYMD(Date date, YearMonthDay *ymd);
 
Date ConvertYMDToDate(Year year, Month month, Day day);
 
void ConvertDateToYMD(TimerGameCalendar::Date date, YearMonthDay *ymd);
 
TimerGameCalendar::Date ConvertYMDToDate(TimerGameCalendar::Year year, TimerGameCalendar::Month month, TimerGameCalendar::Day day);
 

	
 
/**
 
 * Checks whether the given year is a leap year or not.
 
 * @param yr The year to check.
 
 * @return True if \c yr is a leap year, otherwise false.
 
 */
 
static inline bool IsLeapYear(Year yr)
 
static inline bool IsLeapYear(TimerGameCalendar::Year yr)
 
{
 
	return yr % 4 == 0 && (yr % 100 != 0 || yr % 400 == 0);
 
}
 

	
 
#endif /* DATE_FUNC_H */
src/date_gui.cpp
Show inline comments
 
@@ -24,26 +24,26 @@
 

	
 
/** Window to select a date graphically by using dropdowns */
 
struct SetDateWindow : Window {
 
	SetDateCallback *callback; ///< Callback to call when a date has been selected
 
	void *callback_data;       ///< Callback data pointer.
 
	YearMonthDay date; ///< The currently selected date
 
	Year min_year;     ///< The minimum year in the year dropdown
 
	Year max_year;     ///< The maximum year (inclusive) in the year dropdown
 
	TimerGameCalendar::Year min_year; ///< The minimum year in the year dropdown
 
	TimerGameCalendar::Year max_year; ///< The maximum year (inclusive) in the year dropdown
 

	
 
	/**
 
	 * Create the new 'set date' window
 
	 * @param desc the window description
 
	 * @param window_number number of the window
 
	 * @param parent the parent window, i.e. if this closes we should close too
 
	 * @param initial_date the initial date to show
 
	 * @param min_year the minimum year to show in the year dropdown
 
	 * @param max_year the maximum year (inclusive) to show in the year dropdown
 
	 * @param callback the callback to call once a date has been selected
 
	 */
 
	SetDateWindow(WindowDesc *desc, WindowNumber window_number, Window *parent, Date initial_date, Year min_year, Year max_year, SetDateCallback *callback, void *callback_data) :
 
	SetDateWindow(WindowDesc *desc, WindowNumber window_number, Window *parent, TimerGameCalendar::Date initial_date, TimerGameCalendar::Year min_year, TimerGameCalendar::Year max_year, SetDateCallback *callback, void *callback_data) :
 
			Window(desc),
 
			callback(callback),
 
			callback_data(callback_data),
 
			min_year(std::max(MIN_YEAR, min_year)),
 
			max_year(std::min(MAX_YEAR, max_year))
 
	{
 
@@ -86,13 +86,13 @@ struct SetDateWindow : Window {
 
					list.emplace_back(new DropDownListStringItem(STR_MONTH_JAN + i, i, false));
 
				}
 
				selected = this->date.month;
 
				break;
 

	
 
			case WID_SD_YEAR:
 
				for (Year i = this->min_year; i <= this->max_year; i++) {
 
				for (TimerGameCalendar::Year i = this->min_year; i <= this->max_year; i++) {
 
					DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false);
 
					item->SetParam(0, i);
 
					list.emplace_back(item);
 
				}
 
				selected = this->date.year;
 
				break;
 
@@ -211,11 +211,11 @@ static WindowDesc _set_date_desc(
 
 * @param initial_date the initial date to show
 
 * @param min_year the minimum year to show in the year dropdown
 
 * @param max_year the maximum year (inclusive) to show in the year dropdown
 
 * @param callback the callback to call once a date has been selected
 
 * @param callback_data extra callback data
 
 */
 
void ShowSetDateWindow(Window *parent, int window_number, Date initial_date, Year min_year, Year max_year, SetDateCallback *callback, void *callback_data)
 
void ShowSetDateWindow(Window *parent, int window_number, TimerGameCalendar::Date initial_date, TimerGameCalendar::Year min_year, TimerGameCalendar::Year max_year, SetDateCallback *callback, void *callback_data)
 
{
 
	CloseWindowByClass(WC_SET_DATE);
 
	new SetDateWindow(&_set_date_desc, window_number, parent, initial_date, min_year, max_year, callback, callback_data);
 
}
src/date_gui.h
Show inline comments
 
@@ -7,19 +7,19 @@
 

	
 
/** @file date_gui.h Functions related to the graphical selection of a date. */
 

	
 
#ifndef DATE_GUI_H
 
#define DATE_GUI_H
 

	
 
#include "date_type.h"
 
#include "timer/timer_game_calendar.h"
 
#include "window_type.h"
 

	
 
/**
 
 * Callback for when a date has been chosen
 
 * @param w the window that sends the callback
 
 * @param date the date that has been chosen
 
 */
 
typedef void SetDateCallback(const Window *w, Date date, void *data);
 
typedef void SetDateCallback(const Window *w, TimerGameCalendar::Date date, void *data);
 

	
 
void ShowSetDateWindow(Window *parent, int window_number, Date initial_date, Year min_year, Year max_year, SetDateCallback *callback, void *callback_data);
 
void ShowSetDateWindow(Window *parent, int window_number, TimerGameCalendar::Date initial_date, TimerGameCalendar::Year min_year, TimerGameCalendar::Year max_year, SetDateCallback *callback, void *callback_data);
 

	
 
#endif /* DATE_GUI_H */
src/date_type.h
Show inline comments
 
@@ -7,20 +7,16 @@
 

	
 
/** @file date_type.h Types related to the dates in OpenTTD. */
 

	
 
#ifndef DATE_TYPE_H
 
#define DATE_TYPE_H
 

	
 
#include "timer/timer_game_calendar.h"
 

	
 
typedef int32  Date;      ///< The type to store our dates in
 
typedef uint16 DateFract; ///< The fraction of a date we're in, i.e. the number of ticks since the last date changeover
 
typedef int32  Ticks;     ///< The type to store ticks in
 

	
 
typedef int32  Year;  ///< Type for the year, note: 0 based, i.e. starts at the year 0.
 
typedef uint8  Month; ///< Type for the month, note: 0 based, i.e. 0 = January, 11 = December.
 
typedef uint8  Day;   ///< Type for the day of the month, note: 1 based, first day of a month is 1.
 

	
 
/**
 
 * 1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16 and incremented by 885. On
 
 *                    an overflow the new day begun and 65535 / 885 = 74.
 
 * 1 tick is approximately 27 ms.
 
 * 1 day is thus about 2 seconds (74 * 27 = 1998) on a machine that can run OpenTTD normally
 
@@ -46,17 +42,17 @@ static const int INDUSTRY_CUT_TREE_TICKS
 
 * primarily used for loading newgrf and savegame data and returning some
 
 * newgrf (callback) functions that were in the original (TTD) inherited
 
 * format, where 'TimerGameCalendar::date == 0' meant that it was 1920-01-01.
 
 */
 

	
 
/** The minimum starting year/base year of the original TTD */
 
static const Year ORIGINAL_BASE_YEAR = 1920;
 
static const TimerGameCalendar::Year ORIGINAL_BASE_YEAR = 1920;
 
/** The original ending year */
 
static const Year ORIGINAL_END_YEAR  = 2051;
 
static const TimerGameCalendar::Year ORIGINAL_END_YEAR  = 2051;
 
/** The maximum year of the original TTD */
 
static const Year ORIGINAL_MAX_YEAR  = 2090;
 
static const TimerGameCalendar::Year ORIGINAL_MAX_YEAR  = 2090;
 

	
 
/**
 
 * Calculate the number of leap years till a given year.
 
 *
 
 * Each passed leap year adds one day to the 'day count'.
 
 *
 
@@ -80,37 +76,37 @@ static const Year ORIGINAL_MAX_YEAR  = 2
 
 * The offset in days from the 'TimerGameCalendar::date == 0' till
 
 * 'ConvertYMDToDate(ORIGINAL_BASE_YEAR, 0, 1)'
 
 */
 
#define DAYS_TILL_ORIGINAL_BASE_YEAR DAYS_TILL(ORIGINAL_BASE_YEAR)
 

	
 
/** The absolute minimum & maximum years in OTTD */
 
static const Year MIN_YEAR = 0;
 
static const TimerGameCalendar::Year MIN_YEAR = 0;
 

	
 
/** The default starting year */
 
static const Year DEF_START_YEAR = 1950;
 
static const TimerGameCalendar::Year DEF_START_YEAR = 1950;
 
/** The default scoring end year */
 
static const Year DEF_END_YEAR = ORIGINAL_END_YEAR - 1;
 
static const TimerGameCalendar::Year DEF_END_YEAR = ORIGINAL_END_YEAR - 1;
 

	
 
/**
 
 * MAX_YEAR, nicely rounded value of the number of years that can
 
 * be encoded in a single 32 bits date, about 2^31 / 366 years.
 
 */
 
static const Year MAX_YEAR  = 5000000;
 
static const TimerGameCalendar::Year MAX_YEAR  = 5000000;
 

	
 
/** The number of days till the last day */
 
#define MAX_DAY (DAYS_TILL(MAX_YEAR + 1) - 1)
 

	
 
/**
 
 * Data structure to convert between Date and triplet (year, month, and day).
 
 * @see ConvertDateToYMD(), ConvertYMDToDate()
 
 */
 
struct YearMonthDay {
 
	Year  year;   ///< Year (0...)
 
	Month month;  ///< Month (0..11)
 
	Day   day;    ///< Day (1..31)
 
	TimerGameCalendar::Year  year;   ///< Year (0...)
 
	TimerGameCalendar::Month month;  ///< Month (0..11)
 
	TimerGameCalendar::Day   day;    ///< Day (1..31)
 
};
 

	
 
static const Year  INVALID_YEAR  = -1; ///< Representation of an invalid year
 
static const Date  INVALID_DATE  = -1; ///< Representation of an invalid date
 
static const TimerGameCalendar::Year INVALID_YEAR = -1; ///< Representation of an invalid year
 
static const TimerGameCalendar::Date INVALID_DATE = -1; ///< Representation of an invalid date
 
static const Ticks INVALID_TICKS = -1; ///< Representation of an invalid number of ticks
 

	
 
#endif /* DATE_TYPE_H */
src/depot_base.h
Show inline comments
 
@@ -9,23 +9,24 @@
 

	
 
#ifndef DEPOT_BASE_H
 
#define DEPOT_BASE_H
 

	
 
#include "depot_map.h"
 
#include "core/pool_type.hpp"
 
#include "timer/timer_game_calendar.h"
 

	
 
typedef Pool<Depot, DepotID, 64, 64000> DepotPool;
 
extern DepotPool _depot_pool;
 

	
 
struct Depot : DepotPool::PoolItem<&_depot_pool> {
 
	Town *town;
 
	std::string name;
 

	
 
	TileIndex xy;
 
	uint16 town_cn;    ///< The N-1th depot for this town (consecutive number)
 
	Date build_date;   ///< Date of construction
 
	uint16 town_cn; ///< The N-1th depot for this town (consecutive number)
 
	TimerGameCalendar::Date build_date; ///< Date of construction
 

	
 
	Depot(TileIndex xy = INVALID_TILE) : xy(xy) {}
 
	~Depot();
 

	
 
	static inline Depot *GetByTile(TileIndex tile)
 
	{
src/disaster_vehicle.cpp
Show inline comments
 
@@ -897,15 +897,15 @@ static void Disaster_CoalMine_Init()
 
			}
 
		}
 
	}
 
}
 

	
 
struct Disaster {
 
	DisasterInitProc *init_proc; ///< The init function for this disaster.
 
	Year min_year;               ///< The first year this disaster will occur.
 
	Year max_year;               ///< The last year this disaster will occur.
 
	DisasterInitProc *init_proc;      ///< The init function for this disaster.
 
	TimerGameCalendar::Year min_year; ///< The first year this disaster will occur.
 
	TimerGameCalendar::Year max_year; ///< The last year this disaster will occur.
 
};
 

	
 
static const Disaster _disasters[] = {
 
	{Disaster_Zeppeliner_Init,      1930, 1955}, // zeppeliner
 
	{Disaster_Small_Ufo_Init,       1940, 1970}, // ufo (small)
 
	{Disaster_Airplane_Init,        1960, 1990}, // airplane
src/engine.cpp
Show inline comments
 
@@ -44,13 +44,13 @@ INSTANTIATE_POOL_METHODS(Engine)
 
EngineOverrideManager _engine_mngr;
 

	
 
/**
 
 * Year that engine aging stops. Engines will not reduce in reliability
 
 * and no more engines will be introduced
 
 */
 
static Year _year_engine_aging_stops;
 
static TimerGameCalendar::Year _year_engine_aging_stops;
 

	
 
/** Number of engines of each vehicle type in original engine data */
 
const uint8 _engine_counts[4] = {
 
	lengthof(_orig_rail_vehicle_info),
 
	lengthof(_orig_road_vehicle_info),
 
	lengthof(_orig_ship_vehicle_info),
 
@@ -433,13 +433,13 @@ uint Engine::GetDisplayMaxTractiveEffort
 
}
 

	
 
/**
 
 * Returns the vehicle's (not model's!) life length in days.
 
 * @return the life length
 
 */
 
Date Engine::GetLifeLengthInDays() const
 
TimerGameCalendar::Date Engine::GetLifeLengthInDays() const
 
{
 
	/* Assume leap years; this gives the player a bit more than the given amount of years, but never less. */
 
	return (this->info.lifelength + _settings_game.vehicle.extend_vehicle_life) * DAYS_IN_LEAP_YEAR;
 
}
 

	
 
/**
 
@@ -673,13 +673,13 @@ void SetYearEngineAgingStops()
 
/**
 
 * Start/initialise one engine.
 
 * @param e The engine to initialise.
 
 * @param aging_date The date used for age calculations.
 
 * @param seed Random seed.
 
 */
 
void StartupOneEngine(Engine *e, Date aging_date, uint32 seed)
 
void StartupOneEngine(Engine *e, TimerGameCalendar::Date aging_date, uint32 seed)
 
{
 
	const EngineInfo *ei = &e->info;
 

	
 
	e->age = 0;
 
	e->flags = 0;
 
	e->company_avail = 0;
 
@@ -695,13 +695,13 @@ void StartupOneEngine(Engine *e, Date ag
 
	              e->GetGRFID());
 
	uint32 r = Random();
 

	
 
	/* Don't randomise the start-date in the first two years after gamestart to ensure availability
 
	 * of engines in early starting games.
 
	 * Note: TTDP uses fixed 1922 */
 
	e->intro_date = ei->base_intro <= ConvertYMDToDate(_settings_game.game_creation.starting_year + 2, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro;
 
	e->intro_date = ei->base_intro <= ConvertYMDToDate(_settings_game.game_creation.starting_year + 2, 0, 1) ? ei->base_intro : (TimerGameCalendar::Date)GB(r, 0, 9) + ei->base_intro;
 
	if (e->intro_date <= TimerGameCalendar::date) {
 
		e->age = (aging_date - e->intro_date) >> 5;
 
		e->company_avail = MAX_UVALUE(CompanyMask);
 
		e->flags |= ENGINE_AVAILABLE;
 
	}
 

	
 
@@ -742,13 +742,13 @@ void StartupOneEngine(Engine *e, Date ag
 
 * Start/initialise all our engines. Must be called whenever there are changes
 
 * to the NewGRF config.
 
 */
 
void StartupEngines()
 
{
 
	/* Aging of vehicles stops, so account for that when starting late */
 
	const Date aging_date = std::min(TimerGameCalendar::date, ConvertYMDToDate(_year_engine_aging_stops, 0, 1));
 
	const TimerGameCalendar::Date aging_date = std::min(TimerGameCalendar::date, ConvertYMDToDate(_year_engine_aging_stops, 0, 1));
 
	uint32 seed = Random();
 

	
 
	for (Engine *e : Engine::Iterate()) {
 
		StartupOneEngine(e, aging_date, seed);
 
	}
 
	for (Engine *e : Engine::Iterate()) {
 
@@ -1262,13 +1262,13 @@ bool IsEngineRefittable(EngineID engine)
 

	
 
/**
 
 * Check for engines that have an appropriate availability.
 
 */
 
void CheckEngines()
 
{
 
	Date min_date = INT32_MAX;
 
	TimerGameCalendar::Date min_date = INT32_MAX;
 

	
 
	for (const Engine *e : Engine::Iterate()) {
 
		if (!e->IsEnabled()) continue;
 

	
 
		/* Don't consider train wagons, we need a powered engine available. */
 
		if (e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON) continue;
src/engine_base.h
Show inline comments
 
@@ -11,12 +11,13 @@
 
#define ENGINE_BASE_H
 

	
 
#include "engine_type.h"
 
#include "vehicle_type.h"
 
#include "core/pool_type.hpp"
 
#include "newgrf_commons.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
struct WagonOverride {
 
	std::vector<EngineID> engines;
 
	CargoID cargo;
 
	const SpriteGroup *group;
 
};
 
@@ -32,14 +33,14 @@ DECLARE_ENUM_AS_BIT_SET(EngineDisplayFla
 

	
 
typedef Pool<Engine, EngineID, 64, 64000> EnginePool;
 
extern EnginePool _engine_pool;
 

	
 
struct Engine : EnginePool::PoolItem<&_engine_pool> {
 
	std::string name;           ///< Custom name of engine.
 
	Date intro_date;            ///< Date of introduction of the engine.
 
	Date age;
 
	TimerGameCalendar::Date intro_date; ///< Date of introduction of the engine.
 
	TimerGameCalendar::Date age;        ///< Age of the engine, in days.
 
	uint16 reliability;         ///< Current reliability of the engine.
 
	uint16 reliability_spd_dec; ///< Speed of reliability decay between services (per day).
 
	uint16 reliability_start;   ///< Initial reliability of the engine.
 
	uint16 reliability_max;     ///< Maximal reliability of the engine.
 
	uint16 reliability_final;   ///< Final reliability of the engine.
 
	uint16 duration_phase_1;    ///< First reliability phase in months, increasing reliability from #reliability_start to #reliability_max.
 
@@ -120,13 +121,13 @@ struct Engine : EnginePool::PoolItem<&_e
 
	Money GetRunningCost() const;
 
	Money GetCost() const;
 
	uint GetDisplayMaxSpeed() const;
 
	uint GetPower() const;
 
	uint GetDisplayWeight() const;
 
	uint GetDisplayMaxTractiveEffort() const;
 
	Date GetLifeLengthInDays() const;
 
	TimerGameCalendar::Date GetLifeLengthInDays() const;
 
	uint16 GetRange() const;
 
	StringID GetAircraftTypeText() const;
 

	
 
	/**
 
	 * Check whether the engine is hidden in the GUI for the given company.
 
	 * @param c Company to check.
src/engine_func.h
Show inline comments
 
@@ -10,12 +10,13 @@
 
#ifndef ENGINE_FUNC_H
 
#define ENGINE_FUNC_H
 

	
 
#include "engine_type.h"
 
#include "vehicle_type.h"
 
#include "company_type.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
void SetupEngines();
 
void StartupEngines();
 
void CheckEngines();
 

	
 
/* Original engine data counts and offsets */
 
@@ -23,11 +24,11 @@ extern const uint8 _engine_counts[4];
 
extern const uint8 _engine_offsets[4];
 

	
 
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company);
 
bool IsEngineRefittable(EngineID engine);
 
void SetYearEngineAgingStops();
 
void CalcEngineReliability(Engine *e, bool new_month);
 
void StartupOneEngine(Engine *e, Date aging_date, uint32 seed);
 
void StartupOneEngine(Engine *e, TimerGameCalendar::Date aging_date, uint32 seed);
 

	
 
uint GetTotalCapacityOfArticulatedParts(EngineID engine);
 

	
 
#endif /* ENGINE_FUNC_H */
src/engine_type.h
Show inline comments
 
@@ -11,13 +11,13 @@
 
#define ENGINE_TYPE_H
 

	
 
#include "economy_type.h"
 
#include "rail_type.h"
 
#include "road_type.h"
 
#include "cargo_type.h"
 
#include "date_type.h"
 
#include "timer/timer_game_calendar.h"
 
#include "sound_type.h"
 
#include "strings_type.h"
 

	
 
typedef uint16 EngineID; ///< Unique identification number of an engine.
 

	
 
struct Engine;
 
@@ -138,15 +138,15 @@ DECLARE_ENUM_AS_BIT_SET(ExtraEngineFlags
 

	
 
/**
 
 * Information about a vehicle
 
 *  @see table/engines.h
 
 */
 
struct EngineInfo {
 
	Date base_intro;    ///< Basic date of engine introduction (without random parts).
 
	Year lifelength;    ///< Lifetime of a single vehicle
 
	Year base_life;     ///< Basic duration of engine availability (without random parts). \c 0xFF means infinite life.
 
	TimerGameCalendar::Date base_intro;    ///< Basic date of engine introduction (without random parts).
 
	TimerGameCalendar::Year lifelength;    ///< Lifetime of a single vehicle
 
	TimerGameCalendar::Year base_life;     ///< Basic duration of engine availability (without random parts). \c 0xFF means infinite life.
 
	byte decay_speed;
 
	byte load_amount;
 
	byte climates;      ///< Climates supported by the engine.
 
	CargoID cargo_type;
 
	CargoTypes refit_mask;
 
	byte refit_cost;
src/fios.h
Show inline comments
 
@@ -11,12 +11,13 @@
 
#define FIOS_H
 

	
 
#include "gfx_type.h"
 
#include "company_base.h"
 
#include "newgrf_config.h"
 
#include "network/core/tcp_content_type.h"
 
#include "timer/timer_game_calendar.h"
 

	
 

	
 
/** Special values for save-load window for the data parameter of #InvalidateWindowData. */
 
enum SaveLoadInvalidateWindowData {
 
	SLIWD_RESCAN_FILES,          ///< Rescan all files (when changed directory, ...)
 
	SLIWD_SELECTION_CHANGES,     ///< File selection has changed (user click, ...)
 
@@ -31,13 +32,13 @@ typedef SmallMap<uint, CompanyProperties
 
struct LoadCheckData {
 
	bool checkable;     ///< True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.)
 
	StringID error;     ///< Error message from loading. INVALID_STRING_ID if no error.
 
	char *error_data;   ///< Data to pass to SetDParamStr when displaying #error.
 

	
 
	uint32 map_size_x, map_size_y;
 
	Date current_date;
 
	TimerGameCalendar::Date current_date;
 

	
 
	GameSettings settings;
 

	
 
	CompanyPropertiesMap companies;               ///< Company information.
 

	
 
	GRFConfig *grfconfig;                         ///< NewGrf configuration from save.
src/graph_gui.cpp
Show inline comments
 
@@ -13,12 +13,13 @@
 
#include "company_base.h"
 
#include "company_gui.h"
 
#include "economy_func.h"
 
#include "cargotype.h"
 
#include "strings_func.h"
 
#include "window_func.h"
 
#include "date_type.h"
 
#include "timer/timer_game_calendar.h"
 
#include "gfx_func.h"
 
#include "core/geometry_func.hpp"
 
#include "currency.h"
 
#include "timer/timer.h"
 
#include "timer/timer_window.h"
 
@@ -182,13 +183,13 @@ protected:
 
	byte num_dataset;
 
	byte num_on_x_axis;
 
	byte num_vert_lines;
 

	
 
	/* The starting month and year that values are plotted against. */
 
	byte month;
 
	Year year;
 
	TimerGameCalendar::Year year;
 

	
 
	bool draw_dates = true; ///< Should we draw months and years on the time axis?
 

	
 
	/* These values are used if the graph is being plotted against values
 
	 * rather than the dates specified by month and year. */
 
	uint16 x_values_start;
 
@@ -382,13 +383,13 @@ protected:
 

	
 
		/* Draw x-axis labels and markings for graphs based on financial quarters and years.  */
 
		if (this->draw_dates) {
 
			x = r.left;
 
			y = r.bottom + ScaleGUITrad(2);
 
			byte month = this->month;
 
			Year year  = this->year;
 
			TimerGameCalendar::Year year = this->year;
 
			for (int i = 0; i < this->num_on_x_axis; i++) {
 
				SetDParam(0, month + STR_MONTH_ABBREV_JAN);
 
				SetDParam(1, year);
 
				DrawStringMultiLine(x, x + x_sep, y, this->height, month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, GRAPH_AXIS_LABEL_COLOUR, SA_LEFT);
 

	
 
				month += 3;
 
@@ -499,13 +500,13 @@ public:
 

	
 
		uint x_label_width = 0;
 

	
 
		/* Draw x-axis labels and markings for graphs based on financial quarters and years.  */
 
		if (this->draw_dates) {
 
			byte month = this->month;
 
			Year year  = this->year;
 
			TimerGameCalendar::Year year = this->year;
 
			for (int i = 0; i < this->num_on_x_axis; i++) {
 
				SetDParam(0, month + STR_MONTH_ABBREV_JAN);
 
				SetDParam(1, year);
 
				x_label_width = std::max(x_label_width, GetStringBoundingBox(month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH).width);
 

	
 
				month += 3;
src/house.h
Show inline comments
 
@@ -8,13 +8,13 @@
 
/** @file house.h definition of HouseSpec and accessors */
 

	
 
#ifndef HOUSE_H
 
#define HOUSE_H
 

	
 
#include "cargo_type.h"
 
#include "date_type.h"
 
#include "timer/timer_game_calendar.h"
 
#include "house_type.h"
 
#include "newgrf_animation_type.h"
 
#include "newgrf_commons.h"
 

	
 
/**
 
 * Simple value that indicates the house has reached the final stage of
 
@@ -94,14 +94,14 @@ enum HouseExtraFlags {
 
};
 

	
 
DECLARE_ENUM_AS_BIT_SET(HouseExtraFlags)
 

	
 
struct HouseSpec {
 
	/* Standard properties */
 
	Year min_year;                            ///< introduction year of the house
 
	Year max_year;                            ///< last year it can be built
 
	TimerGameCalendar::Year min_year;         ///< introduction year of the house
 
	TimerGameCalendar::Year max_year;         ///< last year it can be built
 
	byte population;                          ///< population (Zero on other tiles in multi tile house.)
 
	byte removal_cost;                        ///< cost multiplier for removing it
 
	StringID building_name;                   ///< building name
 
	uint16 remove_rating_decrease;            ///< rating decrease if removed
 
	byte mail_generation;                     ///< mail generation multiplier (tile based, as the acceptances below)
 
	byte cargo_acceptance[HOUSE_NUM_ACCEPTS]; ///< acceptance level for the cargo slots
src/industry.h
Show inline comments
 
@@ -13,18 +13,19 @@
 
#include "newgrf_storage.h"
 
#include "subsidy_type.h"
 
#include "industry_map.h"
 
#include "industrytype.h"
 
#include "tilearea_type.h"
 
#include "station_base.h"
 
#include "timer/timer_game_calendar.h"
 

	
 

	
 
typedef Pool<Industry, IndustryID, 64, 64000> IndustryPool;
 
extern IndustryPool _industry_pool;
 

	
 
static const Year PROCESSING_INDUSTRY_ABANDONMENT_YEARS = 5; ///< If a processing industry doesn't produce for this many consecutive years, it may close.
 
static const TimerGameCalendar::Year PROCESSING_INDUSTRY_ABANDONMENT_YEARS = 5; ///< If a processing industry doesn't produce for this many consecutive years, it may close.
 

	
 
/**
 
 * Production level maximum, minimum and default values.
 
 * It is not a value been really used in order to change, but rather an indicator
 
 * of how the industry is behaving.
 
 */
 
@@ -75,24 +76,24 @@ struct Industry : IndustryPool::PoolItem
 
	uint16 last_month_transported[INDUSTRY_NUM_OUTPUTS];   ///< total units transported per cargo in the last full month
 
	uint16 counter;                                        ///< used for animation and/or production (if available cargo)
 

	
 
	IndustryType type;             ///< type of industry.
 
	Owner owner;                   ///< owner of the industry.  Which SHOULD always be (imho) OWNER_NONE
 
	byte random_colour;            ///< randomized colour of the industry, for display purpose
 
	Year last_prod_year;           ///< last year of production
 
	TimerGameCalendar::Year last_prod_year; ///< last 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
 

	
 
	PartOfSubsidy part_of_subsidy; ///< NOSAVE: is this industry a source/destination of a subsidy?
 
	StationList stations_near;     ///< NOSAVE: List of nearby stations.
 
	mutable std::string cached_name; ///< NOSAVE: Cache of the resolved name of the industry
 

	
 
	Owner founder;                 ///< Founder of the industry
 
	Date construction_date;        ///< Date of the construction of the industry
 
	TimerGameCalendar::Date construction_date; ///< Date of the construction of the industry
 
	uint8 construction_type;       ///< Way the industry was constructed (@see IndustryConstructionType)
 
	Date last_cargo_accepted_at[INDUSTRY_NUM_INPUTS]; ///< Last day each cargo type was accepted by this industry
 
	TimerGameCalendar::Date last_cargo_accepted_at[INDUSTRY_NUM_INPUTS]; ///< Last day each cargo type was accepted by this industry
 
	byte selected_layout;          ///< Which tile layout was used when creating the industry
 
	Owner exclusive_supplier;      ///< Which company has exclusive rights to deliver cargo (INVALID_OWNER = anyone)
 
	Owner exclusive_consumer;      ///< Which company has exclusive rights to take cargo (INVALID_OWNER = anyone)
 
	std::string text;              ///< General text with additional information.
 

	
 
	uint16 random;                 ///< Random value used for randomisation of all kinds of things
src/linkgraph/linkgraph.cpp
Show inline comments
 
@@ -86,14 +86,14 @@ void LinkGraph::Compress()
 
/**
 
 * Merge a link graph with another one.
 
 * @param other LinkGraph to be merged into this one.
 
 */
 
void LinkGraph::Merge(LinkGraph *other)
 
{
 
	Date age = TimerGameCalendar::date - this->last_compression + 1;
 
	Date other_age = TimerGameCalendar::date - other->last_compression + 1;
 
	TimerGameCalendar::Date age = TimerGameCalendar::date - this->last_compression + 1;
 
	TimerGameCalendar::Date other_age = TimerGameCalendar::date - other->last_compression + 1;
 
	NodeID first = this->Size();
 
	for (NodeID node1 = 0; node1 < other->Size(); ++node1) {
 
		Station *st = Station::Get(other->nodes[node1].station);
 
		NodeID new_node = this->AddNode(st);
 
		this->nodes[new_node].supply = LinkGraph::Scale(other->nodes[node1].supply, age, other_age);
 
		st->goods[this->cargo].link_graph = this->index;
src/linkgraph/linkgraph.h
Show inline comments
 
@@ -11,12 +11,13 @@
 
#define LINKGRAPH_H
 

	
 
#include "../core/pool_type.hpp"
 
#include "../core/smallmap_type.hpp"
 
#include "../station_base.h"
 
#include "../cargotype.h"
 
#include "../date_type.h"
 
#include "../timer/timer_game_calendar.h"
 
#include "../saveload/saveload.h"
 
#include "linkgraph_type.h"
 
#include <utility>
 

	
 
class LinkGraph;
 
@@ -41,14 +42,14 @@ public:
 
	 * An edge in the link graph. Corresponds to a link between two stations.
 
	 */
 
	struct BaseEdge {
 
		uint capacity;                 ///< Capacity of the link.
 
		uint usage;                    ///< Usage of the link.
 
		uint64 travel_time_sum;        ///< Sum of the travel times of the link, in ticks.
 
		Date last_unrestricted_update; ///< When the unrestricted part of the link was last updated.
 
		Date last_restricted_update;   ///< When the restricted part of the link was last updated.
 
		TimerGameCalendar::Date last_unrestricted_update; ///< When the unrestricted part of the link was last updated.
 
		TimerGameCalendar::Date last_restricted_update;   ///< When the restricted part of the link was last updated.
 
		NodeID dest_node;              ///< Destination of the edge.
 

	
 
		BaseEdge(NodeID dest_node = INVALID_NODE);
 

	
 
		/**
 
		 * Get edge's average travel time.
 
@@ -57,13 +58,13 @@ public:
 
		uint32 TravelTime() const { return this->travel_time_sum / this->capacity; }
 

	
 
		/**
 
		 * Get the date of the last update to any part of the edge's capacity.
 
		 * @return Last update.
 
		 */
 
		Date LastUpdate() const { return std::max(this->last_unrestricted_update, this->last_restricted_update); }
 
		TimerGameCalendar::Date LastUpdate() const { return std::max(this->last_unrestricted_update, this->last_restricted_update); }
 

	
 
		void Update(uint capacity, uint usage, uint32 time, EdgeUpdateMode mode);
 
		void Restrict() { this->last_unrestricted_update = INVALID_DATE; }
 
		void Release() { this->last_restricted_update = INVALID_DATE; }
 

	
 
		/** Comparison operator based on \c dest_node. */
 
@@ -90,13 +91,13 @@ public:
 
	 */
 
	struct BaseNode {
 
		uint supply;             ///< Supply at the station.
 
		uint demand;             ///< Acceptance at the station.
 
		StationID station;       ///< Station ID.
 
		TileIndex xy;            ///< Location of the station referred to by the node.
 
		Date last_update;        ///< When the supply was last updated.
 
		TimerGameCalendar::Date last_update;        ///< When the supply was last updated.
 

	
 
		std::vector<BaseEdge> edges; ///< Sorted list of outgoing edges from this node.
 

	
 
		BaseNode(TileIndex xy = INVALID_TILE, StationID st = INVALID_STATION, uint demand = 0);
 

	
 
		/**
 
@@ -231,13 +232,13 @@ public:
 
	inline NodeID Size() const { return (NodeID)this->nodes.size(); }
 

	
 
	/**
 
	 * Get date of last compression.
 
	 * @return Date of last compression.
 
	 */
 
	inline Date LastCompression() const { return this->last_compression; }
 
	inline TimerGameCalendar::Date LastCompression() const { return this->last_compression; }
 

	
 
	/**
 
	 * Get the cargo ID this component's link graph refers to.
 
	 * @return Cargo ID.
 
	 */
 
	inline CargoID Cargo() const { return this->cargo; }
 
@@ -260,11 +261,11 @@ protected:
 
	friend SaveLoadTable GetLinkGraphJobDesc();
 
	friend class SlLinkgraphNode;
 
	friend class SlLinkgraphEdge;
 
	friend class LinkGraphJob;
 

	
 
	CargoID cargo;         ///< Cargo of this component's link graph.
 
	Date last_compression; ///< Last time the capacities and supplies were compressed.
 
	TimerGameCalendar::Date last_compression; ///< Last time the capacities and supplies were compressed.
 
	NodeVector nodes;      ///< Nodes in the component.
 
};
 

	
 
#endif /* LINKGRAPH_H */
src/linkgraph/linkgraphjob.h
Show inline comments
 
@@ -158,19 +158,19 @@ private:
 
	typedef std::vector<NodeAnnotation> NodeAnnotationVector;
 

	
 
	friend SaveLoadTable GetLinkGraphJobDesc();
 
	friend class LinkGraphSchedule;
 

	
 
protected:
 
	const LinkGraph link_graph;       ///< Link graph to by analyzed. Is copied when job is started and mustn't be modified later.
 
	const LinkGraphSettings settings; ///< Copy of _settings_game.linkgraph at spawn time.
 
	std::thread thread;               ///< Thread the job is running in or a default-constructed thread if it's running in the main thread.
 
	Date join_date;                   ///< Date when the job is to be joined.
 
	NodeAnnotationVector nodes;       ///< Extra node data necessary for link graph calculation.
 
	std::atomic<bool> job_completed;  ///< Is the job still running. This is accessed by multiple threads and reads may be stale.
 
	std::atomic<bool> job_aborted;    ///< Has the job been aborted. This is accessed by multiple threads and reads may be stale.
 
	const LinkGraph link_graph;        ///< Link graph to by analyzed. Is copied when job is started and mustn't be modified later.
 
	const LinkGraphSettings settings;  ///< Copy of _settings_game.linkgraph at spawn time.
 
	std::thread thread;                ///< Thread the job is running in or a default-constructed thread if it's running in the main thread.
 
	TimerGameCalendar::Date join_date; ///< Date when the job is to be joined.
 
	NodeAnnotationVector nodes;        ///< Extra node data necessary for link graph calculation.
 
	std::atomic<bool> job_completed;   ///< Is the job still running. This is accessed by multiple threads and reads may be stale.
 
	std::atomic<bool> job_aborted;     ///< Has the job been aborted. This is accessed by multiple threads and reads may be stale.
 

	
 
	void EraseFlows(NodeID from);
 
	void JoinThread();
 
	void SpawnThread();
 

	
 
public:
 
@@ -215,13 +215,13 @@ public:
 
	inline bool IsScheduledToBeJoined() const { return this->join_date <= TimerGameCalendar::date; }
 

	
 
	/**
 
	 * Get the date when the job should be finished.
 
	 * @return Join date.
 
	 */
 
	inline Date JoinDate() const { return join_date; }
 
	inline TimerGameCalendar::Date JoinDate() const { return join_date; }
 

	
 
	/**
 
	 * Change the join date on date cheating.
 
	 * @param interval Number of days to add.
 
	 */
 
	inline void ShiftJoinDate(int interval) { this->join_date += interval; }
 
@@ -252,13 +252,13 @@ public:
 
	inline CargoID Cargo() const { return this->link_graph.Cargo(); }
 

	
 
	/**
 
	 * Get the date when the underlying link graph was last compressed.
 
	 * @return Compression date.
 
	 */
 
	inline Date LastCompression() const { return this->link_graph.LastCompression(); }
 
	inline TimerGameCalendar::Date LastCompression() const { return this->link_graph.LastCompression(); }
 

	
 
	/**
 
	 * Get the ID of the underlying link graph.
 
	 * @return Link graph ID.
 
	 */
 
	inline LinkGraphID LinkGraphIndex() const { return this->link_graph.index; }
src/linkgraph/linkgraphschedule.cpp
Show inline comments
 
@@ -202,13 +202,13 @@ void AfterLoad_LinkGraphPauseControl()
 
 * Spawn or join a link graph job or compress a link graph if any link graph is
 
 * due to do so.
 
 */
 
void OnTick_LinkGraph()
 
{
 
	if (TimerGameCalendar::date_fract != LinkGraphSchedule::SPAWN_JOIN_TICK) return;
 
	Date offset = TimerGameCalendar::date % (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY);
 
	TimerGameCalendar::Date offset = TimerGameCalendar::date % (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY);
 
	if (offset == 0) {
 
		LinkGraphSchedule::instance.SpawnNext();
 
	} else if (offset == (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY) / 2) {
 
		if (!_networking || _network_server) {
 
			PerformanceMeasurer::SetInactive(PFE_GL_LINKGRAPH);
 
			LinkGraphSchedule::instance.JoinNext();
src/network/core/game_info.cpp
Show inline comments
 
@@ -253,13 +253,13 @@ void SerializeNetworkGameInfo(Packet *p,
 
 * Deserializes the NetworkGameInfo struct from the packet.
 
 * @param p    the packet to read the data from.
 
 * @param info the NetworkGameInfo to deserialize into.
 
 */
 
void DeserializeNetworkGameInfo(Packet *p, NetworkGameInfo *info, const GameInfoNewGRFLookupTable *newgrf_lookup_table)
 
{
 
	static const Date MAX_DATE = ConvertYMDToDate(MAX_YEAR, 11, 31); // December is month 11
 
	static const TimerGameCalendar::Date MAX_DATE = ConvertYMDToDate(MAX_YEAR, 11, 31); // December is month 11
 

	
 
	byte game_info_version = p->Recv_uint8();
 
	NewGRFSerializationType newgrf_serialisation = NST_GRFID_MD5;
 

	
 
	/*
 
	 *              Please observe the order.
src/network/core/game_info.h
Show inline comments
 
@@ -12,13 +12,13 @@
 
#ifndef NETWORK_CORE_GAME_INFO_H
 
#define NETWORK_CORE_GAME_INFO_H
 

	
 
#include "config.h"
 
#include "core.h"
 
#include "../../newgrf_config.h"
 
#include "../../date_type.h"
 
#include "../../timer/timer_game_calendar.h"
 

	
 
#include <unordered_map>
 

	
 
/*
 
 * NetworkGameInfo has several revisions which we still need to support on the
 
 * wire. The table below shows the version and size for each field of the
 
@@ -89,14 +89,14 @@ enum NewGRFSerializationType {
 

	
 
/**
 
 * The game information that is sent from the server to the client.
 
 */
 
struct NetworkServerGameInfo {
 
	GRFConfig *grfconfig;        ///< List of NewGRF files used
 
	Date start_date;             ///< When the game started
 
	Date game_date;              ///< Current date
 
	TimerGameCalendar::Date start_date; ///< When the game started
 
	TimerGameCalendar::Date game_date;  ///< Current date
 
	uint16 map_width;            ///< Map width
 
	uint16 map_height;           ///< Map height
 
	std::string server_name;     ///< Server name
 
	std::string server_revision; ///< The version number the server is using (e.g.: 'r304' or 0.5.0)
 
	bool dedicated;              ///< Is this a dedicated server?
 
	bool use_password;           ///< Is this server passworded?
src/network/network.cpp
Show inline comments
 
@@ -1037,13 +1037,13 @@ void NetworkGameLoop()
 
	if (!NetworkReceive()) return;
 

	
 
	if (_network_server) {
 
		/* Log the sync state to check for in-syncedness of replays. */
 
		if (TimerGameCalendar::date_fract == 0) {
 
			/* We don't want to log multiple times if paused. */
 
			static Date last_log;
 
			static TimerGameCalendar::Date last_log;
 
			if (last_log != TimerGameCalendar::date) {
 
				Debug(desync, 1, "sync: {:08x}; {:02x}; {:08x}; {:08x}", TimerGameCalendar::date, TimerGameCalendar::date_fract, _random.state[0], _random.state[1]);
 
				last_log = TimerGameCalendar::date;
 
			}
 
		}
 

	
src/network/network_base.h
Show inline comments
 
@@ -12,23 +12,24 @@
 

	
 
#include "network_type.h"
 
#include "core/address.h"
 
#include "../core/pool_type.hpp"
 
#include "../company_type.h"
 
#include "../date_type.h"
 
#include "../timer/timer_game_calendar.h"
 

	
 
/** Type for the pool with client information. */
 
typedef Pool<NetworkClientInfo, ClientIndex, 8, MAX_CLIENT_SLOTS, PT_NCLIENT> NetworkClientInfoPool;
 
extern NetworkClientInfoPool _networkclientinfo_pool;
 

	
 
/** Container for all information known about a client. */
 
struct NetworkClientInfo : NetworkClientInfoPool::PoolItem<&_networkclientinfo_pool> {
 
	ClientID client_id;      ///< Client identifier (same as ClientState->client_id)
 
	std::string client_name; ///< Name of the client
 
	CompanyID client_playas; ///< As which company is this client playing (CompanyID)
 
	Date join_date;          ///< Gamedate the client has joined
 
	TimerGameCalendar::Date join_date; ///< Gamedate the client has joined
 

	
 
	/**
 
	 * Create a new client.
 
	 * @param client_id The unique identifier of the client.
 
	 */
 
	NetworkClientInfo(ClientID client_id = INVALID_CLIENT_ID) : client_id(client_id) {}
src/network/network_gui.h
Show inline comments
 
@@ -8,13 +8,13 @@
 
/** @file network_gui.h GUIs related to networking. */
 

	
 
#ifndef NETWORK_GUI_H
 
#define NETWORK_GUI_H
 

	
 
#include "../company_type.h"
 
#include "../date_type.h"
 
#include "../timer/timer_game_calendar.h"
 
#include "../economy_type.h"
 
#include "../window_type.h"
 
#include "network_type.h"
 
#include "network_gamelist.h"
 

	
 
void ShowNetworkNeedPassword(NetworkPasswordType npt);
 
@@ -26,13 +26,13 @@ void ShowNetworkCompanyPasswordWindow(Wi
 
void ShowNetworkAskRelay(const std::string &server_connection_string, const std::string &relay_connection_string, const std::string &token);
 

	
 

	
 
/** Company information stored at the client side */
 
struct NetworkCompanyInfo : NetworkCompanyStats {
 
	std::string company_name; ///< Company name
 
	Year inaugurated_year;    ///< What year the company started in
 
	TimerGameCalendar::Year inaugurated_year; ///< What year the company started in
 
	Money company_value;      ///< The company value
 
	Money money;              ///< The amount of money the company has
 
	Money income;             ///< How much did the company earn last year
 
	uint16 performance;       ///< What was his performance last month?
 
	bool use_password;        ///< Is there a password
 
	std::string clients;      ///< The clients that control this company (Name1, name2, ..)
src/newgrf.cpp
Show inline comments
 
@@ -36,12 +36,13 @@
 
#include "newgrf_object.h"
 
#include "rev.h"
 
#include "fios.h"
 
#include "strings_func.h"
 
#include "date_func.h"
 
#include "timer/timer_game_tick.h"
 
#include "timer/timer_game_calendar.h"
 
#include "string_func.h"
 
#include "network/core/config.h"
 
#include <map>
 
#include "smallmap_gui.h"
 
#include "genworld.h"
 
#include "error.h"
 
@@ -2757,13 +2758,13 @@ static ChangeInfoResult GlobalVarChangeI
 
				}
 
				break;
 
			}
 

	
 
			case 0x0F: { //  Euro introduction dates
 
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
 
				Year year_euro = buf->ReadWord();
 
				TimerGameCalendar::Year year_euro = buf->ReadWord();
 

	
 
				if (curidx < CURRENCY_END) {
 
					_currency_specs[curidx].to_euro = year_euro;
 
				} else {
 
					GrfMsg(1, "GlobalVarChangeInfo: Euro intro date {} out of range, ignoring", curidx);
 
				}
 
@@ -6511,13 +6512,13 @@ bool GetGlobalVariable(byte param, uint3
 
			*value = Clamp(TimerGameCalendar::year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
 
			return true;
 

	
 
		case 0x02: { // detailed date information: month of year (bit 0-7), day of month (bit 8-12), leap year (bit 15), day of year (bit 16-24)
 
			YearMonthDay ymd;
 
			ConvertDateToYMD(TimerGameCalendar::date, &ymd);
 
			Date start_of_year = ConvertYMDToDate(ymd.year, 0, 1);
 
			TimerGameCalendar::Date start_of_year = ConvertYMDToDate(ymd.year, 0, 1);
 
			*value = ymd.month | (ymd.day - 1) << 8 | (IsLeapYear(ymd.year) ? 1 << 15 : 0) | (TimerGameCalendar::date - start_of_year) << 16;
 
			return true;
 
		}
 

	
 
		case 0x03: // current climate, 0=temp, 1=arctic, 2=trop, 3=toyland
 
			*value = _settings_game.game_creation.landscape;
 
@@ -9237,13 +9238,13 @@ static bool IsHouseSpecValid(HouseSpec *
 
 * climate / housezone combination.
 
 * @param bitmask The climate and housezone to check for. Exactly one climate
 
 *   bit and one housezone bit should be set.
 
 */
 
static void EnsureEarlyHouse(HouseZones bitmask)
 
{
 
	Year min_year = MAX_YEAR;
 
	TimerGameCalendar::Year min_year = MAX_YEAR;
 

	
 
	for (int i = 0; i < NUM_HOUSES; i++) {
 
		HouseSpec *hs = HouseSpec::Get(i);
 
		if (hs == nullptr || !hs->enabled) continue;
 
		if ((hs->building_availability & bitmask) != bitmask) continue;
 
		if (hs->min_year < min_year) min_year = hs->min_year;
 
@@ -9935,15 +9936,15 @@ static void AfterLoadGRFs()
 
void LoadNewGRF(uint load_index, uint num_baseset)
 
{
 
	/* In case of networking we need to "sync" the start values
 
	 * so all NewGRFs are loaded equally. For this we use the
 
	 * start date of the game and we set the counters, etc. to
 
	 * 0 so they're the same too. */
 
	Date date            = TimerGameCalendar::date;
 
	Year year            = TimerGameCalendar::year;
 
	DateFract date_fract = TimerGameCalendar::date_fract;
 
	TimerGameCalendar::Date date            = TimerGameCalendar::date;
 
	TimerGameCalendar::Year year            = TimerGameCalendar::year;
 
	TimerGameCalendar::DateFract date_fract = TimerGameCalendar::date_fract;
 
	uint64 tick_counter  = TimerGameTick::counter;
 
	byte display_opt     = _display_opt;
 

	
 
	if (_networking) {
 
		TimerGameCalendar::year = _settings_game.game_creation.starting_year;
 
		TimerGameCalendar::date = ConvertYMDToDate(TimerGameCalendar::year, 0, 1);
src/newgrf_airport.h
Show inline comments
 
@@ -9,12 +9,13 @@
 

	
 
#ifndef NEWGRF_AIRPORT_H
 
#define NEWGRF_AIRPORT_H
 

	
 
#include "airport.h"
 
#include "date_type.h"
 
#include "timer/timer_game_calendar.h"
 
#include "newgrf_class.h"
 
#include "newgrf_commons.h"
 
#include "tilearea_type.h"
 

	
 
/** Copy from station_map.h */
 
typedef byte StationGfx;
 
@@ -103,14 +104,14 @@ struct AirportSpec {
 
	const HangarTileTable *depot_table;    ///< gives the position of the depots on the airports
 
	byte nof_depots;                       ///< the number of hangar tiles in this airport
 
	byte size_x;                           ///< size of airport in x direction
 
	byte size_y;                           ///< size of airport in y direction
 
	byte noise_level;                      ///< noise that this airport generates
 
	byte catchment;                        ///< catchment area of this airport
 
	Year min_year;                         ///< first year the airport is available
 
	Year max_year;                         ///< last year the airport is available
 
	TimerGameCalendar::Year min_year;      ///< first year the airport is available
 
	TimerGameCalendar::Year max_year;      ///< last year the airport is available
 
	StringID name;                         ///< name of this airport
 
	TTDPAirportType ttd_airport_type;      ///< ttdpatch airport type (Small/Large/Helipad/Oilrig)
 
	AirportClassID cls_id;                 ///< the class to which this airport type belongs
 
	SpriteID preview_sprite;               ///< preview sprite for this airport
 
	uint16 maintenance_cost;               ///< maintenance cost multiplier
 
	/* Newgrf data */
src/newgrf_industries.cpp
Show inline comments
 
@@ -16,12 +16,13 @@
 
#include "window_func.h"
 
#include "town.h"
 
#include "company_base.h"
 
#include "error.h"
 
#include "strings_func.h"
 
#include "core/random_func.hpp"
 
#include "timer/timer_game_calendar.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "safeguards.h"
 

	
 
/* Since the industry IDs defined by the GRF file don't necessarily correlate
 
@@ -400,13 +401,13 @@ static uint32 GetCountAndDistanceOfClose
 
		case 0xAB: return GB(this->industry->counter, 8, 8);
 
		case 0xAC: return this->industry->was_cargo_delivered;
 

	
 
		case 0xB0: return Clamp(this->industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date when built since 1920 (in days)
 
		case 0xB3: return this->industry->construction_type; // Construction type
 
		case 0xB4: {
 
			Date *latest = std::max_element(this->industry->last_cargo_accepted_at, endof(this->industry->last_cargo_accepted_at));
 
			TimerGameCalendar::Date *latest = std::max_element(this->industry->last_cargo_accepted_at, endof(this->industry->last_cargo_accepted_at));
 
			return Clamp((*latest) - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date last cargo accepted since 1920 (in days)
 
		}
 
	}
 

	
 
	Debug(grf, 1, "Unhandled industry variable 0x{:X}", variable);
 

	
src/newgrf_object.h
Show inline comments
 
@@ -11,13 +11,13 @@
 
#define NEWGRF_OBJECT_H
 

	
 
#include "newgrf_callbacks.h"
 
#include "newgrf_spritegroup.h"
 
#include "newgrf_town.h"
 
#include "economy_func.h"
 
#include "date_type.h"
 
#include "timer/timer_game_calendar.h"
 
#include "object_type.h"
 
#include "newgrf_animation_type.h"
 
#include "newgrf_class.h"
 
#include "newgrf_commons.h"
 

	
 
/** Various object behaviours. */
 
@@ -65,14 +65,14 @@ struct ObjectSpec {
 
	StringID name;                ///< The name for this object.
 

	
 
	uint8 climate;                ///< In which climates is this object available?
 
	uint8 size;                   ///< The size of this objects; low nibble for X, high nibble for Y.
 
	uint8 build_cost_multiplier;  ///< Build cost multiplier per tile.
 
	uint8 clear_cost_multiplier;  ///< Clear cost multiplier per tile.
 
	Date introduction_date;       ///< From when can this object be built.
 
	Date end_of_life_date;        ///< When can't this object be built anymore.
 
	TimerGameCalendar::Date introduction_date; ///< From when can this object be built.
 
	TimerGameCalendar::Date end_of_life_date;  ///< When can't this object be built anymore.
 
	ObjectFlags flags;            ///< Flags/settings related to the object.
 
	uint16 callback_mask;         ///< Bitmask of requested/allowed callbacks.
 
	uint8 height;                 ///< The height of this structure, in heightlevels; max MAX_TILE_HEIGHT.
 
	uint8 views;                  ///< The number of views.
 
	uint8 generate_amount;        ///< Number of objects which are attempted to be generated per 256^2 map during world generation.
 

	
src/newgrf_profiling.cpp
Show inline comments
 
@@ -18,13 +18,13 @@
 
#include "timer/timer_game_tick.h"
 

	
 
#include <chrono>
 

	
 

	
 
std::vector<NewGRFProfiler> _newgrf_profilers;
 
Date _newgrf_profile_end_date;
 
TimerGameCalendar::Date _newgrf_profile_end_date;
 

	
 

	
 
/**
 
 * Create profiler object and begin profiling session.
 
 * @param grffile   The GRF file to collect profiling data on
 
 * @param end_date  Game date to end profiling on
src/newgrf_profiling.h
Show inline comments
 
@@ -9,12 +9,13 @@
 

	
 
#ifndef NEWGRF_PROFILING_H
 
#define NEWGRF_PROFILING_H
 

	
 
#include "stdafx.h"
 
#include "date_type.h"
 
#include "timer/timer_game_calendar.h"
 
#include "newgrf.h"
 
#include "newgrf_callbacks.h"
 
#include "newgrf_spritegroup.h"
 

	
 
#include <vector>
 
#include <string>
 
@@ -55,9 +56,9 @@ struct NewGRFProfiler {
 
	uint64 start_tick;       ///< Tick number this profiler was started on
 
	Call cur_call;           ///< Data for current call in progress
 
	std::vector<Call> calls; ///< All calls collected so far
 
};
 

	
 
extern std::vector<NewGRFProfiler> _newgrf_profilers;
 
extern Date _newgrf_profile_end_date;
 
extern TimerGameCalendar::Date _newgrf_profile_end_date;
 

	
 
#endif /* NEWGRF_PROFILING_H */
src/news_type.h
Show inline comments
 
@@ -8,13 +8,13 @@
 
/** @file news_type.h Types related to news. */
 

	
 
#ifndef NEWS_TYPE_H
 
#define NEWS_TYPE_H
 

	
 
#include "core/enum_type.hpp"
 
#include "date_type.h"
 
#include "timer/timer_game_calendar.h"
 
#include "strings_type.h"
 
#include "sound_type.h"
 

	
 
/**
 
 * Type of news.
 
 */
 
@@ -121,23 +121,23 @@ struct NewsAllocatedData {
 
	virtual ~NewsAllocatedData() {}
 
};
 

	
 

	
 
/** Information about a single item of news. */
 
struct NewsItem {
 
	NewsItem *prev;              ///< Previous news item
 
	NewsItem *next;              ///< Next news item
 
	StringID string_id;          ///< Message text
 
	Date date;                   ///< Date of the news
 
	NewsType type;               ///< Type of the news
 
	NewsFlag flags;              ///< NewsFlags bits @see NewsFlag
 
	NewsItem *prev;               ///< Previous news item
 
	NewsItem *next;               ///< Next news item
 
	StringID string_id;           ///< Message text
 
	TimerGameCalendar::Date date; ///< Date of the news
 
	NewsType type;                ///< Type of the news
 
	NewsFlag flags;               ///< NewsFlags bits @see NewsFlag
 

	
 
	NewsReferenceType reftype1;  ///< Type of ref1
 
	NewsReferenceType reftype2;  ///< Type of ref2
 
	uint32 ref1;                 ///< Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news, and for deleting the news when the object is deleted.
 
	uint32 ref2;                 ///< Reference 2 to some object: Used for scrolling after clicking on the news, and for deleting the news when the object is deleted.
 
	NewsReferenceType reftype1;   ///< Type of ref1
 
	NewsReferenceType reftype2;   ///< Type of ref2
 
	uint32 ref1;                  ///< Reference 1 to some object: Used for a possible viewport, scrolling after clicking on the news, and for deleting the news when the object is deleted.
 
	uint32 ref2;                  ///< Reference 2 to some object: Used for scrolling after clicking on the news, and for deleting the news when the object is deleted.
 

	
 
	std::unique_ptr<const NewsAllocatedData> data; ///< Custom data for the news item that will be deallocated (deleted) when the news item has reached its end.
 

	
 
	uint64 params[10]; ///< Parameters for string resolving.
 

	
 
	NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsReferenceType reftype1, uint32 ref1, NewsReferenceType reftype2, uint32 ref2, const NewsAllocatedData *data);
src/object_base.h
Show inline comments
 
@@ -11,23 +11,23 @@
 
#define OBJECT_BASE_H
 

	
 
#include "core/pool_type.hpp"
 
#include "object_type.h"
 
#include "tilearea_type.h"
 
#include "town_type.h"
 
#include "date_type.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
typedef Pool<Object, ObjectID, 64, 0xFF0000> ObjectPool;
 
extern ObjectPool _object_pool;
 

	
 
/** An object, such as transmitter, on the map. */
 
struct Object : ObjectPool::PoolItem<&_object_pool> {
 
	ObjectType type;    ///< Type of the object
 
	Town *town;         ///< Town the object is built in
 
	TileArea location;  ///< Location of the object
 
	Date build_date;    ///< Date of construction
 
	TimerGameCalendar::Date build_date; ///< Date of construction
 
	byte colour;        ///< Colour of the object, for display purpose
 
	byte view;          ///< The view setting for this object
 

	
 
	/** Make sure the object isn't zeroed. */
 
	Object() {}
 
	/** Make sure the right destructor is called as well! */
src/openttd.cpp
Show inline comments
 
@@ -100,13 +100,13 @@ extern std::string _config_file;
 

	
 
bool _save_config = false;
 
bool _request_newgrf_scan = false;
 
NewGRFScanCallback *_request_newgrf_scan_callback = nullptr;
 

	
 
/** Available settings for autosave intervals. */
 
static const Month _autosave_months[] = {
 
static const TimerGameCalendar::Month _autosave_months[] = {
 
	 0, ///< never
 
	 1, ///< every month
 
	 3, ///< every 3 months
 
	 6, ///< every 6 months
 
	12, ///< every 12 months
 
};
 
@@ -390,13 +390,13 @@ void OpenBrowser(const char *url)
 

	
 
	OSOpenBrowser(url);
 
}
 

	
 
/** Callback structure of statements to be executed after the NewGRF scan. */
 
struct AfterNewGRFScan : NewGRFScanCallback {
 
	Year startyear = INVALID_YEAR;              ///< The start year.
 
	TimerGameCalendar::Year startyear = INVALID_YEAR; ///< The start year.
 
	uint32 generation_seed = GENERATE_NEW_SEED; ///< Seed for the new game.
 
	std::string dedicated_host;                 ///< Hostname for the dedicated server.
 
	uint16 dedicated_port = 0;                  ///< Port for the dedicated server.
 
	std::string connection_string;              ///< Information about the server to connect to
 
	std::string join_server_password;           ///< The password to join the server with.
 
	std::string join_company_password;          ///< The password to join the company with.
src/rail.cpp
Show inline comments
 
@@ -212,13 +212,13 @@ bool ValParamRailtype(const RailType rai
 
 * Add the rail types that are to be introduced at the given date.
 
 * @param current The currently available railtypes.
 
 * @param date    The date for the introduction comparisons.
 
 * @return The rail types that should be available when date
 
 *         introduced rail types are taken into account as well.
 
 */
 
RailTypes AddDateIntroducedRailTypes(RailTypes current, Date date)
 
RailTypes AddDateIntroducedRailTypes(RailTypes current, TimerGameCalendar::Date date)
 
{
 
	RailTypes rts = current;
 

	
 
	for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
 
		const RailtypeInfo *rti = GetRailTypeInfo(rt);
 
		/* Unused rail type. */
src/rail.h
Show inline comments
 
@@ -15,12 +15,13 @@
 
#include "gfx_type.h"
 
#include "core/bitmath_func.hpp"
 
#include "economy_func.h"
 
#include "slope_type.h"
 
#include "strings_type.h"
 
#include "date_type.h"
 
#include "timer/timer_game_calendar.h"
 
#include "signal_type.h"
 
#include "settings_type.h"
 

	
 
/** Railtype flags. */
 
enum RailTypeFlags {
 
	RTF_CATENARY          = 0,                           ///< Bit number for drawing a catenary.
 
@@ -246,13 +247,13 @@ public:
 
	 * Introduction date.
 
	 * When #INVALID_DATE or a vehicle using this railtype gets introduced earlier,
 
	 * the vehicle's introduction date will be used instead for this railtype.
 
	 * The introduction at this date is furthermore limited by the
 
	 * #introduction_required_railtypes.
 
	 */
 
	Date introduction_date;
 
	TimerGameCalendar::Date introduction_date;
 

	
 
	/**
 
	 * Bitmask of railtypes that are required for this railtype to be introduced
 
	 * at a given #introduction_date.
 
	 */
 
	RailTypes introduction_required_railtypes;
 
@@ -447,13 +448,13 @@ Foundation GetRailFoundation(Slope tileh
 

	
 

	
 
bool HasRailtypeAvail(const CompanyID company, const RailType railtype);
 
bool HasAnyRailtypesAvail(const CompanyID company);
 
bool ValParamRailtype(const RailType rail);
 

	
 
RailTypes AddDateIntroducedRailTypes(RailTypes current, Date date);
 
RailTypes AddDateIntroducedRailTypes(RailTypes current, TimerGameCalendar::Date date);
 

	
 
RailTypes GetCompanyRailtypes(CompanyID company, bool introduces = true);
 
RailTypes GetRailTypes(bool introduces);
 

	
 
RailType GetRailTypeByLabel(RailTypeLabel label, bool allow_alternate_labels = true);
 

	
src/road.cpp
Show inline comments
 
@@ -150,13 +150,13 @@ bool ValParamRoadType(RoadType roadtype)
 
 * @param rt      Roadtype
 
 * @param current The currently available roadtypes.
 
 * @param date    The date for the introduction comparisons.
 
 * @return The road types that should be available when date
 
 *         introduced road types are taken into account as well.
 
 */
 
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, Date date)
 
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, TimerGameCalendar::Date date)
 
{
 
	RoadTypes rts = current;
 

	
 
	for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
 
		const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
 
		/* Unused road type. */
src/road.h
Show inline comments
 
@@ -11,13 +11,13 @@
 
#define ROAD_H
 

	
 
#include "road_type.h"
 
#include "gfx_type.h"
 
#include "core/bitmath_func.hpp"
 
#include "strings_type.h"
 
#include "date_type.h"
 
#include "timer/timer_game_calendar.h"
 
#include "core/enum_type.hpp"
 
#include "newgrf.h"
 
#include "economy_func.h"
 

	
 
#include <vector>
 

	
 
@@ -158,13 +158,13 @@ public:
 
	 * Introduction date.
 
	 * When #INVALID_DATE or a vehicle using this roadtype gets introduced earlier,
 
	 * the vehicle's introduction date will be used instead for this roadtype.
 
	 * The introduction at this date is furthermore limited by the
 
	 * #introduction_required_types.
 
	 */
 
	Date introduction_date;
 
	TimerGameCalendar::Date introduction_date;
 

	
 
	/**
 
	 * Bitmask of roadtypes that are required for this roadtype to be introduced
 
	 * at a given #introduction_date.
 
	 */
 
	RoadTypes introduction_required_roadtypes;
src/road_func.h
Show inline comments
 
@@ -148,13 +148,13 @@ static inline bool HasRoadCatenaryDrawn(
 
}
 

	
 
bool HasRoadTypeAvail(CompanyID company, RoadType roadtype);
 
bool ValParamRoadType(RoadType roadtype);
 
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces = true);
 
RoadTypes GetRoadTypes(bool introduces);
 
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, Date date);
 
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, TimerGameCalendar::Date date);
 

	
 
void UpdateLevelCrossing(TileIndex tile, bool sound = true, bool force_bar = false);
 
void MarkDirtyAdjacentLevelCrossingTiles(TileIndex tile, Axis road_axis);
 
void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count);
 

	
 
struct TileInfo;
src/saveload/oldloader_sl.cpp
Show inline comments
 
@@ -27,12 +27,13 @@
 
#include "../engine_func.h"
 
#include "../company_base.h"
 
#include "../disaster_vehicle.h"
 
#include "../core/smallvec_type.hpp"
 
#include "../timer/timer.h"
 
#include "../timer/timer_game_tick.h"
 
#include "../timer/timer_game_calendar.h"
 
#include "saveload_internal.h"
 
#include "oldloader.h"
 
#include <array>
 

	
 
#include "table/strings.h"
 
#include "../table/engines.h"
 
@@ -396,13 +397,13 @@ static bool FixTTOEngines()
 
		for (uint i = 0; i < lengthof(_orig_rail_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_TRAIN, i);
 
		for (uint i = 0; i < lengthof(_orig_road_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_ROAD, i);
 
		for (uint i = 0; i < lengthof(_orig_ship_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_SHIP, i);
 
		for (uint i = 0; i < lengthof(_orig_aircraft_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_AIRCRAFT, i);
 
	}
 

	
 
	Date aging_date = std::min(TimerGameCalendar::date + DAYS_TILL_ORIGINAL_BASE_YEAR, ConvertYMDToDate(2050, 0, 1));
 
	TimerGameCalendar::Date aging_date = std::min(TimerGameCalendar::date + DAYS_TILL_ORIGINAL_BASE_YEAR, ConvertYMDToDate(2050, 0, 1));
 

	
 
	for (EngineID i = 0; i < 256; i++) {
 
		int oi = ttd_to_tto[i];
 
		Engine *e = GetTempDataEngine(i);
 

	
 
		if (oi == 255) {
src/saveload/station_sl.cpp
Show inline comments
 
@@ -15,12 +15,13 @@
 
#include "../station_base.h"
 
#include "../waypoint_base.h"
 
#include "../roadstop_base.h"
 
#include "../vehicle_base.h"
 
#include "../newgrf_station.h"
 
#include "../newgrf_roadstop.h"
 
#include "../timer/timer_game_calendar.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "../safeguards.h"
 

	
 
/**
 
@@ -64,13 +65,13 @@ void MoveBuoysToWaypoints()
 

	
 
		StationID index    = st->index;
 
		TileIndex xy       = st->xy;
 
		Town *town         = st->town;
 
		StringID string_id = st->string_id;
 
		std::string name   = st->name;
 
		Date build_date    = st->build_date;
 
		TimerGameCalendar::Date build_date = st->build_date;
 
		/* TTDPatch could use "buoys with rail station" for rail waypoints */
 
		bool train         = st->train_station.tile != INVALID_TILE;
 
		TileArea train_st  = st->train_station;
 

	
 
		/* Delete the station, so we can make it a real waypoint. */
 
		delete st;
src/saveload/waypoint_sl.cpp
Show inline comments
 
@@ -11,12 +11,13 @@
 
#include "../waypoint_base.h"
 
#include "../debug.h"
 
#include "../newgrf_station.h"
 
#include "../vehicle_base.h"
 
#include "../town.h"
 
#include "../newgrf.h"
 
#include "../timer/timer_game_calendar.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "saveload_internal.h"
 

	
 
#include "../safeguards.h"
 
@@ -28,13 +29,13 @@ struct OldWaypoint {
 
	TownID town_index;
 
	Town *town;
 
	uint16 town_cn;
 
	StringID string_id;
 
	std::string name;
 
	uint8 delete_ctr;
 
	Date build_date;
 
	TimerGameCalendar::Date build_date;
 
	uint8 localidx;
 
	uint32 grfid;
 
	const StationSpec *spec;
 
	Owner owner;
 

	
 
	size_t new_index;
src/script/api/script_industry.cpp
Show inline comments
 
@@ -17,12 +17,13 @@
 
#include "../../industry.h"
 
#include "../../string_func.h"
 
#include "../../strings_func.h"
 
#include "../../station_base.h"
 
#include "../../newgrf_industries.h"
 
#include "../../industry_cmd.h"
 
#include "../../timer/timer_game_calendar.h"
 
#include "table/strings.h"
 
#include <numeric>
 

	
 
#include "../../safeguards.h"
 

	
 
/* static */ SQInteger ScriptIndustry::GetIndustryCount()
 
@@ -231,13 +232,13 @@
 
/* static */ ScriptDate::Date ScriptIndustry::GetCargoLastAcceptedDate(IndustryID industry_id, CargoID cargo_type)
 
{
 
	Industry *i = Industry::GetIfValid(industry_id);
 
	if (i == nullptr) return ScriptDate::DATE_INVALID;
 

	
 
	if (cargo_type == CT_INVALID) {
 
		return (ScriptDate::Date)std::accumulate(std::begin(i->last_cargo_accepted_at), std::end(i->last_cargo_accepted_at), 0, [](Date a, Date b) { return std::max(a, b); });
 
		return (ScriptDate::Date)std::accumulate(std::begin(i->last_cargo_accepted_at), std::end(i->last_cargo_accepted_at), 0, [](TimerGameCalendar::Date a, TimerGameCalendar::Date b) { return std::max(a, b); });
 
	} else {
 
		int index = i->GetCargoAcceptedIndex(cargo_type);
 
		if (index < 0) return ScriptDate::DATE_INVALID;
 
		return (ScriptDate::Date)i->last_cargo_accepted_at[index];
 
	}
 
}
src/settings_type.h
Show inline comments
 
@@ -8,12 +8,13 @@
 
/** @file settings_type.h Types related to global configuration settings. */
 

	
 
#ifndef SETTINGS_TYPE_H
 
#define SETTINGS_TYPE_H
 

	
 
#include "date_type.h"
 
#include "timer/timer_game_calendar.h"
 
#include "economy_type.h"
 
#include "town_type.h"
 
#include "transport_type.h"
 
#include "network/network_type.h"
 
#include "company_type.h"
 
#include "cargotype.h"
 
@@ -149,19 +150,19 @@ struct GUISettings {
 
	bool   timetable_arrival_departure;      ///< show arrivals and departures in vehicle timetables
 
	bool   right_mouse_wnd_close;            ///< close window with right click
 
	bool   pause_on_newgame;                 ///< whether to start new games paused or not
 
	SignalGUISettings signal_gui_mode;       ///< select which signal types are shown in the signal GUI
 
	SignalCycleSettings cycle_signal_types;  ///< Which signal types to cycle with the build signal tool.
 
	SignalType default_signal_type;          ///< The default signal type, which is set automatically by the last signal used. Not available in Settings.
 
	Year   coloured_news_year;               ///< when does newspaper become coloured?
 
	TimerGameCalendar::Year coloured_news_year; ///< when does newspaper become coloured?
 
	bool   timetable_in_ticks;               ///< whether to show the timetable in ticks rather than days
 
	bool   quick_goto;                       ///< Allow quick access to 'goto button' in vehicle orders window
 
	bool   auto_euro;                        ///< automatically switch to euro in 2002
 
	byte   drag_signals_density;             ///< many signals density
 
	bool   drag_signals_fixed_distance;      ///< keep fixed distance between signals when dragging
 
	Year   semaphore_build_before;           ///< build semaphore signals automatically before this year
 
	TimerGameCalendar::Year semaphore_build_before; ///< build semaphore signals automatically before this year
 
	byte   news_message_timeout;             ///< how much longer than the news message "age" should we keep the message in the history
 
	bool   show_track_reservation;           ///< highlight reserved tracks.
 
	byte   station_numtracks;                ///< the number of platforms to default on for rail stations
 
	byte   station_platlength;               ///< the platform length, in tiles, for rail stations
 
	bool   station_dragdrop;                 ///< whether drag and drop is enabled for stations
 
	bool   station_show_coverage;            ///< whether to highlight coverage area
 
@@ -298,25 +299,25 @@ struct NetworkSettings {
 
	bool        autoclean_companies;                      ///< automatically remove companies that are not in use
 
	uint8       autoclean_unprotected;                    ///< remove passwordless companies after this many months
 
	uint8       autoclean_protected;                      ///< remove the password from passworded companies after this many months
 
	uint8       autoclean_novehicles;                     ///< remove companies with no vehicles after this many months
 
	uint8       max_companies;                            ///< maximum amount of companies
 
	uint8       max_clients;                              ///< maximum amount of clients
 
	Year        restart_game_year;                        ///< year the server restarts
 
	TimerGameCalendar::Year restart_game_year;            ///< year the server restarts
 
	uint8       min_active_clients;                       ///< minimum amount of active clients to unpause the game
 
	bool        reload_cfg;                               ///< reload the config file before restarting
 
	std::string last_joined;                              ///< Last joined server
 
	bool        no_http_content_downloads;                ///< do not do content downloads over HTTP
 
	UseRelayService use_relay_service;                        ///< Use relay service?
 
};
 

	
 
/** Settings related to the creation of games. */
 
struct GameCreationSettings {
 
	uint32 generation_seed;                  ///< noise seed for world generation
 
	Year   starting_year;                    ///< starting date
 
	Year   ending_year;                      ///< scoring end date
 
	TimerGameCalendar::Year starting_year;   ///< starting date
 
	TimerGameCalendar::Year ending_year;     ///< scoring end date
 
	uint8  map_x;                            ///< X size of map
 
	uint8  map_y;                            ///< Y size of map
 
	byte   land_generator;                   ///< the landscape generator
 
	byte   oil_refinery_limit;               ///< distance oil refineries allowed from map edge
 
	byte   snow_line_height;                 ///< the configured snow line height (deduced from "snow_coverage")
 
	byte   snow_coverage;                    ///< the amount of snow coverage on the map
src/story.cpp
Show inline comments
 
@@ -342,13 +342,13 @@ CommandCost CmdSetStoryPageTitle(DoComma
 
 * Update date of a story page.
 
 * @param flags type of operation
 
 * @param page_id StoryPageID to update.
 
 * @param date date
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSetStoryPageDate(DoCommandFlag flags, StoryPageID page_id, Date date)
 
CommandCost CmdSetStoryPageDate(DoCommandFlag flags, StoryPageID page_id, TimerGameCalendar::Date date)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	if (!StoryPage::IsValidID(page_id)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		StoryPage *p = StoryPage::Get(page_id);
src/story_base.h
Show inline comments
 
@@ -9,13 +9,13 @@
 

	
 
#ifndef STORY_BASE_H
 
#define STORY_BASE_H
 

	
 
#include "company_type.h"
 
#include "story_type.h"
 
#include "date_type.h"
 
#include "timer/timer_game_calendar.h"
 
#include "gfx_type.h"
 
#include "vehicle_type.h"
 
#include "core/pool_type.hpp"
 

	
 
typedef Pool<StoryPageElement, StoryPageElementID, 64, 64000> StoryPageElementPool;
 
typedef Pool<StoryPage, StoryPageID, 64, 64000> StoryPagePool;
 
@@ -160,13 +160,13 @@ struct StoryPageElement : StoryPageEleme
 
	inline ~StoryPageElement() { free(this->text); }
 
};
 

	
 
/** Struct about stories, current and completed */
 
struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
 
	uint32 sort_value;   ///< A number that increases for every created story page. Used for sorting. The id of a story page is the pool index.
 
	Date date;           ///< Date when the page was created.
 
	TimerGameCalendar::Date date; ///< Date when the page was created.
 
	CompanyID company;   ///< StoryPage is for a specific company; INVALID_COMPANY if it is global
 

	
 
	char *title;         ///< Title of story page
 

	
 
	/**
 
	 * We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
src/story_cmd.h
Show inline comments
 
@@ -17,13 +17,13 @@
 
#include "vehicle_type.h"
 

	
 
std::tuple<CommandCost, StoryPageID> CmdCreateStoryPage(DoCommandFlag flags, CompanyID company, const std::string &text);
 
std::tuple<CommandCost, StoryPageElementID> CmdCreateStoryPageElement(DoCommandFlag flags, TileIndex tile, StoryPageID page_id, StoryPageElementType type, uint32 reference, const std::string &text);
 
CommandCost CmdUpdateStoryPageElement(DoCommandFlag flags, TileIndex tile, StoryPageElementID page_element_id, uint32 reference, const std::string &text);
 
CommandCost CmdSetStoryPageTitle(DoCommandFlag flags, StoryPageID page_id, const std::string &text);
 
CommandCost CmdSetStoryPageDate(DoCommandFlag flags, StoryPageID page_id, Date date);
 
CommandCost CmdSetStoryPageDate(DoCommandFlag flags, StoryPageID page_id, TimerGameCalendar::Date date);
 
CommandCost CmdShowStoryPage(DoCommandFlag flags, StoryPageID page_id);
 
CommandCost CmdRemoveStoryPage(DoCommandFlag flags, StoryPageID page_id);
 
CommandCost CmdRemoveStoryPageElement(DoCommandFlag flags, StoryPageElementID page_element_id);
 
CommandCost CmdStoryPageButton(DoCommandFlag flags, TileIndex tile, StoryPageElementID page_element_id, VehicleID reference);
 

	
 
DEF_CMD_TRAIT(CMD_CREATE_STORY_PAGE,         CmdCreateStoryPage,        CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT)
src/strings.cpp
Show inline comments
 
@@ -21,12 +21,13 @@
 
#include "error.h"
 
#include "error_func.h"
 
#include "strings_func.h"
 
#include "rev.h"
 
#include "core/endian_func.hpp"
 
#include "date_func.h"
 
#include "timer/timer_game_calendar.h"
 
#include "vehicle_base.h"
 
#include "engine_base.h"
 
#include "language.h"
 
#include "townname_func.h"
 
#include "string_func.h"
 
#include "company_base.h"
 
@@ -421,33 +422,33 @@ static char *FormatBytes(char *buff, int
 
	assert(id < lengthof(iec_prefixes));
 
	buff += seprintf(buff, last, NBSP "%sB", iec_prefixes[id]);
 

	
 
	return buff;
 
}
 

	
 
static char *FormatYmdString(char *buff, Date date, const char *last, uint case_index)
 
static char *FormatYmdString(char *buff, TimerGameCalendar::Date date, const char *last, uint case_index)
 
{
 
	YearMonthDay ymd;
 
	ConvertDateToYMD(date, &ymd);
 

	
 
	int64 args[] = {ymd.day + STR_DAY_NUMBER_1ST - 1, STR_MONTH_ABBREV_JAN + ymd.month, ymd.year};
 
	StringParameters tmp_params(args);
 
	return FormatString(buff, GetStringPtr(STR_FORMAT_DATE_LONG), &tmp_params, last, case_index);
 
}
 

	
 
static char *FormatMonthAndYear(char *buff, Date date, const char *last, uint case_index)
 
static char *FormatMonthAndYear(char *buff, TimerGameCalendar::Date date, const char *last, uint case_index)
 
{
 
	YearMonthDay ymd;
 
	ConvertDateToYMD(date, &ymd);
 

	
 
	int64 args[] = {STR_MONTH_JAN + ymd.month, ymd.year};
 
	StringParameters tmp_params(args);
 
	return FormatString(buff, GetStringPtr(STR_FORMAT_DATE_SHORT), &tmp_params, last, case_index);
 
}
 

	
 
static char *FormatTinyOrISODate(char *buff, Date date, StringID str, const char *last)
 
static char *FormatTinyOrISODate(char *buff, TimerGameCalendar::Date date, StringID str, const char *last)
 
{
 
	YearMonthDay ymd;
 
	ConvertDateToYMD(date, &ymd);
 

	
 
	/* Day and month are zero-padded with ZEROFILL_NUM, hence the two 2s. */
 
	int64 args[] = {ymd.day, 2, ymd.month + 1, 2, ymd.year};
src/table/airport_defaults.h
Show inline comments
 
@@ -7,12 +7,14 @@
 

	
 
/** @file airport_defaults.h Tables with default values for airports and airport tiles. */
 

	
 
#ifndef AIRPORT_DEFAULTS_H
 
#define AIRPORT_DEFAULTS_H
 

	
 
#include "date_type.h"
 

	
 
/**
 
 * Definition of an airport tiles layout.
 
 * @param x offset x of this tile
 
 * @param y offset y of this tile
 
 * @param m StationGfx of the tile
 
 * @see _airport_specs
src/tile_cmd.h
Show inline comments
 
@@ -12,12 +12,13 @@
 

	
 
#include "command_type.h"
 
#include "vehicle_type.h"
 
#include "cargo_type.h"
 
#include "track_type.h"
 
#include "tile_map.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
/** The returned bits of VehicleEnterTile. */
 
enum VehicleEnterTileStatus {
 
	VETS_ENTERED_STATION  = 1, ///< The vehicle entered a station
 
	VETS_ENTERED_WORMHOLE = 2, ///< The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/tunnel)
 
	VETS_CANNOT_ENTER     = 3, ///< The vehicle cannot enter the tile
 
@@ -49,13 +50,13 @@ struct TileInfo {
 

	
 
/** Tile description for the 'land area information' tool */
 
struct TileDesc {
 
	StringID str;               ///< Description of the tile
 
	Owner owner[4];             ///< Name of the owner(s)
 
	StringID owner_type[4];     ///< Type of each owner
 
	Date build_date;            ///< Date of construction of tile contents
 
	TimerGameCalendar::Date build_date; ///< Date of construction of tile contents
 
	StringID station_class;     ///< Class of station
 
	StringID station_name;      ///< Type of station within the class
 
	StringID airport_class;     ///< Name of the airport class
 
	StringID airport_name;      ///< Name of the airport
 
	StringID airport_tile_name; ///< Name of the airport tile
 
	const char *grf;            ///< newGRF used for the tile contents
src/timer/timer_game_calendar.cpp
Show inline comments
 
@@ -17,23 +17,23 @@
 
#include "timer_game_calendar.h"
 
#include "vehicle_base.h"
 
#include "linkgraph/linkgraph.h"
 

	
 
#include "safeguards.h"
 

	
 
Year TimerGameCalendar::year = {};
 
Month TimerGameCalendar::month = {};
 
Date TimerGameCalendar::date = {};
 
DateFract TimerGameCalendar::date_fract = {};
 
TimerGameCalendar::Year TimerGameCalendar::year = {};
 
TimerGameCalendar::Month TimerGameCalendar::month = {};
 
TimerGameCalendar::Date TimerGameCalendar::date = {};
 
TimerGameCalendar::DateFract TimerGameCalendar::date_fract = {};
 

	
 
/**
 
 * Set the date.
 
 * @param date  New date
 
 * @param fract The number of ticks that have passed on this date.
 
 */
 
/* static */ void TimerGameCalendar::SetDate(Date date, DateFract fract)
 
/* static */ void TimerGameCalendar::SetDate(TimerGameCalendar::Date date, TimerGameCalendar::DateFract fract)
 
{
 
	assert(fract < DAY_TICKS);
 

	
 
	YearMonthDay ymd;
 

	
 
	TimerGameCalendar::date = date;
src/timer/timer_game_calendar.h
Show inline comments
 
@@ -7,13 +7,13 @@
 

	
 
/** @file timer_game_calendar.h Definition of the game-calendar-timer */
 

	
 
#ifndef TIMER_GAME_CALENDAR_H
 
#define TIMER_GAME_CALENDAR_H
 

	
 
#include "../date_type.h"
 
#include "stdafx.h"
 

	
 
/**
 
 * Timer that is increased every 27ms, 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 27ms, this makes 1 day 1.998 seconds).
 
@@ -72,13 +72,20 @@ public:
 
	};
 

	
 
	using TElapsed = uint;
 
	struct TStorage {
 
	};
 

	
 
	static void SetDate(Date date, DateFract fract);
 
	using Date = int32; ///< The type to store our dates in
 
	using DateFract = uint16; ///< The fraction of a date we're in, i.e. the number of ticks since the last date changeover
 

	
 
	using Year = int32; ///< Type for the year, note: 0 based, i.e. starts at the year 0.
 
	using Month = uint8; ///< Type for the month, note: 0 based, i.e. 0 = January, 11 = December.
 
	using Day = uint8; ///< Type for the day of the month, note: 1 based, first day of a month is 1.
 

	
 
	static void SetDate(TimerGameCalendar::Date date, TimerGameCalendar::DateFract fract);
 

	
 
	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.
 
};
src/timetable_cmd.cpp
Show inline comments
 
@@ -289,13 +289,13 @@ static bool VehicleTimetableSorter(Vehic
 
 * @param flags Operation to perform.
 
 * @param veh_id Vehicle ID.
 
 * @param timetable_all Set to set timetable start for all vehicles sharing this order
 
 * @param start_date The timetable start date.
 
 * @return The error or cost of the operation.
 
 */
 
CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool timetable_all, Date start_date)
 
CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool timetable_all, TimerGameCalendar::Date start_date)
 
{
 
	Vehicle *v = Vehicle::GetIfValid(veh_id);
 
	if (v == nullptr || !v->IsPrimaryVehicle() || v->orders == nullptr) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
src/timetable_cmd.h
Show inline comments
 
@@ -8,18 +8,19 @@
 
/** @file timetable_cmd.h Command definitions related to timetables. */
 

	
 
#ifndef TIMETABLE_CMD_H
 
#define TIMETABLE_CMD_H
 

	
 
#include "command_type.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
CommandCost CmdChangeTimetable(DoCommandFlag flags, VehicleID veh, VehicleOrderID order_number, ModifyTimetableFlags mtf, uint16 data);
 
CommandCost CmdBulkChangeTimetable(DoCommandFlag flags, VehicleID veh, ModifyTimetableFlags mtf, uint16 data);
 
CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID veh, bool apply_to_group);
 
CommandCost CmdAutofillTimetable(DoCommandFlag flags, VehicleID veh, bool autofill, bool preserve_wait_time);
 
CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool timetable_all, Date start_date);
 
CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool timetable_all, TimerGameCalendar::Date start_date);
 

	
 
DEF_CMD_TRAIT(CMD_CHANGE_TIMETABLE,      CmdChangeTimetable,     0, CMDT_ROUTE_MANAGEMENT)
 
DEF_CMD_TRAIT(CMD_BULK_CHANGE_TIMETABLE, CmdBulkChangeTimetable, 0, CMDT_ROUTE_MANAGEMENT)
 
DEF_CMD_TRAIT(CMD_SET_VEHICLE_ON_TIME,   CmdSetVehicleOnTime,    0, CMDT_ROUTE_MANAGEMENT)
 
DEF_CMD_TRAIT(CMD_AUTOFILL_TIMETABLE,    CmdAutofillTimetable,   0, CMDT_ROUTE_MANAGEMENT)
 
DEF_CMD_TRAIT(CMD_SET_TIMETABLE_START,   CmdSetTimetableStart,   0, CMDT_ROUTE_MANAGEMENT)
src/timetable_gui.cpp
Show inline comments
 
@@ -140,13 +140,13 @@ static void FillTimetableArrivalDepartur
 

	
 
/**
 
 * Callback for when a time has been chosen to start the time table
 
 * @param w the window related to the setting of the date
 
 * @param date the actually chosen date
 
 */
 
static void ChangeTimetableStartCallback(const Window *w, Date date, void *data)
 
static void ChangeTimetableStartCallback(const Window *w, TimerGameCalendar::Date date, void *data)
 
{
 
	Command<CMD_SET_TIMETABLE_START>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, (VehicleID)w->window_number, reinterpret_cast<std::uintptr_t>(data) != 0, date);
 
}
 

	
 

	
 
struct TimetableWindow : Window {
src/toolbar_gui.cpp
Show inline comments
 
@@ -15,12 +15,13 @@
 
#include "command_func.h"
 
#include "vehicle_gui.h"
 
#include "rail_gui.h"
 
#include "road.h"
 
#include "road_gui.h"
 
#include "date_func.h"
 
#include "timer/timer_game_calendar.h"
 
#include "vehicle_func.h"
 
#include "sound_func.h"
 
#include "terraform_gui.h"
 
#include "strings_func.h"
 
#include "company_func.h"
 
#include "company_gui.h"
 
@@ -1141,16 +1142,16 @@ void ToggleDirtyBlocks()
 
}
 

	
 
/**
 
 * Set the starting year for a scenario.
 
 * @param year New starting year.
 
 */
 
void SetStartingYear(Year year)
 
void SetStartingYear(TimerGameCalendar::Year year)
 
{
 
	_settings_game.game_creation.starting_year = Clamp(year, MIN_YEAR, MAX_YEAR);
 
	Date new_date = ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1);
 
	TimerGameCalendar::Date new_date = ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1);
 
	/* If you open a savegame as scenario there may already be link graphs.*/
 
	LinkGraphSchedule::instance.ShiftDates(new_date - TimerGameCalendar::date);
 
	TimerGameCalendar::SetDate(new_date, 0);
 
}
 

	
 
/**
src/town.h
Show inline comments
 
@@ -8,12 +8,13 @@
 
/** @file town.h Base of the town class. */
 

	
 
#ifndef TOWN_H
 
#define TOWN_H
 

	
 
#include "viewport_type.h"
 
#include "date_type.h"
 
#include "town_map.h"
 
#include "subsidy_type.h"
 
#include "newgrf_storage.h"
 
#include "cargotype.h"
 
#include <list>
 

	
src/town_map.h
Show inline comments
 
@@ -9,12 +9,13 @@
 

	
 
#ifndef TOWN_MAP_H
 
#define TOWN_MAP_H
 

	
 
#include "road_map.h"
 
#include "house.h"
 
#include "timer/timer_game_calendar.h"
 

	
 
/**
 
 * Get the index of which town this house/street is attached to.
 
 * @param t the tile
 
 * @pre IsTileType(t, MP_HOUSE) or IsTileType(t, MP_ROAD) but not a road depot
 
 * @return TownID
 
@@ -243,13 +244,13 @@ static inline void IncrementHouseAge(Til
 
/**
 
 * Get the age of the house
 
 * @param t the tile of this house
 
 * @pre IsTileType(t, MP_HOUSE)
 
 * @return year
 
 */
 
static inline Year GetHouseAge(Tile t)
 
static inline TimerGameCalendar::Year GetHouseAge(Tile t)
 
{
 
	assert(IsTileType(t, MP_HOUSE));
 
	return IsHouseCompleted(t) ? t.m5() : 0;
 
}
 

	
 
/**
src/vehicle_base.h
Show inline comments
 
@@ -20,12 +20,13 @@
 
#include "order_func.h"
 
#include "transport_type.h"
 
#include "group_type.h"
 
#include "base_consist.h"
 
#include "network/network.h"
 
#include "saveload/saveload.h"
 
#include "timer/timer_game_calendar.h"
 
#include <list>
 
#include <map>
 

	
 
const uint TILE_AXIAL_DISTANCE = 192;  // Logical length of the tile in any DiagDirection used in vehicle movement.
 
const uint TILE_CORNER_DISTANCE = 128;  // Logical length of the tile corner crossing in any non-diagonal direction used in vehicle movement.
 

	
 
@@ -283,16 +284,16 @@ public:
 
	Vehicle **hash_tile_prev;           ///< NOSAVE: Previous vehicle in the tile location hash.
 
	Vehicle **hash_tile_current;        ///< NOSAVE: Cache of the current hash chain.
 

	
 
	SpriteID colourmap;                 ///< NOSAVE: cached colour mapping
 

	
 
	/* Related to age and service time */
 
	Year build_year;                    ///< Year the vehicle has been built.
 
	Date age;                           ///< Age in days
 
	Date max_age;                       ///< Maximum age
 
	Date date_of_last_service;          ///< Last date the vehicle had a service at a depot.
 
	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.
 
	uint16 reliability;                 ///< Reliability.
 
	uint16 reliability_spd_dec;         ///< Reliability decrease speed.
 
	byte breakdown_ctr;                 ///< Counter for managing breakdown events. @see Vehicle::HandleBreakdown
 
	byte breakdown_delay;               ///< Counter for managing breakdown length.
 
	byte breakdowns_since_last_service; ///< Counter for the amount of breakdowns.
 
	byte breakdown_chance;              ///< Current chance of breakdowns.
src/vehicle_func.h
Show inline comments
 
@@ -8,12 +8,13 @@
 
/** @file vehicle_func.h Functions related to vehicles. */
 

	
 
#ifndef VEHICLE_FUNC_H
 
#define VEHICLE_FUNC_H
 

	
 
#include "gfx_type.h"
 
#include "date_type.h"
 
#include "direction_type.h"
 
#include "command_type.h"
 
#include "vehicle_type.h"
 
#include "engine_type.h"
 
#include "transport_type.h"
 
#include "newgrf_config.h"
src/vehicle_gui.cpp
Show inline comments
 
@@ -404,13 +404,13 @@ void DepotSortList(VehicleList *list)
 
{
 
	if (list->size() < 2) return;
 
	std::sort(list->begin(), list->end(), &VehicleNumberSorter);
 
}
 

	
 
/** draw the vehicle profit button in the vehicle list window. */
 
static void DrawVehicleProfitButton(Date age, Money display_profit_last_year, uint num_vehicles, int x, int y)
 
static void DrawVehicleProfitButton(TimerGameCalendar::Date age, Money display_profit_last_year, uint num_vehicles, int x, int y)
 
{
 
	SpriteID spr;
 

	
 
	/* draw profit-based coloured icons */
 
	if (age <= VEHICLE_PROFIT_MIN_AGE) {
 
		spr = SPR_PROFIT_NA;
src/vehicle_gui_base.h
Show inline comments
 
@@ -9,13 +9,13 @@
 

	
 
#ifndef VEHICLE_GUI_BASE_H
 
#define VEHICLE_GUI_BASE_H
 

	
 
#include "core/smallvec_type.hpp"
 
#include "cargo_type.h"
 
#include "date_type.h"
 
#include "timer/timer_game_calendar.h"
 
#include "economy_type.h"
 
#include "sortlist_type.h"
 
#include "vehicle_base.h"
 
#include "vehiclelist.h"
 
#include "window_gui.h"
 
#include "widgets/dropdown_type.h"
 
@@ -54,13 +54,13 @@ struct GUIVehicleGroup {
 
	{
 
		return std::accumulate(this->vehicles_begin, this->vehicles_end, (Money)0, [](Money acc, const Vehicle *v) {
 
			return acc + v->GetDisplayProfitLastYear();
 
		});
 
	}
 

	
 
	Date GetOldestVehicleAge() const
 
	TimerGameCalendar::Date GetOldestVehicleAge() const
 
	{
 
		const Vehicle *oldest = *std::max_element(this->vehicles_begin, this->vehicles_end, [](const Vehicle *v_a, const Vehicle *v_b) {
 
			return v_a->age < v_b->age;
 
		});
 
		return oldest->age;
 
	}
0 comments (0 inline, 0 general)