# HG changeset patch # User Andy <1780327+andythenorth@users.noreply.github.com> # Date 2023-07-20 18:35:37 # Node ID b304bebdbb90f2426ba58b13cea4c6a16907724f # Parent 7f96e43b932b9303f8f93d8dbb94e97815e86fad Add: [Script] GSIndustry.GetConstructionDate() method (#11145) diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -18,6 +18,7 @@ * This version is not yet released. The following changes are not set in stone yet. * * API additions: + * \li GSIndustry::GetConstructionDate * \li GSAsyncMode * \li GSCompanyMode::IsValid * \li GSCompanyMode::IsDeity diff --git a/src/script/api/script_industry.cpp b/src/script/api/script_industry.cpp --- a/src/script/api/script_industry.cpp +++ b/src/script/api/script_industry.cpp @@ -49,6 +49,13 @@ return GetString(STR_INDUSTRY_NAME); } +/* static */ ScriptDate::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; +} + /* static */ bool ScriptIndustry::SetText(IndustryID industry_id, Text *text) { CCountedPtr counter(text); diff --git a/src/script/api/script_industry.hpp b/src/script/api/script_industry.hpp --- a/src/script/api/script_industry.hpp +++ b/src/script/api/script_industry.hpp @@ -82,6 +82,15 @@ public: static std::optional GetName(IndustryID industry_id); /** + * Get the construction 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); + + /** * Set the custom text of an industry, shown in the GUI. * @param industry_id The industry to set the custom text of. * @param text The text to set it to (can be either a raw string, or a ScriptText object). If null, or an empty string, is passed, the text will be removed.