From f8b5661d288ade88a57c39cbf5aca26ea676751e 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] Change: Allow GS access to ScriptGroup functions --- .github/script-missing-mode-enforcement.py | 2 +- src/script/api/game_changelog.hpp | 29 ++++++++++++++++++++++ src/script/api/script_error.hpp | 9 +++++++ src/script/api/script_group.hpp | 2 +- src/script/api/script_grouplist.cpp | 2 +- src/script/api/script_grouplist.hpp | 5 +++- src/script/api/script_vehiclelist.cpp | 4 +-- src/script/api/script_vehiclelist.hpp | 6 +++-- 8 files changed, 51 insertions(+), 8 deletions(-) diff --git a/.github/script-missing-mode-enforcement.py b/.github/script-missing-mode-enforcement.py index 5903b5f0a0..dfb4764abb 100644 --- a/.github/script-missing-mode-enforcement.py +++ b/.github/script-missing-mode-enforcement.py @@ -30,7 +30,7 @@ def check_mode_enforcement(path): continue if re.match( - r"\t(EnforceDeityMode|EnforceCompanyModeValid|EnforceDeityOrCompanyModeValid|EnforceDeityOrCompanyModeValid_Void)\(", + r"\t(EnforceDeityMode|EnforceCompanyModeValid|EnforceCompanyModeValid_Void|EnforceDeityOrCompanyModeValid|EnforceDeityOrCompanyModeValid_Void)\(", line, ): # Mode enforcement macro found diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index e64b9bda96..798b7d0289 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -45,6 +45,35 @@ * \li GSCompany::SetAutoRenewMonths * \li GSCompany::SetAutoRenewMoney * \li GSGameSettings::IsDisabledVehicleType + * \li GSGroup::GroupID + * \li GSGroup::IsValidGroup + * \li GSGroup::CreateGroup + * \li GSGroup::DeleteGroup + * \li GSGroup::GetVehicleType + * \li GSGroup::SetName + * \li GSGroup::GetName + * \li GSGroup::SetParent + * \li GSGroup::GetParent + * \li GSGroup::EnableAutoReplaceProtection + * \li GSGroup::GetAutoReplaceProtection + * \li GSGroup::GetNumEngines + * \li GSGroup::GetNumVehicles + * \li GSGroup::MoveVehicle + * \li GSGroup::EnableWagonRemoval + * \li GSGroup::HasWagonRemoval + * \li GSGroup::SetAutoReplace + * \li GSGroup::GetEngineReplacement + * \li GSGroup::StopAutoReplace + * \li GSGroup::GetProfitThisYear + * \li GSGroup::GetProfitLastYear + * \li GSGroup::GetCurrentUsage + * \li GSGroup::SetPrimaryColour + * \li GSGroup::SetSecondaryColour + * \li GSGroup::GetPrimaryColour + * \li GSGroup::GetSecondaryColour + * \li GSGroupList + * \li GSVehicleList_Group + * \li GSVehicleList_DefaultGroup * * API removals: * \li GSError::ERR_PRECONDITION_TOO_MANY_PARAMETERS, that error is never returned anymore. diff --git a/src/script/api/script_error.hpp b/src/script/api/script_error.hpp index f4adb84cec..e461a7d46d 100644 --- a/src/script/api/script_error.hpp +++ b/src/script/api/script_error.hpp @@ -55,6 +55,15 @@ #define EnforceCompanyModeValid(returnval) \ EnforcePreconditionCustomError(returnval, ScriptCompanyMode::IsValid(), ScriptError::ERR_PRECONDITION_INVALID_COMPANY) +/** + * Helper to enforce the precondition that the company mode is valid. + */ +#define EnforceCompanyModeValid_Void() \ + if (!ScriptCompanyMode::IsValid()) { \ + ScriptObject::SetLastError(ScriptError::ERR_PRECONDITION_INVALID_COMPANY); \ + return; \ + } + /** * Helper to enforce the precondition that we are in a deity mode. * @param returnval The value to return on failure. diff --git a/src/script/api/script_group.hpp b/src/script/api/script_group.hpp index c685813a88..ba61be3fd4 100644 --- a/src/script/api/script_group.hpp +++ b/src/script/api/script_group.hpp @@ -15,7 +15,7 @@ /** * Class that handles all group related functions. - * @api ai + * @api ai game */ class ScriptGroup : public ScriptObject { public: diff --git a/src/script/api/script_grouplist.cpp b/src/script/api/script_grouplist.cpp index 11099ca67e..3fb9358e8d 100644 --- a/src/script/api/script_grouplist.cpp +++ b/src/script/api/script_grouplist.cpp @@ -16,7 +16,7 @@ ScriptGroupList::ScriptGroupList() { - EnforceDeityOrCompanyModeValid_Void(); + EnforceCompanyModeValid_Void(); for (const Group *g : Group::Iterate()) { if (g->owner == ScriptObject::GetCompany()) this->AddItem(g->index); } diff --git a/src/script/api/script_grouplist.hpp b/src/script/api/script_grouplist.hpp index d8195ed96a..49e8028dcb 100644 --- a/src/script/api/script_grouplist.hpp +++ b/src/script/api/script_grouplist.hpp @@ -15,11 +15,14 @@ /** * Creates a list of groups of which you are the owner. * @note Neither ScriptGroup::GROUP_ALL nor ScriptGroup::GROUP_DEFAULT is in this list. - * @api ai + * @api ai game * @ingroup ScriptList */ class ScriptGroupList : public ScriptList { public: + /** + * @game @pre ScriptCompanyMode::IsValid(). + */ ScriptGroupList(); }; diff --git a/src/script/api/script_vehiclelist.cpp b/src/script/api/script_vehiclelist.cpp index 0687ac366c..a00ec91c85 100644 --- a/src/script/api/script_vehiclelist.cpp +++ b/src/script/api/script_vehiclelist.cpp @@ -103,7 +103,7 @@ ScriptVehicleList_SharedOrders::ScriptVehicleList_SharedOrders(VehicleID vehicle ScriptVehicleList_Group::ScriptVehicleList_Group(GroupID group_id) { - EnforceDeityOrCompanyModeValid_Void(); + EnforceCompanyModeValid_Void(); if (!ScriptGroup::IsValidGroup((ScriptGroup::GroupID)group_id)) return; for (const Vehicle *v : Vehicle::Iterate()) { @@ -115,7 +115,7 @@ ScriptVehicleList_Group::ScriptVehicleList_Group(GroupID group_id) ScriptVehicleList_DefaultGroup::ScriptVehicleList_DefaultGroup(ScriptVehicle::VehicleType vehicle_type) { - EnforceDeityOrCompanyModeValid_Void(); + EnforceCompanyModeValid_Void(); if (vehicle_type < ScriptVehicle::VT_RAIL || vehicle_type > ScriptVehicle::VT_AIR) return; for (const Vehicle *v : Vehicle::Iterate()) { diff --git a/src/script/api/script_vehiclelist.hpp b/src/script/api/script_vehiclelist.hpp index 0ce2d86a35..22de3e344c 100644 --- a/src/script/api/script_vehiclelist.hpp +++ b/src/script/api/script_vehiclelist.hpp @@ -69,26 +69,28 @@ public: /** * Creates a list of vehicles that are in a group. - * @api ai + * @api ai game * @ingroup ScriptList */ class ScriptVehicleList_Group : public ScriptList { public: /** * @param group_id The ID of the group the vehicles are in. + * @game @pre ScriptCompanyMode::IsValid(). */ ScriptVehicleList_Group(GroupID group_id); }; /** * Creates a list of vehicles that are in the default group. - * @api ai + * @api ai game * @ingroup ScriptList */ class ScriptVehicleList_DefaultGroup : public ScriptList { public: /** * @param vehicle_type The VehicleType to get the list of vehicles for. + * @game @pre ScriptCompanyMode::IsValid(). */ ScriptVehicleList_DefaultGroup(ScriptVehicle::VehicleType vehicle_type); };