Skip to content

Commit

Permalink
Just make it work with overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
Procyonae committed Nov 29, 2024
1 parent 0ea26b7 commit b1913fb
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 108 deletions.
69 changes: 14 additions & 55 deletions src/regional_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>( overmap_weather_settings_jo, "base_temperature",
overmap_weather_settings.base_temperature, !overlay );
read_and_set_or_throw<double>( overmap_weather_settings_jo, "base_humidity",
overmap_weather_settings.base_humidity, !overlay );
read_and_set_or_throw<double>( overmap_weather_settings_jo, "base_pressure",
overmap_weather_settings.base_pressure, !overlay );
read_and_set_or_throw<double>( overmap_weather_settings_jo, "base_wind",
overmap_weather_settings.base_wind, !overlay );
read_and_set_or_throw<int>( overmap_weather_settings_jo, "base_wind_distrib_peaks",
overmap_weather_settings.base_wind_distrib_peaks, !overlay );
read_and_set_or_throw<int>( overmap_weather_settings_jo, "base_wind_season_variation",
overmap_weather_settings.base_wind_season_variation, !overlay );
read_and_set_or_throw<int>( overmap_weather_settings_jo, "spring_temp_manual_mod",
overmap_weather_settings.spring_temp_manual_mod, !overlay );
read_and_set_or_throw<int>( overmap_weather_settings_jo, "summer_temp_manual_mod",
overmap_weather_settings.summer_temp_manual_mod, !overlay );
read_and_set_or_throw<int>( overmap_weather_settings_jo, "autumn_temp_manual_mod",
overmap_weather_settings.autumn_temp_manual_mod, !overlay );
read_and_set_or_throw<int>( overmap_weather_settings_jo, "winter_temp_manual_mod",
overmap_weather_settings.winter_temp_manual_mod, !overlay );
read_and_set_or_throw<int>( overmap_weather_settings_jo, "spring_humidity_manual_mod",
overmap_weather_settings.spring_humidity_manual_mod, !overlay );
read_and_set_or_throw<int>( overmap_weather_settings_jo, "summer_humidity_manual_mod",
overmap_weather_settings.summer_humidity_manual_mod, !overlay );
read_and_set_or_throw<int>( overmap_weather_settings_jo, "autumn_humidity_manual_mod",
overmap_weather_settings.autumn_humidity_manual_mod, !overlay );
read_and_set_or_throw<int>( 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 )
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );

Expand Down Expand Up @@ -791,6 +746,12 @@ 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 );
}

load_overmap_feature_flag_settings( jo, region.overmap_feature_flag, false, true );

load_overmap_forest_settings( jo, region.overmap_forest, false, true );
Expand All @@ -803,8 +764,6 @@ void apply_region_overlay( const JsonObject &jo, regional_settings &region )

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 );
}

Expand Down
26 changes: 1 addition & 25 deletions src/regional_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<weather_type_id> instead?
std::vector<std::string> weather_black_list;
std::vector<std::string> weather_white_list;

//void finalize(); Finalize weather_type_id s
overmap_weather_settings() = default;
};

struct map_extras {
unsigned int chance;
weighted_int_list<map_extra_id> values;
Expand Down Expand Up @@ -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<std::string, map_extras> region_extras;
Expand Down
61 changes: 36 additions & 25 deletions src/weather_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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<std::string>( "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 {
Expand Down Expand Up @@ -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<int, 4> 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 );
Expand Down Expand Up @@ -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.,
Expand All @@ -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<int>( 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<int>( 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 );
Expand Down Expand Up @@ -347,4 +333,29 @@ void weather_generator::sort_weather()
const weather_type_id & b ) {
return a->priority < b->priority;
} );
}
}

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;
}
27 changes: 24 additions & 3 deletions src/weather_gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "calendar.h"
#include "coordinates.h"
#include "regional_settings.h"
#include "type_id.h"
#include "units.h"

Expand All @@ -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<weather_type_id> and finalise in region settings instead?
std::vector<std::string> weather_black_list;
std::vector<std::string> weather_white_list;
/** All the current weather types based on white or black list and sorted by load order */
std::vector<weather_type_id> sorted_weather;
weather_generator();
Expand All @@ -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

0 comments on commit b1913fb

Please sign in to comment.