summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-08-03 11:28:35 +0000
committersmatz <smatz@openttd.org>2008-08-03 11:28:35 +0000
commit98bb9ffada60531d9c0e698831f224bb98ca9bc2 (patch)
tree22560187fa49fbc21ee69e273d25e241b32f2548 /src
parentbd0f9f1097792a333035dd05b594db4abfba17da (diff)
downloadopenttd-98bb9ffada60531d9c0e698831f224bb98ca9bc2.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.cpp15
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);
}