OpenTTD Source  20240917-master-g9ab0a47812
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 <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef AUTOREPLACE_FUNC_H
11 #define AUTOREPLACE_FUNC_H
12 
13 #include "command_type.h"
14 #include "company_base.h"
15 
17 EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group, bool *replace_when_old = nullptr);
18 CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, bool replace_when_old, DoCommandFlag flags);
20 
26 {
28 }
29 
39 inline EngineID EngineReplacementForCompany(const Company *c, EngineID engine, GroupID group, bool *replace_when_old = nullptr)
40 {
41  return EngineReplacement(c->engine_renew_list, engine, group, replace_when_old);
42 }
43 
51 inline bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
52 {
53  return EngineReplacementForCompany(c, engine, group) != INVALID_ENGINE;
54 }
55 
63 inline bool EngineHasReplacementWhenOldForCompany(const Company *c, EngineID engine, GroupID group)
64 {
65  bool replace_when_old;
66  EngineReplacement(c->engine_renew_list, engine, group, &replace_when_old);
67  return replace_when_old;
68 }
69 
80 inline CommandCost AddEngineReplacementForCompany(Company *c, EngineID old_engine, EngineID new_engine, GroupID group, bool replace_when_old, DoCommandFlag flags)
81 {
82  return AddEngineReplacement(&c->engine_renew_list, old_engine, new_engine, group, replace_when_old, flags);
83 }
84 
94 {
95  return RemoveEngineReplacement(&c->engine_renew_list, engine, group, flags);
96 }
97 
98 bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company);
99 
100 #endif /* AUTOREPLACE_FUNC_H */
INVALID_ENGINE
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Definition: engine_type.h:206
EngineReplacementForCompany
EngineID EngineReplacementForCompany(const Company *c, EngineID engine, GroupID group, bool *replace_when_old=nullptr)
Retrieve the engine replacement for the given company and original engine type.
Definition: autoreplace_func.h:39
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.
Definition: autoreplace.cpp:97
AddEngineReplacementForCompany
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.
Definition: autoreplace_func.h:80
company_base.h
EngineHasReplacementWhenOldForCompany
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.
Definition: autoreplace_func.h:63
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
CheckAutoreplaceValidity
bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
Checks some basic properties whether autoreplace is allowed.
Definition: autoreplace_cmd.cpp:60
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:374
EngineHasReplacementForCompany
bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine.
Definition: autoreplace_func.h:51
RemoveAllEngineReplacement
void RemoveAllEngineReplacement(EngineRenewList *erl)
Remove all engine replacement settings for the company.
Definition: autoreplace.cpp:43
CommandCost
Common return value for all commands.
Definition: command_type.h:23
EngineRenew
Struct to store engine replacements.
Definition: autoreplace_base.h:33
RemoveEngineReplacement
CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, DoCommandFlag flags)
Remove an engine replacement from a given renewlist.
Definition: autoreplace.cpp:132
command_type.h
GroupID
uint16_t GroupID
Type for all group identifiers.
Definition: group_type.h:13
RemoveEngineReplacementForCompany
CommandCost RemoveEngineReplacementForCompany(Company *c, EngineID engine, GroupID group, DoCommandFlag flags)
Remove an engine replacement for the company.
Definition: autoreplace_func.h:93
RemoveAllEngineReplacementForCompany
void RemoveAllEngineReplacementForCompany(Company *c)
Remove all engine replacement settings for the given company.
Definition: autoreplace_func.h:25
EngineReplacement
EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group, bool *replace_when_old=nullptr)
Retrieve the engine replacement in a given renewlist for an original engine type.
Definition: autoreplace.cpp:65
EngineID
uint16_t EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
CompanyProperties::engine_renew_list
EngineRenewList engine_renew_list
Engine renewals of this company.
Definition: company_base.h:121
Company
Definition: company_base.h:133