summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-08-02 22:55:52 +0000
committerrubidium <rubidium@openttd.org>2008-08-02 22:55:52 +0000
commite78a235293be7938040ff33d932d44fa265ca83b (patch)
tree3b5fc174db6ad9a3491b06b6ff1cb7899e515ef3 /src
parent0b38276d5a3ffa7af64d7f889f1bd3eae6734657 (diff)
downloadopenttd-e78a235293be7938040ff33d932d44fa265ca83b.tar.xz
(svn r13960) -Codechange [YAPP]: Reserve a path when exiting a depot into a PBS block. (michi_cc)
Diffstat (limited to 'src')
-rw-r--r--src/signal.cpp6
-rw-r--r--src/signal_func.h1
-rw-r--r--src/train_cmd.cpp20
3 files changed, 24 insertions, 3 deletions
diff --git a/src/signal.cpp b/src/signal.cpp
index 857be866f..8d43b5dbd 100644
--- a/src/signal.cpp
+++ b/src/signal.cpp
@@ -541,8 +541,10 @@ static SigSegState UpdateSignalsInBuffer(Owner owner)
if (first) {
first = false;
- if ((flags & SF_TRAIN) || (flags & SF_EXIT && !(flags & SF_GREEN)) || (flags & SF_FULL)) {
- /* SIGSEG_FREE is set by default */
+ /* SIGSEG_FREE is set by default */
+ if (flags & SF_PBS) {
+ state = SIGSEG_PBS;
+ } else if (flags & SF_TRAIN || (flags & SF_EXIT && !(flags & SF_GREEN)) || flags & SF_FULL) {
state = SIGSEG_FULL;
}
}
diff --git a/src/signal_func.h b/src/signal_func.h
index 7dcf3fd81..7e3516811 100644
--- a/src/signal_func.h
+++ b/src/signal_func.h
@@ -45,6 +45,7 @@ static inline byte SignalOnTrack(Track track)
enum SigSegState {
SIGSEG_FREE, ///< Free and has no pre-signal exits or at least one green exit
SIGSEG_FULL, ///< Occupied by a train
+ SIGSEG_PBS, ///< Segment is a PBS segment
};
SigSegState UpdateSignalsOnSegment(TileIndex tile, DiagDirection side, Owner owner);
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 9e736e3cc..3ba1045d5 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -2379,7 +2379,10 @@ static bool CheckTrainStayInDepot(Vehicle *v)
return true;
}
+ SigSegState seg_state;
+
if (v->u.rail.force_proceed == 0) {
+ /* force proceed was not pressed */
if (++v->load_unload_time_rem < 37) {
InvalidateWindowClasses(WC_TRAINS_LIST);
return true;
@@ -2387,12 +2390,27 @@ static bool CheckTrainStayInDepot(Vehicle *v)
v->load_unload_time_rem = 0;
- if (UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner) == SIGSEG_FULL) {
+ seg_state = _settings_game.pf.reserve_paths ? SIGSEG_PBS : UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner);
+ if (seg_state == SIGSEG_FULL || GetDepotWaypointReservation(v->tile)) {
+ /* Full and no PBS signal in block or depot reserved, can't exit. */
InvalidateWindowClasses(WC_TRAINS_LIST);
return true;
}
+ } else {
+ seg_state = _settings_game.pf.reserve_paths ? SIGSEG_PBS : UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner);
+ }
+
+ /* Only leave when we can reserve a path to our destination. */
+ if (seg_state == SIGSEG_PBS && !TryPathReserve(v) && v->u.rail.force_proceed == 0) {
+ /* No path and no force proceed. */
+ InvalidateWindowClasses(WC_TRAINS_LIST);
+ MarkTrainAsStuck(v);
+ return true;
}
+ SetDepotWaypointReservation(v->tile, true);
+ if (_settings_client.gui.show_track_reservation) MarkTileDirtyByTile(v->tile);
+
VehicleServiceInDepot(v);
InvalidateWindowClasses(WC_TRAINS_LIST);
v->PlayLeaveStationSound();