From 13692798e65b9627ebc5c6eabdcafdfa48660080 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 14 Jul 2007 23:10:27 +0000 Subject: (svn r10567) -Add [FS#915]: a "group" with ungrouped vehicles. Patch by Matthias Wolf. --- src/group.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/group.h') diff --git a/src/group.h b/src/group.h index 8c6667220..b0600db0f 100644 --- a/src/group.h +++ b/src/group.h @@ -8,6 +8,7 @@ #include "oldpool.h" enum { + ALL_GROUP = 0xFFFD, DEFAULT_GROUP = 0xFFFE, INVALID_GROUP = 0xFFFF, }; @@ -50,7 +51,17 @@ static inline bool IsValidGroupID(GroupID index) static inline bool IsDefaultGroupID(GroupID index) { - return (index == DEFAULT_GROUP); + return index == DEFAULT_GROUP; +} + +/** + * Checks if a GroupID stands for all vehicles of a player + * @param id_g The GroupID to check + * @return true is id_g is identical to ALL_GROUP + */ +static inline bool IsAllGroupID(GroupID id_g) +{ + return id_g == ALL_GROUP; } #define FOR_ALL_GROUPS_FROM(g, start) for (g = GetGroup(start); g != NULL; g = (g->index + 1U < GetGroupPoolSize()) ? GetGroup(g->index + 1) : NULL) if (IsValidGroup(g)) @@ -69,6 +80,25 @@ static inline uint GetGroupArraySize(void) return num; } +/** + * Get the number of engines with EngineID id_e in the group with GroupID + * id_g + * @param id_g The GroupID of the group used + * @param id_e The EngineID of the engine to count + * @return The number of engines with EngineID id_e in the group + */ +static inline uint GetGroupNumEngines(GroupID id_g, EngineID id_e) +{ + if (IsValidGroupID(id_g)) return GetGroup(id_g)->num_engines[id_e]; + + uint num = GetPlayer(_local_player)->num_engines[id_e]; + if (!IsDefaultGroupID(id_g)) return num; + + const Group *g; + FOR_ALL_GROUPS(g) num -= g->num_engines[id_e]; + return num; +} + static inline void IncreaseGroupNumVehicle(GroupID id_g) { if (IsValidGroupID(id_g)) GetGroup(id_g)->num_vehicle++; -- cgit v1.2.3-70-g09d2