group.h
Go to the documentation of this file.00001
00002
00005 #ifndef GROUP_H
00006 #define GROUP_H
00007
00008 #include "group_type.h"
00009 #include "oldpool.h"
00010 #include "company_type.h"
00011 #include "vehicle_type.h"
00012 #include "engine_type.h"
00013
00014 DECLARE_OLD_POOL(Group, Group, 5, 2047)
00015
00016 struct Group : PoolItem<Group, GroupID, &_Group_pool> {
00017 char *name;
00018
00019 uint16 num_vehicle;
00020 OwnerByte owner;
00021 VehicleTypeByte vehicle_type;
00022
00023 bool replace_protection;
00024 uint16 *num_engines;
00025
00026 Group(CompanyID owner = INVALID_COMPANY);
00027 virtual ~Group();
00028
00029 bool IsValid() const;
00030 };
00031
00032
00033 static inline bool IsValidGroupID(GroupID index)
00034 {
00035 return index < GetGroupPoolSize() && GetGroup(index)->IsValid();
00036 }
00037
00038 static inline bool IsDefaultGroupID(GroupID index)
00039 {
00040 return index == DEFAULT_GROUP;
00041 }
00042
00048 static inline bool IsAllGroupID(GroupID id_g)
00049 {
00050 return id_g == ALL_GROUP;
00051 }
00052
00053 #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())
00054 #define FOR_ALL_GROUPS(g) FOR_ALL_GROUPS_FROM(g, 0)
00055
00059 static inline uint GetGroupArraySize(void)
00060 {
00061 const Group *g;
00062 uint num = 0;
00063
00064 FOR_ALL_GROUPS(g) num++;
00065
00066 return num;
00067 }
00068
00076 uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e);
00077
00078 static inline void IncreaseGroupNumVehicle(GroupID id_g)
00079 {
00080 if (IsValidGroupID(id_g)) GetGroup(id_g)->num_vehicle++;
00081 }
00082
00083 static inline void DecreaseGroupNumVehicle(GroupID id_g)
00084 {
00085 if (IsValidGroupID(id_g)) GetGroup(id_g)->num_vehicle--;
00086 }
00087
00088
00089 void InitializeGroup();
00090 void SetTrainGroupID(Vehicle *v, GroupID grp);
00091 void UpdateTrainGroupID(Vehicle *v);
00092 void RemoveVehicleFromGroup(const Vehicle *v);
00093 void RemoveAllGroupsForCompany(const CompanyID company);
00094
00095 extern GroupID _new_group_id;
00096
00097 #endif