From cf5eef515e5bafec82ba44e49ef87df1ef43e7af Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 15 Jun 2022 17:49:54 +0100 Subject: [PATCH] Signals: Add GRF restriction info bit for may reverse --- docs/newgrf-additions-nml.html | 4 ++++ docs/newgrf-additions.html | 2 ++ src/newgrf_newsignals.cpp | 1 + src/tracerestrict.cpp | 16 ++++++++++++++-- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/newgrf-additions-nml.html b/docs/newgrf-additions-nml.html index f9b3c549be..1c1e858d3a 100644 --- a/docs/newgrf-additions-nml.html +++ b/docs/newgrf-additions-nml.html @@ -116,6 +116,8 @@
The signal is restricted (has a routing restriction program attached)
RESERVE_THROUGH_ALWAYS
The attached routing restriction program unconditionally sets reserve through
+
MAY_REVERSE
+
The attached routing restriction program may allow trains to reverse behind this signal
@@ -428,6 +430,8 @@ item (FEAT_GLOBALVARS) {
The signal is restricted (has a routing restriction program attached)
RESERVE_THROUGH_ALWAYS
The attached routing restriction program unconditionally sets reserve through
+
MAY_REVERSE
+
The attached routing restriction program may allow trains to reverse behind this signal
diff --git a/docs/newgrf-additions.html b/docs/newgrf-additions.html index 52c792fd97..a6ff925f73 100644 --- a/docs/newgrf-additions.html +++ b/docs/newgrf-additions.html @@ -583,6 +583,7 @@ BitValueMeaning 01This signal has a routing restriction program attached 12Reserve through is unconditionally set in the routing restriction program + 24The routing restriction program may allow trains to reverse behind this signal

See also: railtype_enable_restricted_signals property

@@ -605,6 +606,7 @@ BitValueMeaning 01This signal has a routing restriction program attached 12Reserve through is unconditionally set in the routing restriction program + 24The routing restriction program may allow trains to reverse behind this signal

See also: signals_enable_restricted_signals property

diff --git a/src/newgrf_newsignals.cpp b/src/newgrf_newsignals.cpp index 5532bc4c21..1eaa6737b7 100644 --- a/src/newgrf_newsignals.cpp +++ b/src/newgrf_newsignals.cpp @@ -78,5 +78,6 @@ uint GetNewSignalsRestrictedSignalsInfo(const TraceRestrictProgram *prog, TileIn uint result = 1; if ((prog->actions_used_flags & TRPAUF_RESERVE_THROUGH_ALWAYS) && !IsTileType(tile, MP_TUNNELBRIDGE)) result |= 2; + if ((prog->actions_used_flags & TRPAUF_REVERSE) && !IsTileType(tile, MP_TUNNELBRIDGE)) result |= 4; return result; } diff --git a/src/tracerestrict.cpp b/src/tracerestrict.cpp index 6654fe222c..2a0ff8505e 100644 --- a/src/tracerestrict.cpp +++ b/src/tracerestrict.cpp @@ -1057,7 +1057,19 @@ CommandCost TraceRestrictProgram::Validate(const std::vector break; case TRIT_REVERSE: - actions_used_flags |= TRPAUF_REVERSE; + switch (static_cast(GetTraceRestrictValue(item))) { + case TRRVF_REVERSE: + actions_used_flags |= TRPAUF_REVERSE; + break; + + case TRRVF_CANCEL_REVERSE: + if (condstack.empty()) actions_used_flags &= ~TRPAUF_REVERSE; + break; + + default: + NOT_REACHED(); + break; + } break; case TRIT_SPEED_RESTRICTION: @@ -1327,7 +1339,7 @@ void TraceRestrictCheckRefreshSignals(const TraceRestrictProgram *prog, TileInde { if (_network_dedicated) return; - if (!((old_actions_used_flags ^ prog->actions_used_flags) & TRPAUF_RESERVE_THROUGH_ALWAYS)) return; + if (!((old_actions_used_flags ^ prog->actions_used_flags) & (TRPAUF_RESERVE_THROUGH_ALWAYS | TRPAUF_REVERSE))) return; if (old_size == 0 && prog->refcount == 1) return; // Program is new, no need to refresh again