Skip to content

Commit

Permalink
Rework Morale Display (#1708)
Browse files Browse the repository at this point in the history
* Rework Morale Display

* Move function.
  • Loading branch information
KheirFerrum authored Jul 21, 2022
1 parent f5b347d commit c8c336a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 39 deletions.
26 changes: 5 additions & 21 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,27 +986,11 @@ void avatar::disp_morale()
{
int equilibrium = calc_focus_equilibrium();

int fatigue_penalty = 0;
if( get_fatigue() >= fatigue_levels::massive && equilibrium > 20 ) {
fatigue_penalty = equilibrium - 20;
equilibrium = 20;
} else if( get_fatigue() >= fatigue_levels::exhausted && equilibrium > 40 ) {
fatigue_penalty = equilibrium - 40;
equilibrium = 40;
} else if( get_fatigue() >= fatigue_levels::dead_tired && equilibrium > 60 ) {
fatigue_penalty = equilibrium - 60;
equilibrium = 60;
} else if( get_fatigue() >= fatigue_levels::tired && equilibrium > 80 ) {
fatigue_penalty = equilibrium - 80;
equilibrium = 80;
}

int pain_penalty = 0;
if( get_perceived_pain() && !has_trait( trait_CENOBITE ) ) {
pain_penalty = calc_focus_equilibrium( true ) - equilibrium - fatigue_penalty;
}

morale->display( equilibrium, pain_penalty, fatigue_penalty );
int fatigue_cap = calc_fatigue_cap( *this );

int pain_penalty = has_trait( trait_CENOBITE ) ? 0 : get_perceived_pain();

morale->display( equilibrium, pain_penalty, fatigue_cap );
}

int avatar::get_str_base() const
Expand Down
10 changes: 5 additions & 5 deletions src/morale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ void player_morale::decay( const time_duration &ticks )
invalidate();
}

void player_morale::display( int focus_eq, int pain_penalty, int fatigue_penalty )
void player_morale::display( int focus_eq, int pain_penalty, int fatigue_cap )
{
/*calculates the percent contributions of the morale points,
* must be done before anything else in this method
Expand Down Expand Up @@ -720,11 +720,11 @@ void player_morale::display( int focus_eq, int pain_penalty, int fatigue_penalty
morale_line::line_color::green_gray_red
);
}
if( fatigue_penalty != 0 ) {
if( fatigue_cap ) {
bottom_lines.emplace_back(
_( "Fatigue level:" ), -fatigue_penalty,
morale_line::number_format::signed_or_dash,
morale_line::line_color::green_gray_red
_( "Fatigue Morale Cap:" ), fatigue_cap,
morale_line::number_format::normal,
morale_line::line_color::red_gray_green
);
}
bottom_lines.emplace_back(
Expand Down
2 changes: 1 addition & 1 deletion src/morale.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class player_morale
/** Ticks down morale counters and removes them */
void decay( const time_duration &ticks = 1_turns );
/** Displays morale screen */
void display( int focus_eq, int pain_penalty, int fatigue_penalty );
void display( int focus_eq, int pain_penalty, int fatigue_cap );
/** Returns false whether morale is inconsistent with the argument.
* Only permanent morale is checked */
bool consistent_with( const player_morale &morale ) const;
Expand Down
31 changes: 21 additions & 10 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4407,7 +4407,21 @@ bool player::query_yn( const std::string &mes ) const
return ::query_yn( mes );
}

int player::calc_focus_equilibrium( bool ignore_pain ) const
int calc_fatigue_cap( const player &p )
{
if( p.get_fatigue() >= fatigue_levels::massive ) {
return 20;
} else if( p.get_fatigue() >= fatigue_levels::exhausted ) {
return 40;
} else if( p.get_fatigue() >= fatigue_levels::dead_tired ) {
return 60;
} else if( p.get_fatigue() >= fatigue_levels::tired ) {
return 80;
}
return 0;
}

int player::calc_focus_equilibrium() const
{
int focus_equilibrium = 100;

Expand All @@ -4426,10 +4440,15 @@ int player::calc_focus_equilibrium( bool ignore_pain ) const
int eff_morale = get_morale_level();
// Factor in perceived pain, since it's harder to rest your mind while your body hurts.
// Cenobites don't mind, though
if( !ignore_pain && !has_trait( trait_CENOBITE ) ) {
if( !has_trait( trait_CENOBITE ) ) {
eff_morale = eff_morale - get_perceived_pain();
}

// as baseline morale is 100, calc_fatigue_cap() has to -100 to apply accurate penalties.
if( calc_fatigue_cap( *this ) != 0 && eff_morale > calc_fatigue_cap( *this ) - 100 ) {
eff_morale = calc_fatigue_cap( *this ) - 100;
}

if( eff_morale < -99 ) {
// At very low morale, focus is at it's minimum
focus_equilibrium = 1;
Expand Down Expand Up @@ -4492,14 +4511,6 @@ int player::calc_focus_change() const

gain *= base_change;

// Fatigue will incrementally decrease any focus above related cap
if( ( get_fatigue() >= fatigue_levels::tired && focus_pool > 100 ) ||
( get_fatigue() >= fatigue_levels::dead_tired && focus_pool > 75 ) ||
( get_fatigue() >= fatigue_levels::exhausted && focus_pool > 50 ) ||
( get_fatigue() >= fatigue_levels::massive && focus_pool > 25 ) ) {

gain = std::min( gain, -1 );
}
return gain;
}

Expand Down
7 changes: 5 additions & 2 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ class player : public Character
/** Checked each turn during "lying_down", returns true if the player falls asleep */
bool can_sleep();

/** Uses morale and other factors to return the player's focus target goto value */
int calc_focus_equilibrium( bool ignore_pain = false ) const;
/** Uses morale, pain and fatigue to return the player's focus target goto value */
int calc_focus_equilibrium() const;
/** Calculates actual focus gain/loss value from focus equilibrium*/
int calc_focus_change() const;
/** Uses calc_focus_change to update the player's current focus */
Expand Down Expand Up @@ -777,4 +777,7 @@ class player : public Character
mutable decltype( _skills ) valid_autolearn_skills;
};

/** Calculates the player's morale cap due to fatigue */
int calc_fatigue_cap( const player &p );

#endif // CATA_SRC_PLAYER_H

0 comments on commit c8c336a

Please sign in to comment.