OpenTTD
Functions
autoreplace_func.h File Reference

Functions related to autoreplacing. More...

#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=NULL)
 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...
 
static void RemoveAllEngineReplacementForCompany (Company *c)
 Remove all engine replacement settings for the given company. More...
 
static EngineID EngineReplacementForCompany (const Company *c, EngineID engine, GroupID group, bool *replace_when_old=NULL)
 Retrieve the engine replacement for the given company and original engine type. More...
 
static bool EngineHasReplacementForCompany (const Company *c, EngineID engine, GroupID group)
 Check if a company has a replacement set up for the given engine. More...
 
static 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...
 
static 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...
 
static 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
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 87 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()

static CommandCost AddEngineReplacementForCompany ( Company c,
EngineID  old_engine,
EngineID  new_engine,
GroupID  group,
bool  replace_when_old,
DoCommandFlag  flags 
)
inlinestatic

Add an engine replacement for the company.

Parameters
cCompany.
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 82 of file autoreplace_func.h.

References AddEngineReplacement(), and Company::engine_renew_list.

◆ CheckAutoreplaceValidity()

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

Checks some basic properties whether autoreplace is allowed.

Parameters
fromOrigin engine
toDestination engine
companyCompany to check for
Returns
true if autoreplace is allowed

Definition at line 52 of file autoreplace_cmd.cpp.

Referenced by RemoveEngineReplacementForCompany().

◆ EngineHasReplacementForCompany()

static bool EngineHasReplacementForCompany ( const Company c,
EngineID  engine,
GroupID  group 
)
inlinestatic

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

Parameters
cCompany.
engineEngine type to be replaced.
groupThe group related to this replacement.
Returns
true if a replacement was set up, false otherwise.

Definition at line 53 of file autoreplace_func.h.

References EngineReplacementForCompany(), and INVALID_ENGINE.

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

◆ EngineHasReplacementWhenOldForCompany()

static bool EngineHasReplacementWhenOldForCompany ( const Company c,
EngineID  engine,
GroupID  group 
)
inlinestatic

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

Parameters
cCompany.
engineEngine type to be replaced.
groupThe group related to this replacement.
Returns
True if a replacement when old was set up, false otherwise.

Definition at line 65 of file autoreplace_func.h.

References Company::engine_renew_list, and EngineReplacement().

Referenced by ReplaceVehicleWindow::OnClick().

◆ 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 66 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(), 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()

static EngineID EngineReplacementForCompany ( const Company c,
EngineID  engine,
GroupID  group,
bool *  replace_when_old = NULL 
)
inlinestatic

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

Parameters
ccompany.
engineEngine type.
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 41 of file autoreplace_func.h.

References Company::engine_renew_list, and EngineReplacement().

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

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

Referenced by RemoveAllEngineReplacementForCompany().

◆ RemoveAllEngineReplacementForCompany()

static void RemoveAllEngineReplacementForCompany ( Company c)
inlinestatic

Remove all engine replacement settings for the given company.

Parameters
cthe company.

Definition at line 27 of file autoreplace_func.h.

References Company::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
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 122 of file autoreplace.cpp.

References CMD_ERROR, and DC_EXEC.

Referenced by RemoveEngineReplacementForCompany().

◆ RemoveEngineReplacementForCompany()

static CommandCost RemoveEngineReplacementForCompany ( Company c,
EngineID  engine,
GroupID  group,
DoCommandFlag  flags 
)
inlinestatic

Remove an engine replacement for the company.

Parameters
cCompany.
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 95 of file autoreplace_func.h.

References CheckAutoreplaceValidity(), Company::engine_renew_list, and RemoveEngineReplacement().