(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
authorbjarni
Sun, 03 Sep 2006 11:49:38 +0000
changeset 4529 2bfac24af02a
parent 4528 80cc2712b176
child 4530 8582c903c22c
(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
aircraft_cmd.c
roadveh_cmd.c
ship_cmd.c
train_cmd.c
--- a/aircraft_cmd.c	Sun Sep 03 10:30:38 2006 +0000
+++ b/aircraft_cmd.c	Sun Sep 03 11:49:38 2006 +0000
@@ -667,6 +667,11 @@
 
 	if (_patches.gotodepot && VehicleHasDepotOrders(v)) return;
 
+	if (IsAircraftInHangar(v)) {
+		VehicleServiceInDepot(v);
+		return;
+	}
+
 	st = GetStation(v->current_order.dest);
 	// only goto depot if the target airport has terminals (eg. it is airport)
 	if (IsValidStation(st) && st->airport_tile != 0 && GetAirport(st->airport_type)->terminals != NULL) {
--- a/roadveh_cmd.c	Sun Sep 03 10:30:38 2006 +0000
+++ b/roadveh_cmd.c	Sun Sep 03 11:49:38 2006 +0000
@@ -1640,6 +1640,11 @@
 	// 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 (IsRoadVehInDepot(v)) {
+		VehicleServiceInDepot(v);
+		return;
+	}
+
 	// XXX If we already have a depot order, WHY do we search over and over?
 	depot = FindClosestRoadDepot(v);
 
--- a/ship_cmd.c	Sun Sep 03 10:30:38 2006 +0000
+++ b/ship_cmd.c	Sun Sep 03 11:49:38 2006 +0000
@@ -112,6 +112,11 @@
 
 	if (_patches.gotodepot && VehicleHasDepotOrders(v)) return;
 
+	if (IsShipInDepot(v)) {
+		VehicleServiceInDepot(v);
+		return;
+	}
+
 	depot = FindClosestShipDepot(v);
 
 	if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) {
--- a/train_cmd.c	Sun Sep 03 10:30:38 2006 +0000
+++ b/train_cmd.c	Sun Sep 03 11:49:38 2006 +0000
@@ -829,7 +829,7 @@
 
 /* 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 @@
 		 * 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 @@
 	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 @@
 			(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) {