From bb70dffe70f9b615641f6ae2f8df31513271d575 Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Thu, 30 Jan 2025 12:12:28 +0000 Subject: [PATCH] Add: [Script] GSBaseStation::GetOwner Added method for Game Scripts to retrieve the owner of a basestation. --- src/script/api/game_changelog.hpp | 1 + src/script/api/script_basestation.cpp | 6 ++++++ src/script/api/script_basestation.hpp | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index ffb3578ebf..e57e873a14 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -28,6 +28,7 @@ * \li GSCargo::CC_POTABLE * \li GSCargo::CC_NON_POTABLE * \li GSVehicleList_Waypoint + * \li GSBaseStation::GetOwner * * Other changes: * \li GSBridge::GetBridgeID renamed to GSBridge::GetBridgeType diff --git a/src/script/api/script_basestation.cpp b/src/script/api/script_basestation.cpp index 26a4ca9b45..e7bea4ec29 100644 --- a/src/script/api/script_basestation.cpp +++ b/src/script/api/script_basestation.cpp @@ -28,6 +28,12 @@ return st != nullptr && (st->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity() || st->owner == OWNER_NONE); } +/* static */ ScriptCompany::CompanyID ScriptBaseStation::GetOwner(StationID station_id) +{ + if (!IsValidBaseStation(station_id)) return ScriptCompany::COMPANY_INVALID; + return ScriptCompany::ToScriptCompanyID(::BaseStation::Get(station_id)->owner); +} + /* static */ std::optional ScriptBaseStation::GetName(StationID station_id) { if (!IsValidBaseStation(station_id)) return std::nullopt; diff --git a/src/script/api/script_basestation.hpp b/src/script/api/script_basestation.hpp index c46326cdfb..646bec13ab 100644 --- a/src/script/api/script_basestation.hpp +++ b/src/script/api/script_basestation.hpp @@ -11,6 +11,7 @@ #define SCRIPT_BASESTATION_HPP #include "script_text.hpp" +#include "script_company.hpp" #include "script_date.hpp" #include "../../station_type.h" @@ -32,6 +33,15 @@ public: */ static bool IsValidBaseStation(StationID station_id); + /** + * Get the owner of a basestation. + * @param station_id The basestation to get the owner of. + * @pre IsValidBaseStation(station_id). + * @return The owner the basestation has. + * @api -ai + */ + static ScriptCompany::CompanyID GetOwner(StationID station_id); + /** * Get the name of a basestation. * @param station_id The basestation to get the name of.