From 41fb98db09472cfa2d93e63d9a0f619a84c7f178 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 12 Dec 2022 22:03:07 +0000 Subject: [PATCH] Add NewGRF global flag to allow rocky tiles in tropic desert zones --- docs/newgrf-additions-nml.html | 5 +++++ docs/newgrf-additions.html | 5 +++++ src/clear_cmd.cpp | 6 +++++- src/gfxinit.cpp | 3 +++ src/newgrf.cpp | 8 ++++++++ src/newgrf_extension.cpp | 2 ++ src/newgrf_extension.h | 1 + 7 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/newgrf-additions-nml.html b/docs/newgrf-additions-nml.html index 37c7873428..7ce7997d96 100644 --- a/docs/newgrf-additions-nml.html +++ b/docs/newgrf-additions-nml.html @@ -323,6 +323,11 @@ item (FEAT_GLOBALVARS) { Some station names are always used first even when this is non-zero. + allow_rocks_in_desert0 or 1 + + Sets whether rocky tiles are allowed to generate in and remain in desert zones (tropical climate). + +

Syntax example:

diff --git a/docs/newgrf-additions.html b/docs/newgrf-additions.html
index 702a52838e..845476e130 100644
--- a/docs/newgrf-additions.html
+++ b/docs/newgrf-additions.html
@@ -361,6 +361,11 @@
 	The Action 0 ID field is ignored. The property length is 1 byte.
 	

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

+

Allow rocky tiles in desert zones (tropical climate) (mappable property: global_allow_rocks_in_desert)

+

This sets whether rocky tiles are allowed to generate in and remain in desert zones (tropical climate).
+ The Action 0 ID field is ignored. The property length is 1 byte. 0 is disabled (default). 1 is enabled. +

+

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


Action 0 - Signals (Feature 0E)

Note that Action 0 feature 0E is not supported (does nothing) in standard OpenTTD.

diff --git a/src/clear_cmd.cpp b/src/clear_cmd.cpp index 5fd17aaaec..7286e03667 100644 --- a/src/clear_cmd.cpp +++ b/src/clear_cmd.cpp @@ -24,6 +24,8 @@ #include "safeguards.h" +bool _allow_rocks_desert = false; + static CommandCost ClearTile_Clear(TileIndex tile, DoCommandFlag flags) { static const Price clear_price_table[] = { @@ -298,6 +300,8 @@ static void TileLoopClearDesert(TileIndex tile) if (current == expected) return; + if (_allow_rocks_desert && IsClearGround(tile, CLEAR_ROCKS)) return; + if (expected == 0) { SetClearGroundDensity(tile, CLEAR_GRASS, 3); } else { @@ -404,7 +408,7 @@ void GenerateClearTile() do { if (--j == 0) goto get_out; tile_new = tile + TileOffsByDiagDir((DiagDirection)GB(Random(), 0, 2)); - } while (!IsTileType(tile_new, MP_CLEAR) || IsClearGround(tile_new, CLEAR_DESERT)); + } while (!IsTileType(tile_new, MP_CLEAR) || (!_allow_rocks_desert && IsClearGround(tile_new, CLEAR_DESERT))); tile = tile_new; } get_out:; diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index ff1648296a..9db287279e 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -167,6 +167,9 @@ void InitGRFGlobalVars() extern uint8 _extra_station_names_probability; _extra_station_names_probability = 0; + + extern bool _allow_rocks_desert; + _allow_rocks_desert = false; } /** Actually load the sprite tables. */ diff --git a/src/newgrf.cpp b/src/newgrf.cpp index bf678a8560..f9b0a57a6a 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -2850,6 +2850,13 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, co break; } + case A0RPI_GLOBALVAR_ALLOW_ROCKS_DESERT: { + if (MappedPropertyLengthMismatch(buf, 1, mapping_entry)) break; + extern bool _allow_rocks_desert; + _allow_rocks_desert = (buf->ReadByte() != 0); + break; + } + default: ret = HandleAction0PropertyDefault(buf, prop); break; @@ -2922,6 +2929,7 @@ static ChangeInfoResult GlobalVarReserveInfo(uint gvid, int numinfo, int prop, c case A0RPI_GLOBALVAR_EXTRA_STATION_NAMES_PROBABILITY: case A0RPI_GLOBALVAR_LIGHTHOUSE_GENERATE_AMOUNT: case A0RPI_GLOBALVAR_TRANSMITTER_GENERATE_AMOUNT: + case A0RPI_GLOBALVAR_ALLOW_ROCKS_DESERT: buf->Skip(buf->ReadExtendedByte()); break; diff --git a/src/newgrf_extension.cpp b/src/newgrf_extension.cpp index 65eceebc6f..347c668690 100644 --- a/src/newgrf_extension.cpp +++ b/src/newgrf_extension.cpp @@ -42,6 +42,7 @@ extern const GRFFeatureInfo _grf_feature_list[] = { GRFFeatureInfo("varaction2_railtype_signal_context", 1), GRFFeatureInfo("action0_global_extra_station_names", 2), GRFFeatureInfo("action0_global_default_object_generate_amount", 1), + GRFFeatureInfo("action0_global_allow_rocks_in_desert", 1), GRFFeatureInfo("action0_signals_programmable_signals", 1), GRFFeatureInfo("action0_signals_no_entry_signals", 1), GRFFeatureInfo("action0_signals_restricted_signals", 2), @@ -86,6 +87,7 @@ extern const GRFPropertyMapDefinition _grf_action0_remappable_properties[] = { 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_GLOBALVAR, A0RPI_GLOBALVAR_ALLOW_ROCKS_DESERT, "global_allow_rocks_in_desert"), GRFPropertyMapDefinition(GSF_SIGNALS, A0RPI_SIGNALS_ENABLE_PROGRAMMABLE_SIGNALS, "signals_enable_programmable_signals"), GRFPropertyMapDefinition(GSF_SIGNALS, A0RPI_SIGNALS_ENABLE_NO_ENTRY_SIGNALS, "signals_enable_no_entry_signals"), GRFPropertyMapDefinition(GSF_SIGNALS, A0RPI_SIGNALS_ENABLE_RESTRICTED_SIGNALS, "signals_enable_restricted_signals"), diff --git a/src/newgrf_extension.h b/src/newgrf_extension.h index 705555d061..400a46512b 100644 --- a/src/newgrf_extension.h +++ b/src/newgrf_extension.h @@ -30,6 +30,7 @@ enum Action0RemapPropertyIds { A0RPI_GLOBALVAR_EXTRA_STATION_NAMES_PROBABILITY, A0RPI_GLOBALVAR_LIGHTHOUSE_GENERATE_AMOUNT, A0RPI_GLOBALVAR_TRANSMITTER_GENERATE_AMOUNT, + A0RPI_GLOBALVAR_ALLOW_ROCKS_DESERT, A0RPI_SIGNALS_ENABLE_PROGRAMMABLE_SIGNALS, A0RPI_SIGNALS_ENABLE_NO_ENTRY_SIGNALS, A0RPI_SIGNALS_ENABLE_RESTRICTED_SIGNALS,