Fix #10490: Allow ships to exit depots if another is not moving at the exit point...
[openttd-github.git] / src / group.h
blob3886b155c4459fd2b81ae15c8b0e11aa2334deac
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 */
8 /** @file group.h Base class for groups and group functions. */
10 #ifndef GROUP_H
11 #define GROUP_H
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"
20 typedef Pool<Group, GroupID, 16, 64000> GroupPool;
21 extern GroupPool _group_pool; ///< Pool of groups.
23 /** Statistics and caches on the vehicles in a group. */
24 struct GroupStatistics {
25 Money profit_last_year; ///< Sum of profits for all vehicles.
26 Money profit_last_year_min_age; ///< Sum of profits for vehicles considered for profit statistics.
27 std::map<EngineID, uint16_t> num_engines; ///< Caches the number of engines of each type the company owns.
28 uint16_t num_vehicle; ///< Number of vehicles.
29 uint16_t num_vehicle_min_age; ///< Number of vehicles considered for profit statistics;
30 bool autoreplace_defined; ///< Are any autoreplace rules set?
31 bool autoreplace_finished; ///< Have all autoreplacement finished?
33 void Clear();
35 void ClearProfits()
37 this->profit_last_year = 0;
39 this->num_vehicle_min_age = 0;
40 this->profit_last_year_min_age = 0;
43 void ClearAutoreplace()
45 this->autoreplace_defined = false;
46 this->autoreplace_finished = false;
49 uint16_t GetNumEngines(EngineID engine) const;
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);
55 static void CountVehicle(const Vehicle *v, int delta);
56 static void CountEngine(const Vehicle *v, int delta);
57 static void AddProfitLastYear(const Vehicle *v);
58 static void VehicleReachedMinAge(const Vehicle *v);
60 static void UpdateProfits();
61 static void UpdateAfterLoad();
62 static void UpdateAutoreplace(CompanyID company);
65 enum GroupFlags : uint8_t {
66 GF_REPLACE_PROTECTION, ///< If set to true, the global autoreplace has no effect on the group
67 GF_REPLACE_WAGON_REMOVAL, ///< If set, autoreplace will perform wagon removal on vehicles in this group.
68 GF_END,
71 /** Group data. */
72 struct Group : GroupPool::PoolItem<&_group_pool> {
73 std::string name; ///< Group Name
74 Owner owner; ///< Group Owner
75 VehicleType vehicle_type; ///< Vehicle type of the group
77 uint8_t flags; ///< Group flags
78 Livery livery; ///< Custom colour scheme for vehicles in this group
79 GroupStatistics statistics; ///< NOSAVE: Statistics and caches on the vehicles in the group.
81 bool folded; ///< NOSAVE: Is this group folded in the group view?
83 GroupID parent; ///< Parent group
85 Group(CompanyID owner = INVALID_COMPANY);
89 inline bool IsDefaultGroupID(GroupID index)
91 return index == DEFAULT_GROUP;
94 /**
95 * Checks if a GroupID stands for all vehicles of a company
96 * @param id_g The GroupID to check
97 * @return true is id_g is identical to ALL_GROUP
99 inline bool IsAllGroupID(GroupID id_g)
101 return id_g == ALL_GROUP;
105 uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e);
106 uint GetGroupNumVehicle(CompanyID company, GroupID id_g, VehicleType type);
107 uint GetGroupNumVehicleMinAge(CompanyID company, GroupID id_g, VehicleType type);
108 Money GetGroupProfitLastYearMinAge(CompanyID company, GroupID id_g, VehicleType type);
110 void SetTrainGroupID(Train *v, GroupID grp);
111 void UpdateTrainGroupID(Train *v);
112 void RemoveAllGroupsForCompany(const CompanyID company);
113 bool GroupIsInGroup(GroupID search, GroupID group);
114 void UpdateCompanyGroupLiveries(const Company *c);
116 #endif /* GROUP_H */