From d32672a325b1679860c91a9ab942896479689dc1 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 26 Sep 2020 11:21:49 +0100 Subject: [PATCH] GRF: Allow railtype custom signal sprites for programmable pre-signals --- docs/newgrf-additions.html | 8 +++++++ src/newgrf.cpp | 7 +++++++ src/newgrf.h | 1 + src/newgrf_railtype.cpp | 1 + src/rail.h | 10 +++++++++ src/rail_cmd.cpp | 39 +++++++++++++++++------------------ src/table/newgrf_debug_data.h | 3 +++ src/table/railtypes.h | 12 +++++++++++ 8 files changed, 61 insertions(+), 20 deletions(-) diff --git a/docs/newgrf-additions.html b/docs/newgrf-additions.html index 8e3ea8d954..e151784e2b 100644 --- a/docs/newgrf-additions.html +++ b/docs/newgrf-additions.html @@ -205,6 +205,14 @@

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

More bridges (16 instead of 13)

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

+

Action 0 - Railtypes

+

Enable custom signal sprites for programmable pre-signals (mappable property: railtype_enable_programmable_signals)

+

This enables Action 2/3 - Railtype custom signal sprites for programmable pre-signals.
+ Programmable pre-signals have the signal type value: 06.
+ The property length is 1 byte. 0 is disabled (default). 1 is enabled. +

+

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

+

Variational Action 2 - Stations

Track type in purchase list (42)

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

diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 281f23c37e..4b18166d16 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -4349,6 +4349,11 @@ static ChangeInfoResult RailTypeChangeInfo(uint id, int numinfo, int prop, const for (int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord(); break; + case A0RPI_RAILTYPE_ENABLE_PROGRAMMABLE_SIGNALS: + if (MappedPropertyLengthMismatch(buf, 1, mapping_entry)) break; + SB(rti->ctrl_flags, RTCF_PROGSIG, 1, (buf->ReadByte() != 0 ? 1 : 0)); + break; + default: ret = HandleAction0PropertyDefault(buf, prop); break; @@ -8360,6 +8365,7 @@ static const GRFFeatureInfo _grf_feature_list[] = { GRFFeatureInfo("action0_bridge_prop14", 1), GRFFeatureInfo("action0_bridge_pillar_flags", 1), GRFFeatureInfo("action5_programmable_signals", 1), + GRFFeatureInfo("action0_railtype_programmable_signals", 1), GRFFeatureInfo(), }; @@ -8475,6 +8481,7 @@ static const GRFPropertyMapDefinition _grf_action0_remappable_properties[] = { GRFPropertyMapDefinition(GSF_STATIONS, A0RPI_STATION_DISALLOWED_BRIDGE_PILLARS, "station_disallowed_bridge_pillars"), GRFPropertyMapDefinition(GSF_BRIDGES, A0RPI_BRIDGE_MENU_ICON, "bridge_menu_icon"), GRFPropertyMapDefinition(GSF_BRIDGES, A0RPI_BRIDGE_PILLAR_FLAGS, "bridge_pillar_flags"), + GRFPropertyMapDefinition(GSF_RAILTYPES, A0RPI_RAILTYPE_ENABLE_PROGRAMMABLE_SIGNALS, "railtype_enable_programmable_signals"), GRFPropertyMapDefinition(), }; diff --git a/src/newgrf.h b/src/newgrf.h index 5d2533b8c2..a293944186 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -114,6 +114,7 @@ enum Action0RemapPropertyIds { A0RPI_STATION_DISALLOWED_BRIDGE_PILLARS, A0RPI_BRIDGE_MENU_ICON, A0RPI_BRIDGE_PILLAR_FLAGS, + A0RPI_RAILTYPE_ENABLE_PROGRAMMABLE_SIGNALS, }; enum GRFPropertyMapFallbackMode { diff --git a/src/newgrf_railtype.cpp b/src/newgrf_railtype.cpp index 7b1634dca0..9b902c95b4 100644 --- a/src/newgrf_railtype.cpp +++ b/src/newgrf_railtype.cpp @@ -127,6 +127,7 @@ SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSp SpriteID GetCustomSignalSprite(const RailtypeInfo *rti, TileIndex tile, SignalType type, SignalVariant var, SignalState state, bool gui) { if (rti->group[RTSG_SIGNALS] == nullptr) return 0; + if (type == SIGTYPE_PROG && !HasBit(rti->ctrl_flags, RTCF_PROGSIG)) return 0; uint32 param1 = gui ? 0x10 : 0x00; uint32 param2 = (type << 16) | (var << 8) | state; diff --git a/src/rail.h b/src/rail.h index 41dc1c2125..c0a77cba49 100644 --- a/src/rail.h +++ b/src/rail.h @@ -41,6 +41,11 @@ enum RailTypeFlags { }; DECLARE_ENUM_AS_BIT_SET(RailTypeFlags) +/** Railtype control flags. */ +enum RailTypeCtrlFlags { + RTCF_PROGSIG = 0, ///< Custom signal sprites enabled for programmable pre-signals. +}; + struct SpriteGroup; /** Sprite groups for a railtype. */ @@ -208,6 +213,11 @@ public: */ RailTypeFlags flags; + /** + * Bit mask of rail type control flags + */ + byte ctrl_flags; + /** * Cost multiplier for building this rail type */ diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index d9353527c9..71d601d756 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -69,7 +69,7 @@ void ResetRailTypes() {0,0,0,0,0,0,0,0,{}}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0}, - 0, RAILTYPES_NONE, RAILTYPES_NONE, 0, 0, 0, RTFB_NONE, 0, 0, 0, 0, 0, + 0, RAILTYPES_NONE, RAILTYPES_NONE, 0, 0, 0, RTFB_NONE, 0, 0, 0, 0, 0, 0, RailTypeLabelList(), 0, 0, RAILTYPES_NONE, RAILTYPES_NONE, 0, {}, {} }; for (; i < lengthof(_railtypes); i++) _railtypes[i] = empty_railtype; @@ -2489,39 +2489,38 @@ void DrawSingleSignal(TileIndex tile, const RailtypeInfo *rti, Track track, Sign uint x, y; GetSignalXY(tile, pos, x, y); - SpriteID sprite; - bool is_custom_sprite; - if (type == SIGTYPE_PROG) { + SpriteID sprite = GetCustomSignalSprite(rti, tile, type, variant, condition); + bool is_custom_sprite = (sprite != 0); + if (sprite != 0) { + sprite += image; + } else if (type == SIGTYPE_PROG) { if (variant == SIG_SEMAPHORE) { sprite = SPR_PROGSIGNAL_BASE + image * 2 + condition; } else { sprite = SPR_PROGSIGNAL_BASE + 16 + image * 2 + condition; } + extern int _progsig_grf_file_index; is_custom_sprite = (int) GetOriginFileSlot(sprite) != _progsig_grf_file_index; } else { - sprite = GetCustomSignalSprite(rti, tile, type, variant, condition); - is_custom_sprite = (sprite != 0); - if (sprite != 0) { - sprite += image; - } else { - /* Normal electric signals are stored in a different sprite block than all other signals. */ - sprite = (type == SIGTYPE_NORMAL && variant == SIG_ELECTRIC) ? SPR_ORIGINAL_SIGNALS_BASE : SPR_SIGNALS_BASE - 16; - sprite += type * 16 + variant * 64 + image * 2 + condition + (IsSignalSpritePBS(type) ? 64 : 0); - } + /* Normal electric signals are stored in a different sprite block than all other signals. */ + sprite = (type == SIGTYPE_NORMAL && variant == SIG_ELECTRIC) ? SPR_ORIGINAL_SIGNALS_BASE : SPR_SIGNALS_BASE - 16; + sprite += type * 16 + variant * 64 + image * 2 + condition + (IsSignalSpritePBS(type) ? 64 : 0); - if (!is_custom_sprite) { - int origin_slot = GetOriginFileSlot(sprite); - extern int _first_user_grf_file_index; - extern int _opengfx_grf_file_index; - is_custom_sprite = origin_slot != _opengfx_grf_file_index && (origin_slot >= _first_user_grf_file_index); - } + int origin_slot = GetOriginFileSlot(sprite); + extern int _first_user_grf_file_index; + extern int _opengfx_grf_file_index; + is_custom_sprite = origin_slot != _opengfx_grf_file_index && (origin_slot >= _first_user_grf_file_index); } if (is_custom_sprite && show_restricted && _settings_client.gui.show_restricted_signal_default) { /* Use duplicate sprite block, instead of GRF-specified signals */ if (type == SIGTYPE_PROG) { - sprite += SPR_DUP_PROGSIGNAL_BASE - SPR_PROGSIGNAL_BASE; + if (variant == SIG_SEMAPHORE) { + sprite = SPR_DUP_PROGSIGNAL_BASE + image * 2 + condition; + } else { + sprite = SPR_DUP_PROGSIGNAL_BASE + 16 + image * 2 + condition; + } } else { sprite = (type == SIGTYPE_NORMAL && variant == SIG_ELECTRIC) ? SPR_DUP_ORIGINAL_SIGNALS_BASE : SPR_DUP_SIGNALS_BASE - 16; sprite += type * 16 + variant * 64 + image * 2 + condition + (IsSignalSpritePBS(type) ? 64 : 0); diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index 3fd248d540..8efb837c1c 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -629,6 +629,9 @@ class NIHRailType : public NIHelper { HasBit(info->flags, RTF_ALLOW_90DEG) ? 'a' : '-', HasBit(info->flags, RTF_DISALLOW_90DEG) ? 'd' : '-'); print(buffer); + seprintf(buffer, lastof(buffer), " Ctrl flags: %c", + HasBit(info->ctrl_flags, RTCF_PROGSIG) ? 'p' : '-'); + print(buffer); }; print("Debug Info:"); diff --git a/src/table/railtypes.h b/src/table/railtypes.h index 95285de5f0..25a1fdfa16 100644 --- a/src/table/railtypes.h +++ b/src/table/railtypes.h @@ -77,6 +77,9 @@ static const RailtypeInfo _original_railtypes[] = { /* flags */ RTFB_NONE, + /* control flags */ + 0, + /* cost multiplier */ 8, @@ -178,6 +181,9 @@ static const RailtypeInfo _original_railtypes[] = { /* flags */ RTFB_CATENARY, + /* control flags */ + 0, + /* cost multiplier */ 12, @@ -275,6 +281,9 @@ static const RailtypeInfo _original_railtypes[] = { /* flags */ RTFB_NONE, + /* control flags */ + 0, + /* cost multiplier */ 16, @@ -372,6 +381,9 @@ static const RailtypeInfo _original_railtypes[] = { /* flags */ RTFB_NONE, + /* control flags */ + 0, + /* cost multiplier */ 24,