# HG changeset patch # User rubidium # Date 1217717795 0 # Node ID 8267a774aa12c9a1e2b1151449df7ef26cfcd636 # Parent 7838f660287a16bbb8ab4be2492f6e3fa02fc2b1 (svn r13963) -Codechange [YAPP]: Reserve a track when entering a PBS block through a conventional signal. (michi_cc) diff -r 7838f660287a -r 8267a774aa12 src/train_cmd.cpp --- a/src/train_cmd.cpp Sat Aug 02 22:56:21 2008 +0000 +++ b/src/train_cmd.cpp Sat Aug 02 22:56:35 2008 +0000 @@ -3396,14 +3396,18 @@ } } -static void TrainMovedChangeSignals(TileIndex tile, DiagDirection dir) +static bool TrainMovedChangeSignals(TileIndex tile, DiagDirection dir) { if (IsTileType(tile, MP_RAILWAY) && GetRailTileType(tile) == RAIL_TILE_SIGNALS) { TrackdirBits tracks = TrackBitsToTrackdirBits(GetTrackBits(tile)) & DiagdirReachesTrackdirs(dir); Trackdir trackdir = FindFirstTrackdir(tracks); - UpdateSignalsOnSegment(tile, TrackdirToExitdir(trackdir), GetTileOwner(tile)); + if (UpdateSignalsOnSegment(tile, TrackdirToExitdir(trackdir), GetTileOwner(tile)) == SIGSEG_PBS && HasSignalOnTrackdir(tile, trackdir)) { + /* A PBS block with a non-PBS signal facing us? */ + if (!IsPbsSignal(GetSignalType(tile, TrackdirToTrack(trackdir)))) return true; + } } + return false; } @@ -3766,7 +3770,23 @@ } if (update_signals_crossing) { - if (IsFrontEngine(v)) TrainMovedChangeSignals(gp.new_tile, enterdir); + if (IsFrontEngine(v)) { + if (TrainMovedChangeSignals(gp.new_tile, enterdir)) { + /* We are entering a block with PBS signals right now, but + * not through a PBS signal. This means we don't have a + * reservation right now. As a conventional signal will only + * ever be green if no other train is in the block, getting + * a path should always be possible. If the player built + * such a strange network that it is not possible, the train + * will be marked as stuck and the player has to deal with + * the problem. */ + if ((!HasReservedTracks(gp.new_tile, v->u.rail.track) && + !TryReserveRailTrack(gp.new_tile, FindFirstTrack(v->u.rail.track))) || + !TryPathReserve(v)) { + MarkTrainAsStuck(v); + } + } + } /* Signals can only change when the first * (above) or the last vehicle moves. */