summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2012-03-29 12:27:34 +0000
committermichi_cc <michi_cc@openttd.org>2012-03-29 12:27:34 +0000
commit7e438d27f15b3fbc523bd84c4d97c364752b8554 (patch)
treebcbb0ab5a7d53c442860e8be65c466f6dd127a44 /src
parent4bbea6ee636da2eeceb42072b39b2bf0793dfab8 (diff)
downloadopenttd-7e438d27f15b3fbc523bd84c4d97c364752b8554.tar.xz
(svn r24078) -Fix [FS#5093,FS#5130] (r24071): A fix that breaks all other cases isn't really a fix. Redo it to make sure that reservations of trains entering or exiting depots are properly made and freed.
Diffstat (limited to 'src')
-rw-r--r--src/pbs.cpp3
-rw-r--r--src/train_cmd.cpp13
2 files changed, 12 insertions, 4 deletions
diff --git a/src/pbs.cpp b/src/pbs.cpp
index 3dbd5b883..01e7b2f37 100644
--- a/src/pbs.cpp
+++ b/src/pbs.cpp
@@ -369,8 +369,7 @@ Train *GetTrainForReservation(TileIndex tile, Track track)
*/
bool IsSafeWaitingPosition(const Train *v, TileIndex tile, Trackdir trackdir, bool include_line_end, bool forbid_90deg)
{
- /* A depot is safe if we enter it, but not when we exit. */
- if (IsRailDepotTile(tile) && TrackdirToExitdir(trackdir) != GetRailDepotDirection(tile)) return true;
+ if (IsRailDepotTile(tile)) return true;
if (IsTileType(tile, MP_RAILWAY)) {
/* For non-pbs signals, stop on the signal tile. */
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 101aeca0a..2de9dd5e8 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1827,6 +1827,9 @@ void ReverseTrainDirection(Train *v)
HasSignalOnTrackdir(v->tile, v->GetVehicleTrackdir()) &&
!IsPbsSignal(GetSignalType(v->tile, FindFirstTrack(v->track))));
+ /* If we are on a depot tile facing outwards, do not treat the current tile as safe. */
+ if (IsRailDepotTile(v->tile) && TrackdirToExitdir(v->GetVehicleTrackdir()) == GetRailDepotDirection(v->tile)) first_tile_okay = false;
+
if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), true);
if (TryPathReserve(v, false, first_tile_okay)) {
/* Do a look-ahead now in case our current tile was already a safe tile. */
@@ -2200,8 +2203,14 @@ void FreeTrainTrackReservation(const Train *v, TileIndex origin, Trackdir orig_t
bool free_tile = tile != v->tile || !(IsRailStationTile(v->tile) || IsTileType(v->tile, MP_TUNNELBRIDGE));
StationID station_id = IsRailStationTile(v->tile) ? GetStationIndex(v->tile) : INVALID_STATION;
- /* A train inside a depot can't have a reservation. */
- if (v->track == TRACK_BIT_DEPOT) return;
+ /* Can't be holding a reservation if we enter a depot. */
+ if (IsRailDepotTile(tile) && TrackdirToExitdir(td) != GetRailDepotDirection(tile)) return;
+ if (v->track == TRACK_BIT_DEPOT) {
+ /* Front engine is in a depot. We enter if some part is not in the depot. */
+ for (const Train *u = v; u != NULL; u = u->Next()) {
+ if (u->track != TRACK_BIT_DEPOT || u->tile != v->tile) return;
+ }
+ }
/* Don't free reservation if it's not ours. */
if (TracksOverlap(GetReservedTrackbits(tile) | TrackToTrackBits(TrackdirToTrack(td)))) return;