From b959be98a35dd26c9d4c1e632b5dafcfacf2a2ec Mon Sep 17 00:00:00 2001 From: Tyler Trahan Date: Thu, 14 Dec 2023 17:21:57 -0500 Subject: [PATCH] Codechange: Split calls to ScriptDate into correct Calendar and Economy class --- src/script/api/script_basestation.cpp | 6 +++--- src/script/api/script_basestation.hpp | 6 +++--- src/script/api/script_client.cpp | 6 +++--- src/script/api/script_client.hpp | 6 +++--- src/script/api/script_engine.cpp | 6 +++--- src/script/api/script_engine.hpp | 4 ++-- src/script/api/script_industry.cpp | 16 ++++++++-------- src/script/api/script_industry.hpp | 13 +++++++------ src/script/api/script_story_page.cpp | 10 +++++----- src/script/api/script_story_page.hpp | 12 ++++++------ src/script/api/script_subsidy.cpp | 12 ++++++------ src/script/api/script_subsidy.hpp | 8 ++++---- 12 files changed, 53 insertions(+), 52 deletions(-) diff --git a/src/script/api/script_basestation.cpp b/src/script/api/script_basestation.cpp index 2dc0ce6c81..c3cf5b234c 100644 --- a/src/script/api/script_basestation.cpp +++ b/src/script/api/script_basestation.cpp @@ -59,9 +59,9 @@ return ::BaseStation::Get(station_id)->xy; } -/* static */ ScriptDate::Date ScriptBaseStation::GetConstructionDate(StationID station_id) +/* static */ ScriptDateCalendar::Date ScriptBaseStation::GetConstructionDate(StationID station_id) { - if (!IsValidBaseStation(station_id)) return ScriptDate::DATE_INVALID; + if (!IsValidBaseStation(station_id)) return ScriptDateCalendar::DATE_INVALID; - return (ScriptDate::Date)::BaseStation::Get(station_id)->build_date.base(); + return (ScriptDateCalendar::Date)::BaseStation::Get(station_id)->build_date.base(); } diff --git a/src/script/api/script_basestation.hpp b/src/script/api/script_basestation.hpp index 52df57f78c..73ad334dae 100644 --- a/src/script/api/script_basestation.hpp +++ b/src/script/api/script_basestation.hpp @@ -11,7 +11,7 @@ #define SCRIPT_BASESTATION_HPP #include "script_text.hpp" -#include "script_date.hpp" +#include "script_date_calendar.hpp" /** * Base class for stations and waypoints. @@ -68,11 +68,11 @@ public: static TileIndex GetLocation(StationID station_id); /** - * Get the last date a station part was added to this station. + * Get the last calendar date a station part was added to this station. * @param station_id The station to look at. * @return The last date some part of this station was build. */ - static ScriptDate::Date GetConstructionDate(StationID station_id); + static ScriptDateCalendar::Date GetConstructionDate(StationID station_id); }; #endif /* SCRIPT_BASESTATION_HPP */ diff --git a/src/script/api/script_client.cpp b/src/script/api/script_client.cpp index 9b65f638db..b1ab9fbd00 100644 --- a/src/script/api/script_client.cpp +++ b/src/script/api/script_client.cpp @@ -46,9 +46,9 @@ static NetworkClientInfo *FindClientInfo(ScriptClient::ClientID client) return (ScriptCompany::CompanyID)ci->client_playas; } -/* static */ ScriptDate::Date ScriptClient::GetJoinDate(ScriptClient::ClientID client) +/* static */ ScriptDateCalendar::Date ScriptClient::GetJoinDate(ScriptClient::ClientID client) { NetworkClientInfo *ci = FindClientInfo(client); - if (ci == nullptr) return ScriptDate::DATE_INVALID; - return (ScriptDate::Date)ci->join_date.base(); + if (ci == nullptr) return ScriptDateCalendar::DATE_INVALID; + return (ScriptDateCalendar::Date)ci->join_date.base(); } diff --git a/src/script/api/script_client.hpp b/src/script/api/script_client.hpp index 7b5d6f5dc3..0708affb1f 100644 --- a/src/script/api/script_client.hpp +++ b/src/script/api/script_client.hpp @@ -11,7 +11,7 @@ #define SCRIPT_CLIENT_HPP #include "script_text.hpp" -#include "script_date.hpp" +#include "script_date_calendar.hpp" #include "script_company.hpp" #include "../../network/network_type.h" @@ -56,12 +56,12 @@ public: static ScriptCompany::CompanyID GetCompany(ClientID client); /** - * Get the game date when the given client has joined. + * Get the game calendar date when the given client has joined. * @param client The client to get joining date for. * @pre ResolveClientID(client) != CLIENT_INVALID. * @return The date when client has joined. */ - static ScriptDate::Date GetJoinDate(ClientID client); + static ScriptDateCalendar::Date GetJoinDate(ClientID client); }; diff --git a/src/script/api/script_engine.cpp b/src/script/api/script_engine.cpp index 6475e9d003..2ddadc5a40 100644 --- a/src/script/api/script_engine.cpp +++ b/src/script/api/script_engine.cpp @@ -168,11 +168,11 @@ return ::Engine::Get(engine_id)->GetDisplayMaxTractiveEffort() / 1000; } -/* static */ ScriptDate::Date ScriptEngine::GetDesignDate(EngineID engine_id) +/* static */ ScriptDateCalendar::Date ScriptEngine::GetDesignDate(EngineID engine_id) { - if (!IsValidEngine(engine_id)) return ScriptDate::DATE_INVALID; + if (!IsValidEngine(engine_id)) return ScriptDateCalendar::DATE_INVALID; - return (ScriptDate::Date)::Engine::Get(engine_id)->intro_date.base(); + return (ScriptDateCalendar::Date)::Engine::Get(engine_id)->intro_date.base(); } /* static */ ScriptVehicle::VehicleType ScriptEngine::GetVehicleType(EngineID engine_id) diff --git a/src/script/api/script_engine.hpp b/src/script/api/script_engine.hpp index 2baed5bec3..23c1312420 100644 --- a/src/script/api/script_engine.hpp +++ b/src/script/api/script_engine.hpp @@ -13,7 +13,7 @@ #include "script_vehicle.hpp" #include "script_rail.hpp" #include "script_airport.hpp" -#include "script_date.hpp" +#include "script_date_calendar.hpp" /** * Class that handles all engine related functions. @@ -172,7 +172,7 @@ public: * @pre IsValidEngine(engine_id). * @return The date this engine was designed. */ - static ScriptDate::Date GetDesignDate(EngineID engine_id); + static ScriptDateCalendar::Date GetDesignDate(EngineID engine_id); /** * Get the type of an engine. diff --git a/src/script/api/script_industry.cpp b/src/script/api/script_industry.cpp index 86f5a85e40..6d7237964e 100644 --- a/src/script/api/script_industry.cpp +++ b/src/script/api/script_industry.cpp @@ -49,11 +49,11 @@ return GetString(STR_INDUSTRY_NAME); } -/* static */ ScriptDate::Date ScriptIndustry::GetConstructionDate(IndustryID industry_id) +/* static */ ScriptDateCalendar::Date ScriptIndustry::GetConstructionDate(IndustryID industry_id) { Industry *i = Industry::GetIfValid(industry_id); - if (i == nullptr) return ScriptDate::DATE_INVALID; - return (ScriptDate::Date)i->construction_date.base(); + if (i == nullptr) return ScriptDateCalendar::DATE_INVALID; + return (ScriptDateCalendar::Date)i->construction_date.base(); } /* static */ bool ScriptIndustry::SetText(IndustryID industry_id, Text *text) @@ -225,18 +225,18 @@ return i->last_prod_year.base(); } -/* static */ ScriptDate::Date ScriptIndustry::GetCargoLastAcceptedDate(IndustryID industry_id, CargoID cargo_type) +/* static */ ScriptDateEconomy::Date ScriptIndustry::GetCargoLastAcceptedDate(IndustryID industry_id, CargoID cargo_type) { Industry *i = Industry::GetIfValid(industry_id); - if (i == nullptr) return ScriptDate::DATE_INVALID; + if (i == nullptr) return ScriptDateEconomy::DATE_INVALID; if (!::IsValidCargoID(cargo_type)) { auto it = std::max_element(std::begin(i->accepted), std::end(i->accepted), [](const auto &a, const auto &b) { return a.last_accepted < b.last_accepted; }); - return (ScriptDate::Date)it->last_accepted.base(); + return (ScriptDateEconomy::Date)it->last_accepted.base(); } else { auto it = i->GetCargoAccepted(cargo_type); - if (it == std::end(i->accepted)) return ScriptDate::DATE_INVALID; - return (ScriptDate::Date)it->last_accepted.base(); + if (it == std::end(i->accepted)) return ScriptDateEconomy::DATE_INVALID; + return (ScriptDateEconomy::Date)it->last_accepted.base(); } } diff --git a/src/script/api/script_industry.hpp b/src/script/api/script_industry.hpp index bedb3504d1..20872f6eef 100644 --- a/src/script/api/script_industry.hpp +++ b/src/script/api/script_industry.hpp @@ -11,7 +11,8 @@ #define SCRIPT_INDUSTRY_HPP #include "script_company.hpp" -#include "script_date.hpp" +#include "script_date_economy.hpp" +#include "script_date_calendar.hpp" #include "script_object.hpp" #include "../../industry.h" @@ -86,13 +87,13 @@ public: static std::optional GetName(IndustryID industry_id); /** - * Get the construction date of an industry. + * Get the construction calendar date of an industry. * @param industry_id The index of the industry. * @pre IsValidIndustry(industry_id). * @return Date the industry was constructed. * @api -ai */ - static ScriptDate::Date GetConstructionDate(IndustryID industry_id); + static ScriptDateCalendar::Date GetConstructionDate(IndustryID industry_id); /** * Set the custom text of an industry, shown in the GUI. @@ -255,15 +256,15 @@ public: static SQInteger GetLastProductionYear(IndustryID industry_id); /** - * Get the last date this industry accepted any cargo delivery. + * Get the last economy date this industry accepted any cargo delivery. * @param industry_id The index of the industry. * @param cargo_type The cargo to query, or CT_INVALID to query latest of all accepted cargoes. * @pre IsValidIndustry(industry_id). * @pre IsValidCargo(cargo_type) || cargo_type == CT_INVALID. - * @return Date the industry last received cargo from a delivery, or ScriptDate::DATE_INVALID on error. + * @return Date the industry last received cargo from a delivery, or ScriptDateEconomy::DATE_INVALID on error. * @api -ai */ - static ScriptDate::Date GetCargoLastAcceptedDate(IndustryID industry_id, CargoID cargo_type); + static ScriptDateEconomy::Date GetCargoLastAcceptedDate(IndustryID industry_id, CargoID cargo_type); /** * Get the current control flags for an industry. diff --git a/src/script/api/script_story_page.cpp b/src/script/api/script_story_page.cpp index 87a46427eb..2a97189638 100644 --- a/src/script/api/script_story_page.cpp +++ b/src/script/api/script_story_page.cpp @@ -177,15 +177,15 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type) return company; } -/* static */ ScriptDate::Date ScriptStoryPage::GetDate(StoryPageID story_page_id) +/* static */ ScriptDateCalendar::Date ScriptStoryPage::GetDate(StoryPageID story_page_id) { - EnforcePrecondition(ScriptDate::DATE_INVALID, IsValidStoryPage(story_page_id)); - EnforceDeityMode(ScriptDate::DATE_INVALID); + EnforcePrecondition(ScriptDateCalendar::DATE_INVALID, IsValidStoryPage(story_page_id)); + EnforceDeityMode(ScriptDateCalendar::DATE_INVALID); - return (ScriptDate::Date)StoryPage::Get(story_page_id)->date.base(); + return (ScriptDateCalendar::Date)StoryPage::Get(story_page_id)->date.base(); } -/* static */ bool ScriptStoryPage::SetDate(StoryPageID story_page_id, ScriptDate::Date date) +/* static */ bool ScriptStoryPage::SetDate(StoryPageID story_page_id, ScriptDateCalendar::Date date) { EnforcePrecondition(false, IsValidStoryPage(story_page_id)); EnforceDeityMode(false); diff --git a/src/script/api/script_story_page.hpp b/src/script/api/script_story_page.hpp index c51c4c9363..ae822fb023 100644 --- a/src/script/api/script_story_page.hpp +++ b/src/script/api/script_story_page.hpp @@ -11,7 +11,7 @@ #define SCRIPT_STORY_HPP #include "script_company.hpp" -#include "script_date.hpp" +#include "script_date_calendar.hpp" #include "script_vehicle.hpp" #include "../../story_type.h" #include "../../story_base.h" @@ -255,22 +255,22 @@ public: static ScriptCompany::CompanyID GetCompany(StoryPageID story_page_id); /** - * Get the page date which is displayed at the top of each page. + * Get the page calendar date which is displayed at the top of each page. * @param story_page_id The story page to get the date of. * @return The date * @pre IsValidStoryPage(story_page_id). */ - static ScriptDate::Date GetDate(StoryPageID story_page_id); + static ScriptDateCalendar::Date GetDate(StoryPageID story_page_id); /** - * Update date of a story page. The date is shown in the top left of the page + * Update calendar date of a story page. The date is shown in the top left of the page * @param story_page_id The story page to set the date for. - * @param date Date to display at the top of story page or ScriptDate::DATE_INVALID to disable showing date on this page. (also, @see ScriptDate) + * @param date Date to display at the top of story page or ScriptDateCalendar::DATE_INVALID to disable showing date on this page. (also, @see ScriptDateCalendar) * @return True if the action succeeded. * @pre ScriptCompanyMode::IsDeity(). * @pre IsValidStoryPage(story_page_id). */ - static bool SetDate(StoryPageID story_page_id, ScriptDate::Date date); + static bool SetDate(StoryPageID story_page_id, ScriptDateCalendar::Date date); /** * Update title of a story page. The title is shown in the page selector drop down. diff --git a/src/script/api/script_subsidy.cpp b/src/script/api/script_subsidy.cpp index afc6eef14b..966b65eab1 100644 --- a/src/script/api/script_subsidy.cpp +++ b/src/script/api/script_subsidy.cpp @@ -9,7 +9,7 @@ #include "../../stdafx.h" #include "script_subsidy.hpp" -#include "script_date.hpp" +#include "script_date_economy.hpp" #include "script_industry.hpp" #include "script_town.hpp" #include "script_error.hpp" @@ -50,19 +50,19 @@ return (ScriptCompany::CompanyID)((byte)::Subsidy::Get(subsidy_id)->awarded); } -/* static */ ScriptDate::Date ScriptSubsidy::GetExpireDate(SubsidyID subsidy_id) +/* static */ ScriptDateEconomy::Date ScriptSubsidy::GetExpireDate(SubsidyID subsidy_id) { - if (!IsValidSubsidy(subsidy_id)) return ScriptDate::DATE_INVALID; + if (!IsValidSubsidy(subsidy_id)) return ScriptDateEconomy::DATE_INVALID; - int year = ScriptDate::GetYear(ScriptDate::GetCurrentDate()); - int month = ScriptDate::GetMonth(ScriptDate::GetCurrentDate()); + int year = ScriptDateEconomy::GetYear(ScriptDateEconomy::GetCurrentDate()); + int month = ScriptDateEconomy::GetMonth(ScriptDateEconomy::GetCurrentDate()); month += ::Subsidy::Get(subsidy_id)->remaining; year += (month - 1) / 12; month = ((month - 1) % 12) + 1; - return ScriptDate::GetDate(year, month, 1); + return ScriptDateEconomy::GetDate(year, month, 1); } /* static */ CargoID ScriptSubsidy::GetCargoType(SubsidyID subsidy_id) diff --git a/src/script/api/script_subsidy.hpp b/src/script/api/script_subsidy.hpp index 5bfcf1c9a2..c51f8eb4ee 100644 --- a/src/script/api/script_subsidy.hpp +++ b/src/script/api/script_subsidy.hpp @@ -11,7 +11,7 @@ #define SCRIPT_SUBSIDY_HPP #include "script_company.hpp" -#include "script_date.hpp" +#include "script_date_economy.hpp" /** * Class that handles all subsidy related functions. @@ -74,8 +74,8 @@ public: static ScriptCompany::CompanyID GetAwardedTo(SubsidyID subsidy_id); /** - * Get the date this subsidy expires. In case the subsidy is already - * awarded, return the date the subsidy expires, else, return the date the + * Get the economy date this subsidy expires. In case the subsidy is already + * awarded, return the economy date the subsidy expires, else, return the economy date the * offer expires. * @param subsidy_id The SubsidyID to check. * @pre IsValidSubsidy(subsidy_id). @@ -83,7 +83,7 @@ public: * @note The return value of this function will change if the subsidy is * awarded. */ - static ScriptDate::Date GetExpireDate(SubsidyID subsidy_id); + static ScriptDateEconomy::Date GetExpireDate(SubsidyID subsidy_id); /** * Get the cargo type that has to be transported in order to be awarded this