Skip to content

Commit

Permalink
Fixed body window to show broken limb healing progress. (#36550)
Browse files Browse the repository at this point in the history
* Fixed body part display to show mending progress

* Astyle
  • Loading branch information
Ramza13 authored and kevingranade committed Dec 30, 2019
1 parent 0eecf62 commit 5b3dcd7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
48 changes: 27 additions & 21 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ static const efftype_id effect_infected( "infected" );
static const efftype_id effect_in_pit( "in_pit" );
static const efftype_id effect_lightsnare( "lightsnare" );
static const efftype_id effect_lying_down( "lying_down" );
static const efftype_id effect_mending( "mending" );
static const efftype_id effect_narcosis( "narcosis" );
static const efftype_id effect_nausea( "nausea" );
static const efftype_id effect_no_sight( "no_sight" );
Expand Down Expand Up @@ -4112,22 +4113,7 @@ hp_part Character::body_window( const std::string &menu_header,
max_bp_name_len = std::max( max_bp_name_len, utf8_width( e.name ) );
}

const auto hp_str = [precise]( const int hp, const int maximal_hp ) -> std::string {
if( hp <= 0 )
{
return "==%==";
} else if( precise )
{
return string_format( "%d", hp );
} else
{
std::string h_bar = get_hp_bar( hp, maximal_hp, false ).first;
nc_color h_bar_col = get_hp_bar( hp, maximal_hp, false ).second;

return colorize( h_bar, h_bar_col ) + colorize( std::string( 5 - utf8_width( h_bar ),
'.' ), c_white );
}
};

uilist bmenu;
bmenu.desc_enabled = true;
Expand All @@ -4149,7 +4135,8 @@ hp_part Character::body_window( const std::string &menu_header,
// The same as in the main UI sidebar. Independent of the capability of the healing item/effect!
const nc_color all_state_col = limb_color( bp, true, true, true );
// Broken means no HP can be restored, it requires surgical attention.
const bool limb_is_broken = current_hp == 0;
const bool limb_is_broken = is_limb_broken( hp );
const bool limb_is_mending = worn_with_flag( "SPLINT", bp );

if( show_all ) {
e.allowed = true;
Expand Down Expand Up @@ -4184,11 +4171,30 @@ hp_part Character::body_window( const std::string &menu_header,
int new_d_power = static_cast<int>( std::floor( disinfectant_power ) );

const auto &aligned_name = std::string( max_bp_name_len - utf8_width( e.name ), ' ' ) + e.name;
msg += colorize( aligned_name, all_state_col ) + " " + hp_str( current_hp, maximal_hp );

if( limb_is_broken ) {
std::string hp_str;
if( limb_is_mending ) {
desc += colorize( _( "It is broken but has been set and just needs time to heal." ),
c_blue ) + "\n";
const auto &eff = get_effect( effect_mending, bp );
const int mend_perc = eff.is_null() ? 0.0 : 100 * eff.get_duration() / eff.get_max_duration();

if( precise ) {
hp_str = colorize( string_format( "=%2d%%=", mend_perc ), c_blue );
} else {
const int num = mend_perc / 20;
hp_str = colorize( std::string( num, '#' ) + std::string( 5 - num, '=' ), c_blue );
}
} else if( limb_is_broken ) {
desc += colorize( _( "It is broken. It needs a splint or surgical attention." ), c_red ) + "\n";
}
hp_str = "==%==";
} else if( precise ) {
hp_str = string_format( "%d", current_hp );
} else {
std::pair<std::string, nc_color> h_bar = get_hp_bar( current_hp, maximal_hp, false );
hp_str = colorize( h_bar.first, h_bar.second ) +
colorize( std::string( 5 - utf8_width( h_bar.first ), '.' ), c_white );
};
msg += colorize( aligned_name, all_state_col ) + " " + hp_str;

// BLEEDING block
if( bleeding ) {
Expand Down Expand Up @@ -6302,7 +6308,7 @@ void Character::heal( body_part healed, int dam )

void Character::heal( hp_part healed, int dam )
{
if( hp_cur[healed] > 0 ) {
if( !is_limb_broken( healed ) ) {
int effective_heal = std::min( dam, hp_max[healed] - hp_cur[healed] );
hp_cur[healed] += effective_heal;
g->events().send<event_type::character_heals_damage>( getID(), effective_heal );
Expand Down
2 changes: 1 addition & 1 deletion src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ bool npc::wear_if_wanted( const item &it )
for( int i = 0; i < num_hp_parts; i++ ) {
hp_part hpp = static_cast<hp_part>( i );
body_part bp = player::hp_to_bp( hpp );
if( hp_cur[i] <= 0 && it.covers( bp ) ) {
if( is_limb_broken( hpp ) && it.covers( bp ) ) {
splint = true;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ void player::apply_damage( Creature *source, body_part hurt, int dam, const bool
hp_cur[hurtpart] -= dam_to_bodypart;
g->events().send<event_type::character_takes_damage>( getID(), dam_to_bodypart );

if( hp_cur[hurtpart] <= 0 && ( source == nullptr || !source->is_hallucination() ) ) {
if( is_limb_broken( hurtpart ) && ( source == nullptr || !source->is_hallucination() ) ) {
if( !weapon.is_null() && can_unwield( weapon ).success() ) {
put_into_vehicle_or_drop( *this, item_drop_reason::tumbling, { weapon } );
i_rem( &weapon );
Expand Down
6 changes: 2 additions & 4 deletions src/player_hardcoded_effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1290,13 +1290,11 @@ void player::hardcoded_effects( effect &it )
}
}
} else if( id == effect_mending ) {
// TODO: Remove this and encapsulate hp_cur instead
if( hp_cur[bp_to_hp( bp )] > 0 ) {
if( !is_limb_broken( bp_to_hp( bp ) ) ) {
it.set_duration( 0_turns );
}
} else if( id == effect_disabled ) {
// TODO: Remove this and encapsulate hp_cur instead
if( hp_cur[bp_to_hp( bp )] > 0 ) {
if( !is_limb_broken( bp_to_hp( bp ) ) ) {
// Just unpause, in case someone added it as a temporary effect (numbing poison etc.)
it.unpause_effect();
}
Expand Down
4 changes: 2 additions & 2 deletions src/suffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ void Character::mend( int rate_multiplier )
// Wearing splints can slowly mend a broken limb back to 1 hp.
bool any_broken = false;
for( int i = 0; i < num_hp_parts; i++ ) {
if( hp_cur[i] <= 0 ) {
if( is_limb_broken( static_cast<hp_part>( i ) ) ) {
any_broken = true;
break;
}
Expand Down Expand Up @@ -1625,7 +1625,7 @@ void Character::mend( int rate_multiplier )
}

for( int i = 0; i < num_hp_parts; i++ ) {
const bool broken = ( hp_cur[i] <= 0 );
const bool broken = is_limb_broken( static_cast<hp_part>( i ) );
if( !broken ) {
continue;
}
Expand Down

0 comments on commit 5b3dcd7

Please sign in to comment.