OpenTTD: src/group.h File Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

Data Structures | Macros | Typedefs | Functions | Variables
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"`

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...

## Macros
#define | FOR_ALL_GROUPS_FROM(var, start) FOR_ALL_ITEMS_FROM(Group, group_index, var, start)
#define | FOR_ALL_GROUPS(var) FOR_ALL_GROUPS_FROM(var, 0)

## Typedefs
typedef Pool< Group, GroupID, 16, 64000 > | GroupPool

## Functions
static bool | IsDefaultGroupID (GroupID index)
static 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.
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 | RemoveVehicleFromGroup (const Vehicle *v)
| Decrease the num_vehicle variable before delete an front engine from a group.
void | RemoveAllGroupsForCompany (const CompanyID company)
bool | GroupIsInGroup (GroupID search, GroupID group)
| Test if GroupID group is a descendant of (or is) GroupID search.

## Variables
GroupPool | _group_pool
| Pool of groups.
GroupID | _new_group_id

## Detailed Description

Base class for groups and group functions.

Definition in file group.h.

## Function Documentation

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

  company | The company the group belongs to
  id_g | The GroupID of the group used
  id_e | The EngineID of the engine to count

Returns
  The number of engines with EngineID id_e in the group

Definition at line 693 of file group_cmd.cpp.

References GroupStatistics::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetGroupNumEngines(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, GroupStatistics::num_engines, Group::parent, and Engine::type.

Referenced by DrawEngineList(), ReplaceVehicleWindow::GenerateReplaceVehList(), GetGroupNumEngines(), and InvalidateAutoreplaceWindow().

bool GroupIsInGroup | ( | GroupID | search,
|  | GroupID | group
| ) |  |

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

Parameters

  search | The GroupID to search in
  group | The GroupID to search for

Returns
  True iff group is search or a descendant of search

Definition at line 720 of file group_cmd.cpp.

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

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

static bool IsAllGroupID | ( | GroupID | id_g | ) |
| inlinestatic

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

Parameters

  id_g | The GroupID to check

Returns
  true is id_g is identical to ALL_GROUP

Definition at line 91 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().

void RemoveVehicleFromGroup | ( | const Vehicle * | v | ) |

Decrease the num_vehicle variable before delete an front engine from a group.

Note
  Called in CmdSellRailWagon and DeleteLasWagon,

Parameters

  v | FrontEngine of the train we want to remove.

Definition at line 630 of file group_cmd.cpp.

References GroupStatistics::CountVehicle(), Vehicle::group_id, and Vehicle::IsPrimaryVehicle().

Referenced by CmdMoveRailVehicle().

void SetTrainGroupID | ( | Train * | v,
|  | GroupID | new_g
| ) |  |

Affect the groupID of a train to new_g.

Note
  called in CmdAddVehicleGroup and CmdMoveRailVehicle

Parameters

  v | First vehicle of the chain.
  new_g | index of array group

Definition at line 644 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().

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

  v | First vehicle of the chain.

Definition at line 669 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().