Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limbify drying rate again #72406

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions data/mods/TEST_DATA/body_parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,12 @@
"side": "left",
"hot_morale_mod": 0.5,
"cold_morale_mod": 0.5,
"drying_rate": 2,
"fire_warmth_bonus": 600,
"squeamish_penalty": 5,
"is_limb": true,
"base_hp": 60,
"drench_capacity": 10,
"drench_capacity": 1000,
"smash_message": "You elbow-smash the %s.",
"bionic_slots": 20,
"ugliness": 30,
Expand Down Expand Up @@ -208,7 +209,8 @@
"squeamish_penalty": 5,
"is_limb": true,
"base_hp": 60,
"drench_capacity": 10,
"drench_capacity": 1000,
"drying_rate": 0.5,
"smash_message": "You elbow-smash the %s.",
"bionic_slots": 20,
"ugliness": 30,
Expand Down
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 );
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
Loading