# HG changeset patch # User Tyler Trahan # Date 2023-08-16 13:43:31 # Node ID 803962be032894317c2070d4e67b560e29284463 # Parent ddbd33508a8a76a47468c5b97826138eee0f4a15 Codechange: Move date consts and functions to CalendarTime and TimerGameCalendar classes diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -453,7 +453,7 @@ void Aircraft::OnNewDay() if (this->running_ticks == 0) return; - CommandCost cost(EXPENSES_AIRCRAFT_RUN, this->GetRunningCost() * this->running_ticks / (DAYS_IN_YEAR * Ticks::DAY_TICKS)); + CommandCost cost(EXPENSES_AIRCRAFT_RUN, this->GetRunningCost() * this->running_ticks / (CalendarTime::DAYS_IN_YEAR * Ticks::DAY_TICKS)); this->profit_this_year -= cost.GetCost(); this->running_ticks = 0; 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 @@ -967,7 +967,7 @@ int DrawVehiclePurchaseInfo(int left, in if (e->type != VEH_TRAIN || e->u.rail.railveh_type != RAILVEH_WAGON) { /* Design date - Life length */ SetDParam(0, ymd.year); - SetDParam(1, DateToYear(e->GetLifeLengthInDays())); + SetDParam(1, TimerGameCalendar::DateToYear(e->GetLifeLengthInDays())); DrawString(left, right, y, STR_PURCHASE_INFO_DESIGNED_LIFE); y += FONT_HEIGHT_NORMAL; diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -104,7 +104,7 @@ extern void EnginesMonthlyLoop(); static int32_t ClickChangeDateCheat(int32_t new_value, int32_t change_direction) { /* Don't allow changing to an invalid year, or the current year. */ - auto new_year = Clamp(TimerGameCalendar::Year(new_value), MIN_YEAR, MAX_YEAR); + auto new_year = Clamp(TimerGameCalendar::Year(new_value), CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR); if (new_year == TimerGameCalendar::year) return static_cast(TimerGameCalendar::year); TimerGameCalendar::YearMonthDay ymd; @@ -320,7 +320,7 @@ struct CheatWindow : Window { switch (ce->str) { /* Display date for change date cheat */ case STR_CHEAT_CHANGE_DATE: - SetDParam(0, TimerGameCalendar::ConvertYMDToDate(MAX_YEAR, 11, 31)); + SetDParam(0, TimerGameCalendar::ConvertYMDToDate(CalendarTime::MAX_YEAR, 11, 31)); width = std::max(width, GetStringBoundingBox(ce->str).width); break; diff --git a/src/company_gui.cpp b/src/company_gui.cpp --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -1861,7 +1861,7 @@ struct CompanyInfrastructureWindow : Win } /* Get the date introduced railtypes as well. */ - this->railtypes = AddDateIntroducedRailTypes(this->railtypes, MAX_DATE); + this->railtypes = AddDateIntroducedRailTypes(this->railtypes, CalendarTime::MAX_DATE); /* Find the used roadtypes. */ for (const Engine *e : Engine::IterateType(VEH_ROAD)) { @@ -1871,7 +1871,7 @@ struct CompanyInfrastructureWindow : Win } /* Get the date introduced roadtypes as well. */ - this->roadtypes = AddDateIntroducedRoadTypes(this->roadtypes, MAX_DATE); + this->roadtypes = AddDateIntroducedRoadTypes(this->roadtypes, CalendarTime::MAX_DATE); this->roadtypes &= ~_roadtypes_hidden_mask; } diff --git a/src/date_gui.cpp b/src/date_gui.cpp --- a/src/date_gui.cpp +++ b/src/date_gui.cpp @@ -44,8 +44,8 @@ struct SetDateWindow : Window { Window(desc), callback(callback), callback_data(callback_data), - min_year(std::max(MIN_YEAR, min_year)), - max_year(std::min(MAX_YEAR, max_year)) + min_year(std::max(CalendarTime::MIN_YEAR, min_year)), + max_year(std::min(CalendarTime::MAX_YEAR, max_year)) { assert(this->min_year <= this->max_year); this->parent = parent; diff --git a/src/date_type.h b/src/date_type.h --- a/src/date_type.h +++ b/src/date_type.h @@ -12,72 +12,5 @@ #include "timer/timer_game_calendar.h" -static const int DAYS_IN_YEAR = 365; ///< days per year -static const int DAYS_IN_LEAP_YEAR = 366; ///< sometimes, you need one day more... -static const int MONTHS_IN_YEAR = 12; ///< months per year - -static const int SECONDS_PER_DAY = 2; ///< approximate seconds per day, not for precise calculations - -/* - * ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR and DAYS_TILL_ORIGINAL_BASE_YEAR are - * primarily used for loading newgrf and savegame data and returning some - * newgrf (callback) functions that were in the original (TTD) inherited - * format, where 'TimerGameCalendar::date == 0' meant that it was 1920-01-01. - */ - -/** The minimum starting year/base year of the original TTD */ -static constexpr TimerGameCalendar::Year ORIGINAL_BASE_YEAR = 1920; -/** The original ending year */ -static constexpr TimerGameCalendar::Year ORIGINAL_END_YEAR = 2051; -/** The maximum year of the original TTD */ -static constexpr TimerGameCalendar::Year ORIGINAL_MAX_YEAR = 2090; - -/** - * Calculate the date of the first day of a given year. - * @param year the year to get the first day of. - * @return the date. - */ -static constexpr TimerGameCalendar::Date DateAtStartOfYear(TimerGameCalendar::Year year) -{ - int32_t year_as_int = static_cast(year); - uint number_of_leap_years = (year == 0) ? 0 : ((year_as_int - 1) / 4 - (year_as_int - 1) / 100 + (year_as_int - 1) / 400 + 1); - - return (DAYS_IN_YEAR * year_as_int) + number_of_leap_years; -} - -/** - * Calculate the year of a given date. - * @param date The date to consider. - * @return the year. - */ -static inline TimerGameCalendar::Year DateToYear(TimerGameCalendar::Date date) -{ - return static_cast(date) / DAYS_IN_LEAP_YEAR; -} - -/** - * The date of the first day of the original base year. - */ -static constexpr TimerGameCalendar::Date DAYS_TILL_ORIGINAL_BASE_YEAR = DateAtStartOfYear(ORIGINAL_BASE_YEAR); - -/** The absolute minimum & maximum years in OTTD */ -static constexpr TimerGameCalendar::Year MIN_YEAR = 0; - -/** The default starting year */ -static constexpr TimerGameCalendar::Year DEF_START_YEAR = 1950; -/** The default scoring end year */ -static constexpr TimerGameCalendar::Year DEF_END_YEAR = ORIGINAL_END_YEAR - 1; - -/** - * MAX_YEAR, nicely rounded value of the number of years that can - * be encoded in a single 32 bits date, about 2^31 / 366 years. - */ -static constexpr TimerGameCalendar::Year MAX_YEAR = 5000000; - -/** The date of the last day of the max year. */ -static constexpr TimerGameCalendar::Date MAX_DATE = DateAtStartOfYear(MAX_YEAR + 1) - 1; - -static constexpr TimerGameCalendar::Year INVALID_YEAR = -1; ///< Representation of an invalid year -static constexpr TimerGameCalendar::Date INVALID_DATE = -1; ///< Representation of an invalid date #endif /* DATE_TYPE_H */ diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -360,7 +360,7 @@ struct DepotWindow : Window { DrawSpriteIgnorePadding((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, flag, false, SA_CENTER); SetDParam(0, v->unitnumber); - DrawString(text, STR_JUST_COMMA, (v->max_age - DAYS_IN_LEAP_YEAR) >= v->age ? TC_BLACK : TC_RED); + DrawString(text, STR_JUST_COMMA, (v->max_age - CalendarTime::DAYS_IN_LEAP_YEAR) >= v->age ? TC_BLACK : TC_RED); } } diff --git a/src/economy.cpp b/src/economy.cpp --- a/src/economy.cpp +++ b/src/economy.cpp @@ -735,7 +735,7 @@ bool AddInflation(bool check_year) * inflation doesn't add anything after that either; it even makes playing * it impossible due to the diverging cost and income rates. */ - if (check_year && (TimerGameCalendar::year < ORIGINAL_BASE_YEAR || TimerGameCalendar::year >= ORIGINAL_MAX_YEAR)) return true; + if (check_year && (TimerGameCalendar::year < CalendarTime::ORIGINAL_BASE_YEAR || TimerGameCalendar::year >= CalendarTime::ORIGINAL_MAX_YEAR)) return true; if (_economy.inflation_prices == MAX_INFLATION || _economy.inflation_payment == MAX_INFLATION) return true; @@ -928,7 +928,7 @@ void StartupEconomy() if (_settings_game.economy.inflation) { /* Apply inflation that happened before our game start year. */ - int months = static_cast(std::min(TimerGameCalendar::year, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR) * 12; + int months = static_cast(std::min(TimerGameCalendar::year, CalendarTime::ORIGINAL_MAX_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR) * 12; for (int i = 0; i < months; i++) { AddInflation(false); } diff --git a/src/engine.cpp b/src/engine.cpp --- a/src/engine.cpp +++ b/src/engine.cpp @@ -438,7 +438,7 @@ uint Engine::GetDisplayMaxTractiveEffort */ TimerGameCalendar::Date Engine::GetLifeLengthInDays() const { - return DateAtStartOfYear(this->info.lifelength + _settings_game.vehicle.extend_vehicle_life); + return TimerGameCalendar::DateAtStartOfYear(this->info.lifelength + _settings_game.vehicle.extend_vehicle_life); } /** @@ -663,7 +663,7 @@ void SetYearEngineAgingStops() /* Base year ending date on half the model life */ TimerGameCalendar::YearMonthDay ymd; - TimerGameCalendar::ConvertDateToYMD(ei->base_intro + static_cast(DateAtStartOfYear(ei->lifelength)) / 2, &ymd); + TimerGameCalendar::ConvertDateToYMD(ei->base_intro + static_cast(TimerGameCalendar::DateAtStartOfYear(ei->lifelength)) / 2, &ymd); _year_engine_aging_stops = std::max(_year_engine_aging_stops, ymd.year); } @@ -1103,7 +1103,7 @@ void EnginesMonthlyLoop() /* Do not introduce invalid engines */ if (!e->IsEnabled()) continue; - if (!(e->flags & ENGINE_AVAILABLE) && TimerGameCalendar::date >= (e->intro_date + DAYS_IN_YEAR)) { + if (!(e->flags & ENGINE_AVAILABLE) && TimerGameCalendar::date >= (e->intro_date + CalendarTime::DAYS_IN_YEAR)) { /* Introduce it to all companies */ NewVehicleAvailable(e); } else if (!(e->flags & (ENGINE_AVAILABLE | ENGINE_EXCLUSIVE_PREVIEW)) && TimerGameCalendar::date >= e->intro_date) { diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -569,8 +569,8 @@ struct GenerateLandscapeWindow : public this->SetWidgetDisabledState(WID_GL_HEIGHTMAP_HEIGHT_DOWN, _settings_newgame.game_creation.heightmap_height <= MIN_HEIGHTMAP_HEIGHT); this->SetWidgetDisabledState(WID_GL_HEIGHTMAP_HEIGHT_UP, _settings_newgame.game_creation.heightmap_height >= GetMapHeightLimit()); } - this->SetWidgetDisabledState(WID_GL_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= MIN_YEAR); - this->SetWidgetDisabledState(WID_GL_START_DATE_UP, _settings_newgame.game_creation.starting_year >= MAX_YEAR); + this->SetWidgetDisabledState(WID_GL_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= CalendarTime::MIN_YEAR); + this->SetWidgetDisabledState(WID_GL_START_DATE_UP, _settings_newgame.game_creation.starting_year >= CalendarTime::MAX_YEAR); this->SetWidgetDisabledState(WID_GL_SNOW_COVERAGE_DOWN, _settings_newgame.game_creation.snow_coverage <= 0 || _settings_newgame.game_creation.landscape != LT_ARCTIC); this->SetWidgetDisabledState(WID_GL_SNOW_COVERAGE_UP, _settings_newgame.game_creation.snow_coverage >= 100 || _settings_newgame.game_creation.landscape != LT_ARCTIC); this->SetWidgetDisabledState(WID_GL_DESERT_COVERAGE_DOWN, _settings_newgame.game_creation.desert_coverage <= 0 || _settings_newgame.game_creation.landscape != LT_TROPIC); @@ -599,7 +599,7 @@ struct GenerateLandscapeWindow : public break; case WID_GL_START_DATE_TEXT: - SetDParam(0, TimerGameCalendar::ConvertYMDToDate(MAX_YEAR, 0, 1)); + SetDParam(0, TimerGameCalendar::ConvertYMDToDate(CalendarTime::MAX_YEAR, 0, 1)); d = GetStringBoundingBox(STR_JUST_DATE_LONG); break; @@ -763,7 +763,7 @@ struct GenerateLandscapeWindow : public if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) { this->HandleButtonClick(widget); - _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - WID_GL_START_DATE_TEXT, MIN_YEAR, MAX_YEAR); + _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - WID_GL_START_DATE_TEXT, CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR); this->InvalidateData(); } _left_button_clicked = false; @@ -968,7 +968,7 @@ struct GenerateLandscapeWindow : public /* An empty string means revert to the default */ switch (this->widget_id) { case WID_GL_HEIGHTMAP_HEIGHT_TEXT: value = MAP_HEIGHT_LIMIT_AUTO_MINIMUM; break; - case WID_GL_START_DATE_TEXT: value = static_cast(DEF_START_YEAR); break; + case WID_GL_START_DATE_TEXT: value = static_cast(CalendarTime::DEF_START_YEAR); break; case WID_GL_SNOW_COVERAGE_TEXT: value = DEF_SNOW_COVERAGE; break; case WID_GL_DESERT_COVERAGE_TEXT: value = DEF_DESERT_COVERAGE; break; case WID_GL_TOWN_PULLDOWN: value = 1; break; @@ -987,7 +987,7 @@ struct GenerateLandscapeWindow : public case WID_GL_START_DATE_TEXT: this->SetWidgetDirty(WID_GL_START_DATE_TEXT); - _settings_newgame.game_creation.starting_year = Clamp(TimerGameCalendar::Year(value), MIN_YEAR, MAX_YEAR); + _settings_newgame.game_creation.starting_year = Clamp(TimerGameCalendar::Year(value), CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR); break; case WID_GL_SNOW_COVERAGE_TEXT: @@ -1125,8 +1125,8 @@ struct CreateScenarioWindow : public Win void OnPaint() override { - this->SetWidgetDisabledState(WID_CS_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= MIN_YEAR); - this->SetWidgetDisabledState(WID_CS_START_DATE_UP, _settings_newgame.game_creation.starting_year >= MAX_YEAR); + this->SetWidgetDisabledState(WID_CS_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= CalendarTime::MIN_YEAR); + this->SetWidgetDisabledState(WID_CS_START_DATE_UP, _settings_newgame.game_creation.starting_year >= CalendarTime::MAX_YEAR); this->SetWidgetDisabledState(WID_CS_FLAT_LAND_HEIGHT_DOWN, _settings_newgame.game_creation.se_flat_world_height <= 0); this->SetWidgetDisabledState(WID_CS_FLAT_LAND_HEIGHT_UP, _settings_newgame.game_creation.se_flat_world_height >= GetMapHeightLimit()); @@ -1143,7 +1143,7 @@ struct CreateScenarioWindow : public Win StringID str = STR_JUST_INT; switch (widget) { case WID_CS_START_DATE_TEXT: - SetDParam(0, TimerGameCalendar::ConvertYMDToDate(MAX_YEAR, 0, 1)); + SetDParam(0, TimerGameCalendar::ConvertYMDToDate(CalendarTime::MAX_YEAR, 0, 1)); str = STR_JUST_DATE_LONG; break; @@ -1199,7 +1199,7 @@ struct CreateScenarioWindow : public Win this->HandleButtonClick(widget); this->SetDirty(); - _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - WID_CS_START_DATE_TEXT, MIN_YEAR, MAX_YEAR); + _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - WID_CS_START_DATE_TEXT, CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR); } _left_button_clicked = false; break; @@ -1258,7 +1258,7 @@ struct CreateScenarioWindow : public Win switch (this->widget_id) { case WID_CS_START_DATE_TEXT: this->SetWidgetDirty(WID_CS_START_DATE_TEXT); - _settings_newgame.game_creation.starting_year = Clamp(TimerGameCalendar::Year(value), MIN_YEAR, MAX_YEAR); + _settings_newgame.game_creation.starting_year = Clamp(TimerGameCalendar::Year(value), CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR); break; case WID_CS_FLAT_LAND_HEIGHT_TEXT: diff --git a/src/linkgraph/flowmapper.cpp b/src/linkgraph/flowmapper.cpp --- a/src/linkgraph/flowmapper.cpp +++ b/src/linkgraph/flowmapper.cpp @@ -50,7 +50,7 @@ void FlowMapper::Run(LinkGraphJob &job) /* Scale by time the graph has been running without being compressed. Add 1 to avoid * division by 0 if spawn date == last compression date. This matches * LinkGraph::Monthly(). */ - auto runtime = job.JoinDate() - job.Settings().recalc_time / SECONDS_PER_DAY - job.LastCompression() + 1; + auto runtime = job.JoinDate() - job.Settings().recalc_time / CalendarTime::SECONDS_PER_DAY - job.LastCompression() + 1; for (auto &it : flows) { it.second.ScaleToMonthly(static_cast(runtime)); } diff --git a/src/linkgraph/linkgraph.cpp b/src/linkgraph/linkgraph.cpp --- a/src/linkgraph/linkgraph.cpp +++ b/src/linkgraph/linkgraph.cpp @@ -29,7 +29,7 @@ LinkGraph::BaseNode::BaseNode(TileIndex this->supply = 0; this->demand = demand; this->station = st; - this->last_update = INVALID_DATE; + this->last_update = CalendarTime::INVALID_DATE; } /** @@ -40,8 +40,8 @@ LinkGraph::BaseEdge::BaseEdge(NodeID des this->capacity = 0; this->usage = 0; this->travel_time_sum = 0; - this->last_unrestricted_update = INVALID_DATE; - this->last_restricted_update = INVALID_DATE; + this->last_unrestricted_update = CalendarTime::INVALID_DATE; + this->last_restricted_update = CalendarTime::INVALID_DATE; this->dest_node = dest_node; } @@ -55,10 +55,10 @@ void LinkGraph::ShiftDates(TimerGameCale this->last_compression += interval; for (NodeID node1 = 0; node1 < this->Size(); ++node1) { BaseNode &source = this->nodes[node1]; - if (source.last_update != INVALID_DATE) source.last_update += interval; + if (source.last_update != CalendarTime::INVALID_DATE) source.last_update += interval; for (BaseEdge &edge : this->nodes[node1].edges) { - if (edge.last_unrestricted_update != INVALID_DATE) edge.last_unrestricted_update += interval; - if (edge.last_restricted_update != INVALID_DATE) edge.last_restricted_update += interval; + if (edge.last_unrestricted_update != CalendarTime::INVALID_DATE) edge.last_unrestricted_update += interval; + if (edge.last_restricted_update != CalendarTime::INVALID_DATE) edge.last_restricted_update += interval; } } } diff --git a/src/linkgraph/linkgraph.h b/src/linkgraph/linkgraph.h --- a/src/linkgraph/linkgraph.h +++ b/src/linkgraph/linkgraph.h @@ -63,8 +63,8 @@ public: TimerGameCalendar::Date LastUpdate() const { return std::max(this->last_unrestricted_update, this->last_restricted_update); } void Update(uint capacity, uint usage, uint32_t time, EdgeUpdateMode mode); - void Restrict() { this->last_unrestricted_update = INVALID_DATE; } - void Release() { this->last_restricted_update = INVALID_DATE; } + void Restrict() { this->last_unrestricted_update = CalendarTime::INVALID_DATE; } + void Release() { this->last_restricted_update = CalendarTime::INVALID_DATE; } /** Comparison operator based on \c dest_node. */ bool operator <(const BaseEdge &rhs) const diff --git a/src/linkgraph/linkgraphjob.cpp b/src/linkgraph/linkgraphjob.cpp --- a/src/linkgraph/linkgraphjob.cpp +++ b/src/linkgraph/linkgraphjob.cpp @@ -37,7 +37,7 @@ LinkGraphJob::LinkGraphJob(const LinkGra * This is on purpose. */ link_graph(orig), settings(_settings_game.linkgraph), - join_date(TimerGameCalendar::date + (_settings_game.linkgraph.recalc_time / SECONDS_PER_DAY)), + join_date(TimerGameCalendar::date + (_settings_game.linkgraph.recalc_time / CalendarTime::SECONDS_PER_DAY)), job_completed(false), job_aborted(false) { @@ -131,14 +131,14 @@ LinkGraphJob::~LinkGraphJob() if (st2 == nullptr || st2->goods[this->Cargo()].link_graph != this->link_graph.index || st2->goods[this->Cargo()].node != dest_id || !(*lg)[node_id].HasEdgeTo(dest_id) || - (*lg)[node_id][dest_id].LastUpdate() == INVALID_DATE) { + (*lg)[node_id][dest_id].LastUpdate() == CalendarTime::INVALID_DATE) { /* Edge has been removed. Delete flows. */ StationIDStack erased = flows.DeleteFlows(to); /* Delete old flows for source stations which have been deleted * from the new flows. This avoids flow cycles between old and * new flows. */ while (!erased.IsEmpty()) ge.flows.erase(erased.Pop()); - } else if ((*lg)[node_id][dest_id].last_restricted_update == INVALID_DATE) { + } else if ((*lg)[node_id][dest_id].last_restricted_update == CalendarTime::INVALID_DATE) { /* Edge is fully restricted. */ flows.RestrictFlows(to); } diff --git a/src/linkgraph/linkgraphjob.h b/src/linkgraph/linkgraphjob.h --- a/src/linkgraph/linkgraphjob.h +++ b/src/linkgraph/linkgraphjob.h @@ -178,7 +178,7 @@ public: * settings have to be brutally const-casted in order to populate them. */ LinkGraphJob() : settings(_settings_game.linkgraph), - join_date(INVALID_DATE), job_completed(false), job_aborted(false) {} + join_date(CalendarTime::INVALID_DATE), job_completed(false), job_aborted(false) {} LinkGraphJob(const LinkGraph &orig); ~LinkGraphJob(); diff --git a/src/linkgraph/linkgraphschedule.cpp b/src/linkgraph/linkgraphschedule.cpp --- a/src/linkgraph/linkgraphschedule.cpp +++ b/src/linkgraph/linkgraphschedule.cpp @@ -178,7 +178,7 @@ void StateGameLoop_LinkGraphPauseControl } } else if (_pause_mode == PM_UNPAUSED && TimerGameCalendar::date_fract == LinkGraphSchedule::SPAWN_JOIN_TICK - 2 && - static_cast(TimerGameCalendar::date) % (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY) == (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY) / 2 && + static_cast(TimerGameCalendar::date) % (_settings_game.linkgraph.recalc_interval / CalendarTime::SECONDS_PER_DAY) == (_settings_game.linkgraph.recalc_interval / CalendarTime::SECONDS_PER_DAY) / 2 && LinkGraphSchedule::instance.IsJoinWithUnfinishedJobDue()) { /* Perform check two TimerGameCalendar::date_fract ticks before we would join, to make * sure it also works in multiplayer. */ @@ -205,10 +205,10 @@ void AfterLoad_LinkGraphPauseControl() void OnTick_LinkGraph() { if (TimerGameCalendar::date_fract != LinkGraphSchedule::SPAWN_JOIN_TICK) return; - TimerGameCalendar::Date offset = static_cast(TimerGameCalendar::date) % (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY); + TimerGameCalendar::Date offset = static_cast(TimerGameCalendar::date) % (_settings_game.linkgraph.recalc_interval / CalendarTime::SECONDS_PER_DAY); if (offset == 0) { LinkGraphSchedule::instance.SpawnNext(); - } else if (offset == (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY) / 2) { + } else if (offset == (_settings_game.linkgraph.recalc_interval / CalendarTime::SECONDS_PER_DAY) / 2) { if (!_networking || _network_server) { PerformanceMeasurer::SetInactive(PFE_GL_LINKGRAPH); LinkGraphSchedule::instance.JoinNext(); diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -138,7 +138,7 @@ public: /* Because build_date is not set yet in every TileDesc, we make sure it is empty */ TileDesc td; - td.build_date = INVALID_DATE; + td.build_date = CalendarTime::INVALID_DATE; /* Most tiles have only one owner, but * - drivethrough roadstops can be build on town owned roads (up to 2 owners) and @@ -224,7 +224,7 @@ public: this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY)); /* Build date */ - if (td.build_date != INVALID_DATE) { + if (td.build_date != CalendarTime::INVALID_DATE) { SetDParam(0, td.build_date); this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_BUILD_DATE)); } diff --git a/src/network/core/network_game_info.cpp b/src/network/core/network_game_info.cpp --- a/src/network/core/network_game_info.cpp +++ b/src/network/core/network_game_info.cpp @@ -255,8 +255,6 @@ void SerializeNetworkGameInfo(Packet *p, */ void DeserializeNetworkGameInfo(Packet *p, NetworkGameInfo *info, const GameInfoNewGRFLookupTable *newgrf_lookup_table) { - 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; @@ -323,8 +321,8 @@ void DeserializeNetworkGameInfo(Packet * } case 3: - info->game_date = Clamp(p->Recv_uint32(), 0, static_cast(MAX_DATE)); - info->start_date = Clamp(p->Recv_uint32(), 0, static_cast(MAX_DATE)); + info->game_date = Clamp(p->Recv_uint32(), 0, static_cast(CalendarTime::MAX_DATE)); + info->start_date = Clamp(p->Recv_uint32(), 0, static_cast(CalendarTime::MAX_DATE)); FALLTHROUGH; case 2: @@ -342,8 +340,8 @@ void DeserializeNetworkGameInfo(Packet * info->clients_on = p->Recv_uint8 (); info->spectators_on = p->Recv_uint8 (); if (game_info_version < 3) { // 16 bits dates got scrapped and are read earlier - info->game_date = p->Recv_uint16() + DAYS_TILL_ORIGINAL_BASE_YEAR; - info->start_date = p->Recv_uint16() + DAYS_TILL_ORIGINAL_BASE_YEAR; + info->game_date = p->Recv_uint16() + CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR; + info->start_date = p->Recv_uint16() + CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR; } if (game_info_version < 6) while (p->Recv_uint8() != 0) {} // Used to contain the map-name. info->map_width = p->Recv_uint16(); diff --git a/src/newgrf.cpp b/src/newgrf.cpp --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -996,7 +996,7 @@ static ChangeInfoResult CommonVehicleCha { switch (prop) { case 0x00: // Introduction date - ei->base_intro = buf->ReadWord() + DAYS_TILL_ORIGINAL_BASE_YEAR; + ei->base_intro = buf->ReadWord() + CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR; break; case 0x02: // Decay speed @@ -2197,7 +2197,7 @@ static ChangeInfoResult BridgeChangeInfo case 0x08: { // Year of availability /* We treat '0' as always available */ byte year = buf->ReadByte(); - bridge->avail_year = (year > 0 ? ORIGINAL_BASE_YEAR + year : 0); + bridge->avail_year = (year > 0 ? CalendarTime::ORIGINAL_BASE_YEAR + year : 0); break; } @@ -2257,7 +2257,7 @@ static ChangeInfoResult BridgeChangeInfo break; case 0x0F: // Long format year of availability (year since year 0) - bridge->avail_year = Clamp(TimerGameCalendar::Year(buf->ReadDWord()), MIN_YEAR, MAX_YEAR); + bridge->avail_year = Clamp(TimerGameCalendar::Year(buf->ReadDWord()), CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR); break; case 0x10: { // purchase string @@ -2430,8 +2430,8 @@ static ChangeInfoResult TownHouseChangeI case 0x0A: { // Availability years uint16_t years = buf->ReadWord(); - housespec->min_year = GB(years, 0, 8) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB(years, 0, 8); - housespec->max_year = GB(years, 8, 8) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB(years, 8, 8); + housespec->min_year = GB(years, 0, 8) > 150 ? CalendarTime::MAX_YEAR : CalendarTime::ORIGINAL_BASE_YEAR + GB(years, 0, 8); + housespec->max_year = GB(years, 8, 8) > 150 ? CalendarTime::MAX_YEAR : CalendarTime::ORIGINAL_BASE_YEAR + GB(years, 8, 8); break; } @@ -3991,7 +3991,7 @@ static ChangeInfoResult AirportChangeInf case 0x0C: as->min_year = buf->ReadWord(); as->max_year = buf->ReadWord(); - if (as->max_year == 0xFFFF) as->max_year = MAX_YEAR; + if (as->max_year == 0xFFFF) as->max_year = CalendarTime::MAX_YEAR; break; case 0x0D: @@ -6512,11 +6512,11 @@ bool GetGlobalVariable(byte param, uint3 { switch (param) { case 0x00: // current date - *value = static_cast(std::max(TimerGameCalendar::date - DAYS_TILL_ORIGINAL_BASE_YEAR, TimerGameCalendar::Date(0))); + *value = static_cast(std::max(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR, TimerGameCalendar::Date(0))); return true; case 0x01: // current year - *value = static_cast(Clamp(TimerGameCalendar::year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR); + *value = static_cast(Clamp(TimerGameCalendar::year, CalendarTime::ORIGINAL_BASE_YEAR, CalendarTime::ORIGINAL_MAX_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR); return true; case 0x02: { // detailed date information: month of year (bit 0-7), day of month (bit 8-12), leap year (bit 15), day of year (bit 16-24) @@ -7228,7 +7228,7 @@ static uint32_t GetPatchVariable(uint8_t { switch (param) { /* start year - 1920 */ - case 0x0B: return static_cast(std::max(_settings_game.game_creation.starting_year, ORIGINAL_BASE_YEAR) - ORIGINAL_BASE_YEAR); + case 0x0B: return static_cast(std::max(_settings_game.game_creation.starting_year, CalendarTime::ORIGINAL_BASE_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR); /* freight trains weight factor */ case 0x0E: return _settings_game.vehicle.freight_trains; @@ -9237,7 +9237,7 @@ static bool IsHouseSpecValid(HouseSpec * */ static void EnsureEarlyHouse(HouseZones bitmask) { - TimerGameCalendar::Year min_year = MAX_YEAR; + TimerGameCalendar::Year min_year = CalendarTime::MAX_YEAR; for (int i = 0; i < NUM_HOUSES; i++) { HouseSpec *hs = HouseSpec::Get(i); diff --git a/src/newgrf_airport.cpp b/src/newgrf_airport.cpp --- a/src/newgrf_airport.cpp +++ b/src/newgrf_airport.cpp @@ -212,7 +212,7 @@ void AirportOverrideManager::SetEntitySp case 0x7C: return (this->st->airport.psa != nullptr) ? this->st->airport.psa->GetValue(parameter) : 0; case 0xF0: return this->st->facilities; - case 0xFA: return ClampTo(this->st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR); + case 0xFA: return ClampTo(this->st->build_date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); } return this->st->GetNewGRFVariable(this->ro, variable, parameter, available); diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -767,8 +767,8 @@ static uint32_t VehicleGetVariable(Vehic } return (variable - 0x80) == 0x10 ? ticks : GB(ticks, 8, 8); } - case 0x12: return ClampTo(v->date_of_last_service_newgrf - DAYS_TILL_ORIGINAL_BASE_YEAR); - case 0x13: return GB(ClampTo(v->date_of_last_service_newgrf - DAYS_TILL_ORIGINAL_BASE_YEAR), 8, 8); + case 0x12: return ClampTo(v->date_of_last_service_newgrf - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); + case 0x13: return GB(ClampTo(v->date_of_last_service_newgrf - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR), 8, 8); case 0x14: return v->GetServiceInterval(); case 0x15: return GB(v->GetServiceInterval(), 8, 8); case 0x16: return v->last_station_visited; @@ -829,7 +829,7 @@ static uint32_t VehicleGetVariable(Vehic case 0x41: return GB(ClampTo(v->age), 8, 8); case 0x42: return ClampTo(v->max_age); case 0x43: return GB(ClampTo(v->max_age), 8, 8); - case 0x44: return static_cast(Clamp(v->build_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR); + case 0x44: return static_cast(Clamp(v->build_year, CalendarTime::ORIGINAL_BASE_YEAR, CalendarTime::ORIGINAL_MAX_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR); case 0x45: return v->unitnumber; case 0x46: return v->GetEngine()->grf_prop.local_id; case 0x47: return GB(v->GetEngine()->grf_prop.local_id, 8, 8); @@ -974,9 +974,9 @@ static uint32_t VehicleGetVariable(Vehic case 0x48: return Engine::Get(this->self_type)->flags; // Vehicle Type Info case 0x49: return static_cast(TimerGameCalendar::year); // 'Long' format build year case 0x4B: return static_cast(TimerGameCalendar::date); // Long date of last service - case 0x92: return ClampTo(TimerGameCalendar::date - DAYS_TILL_ORIGINAL_BASE_YEAR); // Date of last service - case 0x93: return GB(ClampTo(TimerGameCalendar::date - DAYS_TILL_ORIGINAL_BASE_YEAR), 8, 8); - case 0xC4: return static_cast(Clamp(TimerGameCalendar::year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR); // Build year + case 0x92: return ClampTo(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date of last service + case 0x93: return GB(ClampTo(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR), 8, 8); + case 0xC4: return static_cast(Clamp(TimerGameCalendar::year, CalendarTime::ORIGINAL_BASE_YEAR, CalendarTime::ORIGINAL_MAX_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR); // Build year case 0xC6: return Engine::Get(this->self_type)->grf_prop.local_id; case 0xC7: return GB(Engine::Get(this->self_type)->grf_prop.local_id, 8, 8); case 0xDA: return INVALID_VEHICLE; // Next vehicle diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -396,16 +396,16 @@ static uint32_t GetCountAndDistanceOfClo case 0xA6: return indspec->grf_prop.local_id; case 0xA7: return this->industry->founder; case 0xA8: return this->industry->random_colour; - case 0xA9: return ClampTo(this->industry->last_prod_year - ORIGINAL_BASE_YEAR); + case 0xA9: return ClampTo(this->industry->last_prod_year - CalendarTime::ORIGINAL_BASE_YEAR); case 0xAA: return this->industry->counter; case 0xAB: return GB(this->industry->counter, 8, 8); case 0xAC: return this->industry->was_cargo_delivered; - case 0xB0: return ClampTo(this->industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR); // Date when built since 1920 (in days) + case 0xB0: return ClampTo(this->industry->construction_date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date when built since 1920 (in days) case 0xB3: return this->industry->construction_type; // Construction type case 0xB4: { auto it = std::max_element(std::begin(this->industry->accepted), std::end(this->industry->accepted), [](const auto &a, const auto &b) { return a.last_accepted < b.last_accepted; }); - return ClampTo(it->last_accepted - DAYS_TILL_ORIGINAL_BASE_YEAR); // Date last cargo accepted since 1920 (in days) + return ClampTo(it->last_accepted - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date last cargo accepted since 1920 (in days) } } diff --git a/src/newgrf_roadstop.cpp b/src/newgrf_roadstop.cpp --- a/src/newgrf_roadstop.cpp +++ b/src/newgrf_roadstop.cpp @@ -173,7 +173,7 @@ uint32_t RoadStopScopeResolver::GetVaria case 0xF0: return this->st == nullptr ? 0 : this->st->facilities; // facilities - case 0xFA: return ClampTo((this->st == nullptr ? TimerGameCalendar::date : this->st->build_date) - DAYS_TILL_ORIGINAL_BASE_YEAR); // build date + case 0xFA: return ClampTo((this->st == nullptr ? TimerGameCalendar::date : this->st->build_date) - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // build date } if (this->st != nullptr) return this->st->GetNewGRFVariable(this->ro, variable, parameter, available); diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -291,7 +291,7 @@ TownScopeResolver *StationResolverObject } break; - case 0xFA: return ClampTo(TimerGameCalendar::date - DAYS_TILL_ORIGINAL_BASE_YEAR); // Build date, clamped to a 16 bit value + case 0xFA: return ClampTo(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Build date, clamped to a 16 bit value } *available = false; @@ -381,7 +381,7 @@ TownScopeResolver *StationResolverObject case 0x84: return this->st->string_id; case 0x86: return 0; case 0xF0: return this->st->facilities; - case 0xFA: return ClampTo(this->st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR); + case 0xFA: return ClampTo(this->st->build_date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); } return this->st->GetNewGRFVariable(this->ro, variable, parameter, available); diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -23,6 +23,7 @@ #include "newgrf_text.h" #include "newgrf_cargo.h" #include "string_func.h" +#include "timer/timer_game_calendar.h" #include "date_type.h" #include "debug.h" #include "core/alloc_type.hpp" @@ -912,7 +913,7 @@ uint RemapNewGRFStringControlCode(uint s /* Dates from NewGRFs have 1920-01-01 as their zero point, convert it to OpenTTD's epoch. */ case SCC_NEWGRF_PRINT_WORD_DATE_LONG: - case SCC_NEWGRF_PRINT_WORD_DATE_SHORT: parameters.SetParam(0, _newgrf_textrefstack.PopUnsignedWord() + DAYS_TILL_ORIGINAL_BASE_YEAR); break; + case SCC_NEWGRF_PRINT_WORD_DATE_SHORT: parameters.SetParam(0, _newgrf_textrefstack.PopUnsignedWord() + CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); break; case SCC_NEWGRF_DISCARD_WORD: _newgrf_textrefstack.PopUnsignedWord(); break; diff --git a/src/news_gui.cpp b/src/news_gui.cpp --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -1134,7 +1134,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, TimerGameCalendar::ConvertYMDToDate(ORIGINAL_MAX_YEAR, 7, 30)); + SetDParam(0, TimerGameCalendar::ConvertYMDToDate(CalendarTime::ORIGINAL_MAX_YEAR, 7, 30)); this->date_width = GetStringBoundingBox(STR_JUST_DATE_TINY).width + WidgetDimensions::scaled.hsep_wide; size->height = 4 * resize->height + WidgetDimensions::scaled.framerect.Vertical(); // At least 4 lines are visible. diff --git a/src/openttd.cpp b/src/openttd.cpp --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -380,7 +380,7 @@ void OpenBrowser(const char *url) /** Callback structure of statements to be executed after the NewGRF scan. */ struct AfterNewGRFScan : NewGRFScanCallback { - TimerGameCalendar::Year startyear = INVALID_YEAR; ///< The start year. + TimerGameCalendar::Year startyear = CalendarTime::INVALID_YEAR; ///< The start year. uint32_t generation_seed = GENERATE_NEW_SEED; ///< Seed for the new game. std::string dedicated_host; ///< Hostname for the dedicated server. uint16_t dedicated_port = 0; ///< Port for the dedicated server. @@ -429,7 +429,7 @@ struct AfterNewGRFScan : NewGRFScanCallb MusicDriver::GetInstance()->SetVolume(_settings_client.music.music_vol); SetEffectVolume(_settings_client.music.effect_vol); - if (startyear != INVALID_YEAR) IConsoleSetSetting("game_creation.starting_year", static_cast(startyear)); + if (startyear != CalendarTime::INVALID_YEAR) IConsoleSetSetting("game_creation.starting_year", static_cast(startyear)); if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed; if (!dedicated_host.empty()) { diff --git a/src/order_base.h b/src/order_base.h --- a/src/order_base.h +++ b/src/order_base.h @@ -367,8 +367,8 @@ public: bool IsCompleteTimetable() const; /** - * Gets the total duration of the vehicles timetable or Tick::INVALID_TICKS is the timetable is not complete. - * @return total timetable duration or Tick::INVALID_TICKS for incomplete timetables + * Gets the total duration of the vehicles timetable or Ticks::INVALID_TICKS is the timetable is not complete. + * @return total timetable duration or Ticks::INVALID_TICKS for incomplete timetables */ inline TimerGameTick::Ticks GetTimetableTotalDuration() const { return this->IsCompleteTimetable() ? this->timetable_duration : Ticks::INVALID_TICKS; } diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -1947,10 +1947,10 @@ VehicleOrderID ProcessConditionalOrder(c case OCV_RELIABILITY: skip_order = OrderConditionCompare(occ, ToPercent16(v->reliability), value); break; case OCV_MAX_RELIABILITY: skip_order = OrderConditionCompare(occ, ToPercent16(v->GetEngine()->reliability), value); break; case OCV_MAX_SPEED: skip_order = OrderConditionCompare(occ, v->GetDisplayMaxSpeed() * 10 / 16, value); break; - case OCV_AGE: skip_order = OrderConditionCompare(occ, DateToYear(v->age), value); break; + case OCV_AGE: skip_order = OrderConditionCompare(occ, TimerGameCalendar::DateToYear(v->age), value); break; case OCV_REQUIRES_SERVICE: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break; case OCV_UNCONDITIONALLY: skip_order = true; break; - case OCV_REMAINING_LIFETIME: skip_order = OrderConditionCompare(occ, std::max(DateToYear(v->max_age - v->age + DAYS_IN_LEAP_YEAR - 1), TimerGameCalendar::Year(0)), value); break; + case OCV_REMAINING_LIFETIME: skip_order = OrderConditionCompare(occ, std::max(TimerGameCalendar::DateToYear(v->max_age - v->age + CalendarTime::DAYS_IN_LEAP_YEAR - 1), TimerGameCalendar::Year(0)), value); break; default: NOT_REACHED(); } diff --git a/src/rail.cpp b/src/rail.cpp --- a/src/rail.cpp +++ b/src/rail.cpp @@ -225,7 +225,7 @@ RailTypes AddDateIntroducedRailTypes(Rai if (rti->label == 0) continue; /* Not date introduced. */ - if (!IsInsideMM(rti->introduction_date, 0, static_cast(MAX_DATE))) continue; + if (!IsInsideMM(rti->introduction_date, 0, static_cast(CalendarTime::MAX_DATE))) continue; /* Not yet introduced at this date. */ if (rti->introduction_date > date) continue; @@ -256,7 +256,7 @@ RailTypes GetCompanyRailtypes(CompanyID const EngineInfo *ei = &e->info; if (HasBit(ei->climates, _settings_game.game_creation.landscape) && - (HasBit(e->company_avail, company) || TimerGameCalendar::date >= e->intro_date + DAYS_IN_YEAR)) { + (HasBit(e->company_avail, company) || TimerGameCalendar::date >= e->intro_date + CalendarTime::DAYS_IN_YEAR)) { const RailVehicleInfo *rvi = &e->u.rail; if (rvi->railveh_type != RAILVEH_WAGON) { @@ -298,7 +298,7 @@ RailTypes GetRailTypes(bool introduces) } } - if (introduces) return AddDateIntroducedRailTypes(rts, MAX_DATE); + if (introduces) return AddDateIntroducedRailTypes(rts, CalendarTime::MAX_DATE); return rts; } diff --git a/src/road.cpp b/src/road.cpp --- a/src/road.cpp +++ b/src/road.cpp @@ -115,7 +115,7 @@ bool HasRoadTypeAvail(const CompanyID co if (rti->label == 0) return false; /* Not yet introduced at this date. */ - if (IsInsideMM(rti->introduction_date, 0, static_cast(MAX_DATE)) && rti->introduction_date > TimerGameCalendar::date) return false; + if (IsInsideMM(rti->introduction_date, 0, static_cast(CalendarTime::MAX_DATE)) && rti->introduction_date > TimerGameCalendar::date) return false; /* * Do not allow building hidden road types, except when a town may build it. @@ -173,7 +173,7 @@ RoadTypes AddDateIntroducedRoadTypes(Roa if (rti->label == 0) continue; /* Not date introduced. */ - if (!IsInsideMM(rti->introduction_date, 0, static_cast(MAX_DATE))) continue; + if (!IsInsideMM(rti->introduction_date, 0, static_cast(CalendarTime::MAX_DATE))) continue; /* Not yet introduced at this date. */ if (rti->introduction_date > date) continue; @@ -204,7 +204,7 @@ RoadTypes GetCompanyRoadTypes(CompanyID const EngineInfo *ei = &e->info; if (HasBit(ei->climates, _settings_game.game_creation.landscape) && - (HasBit(e->company_avail, company) || TimerGameCalendar::date >= e->intro_date + DAYS_IN_YEAR)) { + (HasBit(e->company_avail, company) || TimerGameCalendar::date >= e->intro_date + CalendarTime::DAYS_IN_YEAR)) { const RoadVehicleInfo *rvi = &e->u.road; assert(rvi->roadtype < ROADTYPE_END); if (introduces) { @@ -241,7 +241,7 @@ RoadTypes GetRoadTypes(bool introduces) } } - if (introduces) return AddDateIntroducedRoadTypes(rts, MAX_DATE); + if (introduces) return AddDateIntroducedRoadTypes(rts, CalendarTime::MAX_DATE); return rts; } @@ -302,7 +302,7 @@ RoadTypes ExistingRoadTypes(CompanyID c) } /* Get the date introduced roadtypes as well. */ - known_roadtypes = AddDateIntroducedRoadTypes(known_roadtypes, MAX_DATE); + known_roadtypes = AddDateIntroducedRoadTypes(known_roadtypes, CalendarTime::MAX_DATE); return known_roadtypes; } diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -150,7 +150,7 @@ RoadType AllocateRoadType(RoadTypeLabel rti->label = label; rti->alternate_labels.clear(); rti->flags = ROTFB_NONE; - rti->introduction_date = INVALID_DATE; + rti->introduction_date = CalendarTime::INVALID_DATE; /* Make us compatible with ourself. */ rti->powered_roadtypes = (RoadTypes)(1ULL << rt); diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1720,7 +1720,7 @@ void RoadVehicle::OnNewDay() if (this->running_ticks == 0) return; - CommandCost cost(EXPENSES_ROADVEH_RUN, this->GetRunningCost() * this->running_ticks / (DAYS_IN_YEAR * Ticks::DAY_TICKS)); + CommandCost cost(EXPENSES_ROADVEH_RUN, this->GetRunningCost() * this->running_ticks / (CalendarTime::DAYS_IN_YEAR * Ticks::DAY_TICKS)); this->profit_this_year -= cost.GetCost(); this->running_ticks = 0; diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -259,7 +259,7 @@ static void InitializeWindowsAndCaches() /* For each company, verify (while loading a scenario) that the inauguration date is the current year and set it * accordingly if it is not the case. No need to set it on companies that are not been used already, * thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */ - if (_file_to_saveload.abstract_ftype == FT_SCENARIO && c->inaugurated_year != MIN_YEAR) { + if (_file_to_saveload.abstract_ftype == FT_SCENARIO && c->inaugurated_year != CalendarTime::MIN_YEAR) { c->inaugurated_year = TimerGameCalendar::year; } } @@ -776,13 +776,13 @@ bool AfterLoadGame() } if (IsSavegameVersionBefore(SLV_ENDING_YEAR)) { - _settings_game.game_creation.ending_year = DEF_END_YEAR; + _settings_game.game_creation.ending_year = CalendarTime::DEF_END_YEAR; } /* Convert linkgraph update settings from days to seconds. */ if (IsSavegameVersionBefore(SLV_LINKGRAPH_SECONDS)) { - _settings_game.linkgraph.recalc_interval *= SECONDS_PER_DAY; - _settings_game.linkgraph.recalc_time *= SECONDS_PER_DAY; + _settings_game.linkgraph.recalc_interval *= CalendarTime::SECONDS_PER_DAY; + _settings_game.linkgraph.recalc_time *= CalendarTime::SECONDS_PER_DAY; } /* Load the sprites */ @@ -1422,18 +1422,18 @@ bool AfterLoadGame() /* Time starts at 0 instead of 1920. * Account for this in older games by adding an offset */ if (IsSavegameVersionBefore(SLV_31)) { - TimerGameCalendar::date += DAYS_TILL_ORIGINAL_BASE_YEAR; - TimerGameCalendar::year += ORIGINAL_BASE_YEAR; - - for (Station *st : Station::Iterate()) st->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR; - for (Waypoint *wp : Waypoint::Iterate()) wp->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR; - for (Engine *e : Engine::Iterate()) e->intro_date += DAYS_TILL_ORIGINAL_BASE_YEAR; - for (Company *c : Company::Iterate()) c->inaugurated_year += ORIGINAL_BASE_YEAR; - for (Industry *i : Industry::Iterate()) i->last_prod_year += ORIGINAL_BASE_YEAR; + TimerGameCalendar::date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR; + TimerGameCalendar::year += CalendarTime::ORIGINAL_BASE_YEAR; + + for (Station *st : Station::Iterate()) st->build_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR; + for (Waypoint *wp : Waypoint::Iterate()) wp->build_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR; + for (Engine *e : Engine::Iterate()) e->intro_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR; + for (Company *c : Company::Iterate()) c->inaugurated_year += CalendarTime::ORIGINAL_BASE_YEAR; + for (Industry *i : Industry::Iterate()) i->last_prod_year += CalendarTime::ORIGINAL_BASE_YEAR; for (Vehicle *v : Vehicle::Iterate()) { - v->date_of_last_service += DAYS_TILL_ORIGINAL_BASE_YEAR; - v->build_year += ORIGINAL_BASE_YEAR; + v->date_of_last_service += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR; + v->build_year += CalendarTime::ORIGINAL_BASE_YEAR; } } @@ -1925,7 +1925,7 @@ bool AfterLoadGame() /* Replace "house construction year" with "house age" */ if (IsTileType(t, MP_HOUSE) && IsHouseCompleted(t)) { - t.m5() = ClampTo(TimerGameCalendar::year - (t.m5() + ORIGINAL_BASE_YEAR)); + t.m5() = ClampTo(TimerGameCalendar::year - (t.m5() + CalendarTime::ORIGINAL_BASE_YEAR)); } } } 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 @@ -135,7 +135,7 @@ struct DATEChunkHandler : ChunkHandler { this->LoadCommon(_date_check_desc, _date_check_sl_compat); if (IsSavegameVersionBefore(SLV_31)) { - _load_check_data.current_date += DAYS_TILL_ORIGINAL_BASE_YEAR; + _load_check_data.current_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR; } } }; 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 @@ -398,7 +398,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, TimerGameCalendar::ConvertYMDToDate(2050, 0, 1)); + TimerGameCalendar::Date aging_date = std::min(TimerGameCalendar::date + CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR, TimerGameCalendar::ConvertYMDToDate(2050, 0, 1)); for (EngineID i = 0; i < 256; i++) { int oi = ttd_to_tto[i]; @@ -406,11 +406,11 @@ static bool FixTTOEngines() if (oi == 255) { /* Default engine is used */ - TimerGameCalendar::date += DAYS_TILL_ORIGINAL_BASE_YEAR; + TimerGameCalendar::date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR; StartupOneEngine(e, aging_date, 0); CalcEngineReliability(e, false); - e->intro_date -= DAYS_TILL_ORIGINAL_BASE_YEAR; - TimerGameCalendar::date -= DAYS_TILL_ORIGINAL_BASE_YEAR; + e->intro_date -= CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR; + TimerGameCalendar::date -= CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR; /* Make sure for example monorail and maglev are available when they should be */ if (TimerGameCalendar::date >= e->intro_date && HasBit(e->info.climates, 0)) { @@ -1020,7 +1020,7 @@ static bool LoadOldCompany(LoadgameState } _company_colours[num] = (Colours)c->colour; - c->inaugurated_year -= ORIGINAL_BASE_YEAR; + c->inaugurated_year -= CalendarTime::ORIGINAL_BASE_YEAR; return true; } 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 @@ -56,7 +56,7 @@ { 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; + if (year < 0 || year > CalendarTime::MAX_YEAR) return DATE_INVALID; return (ScriptDate::Date)(int32_t)::TimerGameCalendar::ConvertYMDToDate(year, month - 1, day_of_month); } diff --git a/src/script/api/script_date.hpp b/src/script/api/script_date.hpp --- a/src/script/api/script_date.hpp +++ b/src/script/api/script_date.hpp @@ -11,6 +11,7 @@ #define SCRIPT_DATE_HPP #include "script_object.hpp" +#include "timer/timer_game_calendar.h" #include "../../date_type.h" /** @@ -31,7 +32,7 @@ public: * compose valid date values for a known year, month and day. */ enum Date { - DATE_INVALID = (int32_t)::INVALID_DATE, ///< A value representing an invalid date. + DATE_INVALID = (int32_t)::CalendarTime::INVALID_DATE, ///< A value representing an invalid date. }; /** diff --git a/src/settings.cpp b/src/settings.cpp --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1283,8 +1283,8 @@ void LoadFromConfig(bool startup) /* Load basic settings only during bootstrap, load other settings not during bootstrap */ if (!startup) { if (generic_version < IFV_LINKGRAPH_SECONDS) { - _settings_newgame.linkgraph.recalc_interval *= SECONDS_PER_DAY; - _settings_newgame.linkgraph.recalc_time *= SECONDS_PER_DAY; + _settings_newgame.linkgraph.recalc_interval *= CalendarTime::SECONDS_PER_DAY; + _settings_newgame.linkgraph.recalc_time *= CalendarTime::SECONDS_PER_DAY; } /* Move no_http_content_downloads and use_relay_service from generic_ini to private_ini. */ diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -2751,7 +2751,7 @@ struct CustomCurrencyWindow : Window { this->SetWidgetDisabledState(WID_CC_RATE_DOWN, _custom_currency.rate == 1); this->SetWidgetDisabledState(WID_CC_RATE_UP, _custom_currency.rate == UINT16_MAX); this->SetWidgetDisabledState(WID_CC_YEAR_DOWN, _custom_currency.to_euro == CF_NOEURO); - this->SetWidgetDisabledState(WID_CC_YEAR_UP, _custom_currency.to_euro == MAX_YEAR); + this->SetWidgetDisabledState(WID_CC_YEAR_UP, _custom_currency.to_euro == CalendarTime::MAX_YEAR); } void SetStringParameters(int widget) const override @@ -2850,8 +2850,8 @@ struct CustomCurrencyWindow : Window { break; case WID_CC_YEAR_UP: - _custom_currency.to_euro = Clamp(_custom_currency.to_euro + 1, MIN_EURO_YEAR, MAX_YEAR); - if (_custom_currency.to_euro == MAX_YEAR) this->DisableWidget(WID_CC_YEAR_UP); + _custom_currency.to_euro = Clamp(_custom_currency.to_euro + 1, MIN_EURO_YEAR, CalendarTime::MAX_YEAR); + if (_custom_currency.to_euro == CalendarTime::MAX_YEAR) this->DisableWidget(WID_CC_YEAR_UP); this->EnableWidget(WID_CC_YEAR_DOWN); break; @@ -2897,7 +2897,7 @@ struct CustomCurrencyWindow : Window { case WID_CC_YEAR: { // Year to switch to euro TimerGameCalendar::Year val = atoi(str); - _custom_currency.to_euro = (val < MIN_EURO_YEAR ? CF_NOEURO : std::min(val, MAX_YEAR)); + _custom_currency.to_euro = (val < MIN_EURO_YEAR ? CF_NOEURO : std::min(val, CalendarTime::MAX_YEAR)); break; } } diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -236,7 +236,7 @@ void Ship::OnNewDay() if (this->running_ticks == 0) return; - CommandCost cost(EXPENSES_SHIP_RUN, this->GetRunningCost() * this->running_ticks / (DAYS_IN_YEAR * Ticks::DAY_TICKS)); + CommandCost cost(EXPENSES_SHIP_RUN, this->GetRunningCost() * this->running_ticks / (CalendarTime::DAYS_IN_YEAR * Ticks::DAY_TICKS)); this->profit_this_year -= cost.GetCost(); this->running_ticks = 0; diff --git a/src/station.cpp b/src/station.cpp --- a/src/station.cpp +++ b/src/station.cpp @@ -105,7 +105,7 @@ Station::~Station() for (NodeID node = 0; node < lg->Size(); ++node) { Station *st = Station::Get((*lg)[node].station); st->goods[c].flows.erase(this->index); - if ((*lg)[node].HasEdgeTo(this->goods[c].node) && (*lg)[node][this->goods[c].node].LastUpdate() != INVALID_DATE) { + if ((*lg)[node].HasEdgeTo(this->goods[c].node) && (*lg)[node][this->goods[c].node].LastUpdate() != CalendarTime::INVALID_DATE) { st->goods[c].flows.DeleteFlows(this->index); RerouteCargo(st, c, this->index, st->index); } diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -3863,11 +3863,11 @@ void DeleteStaleLinks(Station *from) ge.flows.DeleteFlows(to->index); RerouteCargo(from, c, to->index, from->index); } - } else if (edge.last_unrestricted_update != INVALID_DATE && TimerGameCalendar::date - edge.last_unrestricted_update > timeout) { + } else if (edge.last_unrestricted_update != CalendarTime::INVALID_DATE && TimerGameCalendar::date - edge.last_unrestricted_update > timeout) { edge.Restrict(); ge.flows.RestrictFlows(to->index); RerouteCargo(from, c, to->index, from->index); - } else if (edge.last_restricted_update != INVALID_DATE && TimerGameCalendar::date - edge.last_restricted_update > timeout) { + } else if (edge.last_restricted_update != CalendarTime::INVALID_DATE && TimerGameCalendar::date - edge.last_restricted_update > timeout) { edge.Release(); } } diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -89,7 +89,7 @@ struct StatusBarWindow : Window { Dimension d; switch (widget) { case WID_S_LEFT: - SetDParamMaxValue(0, DateAtStartOfYear(MAX_YEAR)); + SetDParamMaxValue(0, TimerGameCalendar::DateAtStartOfYear(CalendarTime::MAX_YEAR)); d = GetStringBoundingBox(STR_JUST_DATE_LONG); break; diff --git a/src/story_gui.cpp b/src/story_gui.cpp --- a/src/story_gui.cpp +++ b/src/story_gui.cpp @@ -699,7 +699,7 @@ public: int y_offset = -scrollpos; /* Date */ - if (page->date != INVALID_DATE) { + if (page->date != CalendarTime::INVALID_DATE) { SetDParam(0, page->date); DrawString(0, fr.right, y_offset, STR_JUST_DATE_LONG, TC_BLACK); } diff --git a/src/subsidy.cpp b/src/subsidy.cpp --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -45,7 +45,7 @@ void Subsidy::AwardTo(CompanyID company) assert(!this->IsAwarded()); this->awarded = company; - this->remaining = _settings_game.difficulty.subsidy_duration * MONTHS_IN_YEAR; + this->remaining = _settings_game.difficulty.subsidy_duration * CalendarTime::MONTHS_IN_YEAR; SetDParam(0, company); NewsStringData *company_name = new NewsStringData(GetString(STR_COMPANY_NAME)); diff --git a/src/table/airport_defaults.h b/src/table/airport_defaults.h --- a/src/table/airport_defaults.h +++ b/src/table/airport_defaults.h @@ -10,7 +10,7 @@ #ifndef AIRPORT_DEFAULTS_H #define AIRPORT_DEFAULTS_H -#include "date_type.h" +#include "timer/timer_game_calendar.h" /** * Definition of an airport tiles layout. @@ -397,20 +397,20 @@ static const Direction _default_airports /* The helidepot and helistation have ATP_TTDP_SMALL because they are at ground level */ extern const AirportSpec _origin_airport_specs[] = { AS(country, 4, 3, 0, 1959, 4, 3, 7, ATP_TTDP_SMALL, APC_SMALL, STR_AIRPORT_SMALL, SPR_AIRPORT_PREVIEW_SMALL), - AS(city, 6, 6, 1955, MAX_YEAR, 5, 5, 24, ATP_TTDP_LARGE, APC_LARGE, STR_AIRPORT_CITY, SPR_AIRPORT_PREVIEW_LARGE), - AS_ND(heliport, 1, 1, 1963, MAX_YEAR, 4, 1, 4, ATP_TTDP_HELIPORT, APC_HELIPORT, STR_AIRPORT_HELIPORT, SPR_AIRPORT_PREVIEW_HELIPORT), - AS(metropolitan, 6, 6, 1980, MAX_YEAR, 6, 8, 28, ATP_TTDP_LARGE, APC_LARGE, STR_AIRPORT_METRO, SPR_AIRPORT_PREVIEW_METROPOLITAN), - AS(international, 7, 7, 1990, MAX_YEAR, 8, 17, 42, ATP_TTDP_LARGE, APC_HUB, STR_AIRPORT_INTERNATIONAL, SPR_AIRPORT_PREVIEW_INTERNATIONAL), - AS(commuter, 5, 4, 1983, MAX_YEAR, 4, 4, 20, ATP_TTDP_SMALL, APC_SMALL, STR_AIRPORT_COMMUTER, SPR_AIRPORT_PREVIEW_COMMUTER), - AS(helidepot, 2, 2, 1976, MAX_YEAR, 4, 2, 7, ATP_TTDP_SMALL, APC_HELIPORT, STR_AIRPORT_HELIDEPOT, SPR_AIRPORT_PREVIEW_HELIDEPOT), - AS(intercontinental, 9, 11, 2002, MAX_YEAR, 10, 25, 72, ATP_TTDP_LARGE, APC_HUB, STR_AIRPORT_INTERCONTINENTAL, SPR_AIRPORT_PREVIEW_INTERCONTINENTAL), - AS(helistation, 4, 2, 1980, MAX_YEAR, 4, 3, 14, ATP_TTDP_SMALL, APC_HELIPORT, STR_AIRPORT_HELISTATION, SPR_AIRPORT_PREVIEW_HELISTATION), + AS(city, 6, 6, 1955, CalendarTime::MAX_YEAR, 5, 5, 24, ATP_TTDP_LARGE, APC_LARGE, STR_AIRPORT_CITY, SPR_AIRPORT_PREVIEW_LARGE), + AS_ND(heliport, 1, 1, 1963, CalendarTime::MAX_YEAR, 4, 1, 4, ATP_TTDP_HELIPORT, APC_HELIPORT, STR_AIRPORT_HELIPORT, SPR_AIRPORT_PREVIEW_HELIPORT), + AS(metropolitan, 6, 6, 1980, CalendarTime::MAX_YEAR, 6, 8, 28, ATP_TTDP_LARGE, APC_LARGE, STR_AIRPORT_METRO, SPR_AIRPORT_PREVIEW_METROPOLITAN), + AS(international, 7, 7, 1990, CalendarTime::MAX_YEAR, 8, 17, 42, ATP_TTDP_LARGE, APC_HUB, STR_AIRPORT_INTERNATIONAL, SPR_AIRPORT_PREVIEW_INTERNATIONAL), + AS(commuter, 5, 4, 1983, CalendarTime::MAX_YEAR, 4, 4, 20, ATP_TTDP_SMALL, APC_SMALL, STR_AIRPORT_COMMUTER, SPR_AIRPORT_PREVIEW_COMMUTER), + AS(helidepot, 2, 2, 1976, CalendarTime::MAX_YEAR, 4, 2, 7, ATP_TTDP_SMALL, APC_HELIPORT, STR_AIRPORT_HELIDEPOT, SPR_AIRPORT_PREVIEW_HELIDEPOT), + AS(intercontinental, 9, 11, 2002, CalendarTime::MAX_YEAR, 10, 25, 72, ATP_TTDP_LARGE, APC_HUB, STR_AIRPORT_INTERCONTINENTAL, SPR_AIRPORT_PREVIEW_INTERCONTINENTAL), + AS(helistation, 4, 2, 1980, CalendarTime::MAX_YEAR, 4, 3, 14, ATP_TTDP_SMALL, APC_HELIPORT, STR_AIRPORT_HELISTATION, SPR_AIRPORT_PREVIEW_HELISTATION), AS_GENERIC(&_airportfta_oilrig, nullptr, _default_airports_rotation, 0, nullptr, 0, 1, 1, 0, 4, 0, 0, 0, ATP_TTDP_OILRIG, APC_HELIPORT, STR_NULL, 0, false), }; static_assert(NEW_AIRPORT_OFFSET == lengthof(_origin_airport_specs)); -const AirportSpec AirportSpec::dummy = AS_GENERIC(&_airportfta_dummy, nullptr, _default_airports_rotation, 0, nullptr, 0, 0, 0, 0, 0, MIN_YEAR, MIN_YEAR, 0, ATP_TTDP_LARGE, APC_BEGIN, STR_NULL, 0, false); +const AirportSpec AirportSpec::dummy = AS_GENERIC(&_airportfta_dummy, nullptr, _default_airports_rotation, 0, nullptr, 0, 0, 0, 0, 0, CalendarTime::MIN_YEAR, CalendarTime::MIN_YEAR, 0, ATP_TTDP_LARGE, APC_BEGIN, STR_NULL, 0, false); #undef AS #undef AS_ND diff --git a/src/table/engines.h b/src/table/engines.h --- a/src/table/engines.h +++ b/src/table/engines.h @@ -24,7 +24,7 @@ * @param f Bitmask of the climates * @note the 5 between b and f is the load amount */ -#define MT(a, b, c, d, e, f) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, e, 0, 8, 0, 0, 0, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } +#define MT(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, e, 0, 8, 0, 0, 0, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } /** * Writes the properties of a multiple-unit train into the EngineInfo struct. @@ -37,7 +37,7 @@ * @param f Bitmask of the climates * @note the 5 between b and f is the load amount */ -#define MM(a, b, c, d, e, f) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, e, 0, 8, 1 << EF_RAIL_IS_MU, 0, 0, STR_EMPTY, Tick::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } +#define MM(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, e, 0, 8, 1 << EF_RAIL_IS_MU, 0, 0, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } /** * Writes the properties of a train carriage into the EngineInfo struct. @@ -50,7 +50,7 @@ * @see MT * @note the 5 between b and f is the load amount */ -#define MW(a, b, c, d, e, f) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, e, 0, 8, 0, 0, 0, STR_EMPTY, Tick::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } +#define MW(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, e, 0, 8, 0, 0, 0, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } /** * Writes the properties of a road vehicle into the EngineInfo struct. @@ -63,7 +63,7 @@ * @param f Bitmask of the climates * @note the 5 between b and f is the load amount */ -#define MR(a, b, c, d, e, f) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, e, 0, 8, 0, 0, 0, STR_EMPTY, Tick::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } +#define MR(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, e, 0, 8, 0, 0, 0, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } /** * Writes the properties of a ship into the EngineInfo struct. @@ -75,7 +75,7 @@ * @param f Bitmask of the climates * @note the 10 between b and f is the load amount */ -#define MS(a, b, c, d, e, f) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 10, f, e, 0, 8, 0, 0, 0, STR_EMPTY, Tick::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } +#define MS(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 10, f, e, 0, 8, 0, 0, 0, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } /** * Writes the properties of an aeroplane into the EngineInfo struct. @@ -86,7 +86,7 @@ * @param e Bitmask of the climates * @note the 20 between b and e is the load amount */ -#define MA(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 20, e, CT_INVALID, 0, 8, 0, 0, 0, STR_EMPTY, Tick::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } +#define MA(a, b, c, d, e) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 20, e, CT_INVALID, 0, 8, 0, 0, 0, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE, ExtraEngineFlags::None } /* Climates * T = Temperate diff --git a/src/table/object_land.h b/src/table/object_land.h --- a/src/table/object_land.h +++ b/src/table/object_land.h @@ -121,7 +121,7 @@ static const DrawTileSprites _object_hq[ #undef TILE_SPRITE_LINE -#define M(name, size, build_cost_multiplier, clear_cost_multiplier, height, climate, gen_amount, flags) { GRFFilePropsBase<2>(), {0, 0, 0, 0}, INVALID_OBJECT_CLASS, name, climate, size, build_cost_multiplier, clear_cost_multiplier, 0, MAX_DATE + 1, flags, 0, height, 1, gen_amount } +#define M(name, size, build_cost_multiplier, clear_cost_multiplier, height, climate, gen_amount, flags) { GRFFilePropsBase<2>(), {0, 0, 0, 0}, INVALID_OBJECT_CLASS, name, climate, size, build_cost_multiplier, clear_cost_multiplier, 0, CalendarTime::MAX_DATE + 1, flags, 0, height, 1, gen_amount } /* Climates * T = Temperate diff --git a/src/table/railtypes.h b/src/table/railtypes.h --- a/src/table/railtypes.h +++ b/src/table/railtypes.h @@ -99,7 +99,7 @@ static const RailtypeInfo _original_rail 0x0A, /* introduction date */ - INVALID_DATE, + CalendarTime::INVALID_DATE, /* railtypes required for this to be introduced */ RAILTYPES_NONE, @@ -200,7 +200,7 @@ static const RailtypeInfo _original_rail 0x0A, /* introduction date */ - INVALID_DATE, + CalendarTime::INVALID_DATE, /* railtypes required for this to be introduced */ RAILTYPES_NONE, @@ -297,7 +297,7 @@ static const RailtypeInfo _original_rail 0x0A, /* introduction date */ - INVALID_DATE, + CalendarTime::INVALID_DATE, /* railtypes required for this to be introduced */ RAILTYPES_NONE, @@ -394,7 +394,7 @@ static const RailtypeInfo _original_rail 0x0A, /* introduction date */ - INVALID_DATE, + CalendarTime::INVALID_DATE, /* railtypes required for this to be introduced */ RAILTYPES_NONE, diff --git a/src/table/roadtypes.h b/src/table/roadtypes.h --- a/src/table/roadtypes.h +++ b/src/table/roadtypes.h @@ -82,7 +82,7 @@ static const RoadTypeInfo _original_road 0x01, /* introduction date */ - static_cast(MIN_YEAR), + static_cast(CalendarTime::MIN_YEAR), /* roadtypes required for this to be introduced */ ROADTYPES_NONE, @@ -162,7 +162,7 @@ static const RoadTypeInfo _original_road 0x01, /* introduction date */ - INVALID_DATE, + CalendarTime::INVALID_DATE, /* roadtypes required for this to be introduced */ ROADTYPES_NONE, diff --git a/src/table/settings/currency_settings.ini b/src/table/settings/currency_settings.ini --- a/src/table/settings/currency_settings.ini +++ b/src/table/settings/currency_settings.ini @@ -50,8 +50,8 @@ cat = SC_BASIC var = to_euro type = SLE_INT32 def = 0 -min = MIN_YEAR -max = MAX_YEAR +min = CalendarTime::MIN_YEAR +max = CalendarTime::MAX_YEAR [SDT_SSTR] var = prefix diff --git a/src/table/settings/gui_settings.ini b/src/table/settings/gui_settings.ini --- a/src/table/settings/gui_settings.ini +++ b/src/table/settings/gui_settings.ini @@ -496,8 +496,8 @@ var = gui.coloured_news_year type = SLE_INT32 flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC def = 2000 -min = MIN_YEAR -max = MAX_YEAR +min = CalendarTime::MIN_YEAR +max = CalendarTime::MAX_YEAR interval = 1 str = STR_CONFIG_SETTING_COLOURED_NEWS_YEAR strhelp = STR_CONFIG_SETTING_COLOURED_NEWS_YEAR_HELPTEXT @@ -543,8 +543,8 @@ var = gui.semaphore_build_before type = SLE_INT32 flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC def = 1950 -min = MIN_YEAR -max = MAX_YEAR +min = CalendarTime::MIN_YEAR +max = CalendarTime::MAX_YEAR interval = 1 str = STR_CONFIG_SETTING_SEMAPHORE_BUILD_BEFORE_DATE strhelp = STR_CONFIG_SETTING_SEMAPHORE_BUILD_BEFORE_DATE_HELPTEXT diff --git a/src/table/settings/network_settings.ini b/src/table/settings/network_settings.ini --- a/src/table/settings/network_settings.ini +++ b/src/table/settings/network_settings.ini @@ -237,8 +237,8 @@ var = network.restart_game_year type = SLE_INT32 flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_GUI_0_IS_SPECIAL | SF_NETWORK_ONLY def = 0 -min = MIN_YEAR -max = MAX_YEAR +min = CalendarTime::MIN_YEAR +max = CalendarTime::MAX_YEAR interval = 1 [SDTC_VAR] diff --git a/src/table/settings/world_settings.ini b/src/table/settings/world_settings.ini --- a/src/table/settings/world_settings.ini +++ b/src/table/settings/world_settings.ini @@ -122,9 +122,9 @@ cat = SC_BASIC [SDT_VAR] var = game_creation.starting_year type = SLE_INT32 -def = DEF_START_YEAR -min = MIN_YEAR -max = MAX_YEAR +def = CalendarTime::DEF_START_YEAR +min = CalendarTime::MIN_YEAR +max = CalendarTime::MAX_YEAR interval = 1 str = STR_CONFIG_SETTING_STARTING_YEAR strval = STR_JUST_INT @@ -135,9 +135,9 @@ var = game_creation.ending_year type = SLE_INT32 from = SLV_ENDING_YEAR flags = SF_GUI_0_IS_SPECIAL -def = DEF_END_YEAR -min = MIN_YEAR -max = MAX_YEAR - 1 +def = CalendarTime::DEF_END_YEAR +min = CalendarTime::MIN_YEAR +max = CalendarTime::MAX_YEAR - 1 interval = 1 str = STR_CONFIG_SETTING_ENDING_YEAR strhelp = STR_CONFIG_SETTING_ENDING_YEAR_HELPTEXT diff --git a/src/table/town_land.h b/src/table/town_land.h --- a/src/table/town_land.h +++ b/src/table/town_land.h @@ -1821,7 +1821,7 @@ static const HouseSpec _original_house_s * remove_rating_decrease * | mail_generation * min_year | | 1st CargoID acceptance - * | max_year | | | 2nd CargoID acceptance + * | CalendarTime::MAX_YEAR | | | 2nd CargoID acceptance * | | population | | | | 3th CargoID acceptance * | | | removal_cost | | | | | * | | | | building_name | | | | | @@ -1832,59 +1832,59 @@ static const HouseSpec _original_house_s * +-cargoID accepted | | | | | | | | * | | | | | | | | | | | */ - MS(1963, MAX_YEAR, 187, 150, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 140, 70, 8, 3, 4, + MS(1963, CalendarTime::MAX_YEAR, 187, 150, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 140, 70, 8, 3, 4, TILE_SIZE_1x1, HZ_TEMP | HZ_ZON5, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 00 - MS(1957, MAX_YEAR, 85, 140, STR_TOWN_BUILDING_NAME_OFFICE_BLOCK_1, 130, 55, 8, 3, 4, + MS(1957, CalendarTime::MAX_YEAR, 85, 140, STR_TOWN_BUILDING_NAME_OFFICE_BLOCK_1, 130, 55, 8, 3, 4, TILE_SIZE_1x1, HZ_TEMP | HZ_ZON5 | HZ_ZON4, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 01 - MS(1968, MAX_YEAR, 40, 100, STR_TOWN_BUILDING_NAME_SMALL_BLOCK_OF_FLATS_1, 90, 20, 8, 3, 1, + MS(1968, CalendarTime::MAX_YEAR, 40, 100, STR_TOWN_BUILDING_NAME_SMALL_BLOCK_OF_FLATS_1, 90, 20, 8, 3, 1, TILE_SIZE_1x1, HZ_TEMP | HZ_ZON4 | HZ_ZON3 | HZ_ZON2, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 02 - MS( 0, MAX_YEAR, 5, 90, STR_TOWN_BUILDING_NAME_CHURCH_1, 230, 2, 2, 0, 0, + MS( 0, CalendarTime::MAX_YEAR, 5, 90, STR_TOWN_BUILDING_NAME_CHURCH_1, 230, 2, 2, 0, 0, BUILDING_IS_CHURCH | TILE_SIZE_1x1, HZ_TEMP | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 03 - MS(1975, MAX_YEAR, 220, 160, STR_TOWN_BUILDING_NAME_LARGE_OFFICE_BLOCK_1, 160, 85, 10, 4, 6, + MS(1975, CalendarTime::MAX_YEAR, 220, 160, STR_TOWN_BUILDING_NAME_LARGE_OFFICE_BLOCK_1, 160, 85, 10, 4, 6, BUILDING_IS_ANIMATED | TILE_SIZE_1x1, HZ_TEMP | HZ_SUBARTC_BELOW | HZ_SUBTROPIC | HZ_ZON5, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 04 - MS(1975, MAX_YEAR, 220, 160, STR_TOWN_BUILDING_NAME_LARGE_OFFICE_BLOCK_1, 160, 85, 10, 4, 6, + MS(1975, CalendarTime::MAX_YEAR, 220, 160, STR_TOWN_BUILDING_NAME_LARGE_OFFICE_BLOCK_1, 160, 85, 10, 4, 6, BUILDING_IS_ANIMATED | TILE_SIZE_1x1, HZ_SUBARTC_ABOVE | HZ_ZON5, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 05 - MS( 0, MAX_YEAR, 30, 80, STR_TOWN_BUILDING_NAME_TOWN_HOUSES_1, 80, 12, 4, 1, 0, + MS( 0, CalendarTime::MAX_YEAR, 30, 80, STR_TOWN_BUILDING_NAME_TOWN_HOUSES_1, 80, 12, 4, 1, 0, TILE_SIZE_1x1, HZ_TEMP | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 06 - MS(1959, MAX_YEAR, 140, 180, STR_TOWN_BUILDING_NAME_HOTEL_1, 150, 22, 6, 1, 2, + MS(1959, CalendarTime::MAX_YEAR, 140, 180, STR_TOWN_BUILDING_NAME_HOTEL_1, 150, 22, 6, 1, 2, TILE_SIZE_1x2, HZ_TEMP | HZ_ZON5 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 07 - MS(1959, MAX_YEAR, 0, 180, STR_TOWN_BUILDING_NAME_HOTEL_1, 150, 22, 6, 1, 2, + MS(1959, CalendarTime::MAX_YEAR, 0, 180, STR_TOWN_BUILDING_NAME_HOTEL_1, 150, 22, 6, 1, 2, TILE_NO_FLAG, HZ_NOZNS, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 08 - MS(1945, MAX_YEAR, 0, 65, STR_TOWN_BUILDING_NAME_STATUE_1, 40, 0, 2, 0, 0, + MS(1945, CalendarTime::MAX_YEAR, 0, 65, STR_TOWN_BUILDING_NAME_STATUE_1, 40, 0, 2, 0, 0, TILE_SIZE_1x1, HZ_TEMP | HZ_SUBARTC_BELOW | HZ_SUBTROPIC | HZ_ZON5 | HZ_ZON4, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 09 - MS(1945, MAX_YEAR, 0, 65, STR_TOWN_BUILDING_NAME_FOUNTAIN_1, 40, 0, 2, 0, 0, + MS(1945, CalendarTime::MAX_YEAR, 0, 65, STR_TOWN_BUILDING_NAME_FOUNTAIN_1, 40, 0, 2, 0, 0, TILE_SIZE_1x1, HZ_TEMP | HZ_SUBARTC_BELOW | HZ_SUBTROPIC | HZ_ZON5, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 0A - MS( 0, MAX_YEAR, 0, 60, STR_TOWN_BUILDING_NAME_PARK_1, 75, 0, 2, 0, 0, + MS( 0, CalendarTime::MAX_YEAR, 0, 60, STR_TOWN_BUILDING_NAME_PARK_1, 75, 0, 2, 0, 0, TILE_SIZE_1x1, HZ_TEMP | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 0B - MS(1935, MAX_YEAR, 0, 60, STR_TOWN_BUILDING_NAME_PARK_1, 75, 0, 2, 0, 0, + MS(1935, CalendarTime::MAX_YEAR, 0, 60, STR_TOWN_BUILDING_NAME_PARK_1, 75, 0, 2, 0, 0, TILE_SIZE_1x1, HZ_TEMP | HZ_ZON4, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 0C - MS(1951, MAX_YEAR, 150, 130, STR_TOWN_BUILDING_NAME_OFFICE_BLOCK_2, 110, 65, 8, 2, 4, + MS(1951, CalendarTime::MAX_YEAR, 150, 130, STR_TOWN_BUILDING_NAME_OFFICE_BLOCK_2, 110, 65, 8, 2, 4, TILE_SIZE_1x1, HZ_TEMP | HZ_ZON5 | HZ_ZON4, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 0D @@ -1900,31 +1900,31 @@ static const HouseSpec _original_house_s TILE_SIZE_1x1, HZ_TEMP | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 10 - MS(1977, MAX_YEAR, 130, 200, STR_TOWN_BUILDING_NAME_MODERN_OFFICE_BUILDING_1, 150, 50, 10, 3, 6, + MS(1977, CalendarTime::MAX_YEAR, 130, 200, STR_TOWN_BUILDING_NAME_MODERN_OFFICE_BUILDING_1, 150, 50, 10, 3, 6, TILE_SIZE_1x1, HZ_TEMP | HZ_SUBARTC_BELOW | HZ_SUBTROPIC | HZ_ZON5, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 11 - MS(1983, MAX_YEAR, 6, 145, STR_TOWN_BUILDING_NAME_WAREHOUSE_1, 110, 10, 6, 3, 8, + MS(1983, CalendarTime::MAX_YEAR, 6, 145, STR_TOWN_BUILDING_NAME_WAREHOUSE_1, 110, 10, 6, 3, 8, TILE_SIZE_1x1, HZ_TEMP | HZ_ZON5, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 12 - MS(1985, MAX_YEAR, 110, 155, STR_TOWN_BUILDING_NAME_OFFICE_BLOCK_3, 110, 55, 6, 2, 6, + MS(1985, CalendarTime::MAX_YEAR, 110, 155, STR_TOWN_BUILDING_NAME_OFFICE_BLOCK_3, 110, 55, 6, 2, 6, TILE_SIZE_1x1, HZ_TEMP | HZ_ZON5, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 13 - MS( 0, MAX_YEAR, 65, 250, STR_TOWN_BUILDING_NAME_STADIUM_1, 300, 5, 4, 0, 0, + MS( 0, CalendarTime::MAX_YEAR, 65, 250, STR_TOWN_BUILDING_NAME_STADIUM_1, 300, 5, 4, 0, 0, BUILDING_IS_STADIUM | TILE_SIZE_2x2, HZ_TEMP | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 14 - MS( 0, MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_STADIUM_1, 300, 5, 4, 0, 0, + MS( 0, CalendarTime::MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_STADIUM_1, 300, 5, 4, 0, 0, TILE_NO_FLAG, HZ_NOZNS, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 15 - MS( 0, MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_STADIUM_1, 300, 5, 4, 0, 0, + MS( 0, CalendarTime::MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_STADIUM_1, 300, 5, 4, 0, 0, TILE_NO_FLAG, HZ_NOZNS, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 16 - MS( 0, MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_STADIUM_1, 300, 5, 4, 0, 0, + MS( 0, CalendarTime::MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_STADIUM_1, 300, 5, 4, 0, 0, TILE_NO_FLAG, HZ_NOZNS, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 17 @@ -1936,15 +1936,15 @@ static const HouseSpec _original_house_s TILE_SIZE_1x1, HZ_TEMP | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 19 - MS(1931, MAX_YEAR, 13, 71, STR_TOWN_BUILDING_NAME_HOUSES_1, 75, 8, 3, 1, 0, + MS(1931, CalendarTime::MAX_YEAR, 13, 71, STR_TOWN_BUILDING_NAME_HOUSES_1, 75, 8, 3, 1, 0, TILE_SIZE_1x1, HZ_TEMP | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 1A - MS(1935, MAX_YEAR, 100, 135, STR_TOWN_BUILDING_NAME_FLATS_1, 100, 35, 7, 2, 2, + MS(1935, CalendarTime::MAX_YEAR, 100, 135, STR_TOWN_BUILDING_NAME_FLATS_1, 100, 35, 7, 2, 2, TILE_SIZE_1x1, HZ_TEMP | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 1B - MS(1963, MAX_YEAR, 170, 145, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_2, 170, 50, 8, 3, 3, + MS(1963, CalendarTime::MAX_YEAR, 170, 145, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_2, 170, 50, 8, 3, 3, TILE_SIZE_1x1, HZ_TEMP | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 1C @@ -1952,31 +1952,31 @@ static const HouseSpec _original_house_s TILE_SIZE_1x1, HZ_TEMP | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 1D - MS(1973, MAX_YEAR, 180, 155, STR_TOWN_BUILDING_NAME_SHOPS_AND_OFFICES_3, 180, 64, 8, 3, 3, + MS(1973, CalendarTime::MAX_YEAR, 180, 155, STR_TOWN_BUILDING_NAME_SHOPS_AND_OFFICES_3, 180, 64, 8, 3, 3, TILE_SIZE_1x1, HZ_TEMP | HZ_SUBTROPIC | HZ_ZON5 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 1E - MS( 0, MAX_YEAR, 35, 220, STR_TOWN_BUILDING_NAME_THEATER_1, 230, 23, 8, 2, 2, + MS( 0, CalendarTime::MAX_YEAR, 35, 220, STR_TOWN_BUILDING_NAME_THEATER_1, 230, 23, 8, 2, 2, TILE_SIZE_1x1, HZ_TEMP | HZ_ZON5 | HZ_ZON4, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 1F - MS(1958, MAX_YEAR, 65, 250, STR_TOWN_BUILDING_NAME_STADIUM_2, 300, 5, 4, 0, 0, + MS(1958, CalendarTime::MAX_YEAR, 65, 250, STR_TOWN_BUILDING_NAME_STADIUM_2, 300, 5, 4, 0, 0, BUILDING_IS_STADIUM | TILE_SIZE_2x2, HZ_TEMP | HZ_SUBARTC_BELOW | HZ_SUBTROPIC | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 20 - MS(1958, MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_STADIUM_2, 300, 5, 4, 0, 0, + MS(1958, CalendarTime::MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_STADIUM_2, 300, 5, 4, 0, 0, TILE_NO_FLAG, HZ_NOZNS, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 21 - MS(1958, MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_STADIUM_2, 300, 5, 4, 0, 0, + MS(1958, CalendarTime::MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_STADIUM_2, 300, 5, 4, 0, 0, TILE_NO_FLAG, HZ_NOZNS, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 22 - MS(1958, MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_STADIUM_2, 300, 5, 4, 0, 0, + MS(1958, CalendarTime::MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_STADIUM_2, 300, 5, 4, 0, 0, TILE_NO_FLAG, HZ_NOZNS, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 23 - MS(2000, MAX_YEAR, 140, 170, STR_TOWN_BUILDING_NAME_OFFICES_1, 250, 65, 8, 3, 2, + MS(2000, CalendarTime::MAX_YEAR, 140, 170, STR_TOWN_BUILDING_NAME_OFFICES_1, 250, 65, 8, 3, 2, TILE_SIZE_1x1, HZ_TEMP | HZ_SUBARTC_BELOW | HZ_SUBTROPIC | HZ_ZON5 | HZ_ZON4, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 24 @@ -1988,39 +1988,39 @@ static const HouseSpec _original_house_s TILE_SIZE_1x1, HZ_SUBARTC_ABOVE | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 26 - MS(1945, MAX_YEAR, 35, 210, STR_TOWN_BUILDING_NAME_CINEMA_1, 230, 23, 8, 2, 2, + MS(1945, CalendarTime::MAX_YEAR, 35, 210, STR_TOWN_BUILDING_NAME_CINEMA_1, 230, 23, 8, 2, 2, TILE_SIZE_1x1, HZ_TEMP | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 27 - MS(1983, MAX_YEAR, 180, 250, STR_TOWN_BUILDING_NAME_SHOPPING_MALL_1, 300, 5, 8, 2, 3, + MS(1983, CalendarTime::MAX_YEAR, 180, 250, STR_TOWN_BUILDING_NAME_SHOPPING_MALL_1, 300, 5, 8, 2, 3, TILE_SIZE_2x2, HZ_TEMP | HZ_ZON5 | HZ_ZON4 | HZ_ZON3 |HZ_ZON2, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 28 - MS(1983, MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_SHOPPING_MALL_1, 300, 5, 8, 2, 3, + MS(1983, CalendarTime::MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_SHOPPING_MALL_1, 300, 5, 8, 2, 3, TILE_NO_FLAG, HZ_NOZNS, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 29 - MS(1983, MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_SHOPPING_MALL_1, 300, 5, 8, 2, 3, + MS(1983, CalendarTime::MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_SHOPPING_MALL_1, 300, 5, 8, 2, 3, TILE_NO_FLAG, HZ_NOZNS, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 2A - MS(1983, MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_SHOPPING_MALL_1, 300, 5, 8, 2, 3, + MS(1983, CalendarTime::MAX_YEAR, 0, 250, STR_TOWN_BUILDING_NAME_SHOPPING_MALL_1, 300, 5, 8, 2, 3, TILE_NO_FLAG, HZ_NOZNS, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 2B - MS( 0, MAX_YEAR, 80, 100, STR_TOWN_BUILDING_NAME_FLATS_1, 90, 20, 5, 2, 2, + MS( 0, CalendarTime::MAX_YEAR, 80, 100, STR_TOWN_BUILDING_NAME_FLATS_1, 90, 20, 5, 2, 2, TILE_SIZE_1x1, HZ_SUBARTC_BELOW | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 2C - MS( 0, MAX_YEAR, 80, 100, STR_TOWN_BUILDING_NAME_FLATS_1, 90, 20, 5, 2, 2, + MS( 0, CalendarTime::MAX_YEAR, 80, 100, STR_TOWN_BUILDING_NAME_FLATS_1, 90, 20, 5, 2, 2, TILE_SIZE_1x1, HZ_SUBARTC_ABOVE | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 2D - MS( 0, MAX_YEAR, 16, 70, STR_TOWN_BUILDING_NAME_HOUSES_2, 70, 6, 3, 1, 2, + MS( 0, CalendarTime::MAX_YEAR, 16, 70, STR_TOWN_BUILDING_NAME_HOUSES_2, 70, 6, 3, 1, 2, TILE_SIZE_1x1, HZ_SUBARTC_BELOW | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 2E - MS( 0, MAX_YEAR, 16, 70, STR_TOWN_BUILDING_NAME_HOUSES_2, 70, 6, 3, 1, 2, + MS( 0, CalendarTime::MAX_YEAR, 16, 70, STR_TOWN_BUILDING_NAME_HOUSES_2, 70, 6, 3, 1, 2, TILE_SIZE_1x1, HZ_SUBARTC_ABOVE | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 2F @@ -2032,59 +2032,59 @@ static const HouseSpec _original_house_s TILE_SIZE_1x1, HZ_SUBARTC_ABOVE | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 31 - MS(1966, MAX_YEAR, 135, 150, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 120, 60, 8, 3, 4, + MS(1966, CalendarTime::MAX_YEAR, 135, 150, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 120, 60, 8, 3, 4, TILE_SIZE_1x1, HZ_SUBARTC_BELOW | HZ_SUBTROPIC | HZ_ZON5 | HZ_ZON4, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 32 - MS(1966, MAX_YEAR, 135, 150, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 120, 60, 8, 3, 4, + MS(1966, CalendarTime::MAX_YEAR, 135, 150, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 120, 60, 8, 3, 4, TILE_SIZE_1x1, HZ_SUBARTC_ABOVE | HZ_ZON5 | HZ_ZON4, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 33 - MS(1970, MAX_YEAR, 170, 170, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 130, 70, 9, 3, 4, + MS(1970, CalendarTime::MAX_YEAR, 170, 170, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 130, 70, 9, 3, 4, TILE_SIZE_1x1, HZ_SUBARTC_BELOW | HZ_ZON5 | HZ_ZON4, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 34 - MS(1970, MAX_YEAR, 170, 170, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 130, 70, 9, 3, 4, + MS(1970, CalendarTime::MAX_YEAR, 170, 170, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 130, 70, 9, 3, 4, TILE_SIZE_1x1, HZ_SUBARTC_ABOVE | HZ_ZON5 | HZ_ZON4, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 35 - MS(1974, MAX_YEAR, 210, 200, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 140, 80, 10, 3, 5, + MS(1974, CalendarTime::MAX_YEAR, 210, 200, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 140, 80, 10, 3, 5, TILE_SIZE_1x1, HZ_SUBARTC_BELOW | HZ_SUBTROPIC | HZ_ZON5 | HZ_ZON4, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 36 - MS(1974, MAX_YEAR, 210, 200, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 140, 80, 10, 3, 5, + MS(1974, CalendarTime::MAX_YEAR, 210, 200, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 140, 80, 10, 3, 5, TILE_SIZE_1x1, HZ_SUBARTC_ABOVE | HZ_ZON5 | HZ_ZON4, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 37 - MS( 0, MAX_YEAR, 10, 60, STR_TOWN_BUILDING_NAME_HOUSES_2, 60, 5, 2, 1, 1, + MS( 0, CalendarTime::MAX_YEAR, 10, 60, STR_TOWN_BUILDING_NAME_HOUSES_2, 60, 5, 2, 1, 1, TILE_SIZE_1x1, HZ_SUBARTC_BELOW | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 38 - MS( 0, MAX_YEAR, 10, 60, STR_TOWN_BUILDING_NAME_HOUSES_2, 60, 5, 2, 1, 1, + MS( 0, CalendarTime::MAX_YEAR, 10, 60, STR_TOWN_BUILDING_NAME_HOUSES_2, 60, 5, 2, 1, 1, TILE_SIZE_1x1, HZ_SUBARTC_ABOVE | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 39 - MS( 0, MAX_YEAR, 25, 100, STR_TOWN_BUILDING_NAME_SHOPS_AND_OFFICES_1, 80, 20, 3, 1, 1, + MS( 0, CalendarTime::MAX_YEAR, 25, 100, STR_TOWN_BUILDING_NAME_SHOPS_AND_OFFICES_1, 80, 20, 3, 1, 1, TILE_SIZE_1x1, HZ_SUBARTC_BELOW | HZ_ZON5 | HZ_ZON4 | HZ_ZON3 | HZ_ZON2, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 3A - MS( 0, MAX_YEAR, 25, 100, STR_TOWN_BUILDING_NAME_SHOPS_AND_OFFICES_1, 80, 20, 3, 1, 1, + MS( 0, CalendarTime::MAX_YEAR, 25, 100, STR_TOWN_BUILDING_NAME_SHOPS_AND_OFFICES_1, 80, 20, 3, 1, 1, TILE_SIZE_1x1, HZ_SUBARTC_ABOVE | HZ_ZON5 | HZ_ZON4 | HZ_ZON3 | HZ_ZON2, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 3B - MS( 0, MAX_YEAR, 6, 85, STR_TOWN_BUILDING_NAME_CHURCH_1, 230, 2, 2, 0, 0, + MS( 0, CalendarTime::MAX_YEAR, 6, 85, STR_TOWN_BUILDING_NAME_CHURCH_1, 230, 2, 2, 0, 0, BUILDING_IS_CHURCH | TILE_SIZE_1x1, HZ_SUBARTC_BELOW | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 3C - MS( 0, MAX_YEAR, 6, 85, STR_TOWN_BUILDING_NAME_CHURCH_1, 230, 2, 2, 0, 0, + MS( 0, CalendarTime::MAX_YEAR, 6, 85, STR_TOWN_BUILDING_NAME_CHURCH_1, 230, 2, 2, 0, 0, BUILDING_IS_CHURCH | TILE_SIZE_1x1, HZ_SUBARTC_ABOVE | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 3D - MS( 0, MAX_YEAR, 17, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 80, 7, 3, 1, 1, + MS( 0, CalendarTime::MAX_YEAR, 17, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 80, 7, 3, 1, 1, TILE_SIZE_1x1, HZ_SUBARTC_BELOW | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 3E - MS( 0, MAX_YEAR, 17, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 80, 7, 3, 1, 1, + MS( 0, CalendarTime::MAX_YEAR, 17, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 80, 7, 3, 1, 1, TILE_SIZE_1x1, HZ_SUBARTC_ABOVE | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 3F @@ -2096,179 +2096,179 @@ static const HouseSpec _original_house_s TILE_SIZE_1x1, HZ_SUBARTC_ABOVE| HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 41 - MS(1972, MAX_YEAR, 140, 160, STR_TOWN_BUILDING_NAME_HOTEL_1, 160, 25, 6, 1, 3, + MS(1972, CalendarTime::MAX_YEAR, 140, 160, STR_TOWN_BUILDING_NAME_HOTEL_1, 160, 25, 6, 1, 3, TILE_SIZE_1x2, HZ_SUBARTC_BELOW| HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 42 - MS(1972, MAX_YEAR, 0, 160, STR_TOWN_BUILDING_NAME_HOTEL_1, 160, 25, 6, 1, 2, + MS(1972, CalendarTime::MAX_YEAR, 0, 160, STR_TOWN_BUILDING_NAME_HOTEL_1, 160, 25, 6, 1, 2, TILE_NO_FLAG, HZ_NOZNS, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 43 - MS(1972, MAX_YEAR, 140, 160, STR_TOWN_BUILDING_NAME_HOTEL_1, 160, 25, 6, 1, 3, + MS(1972, CalendarTime::MAX_YEAR, 140, 160, STR_TOWN_BUILDING_NAME_HOTEL_1, 160, 25, 6, 1, 3, TILE_SIZE_1x2, HZ_SUBARTC_ABOVE| HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 44 - MS(1972, MAX_YEAR, 0, 160, STR_TOWN_BUILDING_NAME_HOTEL_1, 160, 25, 6, 1, 2, + MS(1972, CalendarTime::MAX_YEAR, 0, 160, STR_TOWN_BUILDING_NAME_HOTEL_1, 160, 25, 6, 1, 2, TILE_NO_FLAG, HZ_NOZNS, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 45 - MS(1963, MAX_YEAR, 105, 130, STR_TOWN_BUILDING_NAME_SHOPS_AND_OFFICES_1, 105, 50, 7, 2, 3, + MS(1963, CalendarTime::MAX_YEAR, 105, 130, STR_TOWN_BUILDING_NAME_SHOPS_AND_OFFICES_1, 105, 50, 7, 2, 3, TILE_SIZE_1x1, HZ_SUBARTC_BELOW | HZ_SUBTROPIC | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 46 - MS(1963, MAX_YEAR, 105, 130, STR_TOWN_BUILDING_NAME_SHOPS_AND_OFFICES_1, 105, 50, 7, 2, 3, + MS(1963, CalendarTime::MAX_YEAR, 105, 130, STR_TOWN_BUILDING_NAME_SHOPS_AND_OFFICES_1, 105, 50, 7, 2, 3, TILE_SIZE_1x1, HZ_SUBARTC_ABOVE| HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 47 - MS(1978, MAX_YEAR, 190, 190, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 135, 75, 9, 3, 4, + MS(1978, CalendarTime::MAX_YEAR, 190, 190, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 135, 75, 9, 3, 4, TILE_SIZE_1x1, HZ_SUBARTC_BELOW | HZ_ZON5 | HZ_ZON4, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 48 - MS(1978, MAX_YEAR, 190, 190, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 135, 75, 9, 3, 4, + MS(1978, CalendarTime::MAX_YEAR, 190, 190, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 135, 75, 9, 3, 4, TILE_SIZE_1x1, HZ_SUBARTC_ABOVE | HZ_ZON5 | HZ_ZON4, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 49 - MS(1967, MAX_YEAR, 250, 140, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 200, 60, 7, 2, 2, + MS(1967, CalendarTime::MAX_YEAR, 250, 140, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 200, 60, 7, 2, 2, TILE_SIZE_2x1, HZ_SUBARTC_BELOW| HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 4A - MS(1967, MAX_YEAR, 0, 140, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 200, 60, 7, 2, 2, + MS(1967, CalendarTime::MAX_YEAR, 0, 140, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 200, 60, 7, 2, 2, TILE_NO_FLAG, HZ_NOZNS, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 4B - MS(1967, MAX_YEAR, 250, 140, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 200, 60, 7, 2, 2, + MS(1967, CalendarTime::MAX_YEAR, 250, 140, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 200, 60, 7, 2, 2, TILE_SIZE_2x1, HZ_SUBARTC_ABOVE | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 4C - MS(1967, MAX_YEAR, 0, 140, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 200, 60, 7, 2, 2, + MS(1967, CalendarTime::MAX_YEAR, 0, 140, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 200, 60, 7, 2, 2, TILE_NO_FLAG, HZ_NOZNS, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 4D - MS( 0, MAX_YEAR, 16, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 80, 6, 3, 1, 2, + MS( 0, CalendarTime::MAX_YEAR, 16, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 80, 6, 3, 1, 2, TILE_SIZE_1x1, HZ_SUBTROPIC | HZ_ZON5 | HZ_ZON4 | HZ_ZON3 | HZ_ZON2, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 4E - MS( 0, MAX_YEAR, 16, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 80, 6, 3, 1, 2, + MS( 0, CalendarTime::MAX_YEAR, 16, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 80, 6, 3, 1, 2, TILE_SIZE_1x1, HZ_SUBTROPIC | HZ_ZON5 | HZ_ZON4 | HZ_ZON3 | HZ_ZON2, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 4F - MS( 0, MAX_YEAR, 16, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 80, 5, 3, 1, 2, + MS( 0, CalendarTime::MAX_YEAR, 16, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 80, 5, 3, 1, 2, TILE_SIZE_1x1, HZ_SUBTROPIC | HZ_ZON5 | HZ_ZON4 | HZ_ZON3 | HZ_ZON2, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 50 - MS( 0, MAX_YEAR, 7, 30, STR_TOWN_BUILDING_NAME_HOUSES_2, 30, 4, 3, 1, 1, + MS( 0, CalendarTime::MAX_YEAR, 7, 30, STR_TOWN_BUILDING_NAME_HOUSES_2, 30, 4, 3, 1, 1, TILE_SIZE_1x1, HZ_SUBTROPIC | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 51 - MS( 0, MAX_YEAR, 45, 130, STR_TOWN_BUILDING_NAME_FLATS_1, 95, 15, 6, 2, 1, + MS( 0, CalendarTime::MAX_YEAR, 45, 130, STR_TOWN_BUILDING_NAME_FLATS_1, 95, 15, 6, 2, 1, TILE_SIZE_1x1, HZ_SUBTROPIC | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 52 - MS( 0, MAX_YEAR, 8, 90, STR_TOWN_BUILDING_NAME_CHURCH_1, 200, 3, 2, 0, 0, + MS( 0, CalendarTime::MAX_YEAR, 8, 90, STR_TOWN_BUILDING_NAME_CHURCH_1, 200, 3, 2, 0, 0, BUILDING_IS_CHURCH | TILE_SIZE_1x1, HZ_SUBTROPIC | HZ_ZON4 | HZ_ZON3 | HZ_ZON2, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 53 - MS( 0, MAX_YEAR, 18, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 80, 7, 3, 1, 2, + MS( 0, CalendarTime::MAX_YEAR, 18, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 80, 7, 3, 1, 2, TILE_SIZE_1x1, HZ_SUBTROPIC | HZ_ZON5 | HZ_ZON4 | HZ_ZON3 | HZ_ZON2, CT_PASSENGERS, CT_MAIL, CT_FOOD), // 54 - MS(1973, MAX_YEAR, 90, 110, STR_TOWN_BUILDING_NAME_FLATS_1, 95, 24, 6, 2, 1, + MS(1973, CalendarTime::MAX_YEAR, 90, 110, STR_TOWN_BUILDING_NAME_FLATS_1, 95, 24, 6, 2, 1, TILE_SIZE_1x1, HZ_SUBTROPIC | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 55 - MS(1962, MAX_YEAR, 120, 120, STR_TOWN_BUILDING_NAME_FLATS_1, 95, 25, 6, 2, 1, + MS(1962, CalendarTime::MAX_YEAR, 120, 120, STR_TOWN_BUILDING_NAME_FLATS_1, 95, 25, 6, 2, 1, TILE_SIZE_1x1, HZ_SUBTROPIC | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 56 - MS(1984, MAX_YEAR, 250, 190, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 140, 80, 8, 3, 4, + MS(1984, CalendarTime::MAX_YEAR, 250, 190, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 140, 80, 8, 3, 4, TILE_SIZE_2x1, HZ_SUBTROPIC | HZ_ZON5 | HZ_ZON4, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 57 - MS(1984, MAX_YEAR, 0, 190, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 140, 80, 8, 3, 4, + MS(1984, CalendarTime::MAX_YEAR, 0, 190, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 140, 80, 8, 3, 4, TILE_NO_FLAG, HZ_SUBTROPIC, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 58 - MS( 0, MAX_YEAR, 80, 110, STR_TOWN_BUILDING_NAME_FLATS_1, 95, 23, 6, 2, 1, + MS( 0, CalendarTime::MAX_YEAR, 80, 110, STR_TOWN_BUILDING_NAME_FLATS_1, 95, 23, 6, 2, 1, TILE_SIZE_1x1, HZ_SUBTROPIC | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 59 - MS(1993, MAX_YEAR, 180, 180, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 150, 90, 8, 3, 4, + MS(1993, CalendarTime::MAX_YEAR, 180, 180, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 150, 90, 8, 3, 4, TILE_SIZE_1x1, HZ_SUBTROPIC | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_GOODS), // 5A - MS( 0, MAX_YEAR, 8, 90, STR_TOWN_BUILDING_NAME_CHURCH_1, 200, 3, 2, 0, 0, + MS( 0, CalendarTime::MAX_YEAR, 8, 90, STR_TOWN_BUILDING_NAME_CHURCH_1, 200, 3, 2, 0, 0, BUILDING_IS_CHURCH | TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON5 | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_CANDY), // 5B - MS( 0, MAX_YEAR, 18, 90, STR_TOWN_BUILDING_NAME_HOUSES_2, 90, 5, 6, 2, 2, + MS( 0, CalendarTime::MAX_YEAR, 18, 90, STR_TOWN_BUILDING_NAME_HOUSES_2, 90, 5, 6, 2, 2, TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON5 | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_CANDY), // 5C - MS( 0, MAX_YEAR, 7, 70, STR_TOWN_BUILDING_NAME_HOUSES_2, 50, 3, 3, 1, 1, + MS( 0, CalendarTime::MAX_YEAR, 7, 70, STR_TOWN_BUILDING_NAME_HOUSES_2, 50, 3, 3, 1, 1, TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_CANDY), // 5D - MS( 0, MAX_YEAR, 15, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 75, 6, 3, 1, 2, + MS( 0, CalendarTime::MAX_YEAR, 15, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 75, 6, 3, 1, 2, TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_CANDY), // 5E - MS( 0, MAX_YEAR, 17, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 75, 6, 3, 1, 2, + MS( 0, CalendarTime::MAX_YEAR, 17, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 75, 6, 3, 1, 2, TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_CANDY), // 5F - MS( 0, MAX_YEAR, 19, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 75, 6, 3, 1, 2, + MS( 0, CalendarTime::MAX_YEAR, 19, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 75, 6, 3, 1, 2, TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_CANDY), // 60 - MS( 0, MAX_YEAR, 21, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 75, 6, 3, 1, 2, + MS( 0, CalendarTime::MAX_YEAR, 21, 80, STR_TOWN_BUILDING_NAME_HOUSES_2, 75, 6, 3, 1, 2, TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_CANDY), // 61 - MS( 0, MAX_YEAR, 75, 160, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 130, 20, 8, 4, 2, + MS( 0, CalendarTime::MAX_YEAR, 75, 160, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 130, 20, 8, 4, 2, TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_CANDY), // 62 - MS( 0, MAX_YEAR, 35, 90, STR_TOWN_BUILDING_NAME_HOUSES_2, 80, 9, 4, 1, 2, + MS( 0, CalendarTime::MAX_YEAR, 35, 90, STR_TOWN_BUILDING_NAME_HOUSES_2, 80, 9, 4, 1, 2, TILE_SIZE_1x2, HZ_TOYLND | HZ_ZON5 | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_CANDY), // 63 - MS( 0, MAX_YEAR, 0, 90, STR_TOWN_BUILDING_NAME_HOUSES_2, 80, 0, 4, 1, 2, + MS( 0, CalendarTime::MAX_YEAR, 0, 90, STR_TOWN_BUILDING_NAME_HOUSES_2, 80, 0, 4, 1, 2, TILE_NO_FLAG, HZ_NOZNS, CT_PASSENGERS, CT_MAIL, CT_CANDY), // 64 - MS( 0, MAX_YEAR, 85, 150, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 130, 18, 8, 4, 2, + MS( 0, CalendarTime::MAX_YEAR, 85, 150, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 130, 18, 8, 4, 2, TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_CANDY), // 65 - MS( 0, MAX_YEAR, 11, 60, STR_TOWN_BUILDING_NAME_IGLOO_1, 45, 3, 3, 1, 1, + MS( 0, CalendarTime::MAX_YEAR, 11, 60, STR_TOWN_BUILDING_NAME_IGLOO_1, 45, 3, 3, 1, 1, TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_CANDY), // 66 - MS( 0, MAX_YEAR, 10, 60, STR_TOWN_BUILDING_NAME_TEPEES_1, 45, 3, 3, 1, 1, + MS( 0, CalendarTime::MAX_YEAR, 10, 60, STR_TOWN_BUILDING_NAME_TEPEES_1, 45, 3, 3, 1, 1, TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_CANDY), // 67 - MS( 0, MAX_YEAR, 67, 140, STR_TOWN_BUILDING_NAME_SHOPS_AND_OFFICES_1, 130, 22, 8, 4, 4, + MS( 0, CalendarTime::MAX_YEAR, 67, 140, STR_TOWN_BUILDING_NAME_SHOPS_AND_OFFICES_1, 130, 22, 8, 4, 4, TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_FIZZY_DRINKS), // 68 - MS( 0, MAX_YEAR, 86, 145, STR_TOWN_BUILDING_NAME_SHOPS_AND_OFFICES_1, 130, 23, 8, 4, 4, + MS( 0, CalendarTime::MAX_YEAR, 86, 145, STR_TOWN_BUILDING_NAME_SHOPS_AND_OFFICES_1, 130, 23, 8, 4, 4, TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_FIZZY_DRINKS), // 69 - MS( 0, MAX_YEAR, 95, 165, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 130, 28, 8, 4, 2, + MS( 0, CalendarTime::MAX_YEAR, 95, 165, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, 130, 28, 8, 4, 2, TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_CANDY), // 6A - MS( 0, MAX_YEAR, 30, 90, STR_TOWN_BUILDING_NAME_STATUE_1, 70, 10, 4, 1, 2, + MS( 0, CalendarTime::MAX_YEAR, 30, 90, STR_TOWN_BUILDING_NAME_STATUE_1, 70, 10, 4, 1, 2, TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON5 | HZ_ZON4 | HZ_ZON3, CT_PASSENGERS, CT_MAIL, CT_CANDY), // 6B - MS( 0, MAX_YEAR, 25, 75, STR_TOWN_BUILDING_NAME_TEAPOT_HOUSE_1, 65, 8, 3, 1, 2, + MS( 0, CalendarTime::MAX_YEAR, 25, 75, STR_TOWN_BUILDING_NAME_TEAPOT_HOUSE_1, 65, 8, 3, 1, 2, TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON5 | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_CANDY), // 6C - MS( 0, MAX_YEAR, 18, 85, STR_TOWN_BUILDING_NAME_PIGGY_BANK_1, 95, 7, 3, 2, 4, + MS( 0, CalendarTime::MAX_YEAR, 18, 85, STR_TOWN_BUILDING_NAME_PIGGY_BANK_1, 95, 7, 3, 2, 4, TILE_SIZE_1x1, HZ_TOYLND | HZ_ZON5 | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1, CT_PASSENGERS, CT_MAIL, CT_FIZZY_DRINKS), // 6D 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 @@ -68,42 +68,42 @@ static const uint16_t _accum_days_for_mo * @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) +/* static */ void TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::Date date, TimerGameCalendar::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 * (static_cast(date) / (DAYS_IN_YEAR * 400 + 97)); - int rem = static_cast(date) % (DAYS_IN_YEAR * 400 + 97); + TimerGameCalendar::Year yr = 400 * (static_cast(date) / (CalendarTime::DAYS_IN_YEAR * 400 + 97)); + int rem = static_cast(date) % (CalendarTime::DAYS_IN_YEAR * 400 + 97); uint16_t x; - if (rem >= DAYS_IN_YEAR * 100 + 25) { + if (rem >= CalendarTime::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; + rem -= CalendarTime::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)); + yr += 100 * (rem / (CalendarTime::DAYS_IN_YEAR * 100 + 24)); + rem = (rem % (CalendarTime::DAYS_IN_YEAR * 100 + 24)); } - if (!TimerGameCalendar::IsLeapYear(yr) && rem >= DAYS_IN_YEAR * 4) { + if (!TimerGameCalendar::IsLeapYear(yr) && rem >= CalendarTime::DAYS_IN_YEAR * 4) { /* The first 4 year of the century are not always a leap year */ yr += 4; - rem -= DAYS_IN_YEAR * 4; + rem -= CalendarTime::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); + yr += 4 * (rem / (CalendarTime::DAYS_IN_YEAR * 4 + 1)); + rem = rem % (CalendarTime::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; + while (rem >= (TimerGameCalendar::IsLeapYear(yr) ? CalendarTime::DAYS_IN_LEAP_YEAR : CalendarTime::DAYS_IN_YEAR)) { + rem -= TimerGameCalendar::IsLeapYear(yr) ? CalendarTime::DAYS_IN_LEAP_YEAR : CalendarTime::DAYS_IN_YEAR; yr++; } @@ -131,7 +131,7 @@ static const uint16_t _accum_days_for_mo /* Account for the missing of the 29th of February in non-leap years */ if (!TimerGameCalendar::IsLeapYear(year) && days >= ACCUM_MAR) days--; - return DateAtStartOfYear(year) + days; + return TimerGameCalendar::DateAtStartOfYear(year) + days; } /** @@ -153,7 +153,7 @@ static const uint16_t _accum_days_for_mo { assert(fract < Ticks::DAY_TICKS); - YearMonthDay ymd; + TimerGameCalendar::YearMonthDay ymd; TimerGameCalendar::date = date; TimerGameCalendar::date_fract = fract; @@ -240,11 +240,11 @@ void TimerManager::El } /* check if we reached the maximum year, decrement dates by a year */ - if (TimerGameCalendar::year == MAX_YEAR + 1) { + if (TimerGameCalendar::year == CalendarTime::MAX_YEAR + 1) { int days_this_year; TimerGameCalendar::year--; - days_this_year = TimerGameCalendar::IsLeapYear(TimerGameCalendar::year) ? DAYS_IN_LEAP_YEAR : DAYS_IN_YEAR; + days_this_year = TimerGameCalendar::IsLeapYear(TimerGameCalendar::year) ? CalendarTime::DAYS_IN_LEAP_YEAR : CalendarTime::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 @@ -33,6 +33,29 @@ */ class TimerGameCalendar { public: + /** The type to store our dates in. */ + using Date = StrongType::Typedef; + + /** The fraction of a date we're in, i.e. the number of ticks since the last date changeover. */ + using DateFract = uint16_t; + + /** Type for the year, note: 0 based, i.e. starts at the year 0. */ + using Year = StrongType::Typedef; + /** Type for the month, note: 0 based, i.e. 0 = January, 11 = December. */ + using Month = uint8_t; + /** Type for the day of the month, note: 1 based, first day of a month is 1. */ + using Day = uint8_t; + + /** + * Data structure to convert between Date and triplet (year, month, and day). + * @see TimerGameCalendar::ConvertDateToYMD(), TimerGameCalendar::ConvertYMDToDate() + */ + struct YearMonthDay { + Year year; ///< Year (0...) + Month month; ///< Month (0..11) + Day day; ///< Day (1..31) + }; + enum Trigger { DAY, WEEK, @@ -77,33 +100,35 @@ public: struct TStorage { }; - /** The type to store our dates in. */ - using Date = StrongType::Typedef; - - /** The fraction of a date we're in, i.e. the number of ticks since the last date changeover. */ - using DateFract = uint16_t; - - /** Type for the year, note: 0 based, i.e. starts at the year 0. */ - using Year = StrongType::Typedef; - /** Type for the month, note: 0 based, i.e. 0 = January, 11 = December. */ - using Month = uint8_t; - /** Type for the day of the month, note: 1 based, first day of a month is 1. */ - using Day = uint8_t; + static bool IsLeapYear(Year yr); + static void ConvertDateToYMD(Date date, YearMonthDay * ymd); + static Date ConvertYMDToDate(Year year, Month month, Day day); + static void SetDate(Date date, DateFract fract); /** - * 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) - }; + * Calculate the year of a given date. + * @param date The date to consider. + * @return the year. + */ + static constexpr Year DateToYear(Date date) + { + /* Hardcode the number of days in a year because we can't access CalendarTime from here. */ + return static_cast(date) / 366; + } - 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); + /** + * Calculate the date of the first day of a given year. + * @param year the year to get the first day of. + * @return the date. + */ + static constexpr Date DateAtStartOfYear(Year year) + { + int32_t year_as_int = static_cast(year); + uint number_of_leap_years = (year == 0) ? 0 : ((year_as_int - 1) / 4 - (year_as_int - 1) / 100 + (year_as_int - 1) / 400 + 1); + + /* Hardcode the number of days in a year because we can't access CalendarTime from here. */ + return (365 * year_as_int) + number_of_leap_years; + } static Year year; ///< Current year, starting at 0. static Month month; ///< Current month (0..11). @@ -111,4 +136,53 @@ public: static DateFract date_fract; ///< Fractional part of the day. }; +/** + * Storage class for Calendar time constants. + */ +class CalendarTime { +public: + static constexpr int DAYS_IN_YEAR = 365; ///< days per year + static constexpr int DAYS_IN_LEAP_YEAR = 366; ///< sometimes, you need one day more... + static constexpr int MONTHS_IN_YEAR = 12; ///< months per year + + static constexpr int SECONDS_PER_DAY = 2; ///< approximate seconds per day, not for precise calculations + + /* + * ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR and DAYS_TILL_ORIGINAL_BASE_YEAR are + * primarily used for loading newgrf and savegame data and returning some + * newgrf (callback) functions that were in the original (TTD) inherited + * format, where 'TimerGameCalendar::date == 0' meant that it was 1920-01-01. + */ + + /** The minimum starting year/base year of the original TTD */ + static constexpr TimerGameCalendar::Year ORIGINAL_BASE_YEAR = 1920; + /** The original ending year */ + static constexpr TimerGameCalendar::Year ORIGINAL_END_YEAR = 2051; + /** The maximum year of the original TTD */ + static constexpr TimerGameCalendar::Year ORIGINAL_MAX_YEAR = 2090; + + /** The absolute minimum & maximum years in OTTD */ + static constexpr TimerGameCalendar::Year MIN_YEAR = 0; + + /** The default starting year */ + static constexpr TimerGameCalendar::Year DEF_START_YEAR = 1950; + /** The default scoring end year */ + static constexpr TimerGameCalendar::Year DEF_END_YEAR = ORIGINAL_END_YEAR - 1; + + /** + * MAX_YEAR, nicely rounded value of the number of years that can + * be encoded in a single 32 bits date, about 2^31 / 366 years. + */ + static constexpr TimerGameCalendar::Year MAX_YEAR = 5000000; + + /** The date of the first day of the original base year. */ + static constexpr TimerGameCalendar::Date DAYS_TILL_ORIGINAL_BASE_YEAR = TimerGameCalendar::DateAtStartOfYear(ORIGINAL_BASE_YEAR); + + /** The date of the last day of the max year. */ + static constexpr TimerGameCalendar::Date MAX_DATE = TimerGameCalendar::DateAtStartOfYear(CalendarTime::MAX_YEAR + 1) - 1; + + static constexpr TimerGameCalendar::Year INVALID_YEAR = -1; ///< Representation of an invalid year + static constexpr TimerGameCalendar::Date INVALID_DATE = -1; ///< Representation of an invalid date +}; + #endif /* TIMER_GAME_CALENDAR_H */ diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -304,11 +304,11 @@ CommandCost CmdSetTimetableStart(DoComma int total_duration = v->orders->GetTimetableTotalDuration(); /* Don't let a timetable start more than 15 years into the future or 1 year in the past. */ - if (start_date < 0 || start_date > MAX_DATE) return CMD_ERROR; - if (start_date - TimerGameCalendar::date > DateAtStartOfYear(MAX_TIMETABLE_START_YEARS)) return CMD_ERROR; - if (TimerGameCalendar::date - start_date > DAYS_IN_LEAP_YEAR) return CMD_ERROR; + if (start_date < 0 || start_date > CalendarTime::MAX_DATE) return CMD_ERROR; + if (start_date - TimerGameCalendar::date > TimerGameCalendar::DateAtStartOfYear(MAX_TIMETABLE_START_YEARS)) return CMD_ERROR; + if (TimerGameCalendar::date - start_date > CalendarTime::DAYS_IN_LEAP_YEAR) return CMD_ERROR; if (timetable_all && !v->orders->IsCompleteTimetable()) return CommandCost(STR_ERROR_TIMETABLE_INCOMPLETE); - if (timetable_all && start_date + total_duration / Ticks::DAY_TICKS > MAX_DATE) return CMD_ERROR; + if (timetable_all && start_date + total_duration / Ticks::DAY_TICKS > CalendarTime::MAX_DATE) return CMD_ERROR; if (flags & DC_EXEC) { std::vector vehs; @@ -494,7 +494,7 @@ void UpdateVehicleTimetable(Vehicle *v, * check how many ticks the (fully filled) timetable has. If a timetable cycle is * shorter than the amount of ticks we are late we reduce the lateness by the * length of a full cycle till lateness is less than the length of a timetable - * cycle. When the timetable isn't fully filled the cycle will be Tick::INVALID_TICKS. */ + * cycle. When the timetable isn't fully filled the cycle will be Ticks::INVALID_TICKS. */ if (v->lateness_counter > (int)timetabled) { TimerGameTick::Ticks cycle = v->orders->GetTimetableTotalDuration(); if (cycle != Ticks::INVALID_TICKS && v->lateness_counter > cycle) { diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -194,7 +194,7 @@ struct TimetableWindow : Window { { switch (widget) { case WID_VT_ARRIVAL_DEPARTURE_PANEL: - SetDParamMaxValue(1, DateAtStartOfYear(MAX_YEAR), 0, FS_SMALL); + SetDParamMaxValue(1, TimerGameCalendar::DateAtStartOfYear(CalendarTime::MAX_YEAR), 0, FS_SMALL); size->width = std::max(GetStringBoundingBox(STR_TIMETABLE_ARRIVAL).width, GetStringBoundingBox(STR_TIMETABLE_DEPARTURE).width) + WidgetDimensions::scaled.hsep_wide + padding.width; FALLTHROUGH; diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -1148,7 +1148,7 @@ void ToggleDirtyBlocks() */ void SetStartingYear(TimerGameCalendar::Year year) { - _settings_game.game_creation.starting_year = Clamp(year, MIN_YEAR, MAX_YEAR); + _settings_game.game_creation.starting_year = Clamp(year, CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR); 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); @@ -2357,8 +2357,8 @@ struct ScenarioEditorToolbarWindow : Win void OnPaint() override { - this->SetWidgetDisabledState(WID_TE_DATE_BACKWARD, _settings_game.game_creation.starting_year <= MIN_YEAR); - this->SetWidgetDisabledState(WID_TE_DATE_FORWARD, _settings_game.game_creation.starting_year >= MAX_YEAR); + this->SetWidgetDisabledState(WID_TE_DATE_BACKWARD, _settings_game.game_creation.starting_year <= CalendarTime::MIN_YEAR); + this->SetWidgetDisabledState(WID_TE_DATE_FORWARD, _settings_game.game_creation.starting_year >= CalendarTime::MAX_YEAR); this->SetWidgetDisabledState(WID_TE_ROADS, (GetRoadTypes(true) & ~_roadtypes_type) == ROADTYPES_NONE); this->SetWidgetDisabledState(WID_TE_TRAMS, (GetRoadTypes(true) & _roadtypes_type) == ROADTYPES_NONE); @@ -2398,7 +2398,7 @@ struct ScenarioEditorToolbarWindow : Win break; case WID_TE_DATE: - SetDParam(0, TimerGameCalendar::ConvertYMDToDate(MAX_YEAR, 0, 1)); + SetDParam(0, TimerGameCalendar::ConvertYMDToDate(CalendarTime::MAX_YEAR, 0, 1)); *size = GetStringBoundingBox(STR_JUST_DATE_LONG); break; } @@ -2512,7 +2512,7 @@ struct ScenarioEditorToolbarWindow : Win value = atoi(str); } else { /* An empty string means revert to the default */ - value = static_cast(DEF_START_YEAR); + value = static_cast(CalendarTime::DEF_START_YEAR); } SetStartingYear(value); diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -871,7 +871,7 @@ RoadType GetTownRoadType(const Town *t) if (!HasBit(rti->flags, ROTF_TOWN_BUILD)) continue; /* Not yet introduced at this date. */ - if (IsInsideMM(rti->introduction_date, 0, static_cast(MAX_DATE)) && rti->introduction_date > TimerGameCalendar::date) continue; + if (IsInsideMM(rti->introduction_date, 0, static_cast(CalendarTime::MAX_DATE)) && rti->introduction_date > TimerGameCalendar::date) continue; if (best != nullptr) { if ((rti->max_speed == 0 ? assume_max_speed : rti->max_speed) < (best->max_speed == 0 ? assume_max_speed : best->max_speed)) continue; diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -4179,7 +4179,7 @@ void Train::OnNewDay() if (this->running_ticks != 0) { /* running costs */ - CommandCost cost(EXPENSES_TRAIN_RUN, this->GetRunningCost() * this->running_ticks / (DAYS_IN_YEAR * Ticks::DAY_TICKS)); + CommandCost cost(EXPENSES_TRAIN_RUN, this->GetRunningCost() * this->running_ticks / (CalendarTime::DAYS_IN_YEAR * Ticks::DAY_TICKS)); this->profit_this_year -= cost.GetCost(); this->running_ticks = 0; diff --git a/src/vehicle.cpp b/src/vehicle.cpp --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1369,7 +1369,7 @@ bool Vehicle::HandleBreakdown() */ void AgeVehicle(Vehicle *v) { - if (v->age < MAX_DATE) { + if (v->age < CalendarTime::MAX_DATE) { v->age++; if (v->IsPrimaryVehicle() && v->age == VEHICLE_PROFIT_MIN_AGE + 1) GroupStatistics::VehicleReachedMinAge(v); } @@ -1378,7 +1378,7 @@ void AgeVehicle(Vehicle *v) auto age = v->age - v->max_age; for (int32_t i = 0; i <= 4; i++) { - if (age == DateAtStartOfYear(i)) { + if (age == TimerGameCalendar::DateAtStartOfYear(i)) { v->reliability_spd_dec <<= 1; break; } @@ -1396,11 +1396,11 @@ void AgeVehicle(Vehicle *v) if (EngineHasReplacementForCompany(c, v->engine_type, v->group_id)) return; StringID str; - if (age == DateAtStartOfYear(-1)) { + if (age == TimerGameCalendar::DateAtStartOfYear(-1)) { str = STR_NEWS_VEHICLE_IS_GETTING_OLD; - } else if (age == DateAtStartOfYear(0)) { + } else if (age == TimerGameCalendar::DateAtStartOfYear(0)) { str = STR_NEWS_VEHICLE_IS_GETTING_VERY_OLD; - } else if (age > DateAtStartOfYear(0) && (static_cast(age) % DAYS_IN_LEAP_YEAR) == 0) { + } else if (age > TimerGameCalendar::DateAtStartOfYear(0) && (static_cast(age) % CalendarTime::DAYS_IN_LEAP_YEAR) == 0) { str = STR_NEWS_VEHICLE_IS_GETTING_VERY_OLD_AND; } else { return; diff --git a/src/vehicle_func.h b/src/vehicle_func.h --- a/src/vehicle_func.h +++ b/src/vehicle_func.h @@ -25,7 +25,7 @@ #define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD) #define IS_CUSTOM_SECONDHEAD_SPRITE(x) (x == 0xFE) -static const int VEHICLE_PROFIT_MIN_AGE = DAYS_IN_YEAR * 2; ///< Only vehicles older than this have a meaningful profit. +static const int VEHICLE_PROFIT_MIN_AGE = CalendarTime::DAYS_IN_YEAR * 2; ///< Only vehicles older than this have a meaningful profit. static const Money VEHICLE_PROFIT_THRESHOLD = 10000; ///< Threshold for a vehicle to be considered making good profit. /** diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1733,7 +1733,7 @@ void BaseVehicleListWindow::DrawVehicleL if (v->IsChainInDepot()) { tc = TC_BLUE; } else { - tc = (v->age > v->max_age - DAYS_IN_LEAP_YEAR) ? TC_RED : TC_BLACK; + tc = (v->age > v->max_age - CalendarTime::DAYS_IN_LEAP_YEAR) ? TC_RED : TC_BLACK; } SetDParam(0, v->unitnumber); @@ -2438,7 +2438,7 @@ struct VehicleDetailsWindow : Window { case WID_VD_SERVICING_INTERVAL: SetDParamMaxValue(0, MAX_SERVINT_DAYS); // Roughly the maximum interval - SetDParamMaxValue(1, DateAtStartOfYear(MAX_YEAR)); // Roughly the maximum year + SetDParamMaxValue(1, TimerGameCalendar::DateAtStartOfYear(CalendarTime::MAX_YEAR)); // Roughly the maximum year size->width = std::max( GetStringBoundingBox(STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT).width, GetStringBoundingBox(STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS).width @@ -2495,9 +2495,9 @@ struct VehicleDetailsWindow : Window { Rect tr = r.Shrink(WidgetDimensions::scaled.framerect); /* Draw running cost */ - SetDParam(1, DateToYear(v->age)); - SetDParam(0, (v->age + DAYS_IN_YEAR < v->max_age) ? STR_VEHICLE_INFO_AGE : STR_VEHICLE_INFO_AGE_RED); - SetDParam(2, DateToYear(v->max_age)); + SetDParam(1, TimerGameCalendar::DateToYear(v->age)); + SetDParam(0, (v->age + CalendarTime::DAYS_IN_YEAR < v->max_age) ? STR_VEHICLE_INFO_AGE : STR_VEHICLE_INFO_AGE_RED); + SetDParam(2, TimerGameCalendar::DateToYear(v->max_age)); SetDParam(3, v->GetDisplayRunningCost()); DrawString(tr, STR_VEHICLE_INFO_AGE_RUNNING_COST_YR); tr.top += FONT_HEIGHT_NORMAL;