OpenTTD Source 20241224-master-gee860a5c8e
group.h File Reference

Base class for groups and group functions. More...

#include "group_type.h"
#include "core/pool_type.hpp"
#include "company_type.h"
#include "vehicle_type.h"
#include "engine_type.h"
#include "livery.h"

Go to the source code of this file.

Data Structures

struct  GroupStatistics
 Statistics and caches on the vehicles in a group. More...
 
struct  Group
 Group data. More...
 

Typedefs

typedef Pool< Group, GroupID, 16, 64000 > GroupPool
 

Enumerations

enum  GroupFlags : uint8_t { GF_REPLACE_PROTECTION , GF_REPLACE_WAGON_REMOVAL , GF_END }
 

Functions

bool IsDefaultGroupID (GroupID index)
 
bool IsAllGroupID (GroupID id_g)
 Checks if a GroupID stands for all vehicles of a company.
 
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.
 
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.
 
uint GetGroupNumVehicleMinAge (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.
 
Money GetGroupProfitLastYearMinAge (CompanyID company, GroupID id_g, VehicleType type)
 Get last year's profit of vehicles above minimum age for the group with GroupID id_g and its sub-groups.
 
void SetTrainGroupID (Train *v, GroupID grp)
 Affect the groupID of a train to new_g.
 
void UpdateTrainGroupID (Train *v)
 Recalculates the groupID of a train.
 
void RemoveAllGroupsForCompany (const CompanyID company)
 
bool GroupIsInGroup (GroupID search, GroupID group)
 Test if GroupID group is a descendant of (or is) GroupID search.
 
void UpdateCompanyGroupLiveries (const Company *c)
 Update group liveries for a company.
 

Variables

GroupPool _group_pool
 Pool of groups.
 

Detailed Description

Base class for groups and group functions.

Definition in file group.h.

Typedef Documentation

◆ GroupPool

typedef Pool<Group, GroupID, 16, 64000> GroupPool

Definition at line 20 of file group.h.

Enumeration Type Documentation

◆ GroupFlags

enum GroupFlags : uint8_t
Enumerator
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.

Definition at line 65 of file group.h.

Function Documentation

◆ GetGroupNumEngines()

uint GetGroupNumEngines ( CompanyID  company,
GroupID  id_g,
EngineID  id_e 
)

◆ GetGroupNumVehicle()

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.

Parameters
companyThe company the group belongs to
id_gThe GroupID of the group used
typeThe vehicle type of the group
Returns
The number of vehicles in the group

Definition at line 817 of file group_cmd.cpp.

References GroupStatistics::Get(), GetGroupNumVehicle(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::Iterate(), GroupStatistics::num_vehicle, and Group::parent.

Referenced by VehicleGroupWindow::ComputeGroupInfoSize(), VehicleGroupWindow::DrawGroupInfo(), GetGroupNumVehicle(), and VehicleGroupWindow::SetStringParameters().

◆ GetGroupNumVehicleMinAge()

uint GetGroupNumVehicleMinAge ( 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.

Parameters
companyThe company the group belongs to
id_gThe GroupID of the group used
typeThe vehicle type of the group
Returns
The number of vehicles above profit minimum age in the group

Definition at line 834 of file group_cmd.cpp.

References GroupStatistics::Get(), GetGroupNumVehicleMinAge(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::Iterate(), GroupStatistics::num_vehicle_min_age, and Group::parent.

Referenced by VehicleGroupWindow::DrawGroupInfo(), and GetGroupNumVehicleMinAge().

◆ GetGroupProfitLastYearMinAge()

Money GetGroupProfitLastYearMinAge ( CompanyID  company,
GroupID  id_g,
VehicleType  type 
)

Get last year's profit of vehicles above minimum age for the group with GroupID id_g and its sub-groups.

Parameters
companyThe company the group belongs to
id_gThe GroupID of the group used
typeThe vehicle type of the group
Returns
Last year's profit of vehicles above minimum age for the group

Definition at line 851 of file group_cmd.cpp.

References GroupStatistics::Get(), GetGroupProfitLastYearMinAge(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::Iterate(), Group::parent, and GroupStatistics::profit_last_year_min_age.

Referenced by VehicleGroupWindow::DrawGroupInfo(), and GetGroupProfitLastYearMinAge().

◆ GroupIsInGroup()

bool GroupIsInGroup ( GroupID  search,
GroupID  group 
)

Test if GroupID group is a descendant of (or is) GroupID search.

Parameters
searchThe GroupID to search in
groupThe GroupID to search for
Returns
True iff group is search or a descendant of search

Definition at line 874 of file group_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::Get(), INVALID_GROUP, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::IsValidID(), and Group::parent.

Referenced by CmdAlterGroup(), GenerateVehicleSortList(), and GetEngineReplacement().

◆ IsAllGroupID()

bool IsAllGroupID ( GroupID  id_g)
inline

Checks if a GroupID stands for all vehicles of a company.

Parameters
id_gThe GroupID to check
Returns
true is id_g is identical to ALL_GROUP

Definition at line 100 of file group.h.

References ALL_GROUP.

Referenced by CmdSetAutoReplace(), VehicleGroupWindow::DirtyHighlightedGroupWidget(), VehicleGroupWindow::DrawGroupInfo(), GroupStatistics::Get(), VehicleGroupWindow::OnClick(), VehicleGroupWindow::OnInvalidateData(), VehicleGroupWindow::OnPaint(), and VehicleGroupWindow::SetStringParameters().

◆ IsDefaultGroupID()

bool IsDefaultGroupID ( GroupID  index)
inline

Definition at line 90 of file group.h.

◆ RemoveAllGroupsForCompany()

void RemoveAllGroupsForCompany ( const CompanyID  company)

Definition at line 860 of file group_cmd.cpp.

◆ SetTrainGroupID()

void SetTrainGroupID ( Train v,
GroupID  new_g 
)

Affect the groupID of a train to new_g.

Note
called in CmdAddVehicleGroup and CmdMoveRailVehicle
Parameters
vFirst vehicle of the chain.
new_gindex of array group

Definition at line 745 of file group_cmd.cpp.

References Vehicle::IsFrontEngine(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::IsValidID(), SpecializedVehicle< T, Type >::Next(), Vehicle::owner, SetWindowDirty(), GroupStatistics::UpdateAutoreplace(), UpdateNumEngineGroup(), VEH_TRAIN, and WC_REPLACE_VEHICLE.

Referenced by AddVehicleToGroup(), and CmdMoveRailVehicle().

◆ UpdateCompanyGroupLiveries()

void UpdateCompanyGroupLiveries ( const Company c)

◆ UpdateTrainGroupID()

void UpdateTrainGroupID ( Train v)

Recalculates the groupID of a train.

Should be called each time a vehicle is added to/removed from the chain,.

Note
this needs to be called too for 'wagon chains' (in the depot, without an engine)
Called in CmdBuildRailVehicle, CmdBuildRailWagon, CmdMoveRailVehicle, CmdSellRailWagon
Parameters
vFirst vehicle of the chain.

Definition at line 773 of file group_cmd.cpp.

References DEFAULT_GROUP, Vehicle::group_id, GroundVehicle< T, Type >::IsFreeWagon(), Vehicle::IsFrontEngine(), SpecializedVehicle< T, Type >::Next(), Vehicle::owner, SetWindowDirty(), GroupStatistics::UpdateAutoreplace(), UpdateNumEngineGroup(), VEH_TRAIN, and WC_REPLACE_VEHICLE.

Referenced by CmdBuildRailVehicle(), CmdBuildRailWagon(), and NormaliseTrainHead().