OpenTTD Source  20241108-master-g80f628063a
autoreplace.cpp File Reference

Management of replacement lists. More...

#include "stdafx.h"
#include "command_func.h"
#include "group.h"
#include "autoreplace_base.h"
#include "core/bitmath_func.hpp"
#include "core/pool_func.hpp"
#include "safeguards.h"

Go to the source code of this file.

Functions

static EngineRenewGetEngineReplacement (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. More...
 
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. 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...
 

Variables

EngineRenewPool _enginerenew_pool ("EngineRenew")
 The pool of autoreplace "orders".
 

Detailed Description

Management of replacement lists.

Definition in file autoreplace.cpp.

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
erlThe renewlist to add to.
old_engineThe original engine type.
new_engineThe replacement engine type.
groupThe group related to this replacement.
replace_when_oldReplace when old or always?
flagsThe 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().

◆ 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
erlThe renewlist to search in.
engineEngine type to be replaced.
groupThe group related to this replacement.
[out]replace_when_oldSet 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().

◆ RemoveAllEngineReplacement()

void RemoveAllEngineReplacement ( EngineRenewList erl)

Remove all engine replacement settings for the company.

Parameters
erlThe renewlist for a given company.
Returns
The new renewlist for the company.

Definition at line 43 of file autoreplace.cpp.

Referenced by RemoveAllEngineReplacementForCompany().

◆ RemoveEngineReplacement()

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

Remove an engine replacement from a given renewlist.

Parameters
erlThe renewlist from which to remove the replacement
engineThe original engine type.
groupThe group related to this replacement.
flagsThe 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().