Fix: Prevent train reversing when wholly inside a train depot (#9557)

Co-authored-by: Jonathan G Rennison <j.g.rennison@gmail.com>
This commit is contained in:
Patric Stout 2021-09-18 15:56:23 +02:00 committed by GitHub
parent 18247bb3b8
commit 7acdaaaf2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}