summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-08-02 22:56:50 +0000
committerrubidium <rubidium@openttd.org>2008-08-02 22:56:50 +0000
commit14f6b1f49c0c5bf6c280c1dd4882498a64230b6d (patch)
treef2a9bf76d674a4af8c6ebd848484b919afd93dda
parente0e8f0e7116c5ca74a2ccc68b5e70f43cbda000c (diff)
downloadopenttd-14f6b1f49c0c5bf6c280c1dd4882498a64230b6d.tar.xz
(svn r13964) -Codechange [YAPP]: Check if a train needs servicing when reserving the next path segment. (michi_cc)
-rw-r--r--src/train_cmd.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 38d2a95cf..d774a7ee6 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -63,6 +63,7 @@ static Track ChooseTrainTrack(Vehicle* v, TileIndex tile, DiagDirection enterdir
static bool TrainCheckIfLineEnds(Vehicle *v);
static void TrainController(Vehicle *v, Vehicle *nomove, bool update_image);
static TileIndex TrainApproachingCrossingTile(const Vehicle *v);
+static void CheckIfTrainNeedsService(Vehicle *v);
static void CheckNextTrainTile(Vehicle *v);
static const byte _vehicle_initial_x_fract[4] = {10, 8, 4, 8};
@@ -2892,7 +2893,11 @@ static Track ChooseTrainTrack(Vehicle* v, TileIndex tile, DiagDirection enterdir
PBSTileInfo res_dest(tile, INVALID_TRACKDIR, false);
DiagDirection dest_enterdir = enterdir;
if (do_track_reservation) {
- if (v->current_order.IsType(OT_DUMMY) || v->current_order.IsType(OT_CONDITIONAL)) ProcessOrders(v);
+ /* 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) {