Skip to content

Commit

Permalink
Smoothen weary tracker+intake reductions
Browse files Browse the repository at this point in the history
This is an extension of a previous modification to try to smooth out
the weary.intake reduction (smaller changes but more frequent), and
both increases that and does similar for weary.tracker. The
weary.intake changes are leading up to - probably after 0.F - an
exponential moving average being used instead, so that characters
are not, essentially hypoglycemic.
  • Loading branch information
actual-nh committed Feb 18, 2021
1 parent 45b1139 commit ab4ba67
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5690,31 +5690,32 @@ void Character::try_reduce_weariness( const float exertion )
weary.tick_counter++;
if( exertion == NO_EXERCISE ) {
weary.low_activity_ticks++;
// Recover twice as fast if asleep
// Recover twice as fast if asleep/similar
if( in_sleep_state() ) {
weary.low_activity_ticks++;
}
}

const float recovery_mult = get_option<float>( "WEARY_RECOVERY_MULT" );

if( weary.low_activity_ticks >= 6 ) {
if( weary.low_activity_ticks >= 3 ) {
int reduction = weary.tracker;
const int bmr = base_bmr();
// 1/20 of whichever's bigger
// 1/40 of whichever's bigger
if( bmr > reduction ) {
reduction = bmr * recovery_mult;
reduction = std::floor( bmr * recovery_mult * 0.5f );
} else {
reduction *= recovery_mult;
reduction = std::ceil( reduction * recovery_mult * 0.5f );
}
weary.low_activity_ticks -= 6;
weary.low_activity_ticks -= 3;

weary.tracker -= reduction;
weary.tracker -= std::max( reduction, 1 );
}

if( weary.tick_counter >= 6 ) {
weary.intake *= std::sqrt( 1 - recovery_mult );
weary.tick_counter -= 6;
// If happens to be no reduction, character is not (as) hypoglycemic
if( weary.tick_counter >= 3 ) {
weary.intake *= std::pow( 1 - recovery_mult, 0.25f );
weary.tick_counter -= 3;
}

// Normalize values, make sure we stay above 0
Expand Down

0 comments on commit ab4ba67

Please sign in to comment.