# HG changeset patch # User Patric Stout # Date 2021-09-18 13:56:23 # Node ID 453e1656120bd1f6b5333ea333ae6f87bba66e87 # Parent 7acdd433f2c3e87bb9e21f7d9eb72acb9269ac09 Fix: Prevent train reversing when wholly inside a train depot (#9557) Co-authored-by: Jonathan G Rennison diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1809,6 +1809,14 @@ static void AdvanceWagonsAfterSwap(Train } } +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 void ReverseTrainDirection(Train *v) { if (IsRailDepotTile(v->tile)) { + if (IsWholeTrainInsideDepot(v)) return; InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); }