11 ALL_GROUP = 0xFFFD, |
11 ALL_GROUP = 0xFFFD, |
12 DEFAULT_GROUP = 0xFFFE, |
12 DEFAULT_GROUP = 0xFFFE, |
13 INVALID_GROUP = 0xFFFF, |
13 INVALID_GROUP = 0xFFFF, |
14 }; |
14 }; |
15 |
15 |
16 struct Group { |
16 struct Group; |
|
17 DECLARE_OLD_POOL(Group, Group, 5, 2047) |
|
18 |
|
19 struct Group : PoolItem<Group, GroupID, &_Group_pool> { |
17 StringID string_id; ///< Group Name |
20 StringID string_id; ///< Group Name |
18 |
21 |
19 uint16 num_vehicle; ///< Number of vehicles wich belong to the group |
22 uint16 num_vehicle; ///< Number of vehicles wich belong to the group |
20 PlayerID owner; ///< Group Owner |
23 PlayerID owner; ///< Group Owner |
21 GroupID index; ///< Array index |
|
22 VehicleTypeByte vehicle_type; ///< Vehicle type of the group |
24 VehicleTypeByte vehicle_type; ///< Vehicle type of the group |
23 |
25 |
24 bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group |
26 bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group |
25 uint16 num_engines[TOTAL_NUM_ENGINES]; ///< Caches the number of engines of each type the player owns (no need to save this) |
27 uint16 num_engines[TOTAL_NUM_ENGINES]; ///< Caches the number of engines of each type the player owns (no need to save this) |
|
28 |
|
29 Group(StringID str = STR_NULL); |
|
30 virtual ~Group(); |
|
31 |
|
32 void QuickFree(); |
|
33 |
|
34 bool IsValid() const; |
26 }; |
35 }; |
27 |
36 |
28 DECLARE_OLD_POOL(Group, Group, 5, 2047) |
|
29 |
|
30 |
|
31 static inline bool IsValidGroup(const Group *g) |
|
32 { |
|
33 return g->string_id != STR_NULL; |
|
34 } |
|
35 |
|
36 static inline void DestroyGroup(Group *g) |
|
37 { |
|
38 DeleteName(g->string_id); |
|
39 } |
|
40 |
|
41 static inline void DeleteGroup(Group *g) |
|
42 { |
|
43 DestroyGroup(g); |
|
44 g->string_id = STR_NULL; |
|
45 } |
|
46 |
37 |
47 static inline bool IsValidGroupID(GroupID index) |
38 static inline bool IsValidGroupID(GroupID index) |
48 { |
39 { |
49 return index < GetGroupPoolSize() && IsValidGroup(GetGroup(index)); |
40 return index < GetGroupPoolSize() && GetGroup(index)->IsValid(); |
50 } |
41 } |
51 |
42 |
52 static inline bool IsDefaultGroupID(GroupID index) |
43 static inline bool IsDefaultGroupID(GroupID index) |
53 { |
44 { |
54 return index == DEFAULT_GROUP; |
45 return index == DEFAULT_GROUP; |
62 static inline bool IsAllGroupID(GroupID id_g) |
53 static inline bool IsAllGroupID(GroupID id_g) |
63 { |
54 { |
64 return id_g == ALL_GROUP; |
55 return id_g == ALL_GROUP; |
65 } |
56 } |
66 |
57 |
67 #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)) |
58 #define FOR_ALL_GROUPS_FROM(g, start) for (g = GetGroup(start); g != NULL; g = (g->index + 1U < GetGroupPoolSize()) ? GetGroup(g->index + 1) : NULL) if (g->IsValid()) |
68 #define FOR_ALL_GROUPS(g) FOR_ALL_GROUPS_FROM(g, 0) |
59 #define FOR_ALL_GROUPS(g) FOR_ALL_GROUPS_FROM(g, 0) |
69 |
60 |
70 /** |
61 /** |
71 * Get the current size of the GroupPool |
62 * Get the current size of the GroupPool |
72 */ |
63 */ |