From b4c08447121b7f540eed53ef647a0400d3d7f8c6 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Sun, 22 Dec 2024 17:20:39 +0000 Subject: [PATCH 1/4] Allow proper overlaying of weather_generator --- src/regional_settings.cpp | 5 ++--- src/weather_gen.cpp | 39 +++++++++++++++++++-------------------- src/weather_gen.h | 2 +- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/regional_settings.cpp b/src/regional_settings.cpp index 78875cda2987f..2198ef7a8e5b2 100644 --- a/src/regional_settings.cpp +++ b/src/regional_settings.cpp @@ -592,7 +592,7 @@ void load_region_settings( const JsonObject &jo ) jo.throw_error( "\"weather\": { … } required for default" ); } else { JsonObject wjo = jo.get_object( "weather" ); - new_region.weather = weather_generator::load( wjo ); + new_region.weather.load( wjo, false ); } load_overmap_feature_flag_settings( jo, new_region.overmap_feature_flag, strict, false ); @@ -746,10 +746,9 @@ void apply_region_overlay( const JsonObject &jo, regional_settings ®ion ) load_building_types( "shops", region.city_spec.shops ); load_building_types( "parks", region.city_spec.parks ); - // TODO: Support overwriting only some values if( jo.has_object( "weather" ) ) { JsonObject wjo = jo.get_object( "weather" ); - region.weather = weather_generator::load( wjo ); + region.weather.load( wjo, true ); } load_overmap_feature_flag_settings( jo, region.overmap_feature_flag, false, true ); diff --git a/src/weather_gen.cpp b/src/weather_gen.cpp index b7d922f13bacf..866d353b06df2 100644 --- a/src/weather_gen.cpp +++ b/src/weather_gen.cpp @@ -13,6 +13,7 @@ #include "condition.h" #include "dialogue.h" #include "game_constants.h" +#include "generic_factory.h" #include "json.h" #include "math_defines.h" #include "point.h" @@ -335,27 +336,25 @@ void weather_generator::sort_weather() } ); } -weather_generator weather_generator::load( const JsonObject &jo ) +void weather_generator::load( const JsonObject &jo, const bool was_loaded ) { - weather_generator ret; - ret.base_temperature = jo.get_float( "base_temperature", 0.0 ); - ret.base_humidity = jo.get_float( "base_humidity", 50.0 ); - ret.base_pressure = jo.get_float( "base_pressure", 0.0 ); - ret.base_wind = jo.get_float( "base_wind", 0.0 ); - ret.base_wind_distrib_peaks = jo.get_int( "base_wind_distrib_peaks", 0 ); - ret.base_wind_season_variation = jo.get_int( "base_wind_season_variation", 0 ); - ret.summer_temp_manual_mod = jo.get_int( "summer_temp_manual_mod", 0 ); - ret.spring_temp_manual_mod = jo.get_int( "spring_temp_manual_mod", 0 ); - ret.autumn_temp_manual_mod = jo.get_int( "autumn_temp_manual_mod", 0 ); - ret.winter_temp_manual_mod = jo.get_int( "winter_temp_manual_mod", 0 ); - ret.spring_humidity_manual_mod = jo.get_int( "spring_humidity_manual_mod", 0 ); - ret.summer_humidity_manual_mod = jo.get_int( "summer_humidity_manual_mod", 0 ); - ret.autumn_humidity_manual_mod = jo.get_int( "autumn_humidity_manual_mod", 0 ); - ret.winter_humidity_manual_mod = jo.get_int( "winter_humidity_manual_mod", 0 ); - ret.weather_black_list = jo.get_string_array( "weather_black_list" ); - ret.weather_white_list = jo.get_string_array( "weather_white_list" ); - if( !ret.weather_black_list.empty() && !ret.weather_white_list.empty() ) { + mandatory( jo, was_loaded, "base_temperature", base_temperature ); + mandatory( jo, was_loaded, "base_humidity", base_humidity ); + mandatory( jo, was_loaded, "base_pressure", base_pressure ); + mandatory( jo, was_loaded, "base_wind", base_wind ); + mandatory( jo, was_loaded, "base_wind_distrib_peaks", base_wind_distrib_peaks ); + mandatory( jo, was_loaded, "base_wind_season_variation", base_wind_season_variation ); + optional( jo, was_loaded, "summer_temp_manual_mod", summer_temp_manual_mod, 0 ); + optional( jo, was_loaded, "spring_temp_manual_mod", spring_temp_manual_mod, 0 ); + optional( jo, was_loaded, "autumn_temp_manual_mod", autumn_temp_manual_mod, 0 ); + optional( jo, was_loaded, "winter_temp_manual_mod", winter_temp_manual_mod, 0 ); + optional( jo, was_loaded, "spring_humidity_manual_mod", spring_humidity_manual_mod, 0 ); + optional( jo, was_loaded, "summer_humidity_manual_mod", summer_humidity_manual_mod, 0 ); + optional( jo, was_loaded, "autumn_humidity_manual_mod", autumn_humidity_manual_mod, 0 ); + optional( jo, was_loaded, "winter_humidity_manual_mod", winter_humidity_manual_mod, 0 ); + optional( jo, was_loaded, "weather_black_list", weather_black_list ); + optional( jo, was_loaded, "weather_white_list", weather_white_list ); + if( !weather_black_list.empty() && !weather_white_list.empty() ) { jo.throw_error( "weather_black_list and weather_white_list are mutually exclusive" ); } - return ret; } diff --git a/src/weather_gen.h b/src/weather_gen.h index 3f916bf5273f4..e3de604530534 100644 --- a/src/weather_gen.h +++ b/src/weather_gen.h @@ -73,7 +73,7 @@ class weather_generator void sort_weather(); units::temperature get_weather_temperature( const tripoint &, const time_point &, unsigned ) const; - static weather_generator load( const JsonObject &jo ); + void load( const JsonObject &jo, const bool was_loaded ); }; #endif // CATA_SRC_WEATHER_GEN_H From 4b09fbf53e3884283fff3bb7cb08c7beeb488d7b Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Sun, 22 Dec 2024 18:37:42 +0000 Subject: [PATCH 2/4] Add mandatory fields to TEST_DATA --- data/mods/TEST_DATA/regions.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/data/mods/TEST_DATA/regions.json b/data/mods/TEST_DATA/regions.json index f39571b8c9d63..0bdf88d5042c3 100644 --- a/data/mods/TEST_DATA/regions.json +++ b/data/mods/TEST_DATA/regions.json @@ -143,7 +143,14 @@ "s_lot": 6 } }, - "weather": { "base_temperature": 8.0, "base_humidity": 40.0, "base_pressure": 1015.0 }, + "weather": { + "base_temperature": 8.0, + "base_humidity": 40.0, + "base_pressure": 1015.0, + "base_wind": 0, + "base_wind_distrib_peaks": 0, + "base_wind_season_variation": 0 + }, "overmap_feature_flag_settings": { "clear_blacklist": false, "blacklist": [ ], "clear_whitelist": false, "whitelist": [ ] } }, { From 248852b2b8f381016ee7a578c174c67e74d94499 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Mon, 23 Dec 2024 12:13:09 +0000 Subject: [PATCH 3/4] Appease our clang overlords --- src/weather_gen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/weather_gen.h b/src/weather_gen.h index e3de604530534..f1c2cce83e414 100644 --- a/src/weather_gen.h +++ b/src/weather_gen.h @@ -73,7 +73,7 @@ class weather_generator void sort_weather(); units::temperature get_weather_temperature( const tripoint &, const time_point &, unsigned ) const; - void load( const JsonObject &jo, const bool was_loaded ); + void load( const JsonObject &jo, bool was_loaded ); }; #endif // CATA_SRC_WEATHER_GEN_H From 7a520fa38830dad601cf1f27adfd855a7a3c112d Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Mon, 23 Dec 2024 12:16:28 +0000 Subject: [PATCH 4/4] Idk what this is meant to do but it doesn't seem to be referenced anywhere and shouldn't be valid --- data/mods/TEST_DATA/regions.json | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/data/mods/TEST_DATA/regions.json b/data/mods/TEST_DATA/regions.json index 0bdf88d5042c3..ec90163ee85d2 100644 --- a/data/mods/TEST_DATA/regions.json +++ b/data/mods/TEST_DATA/regions.json @@ -263,32 +263,5 @@ "required_str": -1, "flags": [ "TRANSPARENT", "FLAMMABLE_ASH" ], "examine_action": "flower_cactus" - }, - { - "type": "region_settings", - "id": "river", - "default_oter": [ - "open_air", - "open_air", - "open_air", - "open_air", - "open_air", - "open_air", - "open_air", - "open_air", - "open_air", - "open_air", - "field", - "solid_earth", - "empty_rock", - "empty_rock", - "empty_rock", - "empty_rock", - "empty_rock", - "empty_rock", - "empty_rock", - "empty_rock", - "empty_rock" - ] } ]