Add: AI functions to set/get vehicle group parent.

This commit is contained in:
Peter Nelson 2019-02-13 21:18:44 +00:00 committed by Niels Martin Hansen
parent 8139b14e9c
commit b62452903a
4 changed files with 38 additions and 0 deletions

View File

@ -31,6 +31,8 @@ void SQAIGroup_Register(Squirrel *engine)
SQAIGroup.DefSQStaticMethod(engine, &ScriptGroup::GetVehicleType, "GetVehicleType", 2, ".i");
SQAIGroup.DefSQStaticMethod(engine, &ScriptGroup::SetName, "SetName", 3, ".i.");
SQAIGroup.DefSQStaticMethod(engine, &ScriptGroup::GetName, "GetName", 2, ".i");
SQAIGroup.DefSQStaticMethod(engine, &ScriptGroup::SetParent, "SetParent", 3, ".ii");
SQAIGroup.DefSQStaticMethod(engine, &ScriptGroup::GetParent, "GetParent", 2, ".i");
SQAIGroup.DefSQStaticMethod(engine, &ScriptGroup::EnableAutoReplaceProtection, "EnableAutoReplaceProtection", 3, ".ib");
SQAIGroup.DefSQStaticMethod(engine, &ScriptGroup::GetAutoReplaceProtection, "GetAutoReplaceProtection", 2, ".i");
SQAIGroup.DefSQStaticMethod(engine, &ScriptGroup::GetNumEngines, "GetNumEngines", 3, ".ii");

View File

@ -20,6 +20,8 @@
* 1.9.0 is not yet released. The following changes are not set in stone yet.
* API additions:
* \li AIAirport::GetMonthlyMaintenanceCost
* \li AIGroup::SetParent
* \li AIGroup::GetParent
*
* Other changes:
* \li AIBridge::GetName takes one extra parameter to refer the vehicle type

View File

@ -70,6 +70,22 @@
return GetString(STR_GROUP_NAME);
}
/* static */ bool ScriptGroup::SetParent(GroupID group_id, GroupID parent_group_id)
{
EnforcePrecondition(false, IsValidGroup(group_id));
EnforcePrecondition(false, IsValidGroup(parent_group_id));
return ScriptObject::DoCommand(0, group_id | 1 << 16, parent_group_id, CMD_ALTER_GROUP);
}
/* static */ ScriptGroup::GroupID ScriptGroup::GetParent(GroupID group_id)
{
EnforcePrecondition((ScriptGroup::GroupID)INVALID_GROUP, IsValidGroup(group_id));
const Group *g = ::Group::GetIfValid(group_id);
return (ScriptGroup::GroupID)g->parent;
}
/* static */ bool ScriptGroup::EnableAutoReplaceProtection(GroupID group_id, bool enable)
{
EnforcePrecondition(false, IsValidGroup(group_id));

View File

@ -84,6 +84,24 @@ public:
*/
static char *GetName(GroupID group_id);
/**
* Set parent group of a group.
* @param group_id The group to set the parent for.
* @param parent_group_id The parent group to set.
* @pre IsValidGroup(group_id).
* @pre IsValidGroup(parent_group_id).
* @return True if and only if the parent group was changed.
*/
static bool SetParent(GroupID group_id, GroupID parent_group_id);
/**
* Get parent group of a group.
* @param group_id The group to get the parent of.
* @pre IsValidGroup(group_id).
* @return The group id of the parent group.
*/
static GroupID GetParent(GroupID group_id);
/**
* Enable or disable autoreplace protected. If the protection is
* enabled, global autoreplace won't affect vehicles in this group.