summaryrefslogtreecommitdiff
path: root/src/autoreplace_cmd.cpp
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2008-02-23 22:01:55 +0000
committerbjarni <bjarni@openttd.org>2008-02-23 22:01:55 +0000
commit973d1fd6ad97ad17a2b8e25e2059cc1faa933894 (patch)
tree749b019a5a21f0d18977297475fb38406c644ebf /src/autoreplace_cmd.cpp
parent4e90a42f0c7635879b28aa7d28621f8c20fc025a (diff)
downloadopenttd-973d1fd6ad97ad17a2b8e25e2059cc1faa933894.tar.xz
(svn r12230) -Codechange: [autoreplace] made a function to detect if a vehicle needs autorenewing
This will remove duplicated code and ensure that the check is consistent
Diffstat (limited to 'src/autoreplace_cmd.cpp')
-rw-r--r--src/autoreplace_cmd.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index 57083e1ab..90ff7fafe 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -25,6 +25,16 @@
#include "table/strings.h"
+bool Vehicle::NeedsAutorenewing(const Player *p) const
+{
+ assert(p == GetPlayer(this->owner));
+
+ if (!p->engine_renew) return false;
+ if (this->age - this->max_age < (p->engine_renew_months * 30)) return false;
+
+ return true;
+}
+
/*
* move the cargo from one engine to another if possible
*/
@@ -342,8 +352,7 @@ CommandCost MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs)
}
// check if the vehicle should be replaced
- if (!p->engine_renew ||
- w->age - w->max_age < (p->engine_renew_months * 30) || // replace if engine is too old
+ if (!w->NeedsAutorenewing(p) || // replace if engine is too old
w->max_age == 0) { // rail cars got a max age of 0
/* If the vehicle belongs to a group, check if the group is protected from the global autoreplace.
If not, chek if an global auto remplacement is defined */