@@ -115,8 +115,6 @@ add_files(
crashlog.h
currency.cpp
currency.h
date.cpp
date_func.h
date_gui.cpp
date_gui.h
date_type.h
@@ -23,7 +23,7 @@
#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"
@@ -920,8 +920,8 @@ void TestedEngineDetails::FillDefaultCap
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;
@@ -12,7 +12,6 @@
#include "cheat_type.h"
#include "company_base.h"
#include "company_func.h"
#include "saveload/saveload.h"
#include "vehicle_base.h"
#include "textbuf_gui.h"
@@ -108,9 +107,9 @@ static int32 ClickChangeDateCheat(int32
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);
@@ -323,7 +322,7 @@ struct CheatWindow : Window {
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);
break;
@@ -29,7 +29,6 @@
#include "viewport_func.h"
#include "gamelog.h"
@@ -1449,8 +1448,8 @@ DEF_CONSOLE_CMD(ConGetDate)
return true;
}
IConsolePrint(CC_DEFAULT, "Date: {:04d}-{:02d}-{:02d}", ymd.year, ymd.month + 1, ymd.day);
@@ -10,7 +10,6 @@
#include "stdafx.h"
#include "crashlog.h"
#include "map_func.h"
#include "rev.h"
@@ -319,8 +318,8 @@ char *CrashLog::LogRecentNews(char *buff
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);
@@ -359,8 +358,8 @@ char *CrashLog::FillCrashLog(char *buffe
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());
deleted file
@@ -9,11 +9,11 @@
#include "window_gui.h"
#include "date_gui.h"
#include "date_type.h"
#include "core/geometry_func.hpp"
#include "widgets/dropdown_type.h"
@@ -26,7 +26,7 @@
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
@@ -52,7 +52,7 @@ struct SetDateWindow : Window {
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);
@@ -149,7 +149,7 @@ struct SetDateWindow : Window {
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();
@@ -74,7 +74,7 @@ static const TimerGameCalendar::Year ORI
/**
* 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)
@@ -95,16 +95,6 @@ static const TimerGameCalendar::Year MAX
/** 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
@@ -17,7 +17,6 @@
#include "core/random_func.hpp"
#include "autoreplace_gui.h"
#include "ai/ai.hpp"
@@ -663,8 +662,8 @@ void SetYearEngineAgingStops()
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);
@@ -698,7 +697,7 @@ void StartupOneEngine(Engine *e, TimerGa
/* 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);
@@ -745,7 +744,7 @@ void StartupOneEngine(Engine *e, TimerGa
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()) {
#include "querystring_gui.h"
#include "engine_func.h"
#include "landscape_type.h"
#include "stringfilter_type.h"
@@ -520,7 +520,7 @@ public:
/* 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;
@@ -14,7 +14,7 @@
#include "gamelog_internal.h"
#include "console_func.h"
#include "debug.h"
#include "timer/timer_game_tick.h"
#include "network/network.h"
#include "sound_func.h"
#include "fios.h"
@@ -437,7 +437,7 @@ 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;
@@ -600,7 +600,7 @@ struct GenerateLandscapeWindow : public
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);
@@ -1107,7 +1107,7 @@ 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:
@@ -1144,7 +1144,7 @@ struct CreateScenarioWindow : public Win
StringID str = STR_JUST_INT;
str = STR_BLACK_DATE_LONG;
@@ -17,12 +17,12 @@
#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"
@@ -27,7 +27,6 @@
#include "water.h"
#include "animated_tile_func.h"
@@ -21,7 +21,6 @@
#include "genworld.h"
#include "error_func.h"
@@ -613,8 +612,8 @@ byte GetSnowLine()
if (_snow_line == nullptr) return _settings_game.game_creation.snow_line_height;
return _snow_line->table[ymd.month][ymd.day];
@@ -12,7 +12,7 @@
#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"
@@ -15,7 +15,7 @@
#include "newgrf.h"
#include "newgrf_house.h"
#include "economy_func.h"
#include "texteff.hpp"
@@ -74,7 +74,7 @@ void InitializeGame(uint size_x, uint si
_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();
@@ -13,7 +13,6 @@
#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"
@@ -124,7 +123,7 @@ void CheckGameCompatibility(NetworkGameI
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();
@@ -256,7 +255,7 @@ void SerializeNetworkGameInfo(Packet *p,
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;
@@ -10,7 +10,7 @@
#include "../../stdafx.h"
#include "tcp_coordinator.h"
#include "tcp_turn.h"
#include "udp.h"
@@ -9,7 +9,7 @@
#include "../stdafx.h"
#include "../strings_func.h"
#include "core/game_info.h"
#include "network_admin.h"
@@ -178,7 +178,7 @@ NetworkRecvStatus ServerNetworkAdminSock
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());
@@ -9,7 +9,6 @@
#include "../fios.h"
#include "network_client.h"
#include "network_gui.h"
@@ -38,6 +37,7 @@
#include "../company_cmd.h"
#include "../timer/timer.h"
#include "../timer/timer_window.h"
#include "../widgets/network_widget.h"
@@ -432,8 +432,8 @@ protected:
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);
@@ -441,9 +441,9 @@ protected:
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);
@@ -13,7 +13,7 @@
#include "../map_func.h"
#include "../debug.h"
@@ -37,7 +37,6 @@
@@ -6513,10 +6512,10 @@ bool GetGlobalVariable(byte param, uint3
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;
@@ -9947,7 +9946,7 @@ void LoadNewGRF(uint load_index, uint nu
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;
@@ -12,8 +12,6 @@
#include "vehicle_gui.h"
@@ -38,6 +36,7 @@
#include "news_cmd.h"
#include "widgets/news_widget.h"
@@ -1155,7 +1154,7 @@ struct MessageHistoryWindow : Window {
/* 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.
#ifndef YAPF_COSTCACHE_HPP
#define YAPF_COSTCACHE_HPP
* CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements
@@ -22,7 +22,6 @@
#include "../clear_map.h"
#include "../vehicle_func.h"
#include "../string_func.h"
#include "../roadveh.h"
#include "../roadveh_cmd.h"
#include "../train.h"
@@ -59,6 +58,7 @@
#include "../ship.h"
#include "../water.h"
#include "../timer/timer_game_tick.h"
#include "saveload_internal.h"
#include "saveload.h"
#include "compat/misc_sl_compat.h"
#include "../window_gui.h"
@@ -21,6 +20,7 @@
#include "../gfx_func.h"
#include "../core/random_func.hpp"
#include "../date_type.h"
@@ -20,7 +20,7 @@
#include "../subsidy_base.h"
#include "../depot_base.h"
#include "../effectvehicle_base.h"
@@ -400,7 +400,7 @@ static bool FixTTOEngines()
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];
@@ -847,8 +847,8 @@ static bool LoadOldIndustry(LoadgameStat
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);
@@ -31,7 +31,7 @@
#include "../core/endian_func.hpp"
#include "../vehicle_base.h"
#include "../company_func.h"
#include "../autoreplace_base.h"
#include "../roadstop_base.h"
#include "../linkgraph/linkgraph.h"
#include "script_date.hpp"
#include <time.h>
@@ -30,8 +29,8 @@
if (date < 0) return DATE_INVALID;
::YearMonthDay ymd;
::ConvertDateToYMD(date, &ymd);
::TimerGameCalendar::YearMonthDay ymd;
::TimerGameCalendar::ConvertDateToYMD(date, &ymd);
return ymd.year;
@@ -39,8 +38,8 @@
return ymd.month + 1;
@@ -48,8 +47,8 @@
return ymd.day;
@@ -59,7 +58,7 @@
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()
@@ -45,6 +45,7 @@
#include "fileio_func.h"
#include "settings_cmd.h"
#include "table/strings.h"
#ifndef SETTINGS_TYPE_H
#define SETTINGS_TYPE_H
#include "economy_type.h"
#include "town_type.h"
@@ -29,7 +29,7 @@
#include "clear_func.h"
@@ -25,6 +25,7 @@
#include "toolbar_gui.h"
@@ -23,7 +23,6 @@
#include "core/endian_func.hpp"
#include "engine_base.h"
@@ -428,8 +427,8 @@ static char *FormatBytes(char *buff, int
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);
@@ -438,8 +437,8 @@ static char *FormatYmdString(char *buff,
static char *FormatMonthAndYear(char *buff, TimerGameCalendar::Date date, const char *last, uint case_index)
int64 args[] = {STR_MONTH_JAN + ymd.month, ymd.year};
@@ -448,8 +447,8 @@ static char *FormatMonthAndYear(char *bu
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};
#include "town.h"
#include "gui.h"
@@ -143,8 +142,8 @@ struct SubsidyListWindow : Window {
if (widget != WID_SUL_PANEL) return;
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
@@ -11,7 +11,6 @@
#include "openttd.h"
#include "timer.h"
#include "timer_game_calendar.h"
@@ -25,6 +24,126 @@ TimerGameCalendar::Month TimerGameCalend
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
@@ -38,7 +157,7 @@ TimerGameCalendar::DateFract TimerGameCa
TimerGameCalendar::date = date;
TimerGameCalendar::date_fract = fract;
TimerGameCalendar::year = ymd.year;
TimerGameCalendar::month = ymd.month;
@@ -76,8 +195,8 @@ void TimerManager<TimerGameCalendar>::El
/* increase day counter */
TimerGameCalendar::date++;
/* check if we entered a new month? */
bool new_month = ymd.month != TimerGameCalendar::month;
@@ -113,7 +232,7 @@ void TimerManager<TimerGameCalendar>::El
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);
@@ -81,6 +81,19 @@ public:
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.
@@ -17,8 +17,6 @@
#include "rail_gui.h"
#include "road.h"
#include "road_gui.h"
#include "terraform_gui.h"
@@ -56,6 +54,7 @@
#include "league_base.h"
#include "widgets/toolbar_widget.h"
@@ -1148,7 +1147,7 @@ void ToggleDirtyBlocks()
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.*/
LinkGraphSchedule::instance.ShiftDates(new_date - TimerGameCalendar::date);
TimerGameCalendar::SetDate(new_date, 0);
@@ -2377,7 +2376,7 @@ 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));
@@ -2406,7 +2405,7 @@ struct ScenarioEditorToolbarWindow : Win
*size = GetStringBoundingBox(STR_WHITE_DATE_LONG);
@@ -25,7 +25,6 @@
#include "group_gui.h"
#include "autoreplace_func.h"
Status change: