author | rubidium |
Fri, 03 Aug 2007 22:09:42 +0000 | |
branch | noai |
changeset 9694 | e72987579514 |
parent 9686 | d3c195c226f9 |
child 6800 | 6c09e1e86fcb |
child 9701 | d1ac22c62f64 |
permissions | -rw-r--r-- |
9624 | 1 |
/* $Id$ */ |
2 |
||
3 |
/** @file group.h */ |
|
4 |
||
5 |
#ifndef GROUP_H |
|
6 |
#define GROUP_H |
|
7 |
||
8 |
#include "oldpool.h" |
|
9 |
||
10 |
enum { |
|
9686
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
11 |
ALL_GROUP = 0xFFFD, |
9624 | 12 |
DEFAULT_GROUP = 0xFFFE, |
13 |
INVALID_GROUP = 0xFFFF, |
|
14 |
}; |
|
15 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
16 |
struct Group; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
17 |
DECLARE_OLD_POOL(Group, Group, 5, 2047) |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
18 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
19 |
struct Group : PoolItem<Group, GroupID, &_Group_pool> { |
9624 | 20 |
StringID string_id; ///< Group Name |
21 |
||
22 |
uint16 num_vehicle; ///< Number of vehicles wich belong to the group |
|
23 |
PlayerID owner; ///< Group Owner |
|
24 |
VehicleTypeByte vehicle_type; ///< Vehicle type of the group |
|
25 |
||
26 |
bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group |
|
27 |
uint16 num_engines[TOTAL_NUM_ENGINES]; ///< Caches the number of engines of each type the player owns (no need to save this) |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
28 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
29 |
Group(StringID str = STR_NULL); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
30 |
virtual ~Group(); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
31 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
32 |
void QuickFree(); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
33 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
34 |
bool IsValid() const; |
9624 | 35 |
}; |
36 |
||
37 |
||
38 |
static inline bool IsValidGroupID(GroupID index) |
|
39 |
{ |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
40 |
return index < GetGroupPoolSize() && GetGroup(index)->IsValid(); |
9624 | 41 |
} |
42 |
||
43 |
static inline bool IsDefaultGroupID(GroupID index) |
|
44 |
{ |
|
9686
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
45 |
return index == DEFAULT_GROUP; |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
46 |
} |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
47 |
|
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
48 |
/** |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
49 |
* Checks if a GroupID stands for all vehicles of a player |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
50 |
* @param id_g The GroupID to check |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
51 |
* @return true is id_g is identical to ALL_GROUP |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
52 |
*/ |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
53 |
static inline bool IsAllGroupID(GroupID id_g) |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
54 |
{ |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
55 |
return id_g == ALL_GROUP; |
9624 | 56 |
} |
57 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
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()) |
9624 | 59 |
#define FOR_ALL_GROUPS(g) FOR_ALL_GROUPS_FROM(g, 0) |
60 |
||
61 |
/** |
|
62 |
* Get the current size of the GroupPool |
|
63 |
*/ |
|
64 |
static inline uint GetGroupArraySize(void) |
|
65 |
{ |
|
66 |
const Group *g; |
|
67 |
uint num = 0; |
|
68 |
||
69 |
FOR_ALL_GROUPS(g) num++; |
|
70 |
||
71 |
return num; |
|
72 |
} |
|
73 |
||
9686
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
74 |
/** |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
75 |
* Get the number of engines with EngineID id_e in the group with GroupID |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
76 |
* id_g |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
77 |
* @param id_g The GroupID of the group used |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
78 |
* @param id_e The EngineID of the engine to count |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
79 |
* @return The number of engines with EngineID id_e in the group |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
80 |
*/ |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
81 |
static inline uint GetGroupNumEngines(GroupID id_g, EngineID id_e) |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
82 |
{ |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
83 |
if (IsValidGroupID(id_g)) return GetGroup(id_g)->num_engines[id_e]; |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
84 |
|
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
85 |
uint num = GetPlayer(_local_player)->num_engines[id_e]; |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
86 |
if (!IsDefaultGroupID(id_g)) return num; |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
87 |
|
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
88 |
const Group *g; |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
89 |
FOR_ALL_GROUPS(g) num -= g->num_engines[id_e]; |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
90 |
return num; |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
91 |
} |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
92 |
|
9624 | 93 |
static inline void IncreaseGroupNumVehicle(GroupID id_g) |
94 |
{ |
|
95 |
if (IsValidGroupID(id_g)) GetGroup(id_g)->num_vehicle++; |
|
96 |
} |
|
97 |
||
98 |
static inline void DecreaseGroupNumVehicle(GroupID id_g) |
|
99 |
{ |
|
100 |
if (IsValidGroupID(id_g)) GetGroup(id_g)->num_vehicle--; |
|
101 |
} |
|
102 |
||
103 |
||
104 |
void InitializeGroup(); |
|
105 |
void SetTrainGroupID(Vehicle *v, GroupID grp); |
|
106 |
void UpdateTrainGroupID(Vehicle *v); |
|
107 |
void RemoveVehicleFromGroup(const Vehicle *v); |
|
108 |
void RemoveAllGroupsForPlayer(const Player *p); |
|
109 |
||
110 |
#endif /* GROUP_H */ |