diff options
author | Peter Nelson <peter1138@openttd.org> | 2019-02-13 21:18:44 +0000 |
---|---|---|
committer | Niels Martin Hansen <nielsm@indvikleren.dk> | 2019-03-03 09:15:39 +0100 |
commit | b62452903a3af9e51dc308fd674a788214942382 (patch) | |
tree | 0b4f1f1755714e0cb6ddf1877b00a8e23994239b /src/script/api/script_group.cpp | |
parent | 8139b14e9c941433bce74e46a7330123cae4ae2b (diff) | |
download | openttd-b62452903a3af9e51dc308fd674a788214942382.tar.xz |
Add: AI functions to set/get vehicle group parent.
Diffstat (limited to 'src/script/api/script_group.cpp')
-rw-r--r-- | src/script/api/script_group.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
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)); |