summaryrefslogtreecommitdiff
path: root/src/autoreplace_func.h
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2012-04-17 19:44:02 +0000
committermichi_cc <michi_cc@openttd.org>2012-04-17 19:44:02 +0000
commit6a70abbd998ed5b54d52ddb44b4df8521413185c (patch)
tree25d404a46a68f3fa314dd27a4b9555ac4bc1a886 /src/autoreplace_func.h
parented565853889679a409d601a61d661718ac3498cc (diff)
downloadopenttd-6a70abbd998ed5b54d52ddb44b4df8521413185c.tar.xz
(svn r24136) -Feature [FS#4465]: Autoreplace vehicles only when they get old. (Vikthor)
Diffstat (limited to 'src/autoreplace_func.h')
-rw-r--r--src/autoreplace_func.h28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/autoreplace_func.h b/src/autoreplace_func.h
index 7f2c96bf6..3a6fc83a8 100644
--- a/src/autoreplace_func.h
+++ b/src/autoreplace_func.h
@@ -16,8 +16,8 @@
#include "company_base.h"
void RemoveAllEngineReplacement(EngineRenewList *erl);
-EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group);
-CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, DoCommandFlag flags);
+EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group, bool *replace_when_old = NULL);
+CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, bool replace_when_old, DoCommandFlag flags);
CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, DoCommandFlag flags);
/**
@@ -34,12 +34,13 @@ static inline void RemoveAllEngineReplacementForCompany(Company *c)
* @param c company.
* @param engine Engine type.
* @param group The group related to this replacement.
+ * @param[out] replace_when_old Set to true if the replacement should be done when old.
* @return The engine type to replace with, or INVALID_ENGINE if no
* replacement is in the list.
*/
-static inline EngineID EngineReplacementForCompany(const Company *c, EngineID engine, GroupID group)
+static inline EngineID EngineReplacementForCompany(const Company *c, EngineID engine, GroupID group, bool *replace_when_old = NULL)
{
- return EngineReplacement(c->engine_renew_list, engine, group);
+ return EngineReplacement(c->engine_renew_list, engine, group, replace_when_old);
}
/**
@@ -55,17 +56,32 @@ static inline bool EngineHasReplacementForCompany(const Company *c, EngineID eng
}
/**
+ * Check if a company has a replacement set up for the given engine when it gets old.
+ * @param c Company.
+ * @param engine Engine type to be replaced.
+ * @param group The group related to this replacement.
+ * @return True if a replacement when old was set up, false otherwise.
+ */
+static inline bool EngineHasReplacementWhenOldForCompany(const Company *c, EngineID engine, GroupID group)
+{
+ bool replace_when_old;
+ EngineReplacement(c->engine_renew_list, engine, group, &replace_when_old);
+ return replace_when_old;
+}
+
+/**
* Add an engine replacement for the company.
* @param c Company.
* @param old_engine The original engine type.
* @param new_engine The replacement engine type.
* @param group The group related to this replacement.
+ * @param replace_when_old Replace when old or always?
* @param flags The calling command flags.
* @return 0 on success, CMD_ERROR on failure.
*/
-static inline CommandCost AddEngineReplacementForCompany(Company *c, EngineID old_engine, EngineID new_engine, GroupID group, DoCommandFlag flags)
+static inline CommandCost AddEngineReplacementForCompany(Company *c, EngineID old_engine, EngineID new_engine, GroupID group, bool replace_when_old, DoCommandFlag flags)
{
- return AddEngineReplacement(&c->engine_renew_list, old_engine, new_engine, group, flags);
+ return AddEngineReplacement(&c->engine_renew_list, old_engine, new_engine, group, replace_when_old, flags);
}
/**