From 977c1fa68a06bdb04c16165ccbcd65554f026186 Mon Sep 17 00:00:00 2001 From: michi_cc Date: Fri, 30 Dec 2011 17:56:37 +0000 Subject: (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. --- src/train_cmd.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index c3eb8c1fa..1015d8dd3 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2448,12 +2448,6 @@ static Track ChooseTrainTrack(Train *v, TileIndex tile, DiagDirection enterdir, 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 @@ static Track ChooseTrainTrack(Train *v, TileIndex tile, DiagDirection enterdir, 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. */ -- cgit v1.2.3-54-g00ecf