summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2008-04-08 15:48:32 +0000
committerfrosch <frosch@openttd.org>2008-04-08 15:48:32 +0000
commitb91781b715272c0248b766d4e92da812a3c203ee (patch)
treeaa0aa02603f911329fcc1e70972dd58ae153c69a /src
parent4267797cc8f7ee669122c22efeb5a6014644689f (diff)
downloadopenttd-b91781b715272c0248b766d4e92da812a3c203ee.tar.xz
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
-Fix (r11052): Disable servicing by service-interval if a vehicle has depot orders.
Diffstat (limited to 'src')
-rw-r--r--src/aircraft_cmd.cpp2
-rw-r--r--src/order_cmd.cpp2
-rw-r--r--src/roadveh_cmd.cpp2
-rw-r--r--src/ship_cmd.cpp2
-rw-r--r--src/train_cmd.cpp2
-rw-r--r--src/vehicle.cpp25
-rw-r--r--src/vehicle_base.h15
-rw-r--r--src/vehicle_func.h2
8 files changed, 35 insertions, 17 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index c81f5e220..4a94f95b0 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -703,7 +703,7 @@ CommandCost CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
static void CheckIfAircraftNeedsService(Vehicle *v)
{
- if (_patches.servint_aircraft == 0 || !VehicleNeedsService(v)) return;
+ if (_patches.servint_aircraft == 0 || !v->NeedsAutomaticServicing()) return;
if (v->IsInDepot()) {
VehicleServiceInDepot(v);
return;
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index adabeb4a3..f2583598b 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -1352,7 +1352,7 @@ bool ProcessOrders(Vehicle *v)
/* Let a depot order in the orderlist interrupt. */
if (!(v->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) return false;
- if ((v->current_order.GetDepotOrderType() & ODTFB_SERVICE) && !VehicleNeedsService(v)) {
+ if ((v->current_order.GetDepotOrderType() & ODTFB_SERVICE) && !v->NeedsServicing()) {
UpdateVehicleTimetable(v, true);
v->cur_order_index++;
}
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index fba9831cc..a26180837 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -1911,7 +1911,7 @@ void RoadVehicle::Tick()
static void CheckIfRoadVehNeedsService(Vehicle *v)
{
/* If we already got a slot at a stop, use that FIRST, and go to a depot later */
- if (v->u.road.slot != NULL || _patches.servint_roadveh == 0 || !VehicleNeedsService(v)) return;
+ if (v->u.road.slot != NULL || _patches.servint_roadveh == 0 || !v->NeedsAutomaticServicing()) return;
if (v->IsInDepot()) {
VehicleServiceInDepot(v);
return;
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index b3656e9ef..4f5b956d9 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -144,7 +144,7 @@ static const Depot* FindClosestShipDepot(const Vehicle* v)
static void CheckIfShipNeedsService(Vehicle *v)
{
- if (_patches.servint_ships == 0 || !VehicleNeedsService(v)) return;
+ if (_patches.servint_ships == 0 || !v->NeedsAutomaticServicing()) return;
if (v->IsInDepot()) {
VehicleServiceInDepot(v);
return;
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 0447d711c..72a0e1784 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -3543,7 +3543,7 @@ static void CheckIfTrainNeedsService(Vehicle *v)
{
static const uint MAX_ACCEPTABLE_DEPOT_DIST = 16;
- if (_patches.servint_trains == 0 || !VehicleNeedsService(v)) return;
+ if (_patches.servint_trains == 0 || !v->NeedsAutomaticServicing()) return;
if (v->IsInDepot()) {
VehicleServiceInDepot(v);
return;
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)
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index 2aaba064a..bd57e99c1 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -490,6 +490,21 @@ public:
bool NeedsAutorenewing(const Player *p) const;
/**
+ * Check if the vehicle needs to go to a depot in near future (if a opportunity presents itself) for service or replacement.
+ *
+ * @see NeedsAutomaticServicing()
+ * @return true if the vehicle should go to a depot if a opportunity presents itself.
+ */
+ bool NeedsServicing() const;
+
+ /**
+ * Checks if the current order should be interupted for a service-in-depot-order.
+ * @see NeedsServicing()
+ * @return true if the current order should be interupted.
+ */
+ bool NeedsAutomaticServicing() const;
+
+ /**
* Determine the location for the station where the vehicle goes to next.
* Things done for example are allocating slots in a road stop or exact
* location of the platform is determined for ships.
diff --git a/src/vehicle_func.h b/src/vehicle_func.h
index 28355dc11..460f30f5e 100644
--- a/src/vehicle_func.h
+++ b/src/vehicle_func.h
@@ -66,8 +66,6 @@ void TrainConsistChanged(Vehicle *v);
void TrainPowerChanged(Vehicle *v);
Money GetTrainRunningCost(const Vehicle *v);
-bool VehicleNeedsService(const Vehicle *v);
-
uint GenerateVehicleSortList(const Vehicle*** sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type);
void BuildDepotVehicleList(VehicleType type, TileIndex tile, Vehicle ***engine_list, uint16 *engine_list_length, uint16 *engine_count, Vehicle ***wagon_list, uint16 *wagon_list_length, uint16 *wagon_count);
CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id);