OpenTTD Source 20261129-master-g72a8bdc861
autoreplace_func.h File Reference

Functions related to autoreplacing. More...

#include "autoreplace_type.h"
#include "command_type.h"

Go to the source code of this file.

Functions

const EngineRenew * GetEngineRenew (const EngineRenewList &erl, EngineID engine)
 Search within a single engine renew list for an engine to renew.
const EngineRenew * GetEngineRenew (CompanyID company, GroupID group, EngineID engine, bool search)
 Retrieves the EngineRenew that specifies the replacement of the given engine type from the given renewlist.
CommandCost AddEngineReplacement (DoCommandFlags flags, CompanyID company, GroupID group, EngineID engine, EngineID new_engine, bool replace_when_old)
 Add an engine replacement to the given renewlist.
CommandCost RemoveEngineReplacement (DoCommandFlags flags, CompanyID company, GroupID group, EngineID engine)
 Remove an engine replacement from a given renewlist.
void RemoveAllEngineReplacementForCompany (CompanyID company)
 Remove all engine replacements for a company.
bool EngineHasReplacement (CompanyID company, GroupID group, EngineID engine, bool search)
 Check if a company has a replacement set up for the given engine.
bool EngineHasReplacementWhenOld (CompanyID company, GroupID group, EngineID engine, bool search)
 Check if a company has a replacement set up for the given engine when it gets old.
bool CheckAutoreplaceValidity (EngineID from, EngineID to, CompanyID company)
 Checks some basic properties whether autoreplace is allowed.

Detailed Description

Functions related to autoreplacing.

Definition in file autoreplace_func.h.

Function Documentation

◆ AddEngineReplacement()

CommandCost AddEngineReplacement ( DoCommandFlags flags,
CompanyID company,
GroupID group,
EngineID engine,
EngineID new_engine,
bool replace_when_old )

Add an engine replacement to the given renewlist.

Parameters
flagsThe calling command flags.
companyThe company.
groupThe group related to this replacement.
engineThe original engine type.
new_engineThe replacement engine type.
replace_when_oldReplace when old or always?
Returns
0 on success, CMD_ERROR on failure.

Definition at line 103 of file autoreplace.cpp.

References Execute, EngineRenew::from, GetEngineRenewList(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by CmdSetAutoReplace().

◆ CheckAutoreplaceValidity()

◆ EngineHasReplacement()

bool EngineHasReplacement ( CompanyID company,
GroupID group,
EngineID engine,
bool search )
inline

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

Parameters
companyThe company.
groupThe group related to this replacement.
engineEngine type to be replaced.
searchWhether to search groups and company for replacement.
Returns
true if a replacement was set up, false otherwise.

Definition at line 31 of file autoreplace_func.h.

References GetEngineRenew(), and EngineRenew::to.

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

◆ EngineHasReplacementWhenOld()

bool EngineHasReplacementWhenOld ( CompanyID company,
GroupID group,
EngineID engine,
bool search )
inline

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

Parameters
companyThe company.
groupThe group related to this replacement.
engineEngine type to be replaced.
searchWhether to search groups and company for replacement.
Returns
True if a replacement when old was set up, false otherwise.

Definition at line 45 of file autoreplace_func.h.

References GetEngineRenew(), and EngineRenew::replace_when_old.

Referenced by ReplaceVehicleWindow::OnClick().

◆ GetEngineRenew() [1/2]

const EngineRenew * GetEngineRenew ( CompanyID company,
GroupID group,
EngineID engine,
bool search )

Retrieves the EngineRenew that specifies the replacement of the given engine type from the given renewlist.

Parameters
companyThe company.
groupThe group to look for.
engineThe engine to look for.
searchWhether to search groups and company for replacement.
Returns
The engine renew configuration for the given engine and group.

Definition at line 42 of file autoreplace.cpp.

References CompanyProperties::all_engine_renew_list, DEFAULT_GROUP, GetEngineRenew(), ReplaceProtection, and CompanyProperties::ungrouped_engine_renew_list.

◆ GetEngineRenew() [2/2]

const EngineRenew * GetEngineRenew ( const EngineRenewList & erl,
EngineID engine )

Search within a single engine renew list for an engine to renew.

Parameters
erlThe engine renew list.
engineThe engine to search for.
Returns
Engine Renew data if present.

Definition at line 26 of file autoreplace.cpp.

Referenced by DrawEngineList(), ReplaceVehicleWindow::DrawWidget(), EngineHasReplacement(), EngineHasReplacementWhenOld(), ReplaceVehicleWindow::GenerateLists(), ReplaceVehicleWindow::GenerateReplaceVehList(), GetEngineRenew(), GetNewEngineType(), and Vehicle::NeedsServicing().

◆ RemoveAllEngineReplacementForCompany()

void RemoveAllEngineReplacementForCompany ( CompanyID company)

Remove all engine replacements for a company.

Parameters
companyThe company.

Definition at line 63 of file autoreplace.cpp.

References CompanyProperties::all_engine_renew_list, and CompanyProperties::ungrouped_engine_renew_list.

Referenced by ChangeOwnershipOfCompanyItems().

◆ RemoveEngineReplacement()

CommandCost RemoveEngineReplacement ( DoCommandFlags flags,
CompanyID company,
GroupID group,
EngineID engine )

Remove an engine replacement from a given renewlist.

Parameters
flagsThe calling command flags.
companyThe company.
groupThe group related to this replacement.
engineThe original engine type.
Returns
0 on success, CMD_ERROR on failure.

Definition at line 133 of file autoreplace.cpp.

References CMD_ERROR, Execute, EngineRenew::from, GetEngineRenewList(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by CmdSetAutoReplace().