diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -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
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -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;
diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp
--- a/src/cheat_gui.cpp
+++ b/src/cheat_gui.cpp
@@ -12,7 +12,6 @@
#include "cheat_type.h"
#include "company_base.h"
#include "company_func.h"
-#include "date_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;
- YearMonthDay ymd;
- ConvertDateToYMD(TimerGameCalendar::date, &ymd);
- TimerGameCalendar::Date new_date = ConvertYMDToDate(new_value, ymd.month, ymd.day);
+ TimerGameCalendar::YearMonthDay ymd;
+ 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;
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -29,7 +29,6 @@
#include "strings_func.h"
#include "viewport_func.h"
#include "window_func.h"
-#include "date_func.h"
#include "timer/timer_game_calendar.h"
#include "company_func.h"
#include "gamelog.h"
@@ -1449,8 +1448,8 @@ DEF_CONSOLE_CMD(ConGetDate)
return true;
}
- YearMonthDay ymd;
- ConvertDateToYMD(TimerGameCalendar::date, &ymd);
+ TimerGameCalendar::YearMonthDay ymd;
+ TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date, &ymd);
IConsolePrint(CC_DEFAULT, "Date: {:04d}-{:02d}-{:02d}", ymd.year, ymd.month + 1, ymd.day);
return true;
}
diff --git a/src/crashlog.cpp b/src/crashlog.cpp
--- a/src/crashlog.cpp
+++ b/src/crashlog.cpp
@@ -10,7 +10,6 @@
#include "stdafx.h"
#include "crashlog.h"
#include "gamelog.h"
-#include "date_func.h"
#include "timer/timer_game_calendar.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++) {
- YearMonthDay ymd;
- ConvertDateToYMD(news->date, &ymd);
+ TimerGameCalendar::YearMonthDay 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");
- YearMonthDay ymd;
- ConvertDateToYMD(TimerGameCalendar::date, &ymd);
+ TimerGameCalendar::YearMonthDay ymd;
+ TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date, &ymd);
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());
diff --git a/src/date.cpp b/src/date.cpp
deleted file mode 100644
--- a/src/date.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * This file is part of OpenTTD.
- * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
- * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see .
- */
-
-/** @file date.cpp Handling of dates in our native format and transforming them to something human readable. */
-
-#include "stdafx.h"
-#include "network/network.h"
-#include "network/network_func.h"
-#include "currency.h"
-#include "window_func.h"
-#include "settings_type.h"
-#include "date_func.h"
-#include "vehicle_base.h"
-#include "rail_gui.h"
-#include "linkgraph/linkgraph.h"
-#include "saveload/saveload.h"
-#include "newgrf_profiling.h"
-#include "widgets/statusbar_widget.h"
-#include "timer/timer.h"
-#include "timer/timer_game_calendar.h"
-
-#include "safeguards.h"
-
-#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
- */
-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 */
- 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 (!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 >= (IsLeapYear(yr) ? DAYS_IN_LEAP_YEAR : DAYS_IN_YEAR)) {
- rem -= IsLeapYear(yr) ? DAYS_IN_LEAP_YEAR : DAYS_IN_YEAR;
- yr++;
- }
-
- /* Skip the 29th of February in non-leap years */
- if (!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
- */
-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--;
-
- return DAYS_TILL(year) + days;
-}
diff --git a/src/date_func.h b/src/date_func.h
deleted file mode 100644
--- a/src/date_func.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * This file is part of OpenTTD.
- * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
- * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see .
- */
-
-/** @file date_func.h Functions related to dates. */
-
-#ifndef DATE_FUNC_H
-#define DATE_FUNC_H
-
-#include "date_type.h"
-
-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(TimerGameCalendar::Year yr)
-{
- return yr % 4 == 0 && (yr % 100 != 0 || yr % 400 == 0);
-}
-
-#endif /* DATE_FUNC_H */
diff --git a/src/date_gui.cpp b/src/date_gui.cpp
--- a/src/date_gui.cpp
+++ b/src/date_gui.cpp
@@ -9,11 +9,11 @@
#include "stdafx.h"
#include "strings_func.h"
-#include "date_func.h"
#include "timer/timer_game_calendar.h"
#include "window_func.h"
#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 {
break;
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();
break;
}
diff --git a/src/date_type.h b/src/date_type.h
--- a/src/date_type.h
+++ b/src/date_type.h
@@ -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
diff --git a/src/engine.cpp b/src/engine.cpp
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -17,7 +17,6 @@
#include "strings_func.h"
#include "core/random_func.hpp"
#include "window_func.h"
-#include "date_func.h"
#include "autoreplace_gui.h"
#include "string_func.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 */
- YearMonthDay ymd;
- ConvertDateToYMD(ei->base_intro + (ei->lifelength * DAYS_IN_LEAP_YEAR) / 2, &ymd);
+ TimerGameCalendar::YearMonthDay 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()) {
diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp
--- a/src/fios_gui.cpp
+++ b/src/fios_gui.cpp
@@ -23,7 +23,7 @@
#include "querystring_gui.h"
#include "engine_func.h"
#include "landscape_type.h"
-#include "date_func.h"
+#include "timer/timer_game_calendar.h"
#include "core/geometry_func.hpp"
#include "gamelog.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;
}
diff --git a/src/gamelog.cpp b/src/gamelog.cpp
--- a/src/gamelog.cpp
+++ b/src/gamelog.cpp
@@ -14,7 +14,7 @@
#include "gamelog_internal.h"
#include "console_func.h"
#include "debug.h"
-#include "date_func.h"
+#include "timer/timer_game_calendar.h"
#include "timer/timer_game_tick.h"
#include "rev.h"
diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp
--- a/src/genworld_gui.cpp
+++ b/src/genworld_gui.cpp
@@ -14,7 +14,7 @@
#include "network/network.h"
#include "strings_func.h"
#include "window_func.h"
-#include "date_func.h"
+#include "timer/timer_game_calendar.h"
#include "sound_func.h"
#include "fios.h"
#include "string_func.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
break;
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);
break;
@@ -1107,7 +1107,7 @@ struct CreateScenarioWindow : public Win
{
switch (widget) {
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));
break;
case WID_CS_MAPSIZE_X_PULLDOWN:
@@ -1144,7 +1144,7 @@ struct CreateScenarioWindow : public Win
StringID str = STR_JUST_INT;
switch (widget) {
case WID_CS_START_DATE_TEXT:
- SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
+ SetDParam(0, TimerGameCalendar::ConvertYMDToDate(MAX_YEAR, 0, 1));
str = STR_BLACK_DATE_LONG;
break;
diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp
--- a/src/graph_gui.cpp
+++ b/src/graph_gui.cpp
@@ -17,12 +17,12 @@
#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"
+#include "timer/timer_game_calendar.h"
#include "zoom_func.h"
#include "widgets/graph_widget.h"
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -27,7 +27,6 @@
#include "water.h"
#include "strings_func.h"
#include "window_func.h"
-#include "date_func.h"
#include "vehicle_func.h"
#include "sound_func.h"
#include "animated_tile_func.h"
diff --git a/src/landscape.cpp b/src/landscape.cpp
--- a/src/landscape.cpp
+++ b/src/landscape.cpp
@@ -21,7 +21,6 @@
#include "genworld.h"
#include "fios.h"
#include "error_func.h"
-#include "date_func.h"
#include "timer/timer_game_calendar.h"
#include "timer/timer_game_tick.h"
#include "water.h"
@@ -613,8 +612,8 @@ byte GetSnowLine()
{
if (_snow_line == nullptr) return _settings_game.game_creation.snow_line_height;
- YearMonthDay ymd;
- ConvertDateToYMD(TimerGameCalendar::date, &ymd);
+ TimerGameCalendar::YearMonthDay ymd;
+ TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date, &ymd);
return _snow_line->table[ymd.month][ymd.day];
}
diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp
--- a/src/linkgraph/linkgraph_gui.cpp
+++ b/src/linkgraph/linkgraph_gui.cpp
@@ -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"
diff --git a/src/misc.cpp b/src/misc.cpp
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -15,7 +15,7 @@
#include "newgrf.h"
#include "newgrf_house.h"
#include "economy_func.h"
-#include "date_func.h"
+#include "timer/timer_game_calendar.h"
#include "timer/timer_game_tick.h"
#include "texteff.hpp"
#include "gfx_func.h"
@@ -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();
}
diff --git a/src/network/core/game_info.cpp b/src/network/core/game_info.cpp
--- a/src/network/core/game_info.cpp
+++ b/src/network/core/game_info.cpp
@@ -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;
diff --git a/src/network/core/tcp_coordinator.cpp b/src/network/core/tcp_coordinator.cpp
--- a/src/network/core/tcp_coordinator.cpp
+++ b/src/network/core/tcp_coordinator.cpp
@@ -10,7 +10,7 @@
*/
#include "../../stdafx.h"
-#include "../../date_func.h"
+#include "../../timer/timer_game_calendar.h"
#include "../../debug.h"
#include "tcp_coordinator.h"
diff --git a/src/network/core/tcp_turn.cpp b/src/network/core/tcp_turn.cpp
--- a/src/network/core/tcp_turn.cpp
+++ b/src/network/core/tcp_turn.cpp
@@ -10,7 +10,7 @@
*/
#include "../../stdafx.h"
-#include "../../date_func.h"
+#include "../../timer/timer_game_calendar.h"
#include "../../debug.h"
#include "tcp_turn.h"
diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp
--- a/src/network/core/udp.cpp
+++ b/src/network/core/udp.cpp
@@ -10,7 +10,7 @@
*/
#include "../../stdafx.h"
-#include "../../date_func.h"
+#include "../../timer/timer_game_calendar.h"
#include "../../debug.h"
#include "game_info.h"
#include "udp.h"
diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp
--- a/src/network/network_admin.cpp
+++ b/src/network/network_admin.cpp
@@ -9,7 +9,7 @@
#include "../stdafx.h"
#include "../strings_func.h"
-#include "../date_func.h"
+#include "../timer/timer_game_calendar.h"
#include "../timer/timer_game_calendar.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());
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -9,7 +9,6 @@
#include "../stdafx.h"
#include "../strings_func.h"
-#include "../date_func.h"
#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 "../timer/timer_game_calendar.h"
#include "../widgets/network_widget.h"
@@ -432,8 +432,8 @@ protected:
if (nwi_header->IsWidgetVisible(WID_NG_DATE)) {
/* current date */
Rect date = this->GetWidget(WID_NG_DATE)->GetCurrentRect();
- YearMonthDay ymd;
- ConvertDateToYMD(cur_item->info.game_date, &ymd);
+ TimerGameCalendar::YearMonthDay 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(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);
}
diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp
--- a/src/network/network_udp.cpp
+++ b/src/network/network_udp.cpp
@@ -13,7 +13,7 @@
*/
#include "../stdafx.h"
-#include "../date_func.h"
+#include "../timer/timer_game_calendar.h"
#include "../map_func.h"
#include "../debug.h"
#include "core/game_info.h"
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -37,7 +37,6 @@
#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"
@@ -6513,10 +6512,10 @@ bool GetGlobalVariable(byte param, uint3
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);
- 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::YearMonthDay ymd;
+ TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date, &ymd);
+ 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;
return true;
}
@@ -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;
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -12,8 +12,6 @@
#include "viewport_func.h"
#include "strings_func.h"
#include "window_func.h"
-#include "date_func.h"
-#include "timer/timer_game_calendar.h"
#include "vehicle_base.h"
#include "vehicle_func.h"
#include "vehicle_gui.h"
@@ -38,6 +36,7 @@
#include "news_cmd.h"
#include "timer/timer.h"
#include "timer/timer_window.h"
+#include "timer/timer_game_calendar.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.
diff --git a/src/pathfinder/yapf/yapf_costcache.hpp b/src/pathfinder/yapf/yapf_costcache.hpp
--- a/src/pathfinder/yapf/yapf_costcache.hpp
+++ b/src/pathfinder/yapf/yapf_costcache.hpp
@@ -10,7 +10,7 @@
#ifndef YAPF_COSTCACHE_HPP
#define YAPF_COSTCACHE_HPP
-#include "../../date_func.h"
+#include "../../timer/timer_game_calendar.h"
/**
* CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -22,7 +22,6 @@
#include "../clear_map.h"
#include "../vehicle_func.h"
#include "../string_func.h"
-#include "../date_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.h"
+#include "../timer/timer_game_calendar.h"
#include "../timer/timer_game_tick.h"
#include "saveload_internal.h"
diff --git a/src/saveload/misc_sl.cpp b/src/saveload/misc_sl.cpp
--- a/src/saveload/misc_sl.cpp
+++ b/src/saveload/misc_sl.cpp
@@ -12,7 +12,6 @@
#include "saveload.h"
#include "compat/misc_sl_compat.h"
-#include "../date_func.h"
#include "../timer/timer_game_calendar.h"
#include "../zoom_func.h"
#include "../window_gui.h"
@@ -21,6 +20,7 @@
#include "../gfx_func.h"
#include "../core/random_func.hpp"
#include "../fios.h"
+#include "../date_type.h"
#include "../timer/timer.h"
#include "../timer/timer_game_tick.h"
diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp
--- a/src/saveload/oldloader_sl.cpp
+++ b/src/saveload/oldloader_sl.cpp
@@ -20,7 +20,7 @@
#include "../subsidy_base.h"
#include "../debug.h"
#include "../depot_base.h"
-#include "../date_func.h"
+#include "../timer/timer_game_calendar.h"
#include "../timer/timer_game_calendar.h"
#include "../vehicle_func.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
- YearMonthDay ymd;
- ConvertDateToYMD(TimerGameCalendar::date, &ymd);
+ TimerGameCalendar::YearMonthDay ymd;
+ TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date, &ymd);
i->last_prod_year = ymd.year;
i->random_colour = RemapTTOColour(i->random_colour);
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -31,7 +31,7 @@
#include "../core/endian_func.hpp"
#include "../vehicle_base.h"
#include "../company_func.h"
-#include "../date_func.h"
+#include "../timer/timer_game_calendar.h"
#include "../autoreplace_base.h"
#include "../roadstop_base.h"
#include "../linkgraph/linkgraph.h"
diff --git a/src/script/api/script_date.cpp b/src/script/api/script_date.cpp
--- a/src/script/api/script_date.cpp
+++ b/src/script/api/script_date.cpp
@@ -9,7 +9,6 @@
#include "../../stdafx.h"
#include "script_date.hpp"
-#include "../../date_func.h"
#include "../../timer/timer_game_calendar.h"
#include
@@ -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 @@
{
if (date < 0) return DATE_INVALID;
- ::YearMonthDay ymd;
- ::ConvertDateToYMD(date, &ymd);
+ ::TimerGameCalendar::YearMonthDay ymd;
+ ::TimerGameCalendar::ConvertDateToYMD(date, &ymd);
return ymd.month + 1;
}
@@ -48,8 +47,8 @@
{
if (date < 0) return DATE_INVALID;
- ::YearMonthDay ymd;
- ::ConvertDateToYMD(date, &ymd);
+ ::TimerGameCalendar::YearMonthDay ymd;
+ ::TimerGameCalendar::ConvertDateToYMD(date, &ymd);
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()
diff --git a/src/settings.cpp b/src/settings.cpp
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -45,6 +45,7 @@
#include "fios.h"
#include "fileio_func.h"
#include "settings_cmd.h"
+#include "date_type.h"
#include "table/strings.h"
diff --git a/src/settings_type.h b/src/settings_type.h
--- a/src/settings_type.h
+++ b/src/settings_type.h
@@ -10,7 +10,6 @@
#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"
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -29,7 +29,7 @@
#include "water.h"
#include "strings_func.h"
#include "clear_func.h"
-#include "date_func.h"
+#include "timer/timer_game_calendar.h"
#include "vehicle_func.h"
#include "string_func.h"
#include "animated_tile_func.h"
diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp
--- a/src/statusbar_gui.cpp
+++ b/src/statusbar_gui.cpp
@@ -25,6 +25,7 @@
#include "toolbar_gui.h"
#include "core/geometry_func.hpp"
#include "zoom_func.h"
+#include "date_type.h"
#include "timer/timer.h"
#include "timer/timer_game_calendar.h"
#include "timer/timer_window.h"
diff --git a/src/strings.cpp b/src/strings.cpp
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -23,7 +23,6 @@
#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"
@@ -428,8 +427,8 @@ static char *FormatBytes(char *buff, int
static char *FormatYmdString(char *buff, TimerGameCalendar::Date date, const char *last, uint case_index)
{
- YearMonthDay ymd;
- ConvertDateToYMD(date, &ymd);
+ TimerGameCalendar::YearMonthDay 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)
{
- YearMonthDay ymd;
- ConvertDateToYMD(date, &ymd);
+ TimerGameCalendar::YearMonthDay ymd;
+ TimerGameCalendar::ConvertDateToYMD(date, &ymd);
int64 args[] = {STR_MONTH_JAN + ymd.month, ymd.year};
StringParameters tmp_params(args);
@@ -448,8 +447,8 @@ static char *FormatMonthAndYear(char *bu
static char *FormatTinyOrISODate(char *buff, TimerGameCalendar::Date date, StringID str, const char *last)
{
- YearMonthDay ymd;
- ConvertDateToYMD(date, &ymd);
+ TimerGameCalendar::YearMonthDay ymd;
+ TimerGameCalendar::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};
diff --git a/src/subsidy_gui.cpp b/src/subsidy_gui.cpp
--- a/src/subsidy_gui.cpp
+++ b/src/subsidy_gui.cpp
@@ -12,7 +12,6 @@
#include "town.h"
#include "window_gui.h"
#include "strings_func.h"
-#include "date_func.h"
#include "timer/timer_game_calendar.h"
#include "viewport_func.h"
#include "gui.h"
@@ -143,8 +142,8 @@ struct SubsidyListWindow : Window {
{
if (widget != WID_SUL_PANEL) return;
- YearMonthDay ymd;
- ConvertDateToYMD(TimerGameCalendar::date, &ymd);
+ TimerGameCalendar::YearMonthDay ymd;
+ TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date, &ymd);
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
diff --git a/src/timer/timer_game_calendar.cpp b/src/timer/timer_game_calendar.cpp
--- a/src/timer/timer_game_calendar.cpp
+++ b/src/timer/timer_game_calendar.cpp
@@ -11,7 +11,6 @@
*/
#include "stdafx.h"
-#include "date_func.h"
#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;
- ConvertDateToYMD(date, &ymd);
+ TimerGameCalendar::ConvertDateToYMD(date, &ymd);
TimerGameCalendar::year = ymd.year;
TimerGameCalendar::month = ymd.month;
}
@@ -76,8 +195,8 @@ void TimerManager::El
/* increase day counter */
TimerGameCalendar::date++;
- YearMonthDay ymd;
- ConvertDateToYMD(TimerGameCalendar::date, &ymd);
+ TimerGameCalendar::YearMonthDay ymd;
+ TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date, &ymd);
/* check if we entered a new month? */
bool new_month = ymd.month != TimerGameCalendar::month;
@@ -113,7 +232,7 @@ void TimerManager::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);
diff --git a/src/timer/timer_game_calendar.h b/src/timer/timer_game_calendar.h
--- a/src/timer/timer_game_calendar.h
+++ b/src/timer/timer_game_calendar.h
@@ -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.
+ /**
+ * Data structure to convert between Date and triplet (year, month, and day).
+ * @see TimerGameCalendar::ConvertDateToYMD(), TimerGameCalendar::ConvertYMDToDate()
+ */
+ struct YearMonthDay {
+ 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.
diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -17,8 +17,6 @@
#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"
@@ -56,6 +54,7 @@
#include "league_base.h"
#include "timer/timer.h"
#include "timer/timer_window.h"
+#include "timer/timer_game_calendar.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
{
switch (widget) {
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));
break;
}
}
@@ -2406,7 +2405,7 @@ struct ScenarioEditorToolbarWindow : Win
break;
case WID_TE_DATE:
- SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
+ SetDParam(0, TimerGameCalendar::ConvertYMDToDate(MAX_YEAR, 0, 1));
*size = GetStringBoundingBox(STR_WHITE_DATE_LONG);
break;
}
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -25,7 +25,6 @@
#include "group_gui.h"
#include "strings_func.h"
#include "zoom_func.h"
-#include "date_func.h"
#include "vehicle_func.h"
#include "autoreplace_func.h"
#include "autoreplace_gui.h"