Rearrange conditionals in FreeTrainTrackReservation
[openttd/fttd.git] / src / autoreplace_func.h
blob3a6fc83a81e0447875f1d51da2b636ff00c169db
1 /* $Id$ */
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 */
10 /** @file autoreplace_func.h Functions related to autoreplacing. */
12 #ifndef AUTOREPLACE_FUNC_H
13 #define AUTOREPLACE_FUNC_H
15 #include "command_type.h"
16 #include "company_base.h"
18 void RemoveAllEngineReplacement(EngineRenewList *erl);
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);
21 CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, DoCommandFlag flags);
23 /**
24 * Remove all engine replacement settings for the given company.
25 * @param c the company.
27 static inline void RemoveAllEngineReplacementForCompany(Company *c)
29 RemoveAllEngineReplacement(&c->engine_renew_list);
32 /**
33 * Retrieve the engine replacement for the given company and original engine type.
34 * @param c company.
35 * @param engine Engine type.
36 * @param group The group related to this replacement.
37 * @param[out] replace_when_old Set to true if the replacement should be done when old.
38 * @return The engine type to replace with, or INVALID_ENGINE if no
39 * replacement is in the list.
41 static inline EngineID EngineReplacementForCompany(const Company *c, EngineID engine, GroupID group, bool *replace_when_old = NULL)
43 return EngineReplacement(c->engine_renew_list, engine, group, replace_when_old);
46 /**
47 * Check if a company has a replacement set up for the given engine.
48 * @param c Company.
49 * @param engine Engine type to be replaced.
50 * @param group The group related to this replacement.
51 * @return true if a replacement was set up, false otherwise.
53 static inline bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
55 return EngineReplacementForCompany(c, engine, group) != INVALID_ENGINE;
58 /**
59 * Check if a company has a replacement set up for the given engine when it gets old.
60 * @param c Company.
61 * @param engine Engine type to be replaced.
62 * @param group The group related to this replacement.
63 * @return True if a replacement when old was set up, false otherwise.
65 static inline bool EngineHasReplacementWhenOldForCompany(const Company *c, EngineID engine, GroupID group)
67 bool replace_when_old;
68 EngineReplacement(c->engine_renew_list, engine, group, &replace_when_old);
69 return replace_when_old;
72 /**
73 * Add an engine replacement for the company.
74 * @param c Company.
75 * @param old_engine The original engine type.
76 * @param new_engine The replacement engine type.
77 * @param group The group related to this replacement.
78 * @param replace_when_old Replace when old or always?
79 * @param flags The calling command flags.
80 * @return 0 on success, CMD_ERROR on failure.
82 static inline CommandCost AddEngineReplacementForCompany(Company *c, EngineID old_engine, EngineID new_engine, GroupID group, bool replace_when_old, DoCommandFlag flags)
84 return AddEngineReplacement(&c->engine_renew_list, old_engine, new_engine, group, replace_when_old, flags);
87 /**
88 * Remove an engine replacement for the company.
89 * @param c Company.
90 * @param engine The original engine type.
91 * @param group The group related to this replacement.
92 * @param flags The calling command flags.
93 * @return 0 on success, CMD_ERROR on failure.
95 static inline CommandCost RemoveEngineReplacementForCompany(Company *c, EngineID engine, GroupID group, DoCommandFlag flags)
97 return RemoveEngineReplacement(&c->engine_renew_list, engine, group, flags);
100 bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company);
102 #endif /* AUTOREPLACE_FUNC_H */