OpenTTD Source: src/autoreplace_func.h File Reference

OpenTTD Source 14.1

Functions
autoreplace_func.h File Reference
`#include "command_type.h"`
`#include "company_base.h"`

Go to the source code of this file.

## Functions
void | RemoveAllEngineReplacement (EngineRenewList *erl)
| Remove all engine replacement settings for the company. More...
EngineID | EngineReplacement (EngineRenewList erl, EngineID engine, GroupID group, bool *replace_when_old=nullptr)
| Retrieve the engine replacement in a given renewlist for an original engine type. More...
CommandCost | AddEngineReplacement (EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, bool replace_when_old, DoCommandFlag flags)
| Add an engine replacement to the given renewlist. More...
CommandCost | RemoveEngineReplacement (EngineRenewList *erl, EngineID engine, GroupID group, DoCommandFlag flags)
| Remove an engine replacement from a given renewlist. More...
void | RemoveAllEngineReplacementForCompany (Company *c)
| Remove all engine replacement settings for the given company. More...
EngineID | EngineReplacementForCompany (const Company *c, EngineID engine, GroupID group, bool *replace_when_old=nullptr)
| Retrieve the engine replacement for the given company and original engine type. More...
bool | EngineHasReplacementForCompany (const Company *c, EngineID engine, GroupID group)
| Check if a company has a replacement set up for the given engine. More...
bool | EngineHasReplacementWhenOldForCompany (const Company *c, EngineID engine, GroupID group)
| Check if a company has a replacement set up for the given engine when it gets old. More...
CommandCost | AddEngineReplacementForCompany (Company *c, EngineID old_engine, EngineID new_engine, GroupID group, bool replace_when_old, DoCommandFlag flags)
| Add an engine replacement for the company. More...
CommandCost | RemoveEngineReplacementForCompany (Company *c, EngineID engine, GroupID group, DoCommandFlag flags)
| Remove an engine replacement for the company. More...
bool | CheckAutoreplaceValidity (EngineID from, EngineID to, CompanyID company)
| Checks some basic properties whether autoreplace is allowed. More...

## Detailed Description

Functions related to autoreplacing.

Definition in file autoreplace_func.h.

## Function Documentation

## ◆ AddEngineReplacement()

CommandCost AddEngineReplacement | ( | EngineRenewList * | erl,
|  | EngineID | old_engine,
|  | EngineID | new_engine,
|  | GroupID | group,
|  | bool | replace_when_old,
|  | DoCommandFlag | flags
| ) |  |

Add an engine replacement to the given renewlist.

Parameters

  erl | The renewlist to add to.
  old_engine | The original engine type.
  new_engine | The replacement engine type.
  group | The group related to this replacement.
  replace_when_old | Replace when old or always?
  flags | The calling command flags.

Returns
  0 on success, CMD_ERROR on failure.

Definition at line 97 of file autoreplace.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_enginerenew_pool >::CanAllocateItem(), CMD_ERROR, DC_EXEC, GetEngineReplacement(), and EngineRenew::replace_when_old.

Referenced by AddEngineReplacementForCompany().

## ◆ AddEngineReplacementForCompany()

CommandCost AddEngineReplacementForCompany | ( | Company * | c,
|  | EngineID | old_engine,
|  | EngineID | new_engine,
|  | GroupID | group,
|  | bool | replace_when_old,
|  | DoCommandFlag | flags
| ) |  |
| inline

Add an engine replacement for the company.

Parameters

  c | Company.
  old_engine | The original engine type.
  new_engine | The replacement engine type.
  group | The group related to this replacement.
  replace_when_old | Replace when old or always?
  flags | The calling command flags.

Returns
  0 on success, CMD_ERROR on failure.

Definition at line 80 of file autoreplace_func.h.

References AddEngineReplacement(), and CompanyProperties::engine_renew_list.

## ◆ CheckAutoreplaceValidity()

bool CheckAutoreplaceValidity | ( | EngineID | from,
|  | EngineID | to,
|  | CompanyID | company
| ) |  |

Checks some basic properties whether autoreplace is allowed.

Parameters

  from | Origin engine
  to | Destination engine
  company | Company to check for

Returns
  true if autoreplace is allowed

Definition at line 60 of file autoreplace_cmd.cpp.

