Skip to content

Commit

Permalink
Merge pull request #78726 from Procyonae/WeatherGeneratorSupportsPart…
Browse files Browse the repository at this point in the history
…ialOverlay

Allow proper overlaying of weather_generator
  • Loading branch information
Maleclypse authored Dec 26, 2024
2 parents ef49525 + 7a520fa commit 1e44b42
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 52 deletions.
36 changes: 8 additions & 28 deletions data/mods/TEST_DATA/regions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [ ] }
},
{
Expand Down Expand Up @@ -256,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"
]
}
]
5 changes: 2 additions & 3 deletions src/regional_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -746,10 +746,9 @@ void apply_region_overlay( const JsonObject &jo, regional_settings &region )
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 );
Expand Down
39 changes: 19 additions & 20 deletions src/weather_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/weather_gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, bool was_loaded );
};

#endif // CATA_SRC_WEATHER_GEN_H

0 comments on commit 1e44b42

Please sign in to comment.