From 175c5d4d501eb3e7a876d16c4a5f71e6de10a819 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 19 Jun 2022 12:46:56 +0100 Subject: [PATCH] Add signal style flag to limit lookahead extra aspect --- docs/newgrf-additions-nml.html | 9 +++++++++ docs/newgrf-additions.html | 9 +++++++++ src/newgrf.cpp | 10 ++++++++++ src/newgrf_extension.cpp | 1 + src/newgrf_extension.h | 1 + src/newgrf_newsignals.h | 2 ++ src/pbs.cpp | 24 ++++++++++++++++-------- src/signal.cpp | 8 ++++++++ src/table/newgrf_debug_data.h | 2 +- 9 files changed, 57 insertions(+), 9 deletions(-) diff --git a/docs/newgrf-additions-nml.html b/docs/newgrf-additions-nml.html index a4a220b5b8..e658cc1a77 100644 --- a/docs/newgrf-additions-nml.html +++ b/docs/newgrf-additions-nml.html @@ -471,6 +471,15 @@ item (FEAT_GLOBALVARS) { Set whether reserve through is unconditionally enabled for the most recently defined style (defined using the define_style property). + style_lookahead_extra_aspects0 - 6 + + Set the look-ahead extra aspects for the most recently defined style (defined using the define_style property).
+ This property only makes a difference when the "limit train lookahead to signal aspect" game setting is enabled.
+ This limits the signal aspect which the hypothetical train driver can "read" from the signal without affecting signal aspect propagation to other signals, or variable extra_callback_info2.
+ Example values could include: 1 for traditional banner repeater signals, or 0 for shunt signals.
+ The value is clamped to be less than or equal to the value set in the extra_aspects property. + + no_default_style0 or 1 When enabled, custom signal graphics from this GRF are only used for custom signal styles, not the default style diff --git a/docs/newgrf-additions.html b/docs/newgrf-additions.html index d384b7bd3b..52c2178171 100644 --- a/docs/newgrf-additions.html +++ b/docs/newgrf-additions.html @@ -445,6 +445,15 @@ The Action 0 Id field is not used, the value is ignored.

This is indicated by the feature name: action0_signals_style, version 1

+

Set custom signal style train look-ahead extra aspects (mappable property: signals_style_lookahead_extra_aspects)

+

This applies to the most recent custom signal style defined using the signals_define_style property.
+ This property only makes a difference when the "limit train lookahead to signal aspect" game setting is enabled.
+ This limits the signal aspect which the hypothetical train driver can "read" from the signal without affecting signal aspect propagation to other signals, or variable 0x18.
+ Example values could include: 1 for traditional banner repeater signals, or 0 for shunt signals.

+

The property length is 1 byte. The value is clamped to be less than or equal to the value set in the signals_extra_aspects property.
+ The Action 0 Id field is not used, the value is ignored. +

+

This is indicated by the feature name: action0_signals_style, version 1

Set whether custom signal sprites should not be used for the default signal style (mappable property: signals_no_default_style)

This applies to Action 2/3 Signals (Feature 0E) custom signal sprites for this GRF.
When enabled, this GRF is not used for the default signal style, it is only used for custom signal styles defined with signals_define_style.

diff --git a/src/newgrf.cpp b/src/newgrf.cpp index bfb0295efe..245a0a3133 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -4243,6 +4243,16 @@ static ChangeInfoResult SignalsChangeInfo(uint id, int numinfo, int prop, const break; } + case A0RPI_SIGNALS_STYLE_LOOKAHEAD_EXTRA_ASPECTS: { + if (MappedPropertyLengthMismatch(buf, 1, mapping_entry)) break; + uint8 value = std::min(buf->ReadByte(), NEW_SIGNALS_MAX_EXTRA_ASPECT); + if (_cur.grffile->current_new_signal_style != nullptr) { + SetBit(_cur.grffile->current_new_signal_style->style_flags, NSSF_LOOKAHEAD_ASPECTS_SET); + _cur.grffile->current_new_signal_style->lookahead_extra_aspects = value; + } + break; + } + default: ret = HandleAction0PropertyDefault(buf, prop); break; diff --git a/src/newgrf_extension.cpp b/src/newgrf_extension.cpp index f0b456c919..7510543658 100644 --- a/src/newgrf_extension.cpp +++ b/src/newgrf_extension.cpp @@ -96,6 +96,7 @@ extern const GRFPropertyMapDefinition _grf_action0_remappable_properties[] = { GRFPropertyMapDefinition(GSF_SIGNALS, A0RPI_SIGNALS_STYLE_NAME, "signals_style_name"), GRFPropertyMapDefinition(GSF_SIGNALS, A0RPI_SIGNALS_STYLE_NO_ASPECT_INCREASE, "signals_style_no_aspect_increase"), GRFPropertyMapDefinition(GSF_SIGNALS, A0RPI_SIGNALS_STYLE_ALWAYS_RESERVE_THROUGH, "signals_style_always_reserve_through"), + GRFPropertyMapDefinition(GSF_SIGNALS, A0RPI_SIGNALS_STYLE_LOOKAHEAD_EXTRA_ASPECTS, "signals_style_lookahead_extra_aspects"), GRFPropertyMapDefinition(GSF_OBJECTS, A0RPI_OBJECT_USE_LAND_GROUND, "object_use_land_ground"), GRFPropertyMapDefinition(GSF_OBJECTS, A0RPI_OBJECT_EDGE_FOUNDATION_MODE, "object_edge_foundation_mode"), GRFPropertyMapDefinition(GSF_OBJECTS, A0RPI_OBJECT_FLOOD_RESISTANT, "object_flood_resistant"), diff --git a/src/newgrf_extension.h b/src/newgrf_extension.h index 5c79392d53..64910f179b 100644 --- a/src/newgrf_extension.h +++ b/src/newgrf_extension.h @@ -40,6 +40,7 @@ enum Action0RemapPropertyIds { A0RPI_SIGNALS_STYLE_NAME, A0RPI_SIGNALS_STYLE_NO_ASPECT_INCREASE, A0RPI_SIGNALS_STYLE_ALWAYS_RESERVE_THROUGH, + A0RPI_SIGNALS_STYLE_LOOKAHEAD_EXTRA_ASPECTS, A0RPI_OBJECT_USE_LAND_GROUND, A0RPI_OBJECT_EDGE_FOUNDATION_MODE, A0RPI_OBJECT_FLOOD_RESISTANT, diff --git a/src/newgrf_newsignals.h b/src/newgrf_newsignals.h index 992624c094..dd59678f20 100644 --- a/src/newgrf_newsignals.h +++ b/src/newgrf_newsignals.h @@ -27,6 +27,7 @@ enum { enum NewSignalStyleFlags { NSSF_NO_ASPECT_INC = 0, NSSF_ALWAYS_RESERVE_THROUGH = 1, + NSSF_LOOKAHEAD_ASPECTS_SET = 2, }; struct NewSignalStyle { @@ -34,6 +35,7 @@ struct NewSignalStyle { StringID name; uint8 grf_local_id; uint8 style_flags; + uint8 lookahead_extra_aspects; PalSpriteID signals[SIGTYPE_END][2][2]; }; diff --git a/src/pbs.cpp b/src/pbs.cpp index 0441fe1f61..e26dd1fbf7 100644 --- a/src/pbs.cpp +++ b/src/pbs.cpp @@ -13,6 +13,7 @@ #include "newgrf_station.h" #include "pathfinder/follow_track.hpp" #include "tracerestrict.h" +#include "newgrf_newsignals.h" #include "safeguards.h" @@ -584,8 +585,10 @@ static PBSTileInfo FollowReservation(Owner o, RailTypes rts, TileIndex tile, Tra if (signal_speed == 0 || (speed_restriction != 0 && speed_restriction < signal_speed)) signal_speed = speed_restriction; if (signal_speed == 0 || (bridge_speed != 0 && bridge_speed < signal_speed)) signal_speed = bridge_speed; + const uint16 signal_flags = GetTunnelBridgeSignalStyle(tile) << 8; + /* Entrance signal */ - lookahead->AddSignal(signal_speed, 0, z, 0); + lookahead->AddSignal(signal_speed, 0, z, signal_flags); update_z(tile, trackdir, false); @@ -599,7 +602,7 @@ static PBSTileInfo FollowReservation(Owner o, RailTypes rts, TileIndex tile, Tra int offset = start_offset - TILE_SIZE; for (int i = 0; i < signals; i++) { offset += TILE_SIZE * spacing; - lookahead->AddSignal(signal_speed, offset, chunnel ? LookaheadTileHeightForChunnel(length, i * spacing) : z, 0); + lookahead->AddSignal(signal_speed, offset, chunnel ? LookaheadTileHeightForChunnel(length, i * spacing) : z, signal_flags); } /* Exit signal */ @@ -613,7 +616,7 @@ static PBSTileInfo FollowReservation(Owner o, RailTypes rts, TileIndex tile, Tra if (signal_speed == 0 || (bridge_speed != 0 && bridge_speed < signal_speed)) signal_speed = bridge_speed; } - lookahead->AddSignal(signal_speed, end_offset, z, 0); + lookahead->AddSignal(signal_speed, end_offset, z, signal_flags); lookahead->SetNextExtendPositionIfUnset(); } else { @@ -656,8 +659,9 @@ static PBSTileInfo FollowReservation(Owner o, RailTypes rts, TileIndex tile, Tra /* Passing through a signal from the front side */ uint16 signal_speed = GetRailTypeInfo(rt)->max_speed; if (signal_speed == 0 || (speed_restriction != 0 && speed_restriction < signal_speed)) signal_speed = speed_restriction; - uint16 signal_flags = 0; - if (_non_aspect_inc_style_mask != 0 && HasBit(_non_aspect_inc_style_mask, GetSignalStyle(tile, TrackdirToTrack(trackdir)))) { + uint8 signal_style = GetSignalStyle(tile, TrackdirToTrack(trackdir)); + uint16 signal_flags = signal_style << 8; + if (HasBit(_non_aspect_inc_style_mask, signal_style)) { SetBit(signal_flags, TRSLAI_NO_ASPECT_INC); } lookahead->AddSignal(signal_speed, 0, z, signal_flags); @@ -953,11 +957,13 @@ void TryCreateLookAheadForTrainInTunnelBridge(Train *t) int z = IsBridge(t->tile) ? GetBridgeHeight(t->tile) : GetTilePixelZ(t->tile); + const uint16 signal_flags = GetTunnelBridgeSignalStyle(t->tile) << 8; + /* Middle signals */ int offset = -(int)TILE_SIZE; for (int i = 0; i < signals; i++) { offset += TILE_SIZE * spacing; - t->lookahead->AddSignal(signal_speed, offset, HasBit(t->lookahead->flags, TRLF_CHUNNEL) ? LookaheadTileHeightForChunnel(length, i * spacing) : z, 0); + t->lookahead->AddSignal(signal_speed, offset, HasBit(t->lookahead->flags, TRLF_CHUNNEL) ? LookaheadTileHeightForChunnel(length, i * spacing) : z, signal_flags); } /* Exit signal */ @@ -970,7 +976,7 @@ void TryCreateLookAheadForTrainInTunnelBridge(Train *t) if (signal_speed == 0 || (bridge_speed != 0 && bridge_speed < signal_speed)) signal_speed = bridge_speed; } - t->lookahead->AddSignal(signal_speed, end_offset, z, 0); + t->lookahead->AddSignal(signal_speed, end_offset, z, signal_flags); t->lookahead->SetNextExtendPositionIfUnset(); } @@ -996,7 +1002,9 @@ void SetTrainReservationLookaheadEnd(Train *v) if (item.type == TRLIT_SIGNAL) { if (item.start <= threshold) { /* Signal is within visual range */ - uint8 max_aspect = _extra_aspects + (HasBit(item.data_aux, TRSLAI_NO_ASPECT_INC) ? 1 : 2); + uint8 style = item.data_aux >> 8; + uint8 max_aspect = (style == 0) ? _extra_aspects : _new_signal_styles[style - 1].lookahead_extra_aspects; + max_aspect += (HasBit(item.data_aux, TRSLAI_NO_ASPECT_INC) ? 1 : 2); if (max_aspect > known_signals_ahead) known_signals_ahead = max_aspect; } if (!HasBit(item.data_aux, TRSLAI_NO_ASPECT_INC)) { diff --git a/src/signal.cpp b/src/signal.cpp index 1a38add2e9..11affb0b01 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -1531,6 +1531,14 @@ static bool DetermineExtraAspectsVariable() SetBit(_always_reserve_through_style_mask, i + 1); SetBit(_no_tunnel_bridge_style_mask, i + 1); } + if (HasBit(_new_signal_styles[i].style_flags, NSSF_LOOKAHEAD_ASPECTS_SET)) { + _new_signal_styles[i].lookahead_extra_aspects = std::min(_new_signal_styles[i].lookahead_extra_aspects, _new_signal_styles[i].grffile->new_signal_extra_aspects); + } else { + _new_signal_styles[i].lookahead_extra_aspects = _new_signal_styles[i].grffile->new_signal_extra_aspects; + } + } + for (uint i = _num_new_signal_styles; i < MAX_NEW_SIGNAL_STYLES; i++) { + _new_signal_styles[i].lookahead_extra_aspects = new_extra_aspects; } } diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index 7b21cb3d07..5254f5b558 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -276,7 +276,7 @@ class NIHVehicle : public NIHelper { if (item.data_id > 0) print_braking_speed(item.start, item.data_id, item.z_pos); break; case TRLIT_SIGNAL: - b += seprintf(b, lastof(buffer), "signal: target speed: %u, flags:", item.data_id); + b += seprintf(b, lastof(buffer), "signal: target speed: %u, style: %u, flags:", item.data_id, item.data_aux >> 8); if (HasBit(item.data_aux, TRSLAI_NO_ASPECT_INC)) b += seprintf(b, lastof(buffer), "n"); if (_settings_game.vehicle.realistic_braking_aspect_limited == TRBALM_ON && l.lookahead_end_position == item.start) { b += seprintf(b, lastof(buffer), ", lookahead end");