From 7acdaaaf2f6c5f4a605031d25a891e16ff603965 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 18 Sep 2021 15:56:23 +0200 Subject: Fix: Prevent train reversing when wholly inside a train depot (#9557) Co-authored-by: Jonathan G Rennison --- src/train_cmd.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index f926be637..f5eb32d7f 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1809,6 +1809,14 @@ static void AdvanceWagonsAfterSwap(Train *v) } } +static bool IsWholeTrainInsideDepot(const Train *v) +{ + for (const Train *u = v; u != nullptr; u = u->Next()) { + if (u->track != TRACK_BIT_DEPOT || u->tile != v->tile) return false; + } + return true; +} + /** * Turn a train around. * @param v %Train to turn around. @@ -1816,6 +1824,7 @@ static void AdvanceWagonsAfterSwap(Train *v) void ReverseTrainDirection(Train *v) { if (IsRailDepotTile(v->tile)) { + if (IsWholeTrainInsideDepot(v)) return; InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); } -- cgit v1.2.3-70-g09d2