OpenTTD
autoreplace_func.h
Go to the documentation of this file.
1 /* $Id: autoreplace_func.h 24136 2012-04-17 19:44:02Z michi_cc $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef AUTOREPLACE_FUNC_H
13 #define AUTOREPLACE_FUNC_H
14 
15 #include "command_type.h"
16 #include "company_base.h"
17 
19 EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group, bool *replace_when_old = NULL);
20 CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, bool replace_when_old, DoCommandFlag flags);
22 
28 {
30 }
31 
41 static inline EngineID EngineReplacementForCompany(const Company *c, EngineID engine, GroupID group, bool *replace_when_old = NULL)
42 {
43  return EngineReplacement(c->engine_renew_list, engine, group, replace_when_old);
44 }
45 
53 static inline bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
54 {
55  return EngineReplacementForCompany(c, engine, group) != INVALID_ENGINE;
56 }
57 
65 static inline bool EngineHasReplacementWhenOldForCompany(const Company *c, EngineID engine, GroupID group)
66 {
67  bool replace_when_old;
68  EngineReplacement(c->engine_renew_list, engine, group, &replace_when_old);
69  return replace_when_old;
70 }
71 
82 static inline CommandCost AddEngineReplacementForCompany(Company *c, EngineID old_engine, EngineID new_engine, GroupID group, bool replace_when_old, DoCommandFlag flags)
83 {
84  return AddEngineReplacement(&c->engine_renew_list, old_engine, new_engine, group, replace_when_old, flags);
85 }
86 
96 {
97  return RemoveEngineReplacement(&c->engine_renew_list, engine, group, flags);
98 }
99 
100 bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company);
101 
102 #endif /* AUTOREPLACE_FUNC_H */
Definition of stuff that is very close to a company, like the company struct itself.
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.
EngineRenewList engine_renew_list
Engine renewals of this company.
Definition: company_base.h:120
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.
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. ...
Definition: autoreplace.cpp:66
Common return value for all commands.
Definition: command_type.h:25
Types related to commands.
bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
Checks some basic properties whether autoreplace is allowed.
DoCommandFlag
List of flags for a command.
Definition: command_type.h:340
uint16 GroupID
Type for all group identifiers.
Definition: group_type.h:15
void RemoveAllEngineReplacement(EngineRenewList *erl)
Remove all engine replacement settings for the company.
Definition: autoreplace.cpp:44
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.
static void RemoveAllEngineReplacementForCompany(Company *c)
Remove all engine replacement settings for the given company.
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Definition: engine_type.h:174
CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, DoCommandFlag flags)
Remove an engine replacement from a given renewlist.
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:22
Struct to store engine replacements.
static bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine.
Owner
Enum for all companies/owners.
Definition: company_type.h:20
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:87
static CommandCost RemoveEngineReplacementForCompany(Company *c, EngineID engine, GroupID group, DoCommandFlag flags)
Remove an engine replacement for the company.