OpenTTD Source: src/group_cmd.cpp File Reference

OpenTTD Source 15.3

Functions | Variables
group_cmd.cpp File Reference

Handling of the engine groups. More...

`#include "stdafx.h"`
`#include "command_func.h"`
`#include "train.h"`
`#include "vehiclelist.h"`
`#include "vehicle_func.h"`
`#include "autoreplace_base.h"`
`#include "autoreplace_func.h"`
`#include "string_func.h"`
`#include "company_func.h"`
`#include "core/pool_func.hpp"`
`#include "order_backup.h"`
`#include "group_cmd.h"`
`#include "table/strings.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Functions
void | UpdateGroupChildren ()
| Update children list for each group.
static void | UpdateNumEngineGroup (const Vehicle *v, GroupID old_g, GroupID new_g)
| Update the num engines of a groupID.
const Livery * | GetParentLivery (const Group *g)
static void | PropagateChildLivery (const Group *g, bool reset_cache)
| Propagate a livery change to a group's children, and optionally update cached vehicle colourmaps.
void | UpdateCompanyGroupLiveries (const Company *c)
| Update group liveries for a company.
std::tuple< CommandCost, GroupID > | CmdCreateGroup (DoCommandFlags flags, VehicleType vt, GroupID parent_group)
| Create a new vehicle group.
CommandCost | CmdDeleteGroup (DoCommandFlags flags, GroupID group_id)
| Add all vehicles in the given group to the default group and then deletes the group.
CommandCost | CmdAlterGroup (DoCommandFlags flags, AlterGroupMode mode, GroupID group_id, GroupID parent_id, const std::string &text)
| Alter a group.
static void | AddVehicleToGroup (Vehicle *v, GroupID new_g)
| Do add a vehicle to a group.
std::tuple< CommandCost, GroupID > | CmdAddVehicleGroup (DoCommandFlags flags, GroupID group_id, VehicleID veh_id, bool add_shared, const VehicleListIdentifier &vli)
| Add a vehicle to a group.
CommandCost | CmdAddSharedVehicleGroup (DoCommandFlags flags, GroupID id_g, VehicleType type)
| Add all shared vehicles of all vehicles from a group.
CommandCost | CmdRemoveAllVehiclesGroup (DoCommandFlags flags, GroupID group_id)
| Remove all vehicles from a group.
CommandCost | CmdSetGroupLivery (DoCommandFlags flags, GroupID group_id, bool primary, Colours colour)
| Set the livery for a vehicle group.
static void | SetGroupFlag (Group *g, GroupFlag flag, bool set, bool children)
| Set group flag for a group and its sub-groups.
CommandCost | CmdSetGroupFlag (DoCommandFlags flags, GroupID group_id, GroupFlag flag, bool value, bool recursive)
| (Un)set group flag from a group
void | SetTrainGroupID (Train *v, GroupID new_g)
| Affect the groupID of a train to new_g.
void | UpdateTrainGroupID (Train *v)
| Recalculates the groupID of a train.
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.
uint | GetGroupNumVehicle (CompanyID company, GroupID id_g, VehicleType type)
| Get the number of vehicles in the group with GroupID id_g and its sub-groups.
uint | GetGroupNumVehicleMinAge (CompanyID company, GroupID id_g, VehicleType type)
| Get the number of vehicles above profit minimum age in the group with GroupID id_g and its sub-groups.
Money | GetGroupProfitLastYearMinAge (CompanyID company, GroupID id_g, VehicleType type)
| Get last year's profit of vehicles above minimum age for the group with GroupID id_g and its sub-groups.
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 ("Group")

## Detailed Description

Handling of the engine groups.

Definition in file group_cmd.cpp.

## Function Documentation

## ◆ AddVehicleToGroup()

static void AddVehicleToGroup | ( | Vehicle * | v,
|  | GroupID | new_g
| ) |  |
| static

Do add a vehicle to a group.

Parameters

  v | Vehicle to add.
  new_g | Group to add to.

Definition at line 524 of file group_cmd.cpp.

References GroupStatistics::CountVehicle(), SpecializedVehicle< T, Type >::From(), Vehicle::group_id, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, InvalidateWindowData(), Vehicle::IsEngineCountable(), Vehicle::Next(), SetTrainGroupID(), BaseVehicle::type, UpdateNumEngineGroup(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, WC_VEHICLE_DETAILS, and WC_VEHICLE_VIEW.

Referenced by CmdAddVehicleGroup().

## ◆ CmdAddSharedVehicleGroup()

CommandCost CmdAddSharedVehicleGroup | ( | DoCommandFlags | flags,
|  | GroupID | id_g,
|  | VehicleType | type
| ) |  |

Add all shared vehicles of all vehicles from a group.

Parameters

  flags | type of operation
  id_g | index of group
  type | type of vehicles

Returns
  the cost of this operation or an error

Definition at line 626 of file group_cmd.cpp.

References _current_company, CMD_ERROR, Execute, Vehicle::FirstShared(), GetWindowClassForVehicleType(), InvalidateWindowData(), IsCompanyBuildableVehicleType(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Iterate(), Vehicle::NextShared(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and VL_GROUP_LIST.

## ◆ CmdAddVehicleGroup()

std::tuple< CommandCost, GroupID > CmdAddVehicleGroup | ( | DoCommandFlags | flags,
|  | GroupID | group_id,
|  | VehicleID | veh_id,
|  | bool | add_shared,
|  | const VehicleListIdentifier & | vli
| ) |  |

Add a vehicle to a group.

Parameters

  flags | type of operation
  group_id | index of group
  veh_id | vehicle to add to a group
  add_shared | Add shared vehicles as well.

Returns
  the cost of this operation or an error

Definition at line 561 of file group_cmd.cpp.

References _current_company, AddVehicleToGroup(), CMD_ERROR, CmdCreateGroup(), Execute, Vehicle::FirstShared(), GenerateVehicleSortList(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::GetIfValid(), GetWindowClassForVehicleType(), InvalidateWindowData(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::IsValidID(), NEW_GROUP, Group::owner, SetWindowDirty(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Vehicle::tile, GroupStatistics::UpdateAutoreplace(), Group::vehicle_type, VL_GROUP_LIST, WC_REPLACE_VEHICLE, and WC_VEHICLE_DEPOT.

## ◆ CmdAlterGroup()

CommandCost CmdAlterGroup | ( | DoCommandFlags | flags,
|  | AlterGroupMode | mode,
|  | GroupID | group_id,
|  | GroupID | parent_id,
|  | const std::string & | text
| ) |  |

Alter a group.

Parameters

  flags | type of operation
  mode | Operation to perform.
  group_id | GroupID
  parent_id | parent group index
  text | the new name or an empty string when resetting to the default

Returns
  the cost of this operation or an error

Definition at line 449 of file group_cmd.cpp.

References _current_company, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::All(), CMD_ERROR, Livery::colour1, Livery::colour2, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::GetIfValid(), GetWindowClassForVehicleType(), GroupIsInGroup(), Livery::in_use, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, InvalidateWindowClassesData(), InvalidateWindowData(), Group::livery, MarkWholeScreenDirty(), MAX_LENGTH_GROUP_NAME_CHARS, Group::name, Group::owner, Group::parent, Livery::Primary, PropagateChildLivery(), Rename, Livery::Secondary, SetParent, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), VehicleListIdentifier::ToWindowNumber(), GroupStatistics::UpdateAutoreplace(), Utf8StringLength(), Group::vehicle_type, VL_GROUP_LIST, WC_COMPANY_COLOUR, WC_REPLACE_VEHICLE, WC_VEHICLE_DETAILS, and WC_VEHICLE_VIEW.

## ◆ CmdCreateGroup()

std::tuple< CommandCost, GroupID > CmdCreateGroup | ( | DoCommandFlags | flags,
|  | VehicleType | vt,
|  | GroupID | parent_group
| ) |  |

Create a new vehicle group.

Parameters

  flags | type of operation
  vt | vehicle type
  parent_group | parent groupid

Returns
  the cost of this operation or an error

Definition at line 348 of file group_cmd.cpp.

References _current_company, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::CanAllocateItem(), Group::children, CMD_ERROR, Livery::colour1, Livery::colour2, Execute, Group::flags, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::GetIfValid(), GetWindowClassForVehicleType(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, InvalidateWindowData(), IsCompanyBuildableVehicleType(), Group::livery, FreeUnitIDGenerator::NextID(), Group::number, Group::owner, Group::parent, CompanySettings::renew_keep_length, ReplaceWagonRemoval, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), CompanyProperties::settings, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), FreeUnitIDGenerator::UseID(), Group::vehicle_type, VL_GROUP_LIST, and WC_COMPANY_COLOUR.

Referenced by CmdAddVehicleGroup().

## ◆ CmdDeleteGroup()

CommandCost CmdDeleteGroup | ( | DoCommandFlags | flags,
|  | GroupID | group_id
| ) |  |

Add all vehicles in the given group to the default group and then deletes the group.

Parameters

  flags | type of operation
  group_id | index of group

Returns
  the cost of this operation or an error

Definition at line 393 of file group_cmd.cpp.

References _current_company, Group::children, OrderBackup::ClearGroup(), CloseWindowById(), CMD_ERROR, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::GetIfValid(), GetWindowClassForVehicleType(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, InvalidateWindowData(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_enginerenew_pool >::Iterate(), Group::number, Group::owner, Group::parent, FreeUnitIDGenerator::ReleaseID(), RemoveEngineReplacementForCompany(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Group::vehicle_type, VL_GROUP_LIST, WC_COMPANY_COLOUR, and WC_REPLACE_VEHICLE.

## ◆ CmdRemoveAllVehiclesGroup()

CommandCost CmdRemoveAllVehiclesGroup | ( | DoCommandFlags | flags,
|  | GroupID | group_id
| ) |  |

Remove all vehicles from a group.

Parameters

  flags | type of operation
  group_id | index of group

Returns
  the cost of this operation or an error

Definition at line 657 of file group_cmd.cpp.

References _current_company, CMD_ERROR, DEFAULT_GROUP, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::GetIfValid(), GetWindowClassForVehicleType(), InvalidateWindowData(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Iterate(), Group::owner, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), VehicleListIdentifier::ToWindowNumber(), Group::vehicle_type, and VL_GROUP_LIST.

## ◆ CmdSetGroupFlag()

CommandCost CmdSetGroupFlag | ( | DoCommandFlags | flags,
|  | GroupID | group_id,
|  | GroupFlag | flag,
|  | bool | value,
|  | bool | recursive
| ) |  |

(Un)set group flag from a group

Parameters

  flags | type of operation
  group_id | index of group array
  flag | flag to set, by value not bit.
  value | value to set the flag to.
  recursive | to apply to sub-groups.

Returns
  the cost of this operation or an error

Definition at line 742 of file group_cmd.cpp.

References _current_company, CMD_ERROR, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::GetIfValid(), GetWindowClassForVehicleType(), InvalidateWindowData(), Group::owner, ReplaceProtection, ReplaceWagonRemoval, SetGroupFlag(), SetWindowDirty(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), VehicleListIdentifier::ToWindowNumber(), Group::vehicle_type, VL_GROUP_LIST, and WC_REPLACE_VEHICLE.

## ◆ CmdSetGroupLivery()

CommandCost CmdSetGroupLivery | ( | DoCommandFlags | flags,
|  | GroupID | group_id,
|  | bool | primary,
|  | Colours | colour
| ) |  |

Set the livery for a vehicle group.

Parameters

  flags | Command flags.
  group_id | Group ID.
  primary | Set primary instead of secondary colour
  colour | Colour.

Definition at line 687 of file group_cmd.cpp.

References _current_company, CMD_ERROR, Livery::colour1, Livery::colour2, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::GetIfValid(), Livery::in_use, Group::livery, MarkWholeScreenDirty(), Group::owner, Livery::Primary, PropagateChildLivery(), Livery::Secondary, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

## ◆ GetGroupNumEngines()

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

References Group::children, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), GroupStatistics::Get(), GetGroupNumEngines(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::GetIfValid(), and GroupStatistics::GetNumEngines().

Referenced by DrawEngineList(), ReplaceVehicleWindow::GenerateReplaceVehList(), GetGroupNumEngines(), InvalidateAutoreplaceWindow(), NewVehicleAvailable(), ReplaceVehicleWindow::OnClick(), and GroupStatistics::UpdateAutoreplace().

## ◆ GetGroupNumVehicle()

uint GetGroupNumVehicle | ( | CompanyID | company,
|  | GroupID | id_g,
|  | VehicleType | type
| ) |  |

Get the number of vehicles 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
  type | The vehicle type of the group

Returns
  The number of vehicles in the group

Definition at line 840 of file group_cmd.cpp.

References Group::children, GroupStatistics::Get(), GetGroupNumVehicle(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::GetIfValid(), and GroupStatistics::num_vehicle.

Referenced by VehicleGroupWindow::ComputeGroupInfoSize(), VehicleGroupWindow::DrawGroupInfo(), GetGroupNumVehicle(), and VehicleGroupWindow::GetWidgetString().

## ◆ GetGroupNumVehicleMinAge()

uint GetGroupNumVehicleMinAge | ( | CompanyID | company,
|  | GroupID | id_g,
|  | VehicleType | type
| ) |  |

Get the number of vehicles above profit minimum age 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
  type | The vehicle type of the group

Returns
  The number of vehicles above profit minimum age in the group

Definition at line 861 of file group_cmd.cpp.

References Group::children, GroupStatistics::Get(), GetGroupNumVehicleMinAge(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::GetIfValid(), and GroupStatistics::num_vehicle_min_age.

Referenced by GetGroupNumVehicleMinAge(), and VehicleGroupWindow::GetGroupProfitSpriteID().

## ◆ GetGroupProfitLastYearMinAge()

Money GetGroupProfitLastYearMinAge | ( | CompanyID | company,
|  | GroupID | id_g,
|  | VehicleType | type
| ) |  |

Get last year's profit of vehicles above minimum age for 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
  type | The vehicle type of the group

Returns
  Last year's profit of vehicles above minimum age for the group

Definition at line 882 of file group_cmd.cpp.

References Group::children, GroupStatistics::Get(), GetGroupProfitLastYearMinAge(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::GetIfValid(), and GroupStatistics::profit_last_year_min_age.

Referenced by GetGroupProfitLastYearMinAge(), and VehicleGroupWindow::GetGroupProfitSpriteID().

## ◆ GetParentLivery()

const Livery * GetParentLivery | ( | const Group * | g | ) |

Definition at line 285 of file group_cmd.cpp.

## ◆ GroupIsInGroup()

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

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

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

## ◆ PropagateChildLivery()

static void PropagateChildLivery | ( | const Group * | g,
|  | bool | reset_cache
| ) |  |
| static

Propagate a livery change to a group's children, and optionally update cached vehicle colourmaps.

Parameters

  g | Group to propagate colours to children.
  reset_cache | Reset colourmap of vehicles in this group.

Definition at line 302 of file group_cmd.cpp.

References Group::children, Livery::colour1, Livery::colour2, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Get(), Livery::in_use, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Iterate(), Group::livery, Vehicle::Next(), Livery::Primary, PropagateChildLivery(), Livery::Secondary, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by CmdAlterGroup(), CmdSetGroupLivery(), PropagateChildLivery(), and UpdateCompanyGroupLiveries().

## ◆ RemoveAllGroupsForCompany()

void RemoveAllGroupsForCompany | ( | const CompanyID | company | ) |

Definition at line 895 of file group_cmd.cpp.

## ◆ SetGroupFlag()

static void SetGroupFlag | ( | Group * | g,
|  | GroupFlag | flag,
|  | bool | set,
|  | bool | children
| ) |  |
| static

Set group flag for a group and its sub-groups.

Parameters

  g | initial group.
  set | 1 to set or 0 to clear protection.

Definition at line 718 of file group_cmd.cpp.

References Group::children, Group::flags, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Get(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), and SetGroupFlag().

Referenced by CmdSetGroupFlag(), and SetGroupFlag().

## ◆ SetTrainGroupID()

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

References Vehicle::IsFrontEngine(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::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().

## ◆ UpdateCompanyGroupLiveries()

void UpdateCompanyGroupLiveries | ( | const Company * | c | ) |

Update group liveries for a company.

This is called when the LS_DEFAULT scheme is changed, to update groups with colours set to default.

Parameters

  c | Company to update.

Definition at line 329 of file group_cmd.cpp.

References Livery::colour1, Livery::colour2, Livery::in_use, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Iterate(), Group::livery, Group::owner, Group::parent, Livery::Primary, PropagateChildLivery(), Livery::Secondary, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by UpdateCompanyLiveries().

## ◆ UpdateGroupChildren()

void UpdateGroupChildren | ( |  | ) |

Update children list for each group.

Definition at line 47 of file group_cmd.cpp.

References Group::children, Debug, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Iterate(), Group::owner, and Group::vehicle_type.

Referenced by AfterLoadGame().

## ◆ UpdateNumEngineGroup()

static void UpdateNumEngineGroup | ( | const Vehicle * | v,
|  | GroupID | old_g,
|  | GroupID | new_g
| ) |  |
| inlinestatic

Update the num engines of a groupID.

Decrease the old one and increase the new one

Note
  called in SetTrainGroupID and UpdateTrainGroupID

Parameters

  v | Vehicle we have to update
  old_g | index of the old group
  new_g | index of the new group

Definition at line 273 of file group_cmd.cpp.

References Vehicle::engine_type, GroupStatistics::Get(), GroupStatistics::num_engines, Vehicle::owner, and BaseVehicle::type.

Referenced by AddVehicleToGroup(), SetTrainGroupID(), and UpdateTrainGroupID().

## ◆ UpdateTrainGroupID()

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