OpenTTD
group.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
10 #ifndef GROUP_H
11 #define GROUP_H
12 
13 #include "group_type.h"
14 #include "core/pool_type.hpp"
15 #include "company_type.h"
16 #include "vehicle_type.h"
17 #include "engine_type.h"
18 #include "livery.h"
19 
21 extern GroupPool _group_pool;
22 
25  uint16 num_vehicle;
26  uint16 *num_engines;
27 
30 
33 
35  ~GroupStatistics();
36 
37  void Clear();
38 
39  void ClearProfits()
40  {
41  this->num_profit_vehicle = 0;
42  this->profit_last_year = 0;
43  }
44 
45  void ClearAutoreplace()
46  {
47  this->autoreplace_defined = false;
48  this->autoreplace_finished = false;
49  }
50 
51  static GroupStatistics &Get(CompanyID company, GroupID id_g, VehicleType type);
52  static GroupStatistics &Get(const Vehicle *v);
53  static GroupStatistics &GetAllGroup(const Vehicle *v);
54 
55  static void CountVehicle(const Vehicle *v, int delta);
56  static void CountEngine(const Vehicle *v, int delta);
57  static void VehicleReachedProfitAge(const Vehicle *v);
58 
59  static void UpdateProfits();
60  static void UpdateAfterLoad();
61  static void UpdateAutoreplace(CompanyID company);
62 };
63 
65 struct Group : GroupPool::PoolItem<&_group_pool> {
66  char *name;
69 
73 
74  bool folded;
75 
77 
79  ~Group();
80 };
81 
82 
83 static inline bool IsDefaultGroupID(GroupID index)
84 {
85  return index == DEFAULT_GROUP;
86 }
87 
93 static inline bool IsAllGroupID(GroupID id_g)
94 {
95  return id_g == ALL_GROUP;
96 }
97 
98 
99 uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e);
100 uint GetGroupNumVehicle(CompanyID company, GroupID id_g, VehicleType type);
101 uint GetGroupNumProfitVehicle(CompanyID company, GroupID id_g, VehicleType type);
103 
104 void SetTrainGroupID(Train *v, GroupID grp);
105 void UpdateTrainGroupID(Train *v);
106 void RemoveVehicleFromGroup(const Vehicle *v);
107 void RemoveAllGroupsForCompany(const CompanyID company);
108 bool GroupIsInGroup(GroupID search, GroupID group);
109 
110 extern GroupID _new_group_id;
111 
112 #endif /* GROUP_H */
Owner
Enum for all companies/owners.
Definition: company_type.h:18
static void UpdateAfterLoad()
Update all caches after loading a game, changing NewGRF, etc.
Definition: group_cmd.cpp:101
bool replace_protection
If set to true, the global autoreplace have no effect on the group.
Definition: group.h:70
Owner owner
Group Owner.
Definition: group.h:67
VehicleType vehicle_type
Vehicle type of the group.
Definition: group.h:68
GroupStatistics statistics
NOSAVE: Statistics and caches on the vehicles in the group.
Definition: group.h:72
uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e)
Get the number of engines with EngineID id_e in the group with GroupID id_g and its sub-groups...
Definition: group_cmd.cpp:783
Types related to engines.
uint16 * num_engines
Caches the number of engines of each type the company owns.
Definition: group.h:26
bool GroupIsInGroup(GroupID search, GroupID group)
Test if GroupID group is a descendant of (or is) GroupID search.
Definition: group_cmd.cpp:858
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
Vehicle data structure.
Definition: vehicle_base.h:210
Money profit_last_year
Sum of profits for all vehicles.
Definition: group.h:32
bool autoreplace_finished
Have all autoreplacement finished?
Definition: group.h:29
uint16 num_profit_vehicle
Number of vehicles considered for profit statistics;.
Definition: group.h:31
uint GetGroupNumProfitVehicle(CompanyID company, GroupID id_g, VehicleType type)
Get the number of vehicles above profit minimum age in the group with GroupID id_g and its sub-groups...
Definition: group_cmd.cpp:818
static GroupStatistics & GetAllGroup(const Vehicle *v)
Returns the GroupStatistic for the ALL_GROUPO of a vehicle type.
Definition: group_cmd.cpp:93
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle...
GroupPool _group_pool
Pool of groups.
static bool IsAllGroupID(GroupID id_g)
Checks if a GroupID stands for all vehicles of a company.
Definition: group.h:93
Statistics and caches on the vehicles in a group.
Definition: group.h:24
char * name
Group Name.
Definition: group.h:66
void SetTrainGroupID(Train *v, GroupID grp)
Affect the groupID of a train to new_g.
Definition: group_cmd.cpp:729
uint16 GroupID
Type for all group identifiers.
Definition: group_type.h:13
Information about a particular livery.
Definition: livery.h:78
static GroupStatistics & Get(CompanyID company, GroupID id_g, VehicleType type)
Returns the GroupStatistics for a specific group.
Definition: group_cmd.cpp:63
static void CountVehicle(const Vehicle *v, int delta)
Update num_vehicle when adding or removing a vehicle.
Definition: group_cmd.cpp:133
uint GetGroupNumVehicle(CompanyID company, GroupID id_g, VehicleType type)
Get the number of vehicles in the group with GroupID id_g and its sub-groups.
Definition: group_cmd.cpp:801
void Clear()
Clear all caches.
Definition: group_cmd.cpp:45
uint16 num_vehicle
Number of vehicles.
Definition: group.h:25
void UpdateTrainGroupID(Train *v)
Recalculates the groupID of a train.
Definition: group_cmd.cpp:757
Base class for all PoolItems.
Definition: pool_type.hpp:188
Base class for all pools.
Definition: pool_type.hpp:82
&#39;Train&#39; is either a loco or a wagon.
Definition: train.h:85
Livery livery
Custom colour scheme for vehicles in this group.
Definition: group.h:71
static void UpdateProfits()
Recompute the profits for all groups.
Definition: group_cmd.cpp:180
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Definition: group_type.h:17
Functions/types related to livery colours.
An invalid company.
Definition: company_type.h:30
Money GetGroupProfitLastYear(CompanyID company, GroupID id_g, VehicleType type)
Get last year&#39;s profit for the group with GroupID id_g and its sub-groups.
Definition: group_cmd.cpp:835
GroupID parent
Parent group.
Definition: group.h:76
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
bool autoreplace_defined
Are any autoreplace rules set?
Definition: group.h:28
bool folded
NOSAVE: Is this group folded in the group view?
Definition: group.h:74
Types related to vehicles.
static void UpdateAutoreplace(CompanyID company)
Update autoreplace_defined and autoreplace_finished of all statistics of a company.
Definition: group_cmd.cpp:204
Group data.
Definition: group.h:65
static void CountEngine(const Vehicle *v, int delta)
Update num_engines when adding/removing an engine.
Definition: group_cmd.cpp:156
Types related to companies.
void RemoveVehicleFromGroup(const Vehicle *v)
Decrease the num_vehicle variable before delete an front engine from a group.
Definition: group_cmd.cpp:715
static void VehicleReachedProfitAge(const Vehicle *v)
Add a vehicle to the profit sum of its group.
Definition: group_cmd.cpp:166
Types of a group.
static const GroupID ALL_GROUP
All vehicles are in this group.
Definition: group_type.h:16