From ec760cdce08ef2fe7141fc8f711b005a6db9c04e Mon Sep 17 00:00:00 2001 From: andrei Date: Tue, 25 Apr 2023 13:13:29 +0300 Subject: [PATCH] weather/json: fix mist/fog formula and conditions --- data/json/weather_type.json | 19 +++++++++---------- tests/weather_test.cpp | 6 ++++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/data/json/weather_type.json b/data/json/weather_type.json index ac7788262b82e..026eb6e047981 100644 --- a/data/json/weather_type.json +++ b/data/json/weather_type.json @@ -262,12 +262,13 @@ "rains": false, "sound_category": "silent", "priority": 20, - "required_weathers": [ "clear", "sunny" ], + "required_weathers": [ "clear", "sunny", "fog" ], "condition": { "and": [ { "math": [ "weather('windpower')", "<", "12" ] }, { "math": [ "weather('windpower')", ">", "0" ] }, - { "math": [ "dew_point_factor", "<", "5" ] } + { "math": [ "dew_point_factor", "!=", "0" ] }, + { "math": [ "dew_point_factor", "<=", "5" ] } ] } }, @@ -288,11 +289,12 @@ "rains": false, "sound_category": "silent", "priority": 20, - "required_weathers": [ "mist" ], + "required_weathers": [ "clear", "sunny", "mist" ], "condition": { "and": [ { "math": [ "weather('windpower')", "<", "12" ] }, { "math": [ "weather('windpower')", ">", "0" ] }, + { "math": [ "dew_point_factor", "!=", "0" ] }, { "math": [ "dew_point_factor", "<=", "2.5" ] } ] } @@ -304,15 +306,12 @@ "//": "First and second math calculate the dew point, the third calculate how close the weather to the point it can form a fog", "//2": "dew_point_factor is a difference between actual temperature and the dew point. the closer it gets to zero, the bigger probability to cause a mist or dew, starting somewhere from 2,5 centigrade or 5 fahrenheit, to zero", "effect": [ + { "math": [ "wtemp_celsius", "=", "celsius( weather('temperature') )" ] }, { - "math": [ - "dprhx", - "=", - "log ( weather('humidity') / 100 ) + 17.625 * weather('temperature') / ( 516.2 + weather('temperature') )" - ] + "math": [ "dprhx", "=", "log ( weather('humidity') / 100 ) + 17.625 * wtemp_celsius / ( 243.04 + wtemp_celsius )" ] }, - { "math": [ "dew_point", "=", "516.2 * dprhx / ( 17.625 - dprhx )" ] }, - { "math": [ "dew_point_factor", "=", "weather('temperature') - ( dew_point )" ] } + { "math": [ "dew_point", "=", "243.04 * dprhx / ( 17.625 - dprhx )" ] }, + { "math": [ "dew_point_factor", "=", "abs( wtemp_celsius - dew_point )" ] } ] }, { diff --git a/tests/weather_test.cpp b/tests/weather_test.cpp index f09f89835adda..78acd37b0e31a 100644 --- a/tests/weather_test.cpp +++ b/tests/weather_test.cpp @@ -6,6 +6,7 @@ #include "calendar.h" #include "cata_catch.h" #include "cata_scope_helpers.h" +#include "effect_on_condition.h" #include "options_helpers.h" #include "point.h" #include "type_id.h" @@ -13,6 +14,9 @@ #include "weather_gen.h" #include "weather_type.h" +static const effect_on_condition_id +effect_on_condition_EOC_DEW_POINT_FACTOR( "EOC_DEW_POINT_FACTOR" ); + static double mean_abs_running_diff( std::vector const &v ) { double x = 0; @@ -68,9 +72,11 @@ static year_of_weather_data collect_weather_data( unsigned seed ) const time_point end = begin + calendar::year_length(); const int n_days = to_days( end - begin ); year_of_weather_data result( n_days ); + dialogue d( std::make_unique(), std::make_unique() ); // Collect generated weather data for a single year. for( time_point i = begin ; i < end ; i += 1_minutes ) { + effect_on_condition_EOC_DEW_POINT_FACTOR->activate( d ); w_point w = wgen.get_weather( tripoint_zero, i, seed ); int day = to_days( time_past_new_year( i ) ); int minute = to_minutes( time_past_midnight( i ) );