OpenTTD

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 ()

## Static Public Member Functions
static GroupStatistics & | Get (CompanyID company, GroupID id_g, VehicleType type)
| Returns the GroupStatistics for a specific group. More...
static GroupStatistics & | Get (const Vehicle *v)
| Returns the GroupStatistic for the group of a vehicle. More...
static GroupStatistics & | GetAllGroup (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 | VehicleReachedProfitAge (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. More...
static void | UpdateAutoreplace (CompanyID company)
| Update autoreplace_defined and autoreplace_finished of all statistics of a company. More...

## Data Fields
uint16 | num_vehicle
| Number of vehicles.
uint16 * | num_engines
| Caches the number of engines of each type the company owns.
bool | autoreplace_defined
| Are any autoreplace rules set?
bool | autoreplace_finished
| Have all autoreplacement finished?
uint16 | num_profit_vehicle
| Number of vehicles considered for profit statistics;.
Money | profit_last_year
| Sum of profits for all vehicles.

## Detailed Description

Statistics and caches on the vehicles in a group.

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

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

Definition at line 161 of file group_cmd.cpp.

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

Referenced by AddVehicleToGroup(), and CmdSellRailWagon().

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

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

Referenced by Get(), GetAllGroup(), UpdateNumEngineGroup(), and VehicleReachedProfitAge().

## ◆ 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 85 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

  v | Vehicle.

Returns
  GroupStatistics for the ALL_GROUP of the vehicle type.

Definition at line 95 of file group_cmd.cpp.

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

Referenced by VehicleReachedProfitAge().

## ◆ UpdateAfterLoad()

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

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

Definition at line 103 of file group_cmd.cpp.

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

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

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

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