OpenTTD Source  20241109-master-g5e4f8db7d6
GroupStatistics Struct Reference

Statistics and caches on the vehicles in a group. More...

#include <group.h>

Public Member Functions

void Clear ()
 Clear all caches.
 
void ClearProfits ()
 
void ClearAutoreplace ()
 
uint16_t GetNumEngines (EngineID engine) const
 Get number of vehicles of a specific engine ID. More...
 

Static Public Member Functions

static GroupStatisticsGet (CompanyID company, GroupID id_g, VehicleType type)
 Returns the GroupStatistics for a specific group. More...
 
static GroupStatisticsGet (const Vehicle *v)
 Returns the GroupStatistic for the group of a vehicle. More...
 
static GroupStatisticsGetAllGroup (const Vehicle *v)
 Returns the GroupStatistic for the ALL_GROUPO of a vehicle type. More...
 
static void CountVehicle (const Vehicle *v, int delta)
 Update num_vehicle when adding or removing a vehicle. More...
 
static void CountEngine (const Vehicle *v, int delta)
 Update num_engines when adding/removing an engine. More...
 
static void AddProfitLastYear (const Vehicle *v)
 Add a vehicle's last year profit to the profit sum of its group.
 
static void VehicleReachedMinAge (const Vehicle *v)
 Add a vehicle to the profit sum of its group.
 
static void UpdateProfits ()
 Recompute the profits for all groups.
 
static void UpdateAfterLoad ()
 Update all caches after loading a game, changing NewGRF, etc.
 
static void UpdateAutoreplace (CompanyID company)
 Update autoreplace_defined and autoreplace_finished of all statistics of a company. More...
 

Data Fields

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.
 
std::map< EngineID, uint16_t > num_engines
 Caches the number of engines of each type the company owns.
 
uint16_t num_vehicle
 Number of vehicles.
 
uint16_t num_vehicle_min_age
 Number of vehicles considered for profit statistics;.
 
bool autoreplace_defined
 Are any autoreplace rules set?
 
bool autoreplace_finished
 Have all autoreplacement finished?
 

Detailed Description

Statistics and caches on the vehicles in a group.

Definition at line 24 of file group.h.

Member Function Documentation

◆ CountEngine()

void GroupStatistics::CountEngine ( const Vehicle v,
int  delta 
)
static

Update num_engines when adding/removing an engine.

Parameters
vEngine to count.
delta+1 to add, -1 to remove.

Definition at line 158 of file group_cmd.cpp.

References Vehicle::engine_type, Get(), GetAllGroup(), and num_engines.

Referenced by ChangeOwnershipOfCompanyItems().

◆ CountVehicle()

void GroupStatistics::CountVehicle ( const Vehicle v,
int  delta 
)
static

Update num_vehicle when adding or removing a vehicle.

Parameters
vVehicle to count.
delta+1 to add, -1 to remove.

Definition at line 133 of file group_cmd.cpp.

References Vehicle::economy_age, Get(), GetAllGroup(), Vehicle::GetDisplayProfitLastYear(), num_vehicle, num_vehicle_min_age, profit_last_year, profit_last_year_min_age, and VEHICLE_PROFIT_MIN_AGE.

Referenced by AddVehicleToGroup(), ChangeOwnershipOfCompanyItems(), and CmdSellRailWagon().

◆ Get() [1/2]

◆ Get() [2/2]

GroupStatistics & GroupStatistics::Get ( const Vehicle v)
static

Returns the GroupStatistic for the group of a vehicle.

Parameters
vVehicle.
Returns
GroupStatistics for the group of the vehicle.

Definition at line 83 of file group_cmd.cpp.

References Get(), Vehicle::group_id, Vehicle::owner, and BaseVehicle::type.

◆ GetAllGroup()

GroupStatistics & GroupStatistics::GetAllGroup ( const Vehicle v)
static

Returns the GroupStatistic for the ALL_GROUPO of a vehicle type.

Parameters
vVehicle.
Returns
GroupStatistics for the ALL_GROUP of the vehicle type.

Definition at line 93 of file group_cmd.cpp.

References ALL_GROUP, Get(), Vehicle::owner, and BaseVehicle::type.

Referenced by AddProfitLastYear(), CountEngine(), CountVehicle(), and VehicleReachedMinAge().

◆ GetNumEngines()

uint16_t GroupStatistics::GetNumEngines ( EngineID  engine) const

Get number of vehicles of a specific engine ID.

Parameters
engineEngine ID.
Returns
number of vehicles of this engine ID.

Definition at line 49 of file group_cmd.cpp.

Referenced by GetGroupNumEngines().

◆ UpdateAutoreplace()

void GroupStatistics::UpdateAutoreplace ( CompanyID  company)
static

Update autoreplace_defined and autoreplace_finished of all statistics of a company.

Parameters
companyCompany to update statistics for.

Definition at line 221 of file group_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get().

Referenced by CmdAlterGroup().


The documentation for this struct was generated from the following files: