Skip to content

Commit

Permalink
Drying_rate
Browse files Browse the repository at this point in the history
  • Loading branch information
Venera3 committed Mar 15, 2024
1 parent 3601a6a commit 4fd3179
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
3 changes: 1 addition & 2 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -1051,8 +1051,7 @@ reference at least one body part or sub body part.
| `hit_difficulty` | (_mandatory_) How hard is it to hit a given body part, assuming "owner" is hit. Higher number means good hits will veer towards this part, lower means this part is unlikely to be hit by inaccurate attacks. Formula is `chance *= pow(hit_roll, hit_difficulty)`
| `drench_capacity` | (_mandatory_) How wet this part can get before being 100% drenched. 0 makes the limb waterproof, morale checks for absolute wetness while other effects for wetness percentage - making a high `drench_capacity` prevent the penalties longer.
| `drench_increment` | (_optional_) Units of "wetness" applied each time the limb gets drenched. Default 2, ignored by diving underwater.
| `drying_chance` | (_optional_) Base chance the bodypart will succeed in the drying roll ( `x/80` chance, modified by ambient temperature etc)
| `drying_increment` | (_optonal_) Units of wetness the limb will dry each turn, if it succeeds in the drying roll (base chance `drench_capacity / 80`, modified by ambient temperature).
| `drying_rate` | (_optional float_) Divisor on the time needed to dry a given amount of wetness from a bodypart, modified by clothing. Final drying rate depends on breathability, weather, and `drying_capacity` of the bodypart.
| `wet_morale` | (_optional_) Mood bonus/malus when the limb gets wet, representing the morale effect at 100% limb saturation. Modified by worn clothing and ambient temperature.
| `stylish_bonus` | (_optional_) Mood bonus associated with wearing fancy clothing on this part. (default: `0`)
| `hot_morale_mod` | (_optional_) Mood effect of being too hot on this part. (default: `0`)
Expand Down
3 changes: 1 addition & 2 deletions src/bodypart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ void body_part_type::load( const JsonObject &jo, const std::string_view )

mandatory( jo, was_loaded, "drench_capacity", drench_max );
optional( jo, was_loaded, "drench_increment", drench_increment, 2 );
optional( jo, was_loaded, "drying_chance", drying_chance, drench_max );
optional( jo, was_loaded, "drying_increment", drying_increment, 1 );
optional( jo, was_loaded, "drying_rate", drying_rate, 1.0f );

optional( jo, was_loaded, "wet_morale", wet_morale, 0 );

Expand Down
3 changes: 1 addition & 2 deletions src/bodypart.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ struct body_part_type {
units::temperature_delta temp_max = 0_C_delta;
int drench_max = 0;
int drench_increment = 2;
int drying_chance = 1;
int drying_increment = 1;
float drying_rate = 1.0f;
// Wetness morale bonus/malus of the limb
int wet_morale = 0;
int technique_enc_limit = 50;
Expand Down
7 changes: 3 additions & 4 deletions src/character_body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,10 @@ void Character::update_body_wetness( const w_point &weather )

// Make clothing slow down drying
const float clothing_mult = worn.clothing_wetness_mult( bp );

const time_duration drying = bp->drying_increment * average_drying * trait_mult * weather_mult *
const float drying_rate = bp->drying_rate;
const time_duration drying = average_drying * trait_mult * weather_mult *
temp_mult / clothing_mult;
const float turns_to_dry = to_turns<float>( drying );

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 Down
45 changes: 45 additions & 0 deletions tests/limb_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,51 @@ TEST_CASE( "Healing/mending_bonuses", "[character][limb]" )
}
}

TEST_CASE( "drying_rate", "[character][limb]" )
{
standard_npc dude( "Test NPC" );
clear_character( dude, true );
const weather_manager weather = get_weather();
REQUIRE( body_part_arm_l->drying_rate == 1.0f );
dude.drench( 100, dude.get_drenching_body_parts(), false );
REQUIRE( dude.get_part_wetness( body_part_arm_l ) == 200 );

// 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 );
base_dry++;
}
REQUIRE( base_dry == Approx( 450 ).margin( 100 ) );

// Birdify, clear water
clear_character( dude, true );
create_bird_char( dude );
REQUIRE( body_part_test_bird_wing_l->drying_rate == 2.0f );

Check failure on line 167 in tests/limb_test.cpp

View workflow job for this annotation

GitHub Actions / Basic Build and Test (Clang 10, Ubuntu, Curses)

1.0f == 2.0f
REQUIRE( body_part_test_bird_wing_r->drying_rate == 0.5f );
REQUIRE( dude.get_part_wetness( body_part_test_bird_wing_l ) == 0 );
REQUIRE( dude.get_part_wetness( body_part_test_bird_wing_r ) == 0 );
dude.drench( 100, dude.get_drenching_body_parts(), false );
REQUIRE( dude.get_part_wetness( body_part_test_bird_wing_l ) == 200 );
REQUIRE( dude.get_part_wetness( body_part_test_bird_wing_r ) == 200 );

int high_dry = 0;
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 );
if( dude.get_part_wetness( body_part_test_bird_wing_l ) > 0 ) {
high_dry++;
}
low_dry++;
}

// 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( base_dry / 2 ).margin( base_dry / 4 ) );
CHECK( low_dry == Approx( base_dry * 2 ).margin( base_dry ) );
}

TEST_CASE( "Limb_armor_coverage", "[character][limb][armor]" )
{
standard_npc dude( "Test NPC" );
Expand Down

0 comments on commit 4fd3179

Please sign in to comment.