Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move more body_part to bodypart_id in Character part1 #40144

Merged
merged 14 commits into from
May 11, 2020
Prev Previous commit
Next Next commit
limb_color
  • Loading branch information
Fris0uman committed May 8, 2020
commit 6789c1ef47ab9b731ee729bc40282400dda0948c
59 changes: 30 additions & 29 deletions src/character.cpp
Original file line number Diff line number Diff line change
@@ -5917,20 +5917,20 @@ hp_part Character::body_window( const std::string &menu_header,
* Damage to bp_head, bp_eyes and bp_mouth is all applied on the HP of hp_head. */
struct healable_bp {
mutable bool allowed;
body_part bp;
bodypart_id bp;
hp_part hp;
std::string name; // Translated name as it appears in the menu.
int bonus;
};
/* The array of the menu entries show to the player. The entries are displayed in this order,
* it may be changed here. */
std::array<healable_bp, num_hp_parts> parts = { {
{ false, bp_head, hp_head, _( "Head" ), head_bonus },
{ false, bp_torso, hp_torso, _( "Torso" ), torso_bonus },
{ false, bp_arm_l, hp_arm_l, _( "Left Arm" ), normal_bonus },
{ false, bp_arm_r, hp_arm_r, _( "Right Arm" ), normal_bonus },
{ false, bp_leg_l, hp_leg_l, _( "Left Leg" ), normal_bonus },
{ false, bp_leg_r, hp_leg_r, _( "Right Leg" ), normal_bonus },
{ false, bodypart_id( "head" ), hp_head, _( "Head" ), head_bonus },
{ false, bodypart_id( "torso" ), hp_torso, _( "Torso" ), torso_bonus },
{ false, bodypart_id( "arm_l" ), hp_arm_l, _( "Left Arm" ), normal_bonus },
{ false, bodypart_id( "arm_r" ), hp_arm_r, _( "Right Arm" ), normal_bonus },
{ false, bodypart_id( "leg_l" ), hp_leg_l, _( "Left Leg" ), normal_bonus },
{ false, bodypart_id( "leg_r" ), hp_leg_r, _( "Right Leg" ), normal_bonus },
}
};

@@ -5948,7 +5948,8 @@ hp_part Character::body_window( const std::string &menu_header,

for( size_t i = 0; i < parts.size(); i++ ) {
const auto &e = parts[i];
const body_part bp = e.bp;
const bodypart_id &bp = e.bp;
const body_part bp_token = bp->token;
const hp_part hp = e.hp;
const int maximal_hp = hp_max[hp];
const int current_hp = hp_cur[hp];
@@ -5960,7 +5961,7 @@ hp_part Character::body_window( const std::string &menu_header,
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 = is_limb_broken( hp );
const bool limb_is_mending = worn_with_flag( flag_SPLINT, bp );
const bool limb_is_mending = worn_with_flag( flag_SPLINT, bp_token );

if( show_all ) {
e.allowed = true;
@@ -5977,16 +5978,16 @@ hp_part Character::body_window( const std::string &menu_header,

std::string msg;
std::string desc;
bool bleeding = has_effect( effect_bleed, e.bp );
bool bitten = has_effect( effect_bite, e.bp );
bool infected = has_effect( effect_infected, e.bp );
bool bandaged = has_effect( effect_bandaged, e.bp );
bool disinfected = has_effect( effect_disinfected, e.bp );
const int b_power = get_effect_int( effect_bandaged, e.bp );
const int d_power = get_effect_int( effect_disinfected, e.bp );
bool bleeding = has_effect( effect_bleed, bp_token );
bool bitten = has_effect( effect_bite, bp_token );
bool infected = has_effect( effect_infected, bp_token );
bool bandaged = has_effect( effect_bandaged, bp_token );
bool disinfected = has_effect( effect_disinfected, bp_token );
const int b_power = get_effect_int( effect_bandaged, bp_token );
const int d_power = get_effect_int( effect_disinfected, bp_token );
int new_b_power = static_cast<int>( std::floor( bandage_power ) );
if( bandaged ) {
const effect &eff = get_effect( effect_bandaged, e.bp );
const effect &eff = get_effect( effect_bandaged, bp_token );
if( new_b_power > eff.get_max_intensity() ) {
new_b_power = eff.get_max_intensity();
}
@@ -5999,7 +6000,7 @@ hp_part Character::body_window( const std::string &menu_header,
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 auto &eff = get_effect( effect_mending, bp_token );
const int mend_perc = eff.is_null() ? 0.0 : 100 * eff.get_duration() / eff.get_max_duration();

if( precise ) {
@@ -6032,8 +6033,8 @@ hp_part Character::body_window( const std::string &menu_header,

// BLEEDING block
if( bleeding ) {
desc += colorize( string_format( "%s: %s", get_effect( effect_bleed, e.bp ).get_speed_name(),
get_effect( effect_bleed, e.bp ).disp_short_desc() ), c_red ) + "\n";
desc += colorize( string_format( "%s: %s", get_effect( effect_bleed, bp_token ).get_speed_name(),
get_effect( effect_bleed, bp_token ).disp_short_desc() ), c_red ) + "\n";
if( bleed > 0.0f ) {
desc += colorize( string_format( _( "Chance to stop: %d %%" ),
static_cast<int>( bleed * 100 ) ), c_light_green ) + "\n";
@@ -6058,7 +6059,7 @@ hp_part Character::body_window( const std::string &menu_header,
// BITTEN block
if( bitten ) {
desc += colorize( string_format( "%s: ", get_effect( effect_bite,
e.bp ).get_speed_name() ), c_red );
bp_token ).get_speed_name() ), c_red );
desc += colorize( _( "It has a deep bite wound that needs cleaning." ), c_red ) + "\n";
if( bite > 0 ) {
desc += colorize( string_format( _( "Chance to clean and disinfect: %d %%" ),
@@ -6070,7 +6071,7 @@ hp_part Character::body_window( const std::string &menu_header,
// INFECTED block
if( infected ) {
desc += colorize( string_format( "%s: ", get_effect( effect_infected,
e.bp ).get_speed_name() ), c_red );
bp_token ).get_speed_name() ), c_red );
desc += colorize( _( "It has a deep wound that looks infected. Antibiotics might be required." ),
c_red ) + "\n";
if( infect > 0 ) {
@@ -6126,21 +6127,21 @@ hp_part Character::body_window( const std::string &menu_header,
}
}

nc_color Character::limb_color( body_part bp, bool bleed, bool bite, bool infect ) const
nc_color Character::limb_color( const bodypart_id &bp, bool bleed, bool bite, bool infect ) const
{
if( bp == num_bp ) {
if( bp == bodypart_id( "num_bp" ) ) {
return c_light_gray;
}

const body_part bp_token = bp->token;
int color_bit = 0;
nc_color i_color = c_light_gray;
if( bleed && has_effect( effect_bleed, bp ) ) {
if( bleed && has_effect( effect_bleed, bp_token ) ) {
color_bit += 1;
}
if( bite && has_effect( effect_bite, bp ) ) {
if( bite && has_effect( effect_bite, bp_token ) ) {
color_bit += 10;
}
if( infect && has_effect( effect_infected, bp ) ) {
if( infect && has_effect( effect_infected, bp_token ) ) {
color_bit += 100;
}
switch( color_bit ) {
@@ -6714,7 +6715,7 @@ std::string Character::extended_description() const

const int maximal_hp = hp_max[hp];
const int current_hp = hp_cur[hp];
const nc_color state_col = limb_color( bp->token, true, true, true );
const nc_color state_col = limb_color( bp, true, true, true );
nc_color name_color = state_col;
auto hp_bar = get_hp_bar( current_hp, maximal_hp, false );

4 changes: 2 additions & 2 deletions src/character.h
Original file line number Diff line number Diff line change
@@ -731,7 +731,7 @@ class Character : public Creature, public visitable<Character>
/** Returns the armor bonus against given type from martial arts buffs */
int mabuff_armor_bonus( damage_type type ) const;
/** Returns overall fire resistance for the body part */
int get_armor_fire( body_part bp ) const;
int get_armor_fire( const bodypart_id &bp ) const;
// --------------- Mutation Stuff ---------------
// In newcharacter.cpp
/** Returns the id of a random starting trait that costs >= 0 points */
@@ -827,7 +827,7 @@ class Character : public Creature, public visitable<Character>
float bleed, float bite, float infect, float bandage_power, float disinfectant_power ) const;

// Returns color which this limb would have in healing menus
nc_color limb_color( body_part bp, bool bleed, bool bite, bool infect ) const;
nc_color limb_color( const bodypart_id &bp, bool bleed, bool bite, bool infect ) const;

static const std::vector<material_id> fleshy;
bool made_of( const material_id &m ) const override;
34 changes: 17 additions & 17 deletions src/panels.cpp
Original file line number Diff line number Diff line change
@@ -922,15 +922,15 @@ static void draw_limb_health( avatar &u, const catacurses::window &w, int limb_i

static void draw_limb2( avatar &u, const catacurses::window &w )
{
static std::array<body_part, 6> part = { {
bp_head, bp_torso, bp_arm_l, bp_arm_r, bp_leg_l, bp_leg_r
static std::array<bodypart_id, 6> part = { {
bodypart_id( "head" ), bodypart_id( "torso" ), bodypart_id( "arm_l" ), bodypart_id( "arm_r" ), bodypart_id( "leg_l" ), bodypart_id( "leg_r" )
}
};

werase( w );
// print limb health
for( int i = 0; i < num_hp_parts; i++ ) {
const std::string str = body_part_hp_bar_ui_text( part[i] );
const std::string str = body_part_hp_bar_ui_text( part[i]->token );
if( i % 2 == 0 ) {
wmove( w, point( 0, i / 2 ) );
} else {
@@ -1150,8 +1150,8 @@ static void draw_limb_narrow( avatar &u, const catacurses::window &w )
}

// display limbs status
static std::array<body_part, 6> part = { {
bp_head, bp_torso, bp_arm_l, bp_arm_r, bp_leg_l, bp_leg_r
static std::array<bodypart_id, 6> part = { {
bodypart_id( "head" ), bodypart_id( "torso" ), bodypart_id( "arm_l" ), bodypart_id( "arm_r" ), bodypart_id( "leg_l" ), bodypart_id( "leg_r" )
}
};
ny2 = 0;
@@ -1166,7 +1166,7 @@ static void draw_limb_narrow( avatar &u, const catacurses::window &w )
nx = 19;
}

std::string str = body_part_hp_bar_ui_text( part[i] );
std::string str = body_part_hp_bar_ui_text( part[i]->token );
wmove( w, point( nx, ny ) );
str = left_justify( str, 5 );
wprintz( w, u.limb_color( part[i], true, true, true ), str + ":" );
@@ -1176,21 +1176,21 @@ static void draw_limb_narrow( avatar &u, const catacurses::window &w )

static void draw_limb_wide( avatar &u, const catacurses::window &w )
{
const std::vector<std::pair<body_part, int>> parts = {
{bp_arm_l, 2},
{bp_head, 0},
{bp_arm_r, 3},
{bp_leg_l, 4},
{bp_torso, 1},
{bp_leg_r, 5}
const std::vector<std::pair<bodypart_id, int>> parts = {
{bodypart_id( "arm_l" ), 2},
{bodypart_id( "head" ), 0},
{bodypart_id( "arm_r" ), 3},
{bodypart_id( "leg_l" ), 4},
{bodypart_id( "torso" ), 1},
{bodypart_id( "leg_r" ), 5}
};
werase( w );
for( int i = 0; i < num_hp_parts; i++ ) {
int offset = i * 15;
int ny = offset / 45;
int nx = offset % 45;
std::string str = string_format( " %s: ",
left_justify( body_part_hp_bar_ui_text( parts[i].first ), 5 ) );
left_justify( body_part_hp_bar_ui_text( parts[i].first->token ), 5 ) );
nc_color part_color = u.limb_color( parts[i].first, true, true, true );
print_colored_text( w, point( nx, ny ), part_color, c_white, str );
draw_limb_health( u, w, parts[i].second );
@@ -1560,8 +1560,8 @@ static void draw_wind_padding( avatar &u, const catacurses::window &w )

static void draw_health_classic( avatar &u, const catacurses::window &w )
{
static std::array<body_part, 6> part = { {
bp_head, bp_torso, bp_arm_l, bp_arm_r, bp_leg_l, bp_leg_r
static std::array<bodypart_id, 6> part = { {
bodypart_id( "head" ), bodypart_id( "torso" ), bodypart_id( "arm_l" ), bodypart_id( "arm_r" ), bodypart_id( "leg_l" ), bodypart_id( "leg_r" )
}
};

@@ -1577,7 +1577,7 @@ static void draw_health_classic( avatar &u, const catacurses::window &w )

// print limb health
for( int i = 0; i < num_hp_parts; i++ ) {
const std::string str = body_part_hp_bar_ui_text( part[i] );
const std::string str = body_part_hp_bar_ui_text( part[i]->token );
wmove( w, point( 8, i ) );
wprintz( w, u.limb_color( part[i], true, true, true ), str );
wmove( w, point( 14, i ) );