# group.h File Reference

`#include "oldpool.h"`
`#include "player_type.h"`
`#include "vehicle_type.h"`
`#include "engine.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)
## Enumerations
enum | { ALL_GROUP = 0xFFFD, DEFAULT_GROUP = 0xFFFE, INVALID_GROUP = 0xFFFF }
## 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 player.
static uint | GetGroupArraySize (void)
| Get the current size of the GroupPool.
uint | GetGroupNumEngines (PlayerID p, 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 | RemoveAllGroupsForPlayer (const PlayerID p)

## Detailed Description

Definition in file group.h.

## Enumeration Type Documentation

anonymous enum

Enumerator:

  DEFAULT_GROUP | ungrouped vehicles are in this group.

Definition at line 13 of file group.h.

## Function Documentation

uint GetGroupNumEngines | ( | PlayerID | p,
|  | 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 402 of file group_cmd.cpp.

Referenced by DrawEngineList(), GenerateReplaceVehList(), and InvalidateAutoreplaceWindow().

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

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

Parameters:

  | id_g | The GroupID to check

Returns:
  true is id_g is identical to ALL_GROUP

Definition at line 54 of file group.h.

Referenced by CmdSetAutoReplace(), and GroupWndProc().

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

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

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

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