|
1 /* $Id$ */ |
|
2 |
|
3 /** @file group.h */ |
|
4 |
|
5 #ifndef GROUP_H |
|
6 #define GROUP_H |
|
7 |
|
8 #include "oldpool.h" |
|
9 |
|
10 enum { |
|
11 DEFAULT_GROUP = 0xFFFE, |
|
12 INVALID_GROUP = 0xFFFF, |
|
13 }; |
|
14 |
|
15 struct Group { |
|
16 StringID string_id; ///< Group Name |
|
17 |
|
18 uint16 num_vehicle; ///< Number of vehicles wich belong to the group |
|
19 PlayerID owner; ///< Group Owner |
|
20 GroupID index; ///< Array index |
|
21 VehicleTypeByte vehicle_type; ///< Vehicle type of the group |
|
22 |
|
23 bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group |
|
24 uint16 num_engines[TOTAL_NUM_ENGINES]; ///< Caches the number of engines of each type the player owns (no need to save this) |
|
25 }; |
|
26 |
|
27 DECLARE_OLD_POOL(Group, Group, 5, 2047) |
|
28 |
|
29 |
|
30 static inline bool IsValidGroup(const Group *g) |
|
31 { |
|
32 return g->string_id != STR_NULL; |
|
33 } |
|
34 |
|
35 static inline void DestroyGroup(Group *g) |
|
36 { |
|
37 DeleteName(g->string_id); |
|
38 } |
|
39 |
|
40 static inline void DeleteGroup(Group *g) |
|
41 { |
|
42 DestroyGroup(g); |
|
43 g->string_id = STR_NULL; |
|
44 } |
|
45 |
|
46 static inline bool IsValidGroupID(GroupID index) |
|
47 { |
|
48 return index < GetGroupPoolSize() && IsValidGroup(GetGroup(index)); |
|
49 } |
|
50 |
|
51 static inline bool IsDefaultGroupID(GroupID index) |
|
52 { |
|
53 return (index == DEFAULT_GROUP); |
|
54 } |
|
55 |
|
56 static inline StringID GetGroupName(GroupID index) |
|
57 { |
|
58 if (!IsValidGroupID(index)) return STR_NULL; |
|
59 |
|
60 return GetGroup(index)->string_id; |
|
61 } |
|
62 |
|
63 |
|
64 #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)) |
|
65 #define FOR_ALL_GROUPS(g) FOR_ALL_GROUPS_FROM(g, 0) |
|
66 |
|
67 /** |
|
68 * Get the current size of the GroupPool |
|
69 */ |
|
70 static inline uint GetGroupArraySize(void) |
|
71 { |
|
72 const Group *g; |
|
73 uint num = 0; |
|
74 |
|
75 FOR_ALL_GROUPS(g) num++; |
|
76 |
|
77 return num; |
|
78 } |
|
79 |
|
80 static inline void IncreaseGroupNumVehicle(GroupID id_g) |
|
81 { |
|
82 if (IsValidGroupID(id_g)) GetGroup(id_g)->num_vehicle++; |
|
83 } |
|
84 |
|
85 static inline void DecreaseGroupNumVehicle(GroupID id_g) |
|
86 { |
|
87 if (IsValidGroupID(id_g)) GetGroup(id_g)->num_vehicle--; |
|
88 } |
|
89 |
|
90 |
|
91 void InitializeGroup(); |
|
92 void SetTrainGroupID(Vehicle *v, GroupID grp); |
|
93 void UpdateTrainGroupID(Vehicle *v); |
|
94 void RemoveVehicleFromGroup(const Vehicle *v); |
|
95 void RemoveAllGroupsForPlayer(const Player *p); |
|
96 |
|
97 #endif /* GROUP_H */ |