diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index be1bfce..5e123d2 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -314,7 +314,7 @@ CommandCost CmdDeleteGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 /* Remove all vehicles from the group */ DoCommand(0, p1, 0, flags, CMD_REMOVE_ALL_VEHICLES_GROUP); - /* Delete sub-groups */ + /* Delete subgroups. */ Group *gp; FOR_ALL_GROUPS(gp) { if (gp->parent == g->index) { @@ -402,11 +402,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) { @@ -579,7 +575,7 @@ CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, DoCommandFlag flags, uint3 } /** - * Set replace protection for a group and its sub-groups. + * Set replace protection for a group and its subgroups. * @param g initial group. * @param protect 1 to set or 0 to clear protection. */ @@ -601,7 +597,7 @@ static void SetGroupReplaceProtection(Group *g, bool protect) * - p1 bit 0-15 : GroupID * @param p2 * - p2 bit 0 : 1 to set or 0 to clear protection. - * - p2 bit 1 : 1 to apply to sub-groups. + * - p2 bit 1 : 1 to apply to subgroups. * @param text unused * @return the cost of this operation or an error */ @@ -686,7 +682,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 subgroups. * @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 @@ -721,10 +717,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; diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 0b6c860..17f7836 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -30,7 +30,7 @@ #include "table/sprites.h" -static const int LEVEL_WIDTH = 10; ///< Indenting width of a sub-group in pixels +static const int LEVEL_WIDTH = 10; ///< Indenting width of a subgroup in pixels. typedef GUIList GUIGroupList; @@ -549,7 +549,7 @@ public: case WID_GL_LIST_VEHICLE: if (this->vli.index != ALL_GROUP) { - /* Mark vehicles which are in sub-groups */ + /* Mark vehicles which are in subgroups. */ int y = r.top; uint max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->vehicles.Length()); for (uint i = this->vscroll->GetPosition(); i < max; ++i) {