Skip to content

Commit

Permalink
Merge pull request #78189 from ShnitzelX2/fix-limb-drying
Browse files Browse the repository at this point in the history
Fix limb drying rate test
  • Loading branch information
Night-Pryanik authored Nov 28, 2024
2 parents dee2697 + 6a78cc5 commit b21c346
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/character_body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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<float>( drying ) / drying_rate;
const int drench_cap = get_part_drench_capacity( bp );
const float dry_per_turn = static_cast<float>( drench_cap ) / turns_to_dry;
mod_part_wetness( bp, roll_remainder( dry_per_turn ) * -1 );

Expand All @@ -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
Expand Down
33 changes: 24 additions & 9 deletions tests/limb_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down Expand Up @@ -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<std::optional<units::temperature>> restore_temp(
weather_point.temperature );
weather_point.temperature = units::from_fahrenheit( 65 );
restore_on_out_of_scope<std::optional<double>> 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 );
Expand All @@ -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 );
Expand All @@ -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++;
}
Expand All @@ -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]" )
Expand Down

0 comments on commit b21c346

Please sign in to comment.