OpenTTD Source 20261129-master-g72a8bdc861
autoreplace.cpp File Reference

Management of replacement lists. More...

#include "stdafx.h"
#include "autoreplace_func.h"
#include "autoreplace_type.h"
#include "command_func.h"
#include "company_base.h"
#include "group.h"
#include "safeguards.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.
void RemoveAllEngineReplacementForCompany (CompanyID company)
 Remove all engine replacements for a company.
EngineRenewList & GetEngineRenewList (CompanyID company, GroupID group)
 Get the Engine Renew List for a company/group.
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.

Detailed Description

Management of replacement lists.

Definition in file autoreplace.cpp.

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().

◆ 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().

◆ GetEngineRenewList()

EngineRenewList & GetEngineRenewList ( CompanyID company,
GroupID group )

Get the Engine Renew List for a company/group.

Parameters
companyThe company.
groupThe group.
Returns
The EngineRenewList for the company/group.

Definition at line 83 of file autoreplace.cpp.

References ALL_GROUP, DEFAULT_GROUP, and Group::engine_renew_list.

Referenced by AddEngineReplacement(), and RemoveEngineReplacement().

◆ 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().