FS#6491 - Vehicle Groups: new group as subgroup of selected group

Attached to Project: OpenTTD
Opened by 3298 (3298) - Monday, 18 July 2016, 19:31 GMT
Last edited by andythenorth (andythenorth) - Saturday, 02 September 2017, 13:05 GMT
Type Feature Request
Category Interface
Status With patch
Assigned To andythenorth (andythenorth)
Operating System All
Severity Low
Priority Flash
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No


When creating a group, it is sometimes meant to be a subgroup of an existing group. Currently this has to be done in two steps: creating the group, then dragging it onto the parent group. With a lot of groups, dragging can become unpleasant. This patch aims to eliminate the second step by using the selected group as parent of the new group. Parent-less groups can be created by selecting the special groups (all, ungrouped).
This patch was originally done as a response to a thread in the OpenTTD Suggestions forum (, but it seems I never actually posted it. I recently rediscovered it in my local git repository and rebased it.
The implementation is pretty straightforward, using the (previously unused) parameter p2 of CmdCreateGroup to transfer the parent group. If it is a valid group, the same sanity checks as in CmdAlterGroup are performed (excluding the infinite loop check because the newly created group cannot be the parent of anything yet).
Creating a group by pushing the button sends the currently selected group as parent, of course.
Creating a group by dragging a vehicle sends INVALID_GROUP as parent because it needs to be dragged into the empty space below the list of groups. In that case, it feels more logical to create a parent-less group, but I am open to suggestions here.
Scripts also get to create parent-less groups only because I value compatibility over the slight performance and convenience advantages of changing the API to expose the added parent parameter. If a script wizard (Zuu?) knows how to expose the new parameter while preserving compatibility, feel free to amend the patch.
The attached patch applies to r27618.
This task depends upon

Comment by andythenorth (andythenorth) - Monday, 21 August 2017, 06:28 GMT
See also FS#6053 for group expand/collapse, FS#6189 for group totals, and  FS#5334  for group profit display.