Changeset - r27116:1ccc1b40b87f
[Not reviewed]
master
0 8 0
SamuXarick - 22 months ago 2023-01-23 23:10:46
43006711+SamuXarick@users.noreply.github.com
Change: Allow GS access to ScriptGroup functions
8 files changed with 51 insertions and 8 deletions:
0 comments (0 inline, 0 general)
.github/script-missing-mode-enforcement.py
Show inline comments
 
@@ -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
src/script/api/game_changelog.hpp
Show inline comments
 
@@ -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.
src/script/api/script_error.hpp
Show inline comments
 
@@ -56,6 +56,15 @@
 
	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.
 
 */
src/script/api/script_group.hpp
Show inline comments
 
@@ -15,7 +15,7 @@
 

	
 
/**
 
 * Class that handles all group related functions.
 
 * @api ai
 
 * @api ai game
 
 */
 
class ScriptGroup : public ScriptObject {
 
public:
src/script/api/script_grouplist.cpp
Show inline comments
 
@@ -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);
 
	}
src/script/api/script_grouplist.hpp
Show inline comments
 
@@ -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();
 
};
 

	
src/script/api/script_vehiclelist.cpp
Show inline comments
 
@@ -103,7 +103,7 @@ ScriptVehicleList_SharedOrders::ScriptVe
 

	
 
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::ScriptVehicleLi
 

	
 
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()) {
src/script/api/script_vehiclelist.hpp
Show inline comments
 
@@ -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);
 
};
0 comments (0 inline, 0 general)