From 7126fcafcc29f4f00b752da2a5dc3dac58f21a5b Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 15 Jul 2026 12:40:37 +0100 Subject: [PATCH] Fix: Rail depot overbuild did not handle associated reservation (#15860) --- src/rail_cmd.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 9cbc55922c..939a5d6c54 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -990,15 +990,21 @@ CommandCost CmdBuildTrainDepot(DoCommandFlags flags, TileIndex tile, RailType ra /* Allow the user to rotate the depot instead of having to destroy it and build it again */ bool rotate_existing_depot = false; + Train *v = nullptr; if (IsRailDepotTile(tile) && railtype == GetRailType(tile)) { CommandCost ret = CheckTileOwnership(tile); if (ret.Failed()) return ret; - if (dir == GetRailDepotDirection(tile)) return CommandCost(); + DiagDirection old_dir = GetRailDepotDirection(tile); + if (dir == old_dir) return CommandCost(); ret = EnsureNoVehicleOnGround(tile); if (ret.Failed()) return ret; + if (HasDepotReservation(tile)) { + v = GetTrainForReservation(tile, DiagDirToDiagTrack(old_dir)); + } + rotate_existing_depot = true; } @@ -1015,7 +1021,10 @@ CommandCost CmdBuildTrainDepot(DoCommandFlags flags, TileIndex tile, RailType ra } if (flags.Test(DoCommandFlag::Execute)) { + if (v != nullptr) FreeTrainTrackReservation(v); + if (rotate_existing_depot) { + SetDepotReservation(tile, false); SetRailDepotExitDirection(tile, dir); } else { Depot *d = Depot::Create(tile); @@ -1030,6 +1039,8 @@ CommandCost CmdBuildTrainDepot(DoCommandFlags flags, TileIndex tile, RailType ra MarkTileDirtyByTile(tile); AddSideToSignalBuffer(tile, DiagDirection::Invalid, _current_company); YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir)); + + if (v != nullptr) TryPathReserve(v, true); } cost.AddCost(_price[Price::BuildDepotTrain]);