summaryrefslogtreecommitdiff
path: root/train_cmd.c
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-09-03 11:49:38 +0000
committerbjarni <bjarni@openttd.org>2006-09-03 11:49:38 +0000
commit6baf4888392407fdd8f08b948fd6a4087ebd107b (patch)
treecbbd6966c9d25e321e0ce148f06610e534e7422d /train_cmd.c
parent23168f630952490f6a548f1889e1a3b035b29f1d (diff)
downloadopenttd-6baf4888392407fdd8f08b948fd6a4087ebd107b.tar.xz
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
Now all vehicles are serviced when it's time for service and they are in a depot This will avoid the goto depot order from ever showing up when in a depot
Diffstat (limited to 'train_cmd.c')
-rw-r--r--train_cmd.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/train_cmd.c b/train_cmd.c
index 8b033054d..a1fcf2938 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -829,7 +829,7 @@ int32 CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
/* Check if all the wagons of the given train are in a depot, returns the
* number of cars (including loco) then. If not it returns -1 */
-int CheckTrainStoppedInDepot(const Vehicle *v)
+static int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped)
{
int count;
TileIndex tile = v->tile;
@@ -846,7 +846,7 @@ int CheckTrainStoppedInDepot(const Vehicle *v)
* Also skip counting rear ends of multiheaded engines */
if (!IsArticulatedPart(v) && !(!IsTrainEngine(v) && IsMultiheaded(v))) count++;
if (v->u.rail.track != 0x80 || v->tile != tile ||
- (IsFrontEngine(v) && !(v->vehstatus & VS_STOPPED))) {
+ (IsFrontEngine(v) && needs_to_be_stopped && !(v->vehstatus & VS_STOPPED))) {
return -1;
}
}
@@ -854,6 +854,18 @@ int CheckTrainStoppedInDepot(const Vehicle *v)
return count;
}
+/* Used to check if the train is inside the depot and verifying that the VS_STOPPED flag is set */
+inline int CheckTrainStoppedInDepot(const Vehicle *v)
+{
+ return CheckTrainInDepot(v, true);
+}
+
+/* Used to check if the train is inside the depot, but not checking the VS_STOPPED flag */
+inline bool CheckTrainIsInsideDepot(const Vehicle *v)
+{
+ return (CheckTrainInDepot(v, false) > 0);
+}
+
/**
* Unlink a rail wagon from the consist.
* @param v Vehicle to remove.
@@ -3511,6 +3523,11 @@ static void CheckIfTrainNeedsService(Vehicle *v)
(v->current_order.flags & (OF_HALT_IN_DEPOT | OF_PART_OF_ORDERS)) != 0)
return;
+ if (CheckTrainIsInsideDepot(v)) {
+ VehicleServiceInDepot(v);
+ return;
+ }
+
tfdd = FindClosestTrainDepot(v, MAX_ACCEPTABLE_DEPOT_DIST);
/* Only go to the depot if it is not too far out of our way. */
if (tfdd.best_length == (uint)-1 || tfdd.best_length > MAX_ACCEPTABLE_DEPOT_DIST) {