diff --git a/docs/newgrf-additions-nml.html b/docs/newgrf-additions-nml.html index 84112b2ecc..2f0bbb0088 100644 --- a/docs/newgrf-additions-nml.html +++ b/docs/newgrf-additions-nml.html @@ -271,6 +271,12 @@ item (FEAT_GLOBALVARS) { + extra_station_names_probability0 .. 255 + + Sets the probability that an extra station name is used even when the available default names have not been exhausted.
+ Some station names are always used first even when this is non-zero. + +

Syntax example:

diff --git a/docs/newgrf-additions.html b/docs/newgrf-additions.html
index 346b2e0676..40a8ea78dd 100644
--- a/docs/newgrf-additions.html
+++ b/docs/newgrf-additions.html
@@ -315,6 +315,14 @@
 	
 	

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

+

Extra station names probability (mappable property: global_extra_station_names_probability)

+

This sets the probability of using an extra station name even when the available default names have not been exhausted.
+ The range is 0 - 255, where 0 is never (the default) and 255 is always.
+ Some station names are always used first even when this is non-zero.
+ The Action 0 ID field is ignored.
+ The property length is 1 bytes. +

+

This is indicated by the feature name: action0_global_extra_station_names, version 2

Lighthouse object map generation amount (mappable property: global_lighthouse_generate_amount)

This sets the map generation amount value for the lighthouse default object (0 is no generation, 255 is maximum).
The Action 0 ID field is ignored. The property length is 1 byte. diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index cae3092da7..11b3d47288 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -231,6 +231,9 @@ static void LoadSpriteTables() extern uint _extra_station_names_used; _extra_station_names_used = 0; + extern uint8 _extra_station_names_probability; + _extra_station_names_probability = 0; + /* * Load the base and extra NewGRF with OTTD required graphics as first NewGRF. * However, we do not want it to show up in the list of used NewGRFs, diff --git a/src/misc.cpp b/src/misc.cpp index 69559daa45..a76cb2c469 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -97,6 +97,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin _game_load_tick_skip_counter = 0; _game_load_time = 0; _extra_station_names_used = 0; + _extra_station_names_probability = 0; _extra_aspects = 0; _loadgame_DBGL_data.clear(); if (reset_settings) MakeNewgameSettingsLive(); diff --git a/src/newgrf.cpp b/src/newgrf.cpp index e91421c20f..891bbbbbd1 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -2919,6 +2919,12 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, co break; } + case A0RPI_GLOBALVAR_EXTRA_STATION_NAMES_PROBABILITY: { + if (MappedPropertyLengthMismatch(buf, 1, mapping_entry)) break; + _extra_station_names_probability = buf->ReadByte(); + break; + } + case A0RPI_GLOBALVAR_LIGHTHOUSE_GENERATE_AMOUNT: case A0RPI_GLOBALVAR_TRANSMITTER_GENERATE_AMOUNT: { if (MappedPropertyLengthMismatch(buf, 1, mapping_entry)) break; @@ -2997,6 +3003,7 @@ static ChangeInfoResult GlobalVarReserveInfo(uint gvid, int numinfo, int prop, c break; case A0RPI_GLOBALVAR_EXTRA_STATION_NAMES: + case A0RPI_GLOBALVAR_EXTRA_STATION_NAMES_PROBABILITY: case A0RPI_GLOBALVAR_LIGHTHOUSE_GENERATE_AMOUNT: case A0RPI_GLOBALVAR_TRANSMITTER_GENERATE_AMOUNT: buf->Skip(buf->ReadExtendedByte()); diff --git a/src/newgrf_extension.cpp b/src/newgrf_extension.cpp index 43ba27d9ee..c301506def 100644 --- a/src/newgrf_extension.cpp +++ b/src/newgrf_extension.cpp @@ -39,7 +39,7 @@ extern const GRFFeatureInfo _grf_feature_list[] = { GRFFeatureInfo("action0_railtype_recolour", 1), GRFFeatureInfo("action0_railtype_extra_aspects", 1), GRFFeatureInfo("action0_roadtype_extra_flags", 1), - GRFFeatureInfo("action0_global_extra_station_names", 1), + GRFFeatureInfo("action0_global_extra_station_names", 2), GRFFeatureInfo("action0_global_default_object_generate_amount", 1), GRFFeatureInfo("action0_signals_programmable_signals", 1), GRFFeatureInfo("action0_signals_no_entry_signals", 1), @@ -78,6 +78,7 @@ extern const GRFPropertyMapDefinition _grf_action0_remappable_properties[] = { GRFPropertyMapDefinition(GSF_ROADTYPES, A0RPI_ROADTYPE_EXTRA_FLAGS, "roadtype_extra_flags"), GRFPropertyMapDefinition(GSF_TRAMTYPES, A0RPI_ROADTYPE_EXTRA_FLAGS, "roadtype_extra_flags"), GRFPropertyMapDefinition(GSF_GLOBALVAR, A0RPI_GLOBALVAR_EXTRA_STATION_NAMES, "global_extra_station_names"), + GRFPropertyMapDefinition(GSF_GLOBALVAR, A0RPI_GLOBALVAR_EXTRA_STATION_NAMES_PROBABILITY, "global_extra_station_names_probability"), GRFPropertyMapDefinition(GSF_GLOBALVAR, A0RPI_GLOBALVAR_LIGHTHOUSE_GENERATE_AMOUNT, "global_lighthouse_generate_amount"), GRFPropertyMapDefinition(GSF_GLOBALVAR, A0RPI_GLOBALVAR_TRANSMITTER_GENERATE_AMOUNT, "global_transmitter_generate_amount"), GRFPropertyMapDefinition(GSF_SIGNALS, A0RPI_SIGNALS_ENABLE_PROGRAMMABLE_SIGNALS, "signals_enable_programmable_signals"), diff --git a/src/newgrf_extension.h b/src/newgrf_extension.h index 630da1aed8..d8c82d1c5a 100644 --- a/src/newgrf_extension.h +++ b/src/newgrf_extension.h @@ -27,6 +27,7 @@ enum Action0RemapPropertyIds { A0RPI_RAILTYPE_EXTRA_ASPECTS, A0RPI_ROADTYPE_EXTRA_FLAGS, A0RPI_GLOBALVAR_EXTRA_STATION_NAMES, + A0RPI_GLOBALVAR_EXTRA_STATION_NAMES_PROBABILITY, A0RPI_GLOBALVAR_LIGHTHOUSE_GENERATE_AMOUNT, A0RPI_GLOBALVAR_TRANSMITTER_GENERATE_AMOUNT, A0RPI_SIGNALS_ENABLE_PROGRAMMABLE_SIGNALS, diff --git a/src/openttd.cpp b/src/openttd.cpp index 5d47752131..04730ccd9e 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -471,6 +471,7 @@ static void ShutdownGame() _game_load_tick_skip_counter = 0; _game_load_time = 0; _extra_station_names_used = 0; + _extra_station_names_probability = 0; _extra_aspects = 0; _loadgame_DBGL_data.clear(); _loadgame_DBGC_data.clear(); diff --git a/src/station.cpp b/src/station.cpp index 01d6c3ad4b..8c9d5c3054 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -40,6 +40,7 @@ INSTANTIATE_POOL_METHODS(Station) std::array _extra_station_names; uint _extra_station_names_used; +uint8 _extra_station_names_probability; StationKdtree _station_kdtree(Kdtree_StationXYFunc); diff --git a/src/station_base.h b/src/station_base.h index f82af82b66..b1c5412713 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -50,6 +50,7 @@ struct ExtraStationNameInfo { extern std::array _extra_station_names; extern uint _extra_station_names_used; +extern uint8 _extra_station_names_probability; class FlowStatMap; diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 45c06959c9..622c04edae 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -317,6 +317,42 @@ static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming n return STR_SV_STNAME_CENTRAL; } + bool use_extra_names = _extra_station_names_used > 0; + auto check_extra_names = [&]() -> bool { + if (use_extra_names) { + use_extra_names = false; + const bool near_water = CountMapSquareAround(tile, CMSAWater) >= 5; + std::vector candidates; + for (uint i = 0; i < _extra_station_names_used; i++) { + const ExtraStationNameInfo &info = _extra_station_names[i]; + if (extra_names[i]) continue; + if (!HasBit(info.flags, name_class)) continue; + if (HasBit(info.flags, ESNIF_CENTRAL) && !is_central) continue; + if (HasBit(info.flags, ESNIF_NOT_CENTRAL) && is_central) continue; + if (HasBit(info.flags, ESNIF_NEAR_WATER) && !near_water) continue; + if (HasBit(info.flags, ESNIF_NOT_NEAR_WATER) && near_water) continue; + candidates.push_back(i); + } + + if (!candidates.empty()) { + SavedRandomSeeds saved_seeds; + SaveRandomSeeds(&saved_seeds); + st->extra_name_index = candidates[RandomRange((uint)candidates.size())]; + RestoreRandomSeeds(saved_seeds); + return true; + } + } + return false; + }; + + if (_extra_station_names_probability > 0) { + SavedRandomSeeds saved_seeds; + SaveRandomSeeds(&saved_seeds); + bool extra_name = (RandomRange(0xFF) < _extra_station_names_probability) && check_extra_names(); + RestoreRandomSeeds(saved_seeds); + if (extra_name) return STR_SV_STNAME_FALLBACK; + } + /* Check lakeside */ if (HasBit(free_names, M(STR_SV_STNAME_LAKESIDE)) && DistanceFromEdge(tile) < 20 && @@ -356,28 +392,7 @@ static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming n tmp = free_names & ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 6) | (1 << 7) | (1 << 12) | (1 << 26) | (1 << 27) | (1 << 28) | (1 << 29) | (1 << 30)); if (tmp != 0) return STR_SV_STNAME + FindFirstBit(tmp); - if (_extra_station_names_used > 0) { - const bool near_water = CountMapSquareAround(tile, CMSAWater) >= 5; - std::vector candidates; - for (uint i = 0; i < _extra_station_names_used; i++) { - const ExtraStationNameInfo &info = _extra_station_names[i]; - if (extra_names[i]) continue; - if (!HasBit(info.flags, name_class)) continue; - if (HasBit(info.flags, ESNIF_CENTRAL) && !is_central) continue; - if (HasBit(info.flags, ESNIF_NOT_CENTRAL) && is_central) continue; - if (HasBit(info.flags, ESNIF_NEAR_WATER) && !near_water) continue; - if (HasBit(info.flags, ESNIF_NOT_NEAR_WATER) && near_water) continue; - candidates.push_back(i); - } - - if (!candidates.empty()) { - SavedRandomSeeds saved_seeds; - SaveRandomSeeds(&saved_seeds); - st->extra_name_index = candidates[RandomRange((uint)candidates.size())]; - RestoreRandomSeeds(saved_seeds); - return STR_SV_STNAME_FALLBACK; - } - } + if (check_extra_names()) return STR_SV_STNAME_FALLBACK; return STR_SV_STNAME_FALLBACK; }