# autoreplace.cpp File Reference

Management of replacement lists. More...

`#include "stdafx.h"`
`#include "command_func.h"`
`#include "group.h"`
`#include "autoreplace_base.h"`
`#include "oldpool_func.h"`

Go to the source code of this file.

## Functions
static EngineRenew * | GetEngineReplacement (EngineRenewList erl, EngineID engine, GroupID group)
| Retrieves the EngineRenew that specifies the replacement of the given engine type from the given renewlist.
void | RemoveAllEngineReplacement (EngineRenewList *erl)
| Remove all engine replacement settings for the company.
EngineID | EngineReplacement (EngineRenewList erl, EngineID engine, GroupID group)
| Retrieve the engine replacement in a given renewlist for an original engine type.
CommandCost | AddEngineReplacement (EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, DoCommandFlag flags)
| Add an engine replacement to the given renewlist.
CommandCost | RemoveEngineReplacement (EngineRenewList *erl, EngineID engine, GroupID group, DoCommandFlag flags)
| Remove an engine replacement from a given renewlist.
void | InitializeEngineRenews ()

## Detailed Description

Management of replacement lists.

Definition in file autoreplace.cpp.

## Function Documentation

CommandCost AddEngineReplacement | ( | EngineRenewList * | erl,
|  | EngineID | old_engine,
|  | EngineID | new_engine,
|  | GroupID | group,
|  | 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.
  | flags | The calling command flags.

Returns:
  0 on success, CMD_ERROR on failure.

Definition at line 50 of file autoreplace.cpp.

References PoolItem< T, Tid, Tpool >::CanAllocateItem(), CMD_ERROR, DC_EXEC, GetEngineReplacement(), EngineRenew::group_id, EngineRenew::next, and EngineRenew::to.

Referenced by AddEngineReplacementForCompany().

EngineID EngineReplacement | ( | EngineRenewList | erl,
|  | EngineID | engine,
|  | GroupID | group |
| ) |  |  |

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.

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

Definition at line 40 of file autoreplace.cpp.

References DEFAULT_GROUP, GetEngineReplacement(), and EngineRenew::to.

Referenced by EngineReplacementForCompany().

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 27 of file autoreplace.cpp.

References EngineRenew::next.

Referenced by RemoveAllEngineReplacementForCompany().

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.
  | flags | The calling command flags.

Returns:
  0 on success, CMD_ERROR on failure.

Definition at line 75 of file autoreplace.cpp.

References CMD_ERROR, DC_EXEC, EngineRenew::from, EngineRenew::group_id, and EngineRenew::next.

Referenced by RemoveEngineReplacementForCompany().