1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-29 17:39:09 +00:00

Codechange: Split calls to ScriptDate into correct Calendar and Economy class

This commit is contained in:
Tyler Trahan
2023-12-14 17:21:57 -05:00
parent f9d04e9358
commit b959be98a3
12 changed files with 53 additions and 52 deletions

View File

@@ -59,9 +59,9 @@
return ::BaseStation::Get(station_id)->xy; 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();
} }

View File

@@ -11,7 +11,7 @@
#define SCRIPT_BASESTATION_HPP #define SCRIPT_BASESTATION_HPP
#include "script_text.hpp" #include "script_text.hpp"
#include "script_date.hpp" #include "script_date_calendar.hpp"
/** /**
* Base class for stations and waypoints. * Base class for stations and waypoints.
@@ -68,11 +68,11 @@ public:
static TileIndex GetLocation(StationID station_id); 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. * @param station_id The station to look at.
* @return The last date some part of this station was build. * @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 */ #endif /* SCRIPT_BASESTATION_HPP */

View File

@@ -46,9 +46,9 @@ static NetworkClientInfo *FindClientInfo(ScriptClient::ClientID client)
return (ScriptCompany::CompanyID)ci->client_playas; 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); NetworkClientInfo *ci = FindClientInfo(client);
if (ci == nullptr) return ScriptDate::DATE_INVALID; if (ci == nullptr) return ScriptDateCalendar::DATE_INVALID;
return (ScriptDate::Date)ci->join_date.base(); return (ScriptDateCalendar::Date)ci->join_date.base();
} }

View File

@@ -11,7 +11,7 @@
#define SCRIPT_CLIENT_HPP #define SCRIPT_CLIENT_HPP
#include "script_text.hpp" #include "script_text.hpp"
#include "script_date.hpp" #include "script_date_calendar.hpp"
#include "script_company.hpp" #include "script_company.hpp"
#include "../../network/network_type.h" #include "../../network/network_type.h"
@@ -56,12 +56,12 @@ public:
static ScriptCompany::CompanyID GetCompany(ClientID client); 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. * @param client The client to get joining date for.
* @pre ResolveClientID(client) != CLIENT_INVALID. * @pre ResolveClientID(client) != CLIENT_INVALID.
* @return The date when client has joined. * @return The date when client has joined.
*/ */
static ScriptDate::Date GetJoinDate(ClientID client); static ScriptDateCalendar::Date GetJoinDate(ClientID client);
}; };

View File

@@ -168,11 +168,11 @@
return ::Engine::Get(engine_id)->GetDisplayMaxTractiveEffort() / 1000; 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) /* static */ ScriptVehicle::VehicleType ScriptEngine::GetVehicleType(EngineID engine_id)

View File

@@ -13,7 +13,7 @@
#include "script_vehicle.hpp" #include "script_vehicle.hpp"
#include "script_rail.hpp" #include "script_rail.hpp"
#include "script_airport.hpp" #include "script_airport.hpp"
#include "script_date.hpp" #include "script_date_calendar.hpp"
/** /**
* Class that handles all engine related functions. * Class that handles all engine related functions.
@@ -172,7 +172,7 @@ public:
* @pre IsValidEngine(engine_id). * @pre IsValidEngine(engine_id).
* @return The date this engine was designed. * @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. * Get the type of an engine.

View File

@@ -49,11 +49,11 @@
return GetString(STR_INDUSTRY_NAME); 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); Industry *i = Industry::GetIfValid(industry_id);
if (i == nullptr) return ScriptDate::DATE_INVALID; if (i == nullptr) return ScriptDateCalendar::DATE_INVALID;
return (ScriptDate::Date)i->construction_date.base(); return (ScriptDateCalendar::Date)i->construction_date.base();
} }
/* static */ bool ScriptIndustry::SetText(IndustryID industry_id, Text *text) /* static */ bool ScriptIndustry::SetText(IndustryID industry_id, Text *text)
@@ -225,18 +225,18 @@
return i->last_prod_year.base(); 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); Industry *i = Industry::GetIfValid(industry_id);
if (i == nullptr) return ScriptDate::DATE_INVALID; if (i == nullptr) return ScriptDateEconomy::DATE_INVALID;
if (!::IsValidCargoID(cargo_type)) { 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; }); 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 { } else {
auto it = i->GetCargoAccepted(cargo_type); auto it = i->GetCargoAccepted(cargo_type);
if (it == std::end(i->accepted)) return ScriptDate::DATE_INVALID; if (it == std::end(i->accepted)) return ScriptDateEconomy::DATE_INVALID;
return (ScriptDate::Date)it->last_accepted.base(); return (ScriptDateEconomy::Date)it->last_accepted.base();
} }
} }

View File

