diff options
author | smatz <smatz@openttd.org> | 2008-08-03 11:28:35 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2008-08-03 11:28:35 +0000 |
commit | 9a1958be91096d77294c196fa543d6e45b7c9873 (patch) | |
tree | 22560187fa49fbc21ee69e273d25e241b32f2548 /src | |
parent | 6639c496c3c8ba5297d4ee979cb14a1bfebf3058 (diff) | |
download | openttd-9a1958be91096d77294c196fa543d6e45b7c9873.tar.xz |
(svn r13973) -Codechange [YAPP]: Improve the behavior when changing signals to not cause stale reservations. (michi_cc)
Diffstat (limited to 'src')
-rw-r--r-- | src/rail_cmd.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index fd3755e5e..80d5de887 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -877,6 +877,15 @@ CommandCost CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 } if (flags & DC_EXEC) { + Vehicle *v = NULL; + /* The new/changed signal could block our path. As this can lead to + * stale reservations, we clear the path reservation here and try + * to redo it later on. */ + if (HasReservedTracks(tile, TrackToTrackBits(track))) { + v = GetTrainForReservation(tile, track); + if (v != NULL) FreeTrainTrackReservation(v); + } + if (!HasSignals(tile)) { /* there are no signals at all on this tile yet */ SetHasSignals(tile, true); @@ -938,6 +947,7 @@ CommandCost CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 MarkTileDirtyByTile(tile); AddTrackToSignalBuffer(tile, track, _current_player); YapfNotifyTrackLayoutChange(tile, track); + if (v != NULL) TryPathReserve(v, true); } return cost; @@ -1166,6 +1176,10 @@ CommandCost CmdRemoveSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint3 /* Do it? */ if (flags & DC_EXEC) { + Vehicle *v = NULL; + if (HasReservedTracks(tile, TrackToTrackBits(track))) { + v = GetTrainForReservation(tile, track); + } SetPresentSignals(tile, GetPresentSignals(tile) & ~SignalOnTrack(track)); /* removed last signal from tile? */ @@ -1177,6 +1191,7 @@ CommandCost CmdRemoveSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint3 AddTrackToSignalBuffer(tile, track, GetTileOwner(tile)); YapfNotifyTrackLayoutChange(tile, track); + if (v != NULL) TryPathReserve(v, false); MarkTileDirtyByTile(tile); } |