OpenTTD
group.h
Go to the documentation of this file.
1 /* $Id: group.h 26450 2014-04-08 21:09:06Z peter1138 $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #ifndef GROUP_H
13 #define GROUP_H
14 
15 #include "group_type.h"
16 #include "core/pool_type.hpp"
17 #include "company_type.h"
18 #include "vehicle_type.h"
19 #include "engine_type.h"
20 
22 extern GroupPool _group_pool;
23 
26  uint16 num_vehicle;
27  uint16 *num_engines;
28 
31 
34 
36  ~GroupStatistics();
37 
38  void Clear();
39 
40  void ClearProfits()
41  {
42  this->num_profit_vehicle = 0;
43  this->profit_last_year = 0;
44  }
45 
46  void ClearAutoreplace()
47  {
48  this->autoreplace_defined = false;
49  this->autoreplace_finished = false;
50  }
51 
52  static GroupStatistics &Get(CompanyID company, GroupID id_g, VehicleType type);
53  static GroupStatistics &Get(const Vehicle *v);
54  static GroupStatistics &GetAllGroup(const Vehicle *v);
55 
56  static void CountVehicle(const Vehicle *v, int delta);
57  static void CountEngine(const Vehicle *v, int delta);
58  static void VehicleReachedProfitAge(const Vehicle *v);
59 
60  static void UpdateProfits();
61  static void UpdateAfterLoad();
62  static void UpdateAutoreplace(CompanyID company);
63 };
64 
66 struct Group : GroupPool::PoolItem<&_group_pool> {
67  char *name;
70 
73 
75 
77  ~Group();
78 };
79 
80 
81 static inline bool IsDefaultGroupID(GroupID index)
82 {
83  return index == DEFAULT_GROUP;
84 }
85 
91 static inline bool IsAllGroupID(GroupID id_g)
92 {
93  return id_g == ALL_GROUP;
94 }
95 
96 #define FOR_ALL_GROUPS_FROM(var, start) FOR_ALL_ITEMS_FROM(Group, group_index, var, start)
97 #define FOR_ALL_GROUPS(var) FOR_ALL_GROUPS_FROM(var, 0)
98 
99 
100 uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e);
101 
102 void SetTrainGroupID(Train *v, GroupID grp);
103 void UpdateTrainGroupID(Train *v);
104 void RemoveVehicleFromGroup(const Vehicle *v);
105 void RemoveAllGroupsForCompany(const CompanyID company);
106 bool GroupIsInGroup(GroupID search, GroupID group);
107 
108 extern GroupID _new_group_id;
109 
110 #endif /* GROUP_H */