2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2011-05-14 20:38:54 +02:00
|
|
|
/** @file group.h Base class for groups and group functions. */
|
2007-05-19 11:40:18 +02:00
|
|
|
|
|
|
|
#ifndef GROUP_H
|
|
|
|
#define GROUP_H
|
|
|
|
|
2008-03-28 17:34:50 +01:00
|
|
|
#include "group_type.h"
|
2009-05-22 17:39:22 +02:00
|
|
|
#include "core/pool_type.hpp"
|
2008-09-30 22:51:04 +02:00
|
|
|
#include "company_type.h"
|
2008-01-12 15:10:35 +01:00
|
|
|
#include "vehicle_type.h"
|
2008-03-31 02:17:39 +02:00
|
|
|
#include "engine_type.h"
|
2019-01-31 14:57:44 +01:00
|
|
|
#include "livery.h"
|
2007-05-19 11:40:18 +02:00
|
|
|
|
2009-05-22 17:13:50 +02:00
|
|
|
typedef Pool<Group, GroupID, 16, 64000> GroupPool;
|
2011-05-14 20:38:54 +02:00
|
|
|
extern GroupPool _group_pool; ///< Pool of groups.
|
2007-08-02 14:51:57 +02:00
|
|
|
|
2011-10-03 19:20:26 +02:00
|
|
|
/** Statistics and caches on the vehicles in a group. */
|
|
|
|
struct GroupStatistics {
|
2023-01-22 14:14:02 +01:00
|
|
|
Money profit_last_year; ///< Sum of profits for all vehicles.
|
|
|
|
Money profit_last_year_min_age; ///< Sum of profits for vehicles considered for profit statistics.
|
2024-01-21 15:09:44 +01:00
|
|
|
std::map<EngineID, uint16_t> num_engines; ///< Caches the number of engines of each type the company owns.
|
2023-05-08 19:01:06 +02:00
|
|
|
uint16_t num_vehicle; ///< Number of vehicles.
|
|
|
|
uint16_t num_vehicle_min_age; ///< Number of vehicles considered for profit statistics;
|
2011-10-03 19:26:37 +02:00
|
|
|
bool autoreplace_defined; ///< Are any autoreplace rules set?
|
|
|
|
bool autoreplace_finished; ///< Have all autoreplacement finished?
|
|
|
|
|
2011-10-03 19:20:26 +02:00
|
|
|
void Clear();
|
2011-10-03 19:20:56 +02:00
|
|
|
|
2011-10-03 19:25:44 +02:00
|
|
|
void ClearProfits()
|
|
|
|
{
|
|
|
|
this->profit_last_year = 0;
|
2023-01-22 14:14:02 +01:00
|
|
|
|
|
|
|
this->num_vehicle_min_age = 0;
|
|
|
|
this->profit_last_year_min_age = 0;
|
2011-10-03 19:25:44 +02:00
|
|
|
}
|
|
|
|
|
2011-10-03 19:26:37 +02:00
|
|
|
void ClearAutoreplace()
|
|
|
|
{
|
|
|
|
this->autoreplace_defined = false;
|
|
|
|
this->autoreplace_finished = false;
|
|
|
|
}
|
|
|
|
|
2024-01-21 15:09:44 +01:00
|
|
|
uint16_t GetNumEngines(EngineID engine) const;
|
|
|
|
|
2011-10-03 19:21:41 +02:00
|
|
|
static GroupStatistics &Get(CompanyID company, GroupID id_g, VehicleType type);
|
|
|
|
static GroupStatistics &Get(const Vehicle *v);
|
2011-10-03 19:23:41 +02:00
|
|
|
static GroupStatistics &GetAllGroup(const Vehicle *v);
|
2011-10-03 19:21:41 +02:00
|
|
|
|
|
|
|
static void CountVehicle(const Vehicle *v, int delta);
|
2011-10-03 19:22:09 +02:00
|
|
|
static void CountEngine(const Vehicle *v, int delta);
|
2023-01-22 14:14:02 +01:00
|
|
|
static void AddProfitLastYear(const Vehicle *v);
|
|
|
|
static void VehicleReachedMinAge(const Vehicle *v);
|
2011-10-03 19:21:41 +02:00
|
|
|
|
2011-10-03 19:25:44 +02:00
|
|
|
static void UpdateProfits();
|
2011-10-03 19:20:56 +02:00
|
|
|
static void UpdateAfterLoad();
|
2011-10-03 19:26:37 +02:00
|
|
|
static void UpdateAutoreplace(CompanyID company);
|
2011-10-03 19:20:26 +02:00
|
|
|
};
|
|
|
|
|
2023-05-08 19:01:06 +02:00
|
|
|
enum GroupFlags : uint8_t {
|
2019-03-30 08:13:08 +01:00
|
|
|
GF_REPLACE_PROTECTION, ///< If set to true, the global autoreplace has no effect on the group
|
|
|
|
GF_REPLACE_WAGON_REMOVAL, ///< If set, autoreplace will perform wagon removal on vehicles in this group.
|
2019-03-30 00:44:28 +01:00
|
|
|
GF_END,
|
2019-03-30 00:24:40 +01:00
|
|
|
};
|
|
|
|
|
2011-05-14 20:38:54 +02:00
|
|
|
/** Group data. */
|
2009-05-22 17:13:50 +02:00
|
|
|
struct Group : GroupPool::PoolItem<&_group_pool> {
|
2020-05-17 23:31:59 +02:00
|
|
|
std::string name; ///< Group Name
|
2019-04-22 10:10:04 +02:00
|
|
|
Owner owner; ///< Group Owner
|
2019-04-21 23:25:54 +02:00
|
|
|
VehicleType vehicle_type; ///< Vehicle type of the group
|
2007-05-19 11:40:18 +02:00
|
|
|
|
2023-05-08 19:01:06 +02:00
|
|
|
uint8_t flags; ///< Group flags
|
2019-04-21 23:25:54 +02:00
|
|
|
Livery livery; ///< Custom colour scheme for vehicles in this group
|
|
|
|
GroupStatistics statistics; ///< NOSAVE: Statistics and caches on the vehicles in the group.
|
2007-05-19 11:40:18 +02:00
|
|
|
|
2019-04-21 23:25:54 +02:00
|
|
|
bool folded; ///< NOSAVE: Is this group folded in the group view?
|
2019-03-26 01:35:01 +01:00
|
|
|
|
2019-04-21 23:25:54 +02:00
|
|
|
GroupID parent; ///< Parent group
|
2014-04-08 23:09:06 +02:00
|
|
|
|
2008-09-30 22:39:50 +02:00
|
|
|
Group(CompanyID owner = INVALID_COMPANY);
|
2007-08-02 14:51:57 +02:00
|
|
|
};
|
2007-05-19 11:40:18 +02:00
|
|
|
|
|
|
|
|
2024-01-06 12:19:27 +01:00
|
|
|
inline bool IsDefaultGroupID(GroupID index)
|
2007-05-19 11:40:18 +02:00
|
|
|
{
|
2007-07-15 01:10:27 +02:00
|
|
|
return index == DEFAULT_GROUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-09-30 22:39:50 +02:00
|
|
|
* Checks if a GroupID stands for all vehicles of a company
|
2007-07-15 01:10:27 +02:00
|
|
|
* @param id_g The GroupID to check
|
|
|
|
* @return true is id_g is identical to ALL_GROUP
|
|
|
|
*/
|
2024-01-06 12:19:27 +01:00
|
|
|
inline bool IsAllGroupID(GroupID id_g)
|
2007-07-15 01:10:27 +02:00
|
|
|
{
|
|
|
|
return id_g == ALL_GROUP;
|
2007-05-19 11:40:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-30 22:39:50 +02:00
|
|
|
uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e);
|
2019-03-26 01:07:20 +01:00
|
|
|
uint GetGroupNumVehicle(CompanyID company, GroupID id_g, VehicleType type);
|
2023-01-22 14:14:02 +01:00
|
|
|
uint GetGroupNumVehicleMinAge(CompanyID company, GroupID id_g, VehicleType type);
|
|
|
|
Money GetGroupProfitLastYearMinAge(CompanyID company, GroupID id_g, VehicleType type);
|
2007-07-15 01:10:27 +02:00
|
|
|
|
2009-07-02 00:22:01 +02:00
|
|
|
void SetTrainGroupID(Train *v, GroupID grp);
|
|
|
|
void UpdateTrainGroupID(Train *v);
|
2008-09-30 22:39:50 +02:00
|
|
|
void RemoveAllGroupsForCompany(const CompanyID company);
|
2014-04-08 23:09:06 +02:00
|
|
|
bool GroupIsInGroup(GroupID search, GroupID group);
|
2023-12-27 16:26:33 +01:00
|
|
|
void UpdateCompanyGroupLiveries(const Company *c);
|
2007-05-19 11:40:18 +02:00
|
|
|
|
|
|
|
#endif /* GROUP_H */
|