Add signal style flag to limit lookahead extra aspect

pull/400/head
Jonathan G Rennison 2 years ago
parent 22caac6529
commit 175c5d4d50

@ -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).
</td>
</tr>
<tr><td>style_lookahead_extra_aspects</td><td>0 - 6</td>
<td>
Set the look-ahead extra aspects for the most recently defined style (defined using the define_style property).<br />
This property only makes a difference when the "limit train lookahead to signal aspect" game setting is enabled.<br />
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 <span class="code">extra_callback_info2</span>.<br />
Example values could include: 1 for traditional banner repeater signals, or 0 for shunt signals.<br />
The value is clamped to be less than or equal to the value set in the <span class="code">extra_aspects</span> property.
</td>
</tr>
<tr><td>no_default_style</td><td>0 or 1</td>
<td>
When enabled, custom signal graphics from this GRF are only used for custom signal styles, not the default style

@ -445,6 +445,15 @@
The Action 0 Id field is not used, the value is ignored.
</p>
<p>This is indicated by the feature name: <font face="monospace">action0_signals_style</font>, version 1</p>
<h4 id="signals_style_lookahead_extra_aspects">Set custom signal style train look-ahead extra aspects (mappable property: signals_style_lookahead_extra_aspects)</h4>
<p>This applies to the most recent custom signal style defined using the <a href="#signals_define_style">signals_define_style</a> property.<br />
This property only makes a difference when the "limit train lookahead to signal aspect" game setting is enabled.<br />
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.<br />
Example values could include: 1 for traditional banner repeater signals, or 0 for shunt signals.</p>
<p>The property length is 1 byte. The value is clamped to be less than or equal to the value set in the <a href="#signals_extra_aspects">signals_extra_aspects</a> property.<br />
The Action 0 Id field is not used, the value is ignored.
</p>
<p>This is indicated by the feature name: <font face="monospace">action0_signals_style</font>, version 1</p>
<h4 id="signals_no_default_style">Set whether custom signal sprites should not be used for the default signal style (mappable property: signals_no_default_style)</h4>
<p>This applies to <a href="#a3signals_custom_signal_sprites">Action 2/3 Signals (Feature 0E) custom signal sprites</a> for this GRF.<br />
When enabled, this GRF is not used for the default signal style, it is only used for custom signal styles defined with <a href="#signals_define_style">signals_define_style</a>.</p>

@ -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<byte>(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;

@ -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"),

@ -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,

@ -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];
};

@ -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)) {

@ -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<uint8>(_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;
}
}

@ -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");

Loading…
Cancel
Save