From 70ef0f562b6544d48f24864aa5b3ffb91df43a0a Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 18 Aug 2019 14:40:24 +0100 Subject: [PATCH] Fix train reverse inside signalled tunnel/bridge entrance clearing reservation of incoming train --- src/train_cmd.cpp | 3 +++ src/tunnelbridge_map.h | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 071d78acd3..625e5b6174 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2725,6 +2725,9 @@ void FreeTrainTrackReservation(const Train *v, TileIndex origin, Trackdir orig_t /* Don't free reservation if it's not ours. */ if (TracksOverlap(GetReservedTrackbits(tile) | TrackToTrackBits(TrackdirToTrack(td)))) return; + /* Do not attempt to unreserve out of a signalled tunnel/bridge entrance, as this would unreserve the reservations of another train coming in */ + if (IsTunnelBridgeWithSignalSimulation(tile) && TrackdirExitsTunnelBridge(tile, td) && IsTunnelBridgeSignalSimulationEntranceOnly(tile)) return; + CFollowTrackRail ft(v, GetRailTypeInfo(v->railtype)->compatible_railtypes); while (ft.Follow(tile, td)) { tile = ft.m_new_tile; diff --git a/src/tunnelbridge_map.h b/src/tunnelbridge_map.h index 4b2202dc10..775c2f307b 100644 --- a/src/tunnelbridge_map.h +++ b/src/tunnelbridge_map.h @@ -372,6 +372,18 @@ static inline bool IsTunnelBridgeSignalSimulationEntrance(TileIndex t) return HasBit(_m[t].m5, 5); } +/** + * Is this a tunnel/bridge entrance tile with signal only? + * @param t the tile that might be a tunnel/bridge. + * @pre IsTileType(t, MP_TUNNELBRIDGE) + * @return true if and only if this tile is a tunnel/bridge entrance only. + */ +static inline bool IsTunnelBridgeSignalSimulationEntranceOnly(TileIndex t) +{ + assert_tile(IsTileType(t, MP_TUNNELBRIDGE), t); + return HasBit(_m[t].m5, 5) && !HasBit(_m[t].m5, 6); +} + /** * Is this a tunnel/bridge exit? * @param t the tile that might be a tunnel/bridge.