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 GroupStatistics {
00026 uint16 num_vehicle;
00027 uint16 *num_engines;
00028
00029 bool autoreplace_defined;
00030 bool autoreplace_finished;
00031
00032 uint16 num_profit_vehicle;
00033 Money profit_last_year;
00034
00035 GroupStatistics();
00036 ~GroupStatistics();
00037
00038 void Clear();
00039
00040 void ClearProfits()
00041 {
00042 this->num_profit_vehicle = 0;
00043 this->profit_last_year = 0;
00044 }
00045
00046 void ClearAutoreplace()
00047 {
00048 this->autoreplace_defined = false;
00049 this->autoreplace_finished = false;
00050 }
00051
00052 static GroupStatistics &Get(CompanyID company, GroupID id_g, VehicleType type);
00053 static GroupStatistics &Get(const Vehicle *v);
00054 static GroupStatistics &GetAllGroup(const Vehicle *v);
00055
00056 static void CountVehicle(const Vehicle *v, int delta);
00057 static void CountEngine(const Vehicle *v, int delta);
00058 static void VehicleReachedProfitAge(const Vehicle *v);
00059
00060 static void UpdateProfits();
00061 static void UpdateAfterLoad();
00062 static void UpdateAutoreplace(CompanyID company);
00063 };
00064
00066 struct Group : GroupPool::PoolItem<&_group_pool> {
00067 char *name;
00068 OwnerByte owner;
00069 VehicleTypeByte vehicle_type;
00070
00071 bool replace_protection;
00072 GroupStatistics statistics;
00073
00074 Group(CompanyID owner = INVALID_COMPANY);
00075 ~Group();
00076 };
00077
00078
00079 static inline bool IsDefaultGroupID(GroupID index)
00080 {
00081 return index == DEFAULT_GROUP;
00082 }
00083
00089 static inline bool IsAllGroupID(GroupID id_g)
00090 {
00091 return id_g == ALL_GROUP;
00092 }
00093
00094 #define FOR_ALL_GROUPS_FROM(var, start) FOR_ALL_ITEMS_FROM(Group, group_index, var, start)
00095 #define FOR_ALL_GROUPS(var) FOR_ALL_GROUPS_FROM(var, 0)
00096
00097
00098 uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e);
00099
00100 void SetTrainGroupID(Train *v, GroupID grp);
00101 void UpdateTrainGroupID(Train *v);
00102 void RemoveVehicleFromGroup(const Vehicle *v);
00103 void RemoveAllGroupsForCompany(const CompanyID company);
00104
00105 extern GroupID _new_group_id;
00106
00107 #endif