src/vehicle.cpp
changeset 10098 00ebbccc6181
parent 10081 e46b9eb2f9c1
child 10117 6a796f06bff4
equal deleted inserted replaced
10097:854e70c3bea6 10098:00ebbccc6181
   116 	v->breakdowns_since_last_service = 0;
   116 	v->breakdowns_since_last_service = 0;
   117 	v->reliability = GetEngine(v->engine_type)->reliability;
   117 	v->reliability = GetEngine(v->engine_type)->reliability;
   118 	InvalidateWindow(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated
   118 	InvalidateWindow(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated
   119 }
   119 }
   120 
   120 
   121 bool VehicleNeedsService(const Vehicle *v)
   121 bool Vehicle::NeedsServicing() const
   122 {
   122 {
   123 	if (v->vehstatus & (VS_STOPPED | VS_CRASHED))       return false;
   123 	if (this->vehstatus & (VS_STOPPED | VS_CRASHED)) return false;
   124 	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
       
   125 		if (_patches.gotodepot && VehicleHasDepotOrders(v)) return false;
       
   126 		if (v->current_order.IsType(OT_LOADING))            return false;
       
   127 		if (v->current_order.IsType(OT_GOTO_DEPOT) && v->current_order.GetDepotActionType() & ODATFB_HALT) return false;
       
   128 	}
       
   129 
   124 
   130 	if (_patches.no_servicing_if_no_breakdowns && _opt.diff.vehicle_breakdowns == 0) {
   125 	if (_patches.no_servicing_if_no_breakdowns && _opt.diff.vehicle_breakdowns == 0) {
   131 		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 */
   126 		/* Vehicles set for autoreplacing needs to go to a depot even if breakdowns are turned off.
       
   127 		 * Note: If servicing is enabled, we postpone replacement till next service. */
       
   128 		return EngineHasReplacementForPlayer(GetPlayer(this->owner), this->engine_type, this->group_id);
   132 	}
   129 	}
   133 
   130 
   134 	return _patches.servint_ispercent ?
   131 	return _patches.servint_ispercent ?
   135 		(v->reliability < GetEngine(v->engine_type)->reliability * (100 - v->service_interval) / 100) :
   132 		(this->reliability < GetEngine(this->engine_type)->reliability * (100 - this->service_interval) / 100) :
   136 		(v->date_of_last_service + v->service_interval < _date);
   133 		(this->date_of_last_service + this->service_interval < _date);
       
   134 }
       
   135 
       
   136 bool Vehicle::NeedsAutomaticServicing() const
       
   137 {
       
   138 	if (_patches.gotodepot && VehicleHasDepotOrders(this)) return false;
       
   139 	if (this->current_order.IsType(OT_LOADING))            return false;
       
   140 	if (this->current_order.IsType(OT_GOTO_DEPOT) && this->current_order.GetDepotActionType() & ODATFB_HALT) return false;
       
   141 	return NeedsServicing();
   137 }
   142 }
   138 
   143 
   139 StringID VehicleInTheWayErrMsg(const Vehicle* v)
   144 StringID VehicleInTheWayErrMsg(const Vehicle* v)
   140 {
   145 {
   141 	switch (v->type) {
   146 	switch (v->type) {