From b1913fb6c53d9896ed4dbc594d6b61b890b97c29 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Fri, 29 Nov 2024 13:27:26 +0000 Subject: [PATCH] Just make it work with overlay --- src/regional_settings.cpp | 69 ++++++++------------------------------- src/regional_settings.h | 26 +-------------- src/weather_gen.cpp | 61 ++++++++++++++++++++-------------- src/weather_gen.h | 27 +++++++++++++-- 4 files changed, 75 insertions(+), 108 deletions(-) diff --git a/src/regional_settings.cpp b/src/regional_settings.cpp index 4cd4a8e852341..78875cda2987f 100644 --- a/src/regional_settings.cpp +++ b/src/regional_settings.cpp @@ -360,57 +360,6 @@ static void load_overmap_connection_settings( } } -static void load_overmap_weather_settings( - const JsonObject &jo, overmap_weather_settings &overmap_weather_settings, const bool strict, - const bool overlay ) -{ - if( !jo.has_object( "weather" ) ) { - if( strict ) { - jo.throw_error( "\"weather\": { … } required for default" ); - } - } else { - JsonObject overmap_weather_settings_jo = jo.get_object( "weather" ); - read_and_set_or_throw( overmap_weather_settings_jo, "base_temperature", - overmap_weather_settings.base_temperature, !overlay ); - read_and_set_or_throw( overmap_weather_settings_jo, "base_humidity", - overmap_weather_settings.base_humidity, !overlay ); - read_and_set_or_throw( overmap_weather_settings_jo, "base_pressure", - overmap_weather_settings.base_pressure, !overlay ); - read_and_set_or_throw( overmap_weather_settings_jo, "base_wind", - overmap_weather_settings.base_wind, !overlay ); - read_and_set_or_throw( overmap_weather_settings_jo, "base_wind_distrib_peaks", - overmap_weather_settings.base_wind_distrib_peaks, !overlay ); - read_and_set_or_throw( overmap_weather_settings_jo, "base_wind_season_variation", - overmap_weather_settings.base_wind_season_variation, !overlay ); - read_and_set_or_throw( overmap_weather_settings_jo, "spring_temp_manual_mod", - overmap_weather_settings.spring_temp_manual_mod, !overlay ); - read_and_set_or_throw( overmap_weather_settings_jo, "summer_temp_manual_mod", - overmap_weather_settings.summer_temp_manual_mod, !overlay ); - read_and_set_or_throw( overmap_weather_settings_jo, "autumn_temp_manual_mod", - overmap_weather_settings.autumn_temp_manual_mod, !overlay ); - read_and_set_or_throw( overmap_weather_settings_jo, "winter_temp_manual_mod", - overmap_weather_settings.winter_temp_manual_mod, !overlay ); - read_and_set_or_throw( overmap_weather_settings_jo, "spring_humidity_manual_mod", - overmap_weather_settings.spring_humidity_manual_mod, !overlay ); - read_and_set_or_throw( overmap_weather_settings_jo, "summer_humidity_manual_mod", - overmap_weather_settings.summer_humidity_manual_mod, !overlay ); - read_and_set_or_throw( overmap_weather_settings_jo, "autumn_humidity_manual_mod", - overmap_weather_settings.autumn_humidity_manual_mod, !overlay ); - read_and_set_or_throw( overmap_weather_settings_jo, "winter_humidity_manual_mod", - overmap_weather_settings.winter_humidity_manual_mod, !overlay ); - - if( jo.has_member( "weather_black_list" ) && jo.has_member( "weather_white_list" ) ) { - jo.throw_error( "weather_black_list and weather_white_list are mutually exclusive" ); - } else if( jo.has_member( "weather_black_list" ) ) { - overmap_weather_settings.weather_black_list = jo.get_string_array( "weather_black_list" ); - overmap_weather_settings.weather_white_list.clear(); - } else if( jo.has_member( "weather_white_list" ) ) { - overmap_weather_settings.weather_white_list = jo.get_string_array( "weather_white_list" ); - overmap_weather_settings.weather_black_list.clear(); - } - } -} - static void load_overmap_lake_settings( const JsonObject &jo, overmap_lake_settings &overmap_lake_settings, const bool strict, const bool overlay ) @@ -638,6 +587,14 @@ void load_region_settings( const JsonObject &jo ) load_building_types( "parks", new_region.city_spec.parks ); } + // TODO: Support overwriting only some values in non default regions + if( strict && !jo.has_object( "weather" ) ) { + jo.throw_error( "\"weather\": { … } required for default" ); + } else { + JsonObject wjo = jo.get_object( "weather" ); + new_region.weather = weather_generator::load( wjo ); + } + load_overmap_feature_flag_settings( jo, new_region.overmap_feature_flag, strict, false ); load_overmap_forest_settings( jo, new_region.overmap_forest, strict, false ); @@ -650,8 +607,6 @@ void load_region_settings( const JsonObject &jo ) load_overmap_connection_settings( jo, new_region.overmap_connection, strict, false ); - load_overmap_weather_settings( jo, new_region.weather, strict, false ); - load_region_terrain_and_furniture_settings( jo, new_region.region_terrain_and_furniture, strict, false ); @@ -791,6 +746,12 @@ 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 ); + } + load_overmap_feature_flag_settings( jo, region.overmap_feature_flag, false, true ); load_overmap_forest_settings( jo, region.overmap_forest, false, true ); @@ -803,8 +764,6 @@ void apply_region_overlay( const JsonObject &jo, regional_settings ®ion ) load_overmap_connection_settings( jo, region.overmap_connection, false, true ); - load_overmap_weather_settings( jo, new_region.weather, false, true ); - load_region_terrain_and_furniture_settings( jo, region.region_terrain_and_furniture, false, true ); } diff --git a/src/regional_settings.h b/src/regional_settings.h index b7c26393d0181..558bad5c2bf7e 100644 --- a/src/regional_settings.h +++ b/src/regional_settings.h @@ -245,30 +245,6 @@ struct overmap_connection_settings { overmap_connection_settings() = default; }; -struct overmap_weather_settings { - double base_temperature = 6.5; - double base_humidity = 70.0; - double base_pressure = 1015.0; - double base_wind = 3.4; - int base_wind_distrib_peaks = 80; - int base_wind_season_variation = 50; - // TODO: Store as arrays? - int spring_temp_manual_mod = 0; - int summer_temp_manual_mod = 0; - int autumn_temp_manual_mod = 0; - int winter_temp_manual_mod = 0; - int spring_humidity_manual_mod = 0; - int summer_humidity_manual_mod = 0; - int autumn_humidity_manual_mod = 0; - int winter_humidity_manual_mod = 0; - // TODO: Use std::vector instead? - std::vector weather_black_list; - std::vector weather_white_list; - - //void finalize(); Finalize weather_type_id s - overmap_weather_settings() = default; -}; - struct map_extras { unsigned int chance; weighted_int_list values; @@ -305,13 +281,13 @@ struct regional_settings { city_settings city_spec; // put what where in a city of what kind forest_mapgen_settings forest_composition; forest_trail_settings forest_trail; + weather_generator weather; overmap_feature_flag_settings overmap_feature_flag; overmap_forest_settings overmap_forest; overmap_lake_settings overmap_lake; overmap_ocean_settings overmap_ocean; overmap_ravine_settings overmap_ravine; overmap_connection_settings overmap_connection; - overmap_weather_settings weather; region_terrain_and_furniture_settings region_terrain_and_furniture; std::unordered_map region_extras; diff --git a/src/weather_gen.cpp b/src/weather_gen.cpp index 48a8ec8551daa..b7d922f13bacf 100644 --- a/src/weather_gen.cpp +++ b/src/weather_gen.cpp @@ -16,7 +16,6 @@ #include "json.h" #include "math_defines.h" #include "point.h" -#include "regional_settings.h" #include "rng.h" #include "simplexnoise.h" #include "translations.h" @@ -37,18 +36,6 @@ constexpr double noise_magnitude_K = 8; } //namespace weather_generator::weather_generator() = default; - -weather_generator::weather_generator() -{ - const std::string rsettings_id = get_option( "DEFAULT_REGION" ); - t_regional_settings_map_citr rsit = region_settings_map.find( rsettings_id ); - - if( rsit == region_settings_map.end() ) { - debugmsg( "weather_generator: can't find region '%s'", rsettings_id.c_str() ); - } - s = &rsit->second.overmap_weather_settings; -} - int weather_generator::current_winddir = 1000; struct weather_gen_common { @@ -104,11 +91,11 @@ static units::temperature weather_temperature_from_common_data( const weather_ge // manually specified seasonal temp variation from region_settings.json const std::array seasonal_temp_mod = { - wg.s->spring_temp_manual_mod, wg.s->summer_temp_manual_mod, wg.s->autumn_temp_manual_mod, - wg.s->winter_temp_manual_mod + wg.spring_temp_manual_mod, wg.summer_temp_manual_mod, wg.autumn_temp_manual_mod, + wg.winter_temp_manual_mod }; const double baseline( - wg.s->base_temperature + + wg.base_temperature + seasonal_temp_mod[season] + dayv * daily_magnitude_K + seasonality * seasonality_magnitude_K ); @@ -147,13 +134,13 @@ w_point weather_generator::get_weather( const tripoint_abs_ms &location, const t // Humidity variation double mod_h( 0 ); if( season == WINTER ) { - mod_h += s->winter_humidity_manual_mod; + mod_h += winter_humidity_manual_mod; } else if( season == SPRING ) { - mod_h += s->spring_humidity_manual_mod; + mod_h += spring_humidity_manual_mod; } else if( season == SUMMER ) { - mod_h += s->summer_humidity_manual_mod; + mod_h += summer_humidity_manual_mod; } else if( season == AUTUMN ) { - mod_h += s->autumn_humidity_manual_mod; + mod_h += autumn_humidity_manual_mod; } // Relative humidity, a percentage. double H = std::min( 100., std::max( 0., @@ -169,10 +156,9 @@ w_point weather_generator::get_weather( const tripoint_abs_ms &location, const t 10 * ( -seasonality + 2 ); // Wind power - W = std::max( 0, static_cast( s->base_wind * rng( 1, 2 ) / std::pow( ( P + W ) / 1014.78, - rng( 9, - s->base_wind_distrib_peaks ) ) + - -cyf / s->base_wind_season_variation * rng( 1, 2 ) ) ); + W = std::max( 0, static_cast( base_wind * rng( 1, 2 ) / std::pow( ( P + W ) / 1014.78, rng( 9, + base_wind_distrib_peaks ) ) + + -cyf / base_wind_season_variation * rng( 1, 2 ) ) ); // Initial static variable if( current_winddir == 1000 ) { current_winddir = get_wind_direction( season ); @@ -347,4 +333,29 @@ void weather_generator::sort_weather() const weather_type_id & b ) { return a->priority < b->priority; } ); -} \ No newline at end of file +} + +weather_generator weather_generator::load( const JsonObject &jo ) +{ + 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() ) { + 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 87d30852b8353..3f916bf5273f4 100644 --- a/src/weather_gen.h +++ b/src/weather_gen.h @@ -8,7 +8,6 @@ #include "calendar.h" #include "coordinates.h" -#include "regional_settings.h" #include "type_id.h" #include "units.h" @@ -29,7 +28,31 @@ struct w_point { class weather_generator { public: + // Average temperature + double base_temperature = 0; + // Average humidity + double base_humidity = 0; + // Average atmospheric pressure + double base_pressure = 0; + //Average yearly windspeed + double base_wind = 0; + //How much the wind peaks above average + int base_wind_distrib_peaks = 0; + // TODO: Store as arrays? + int summer_temp_manual_mod = 0; + int spring_temp_manual_mod = 0; + int autumn_temp_manual_mod = 0; + int winter_temp_manual_mod = 0; + int spring_humidity_manual_mod = 0; + int summer_humidity_manual_mod = 0; + int autumn_humidity_manual_mod = 0; + int winter_humidity_manual_mod = 0; + //How much the wind follows seasonal variation ( lower means more change ) + int base_wind_season_variation = 0; static int current_winddir; + // TODO: Use std::vector and finalise in region settings instead? + std::vector weather_black_list; + std::vector weather_white_list; /** All the current weather types based on white or black list and sorted by load order */ std::vector sorted_weather; weather_generator(); @@ -51,8 +74,6 @@ class weather_generator units::temperature get_weather_temperature( const tripoint &, const time_point &, unsigned ) const; static weather_generator load( const JsonObject &jo ); - private: - const overmap_weather_settings *s; }; #endif // CATA_SRC_WEATHER_GEN_H