From 68a9f6e77449741089a6e0ff5df768545f751d33 Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Mon, 23 Jan 2023 23:10:46 +0000 Subject: [PATCH] Add: ScriptGroup::GetOwner for Game Scripts --- src/script/api/game_changelog.hpp | 1 + src/script/api/script_group.cpp | 7 +++++++ src/script/api/script_group.hpp | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index 13498b62e4..e65c57f148 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -27,6 +27,7 @@ * \li GSCargo::CC_NON_POURABLE * \li GSCargo::CC_POTABLE * \li GSCargo::CC_NON_POTABLE + * \li GSGroup::GetOwner * * Other changes: * \li GSBridge::GetBridgeID renamed to GSBridge::GetBridgeType diff --git a/src/script/api/script_group.cpp b/src/script/api/script_group.cpp index 352e78b28f..5dcf1a60d1 100644 --- a/src/script/api/script_group.cpp +++ b/src/script/api/script_group.cpp @@ -31,6 +31,13 @@ return g != nullptr && g->owner == ScriptObject::GetCompany(); } +/* static */ ScriptCompany::CompanyID ScriptGroup::GetOwner(GroupID group_id) +{ + if (!IsValidGroup(group_id)) return ScriptCompany::COMPANY_INVALID; + + return ScriptCompany::ToScriptCompanyID(::Group::Get(group_id)->owner); +} + /* static */ GroupID ScriptGroup::CreateGroup(ScriptVehicle::VehicleType vehicle_type, GroupID parent_group_id) { EnforceCompanyModeValid(GROUP_INVALID); diff --git a/src/script/api/script_group.hpp b/src/script/api/script_group.hpp index a4a497c05d..2dd978afb9 100644 --- a/src/script/api/script_group.hpp +++ b/src/script/api/script_group.hpp @@ -31,6 +31,15 @@ public: */ static bool IsValidGroup(GroupID group_id); + /** + * Get the owner of a group. + * @param group_id The group to get the owner of. + * @pre IsValidGroup(group_id). + * @return The owner the group has. + * @api -ai + */ + static ScriptCompany::CompanyID GetOwner(GroupID group_id); + /** * Create a new group. * @param vehicle_type The type of vehicle to create a group for.