Skip to content

Commit

Permalink
[WIP] Add heartrate function for character
Browse files Browse the repository at this point in the history
  • Loading branch information
CountAlex committed Dec 18, 2019
1 parent 572b78f commit 3150564
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_max_stamina() );
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 )y=3\ -\frac{3}{\left(1+0.005x\cdot x\right)}
{
//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 * x * x );
}
heartbeat *= 1 + healthy_modifier;
//add morale effects, mutations, fear(?), medication effects
heartbeat = clamp( heartbeat, average_heartbeat, 250 );
return heartbeat;
}
1 change: 1 addition & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,7 @@ class Character : public Creature, public visitable<Character>
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();
Expand Down

0 comments on commit 3150564

Please sign in to comment.