# group.h File Reference

Base class from groups. More...

`#include "group_type.h"`
`#include "oldpool.h"`
`#include "company_type.h"`
`#include "vehicle_type.h"`
`#include "engine_type.h"`

Go to the source code of this file.

## Data Structures

struct | Group

## Defines

#define | FOR_ALL_GROUPS_FROM(g, start) for (g = GetGroup(start); g != NULL; g = (g->index + 1U < GetGroupPoolSize()) ? GetGroup(g->index + 1) : NULL) if (g->IsValid())
#define | FOR_ALL_GROUPS(g) FOR_ALL_GROUPS_FROM(g, 0)

## Functions

static bool | IsValidGroupID (GroupID index)
static bool | IsDefaultGroupID (GroupID index)
static bool | IsAllGroupID (GroupID id_g)
| Checks if a GroupID stands for all vehicles of a company.
static uint | GetGroupArraySize (void)
| Get the current size of the GroupPool.
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.
static void | IncreaseGroupNumVehicle (GroupID id_g)
static void | DecreaseGroupNumVehicle (GroupID id_g)
void | InitializeGroup ()
void | SetTrainGroupID (Vehicle *v, GroupID grp)
| Affect the groupID of a train to new_g.
void | UpdateTrainGroupID (Vehicle *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)

## Variables

GroupID | _new_group_id

## Detailed Description

Base class from groups.

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.

Parameters:

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

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

static bool IsAllGroupID | ( | GroupID | id_g | ) | `[inline, static]`

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

Referenced by CmdSetAutoReplace().

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

Referenced by CmdMoveRailVehicle().

void SetTrainGroupID | ( | Vehicle * | 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 357 of file group_cmd.cpp.

References InvalidateWindow(), IsEngineCountable(), IsFrontEngine(), and UpdateNumEngineGroup().

Referenced by CmdAddVehicleGroup(), and CmdMoveRailVehicle().

void UpdateTrainGroupID | ( | Vehicle * | 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 381 of file group_cmd.cpp.

References DEFAULT_GROUP, InvalidateWindow(), IsEngineCountable(), IsFreeWagon(), IsFrontEngine(), and UpdateNumEngineGroup().

Referenced by CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdMoveRailVehicle(), and CmdSellRailWagon().