group.h
Go to the documentation of this file.00001
00002
00005 #ifndef GROUP_H
00006 #define GROUP_H
00007
00008 #include "oldpool.h"
00009 #include "player_type.h"
00010 #include "vehicle_type.h"
00011 #include "engine.h"
00012
00013 enum {
00014 ALL_GROUP = 0xFFFD,
00015 DEFAULT_GROUP = 0xFFFE,
00016 INVALID_GROUP = 0xFFFF,
00017 };
00018
00019 struct Group;
00020 DECLARE_OLD_POOL(Group, Group, 5, 2047)
00021
00022 struct Group : PoolItem<Group, GroupID, &_Group_pool> {
00023 char *name;
00024
00025 uint16 num_vehicle;
00026 PlayerByte owner;
00027 VehicleTypeByte vehicle_type;
00028
00029 bool replace_protection;
00030 uint16 num_engines[TOTAL_NUM_ENGINES];
00031
00032 Group(PlayerID owner = INVALID_PLAYER);
00033 virtual ~Group();
00034
00035 bool IsValid() const;
00036 };
00037
00038
00039 static inline bool IsValidGroupID(GroupID index)
00040 {
00041 return index < GetGroupPoolSize() && GetGroup(index)->IsValid();
00042 }
00043
00044 static inline bool IsDefaultGroupID(GroupID index)
00045 {
00046 return index == DEFAULT_GROUP;
00047 }
00048
00054 static inline bool IsAllGroupID(GroupID id_g)
00055 {
00056 return id_g == ALL_GROUP;
00057 }
00058
00059 #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())
00060 #define FOR_ALL_GROUPS(g) FOR_ALL_GROUPS_FROM(g, 0)
00061
00065 static inline uint GetGroupArraySize(void)
00066 {
00067 const Group *g;
00068 uint num = 0;
00069
00070 FOR_ALL_GROUPS(g) num++;
00071
00072 return num;
00073 }
00074
00082 uint GetGroupNumEngines(PlayerID p, GroupID id_g, EngineID id_e);
00083
00084 static inline void IncreaseGroupNumVehicle(GroupID id_g)
00085 {
00086 if (IsValidGroupID(id_g)) GetGroup(id_g)->num_vehicle++;
00087 }
00088
00089 static inline void DecreaseGroupNumVehicle(GroupID id_g)
00090 {
00091 if (IsValidGroupID(id_g)) GetGroup(id_g)->num_vehicle--;
00092 }
00093
00094
00095 void InitializeGroup();
00096 void SetTrainGroupID(Vehicle *v, GroupID grp);
00097 void UpdateTrainGroupID(Vehicle *v);
00098 void RemoveVehicleFromGroup(const Vehicle *v);
00099 void RemoveAllGroupsForPlayer(const PlayerID p);
00100
00101 #endif