changeset 18839:1d05c702134c draft

(svn r23688) -Codechange: No need to check if a train needs servicing if we only extend a train's path without actually calling the pathfinder. The path extension will stop when hitting a junction tile, so it is impossible to miss a depot this way.
author michi_cc <michi_cc@openttd.org>
date Fri, 30 Dec 2011 17:56:37 +0000
parents 2ec03d6f7fa6
children e67dec11753f
files src/train_cmd.cpp
diffstat 1 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -2448,12 +2448,6 @@
 	PBSTileInfo   res_dest(tile, INVALID_TRACKDIR, false);
 	DiagDirection dest_enterdir = enterdir;
 	if (do_track_reservation) {
-		/* Check if the train needs service here, so it has a chance to always find a depot.
-		 * Also check if the current order is a service order so we don't reserve a path to
-		 * the destination but instead to the next one if service isn't needed. */
-		CheckIfTrainNeedsService(v);
-		if (v->current_order.IsType(OT_DUMMY) || v->current_order.IsType(OT_CONDITIONAL) || v->current_order.IsType(OT_GOTO_DEPOT)) ProcessOrders(v);
-
 		res_dest = ExtendTrainReservation(v, &tracks, &dest_enterdir);
 		if (res_dest.tile == INVALID_TILE) {
 			/* Reservation failed? */
@@ -2461,6 +2455,19 @@
 			if (changed_signal) SetSignalStateByTrackdir(tile, TrackEnterdirToTrackdir(best_track, enterdir), SIGNAL_STATE_RED);
 			return FindFirstTrack(tracks);
 		}
+		if (res_dest.okay) {
+			/* Got a valid reservation that ends at a safe target, quick exit. */
+			if (got_reservation != NULL) *got_reservation = true;
+			if (changed_signal) MarkTileDirtyByTile(tile);
+			TryReserveRailTrack(v->tile, TrackdirToTrack(v->GetVehicleTrackdir()));
+			return best_track;
+		}
+
+		/* Check if the train needs service here, so it has a chance to always find a depot.
+		 * Also check if the current order is a service order so we don't reserve a path to
+		 * the destination but instead to the next one if service isn't needed. */
+		CheckIfTrainNeedsService(v);
+		if (v->current_order.IsType(OT_DUMMY) || v->current_order.IsType(OT_CONDITIONAL) || v->current_order.IsType(OT_GOTO_DEPOT)) ProcessOrders(v);
 	}
 
 	/* Save the current train order. The destructor will restore the old order on function exit. */