@@ -11,7 +11,8 @@
#define SCRIPT_INDUSTRY_HPP #define SCRIPT_INDUSTRY_HPP
#include "script_company.hpp" #include "script_company.hpp"
#include "script_date.hpp" #include "script_date_economy.hpp"
#include "script_date_calendar.hpp"
#include "script_object.hpp" #include "script_object.hpp"
#include "../../industry.h" #include "../../industry.h"
@@ -86,13 +87,13 @@ public:
static std::optional<std::string> GetName(IndustryID industry_id); static std::optional<std::string> 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. * @param industry_id The index of the industry.
* @pre IsValidIndustry(industry_id). * @pre IsValidIndustry(industry_id).
* @return Date the industry was constructed. * @return Date the industry was constructed.
* @api -ai * @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. * Set the custom text of an industry, shown in the GUI.
@@ -255,15 +256,15 @@ public:
static SQInteger GetLastProductionYear(IndustryID industry_id); 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 industry_id The index of the industry.
* @param cargo_type The cargo to query, or CT_INVALID to query latest of all accepted cargoes. * @param cargo_type The cargo to query, or CT_INVALID to query latest of all accepted cargoes.
* @pre IsValidIndustry(industry_id). * @pre IsValidIndustry(industry_id).
* @pre IsValidCargo(cargo_type) || cargo_type == CT_INVALID. * @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 * @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. * Get the current control flags for an industry.

View File

@@ -177,15 +177,15 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
return company; 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)); EnforcePrecondition(ScriptDateCalendar::DATE_INVALID, IsValidStoryPage(story_page_id));
EnforceDeityMode(ScriptDate::DATE_INVALID); 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)); EnforcePrecondition(false, IsValidStoryPage(story_page_id));
EnforceDeityMode(false); EnforceDeityMode(false);

View File

@@ -11,7 +11,7 @@
#define SCRIPT_STORY_HPP #define SCRIPT_STORY_HPP
#include "script_company.hpp" #include "script_company.hpp"
#include "script_date.hpp" #include "script_date_calendar.hpp"
#include "script_vehicle.hpp" #include "script_vehicle.hpp"
#include "../../story_type.h" #include "../../story_type.h"
#include "../../story_base.h" #include "../../story_base.h"
@@ -255,22 +255,22 @@ public:
static ScriptCompany::CompanyID GetCompany(StoryPageID story_page_id); 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. * @param story_page_id The story page to get the date of.
* @return The date * @return The date
* @pre IsValidStoryPage(story_page_id). * @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 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. * @return True if the action succeeded.
* @pre ScriptCompanyMode::IsDeity(). * @pre ScriptCompanyMode::IsDeity().
* @pre IsValidStoryPage(story_page_id). * @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. * Update title of a story page. The title is shown in the page selector drop down.

View File

@@ -9,7 +9,7 @@
#include "../../stdafx.h" #include "../../stdafx.h"
#include "script_subsidy.hpp" #include "script_subsidy.hpp"
#include "script_date.hpp" #include "script_date_economy.hpp"
#include "script_industry.hpp" #include "script_industry.hpp"
#include "script_town.hpp" #include "script_town.hpp"
#include "script_error.hpp" #include "script_error.hpp"
@@ -50,19 +50,19 @@
return (ScriptCompany::CompanyID)((byte)::Subsidy::Get(subsidy_id)->awarded); 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 year = ScriptDateEconomy::GetYear(ScriptDateEconomy::GetCurrentDate());
int month = ScriptDate::GetMonth(ScriptDate::GetCurrentDate()); int month = ScriptDateEconomy::GetMonth(ScriptDateEconomy::GetCurrentDate());
month += ::Subsidy::Get(subsidy_id)->remaining; month += ::Subsidy::Get(subsidy_id)->remaining;
year += (month - 1) / 12; year += (month - 1) / 12;
month = ((month - 1) % 12) + 1; month = ((month - 1) % 12) + 1;
return ScriptDate::GetDate(year, month, 1); return ScriptDateEconomy::GetDate(year, month, 1);
} }
/* static */ CargoID ScriptSubsidy::GetCargoType(SubsidyID subsidy_id) /* static */ CargoID ScriptSubsidy::GetCargoType(SubsidyID subsidy_id)

View File

@@ -11,7 +11,7 @@
#define SCRIPT_SUBSIDY_HPP #define SCRIPT_SUBSIDY_HPP
#include "script_company.hpp" #include "script_company.hpp"
#include "script_date.hpp" #include "script_date_economy.hpp"
/** /**
* Class that handles all subsidy related functions. * Class that handles all subsidy related functions.
@@ -74,8 +74,8 @@ public:
static ScriptCompany::CompanyID GetAwardedTo(SubsidyID subsidy_id); static ScriptCompany::CompanyID GetAwardedTo(SubsidyID subsidy_id);
/** /**
* Get the date this subsidy expires. In case the subsidy is already * Get the economy date this subsidy expires. In case the subsidy is already
* awarded, return the date the subsidy expires, else, return the date the * awarded, return the economy date the subsidy expires, else, return the economy date the
* offer expires. * offer expires.
* @param subsidy_id The SubsidyID to check. * @param subsidy_id The SubsidyID to check.
* @pre IsValidSubsidy(subsidy_id). * @pre IsValidSubsidy(subsidy_id).
@@ -83,7 +83,7 @@ public:
* @note The return value of this function will change if the subsidy is * @note The return value of this function will change if the subsidy is
* awarded. * 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 * Get the cargo type that has to be transported in order to be awarded this