diff --git a/src/signal.cpp b/src/signal.cpp index 3ac77872f8..2a78ad977f 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -1709,11 +1709,35 @@ static bool RemapNewSignalStyles(const std::array old_mapping = _new_signal_style_mapping; _new_signal_style_mapping = new_mapping; - uint8 remap_table[MAX_NEW_SIGNAL_STYLES + 1] = {}; + uint8 remap_table[MAX_NEW_SIGNAL_STYLES + 1] = {}; remap_table[0] = 0; uint8 next_free = _num_new_signal_styles; + std::array usage_table; + const bool assume_all_styles_in_use = _networking && !_network_server; + usage_table.fill(assume_all_styles_in_use); + bool usage_table_populated = !assume_all_styles_in_use; + + auto populate_usage_table = [&]() { + usage_table_populated = true; + + const TileIndex map_size = MapSize(); + for (TileIndex t = 0; t < map_size; t++) { + if (IsTileType(t, MP_RAILWAY) && HasSignals(t)) { + for (Track track : { TRACK_LOWER, TRACK_UPPER }) { + uint8 old_style = GetSignalStyle(t, track); + if (old_style > 0) usage_table[old_style - 1] = true; + } + } + if (IsRailTunnelBridgeTile(t) && GetTunnelBridgeDirection(t) < DIAGDIR_SW) { + /* Only process west end of tunnel/bridge */ + uint8 old_style = GetTunnelBridgeSignalStyle(t); + if (old_style > 0) usage_table[old_style - 1] = true; + } + } + }; + bool do_remap = false; for (uint i = 0; i < MAX_NEW_SIGNAL_STYLES; i++) { if (old_mapping[i].grfid == 0) { @@ -1725,16 +1749,27 @@ static bool RemapNewSignalStyles(const std::array &mapping)