mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-18 05:01:13 +00:00
Change: Allow GS access to ScriptGroup functions
This commit is contained in:
parent
f225f36c3d
commit
f8b5661d28
2
.github/script-missing-mode-enforcement.py
vendored
2
.github/script-missing-mode-enforcement.py
vendored
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
/**
|
||||
* Class that handles all group related functions.
|
||||
* @api ai
|
||||
* @api ai game
|
||||
*/
|
||||
class ScriptGroup : public ScriptObject {
|
||||
public:
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
};
|
||||
|
||||
|
@ -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()) {
|
||||
|
@ -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);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user