Skip to content

Commit

Permalink
Merge pull request #28692 from CleverRaven/kevingranade-fix-sts-insta…
Browse files Browse the repository at this point in the history
…nt-death

Adjust recalc_hp to avoid migrating hp levels
  • Loading branch information
Rivet-the-Zombie authored Mar 14, 2019
2 parents 7d7eaf6 + afae3ff commit 5b6a055
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,15 @@ void Character::recalc_hp()
new_max_hp[hp_head] *= 0.8;
}
for( int i = 0; i < num_hp_parts; i++ ) {
hp_cur[i] *= static_cast<float>( new_max_hp[i] ) / static_cast<float>( hp_max[i] );
// Only recalculate when max changes,
// otherwise we end up walking all over due to rounding errors.
if( new_max_hp[i] == hp_max[i] ) {
continue;
}
float max_hp_ratio = static_cast<float>( new_max_hp[i] ) /
static_cast<float>( hp_max[i] );
hp_cur[i] = std::ceil( static_cast<float>( hp_cur[i] ) * max_hp_ratio );
hp_cur[i] = std::max( std::min( hp_cur[i], new_max_hp[i] ), 1 );
hp_max[i] = new_max_hp[i];
}
}
Expand Down

0 comments on commit 5b6a055

Please sign in to comment.