References AIR_CTOL, RailTypeInfo::compatible_railtypes, EF_ROAD_TRAM, EnginesHaveCargoInCommon(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetRailTypeInfo(), GetRoadTypeInfo(), HasBit(), IsEngineBuildable(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::IsValidID(), EngineInfo::misc_flags, RoadTypeInfo::powered_roadtypes, RailVehicleInfo::railtype, RAILVEH_WAGON, RoadVehicleInfo::roadtype, ROADTYPES_NONE, AircraftVehicleInfo::subtype, Engine::type, VEH_AIRCRAFT, VEH_ROAD, and VEH_TRAIN.

Referenced by ReplaceVehicleWindow::GenerateReplaceVehList().

## ◆ EngineHasReplacementForCompany()

bool EngineHasReplacementForCompany | ( | const Company * | c,
|  | EngineID | engine,
|  | GroupID | group
| ) |  |
| inline

Check if a company has a replacement set up for the given engine.

Parameters

  c | Company.
  engine | Engine type to be replaced.
  group | The group related to this replacement.

Returns
  true if a replacement was set up, false otherwise.

Definition at line 51 of file autoreplace_func.h.

References EngineReplacementForCompany(), and INVALID_ENGINE.

Referenced by AgeVehicle(), and ReplaceVehicleWindow::OnPaint().

## ◆ EngineHasReplacementWhenOldForCompany()

bool EngineHasReplacementWhenOldForCompany | ( | const Company * | c,
|  | EngineID | engine,
|  | GroupID | group
| ) |  |
| inline

Check if a company has a replacement set up for the given engine when it gets old.

Parameters

  c | Company.
  engine | Engine type to be replaced.
  group | The group related to this replacement.

Returns
  True if a replacement when old was set up, false otherwise.

Definition at line 63 of file autoreplace_func.h.

References CompanyProperties::engine_renew_list, and EngineReplacement().

## ◆ EngineReplacement()

EngineID EngineReplacement | ( | EngineRenewList | erl,
|  | EngineID | engine,
|  | GroupID | group,
|  | bool * | replace_when_old
| ) |  |

Retrieve the engine replacement in a given renewlist for an original engine type.

Parameters

  | erl | The renewlist to search in.
  | engine | Engine type to be replaced.
  | group | The group related to this replacement.
  [out] | replace_when_old | Set to true if the replacement should be done when old.

Returns
  The engine type to replace with, or INVALID_ENGINE if no replacement is in the list.

Definition at line 65 of file autoreplace.cpp.

References ALL_GROUP, DEFAULT_GROUP, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::Get(), GetEngineReplacement(), GF_REPLACE_PROTECTION, HasBit(), INVALID_ENGINE, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::IsValidID(), and EngineRenew::replace_when_old.

Referenced by EngineHasReplacementWhenOldForCompany(), and EngineReplacementForCompany().

## ◆ EngineReplacementForCompany()

EngineID EngineReplacementForCompany | ( | const Company * | c,
|  | EngineID | engine,
|  | GroupID | group,
|  | bool * | replace_when_old = `nullptr`
| ) |  |
| inline

Retrieve the engine replacement for the given company and original engine type.

Parameters

  | c | company.
  | engine | Engine type.
  | group | The group related to this replacement.
  [out] | replace_when_old | Set to true if the replacement should be done when old.

Returns
  The engine type to replace with, or INVALID_ENGINE if no replacement is in the list.

Definition at line 39 of file autoreplace_func.h.

References CompanyProperties::engine_renew_list, and EngineReplacement().

Referenced by EngineHasReplacementForCompany(), ReplaceVehicleWindow::GenerateLists(), ReplaceVehicleWindow::GenerateReplaceVehList(), GetNewEngineType(), Vehicle::NeedsServicing(), and ReplaceVehicleWindow::OnPaint().

## ◆ RemoveAllEngineReplacement()

void RemoveAllEngineReplacement | ( | EngineRenewList * | erl | ) |

Remove all engine replacement settings for the company.

Parameters

  erl | The renewlist for a given company.

Returns
  The new renewlist for the company.

Definition at line 43 of file autoreplace.cpp.

Referenced by RemoveAllEngineReplacementForCompany().

## ◆ RemoveAllEngineReplacementForCompany()

void RemoveAllEngineReplacementForCompany | ( | Company * | c | ) |
| inline

Remove all engine replacement settings for the given company.

Parameters

  c | the company.

Definition at line 25 of file autoreplace_func.h.

References CompanyProperties::engine_renew_list, and RemoveAllEngineReplacement().

## ◆ RemoveEngineReplacement()

CommandCost RemoveEngineReplacement | ( | EngineRenewList * | erl,
|  | EngineID | engine,
|  | GroupID | group,
|  | DoCommandFlag | flags
| ) |  |

Remove an engine replacement from a given renewlist.

Parameters

  erl | The renewlist from which to remove the replacement
  engine | The original engine type.
  group | The group related to this replacement.
  flags | The calling command flags.

Returns
  0 on success, CMD_ERROR on failure.

Definition at line 132 of file autoreplace.cpp.

References CMD_ERROR, and DC_EXEC.

Referenced by RemoveEngineReplacementForCompany().

## ◆ RemoveEngineReplacementForCompany()

CommandCost RemoveEngineReplacementForCompany | ( | Company * | c,
|  | EngineID | engine,
|  | GroupID | group,
|  | DoCommandFlag | flags
| ) |  |
| inline

Remove an engine replacement for the company.

Parameters

  c | Company.
  engine | The original engine type.
  group | The group related to this replacement.
  flags | The calling command flags.

Returns
  0 on success, CMD_ERROR on failure.

Definition at line 93 of file autoreplace_func.h.

References CompanyProperties::engine_renew_list, and RemoveEngineReplacement().

Referenced by CmdDeleteGroup().