summaryrefslogtreecommitdiff
path: root/src/vehicle.cpp
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/vehicle.cpp
parented565853889679a409d601a61d661718ac3498cc (diff)
downloadopenttd-6a70abbd998ed5b54d52ddb44b4df8521413185c.tar.xz
(svn r24136) -Feature [FS#4465]: Autoreplace vehicles only when they get old. (Vikthor)
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r--src/vehicle.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 8be891b2f..1db865ef9 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -67,9 +67,10 @@ INSTANTIATE_POOL_METHODS(Vehicle)
/**
* Function to tell if a vehicle needs to be autorenewed
* @param *c The vehicle owner
+ * @param use_renew_setting Should the company renew setting be considered?
* @return true if the vehicle is old enough for replacement
*/
-bool Vehicle::NeedsAutorenewing(const Company *c) const
+bool Vehicle::NeedsAutorenewing(const Company *c, bool use_renew_setting) const
{
/* We can always generate the Company pointer when we have the vehicle.
* However this takes time and since the Company pointer is often present
@@ -77,7 +78,7 @@ bool Vehicle::NeedsAutorenewing(const Company *c) const
* argument rather than finding it again. */
assert(c == Company::Get(this->owner));
- if (!c->settings.engine_renew) return false;
+ if (use_renew_setting && !c->settings.engine_renew) return false;
if (this->age - this->max_age < (c->settings.engine_renew_months * 30)) return false;
/* Only engines need renewing */
@@ -131,10 +132,13 @@ bool Vehicle::NeedsServicing() const
if (needed_money > c->money) return false;
for (const Vehicle *v = this; v != NULL; v = (v->type == VEH_TRAIN) ? Train::From(v)->GetNextUnit() : NULL) {
- EngineID new_engine = EngineReplacementForCompany(c, v->engine_type, v->group_id);
+ bool replace_when_old = false;
+ EngineID new_engine = EngineReplacementForCompany(c, v->engine_type, v->group_id, &replace_when_old);
/* Check engine availability */
if (new_engine == INVALID_ENGINE || !HasBit(Engine::Get(new_engine)->company_avail, v->owner)) continue;
+ /* Is the vehicle old if we are not always replacing? */
+ if (replace_when_old && !v->NeedsAutorenewing(c, false)) continue;
/* Check refittability */
uint32 available_cargo_types, union_mask;