Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef GROUP_H
00013 #define GROUP_H
00014
00015 #include "group_type.h"
00016 #include "core/pool_type.hpp"
00017 #include "company_type.h"
00018 #include "vehicle_type.h"
00019 #include "engine_type.h"
00020
00021 typedef Pool<Group, GroupID, 16, 64000> GroupPool;
00022 extern GroupPool _group_pool;
00023
00025 struct Group : GroupPool::PoolItem<&_group_pool> {
00026 char *name;
00027
00028 uint16 num_vehicle;
00029 OwnerByte owner;
00030 VehicleTypeByte vehicle_type;
00031
00032 bool replace_protection;
00033 uint16 *num_engines;
00034
00035 Group(CompanyID owner = INVALID_COMPANY);
00036 ~Group();
00037 };
00038
00039
00040 static inline bool IsDefaultGroupID(GroupID index)
00041 {
00042 return index == DEFAULT_GROUP;
00043 }
00044
00050 static inline bool IsAllGroupID(GroupID id_g)
00051 {
00052 return id_g == ALL_GROUP;
00053 }
00054
00055 #define FOR_ALL_GROUPS_FROM(var, start) FOR_ALL_ITEMS_FROM(Group, group_index, var, start)
00056 #define FOR_ALL_GROUPS(var) FOR_ALL_GROUPS_FROM(var, 0)
00057
00061 static inline uint GetGroupArraySize()
00062 {
00063 const Group *g;
00064 uint num = 0;
00065
00066 FOR_ALL_GROUPS(g) num++;
00067
00068 return num;
00069 }
00070
00071 uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e);
00072
00077 static inline void IncreaseGroupNumVehicle(GroupID id_g)
00078 {
00079 Group *g = Group::GetIfValid(id_g);
00080 if (g != NULL) g->num_vehicle++;
00081 }
00082
00087 static inline void DecreaseGroupNumVehicle(GroupID id_g)
00088 {
00089 Group *g = Group::GetIfValid(id_g);
00090 if (g != NULL) g->num_vehicle--;
00091 }
00092
00093
00094 void SetTrainGroupID(Train *v, GroupID grp);
00095 void UpdateTrainGroupID(Train *v);
00096 void RemoveVehicleFromGroup(const Vehicle *v);
00097 void RemoveAllGroupsForCompany(const CompanyID company);
00098
00099 extern GroupID _new_group_id;
00100
00101 #endif