Skip to content

Commit

Permalink
Fog and mist weather (CleverRaven#64954)
Browse files Browse the repository at this point in the history
* initial commit

* no message

* improve calculations, currently uses test values

* oops

* no message

* no message

* fixing the wrong values, remove debug message

* tests: override weather in tests that need clear vision

* Andrei's fix of vision test

* vision_junction_reciprocity fix

* weather realism test fix

---------

Co-authored-by: andrei <[email protected]>
  • Loading branch information
GuardianDll and andrei8l authored Apr 21, 2023
1 parent 9d5ac50 commit af4a7b3
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 10 deletions.
70 changes: 70 additions & 0 deletions data/json/weather_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,76 @@
]
}
},
{
"id": "mist",
"type": "weather_type",
"name": "Mist",
"color": "light_gray",
"map_color": "dark_gray_white",
"sym": "~",
"ranged_penalty": 3,
"sight_penalty": 1.3,
"light_modifier": -20,
"sun_multiplier": 0.3,
"sound_attn": 0,
"dangerous": false,
"precip": "none",
"rains": false,
"sound_category": "silent",
"priority": 20,
"required_weathers": [ "clear", "sunny" ],
"condition": {
"and": [
{ "math": [ "u_val( 'weather:windpower' )", "<", "12" ] },
{ "math": [ "u_val( 'weather:windpower' )", ">", "0" ] },
{ "math": [ "dew_point_factor", "<", "5" ] }
]
}
},
{
"id": "fog",
"type": "weather_type",
"name": "Fog",
"color": "light_gray",
"map_color": "dark_gray_white",
"sym": "~",
"ranged_penalty": 7,
"sight_penalty": 1.7,
"light_modifier": -40,
"sun_multiplier": 0.3,
"sound_attn": 0,
"dangerous": false,
"precip": "none",
"rains": false,
"sound_category": "silent",
"priority": 20,
"required_weathers": [ "mist" ],
"condition": {
"and": [
{ "math": [ "u_val( 'weather:windpower' )", "<", "12" ] },
{ "math": [ "u_val( 'weather:windpower' )", ">", "0" ] },
{ "math": [ "dew_point_factor", "<=", "2.5" ] }
]
}
},
{
"type": "effect_on_condition",
"id": "EOC_DEW_POINT_FACTOR",
"recurrence": [ "15 minutes", "30 minutes" ],
"//": "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": [
"dprhx",
"=",
"log ( u_val( 'weather:humidity' ) / 100 ) + 17.625 * u_val( 'weather:temperature' ) / ( 469.5 + u_val( 'weather:temperature' ) )"
]
},
{ "math": [ "dew_point", "=", "469.5 * dprhx / ( 17.625 - dprhx )" ] },
{ "math": [ "dew_point_factor", "=", "u_val('weather: temperature') - ( dew_point )" ] }
]
},
{
"id": "early_portal_storm",
"type": "weather_type",
Expand Down
2 changes: 2 additions & 0 deletions tests/bionics_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "item_pocket.h"
#include "map_helpers.h"
#include "npc.h"
#include "options_helpers.h"
#include "pimpl.h"
#include "player_helpers.h"
#include "ret_val.h"
Expand Down Expand Up @@ -537,6 +538,7 @@ TEST_CASE( "fueled bionics", "[bionics] [item]" )
// Midday for solar test
clear_map();
g->reset_light_level();
scoped_weather_override weather_clear( WEATHER_CLEAR );
calendar::turn = calendar::turn_zero + 12_hours;
REQUIRE( g->is_in_sunlight( dummy.pos() ) );

Expand Down
4 changes: 4 additions & 0 deletions tests/char_sight_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "lightmap.h"
#include "map.h"
#include "map_helpers.h"
#include "options_helpers.h"
#include "player_helpers.h"
#include "type_id.h"

Expand Down Expand Up @@ -55,6 +56,7 @@ TEST_CASE( "light and fine_detail_vision_mod", "[character][sight][light][vision
clear_avatar();
clear_map();
g->reset_light_level();
scoped_weather_override weather_clear( WEATHER_CLEAR );

SECTION( "full daylight" ) {
// Set clock to noon
Expand Down Expand Up @@ -117,6 +119,7 @@ TEST_CASE( "character sight limits", "[character][sight][vision]" )
clear_avatar();
clear_map();
g->reset_light_level();
scoped_weather_override weather_clear( WEATHER_CLEAR );

GIVEN( "it is midnight with a new moon" ) {
calendar::turn = calendar::turn_zero;
Expand Down Expand Up @@ -212,6 +215,7 @@ TEST_CASE( "ursine vision", "[character][ursine][vision]" )
clear_avatar();
clear_map();
g->reset_light_level();
scoped_weather_override weather_clear( WEATHER_CLEAR );

float light_here = 0.0f;

Expand Down
31 changes: 21 additions & 10 deletions tests/vision_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "map_test_case.h"
#include "mapdata.h"
#include "mtype.h"
#include "options_helpers.h"
#include "point.h"
#include "type_id.h"
#include "units.h"
Expand Down Expand Up @@ -157,6 +158,7 @@ struct vision_test_case {
player_character.clear_moncams();
clear_map( -2, OVERMAP_HEIGHT );
g->reset_light_level();
scoped_weather_override weather_clear( WEATHER_CLEAR );

REQUIRE( !player_character.is_blind() );
REQUIRE( !player_character.in_sleep_state() );
Expand Down Expand Up @@ -534,40 +536,49 @@ TEST_CASE( "vision_single_tile_skylight", "[shadowcasting][vision]" )
TEST_CASE( "vision_junction_reciprocity", "[vision][reciprocity]" )
{
bool player_in_junction = GENERATE( true, false );
CAPTURE( player_in_junction );

vision_test_case t {
player_in_junction ?
std::vector<std::string>{
"u# ",
"-- Z",
"### ",
"#u####",
"#---z#",
"######",
}:
std::vector<std::string>{
"z# ",
"-- u",
"### ",
"#z####",
"#---u#",
"######",
},
player_in_junction ?
std::vector<std::string>{
"4466",
"4446",
"444666",
"444666",
"444466",
"444466",
}:
std::vector<std::string>{
"4444",
"4444",
"666666",
"444444",
"444444",
"444444",
},
day_time
};

monster *zombie = nullptr;
tile_predicate spawn_zombie = [&]( map_test_case::tile tile ) {
zombie = g->place_critter_at( mon_zombie, tile.p );
get_map().ter_set( tile.p + tripoint_above, ter_t_flat_roof );
return true;
};

t.set_up_tiles =
ifchar( 'C', spawn_moncam ) ||
ifchar( 'Z', spawn_zombie ) ||
ifchar( 'z', spawn_zombie ) ||
t.set_up_tiles;
t.flags.headlamp = true;
t.test_all();

if( player_in_junction ) {
Expand Down

0 comments on commit af4a7b3

Please sign in to comment.