summaryrefslogtreecommitdiff
path: root/src/group.h
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-07-14 23:10:27 +0000
committerrubidium <rubidium@openttd.org>2007-07-14 23:10:27 +0000
commit13692798e65b9627ebc5c6eabdcafdfa48660080 (patch)
tree8e0bc57b2b06b68cd87f0cd9d2168ec3eb7ed227 /src/group.h
parentc598d1b446ba8902d7070f7d7ba137fc8edf2e96 (diff)
downloadopenttd-13692798e65b9627ebc5c6eabdcafdfa48660080.tar.xz
(svn r10567) -Add [FS#915]: a "group" with ungrouped vehicles. Patch by Matthias Wolf.
Diffstat (limited to 'src/group.h')
-rw-r--r--src/group.h32
1 files changed, 31 insertions, 1 deletions
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++;