From 9443f4456f2eae76e79ca6aea6c3f5b386ab0ce7 Mon Sep 17 00:00:00 2001 From: CountSerg Date: Wed, 18 Dec 2019 23:14:08 +0400 Subject: [PATCH] [WIP] Add heartrate function for character --- src/character.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++++ src/character.h | 1 + 2 files changed, 49 insertions(+) diff --git a/src/character.cpp b/src/character.cpp index 10740e870ac85..b5c11820f157c 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -7281,3 +7281,51 @@ void Character::use_fire( const int quantity ) return; } } + +int Character::heartrate_bpm() const +{ + //This function returns heartrate in BPM basing of health, physical state, tiredness, moral effects, stimulators and anything that should fit here. + //Some values are picked to make sense from math point of view and seem correct but effects may vary in real life + //This needs more attention from experienced contributors to work more smooth + //Average healthy is 60-80. That's a simple imitation of mormal distribution. There's probably a better way to do that. Possibly this value should be generated with player creation. + int average_heartbeat = 70 + rng( -5, 5 ) + rng( -5, 5 ); + float stamina_level = float(get_stamina()) / float( get_stamina_max() ); + int stamina_effect = 0; + if( stamina_level >= 0.9 ) { + stamina_effect = 0; + } else if( stamina_level >= 0.8 ) { + stamina_effect = 0.2; + } else if( stamina_level >= 0.6 ) { + stamina_effect = 0.5; + } else if( stamina_level >= 0.4 ) { + stamina_effect = 1; + } else if( stamina_level >= 0.2 ) { + stamina_effect = 1.5; + } else { + stamina_effect = 2; + } + int heartbeat = average_heartbeat * ( 1 + stamina_effect );//can triple heartrate + int healthy = get_healthy();//already has over/underweight conditions factored + + float healthy_modifier = 0; + healthy_modifier = -0.05 * round( healthy / 20 );//a bit arbitary formula that can use some love + /*if ( healthy > 10 ) + { + healthy_modifier = -0.05 * ( healthy - 10 ) / 20;//5 percent per 20 health above 10. Might think of better way + } else if ( healthy < -10 ) { + { + healthy_modifier = 0.05 * ( healthy + 10 ) / 20;//-5 percent per 20 health above 10. Might think of better way + }*/ + heartbeat *= 1 + healthy_modifier;//probably a single clamp in the end should be enough + int stim_level = get_stim(); + int stim_modifer = 0; + if ( stim_level > 0 ) + { + //that's asymptotical function that is equal to 1 at around 30 stim level and slows down all the time almost reaching 2. Tweaking x*x multiplier will accordingly change effect accumulation + stim_modifer = 2.1 - 2/( 1 + 0.001 * stim_level * stim_level ); + } + heartbeat *= 1 + stim_modifer; + //add morale effects, mutations, fear(?), medication effects + heartbeat = clamp( heartbeat, average_heartbeat, 250 ); + return heartbeat; +} diff --git a/src/character.h b/src/character.h index 64f16bd158a2a..326eb94a3aea0 100644 --- a/src/character.h +++ b/src/character.h @@ -1550,6 +1550,7 @@ class Character : public Creature, public visitable void drench( int saturation, const body_part_set &flags, bool ignore_waterproof ); /** Recalculates morale penalty/bonus from wetness based on mutations, equipment and temperature */ void apply_wetness_morale( int temperature ); + int heartrate_bpm() const; protected: Character();