OpenTTD Source: GroupStatistics Struct Reference

OpenTTD Source 15.0-RC2

Public Member Functions | Static Public Member Functions | Data Fields
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.

## Static Public Member Functions
static GroupStatistics & | Get (CompanyID company, GroupID id_g, VehicleType type)
| Returns the GroupStatistics for a specific group.
static GroupStatistics & | Get (const Vehicle *v)
| Returns the GroupStatistic for the group of a vehicle.
static GroupStatistics & | GetAllGroup (const Vehicle *v)
| Returns the GroupStatistic for the ALL_GROUP of a vehicle type.
static void | CountVehicle (const Vehicle *v, int delta)
| Update num_vehicle when adding or removing a vehicle.
static void | CountEngine (const Vehicle *v, int delta)
| Update num_engines when adding/removing an engine.
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.

## Data Fields
Money | profit_last_year = 0
| Sum of profits for all vehicles.
Money | profit_last_year_min_age = 0
| 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 = 0
| Number of vehicles.
uint16_t | num_vehicle_min_age = 0
| Number of vehicles considered for profit statistics;.
bool | autoreplace_defined = false
| Are any autoreplace rules set?
bool | autoreplace_finished = false
| Have all autoreplacement finished?

## Detailed Description

Statistics and caches on the vehicles in a group.

Definition at line 25 of file group.h.

## Member Function Documentation

## ◆ AddProfitLastYear()

void GroupStatistics::AddProfitLastYear | ( | const Vehicle * | v | ) |
| static

Add a vehicle's last year profit to the profit sum of its group.

Definition at line 178 of file group_cmd.cpp.

References Get(), GetAllGroup(), Vehicle::GetDisplayProfitLastYear(), and profit_last_year.

Referenced by CopyHeadSpecificThings(), and UpdateProfits().

## ◆ Clear()

void GroupStatistics::Clear | ( |  | ) |

Clear all caches.

Definition at line 33 of file group_cmd.cpp.

## ◆ ClearAutoreplace()

void GroupStatistics::ClearAutoreplace | ( |  | ) |
| inline

Definition at line 44 of file group.h.

## ◆ ClearProfits()

void GroupStatistics::ClearProfits | ( |  | ) |
| inline

Definition at line 36 of file group.h.

## ◆ CountEngine()

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

Update num_engines when adding/removing an engine.

Parameters

  v | Engine to count.
  delta | +1 to add, -1 to remove.

Definition at line 168 of file group_cmd.cpp.

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

Referenced by ChangeOwnershipOfCompanyItems(), CmdBuildVehicle(), Vehicle::PreDestructor(), and UpdateAfterLoad().

## ◆ CountVehicle()

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

Update num_vehicle when adding or removing a vehicle.

Parameters

  v | Vehicle to count.
  delta | +1 to add, -1 to remove.

Definition at line 143 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(), CmdBuildVehicle(), CmdMoveRailVehicle(), CmdSellRailWagon(), Vehicle::PreDestructor(), and UpdateAfterLoad().

## ◆ Get() [1/2]

GroupStatistics & GroupStatistics::Get | ( | CompanyID | company,
|  | GroupID | id_g,
|  | VehicleType | type
| ) |  |
| static

Returns the GroupStatistics for a specific group.

Parameters

  company | Owner of the group.
  id_g | GroupID of the group.
  type | VehicleType of the vehicles in the group.

Returns
  Statistics for the group.

Definition at line 73 of file group_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Get(), IsAllGroupID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::IsValidID(), Group::owner, Group::statistics, and Group::vehicle_type.

Referenced by AddProfitLastYear(), CountEngine(), CountVehicle(), VehicleGroupWindow::DrawGroupInfo(), Get(), GetAllGroup(), GetGroupNumEngines(), GetGroupNumVehicle(), GetGroupNumVehicleMinAge(), GetGroupProfitLastYearMinAge(), UpdateAutoreplace(), UpdateNumEngineGroup(), and VehicleReachedMinAge().

## ◆ Get() [2/2]

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

Returns the GroupStatistic for the group of a vehicle.

Parameters

  v | Vehicle.

Returns
  GroupStatistics for the group of the vehicle.

Definition at line 93 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_GROUP of a vehicle type.

