summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-12-19 21:19:45 +0000
committerrubidium <rubidium@openttd.org>2009-12-19 21:19:45 +0000
commitd48ad4b6e33bef9d3360f4a1cacccece6591b3c0 (patch)
treec0075619f8f6e784c53bcb2dab1685d9f2bf7d35 /src
parente97f828c64ee9f2249b676bbb16685d77ea7fcb8 (diff)
downloadopenttd-d48ad4b6e33bef9d3360f4a1cacccece6591b3c0.tar.xz
(svn r18549) -Fix: first do the time-since-last-service check and only then determine whether autoreplace needs to take place. This way they will not keep autoreplacing continuously on failure, but only after some timeout.
Diffstat (limited to 'src')
-rw-r--r--src/vehicle.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 3779c07bc..839351090 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -91,17 +91,27 @@ void VehicleServiceInDepot(Vehicle *v)
bool Vehicle::NeedsServicing() const
{
+ /* Stopped or crashed vehicles will not move, as such making unmovable
+ * vehicles to go for service is lame. */
if (this->vehstatus & (VS_STOPPED | VS_CRASHED)) return false;
- if (_settings_game.order.no_servicing_if_no_breakdowns && _settings_game.difficulty.vehicle_breakdowns == 0) {
- /* Vehicles set for autoreplacing needs to go to a depot even if breakdowns are turned off.
- * Note: If servicing is enabled, we postpone replacement till next service. */
- return EngineHasReplacementForCompany(Company::Get(this->owner), this->engine_type, this->group_id);
+ /* Are we ready for the next service cycle? */
+ if (Company::Get(this->owner)->settings.vehicle.servint_ispercent ?
+ (this->reliability >= Engine::Get(this->engine_type)->reliability * (100 - this->service_interval) / 100) :
+ (this->date_of_last_service + this->service_interval >= _date)) {
+ return false;
+ }
+
+ /* If we're servicing anyway, because we have not disabled servicing when
+ * there are no breakdowns or we are playing with breakdowns, bail out. */
+ if (!_settings_game.order.no_servicing_if_no_breakdowns ||
+ _settings_game.difficulty.vehicle_breakdowns != 0) {
+ return true;
}
- return Company::Get(this->owner)->settings.vehicle.servint_ispercent ?
- (this->reliability < Engine::Get(this->engine_type)->reliability * (100 - this->service_interval) / 100) :
- (this->date_of_last_service + this->service_interval < _date);
+ /* Vehicles set for autoreplacing needs to go to a depot even if breakdowns are turned off.
+ * Note: If servicing is enabled, we postpone replacement till next service. */
+ return EngineHasReplacementForCompany(Company::Get(this->owner), this->engine_type, this->group_id);
}
bool Vehicle::NeedsAutomaticServicing() const