OpenTTD Source 20261129-master-g72a8bdc861
autoreplace_func.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef AUTOREPLACE_FUNC_H
11#define AUTOREPLACE_FUNC_H
12
13#include "autoreplace_type.h"
14#include "command_type.h"
15
16const EngineRenew *GetEngineRenew(const EngineRenewList &erl, EngineID engine);
17const EngineRenew *GetEngineRenew(CompanyID company, GroupID group, EngineID engine, bool search);
18CommandCost AddEngineReplacement(DoCommandFlags flags, CompanyID company, GroupID group, EngineID engine, EngineID new_engine, bool replace_when_old);
19CommandCost RemoveEngineReplacement(DoCommandFlags flags, CompanyID company, GroupID group, EngineID engine);
20
21void RemoveAllEngineReplacementForCompany(CompanyID company);
22
31inline bool EngineHasReplacement(CompanyID company, GroupID group, EngineID engine, bool search)
32{
33 const EngineRenew *er = GetEngineRenew(company, group, engine, search);
34 return er != nullptr && engine != er->to;
35}
36
45inline bool EngineHasReplacementWhenOld(CompanyID company, GroupID group, EngineID engine, bool search)
46{
47 const EngineRenew *er = GetEngineRenew(company, group, engine, search);
48 return er != nullptr && er->replace_when_old;
49}
50
51bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company);
52
53#endif /* AUTOREPLACE_FUNC_H */
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.
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 CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
Checks some basic properties whether autoreplace is allowed.
const EngineRenew * GetEngineRenew(const EngineRenewList &erl, EngineID engine)
Search within a single engine renew list for an engine to renew.
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.
CommandCost RemoveEngineReplacement(DoCommandFlags flags, CompanyID company, GroupID group, EngineID engine)
Remove an engine replacement from a given renewlist.
Types related to autoreplacing.
std::vector< EngineRenew > EngineRenewList
A list to group EngineRenew directives together (such as per-company).
Common return value for all commands.
Types related to commands.
EnumBitSet< DoCommandFlag, uint16_t > DoCommandFlags
Bitset of DoCommandFlag elements.
PoolID< uint16_t, struct EngineIDTag, 64000, 0xFFFF > EngineID
Unique identification number of an engine.
Definition engine_type.h:25
Information about engine autorenews and autoreplacements.
EngineID to
Engine to replace to.
bool replace_when_old
Do replacement only when vehicle is old.