summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2014-12-24 16:49:57 +0000
committerfrosch <frosch@openttd.org>2014-12-24 16:49:57 +0000
commitfbd7b7ce334deaad6e78ca5168a9aae89adb41d5 (patch)
treee2a4ed032140803762ba19bfbcadd9ed9796498f
parentc5ea52027c1f22d286df4b13c982091c775cc714 (diff)
downloadopenttd-fbd7b7ce334deaad6e78ca5168a9aae89adb41d5.tar.xz
(svn r27090) -Codechange [FS#5976]: Simplify some hierarchical groups code. (Juanjo)
-rw-r--r--src/group_cmd.cpp13
1 files changed, 3 insertions, 10 deletions
diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp
index 8712c378f..12cce41f7 100644
--- a/src/group_cmd.cpp
+++ b/src/group_cmd.cpp
@@ -404,11 +404,7 @@ CommandCost CmdAlterGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
/* Ensure request parent isn't child of group.
* This is the only place that infinite loops are prevented. */
- const Group *looptest = pg;
- while (looptest->parent != INVALID_GROUP) {
- if (looptest->parent == g->index) return CMD_ERROR;
- looptest = Group::Get(looptest->parent);
- }
+ if (GroupIsInGroup(pg->index, g->index)) return CMD_ERROR;
}
if (flags & DC_EXEC) {
@@ -688,7 +684,7 @@ void UpdateTrainGroupID(Train *v)
/**
* Get the number of engines with EngineID id_e in the group with GroupID
- * id_g
+ * id_g and its sub-groups.
* @param company The company the group belongs to
* @param id_g The GroupID of the group used
* @param id_e The EngineID of the engine to count
@@ -723,10 +719,7 @@ void RemoveAllGroupsForCompany(const CompanyID company)
*/
bool GroupIsInGroup(GroupID search, GroupID group)
{
- if (search == NEW_GROUP ||
- search == ALL_GROUP ||
- search == DEFAULT_GROUP ||
- search == INVALID_GROUP) return search == group;
+ if (!Group::IsValidID(search)) return search == group;
do {
if (search == group) return true;