Skip to content

Commit

Permalink
weather/json: fix mist/fog formula and conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei8l committed Apr 28, 2023
1 parent 6b88550 commit ca746d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
19 changes: 9 additions & 10 deletions data/json/weather_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ] }
]
}
},
Expand All @@ -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" ] }
]
}
Expand All @@ -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 )" ] }
]
},
{
Expand Down
6 changes: 6 additions & 0 deletions tests/weather_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
#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"
#include "weather.h"
#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<double> const &v )
{
double x = 0;
Expand Down Expand Up @@ -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<int>( end - begin );
year_of_weather_data result( n_days );
dialogue d( std::make_unique<talker>(), std::make_unique<talker>() );

// 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<int>( time_past_new_year( i ) );
int minute = to_minutes<int>( time_past_midnight( i ) );
Expand Down

0 comments on commit ca746d0

Please sign in to comment.