@@ -112,14 +112,12 @@ add_files(
cpu.cpp
cpu.h
crashlog.cpp
crashlog.h
currency.cpp
currency.h
date.cpp
date_func.h
date_gui.cpp
date_gui.h
date_type.h
debug.cpp
debug.h
dedicated.cpp
@@ -20,13 +20,13 @@
#include "newgrf_engine.h"
#include "newgrf_text.h"
#include "group.h"
#include "string_func.h"
#include "strings_func.h"
#include "window_func.h"
#include "date_func.h"
#include "timer/timer_game_calendar.h"
#include "vehicle_func.h"
#include "widgets/dropdown_func.h"
#include "engine_gui.h"
#include "cargotype.h"
#include "core/geometry_func.hpp"
#include "autoreplace_func.h"
@@ -917,14 +917,14 @@ void TestedEngineDetails::FillDefaultCap
* @param engine_number the engine of which to draw the info of
* @return y after drawing all the text
*/
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
{
const Engine *e = Engine::Get(engine_number);
YearMonthDay ymd;
ConvertDateToYMD(e->intro_date, &ymd);
TimerGameCalendar::YearMonthDay ymd;
TimerGameCalendar::ConvertDateToYMD(e->intro_date, &ymd);
bool refittable = IsArticulatedVehicleRefittable(engine_number);
bool articulated_cargo = false;
switch (e->type) {
default: NOT_REACHED();
case VEH_TRAIN:
@@ -9,13 +9,12 @@
#include "stdafx.h"
#include "command_func.h"
#include "cheat_type.h"
#include "company_base.h"
#include "company_func.h"
#include "saveload/saveload.h"
#include "vehicle_base.h"
#include "textbuf_gui.h"
#include "window_gui.h"
@@ -105,15 +104,15 @@ extern void EnginesMonthlyLoop();
static int32 ClickChangeDateCheat(int32 new_value, int32 change_direction)
/* 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;
ConvertDateToYMD(TimerGameCalendar::date, &ymd);
TimerGameCalendar::Date new_date = ConvertYMDToDate(new_value, ymd.month, ymd.day);
TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date, &ymd);
TimerGameCalendar::Date new_date = TimerGameCalendar::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. */
@@ -320,13 +319,13 @@ struct CheatWindow : Window {
break;
default:
switch (ce->str) {
/* Display date for change date cheat */
case STR_CHEAT_CHANGE_DATE:
SetDParam(0, ConvertYMDToDate(MAX_YEAR, 11, 31));
SetDParam(0, TimerGameCalendar::ConvertYMDToDate(MAX_YEAR, 11, 31));
width = std::max(width, GetStringBoundingBox(ce->str).width);
/* Draw coloured flag for change company cheat */
case STR_CHEAT_CHANGE_COMPANY:
SetDParamMaxValue(0, MAX_COMPANIES);
@@ -26,13 +26,12 @@
#include "fontcache.h"
#include "screenshot.h"
#include "genworld.h"
#include "viewport_func.h"
#include "gamelog.h"
#include "ai/ai.hpp"
#include "ai/ai_config.hpp"
#include "newgrf.h"
@@ -1446,14 +1445,14 @@ DEF_CONSOLE_CMD(ConGetDate)
if (argc == 0) {
IConsolePrint(CC_HELP, "Returns the current date (year-month-day) of the game. Usage: 'getdate'.");
return true;
}
IConsolePrint(CC_DEFAULT, "Date: {:04d}-{:02d}-{:02d}", ymd.year, ymd.month + 1, ymd.day);
DEF_CONSOLE_CMD(ConGetSysDate)
@@ -7,13 +7,12 @@
/** @file crashlog.cpp Implementation of generic function to be called to log a crash */
#include "crashlog.h"
#include "map_func.h"
#include "rev.h"
#include "blitter/factory.hpp"
#include "base_media_base.h"
@@ -316,14 +315,14 @@ char *CrashLog::LogGamelog(char *buffer,
char *CrashLog::LogRecentNews(char *buffer, const char *last) const
buffer += seprintf(buffer, last, "Recent news messages:\n");
int i = 0;
for (NewsItem *news = _latest_news; i < 32 && news != nullptr; news = news->prev, i++) {
ConvertDateToYMD(news->date, &ymd);
TimerGameCalendar::ConvertDateToYMD(news->date, &ymd);
buffer += seprintf(buffer, last, "(%i-%02i-%02i) StringID: %u, Type: %u, Ref1: %u, %u, Ref2: %u, %u\n",
ymd.year, ymd.month + 1, ymd.day, news->string_id, news->type,
news->reftype1, news->ref1, news->reftype2, news->ref2);
buffer += seprintf(buffer, last, "\n");
return buffer;
@@ -356,14 +355,14 @@ int CrashLog::CreateFileName(char *filen
char *CrashLog::FillCrashLog(char *buffer, const char *last) const
buffer += seprintf(buffer, last, "*** OpenTTD Crash Report ***\n\n");
buffer += UTCTime::Format(buffer, last, "Crash at: %Y-%m-%d %H:%M:%S (UTC)\n");
buffer += seprintf(buffer, last, "In game date: %i-%02i-%02i (%i)\n\n", ymd.year, ymd.month + 1, ymd.day, TimerGameCalendar::date_fract);
buffer = this->LogError(buffer, last, CrashLog::message.c_str());
buffer = this->LogOpenTTDVersion(buffer, last);
buffer = this->LogRegisters(buffer, last);
buffer = this->LogStacktrace(buffer, last);
deleted file
@@ -6,30 +6,30 @@
/** @file date_gui.cpp Graphical selection of a date. */
#include "date_gui.h"
#include "date_type.h"
#include "widgets/dropdown_type.h"
#include "widgets/date_widget.h"
#include "safeguards.h"
/** 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
TimerGameCalendar::YearMonthDay date; ///< The currently selected date
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
@@ -49,13 +49,13 @@ struct SetDateWindow : Window {
assert(this->min_year <= this->max_year);
this->parent = parent;
this->InitNested(window_number);
if (initial_date == 0) initial_date = TimerGameCalendar::date;
ConvertDateToYMD(initial_date, &this->date);
TimerGameCalendar::ConvertDateToYMD(initial_date, &this->date);
this->date.year = Clamp(this->date.year, min_year, max_year);
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
Point pt = { this->parent->left + this->parent->width / 2 - sm_width / 2, this->parent->top + this->parent->height / 2 - sm_height / 2 };
@@ -146,13 +146,13 @@ struct SetDateWindow : Window {
case WID_SD_MONTH:
case WID_SD_YEAR:
ShowDateDropDown(widget);
case WID_SD_SET_DATE:
if (this->callback != nullptr) this->callback(this, ConvertYMDToDate(this->date.year, this->date.month, this->date.day), this->callback_data);
if (this->callback != nullptr) this->callback(this, TimerGameCalendar::ConvertYMDToDate(this->date.year, this->date.month, this->date.day), this->callback_data);
this->Close();
void OnDropdownSelect(int widget, int index) override
@@ -71,13 +71,13 @@ static const TimerGameCalendar::Year ORI
* @return the date.
#define DAYS_TILL(year) (DAYS_IN_YEAR * (year) + LEAP_YEARS_TILL(year))
* The offset in days from the 'TimerGameCalendar::date == 0' till
* 'ConvertYMDToDate(ORIGINAL_BASE_YEAR, 0, 1)'
* 'TimerGameCalendar::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 TimerGameCalendar::Year MIN_YEAR = 0;
@@ -92,21 +92,11 @@ static const TimerGameCalendar::Year DEF
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 {
TimerGameCalendar::Year year; ///< Year (0...)
TimerGameCalendar::Month month; ///< Month (0..11)
TimerGameCalendar::Day day; ///< Day (1..31)
};
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 */
@@ -14,13 +14,12 @@
#include "aircraft.h"
#include "core/random_func.hpp"
#include "autoreplace_gui.h"
#include "core/pool_func.hpp"
#include "engine_func.h"
@@ -660,14 +659,14 @@ void SetYearEngineAgingStops()
/* Exclude certain engines */
if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) continue;
if (e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON) continue;
/* Base year ending date on half the model life */
ConvertDateToYMD(ei->base_intro + (ei->lifelength * DAYS_IN_LEAP_YEAR) / 2, &ymd);
TimerGameCalendar::ConvertDateToYMD(ei->base_intro + (ei->lifelength * DAYS_IN_LEAP_YEAR) / 2, &ymd);
_year_engine_aging_stops = std::max(_year_engine_aging_stops, ymd.year);
@@ -695,13 +694,13 @@ void StartupOneEngine(Engine *e, TimerGa
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 : (TimerGameCalendar::Date)GB(r, 0, 9) + ei->base_intro;
e->intro_date = ei->base_intro <= TimerGameCalendar::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 +741,13 @@ void StartupOneEngine(Engine *e, TimerGa
* 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 TimerGameCalendar::Date aging_date = std::min(TimerGameCalendar::date, ConvertYMDToDate(_year_engine_aging_stops, 0, 1));
const TimerGameCalendar::Date aging_date = std::min(TimerGameCalendar::date, TimerGameCalendar::ConvertYMDToDate(_year_engine_aging_stops, 0, 1));
uint32 seed = Random();
for (Engine *e : Engine::Iterate()) {
StartupOneEngine(e, aging_date, seed);
#include "fios.h"
#include "tilehighlight_func.h"
#include "querystring_gui.h"
#include "landscape_type.h"
#include "stringfilter_type.h"
#include "misc_cmd.h"
#include "gamelog_internal.h"
@@ -517,13 +517,13 @@ public:
tr.top += WidgetDimensions::scaled.vsep_normal;
if (tr.top > tr.bottom) return;
/* Start date (if available) */
if (_load_check_data.settings.game_creation.starting_year != 0) {
SetDParam(0, ConvertYMDToDate(_load_check_data.settings.game_creation.starting_year, 0, 1));
SetDParam(0, TimerGameCalendar::ConvertYMDToDate(_load_check_data.settings.game_creation.starting_year, 0, 1));
DrawString(tr, STR_NETWORK_SERVER_LIST_START_DATE);
tr.top += FONT_HEIGHT_NORMAL;
/* Hide current date for scenarios */
@@ -11,13 +11,13 @@
#include "settings_type.h"
#include "console_func.h"
#include "debug.h"
#include "timer/timer_game_tick.h"
#include <stdarg.h>
#include "heightmap.h"
#include "network/network.h"
#include "sound_func.h"
@@ -434,13 +434,13 @@ struct GenerateLandscapeWindow : public
void SetStringParameters(int widget) const override
switch (widget) {
case WID_GL_START_DATE_TEXT: SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); break;
case WID_GL_START_DATE_TEXT: SetDParam(0, TimerGameCalendar::ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); break;
case WID_GL_MAPSIZE_X_PULLDOWN: SetDParam(0, 1LL << _settings_newgame.game_creation.map_x); break;
case WID_GL_MAPSIZE_Y_PULLDOWN: SetDParam(0, 1LL << _settings_newgame.game_creation.map_y); break;
case WID_GL_HEIGHTMAP_HEIGHT_TEXT: SetDParam(0, _settings_newgame.game_creation.heightmap_height); break;
case WID_GL_SNOW_COVERAGE_TEXT: SetDParam(0, _settings_newgame.game_creation.snow_coverage); break;
case WID_GL_DESERT_COVERAGE_TEXT: SetDParam(0, _settings_newgame.game_creation.desert_coverage); break;
@@ -597,13 +597,13 @@ struct GenerateLandscapeWindow : public
case WID_GL_HEIGHTMAP_HEIGHT_TEXT:
SetDParam(0, MAX_TILE_HEIGHT);
d = GetStringBoundingBox(STR_JUST_INT);
case WID_GL_START_DATE_TEXT:
SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
SetDParam(0, TimerGameCalendar::ConvertYMDToDate(MAX_YEAR, 0, 1));
d = GetStringBoundingBox(STR_BLACK_DATE_LONG);
case WID_GL_MAPSIZE_X_PULLDOWN:
case WID_GL_MAPSIZE_Y_PULLDOWN:
SetDParamMaxValue(0, MAX_MAP_SIZE);
@@ -1104,13 +1104,13 @@ struct CreateScenarioWindow : public Win
case WID_CS_START_DATE_TEXT:
SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1));
SetDParam(0, TimerGameCalendar::ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1));
case WID_CS_MAPSIZE_X_PULLDOWN:
SetDParam(0, 1LL << _settings_newgame.game_creation.map_x);
@@ -1141,13 +1141,13 @@ struct CreateScenarioWindow : public Win
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
StringID str = STR_JUST_INT;
str = STR_BLACK_DATE_LONG;
case WID_CS_MAPSIZE_Y_PULLDOWN:
@@ -14,18 +14,18 @@
#include "company_gui.h"
#include "economy_func.h"
#include "gfx_func.h"
#include "currency.h"
#include "timer/timer.h"
#include "timer/timer_window.h"
#include "zoom_func.h"
#include "widgets/graph_widget.h"
#include "table/strings.h"
#include "table/sprites.h"
@@ -24,13 +24,12 @@
#include "newgrf_debug.h"
#include "newgrf_industrytiles.h"
#include "autoslope.h"
#include "water.h"
#include "animated_tile_func.h"
#include "effectvehicle_func.h"
#include "effectvehicle_base.h"
@@ -18,13 +18,12 @@
#include "landscape.h"
#include "void_map.h"
#include "tgp.h"
#include "error_func.h"
@@ -610,14 +609,14 @@ void SetSnowLine(byte table[SNOW_LINE_MO
* @ingroup SnowLineGroup
byte GetSnowLine()
if (_snow_line == nullptr) return _settings_game.game_creation.snow_line_height;
return _snow_line->table[ymd.month][ymd.day];
* Get the highest possible snow line height, either variable or static.
* @return the highest snow line height.
@@ -9,13 +9,13 @@
#include "../stdafx.h"
#include "../window_gui.h"
#include "../window_func.h"
#include "../company_base.h"
#include "../company_gui.h"
#include "../date_func.h"
#include "../timer/timer_game_calendar.h"
#include "../viewport_func.h"
#include "../zoom_func.h"
#include "../smallmap_gui.h"
#include "../core/geometry_func.hpp"
#include "../widgets/link_graph_legend_widget.h"
@@ -12,13 +12,13 @@
#include "news_func.h"
#include "script/script_gui.h"
#include "newgrf_house.h"
#include "texteff.hpp"
@@ -71,13 +71,13 @@ void InitializeGame(uint size_x, uint si
_thd.redsq = INVALID_TILE;
if (reset_settings) MakeNewgameSettingsLive();
_newgrf_profilers.clear();
if (reset_date) {
TimerGameCalendar::SetDate(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1), 0);
TimerGameCalendar::SetDate(TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1), 0);
InitializeOldNames();
LinkGraphSchedule::Clear();
PoolBase::Clean(PT_NORMAL);
@@ -10,13 +10,12 @@
#include "../../stdafx.h"
#include "game_info.h"
#include "../../core/bitmath_func.hpp"
#include "../../company_base.h"
#include "../../date_func.h"
#include "../../timer/timer_game_calendar.h"
#include "../../debug.h"
#include "../../map_func.h"
#include "../../game/game.hpp"
#include "../../game/game_info.hpp"
#include "../../settings_type.h"
@@ -121,13 +120,13 @@ void CheckGameCompatibility(NetworkGameI
* Fill a NetworkServerGameInfo structure with the static content, or things
* that are so static they can be updated on request from a settings change.
void FillStaticNetworkServerGameInfo()
_network_game_info.use_password = !_settings_client.network.server_password.empty();
_network_game_info.start_date = ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1);
_network_game_info.start_date = TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1);
_network_game_info.clients_max = _settings_client.network.max_clients;
_network_game_info.companies_max = _settings_client.network.max_companies;
_network_game_info.map_width = Map::SizeX();
_network_game_info.map_height = Map::SizeY();
_network_game_info.landscape = _settings_game.game_creation.landscape;
_network_game_info.dedicated = _network_dedicated;
@@ -253,13 +252,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 TimerGameCalendar::Date MAX_DATE = ConvertYMDToDate(MAX_YEAR, 11, 31); // December is month 11
static const TimerGameCalendar::Date MAX_DATE = TimerGameCalendar::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.
@@ -7,13 +7,13 @@
* @file tcp_coordinator.cpp Basic functions to receive and send Game Coordinator packets.
#include "tcp_coordinator.h"
#include "../../safeguards.h"
* @file tcp_turn.cpp Basic functions to receive and send TURN packets.
#include "tcp_turn.h"
* @file core/udp.cpp Basic functions to receive and send UDP packets.
#include "udp.h"
@@ -6,13 +6,13 @@
/** @file network_admin.cpp Server part of the admin network protocol. */
#include "../strings_func.h"
#include "core/game_info.h"
#include "network_admin.h"
#include "network_base.h"
#include "network_server.h"
#include "../command_func.h"
@@ -175,13 +175,13 @@ NetworkRecvStatus ServerNetworkAdminSock
p->Send_string(GetNetworkRevisionString());
p->Send_bool (_network_dedicated);
p->Send_string(""); // Used to be map-name.
p->Send_uint32(_settings_game.game_creation.generation_seed);
p->Send_uint8 (_settings_game.game_creation.landscape);
p->Send_uint32(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1));
p->Send_uint32(TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1));
p->Send_uint16(Map::SizeX());
p->Send_uint16(Map::SizeY());
this->SendPacket(p);
return NETWORK_RECV_STATUS_OKAY;
@@ -6,13 +6,12 @@
/** @file network_gui.cpp Implementation of the Network related GUIs. */
#include "../fios.h"
#include "network_client.h"
#include "network_gui.h"
#include "network_gamelist.h"
#include "network.h"
@@ -35,12 +34,13 @@
#include "../sprite.h"
#include "../settings_internal.h"
#include "../company_cmd.h"
#include "../timer/timer.h"
#include "../timer/timer_window.h"
#include "../widgets/network_widget.h"
#include "../table/sprites.h"
@@ -429,24 +429,24 @@ protected:
DrawString(mapsize.left, mapsize.right, y + text_y_offset, STR_NETWORK_SERVER_LIST_MAP_SIZE_SHORT, TC_FROMSTRING, SA_HOR_CENTER);
if (nwi_header->IsWidgetVisible(WID_NG_DATE)) {
/* current date */
Rect date = this->GetWidget<NWidgetBase>(WID_NG_DATE)->GetCurrentRect();
ConvertDateToYMD(cur_item->info.game_date, &ymd);
TimerGameCalendar::ConvertDateToYMD(cur_item->info.game_date, &ymd);
SetDParam(0, ymd.year);
DrawString(date.left, date.right, y + text_y_offset, STR_JUST_INT, TC_BLACK, SA_HOR_CENTER);
if (nwi_header->IsWidgetVisible(WID_NG_YEARS)) {
/* number of years the game is running */
Rect years = this->GetWidget<NWidgetBase>(WID_NG_YEARS)->GetCurrentRect();
YearMonthDay ymd_cur, ymd_start;
ConvertDateToYMD(cur_item->info.game_date, &ymd_cur);
ConvertDateToYMD(cur_item->info.start_date, &ymd_start);
TimerGameCalendar::YearMonthDay ymd_cur, ymd_start;
TimerGameCalendar::ConvertDateToYMD(cur_item->info.game_date, &ymd_cur);
TimerGameCalendar::ConvertDateToYMD(cur_item->info.start_date, &ymd_start);
SetDParam(0, ymd_cur.year - ymd_start.year);
DrawString(years.left, years.right, y + text_y_offset, STR_JUST_INT, TC_BLACK, SA_HOR_CENTER);
/* draw a lock if the server is password protected */
if (cur_item->info.use_password) DrawSprite(SPR_LOCK, PAL_NONE, info.left + this->lock_offset, y + lock_y_offset);
@@ -10,13 +10,13 @@
*
* This is the GameServer <-> GameClient
* communication before the game is being joined.
#include "../map_func.h"
#include "../debug.h"
#include "network_internal.h"
#include "network_udp.h"
@@ -34,13 +34,12 @@
#include "newgrf_airporttiles.h"
#include "newgrf_airport.h"
#include "newgrf_object.h"
#include "network/core/config.h"
#include <map>
#include "smallmap_gui.h"
@@ -6510,16 +6509,16 @@ bool GetGlobalVariable(byte param, uint3
case 0x01: // current year
*value = Clamp(TimerGameCalendar::year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
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)
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;
TimerGameCalendar::Date start_of_year = TimerGameCalendar::ConvertYMDToDate(ymd.year, 0, 1);
*value = ymd.month | (ymd.day - 1) << 8 | (TimerGameCalendar::IsLeapYear(ymd.year) ? 1 << 15 : 0) | (TimerGameCalendar::date - start_of_year) << 16;
case 0x03: // current climate, 0=temp, 1=arctic, 2=trop, 3=toyland
*value = _settings_game.game_creation.landscape;
@@ -9944,13 +9943,13 @@ void LoadNewGRF(uint load_index, uint nu
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);
TimerGameCalendar::date = TimerGameCalendar::ConvertYMDToDate(TimerGameCalendar::year, 0, 1);
TimerGameCalendar::date_fract = 0;
TimerGameTick::counter = 0;
_display_opt = 0;
InitializeGRFSpecial();
@@ -9,14 +9,12 @@
#include "gui.h"
#include "vehicle_gui.h"
#include "roadveh.h"
#include "station_base.h"
#include "industry.h"
@@ -35,12 +33,13 @@
#include "settings_internal.h"
#include "group_gui.h"
#include "news_cmd.h"
#include "widgets/news_widget.h"
@@ -1152,13 +1151,13 @@ struct MessageHistoryWindow : Window {
if (widget == WID_MH_BACKGROUND) {
this->line_height = FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal;
resize->height = this->line_height;
/* Months are off-by-one, so it's actually 8. Not using
* month 12 because the 1 is usually less wide. */
SetDParam(0, ConvertYMDToDate(ORIGINAL_MAX_YEAR, 7, 30));
SetDParam(0, TimerGameCalendar::ConvertYMDToDate(ORIGINAL_MAX_YEAR, 7, 30));
this->date_width = GetStringBoundingBox(STR_SHORT_DATE).width + WidgetDimensions::scaled.hsep_wide;
size->height = 4 * resize->height + WidgetDimensions::scaled.framerect.Vertical(); // At least 4 lines are visible.
size->width = std::max(200u, size->width); // At least 200 pixels wide.
/** @file yapf_costcache.hpp Caching of segment costs. */
#ifndef YAPF_COSTCACHE_HPP
#define YAPF_COSTCACHE_HPP
* CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements
* PfNodeCacheFetch() and PfNodeCacheFlush() callbacks. Used when nodes don't have CachedData
* defined (they don't count with any segment cost caching).
@@ -19,13 +19,12 @@
#include "../viewport_kdtree.h"
#include "../industry.h"
#include "../clear_map.h"
#include "../vehicle_func.h"
#include "../string_func.h"
#include "../roadveh.h"
#include "../roadveh_cmd.h"
#include "../train.h"
#include "../station_base.h"
#include "../waypoint_base.h"
#include "../roadstop_base.h"
@@ -56,12 +55,13 @@
#include "../order_backup.h"
#include "../error.h"
#include "../disaster_vehicle.h"
#include "../ship.h"
#include "../water.h"
#include "../timer/timer_game_tick.h"
#include "saveload_internal.h"
#include <signal.h>
@@ -9,21 +9,21 @@
#include "saveload.h"
#include "compat/misc_sl_compat.h"
#include "../gfx_func.h"
#include "../core/random_func.hpp"
#include "../date_type.h"
#include "../safeguards.h"
extern TileIndex _cur_tileloop_tile;
@@ -17,13 +17,13 @@
#include "../signs_base.h"
#include "../subsidy_base.h"
#include "../depot_base.h"
#include "../effectvehicle_base.h"
#include "../engine_func.h"
@@ -397,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);
TimerGameCalendar::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, TimerGameCalendar::ConvertYMDToDate(2050, 0, 1));
for (EngineID i = 0; i < 256; i++) {
int oi = ttd_to_tto[i];
Engine *e = GetTempDataEngine(i);
if (oi == 255) {
@@ -844,14 +844,14 @@ static bool LoadOldIndustry(LoadgameStat
i->town = Town::Get(RemapTownIndex(_old_town_index));
if (_savegame_type == SGT_TTO) {
if (i->type > 0x06) i->type++; // Printing Works were added
if (i->type == 0x0A) i->type = 0x12; // Iron Ore Mine has different ID
i->last_prod_year = ymd.year;
i->random_colour = RemapTTOColour(i->random_colour);
Industry::IncIndustryTypeCount(i->type);
@@ -28,13 +28,13 @@
#include "../network/network.h"
#include "../core/endian_func.hpp"
#include "../vehicle_base.h"
#include "../company_func.h"
#include "../autoreplace_base.h"
#include "../linkgraph/linkgraph.h"
#include "../linkgraph/linkgraphjob.h"
#include "../statusbar_gui.h"
#include "../fileio_func.h"
/** @file script_date.cpp Implementation of ScriptDate. */
#include "script_date.hpp"
#include <time.h>
@@ -27,42 +26,42 @@
/* static */ SQInteger ScriptDate::GetYear(ScriptDate::Date date)
if (date < 0) return DATE_INVALID;
::YearMonthDay ymd;
::ConvertDateToYMD(date, &ymd);
::TimerGameCalendar::YearMonthDay ymd;
::TimerGameCalendar::ConvertDateToYMD(date, &ymd);
return ymd.year;
/* static */ SQInteger ScriptDate::GetMonth(ScriptDate::Date date)
return ymd.month + 1;
/* static */ SQInteger ScriptDate::GetDayOfMonth(ScriptDate::Date date)
return ymd.day;
/* static */ ScriptDate::Date ScriptDate::GetDate(SQInteger year, SQInteger month, SQInteger day_of_month)
if (month < 1 || month > 12) return DATE_INVALID;
if (day_of_month < 1 || day_of_month > 31) return DATE_INVALID;
if (year < 0 || year > MAX_YEAR) return DATE_INVALID;
return (ScriptDate::Date)::ConvertYMDToDate(year, month - 1, day_of_month);
return (ScriptDate::Date)::TimerGameCalendar::ConvertYMDToDate(year, month - 1, day_of_month);
/* static */ SQInteger ScriptDate::GetSystemTime()
time_t t;
time(&t);
@@ -42,12 +42,13 @@
#include "game/game_config.hpp"
#include "newgrf_config.h"
#include "fileio_func.h"
#include "settings_cmd.h"
ClientSettings _settings_client;
/** @file settings_type.h Types related to global configuration settings. */
#ifndef SETTINGS_TYPE_H
#define SETTINGS_TYPE_H
#include "economy_type.h"
#include "town_type.h"
#include "transport_type.h"
#include "network/network_type.h"
#include "company_type.h"
@@ -26,13 +26,13 @@
#include "pathfinder/yapf/yapf_cache.h"
#include "road_internal.h" /* For drawing catenary/checking road removal */
#include "clear_func.h"
#include "elrail_func.h"
#include "station_func.h"
@@ -22,12 +22,13 @@
#include "statusbar_gui.h"
#include "toolbar_gui.h"
#include "widgets/statusbar_widget.h"
@@ -20,13 +20,12 @@
#include "fontdetection.h"
#include "error.h"
#include "core/endian_func.hpp"
#include "engine_base.h"
#include "language.h"
#include "townname_func.h"
@@ -425,34 +424,34 @@ static char *FormatBytes(char *buff, int
return buff;
static char *FormatYmdString(char *buff, TimerGameCalendar::Date date, const char *last, uint case_index)
ConvertDateToYMD(date, &ymd);
TimerGameCalendar::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, TimerGameCalendar::Date date, const char *last, uint case_index)
int64 args[] = {STR_MONTH_JAN + ymd.month, ymd.year};
return FormatString(buff, GetStringPtr(STR_FORMAT_DATE_SHORT), &tmp_params, last, case_index);
static char *FormatTinyOrISODate(char *buff, TimerGameCalendar::Date date, StringID str, const char *last)
/* Day and month are zero-padded with ZEROFILL_NUM, hence the two 2s. */
int64 args[] = {ymd.day, 2, ymd.month + 1, 2, ymd.year};
return FormatString(buff, GetStringPtr(str), &tmp_params, last);
#include "town.h"
#include "subsidy_func.h"
#include "subsidy_base.h"
@@ -140,14 +139,14 @@ struct SubsidyListWindow : Window {
void DrawWidget(const Rect &r, int widget) const override
if (widget != WID_SUL_PANEL) return;
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
int pos = -this->vscroll->GetPosition();
const int cap = this->vscroll->GetCapacity();
@@ -8,13 +8,12 @@
* @file timer_game_calendar.cpp
* This file implements the timer logic for the game-calendar-timer.
#include "openttd.h"
#include "timer.h"
#include "timer_game_calendar.h"
#include "linkgraph/linkgraph.h"
@@ -22,12 +21,132 @@
TimerGameCalendar::Year TimerGameCalendar::year = {};
TimerGameCalendar::Month TimerGameCalendar::month = {};
TimerGameCalendar::Date TimerGameCalendar::date = {};
TimerGameCalendar::DateFract TimerGameCalendar::date_fract = {};
#define M(a, b) ((a << 5) | b)
static const uint16 _month_date_from_year_day[] = {
M(0, 1), M(0, 2), M(0, 3), M(0, 4), M(0, 5), M(0, 6), M(0, 7), M(0, 8), M(0, 9), M(0, 10), M(0, 11), M(0, 12), M(0, 13), M(0, 14), M(0, 15), M(0, 16), M(0, 17), M(0, 18), M(0, 19), M(0, 20), M(0, 21), M(0, 22), M(0, 23), M(0, 24), M(0, 25), M(0, 26), M(0, 27), M(0, 28), M(0, 29), M(0, 30), M(0, 31),
M(1, 1), M(1, 2), M(1, 3), M(1, 4), M(1, 5), M(1, 6), M(1, 7), M(1, 8), M(1, 9), M(1, 10), M(1, 11), M(1, 12), M(1, 13), M(1, 14), M(1, 15), M(1, 16), M(1, 17), M(1, 18), M(1, 19), M(1, 20), M(1, 21), M(1, 22), M(1, 23), M(1, 24), M(1, 25), M(1, 26), M(1, 27), M(1, 28), M(1, 29),
M(2, 1), M(2, 2), M(2, 3), M(2, 4), M(2, 5), M(2, 6), M(2, 7), M(2, 8), M(2, 9), M(2, 10), M(2, 11), M(2, 12), M(2, 13), M(2, 14), M(2, 15), M(2, 16), M(2, 17), M(2, 18), M(2, 19), M(2, 20), M(2, 21), M(2, 22), M(2, 23), M(2, 24), M(2, 25), M(2, 26), M(2, 27), M(2, 28), M(2, 29), M(2, 30), M(2, 31),
M(3, 1), M(3, 2), M(3, 3), M(3, 4), M(3, 5), M(3, 6), M(3, 7), M(3, 8), M(3, 9), M(3, 10), M(3, 11), M(3, 12), M(3, 13), M(3, 14), M(3, 15), M(3, 16), M(3, 17), M(3, 18), M(3, 19), M(3, 20), M(3, 21), M(3, 22), M(3, 23), M(3, 24), M(3, 25), M(3, 26), M(3, 27), M(3, 28), M(3, 29), M(3, 30),
M(4, 1), M(4, 2), M(4, 3), M(4, 4), M(4, 5), M(4, 6), M(4, 7), M(4, 8), M(4, 9), M(4, 10), M(4, 11), M(4, 12), M(4, 13), M(4, 14), M(4, 15), M(4, 16), M(4, 17), M(4, 18), M(4, 19), M(4, 20), M(4, 21), M(4, 22), M(4, 23), M(4, 24), M(4, 25), M(4, 26), M(4, 27), M(4, 28), M(4, 29), M(4, 30), M(4, 31),
M(5, 1), M(5, 2), M(5, 3), M(5, 4), M(5, 5), M(5, 6), M(5, 7), M(5, 8), M(5, 9), M(5, 10), M(5, 11), M(5, 12), M(5, 13), M(5, 14), M(5, 15), M(5, 16), M(5, 17), M(5, 18), M(5, 19), M(5, 20), M(5, 21), M(5, 22), M(5, 23), M(5, 24), M(5, 25), M(5, 26), M(5, 27), M(5, 28), M(5, 29), M(5, 30),
M(6, 1), M(6, 2), M(6, 3), M(6, 4), M(6, 5), M(6, 6), M(6, 7), M(6, 8), M(6, 9), M(6, 10), M(6, 11), M(6, 12), M(6, 13), M(6, 14), M(6, 15), M(6, 16), M(6, 17), M(6, 18), M(6, 19), M(6, 20), M(6, 21), M(6, 22), M(6, 23), M(6, 24), M(6, 25), M(6, 26), M(6, 27), M(6, 28), M(6, 29), M(6, 30), M(6, 31),
M(7, 1), M(7, 2), M(7, 3), M(7, 4), M(7, 5), M(7, 6), M(7, 7), M(7, 8), M(7, 9), M(7, 10), M(7, 11), M(7, 12), M(7, 13), M(7, 14), M(7, 15), M(7, 16), M(7, 17), M(7, 18), M(7, 19), M(7, 20), M(7, 21), M(7, 22), M(7, 23), M(7, 24), M(7, 25), M(7, 26), M(7, 27), M(7, 28), M(7, 29), M(7, 30), M(7, 31),
M(8, 1), M(8, 2), M(8, 3), M(8, 4), M(8, 5), M(8, 6), M(8, 7), M(8, 8), M(8, 9), M(8, 10), M(8, 11), M(8, 12), M(8, 13), M(8, 14), M(8, 15), M(8, 16), M(8, 17), M(8, 18), M(8, 19), M(8, 20), M(8, 21), M(8, 22), M(8, 23), M(8, 24), M(8, 25), M(8, 26), M(8, 27), M(8, 28), M(8, 29), M(8, 30),
M(9, 1), M(9, 2), M(9, 3), M(9, 4), M(9, 5), M(9, 6), M(9, 7), M(9, 8), M(9, 9), M(9, 10), M(9, 11), M(9, 12), M(9, 13), M(9, 14), M(9, 15), M(9, 16), M(9, 17), M(9, 18), M(9, 19), M(9, 20), M(9, 21), M(9, 22), M(9, 23), M(9, 24), M(9, 25), M(9, 26), M(9, 27), M(9, 28), M(9, 29), M(9, 30), M(9, 31),
M(10, 1), M(10, 2), M(10, 3), M(10, 4), M(10, 5), M(10, 6), M(10, 7), M(10, 8), M(10, 9), M(10, 10), M(10, 11), M(10, 12), M(10, 13), M(10, 14), M(10, 15), M(10, 16), M(10, 17), M(10, 18), M(10, 19), M(10, 20), M(10, 21), M(10, 22), M(10, 23), M(10, 24), M(10, 25), M(10, 26), M(10, 27), M(10, 28), M(10, 29), M(10, 30),
M(11, 1), M(11, 2), M(11, 3), M(11, 4), M(11, 5), M(11, 6), M(11, 7), M(11, 8), M(11, 9), M(11, 10), M(11, 11), M(11, 12), M(11, 13), M(11, 14), M(11, 15), M(11, 16), M(11, 17), M(11, 18), M(11, 19), M(11, 20), M(11, 21), M(11, 22), M(11, 23), M(11, 24), M(11, 25), M(11, 26), M(11, 27), M(11, 28), M(11, 29), M(11, 30), M(11, 31),
#undef M
enum DaysTillMonth {
ACCUM_JAN = 0,
ACCUM_FEB = ACCUM_JAN + 31,
ACCUM_MAR = ACCUM_FEB + 29,
ACCUM_APR = ACCUM_MAR + 31,
ACCUM_MAY = ACCUM_APR + 30,
ACCUM_JUN = ACCUM_MAY + 31,
ACCUM_JUL = ACCUM_JUN + 30,
ACCUM_AUG = ACCUM_JUL + 31,
ACCUM_SEP = ACCUM_AUG + 31,
ACCUM_OCT = ACCUM_SEP + 30,
ACCUM_NOV = ACCUM_OCT + 31,
ACCUM_DEC = ACCUM_NOV + 30,
/** Number of days to pass from the first day in the year before reaching the first of a month. */
static const uint16 _accum_days_for_month[] = {
ACCUM_JAN, ACCUM_FEB, ACCUM_MAR, ACCUM_APR,
ACCUM_MAY, ACCUM_JUN, ACCUM_JUL, ACCUM_AUG,
ACCUM_SEP, ACCUM_OCT, ACCUM_NOV, ACCUM_DEC,
* 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
/* static */ void TimerGameCalendar::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 */
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 */
yr += 100;
rem -= DAYS_IN_YEAR * 100 + 25;
/* There are 24 leap years in the next couple of 100 years */
yr += 100 * (rem / (DAYS_IN_YEAR * 100 + 24));
rem = (rem % (DAYS_IN_YEAR * 100 + 24));
if (!TimerGameCalendar::IsLeapYear(yr) && rem >= DAYS_IN_YEAR * 4) {
/* The first 4 year of the century are not always a leap year */
yr += 4;
rem -= DAYS_IN_YEAR * 4;
/* There is 1 leap year every 4 years */
yr += 4 * (rem / (DAYS_IN_YEAR * 4 + 1));
rem = rem % (DAYS_IN_YEAR * 4 + 1);
/* The last (max 3) years to account for; the first one
* can be, but is not necessarily a leap year */
while (rem >= (TimerGameCalendar::IsLeapYear(yr) ? DAYS_IN_LEAP_YEAR : DAYS_IN_YEAR)) {
rem -= TimerGameCalendar::IsLeapYear(yr) ? DAYS_IN_LEAP_YEAR : DAYS_IN_YEAR;
yr++;
/* Skip the 29th of February in non-leap years */
if (!TimerGameCalendar::IsLeapYear(yr) && rem >= ACCUM_MAR - 1) rem++;
ymd->year = yr;
x = _month_date_from_year_day[rem];
ymd->month = x >> 5;
ymd->day = x & 0x1F;
* 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
/* static */ TimerGameCalendar::Date TimerGameCalendar::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 (!TimerGameCalendar::IsLeapYear(year) && days >= ACCUM_MAR) days--;
return DAYS_TILL(year) + days;
* 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 */ bool TimerGameCalendar::IsLeapYear(TimerGameCalendar::Year yr)
return yr % 4 == 0 && (yr % 100 != 0 || yr % 400 == 0);
* Set the date.
* @param date New date
* @param fract The number of ticks that have passed on this date.
/* static */ void TimerGameCalendar::SetDate(TimerGameCalendar::Date date, TimerGameCalendar::DateFract fract)
@@ -35,13 +154,13 @@ TimerGameCalendar::DateFract TimerGameCa
assert(fract < DAY_TICKS);
TimerGameCalendar::date = date;
TimerGameCalendar::date_fract = fract;
TimerGameCalendar::year = ymd.year;
TimerGameCalendar::month = ymd.month;
template<>
void IntervalTimer<TimerGameCalendar>::Elapsed(TimerGameCalendar::TElapsed trigger)
@@ -73,14 +192,14 @@ void TimerManager<TimerGameCalendar>::El
if (TimerGameCalendar::date_fract < DAY_TICKS) return;
/* increase day counter */
TimerGameCalendar::date++;
/* check if we entered a new month? */
bool new_month = ymd.month != TimerGameCalendar::month;
/* check if we entered a new year? */
bool new_year = ymd.year != TimerGameCalendar::year;
@@ -110,13 +229,13 @@ void TimerManager<TimerGameCalendar>::El
/* check if we reached the maximum year, decrement dates by a year */
if (TimerGameCalendar::year == MAX_YEAR + 1) {
int days_this_year;
TimerGameCalendar::year--;
days_this_year = IsLeapYear(TimerGameCalendar::year) ? DAYS_IN_LEAP_YEAR : DAYS_IN_YEAR;
days_this_year = TimerGameCalendar::IsLeapYear(TimerGameCalendar::year) ? DAYS_IN_LEAP_YEAR : DAYS_IN_YEAR;
TimerGameCalendar::date -= days_this_year;
for (Vehicle *v : Vehicle::Iterate()) v->ShiftDates(-days_this_year);
for (LinkGraph *lg : LinkGraph::Iterate()) lg->ShiftDates(-days_this_year);
@@ -78,12 +78,25 @@ public:
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.
* @see TimerGameCalendar::ConvertDateToYMD(), TimerGameCalendar::ConvertYMDToDate()
Year year; ///< Year (0...)
Month month; ///< Month (0..11)
Day day; ///< Day (1..31)
static bool IsLeapYear(TimerGameCalendar::Year yr);
static void ConvertDateToYMD(TimerGameCalendar::Date date, YearMonthDay *ymd);
static TimerGameCalendar::Date ConvertYMDToDate(TimerGameCalendar::Year year, TimerGameCalendar::Month month, TimerGameCalendar::Day day);
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.
@@ -14,14 +14,12 @@
#include "rail_gui.h"
#include "road.h"
#include "road_gui.h"
#include "terraform_gui.h"
@@ -53,12 +51,13 @@
#include "screenshot_gui.h"
#include "league_gui.h"
#include "league_base.h"
#include "widgets/toolbar_widget.h"
#include "network/network_gui.h"
#include "network/network_func.h"
@@ -1145,13 +1144,13 @@ void ToggleDirtyBlocks()
* Set the starting year for a scenario.
* @param year New starting year.
void SetStartingYear(TimerGameCalendar::Year year)
_settings_game.game_creation.starting_year = Clamp(year, MIN_YEAR, MAX_YEAR);
TimerGameCalendar::Date new_date = ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1);
TimerGameCalendar::Date new_date = TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1);
/* If you open a savegame as scenario there may already be link graphs.*/
TimerGameCalendar::SetDate(new_date, 0);
@@ -2374,13 +2373,13 @@ struct ScenarioEditorToolbarWindow : Win
case WID_TE_DATE:
SetDParam(0, ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1));
SetDParam(0, TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1));
@@ -2403,13 +2402,13 @@ struct ScenarioEditorToolbarWindow : Win
case WID_TE_SPACER:
size->width = std::max(GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_OPENTTD).width, GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR).width) + padding.width;
*size = GetStringBoundingBox(STR_WHITE_DATE_LONG);
void OnClick(Point pt, int widget, int click_count) override
@@ -22,13 +22,12 @@
#include "newgrf_sound.h"
#include "newgrf_station.h"
#include "depot_func.h"
Status change: