# AIGroup Class Reference

Class that handles all group related functions. More...

`#include <ai_group.hpp>`

Inheritance diagram for AIGroup:

## Public Types
enum | GroupID { GROUP_ALL = 0xFFFD, GROUP_DEFAULT = 0xFFFE, GROUP_INVALID = 0xFFFF }
| The group IDs of some special groups. More...
## Static Public Member Functions
static const char * | GetClassName ()
static bool | IsValidGroup (GroupID group_id)
| Checks whether the given group is valid.
static GroupID | CreateGroup (AIVehicle::VehicleType vehicle_type)
| Create a new group.
static bool | DeleteGroup (GroupID group_id)
| Delete the given group.
static AIVehicle::VehicleType | GetVehicleType (GroupID group_id)
| Get the vehicle type of a group.
static bool | SetName (GroupID group_id, const char *name)
| Set the name of a group.
static char * | GetName (GroupID group_id)
| Get the name of a group.
static bool | EnableAutoReplaceProtection (GroupID group_id, bool enable)
| Enable or disable autoreplace protected.
static bool | GetAutoReplaceProtection (GroupID group_id)
| Get the autoreplace protection status.
static int32 | GetNumEngines (GroupID group_id, EngineID engine_id)
| Get the number of engines in a given group.
static bool | MoveVehicle (GroupID group_id, VehicleID vehicle_id)
| Move a vehicle to a group.
static bool | EnableWagonRemoval (bool keep_length)
| Enable or disable the removal of wagons when a (part of a) vehicle is (auto)replaced with a longer variant (longer wagons or longer engines) If enabled, wagons are removed from the end of the vehicle until it fits in the same number of tiles as it did before.
static bool | HasWagonRemoval ()
| Get the current status of wagon removal.
static bool | SetAutoReplace (GroupID group_id, EngineID engine_id_old, EngineID engine_id_new)
| Start replacing all vehicles with a specified engine with another engine.
static EngineID | GetEngineReplacement (GroupID group_id, EngineID engine_id)
| Get the EngineID the given EngineID is replaced with.
static bool | StopAutoReplace (GroupID group_id, EngineID engine_id)
| Stop replacing a certain engine in the specified group.

## Detailed Description

Class that handles all group related functions.

Definition at line 21 of file ai_group.hpp.

## Member Enumeration Documentation

enum AIGroup::GroupID

The group IDs of some special groups.

Enumerator:

  GROUP_ALL | All vehicles are in this group.
  GROUP_DEFAULT | Vehicles not put in any other group are in this one.
  GROUP_INVALID | An invalid group id.

Definition at line 28 of file ai_group.hpp.

## Member Function Documentation

AIGroup::GroupID AIGroup::CreateGroup | ( | AIVehicle::VehicleType | vehicle_type | ) | `[static]`

Create a new group.

Parameters:

  | vehicle_type | The type of vehicle to create a group for.

Returns:
  The GroupID of the new group, or an invalid GroupID when it failed. Check the return value using IsValidGroup(). In test-mode 0 is returned if it was successful; any other value indicates failure.

Definition at line 29 of file ai_group.cpp.

References CMD_CREATE_GROUP, AIObject::DoCommand(), AIInstance::DoCommandReturnGroupID(), and GROUP_INVALID.

bool AIGroup::DeleteGroup | ( | GroupID | group_id | ) | `[static]`

Delete the given group.

When the deletion succeeds all vehicles in the given group will move to the GROUP_DEFAULT.

Parameters:

  | group_id | The group to delete.

Precondition:
  IsValidGroup(group_id).

Returns:
  True if and only if the group was succesfully deleted.

Definition at line 37 of file ai_group.cpp.

References CMD_DELETE_GROUP, AIObject::DoCommand(), EnforcePrecondition, and IsValidGroup().

bool AIGroup::EnableAutoReplaceProtection | ( | GroupID | group_id,
|  | bool | enable |
| ) |  |  | `[static]`

Enable or disable autoreplace protected.

If the protection is enabled, global autoreplace won't affect vehicles in this group.

Parameters:

  | group_id | The group to change the protection for.
  | enable | True if protection should be enabled.

Precondition:
  IsValidGroup(group_id).

Returns:
  True if and only if the protection was succesfully changed.

Definition at line 72 of file ai_group.cpp.

References CMD_SET_GROUP_REPLACE_PROTECTION, AIObject::DoCommand(), EnforcePrecondition, and IsValidGroup().

bool AIGroup::EnableWagonRemoval | ( | bool | keep_length | ) | `[static]`

Enable or disable the removal of wagons when a (part of a) vehicle is (auto)replaced with a longer variant (longer wagons or longer engines) If enabled, wagons are removed from the end of the vehicle until it fits in the same number of tiles as it did before.

Parameters:

  | keep_length | If true, wagons will be removed if the a new engine is longer.

Returns:
  True if and only if the value was succesfully changed.

Definition at line 101 of file ai_group.cpp.

References CMD_CHANGE_COMPANY_SETTING, AIObject::DoCommand(), GetCompanySettingIndex(), and HasWagonRemoval().

bool AIGroup::GetAutoReplaceProtection | ( | GroupID | group_id | ) | `[static]`

Get the autoreplace protection status.

Parameters:

  | group_id | The group to get the protection status for.

Precondition:
  IsValidGroup(group_id).

Returns:
  The autoreplace protection status for the given group.

Definition at line 79 of file ai_group.cpp.

References IsValidGroup().

EngineID AIGroup::GetEngineReplacement | ( | GroupID | group_id,
|  | EngineID | engine_id |
| ) |  |  | `[static]`

Get the EngineID the given EngineID is replaced with.

Parameters:

  | group_id | The group to get the replacement from.
  | engine_id | The engine that is being replaced.

Precondition:
  IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL.

Returns:
  The EngineID that is replacing engine_id or an invalid EngineID in case engine_id is not begin replaced.

Definition at line 121 of file ai_group.cpp.

References EngineReplacementForCompany(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), GROUP_ALL, GROUP_DEFAULT, and IsValidGroup().

char * AIGroup::GetName | ( | GroupID | group_id | ) | `[static]`

Get the name of a group.

Parameters:

  | group_id | The group to get the name of.

Precondition:
  IsValidGroup(group_id).

Returns:
  The name the group has.

Definition at line 60 of file ai_group.cpp.

References IsValidGroup(), and SetDParam().

int32 AIGroup::GetNumEngines | ( | GroupID | group_id,
|  | EngineID | engine_id |
| ) |  |  | `[static]`

Get the number of engines in a given group.

Parameters:

  | group_id | The group to get the number of engines in.
  | engine_id | The engine id to count.

Precondition:
  IsValidGroup(group_id) || group_id == GROUP_ALL || group_id == GROUP_DEFAULT.

Returns:
  The number of engines with id engine_id in the group with id group_id.

Definition at line 86 of file ai_group.cpp.

References GetGroupNumEngines(), GROUP_ALL, GROUP_DEFAULT, and IsValidGroup().

AIVehicle::VehicleType AIGroup::GetVehicleType | ( | GroupID | group_id | ) | `[static]`

Get the vehicle type of a group.

Parameters:

  | group_id | The group to get the type from.

Precondition:
  IsValidGroup(group_id).

Returns:
  The vehicletype of the given group.

Definition at line 44 of file ai_group.cpp.

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

bool AIGroup::HasWagonRemoval | ( |  | ) | `[static]`

Get the current status of wagon removal.

Returns:
  Whether or not wagon removal is enabled.

Definition at line 108 of file ai_group.cpp.

Referenced by EnableWagonRemoval().

bool AIGroup::IsValidGroup | ( | GroupID | group_id | ) | `[static]`

Checks whether the given group is valid.

Parameters:

  | group_id | The group to check.

Precondition:
  group_id != GROUP_DEFAULT && group_id != GROUP_ALL.

Returns:
  True if and only if the group is valid.

Definition at line 23 of file ai_group.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_group_pool >::GetIfValid(), and Group::owner.

Referenced by AIVehicleList_Group::AIVehicleList_Group(), DeleteGroup(), EnableAutoReplaceProtection(), GetAutoReplaceProtection(), GetEngineReplacement(), GetName(), GetNumEngines(), GetVehicleType(), MoveVehicle(), SetAutoReplace(), SetName(), and StopAutoReplace().

bool AIGroup::MoveVehicle | ( | GroupID | group_id,
|  | VehicleID | vehicle_id |
| ) |  |  | `[static]`

Move a vehicle to a group.

Parameters:

  | group_id | The group to move the vehicel to.
  | vehicle_id | The vehicle to move to the group.

Precondition:
  IsValidGroup(group_id) || group_id == GROUP_DEFAULT.
  AIVehicle::IsValidVehicle(vehicle_id).

Returns:
  True if and only if the vehicle was succesfully moved to the group.

Note:
  A vehicle can be in only one group at the same time. To remove it from a group, move it to another or to GROUP_DEFAULT. Moving the vehicle to the given group means removing it from another group.

Definition at line 93 of file ai_group.cpp.

References CMD_ADD_VEHICLE_GROUP, AIObject::DoCommand(), EnforcePrecondition, GROUP_DEFAULT, IsValidGroup(), and AIVehicle::IsValidVehicle().

bool AIGroup::SetAutoReplace | ( | GroupID | group_id,
|  | EngineID | engine_id_old,
|  | EngineID | engine_id_new |
| ) |  |  | `[static]`

Start replacing all vehicles with a specified engine with another engine.

Parameters:

  | group_id | The group to replace vehicles from. Use ALL_GROUP to replace vehicles from all groups that haven't set autoreplace protection.
  | engine_id_old | The engine id to start replacing.
  | engine_id_new | The engine id to replace with.

Precondition:
  IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL.
  AIEngine.IsBuildable(engine_id_new).

Note:
  To stop autoreplacing engine_id_old, call StopAutoReplace(group_id, engine_id_old).

Definition at line 113 of file ai_group.cpp.

References CMD_SET_AUTOREPLACE, AIObject::DoCommand(), EnforcePrecondition, GROUP_ALL, GROUP_DEFAULT, AIEngine::IsBuildable(), and IsValidGroup().

bool AIGroup::SetName | ( | GroupID | group_id,
|  | const char * | name |
| ) |  |  | `[static]`

Set the name of a group.

Parameters:

  | group_id | The group to set the name for.
  | name | The name for the group.

Precondition:
  IsValidGroup(group_id).
  'name' must have at least one character.
  'name' must have at most 30 characters.

Exceptions:

  | AIError::ERR_NAME_IS_NOT_UNIQUE |

Returns:
  True if and only if the name was changed.

Definition at line 51 of file ai_group.cpp.

References CMD_RENAME_GROUP, AIObject::DoCommand(), EnforcePrecondition, EnforcePreconditionCustomError, AIError::ERR_PRECONDITION_STRING_TOO_LONG, IsValidGroup(), MAX_LENGTH_GROUP_NAME_BYTES, and StrEmpty().

bool AIGroup::StopAutoReplace | ( | GroupID | group_id,
|  | EngineID | engine_id |
| ) |  |  | `[static]`

Stop replacing a certain engine in the specified group.

Parameters:

  | group_id | The group to stop replacing the engine in.
  | engine_id | The engine id to stop replacing with another engine.

Precondition:
  IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL.

Returns:
  True if and if the replacing was succesfully stopped.

Definition at line 128 of file ai_group.cpp.

References CMD_SET_AUTOREPLACE, AIObject::DoCommand(), EnforcePrecondition, GROUP_ALL, GROUP_DEFAULT, and IsValidGroup().

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

- src/ai/api/ai_group.hpp
- src/ai/api/ai_group.cpp