summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorPeter Nelson <peter1138@openttd.org>2019-02-13 21:18:44 +0000
committerNiels Martin Hansen <nielsm@indvikleren.dk>2019-03-03 09:15:39 +0100
commitb62452903a3af9e51dc308fd674a788214942382 (patch)
tree0b4f1f1755714e0cb6ddf1877b00a8e23994239b /src/script
parent8139b14e9c941433bce74e46a7330123cae4ae2b (diff)
downloadopenttd-b62452903a3af9e51dc308fd674a788214942382.tar.xz
Add: AI functions to set/get vehicle group parent.
Diffstat (limited to 'src/script')
-rw-r--r--src/script/api/ai/ai_group.hpp.sq2
-rw-r--r--src/script/api/ai_changelog.hpp2
-rw-r--r--src/script/api/script_group.cpp16
-rw-r--r--src/script/api/script_group.hpp18
4 files changed, 38 insertions, 0 deletions
diff --git a/src/script/api/ai/ai_group.hpp.sq b/src/script/api/ai/ai_group.hpp.sq
index 52ade08d5..a5f0e25a0 100644
--- a/src/script/api/ai/ai_group.hpp.sq
+++ b/src/script/api/ai/ai_group.hpp.sq
@@ -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");
diff --git a/src/script/api/ai_changelog.hpp b/src/script/api/ai_changelog.hpp
index eb2b3a501..bba36b7ea 100644
--- a/src/script/api/ai_changelog.hpp
+++ b/src/script/api/ai_changelog.hpp
@@ -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
diff --git a/src/script/api/script_group.cpp b/src/script/api/script_group.cpp
index cf8dd51a8..7823fb28b 100644
--- a/src/script/api/script_group.cpp
+++ b/src/script/api/script_group.cpp
@@ -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));
diff --git a/src/script/api/script_group.hpp b/src/script/api/script_group.hpp
index fd8888a17..7b375e29a 100644
--- a/src/script/api/script_group.hpp
+++ b/src/script/api/script_group.hpp
@@ -85,6 +85,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.
* @param group_id The group to change the protection for.