author | rubidium |
Tue, 22 Jan 2008 21:00:30 +0000 | |
branch | NewGRF_ports |
changeset 6872 | 1c4a4a609f85 |
parent 6868 | 7eb395287b3d |
child 6878 | 7d1ff2f621c7 |
permissions | -rw-r--r-- |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
1 |
/* $Id$ */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
2 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
3 |
/** @file group.h */ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
4 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
5 |
#ifndef GROUP_H |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
6 |
#define GROUP_H |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
7 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
8 |
#include "oldpool.h" |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6868
diff
changeset
|
9 |
#include "player_type.h" |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6868
diff
changeset
|
10 |
#include "vehicle_type.h" |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6868
diff
changeset
|
11 |
#include "engine.h" |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
12 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
13 |
enum { |
6725
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
14 |
ALL_GROUP = 0xFFFD, |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
15 |
DEFAULT_GROUP = 0xFFFE, |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
16 |
INVALID_GROUP = 0xFFFF, |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
17 |
}; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
18 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6725
diff
changeset
|
19 |
struct Group; |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6725
diff
changeset
|
20 |
DECLARE_OLD_POOL(Group, Group, 5, 2047) |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6725
diff
changeset
|
21 |
|
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6725
diff
changeset
|
22 |
struct Group : PoolItem<Group, GroupID, &_Group_pool> { |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6868
diff
changeset
|
23 |
char *name; ///< Group Name |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
24 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
25 |
uint16 num_vehicle; ///< Number of vehicles wich belong to the group |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
26 |
PlayerID owner; ///< Group Owner |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
27 |
VehicleTypeByte vehicle_type; ///< Vehicle type of the group |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
28 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
29 |
bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
30 |
uint16 num_engines[TOTAL_NUM_ENGINES]; ///< Caches the number of engines of each type the player owns (no need to save this) |
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6725
diff
changeset
|
31 |
|
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6868
diff
changeset
|
32 |
Group(PlayerID owner = INVALID_PLAYER); |
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6725
diff
changeset
|
33 |
virtual ~Group(); |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6725
diff
changeset
|
34 |
|
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6725
diff
changeset
|
35 |
bool IsValid() const; |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
36 |
}; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
37 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
38 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
39 |
static inline bool IsValidGroupID(GroupID index) |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
40 |
{ |
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6725
diff
changeset
|
41 |
return index < GetGroupPoolSize() && GetGroup(index)->IsValid(); |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
42 |
} |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
43 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
44 |
static inline bool IsDefaultGroupID(GroupID index) |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
45 |
{ |
6725
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
46 |
return index == DEFAULT_GROUP; |
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
47 |
} |
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
48 |
|
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
49 |
/** |
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
50 |
* Checks if a GroupID stands for all vehicles of a player |
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
51 |
* @param id_g The GroupID to check |
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
52 |
* @return true is id_g is identical to ALL_GROUP |
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
53 |
*/ |
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
54 |
static inline bool IsAllGroupID(GroupID id_g) |
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
55 |
{ |
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
56 |
return id_g == ALL_GROUP; |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
57 |
} |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
58 |
|
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6725
diff
changeset
|
59 |
#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()) |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
60 |
#define FOR_ALL_GROUPS(g) FOR_ALL_GROUPS_FROM(g, 0) |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
61 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
62 |
/** |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
63 |
* Get the current size of the GroupPool |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
64 |
*/ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
65 |
static inline uint GetGroupArraySize(void) |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
66 |
{ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
67 |
const Group *g; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
68 |
uint num = 0; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
69 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
70 |
FOR_ALL_GROUPS(g) num++; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
71 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
72 |
return num; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
73 |
} |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
74 |
|
6725
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
75 |
/** |
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
76 |
* Get the number of engines with EngineID id_e in the group with GroupID |
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
77 |
* id_g |
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
78 |
* @param id_g The GroupID of the group used |
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
79 |
* @param id_e The EngineID of the engine to count |
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
80 |
* @return The number of engines with EngineID id_e in the group |
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
81 |
*/ |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6868
diff
changeset
|
82 |
uint GetGroupNumEngines(PlayerID p, GroupID id_g, EngineID id_e); |
6725
23339968083f
(svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents:
6720
diff
changeset
|
83 |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
84 |
static inline void IncreaseGroupNumVehicle(GroupID id_g) |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
85 |
{ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
86 |
if (IsValidGroupID(id_g)) GetGroup(id_g)->num_vehicle++; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
87 |
} |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
88 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
89 |
static inline void DecreaseGroupNumVehicle(GroupID id_g) |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
90 |
{ |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
91 |
if (IsValidGroupID(id_g)) GetGroup(id_g)->num_vehicle--; |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
92 |
} |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
93 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
94 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
95 |
void InitializeGroup(); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
96 |
void SetTrainGroupID(Vehicle *v, GroupID grp); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
97 |
void UpdateTrainGroupID(Vehicle *v); |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
98 |
void RemoveVehicleFromGroup(const Vehicle *v); |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6868
diff
changeset
|
99 |
void RemoveAllGroupsForPlayer(const PlayerID p); |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
100 |
|
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
diff
changeset
|
101 |
#endif /* GROUP_H */ |