From 6a78cc5e03c3b583a7fbbed58255a1b5aa5cf47c Mon Sep 17 00:00:00 2001 From: ShnitzelX2 <65314588+ShnitzelX2@users.noreply.github.com> Date: Tue, 26 Nov 2024 23:02:50 -0500 Subject: [PATCH] fix limb drying rate and related test data weather not accounted for in test, update test values --- src/character_body.cpp | 8 ++++---- tests/limb_test.cpp | 33 ++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/character_body.cpp b/src/character_body.cpp index 445d7db309b48..118924a7422a7 100644 --- a/src/character_body.cpp +++ b/src/character_body.cpp @@ -147,6 +147,7 @@ void Character::update_body_wetness( const w_point &weather ) for( const bodypart_id &bp : get_all_body_parts() ) { const units::temperature temp_conv = get_part_temp_conv( bp ); + const int drench_cap = get_part_drench_capacity( bp ); // do sweat related tests assuming not underwater if( !is_underwater() ) { const int wetness = get_part_wetness( bp ); @@ -177,7 +178,6 @@ void Character::update_body_wetness( const w_point &weather ) const time_duration drying = average_drying * trait_mult * weather_mult * temp_mult / clothing_mult; const float turns_to_dry = to_turns( drying ) / drying_rate; - const int drench_cap = get_part_drench_capacity( bp ); const float dry_per_turn = static_cast( drench_cap ) / turns_to_dry; mod_part_wetness( bp, roll_remainder( dry_per_turn ) * -1 ); @@ -193,14 +193,14 @@ void Character::update_body_wetness( const w_point &weather ) // Safety measure to keep wetness within bounds if( get_part_wetness( bp ) <= 0 ) { // if we are hot still we should always be a bit wet (still sweating), this is a small hack to make sure we don't miss cooling ticks with good breathability clothing - if( temp_conv >= BODYTEMP_HOT && get_part_drench_capacity( bp ) > 0 ) { + if( temp_conv >= BODYTEMP_HOT && drench_cap > 0 ) { set_part_wetness( bp, 1 ); } else { set_part_wetness( bp, 0 ); } } - if( get_part_wetness( bp ) > get_part_drench_capacity( bp ) ) { - set_part_wetness( bp, get_part_drench_capacity( bp ) ); + if( get_part_wetness( bp ) > drench_cap ) { + set_part_wetness( bp, drench_cap ); } // Add effects to track wetness diff --git a/tests/limb_test.cpp b/tests/limb_test.cpp index 29e2507631e3b..cbd0229b855c7 100644 --- a/tests/limb_test.cpp +++ b/tests/limb_test.cpp @@ -9,6 +9,7 @@ #include "magic_enchantment.h" #include "map_helpers.h" #include "mutation.h" +#include "options_helpers.h" #include "player_helpers.h" static const bodypart_str_id body_part_test_arm_l( "test_arm_l" ); @@ -166,13 +167,24 @@ TEST_CASE( "drying_rate", "[character][limb]" ) map &here = get_map(); standard_npc dude( "Test NPC" ); clear_character( dude, true ); - const weather_manager weather = get_weather(); + + set_time_to_day(); + const weather_manager &weather = get_weather(); + w_point &weather_point = *weather.weather_precise; + scoped_weather_override weather_clear( WEATHER_CLEAR ); + restore_on_out_of_scope> restore_temp( + weather_point.temperature ); + weather_point.temperature = units::from_fahrenheit( 65 ); + restore_on_out_of_scope> restore_humidity( + weather_point.humidity ); + weather_point.humidity = 66.0f; + + CAPTURE( weather.weather_id.c_str() ); + CAPTURE( units::to_fahrenheit( weather_point.temperature ) ); + CAPTURE( weather_point.humidity ); REQUIRE( here.ter( dude.pos() ).id() == ter_t_grass ); REQUIRE( here.furn( dude.pos() ).id() == furn_str_id::NULL_ID() ); - CAPTURE( weather.weather_id.c_str() ); - CAPTURE( units::to_fahrenheit( weather.temperature ) ); - CAPTURE( weather.weather_precise->humidity ); REQUIRE( body_part_arm_l->drying_rate == 1.0f ); dude.drench( 100, dude.get_drenching_body_parts(), false ); @@ -181,10 +193,11 @@ TEST_CASE( "drying_rate", "[character][limb]" ) // Baseline arm dries in 450ish turns int base_dry = 0; while( dude.get_part_wetness( body_part_arm_l ) > 0 ) { - dude.update_body_wetness( *weather.weather_precise ); + dude.update_body_wetness( weather_point ); base_dry++; } - REQUIRE( base_dry == Approx( 450 ).margin( 125 ) ); + // 200 wetness / (1000 drench cap / ~1800 turns ) = 360 + REQUIRE( base_dry == Approx( 360 ).margin( 120 ) ); // Birdify, clear water clear_character( dude, true ); @@ -203,7 +216,7 @@ TEST_CASE( "drying_rate", "[character][limb]" ) int low_dry = 0; // Filter on the slower drying limb while( dude.get_part_wetness( body_part_test_bird_wing_r ) > 0 ) { - dude.update_body_wetness( *weather.weather_precise ); + dude.update_body_wetness( weather_point ); if( dude.get_part_wetness( body_part_test_bird_wing_l ) > 0 ) { high_dry++; } @@ -212,8 +225,10 @@ TEST_CASE( "drying_rate", "[character][limb]" ) // A drying rate of 2 should halve the drying time // Higher margin for the lower rate to account for the randomness - CHECK( high_dry == Approx( 200 ).margin( 100 ) ); - CHECK( low_dry == Approx( 900 ).margin( 300 ) ); + // 200 wetness / (1000 drench cap / ~(1800/2) turns) = 180 + CHECK( high_dry == Approx( 180 ).margin( 60 ) ); + // 200 wetness / (1000 drench cap / ~(1800*2) turns) = 720 + CHECK( low_dry == Approx( 720 ).margin( 240 ) ); } TEST_CASE( "Limb_consumption", "[limb]" )