From 96700d560560215ec24d283d774f7dbaa11c384c Mon Sep 17 00:00:00 2001 From: frosch Date: Tue, 8 Apr 2008 15:48:32 +0000 Subject: (svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing(). -Fix (r11052): Disable servicing by service-interval if a vehicle has depot orders. --- src/vehicle.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src/vehicle.cpp') diff --git a/src/vehicle.cpp b/src/vehicle.cpp index c8c963b7c..60f212b2d 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -118,22 +118,27 @@ void VehicleServiceInDepot(Vehicle *v) InvalidateWindow(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated } -bool VehicleNeedsService(const Vehicle *v) +bool Vehicle::NeedsServicing() const { - if (v->vehstatus & (VS_STOPPED | VS_CRASHED)) return false; - if (!v->current_order.IsType(OT_GOTO_DEPOT) || !(v->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) { // Don't interfere with a depot visit by the order list - if (_patches.gotodepot && VehicleHasDepotOrders(v)) return false; - if (v->current_order.IsType(OT_LOADING)) return false; - if (v->current_order.IsType(OT_GOTO_DEPOT) && v->current_order.GetDepotActionType() & ODATFB_HALT) return false; - } + if (this->vehstatus & (VS_STOPPED | VS_CRASHED)) return false; if (_patches.no_servicing_if_no_breakdowns && _opt.diff.vehicle_breakdowns == 0) { - return EngineHasReplacementForPlayer(GetPlayer(v->owner), v->engine_type, v->group_id); /* Vehicles set for autoreplacing needs to go to a depot even if breakdowns are turned off */ + /* 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 EngineHasReplacementForPlayer(GetPlayer(this->owner), this->engine_type, this->group_id); } return _patches.servint_ispercent ? - (v->reliability < GetEngine(v->engine_type)->reliability * (100 - v->service_interval) / 100) : - (v->date_of_last_service + v->service_interval < _date); + (this->reliability < GetEngine(this->engine_type)->reliability * (100 - this->service_interval) / 100) : + (this->date_of_last_service + this->service_interval < _date); +} + +bool Vehicle::NeedsAutomaticServicing() const +{ + if (_patches.gotodepot && VehicleHasDepotOrders(this)) return false; + if (this->current_order.IsType(OT_LOADING)) return false; + if (this->current_order.IsType(OT_GOTO_DEPOT) && this->current_order.GetDepotActionType() & ODATFB_HALT) return false; + return NeedsServicing(); } StringID VehicleInTheWayErrMsg(const Vehicle* v) -- cgit v1.2.3-54-g00ecf