Parameters

  v | Vehicle.

Returns
  GroupStatistics for the ALL_GROUP of the vehicle type.

Definition at line 103 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

  engine | Engine ID.

Returns
  number of vehicles of this engine ID.

Definition at line 59 of file group_cmd.cpp.

References num_engines.

Referenced by GetGroupNumEngines().

## ◆ UpdateAfterLoad()

void GroupStatistics::UpdateAfterLoad | ( |  | ) |
| static

Update all caches after loading a game, changing NewGRF, etc.

Definition at line 111 of file group_cmd.cpp.

References CountEngine(), CountVehicle(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), UpdateAutoreplace(), and VEH_COMPANY_END.

Referenced by AfterLoadGame(), InitializeWindowsAndCaches(), and ReloadNewGRFData().

## ◆ UpdateAutoreplace()

void GroupStatistics::UpdateAutoreplace | ( | CompanyID | company | ) |
| static

Update autoreplace_defined and autoreplace_finished of all statistics of a company.

Parameters

  company | Company to update statistics for.

Definition at line 231 of file group_cmd.cpp.

References autoreplace_defined, autoreplace_finished, CompanyProperties::engine_renew_list, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), Get(), GetGroupNumEngines(), Company::group_all, Company::group_default, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Iterate(), Engine::type, and VEH_COMPANY_END.

Referenced by ChangeOwnershipOfCompanyItems(), CmdAddVehicleGroup(), CmdAlterGroup(), CmdBuildVehicle(), CmdSetAutoReplace(), Vehicle::PreDestructor(), SetTrainGroupID(), UpdateAfterLoad(), and UpdateTrainGroupID().

## ◆ UpdateProfits()

void GroupStatistics::UpdateProfits | ( |  | ) |
| static

Recompute the profits for all groups.

Definition at line 204 of file group_cmd.cpp.

References AddProfitLastYear(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), VEH_COMPANY_END, VEHICLE_PROFIT_MIN_AGE, and VehicleReachedMinAge().

## ◆ VehicleReachedMinAge()

void GroupStatistics::VehicleReachedMinAge | ( | const Vehicle * | v | ) |
| static

Add a vehicle to the profit sum of its group.

Definition at line 190 of file group_cmd.cpp.

References Get(), GetAllGroup(), Vehicle::GetDisplayProfitLastYear(), num_vehicle_min_age, and profit_last_year_min_age.

Referenced by EconomyAgeVehicle(), and UpdateProfits().

## Field Documentation

## ◆ autoreplace_defined

bool GroupStatistics::autoreplace_defined = false

Are any autoreplace rules set?

Definition at line 31 of file group.h.

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

## ◆ autoreplace_finished

bool GroupStatistics::autoreplace_finished = false

Have all autoreplacement finished?

Definition at line 32 of file group.h.

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

## ◆ num_engines

std::map<EngineID, uint16_t> GroupStatistics::num_engines {}

Caches the number of engines of each type the company owns.

Definition at line 28 of file group.h.

Referenced by CountEngine(), GetNumEngines(), and UpdateNumEngineGroup().

## ◆ num_vehicle

uint16_t GroupStatistics::num_vehicle = 0

Number of vehicles.

Definition at line 29 of file group.h.

Referenced by CountVehicle(), VehicleGroupWindow::DrawGroupInfo(), and GetGroupNumVehicle().

## ◆ num_vehicle_min_age

uint16_t GroupStatistics::num_vehicle_min_age = 0

Number of vehicles considered for profit statistics;.

Definition at line 30 of file group.h.

Referenced by CountVehicle(), GetGroupNumVehicleMinAge(), and VehicleReachedMinAge().

## ◆ profit_last_year

Money GroupStatistics::profit_last_year = 0

Sum of profits for all vehicles.

Definition at line 26 of file group.h.

Referenced by AddProfitLastYear(), and CountVehicle().

## ◆ profit_last_year_min_age

Money GroupStatistics::profit_last_year_min_age = 0

Sum of profits for vehicles considered for profit statistics.

Definition at line 27 of file group.h.

Referenced by CountVehicle(), GetGroupProfitLastYearMinAge(), and VehicleReachedMinAge().

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

- src/group.h
- src/group_cmd.cpp