summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/aircraft_cmd.cpp14
-rw-r--r--src/roadveh_cmd.cpp18
-rw-r--r--src/ship_cmd.cpp16
-rw-r--r--src/train_cmd.cpp16
-rw-r--r--src/vehicle.cpp6
5 files changed, 12 insertions, 58 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 4f6098d79..db22fbd0a 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -696,17 +696,8 @@ CommandCost CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
static void CheckIfAircraftNeedsService(Vehicle *v)
{
- if (_patches.servint_aircraft == 0) return;
- if (!VehicleNeedsService(v)) return;
- if (v->vehstatus & VS_STOPPED) return;
-
- if (v->current_order.type == OT_GOTO_DEPOT &&
- v->current_order.flags & OF_HALT_IN_DEPOT)
- return;
-
- if (_patches.gotodepot && VehicleHasDepotOrders(v)) return;
-
- if (v->IsInDepot()) {
+ if (_patches.servint_aircraft == 0 || !VehicleNeedsService(v)) return;
+ if (v->IsInDepot()) {
VehicleServiceInDepot(v);
return;
}
@@ -716,7 +707,6 @@ static void CheckIfAircraftNeedsService(Vehicle *v)
if (st->IsValid() && st->airport_tile != 0 && st->Airport()->terminals != NULL) {
// printf("targetairport = %d, st->index = %d\n", v->u.air.targetairport, st->index);
// v->u.air.targetairport = st->index;
- if (v->current_order.type == OT_LOADING) v->LeaveStation();
v->current_order.type = OT_GOTO_DEPOT;
v->current_order.flags = OF_NON_STOP;
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index ccb0c6962..137ecd77e 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -1841,29 +1841,15 @@ void RoadVehicle::Tick()
static void CheckIfRoadVehNeedsService(Vehicle *v)
{
- const Depot* depot;
-
- if (_patches.servint_roadveh == 0) return;
- if (!VehicleNeedsService(v)) return;
- if (v->vehstatus & VS_STOPPED) return;
- if (_patches.gotodepot && VehicleHasDepotOrders(v)) return;
-
- /* Don't interfere with a depot visit scheduled by the user, or a
- * depot visit by the order list. */
- if (v->current_order.type == OT_GOTO_DEPOT &&
- (v->current_order.flags & (OF_HALT_IN_DEPOT | OF_PART_OF_ORDERS)) != 0)
- return;
-
/* If we already got a slot at a stop, use that FIRST, and go to a depot later */
- if (v->u.road.slot != NULL) return;
-
+ if (v->u.road.slot != NULL || _patches.servint_roadveh == 0 || !VehicleNeedsService(v)) return;
if (v->IsInDepot()) {
VehicleServiceInDepot(v);
return;
}
/* XXX If we already have a depot order, WHY do we search over and over? */
- depot = FindClosestRoadDepot(v);
+ const Depot *depot = FindClosestRoadDepot(v);
if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) {
if (v->current_order.type == OT_GOTO_DEPOT) {
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 5b13a2580..67e358d41 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -140,24 +140,13 @@ static const Depot* FindClosestShipDepot(const Vehicle* v)
static void CheckIfShipNeedsService(Vehicle *v)
{
- const Depot* depot;
-
- if (_patches.servint_ships == 0) return;
- if (!VehicleNeedsService(v)) return;
- if (v->vehstatus & VS_STOPPED) return;
-
- if (v->current_order.type == OT_GOTO_DEPOT &&
- v->current_order.flags & OF_HALT_IN_DEPOT)
- return;
-
- if (_patches.gotodepot && VehicleHasDepotOrders(v)) return;
-
+ if (_patches.servint_ships == 0 || !VehicleNeedsService(v)) return;
if (v->IsInDepot()) {
VehicleServiceInDepot(v);
return;
}
- depot = FindClosestShipDepot(v);
+ const Depot *depot = FindClosestShipDepot(v);
if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) {
if (v->current_order.type == OT_GOTO_DEPOT) {
@@ -168,7 +157,6 @@ static void CheckIfShipNeedsService(Vehicle *v)
return;
}
- if (v->current_order.type == OT_LOADING) v->LeaveStation();
v->current_order.type = OT_GOTO_DEPOT;
v->current_order.flags = OF_NON_STOP;
v->current_order.dest = depot->index;
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index caf665cf0..2981eec40 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -3348,18 +3348,8 @@ void Train::Tick()
static void CheckIfTrainNeedsService(Vehicle *v)
{
- if (_patches.servint_trains == 0) return;
- if (!VehicleNeedsService(v)) return;
- if (v->vehstatus & VS_STOPPED) return;
- if (_patches.gotodepot && VehicleHasDepotOrders(v)) return;
-
- /* Don't interfere with a depot visit scheduled by the user, or a
- * depot visit by the order list. */
- if (v->current_order.type == OT_GOTO_DEPOT &&
- (v->current_order.flags & (OF_HALT_IN_DEPOT | OF_PART_OF_ORDERS)) != 0)
- return;
-
- if (CheckTrainIsInsideDepot(v)) {
+ if (_patches.servint_trains == 0 || !VehicleNeedsService(v)) return;
+ if (v->IsInDepot()) {
VehicleServiceInDepot(v);
return;
}
@@ -3386,8 +3376,6 @@ static void CheckIfTrainNeedsService(Vehicle *v)
return;
}
- if (v->current_order.type == OT_LOADING) v->LeaveStation();
-
v->current_order.type = OT_GOTO_DEPOT;
v->current_order.flags = OF_NON_STOP;
v->current_order.dest = depot->index;
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 2e37d1c15..003f21b47 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -91,8 +91,10 @@ void VehicleServiceInDepot(Vehicle *v)
bool VehicleNeedsService(const Vehicle *v)
{
- if (v->vehstatus & VS_CRASHED)
- return false; // Crashed vehicles don't need service anymore
+ if (v->vehstatus & (VS_STOPPED | VS_CRASHED)) return false;
+ if (_patches.gotodepot && VehicleHasDepotOrders(v)) return false;
+ if (v->current_order.type == OT_LOADING) return false;
+ if (v->current_order.type == OT_GOTO_DEPOT && v->current_order.flags & OF_HALT_IN_DEPOT) 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 */