OpenTTD Source 20260208-master-g43af8e94d0
group.h File Reference

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

#include "group_type.h"
#include "core/flatset_type.hpp"
#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

using GroupPool = Pool<Group, GroupID, 16>
using GroupFlags = EnumBitSet<GroupFlag, uint8_t>

Enumerations

enum class  GroupFlag : uint8_t { ReplaceProtection = 0 , ReplaceWagonRemoval = 1 }
 Configuration flags for a group. More...

Functions

bool IsDefaultGroupID (GroupID index)
bool IsAllGroupID (GroupID id_g)
 Checks if a GroupID stands for all vehicles of a company.
void UpdateGroupChildren ()
 Update children list for each group.
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

◆ GroupFlags

using GroupFlags = EnumBitSet<GroupFlag, uint8_t>

Definition at line 71 of file group.h.

◆ GroupPool

using GroupPool = Pool<Group, GroupID, 16>

Definition at line 21 of file group.h.

Enumeration Type Documentation

◆ GroupFlag

enum class GroupFlag : uint8_t
strong

Configuration flags for a group.

Enumerator
ReplaceProtection 

If set, the global autoreplace has no effect on the group.

ReplaceWagonRemoval 

If set, autoreplace will perform wagon removal on vehicles in this group.

Definition at line 67 of file group.h.

Function Documentation

◆ GetGroupNumEngines()

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.

Parameters
companyThe company the group belongs to
id_gThe GroupID of the group used
id_eThe EngineID of the engine to count
Returns
The number of engines with EngineID id_e in the group

Definition at line 822 of file group_cmd.cpp.

References Group::children, GroupStatistics::Get(), GetGroupNumEngines(), and GroupStatistics::GetNumEngines().

Referenced by DrawEngineList(), ReplaceVehicleWindow::GenerateReplaceVehList(), GetGroupNumEngines(), InvalidateAutoreplaceWindow(), NewVehicleAvailable(), ReplaceVehicleWindow::OnClick(), and GroupStatistics::UpdateAutoreplace().

◆ 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 843 of file group_cmd.cpp.

References Group::children, GroupStatistics::Get(), GetGroupNumVehicle(), and GroupStatistics::num_vehicle.

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

◆ 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 864 of file group_cmd.cpp.

References Group::children, GroupStatistics::Get(), GetGroupNumVehicleMinAge(), and GroupStatistics::num_vehicle_min_age.

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

◆ 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 885 of file group_cmd.cpp.

References Group::children, GroupStatistics::Get(), GetGroupProfitLastYearMinAge(), and GroupStatistics::profit_last_year_min_age.

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

◆ 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 912 of file group_cmd.cpp.

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 104 of file group.h.

References ALL_GROUP.

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

◆ IsDefaultGroupID()

bool IsDefaultGroupID ( GroupID index)
inline

Definition at line 94 of file group.h.

◆ RemoveAllGroupsForCompany()

void RemoveAllGroupsForCompany ( const CompanyID company)

Definition at line 898 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 768 of file group_cmd.cpp.

References Vehicle::IsFrontEngine(), 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)

Update group liveries for a company.

This is called when the LS_DEFAULT scheme is changed, to update groups with colours set to default.

Parameters
cCompany to update.

Definition at line 329 of file group_cmd.cpp.

References Livery::colour1, Livery::colour2, Livery::in_use, Group::livery, Group::owner, Group::parent, Livery::Primary, PropagateChildLivery(), Livery::Secondary, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by UpdateCompanyLiveries().

◆ UpdateGroupChildren()

void UpdateGroupChildren ( )

Update children list for each group.

Definition at line 47 of file group_cmd.cpp.

References Group::children, Debug, Group::owner, and Group::vehicle_type.

Referenced by AfterLoadGame().

◆ 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 796 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().