Skip to content

Commit

Permalink
refactor: Remove usage of hp_part from bandaging and disinfection (#5647
Browse files Browse the repository at this point in the history
)

* Remove usage of hp_part from bandaging and disinfection

* Remove debugmsg after debugging the thing
  • Loading branch information
Coolthulhu authored Nov 4, 2024
1 parent b623176 commit 37a1f76
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 156 deletions.
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ void activity_handlers::firstaid_finish( player_activity *act, player *p )

// TODO: Store the patient somehow, retrieve here
player &patient = *p;
const hp_part healed = static_cast<hp_part>( act->values[0] );
const bodypart_str_id healed = bodypart_str_id( act->str_values[0] );
const int charges_consumed = actor->finish_using( *p, patient, *used_tool, healed );
p->consume_charges( it, charges_consumed );

Expand Down
1 change: 0 additions & 1 deletion src/bodypart.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ class bodypart
int hp_max;

int healed_total = 0;
/** Not used yet*/
int damage_bandaged = 0;
int damage_disinfected = 0;

Expand Down
76 changes: 26 additions & 50 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,6 @@ Character &get_player_character()
Character::Character() :
location_visitable<Character>(),
worn(new worn_item_location(this)),
damage_bandaged( {{ 0 }} ),
damage_disinfected( {{ 0 }} ),
cached_time( calendar::before_time_starts ),
inv(new character_item_location(this)),
id( -1 ),
Expand Down Expand Up @@ -497,7 +495,6 @@ void Character::move_operator_common( Character &&source ) noexcept
male = source.male ;

worn = std::move( source.worn );
damage_disinfected = source.damage_disinfected ;
in_vehicle = source.in_vehicle ;
hauling = source.hauling ;

Expand Down Expand Up @@ -4966,31 +4963,32 @@ void Character::regen( int rate_multiplier )
healed_bp( i, healing_apply );
heal( bp, healing_apply );

if( damage_bandaged[i] > 0 ) {
damage_bandaged[i] -= healing_apply;
if( damage_bandaged[i] <= 0 ) {
damage_bandaged[i] = 0;
bodypart &part = get_part( bp );
if( part.get_damage_bandaged() > 0 ) {
part.set_damage_bandaged( part.get_damage_bandaged() - healing_apply );
if( part.get_damage_bandaged() <= 0 ) {
part.set_damage_bandaged( 0 );
remove_effect( effect_bandaged, bp.id() );
add_msg_if_player( _( "Bandaged wounds on your %s healed." ), body_part_name( bp ) );
}
}
if( damage_disinfected[i] > 0 ) {
damage_disinfected[i] -= healing_apply;
if( damage_disinfected[i] <= 0 ) {
damage_disinfected[i] = 0;
if( part.get_damage_disinfected() > 0 ) {
part.set_damage_disinfected( part.get_damage_disinfected() - healing_apply );
if( part.get_damage_disinfected() <= 0 ) {
part.set_damage_disinfected( 0 );
remove_effect( effect_disinfected, bp.id() );
add_msg_if_player( _( "Disinfected wounds on your %s healed." ), body_part_name( bp ) );
}
}

// remove effects if the limb was healed by other way
if( has_effect( effect_bandaged, bp.id() ) && ( get_part( bp ).is_at_max_hp() ) ) {
damage_bandaged[i] = 0;
part.set_damage_bandaged( 0 );
remove_effect( effect_bandaged, bp.id() );
add_msg_if_player( _( "Bandaged wounds on your %s healed." ), body_part_name( bp ) );
}
if( has_effect( effect_disinfected, bp.id() ) && ( get_part( bp ).is_at_max_hp() ) ) {
damage_disinfected[i] = 0;
part.set_damage_disinfected( 0 );
remove_effect( effect_disinfected, bp.id() );
add_msg_if_player( _( "Disinfected wounds on your %s healed." ), body_part_name( bp ) );
}
Expand Down Expand Up @@ -6112,30 +6110,29 @@ float Character::get_hit_base() const
return get_dex() / 4.0f;
}

hp_part Character::body_window( const std::string &menu_header,
bool show_all, bool precise,
int normal_bonus, int head_bonus, int torso_bonus,
float bleed, float bite, float infect, float bandage_power, float disinfectant_power ) const
bodypart_str_id Character::body_window( const std::string &menu_header,
bool show_all, bool precise,
int normal_bonus, int head_bonus, int torso_bonus,
float bleed, float bite, float infect, float bandage_power, float disinfectant_power ) const
{
/* This struct establishes some kind of connection between the hp_part (which can be healed and
* have HP) and the body_part. Note that there are more body_parts than hp_parts. For example:
* Damage to bp_head, bp_eyes and bp_mouth is all applied on the HP of hp_head. */
struct healable_bp {
mutable bool allowed;
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, 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 },
{ false, bodypart_id( "head" ), _( "Head" ), head_bonus },
{ false, bodypart_id( "torso" ), _( "Torso" ), torso_bonus },
{ false, bodypart_id( "arm_l" ), _( "Left Arm" ), normal_bonus },
{ false, bodypart_id( "arm_r" ), _( "Right Arm" ), normal_bonus },
{ false, bodypart_id( "leg_l" ), _( "Left Leg" ), normal_bonus },
{ false, bodypart_id( "leg_r" ), _( "Right Leg" ), normal_bonus },
}
};

Expand Down Expand Up @@ -6312,9 +6309,9 @@ hp_part Character::body_window( const std::string &menu_header,
bmenu.query();
if( bmenu.ret >= 0 && static_cast<size_t>( bmenu.ret ) < parts.size() &&
parts[bmenu.ret].allowed ) {
return parts[bmenu.ret].hp;
return parts[bmenu.ret].bp.id();
} else {
return num_hp_parts;
return bodypart_str_id::NULL_ID();
}
}

Expand Down Expand Up @@ -6815,30 +6812,9 @@ float Character::rest_quality() const
return has_effect( effect_sleep ) ? 1.0f : 0.0f;
}

hp_part Character::bp_to_hp( const bodypart_str_id &bp )
{
switch( bp->token ) {
case bp_head:
case bp_eyes:
case bp_mouth:
return hp_head;
case bp_torso:
return hp_torso;
case bp_arm_l:
case bp_hand_l:
return hp_arm_l;
case bp_arm_r:
case bp_hand_r:
return hp_arm_r;
case bp_leg_l:
case bp_foot_l:
return hp_leg_l;
case bp_leg_r:
case bp_foot_r:
return hp_leg_r;
default:
return num_hp_parts;
}
bodypart_str_id Character::bp_to_hp( const bodypart_str_id &bp )
{
return bp->main_part;
}

const bodypart_str_id &Character::hp_to_bp( const hp_part hpart )
Expand Down
11 changes: 5 additions & 6 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ class Character : public Creature, public location_visitable<Character>
void mutation_spend_resources( const trait_id &mut );

/** Converts a bodypart_str_id to an hp_part */
static hp_part bp_to_hp( const bodypart_str_id &bp );
static bodypart_str_id bp_to_hp( const bodypart_str_id &bp );
/** Converts an hp_part to a bodypart_str_id */
static const bodypart_str_id &hp_to_bp( hp_part hpart );

Expand Down Expand Up @@ -793,10 +793,10 @@ class Character : public Creature, public location_visitable<Character>
* bandage_power - quality of bandage
* disinfectant_power - quality of disinfectant
*/
hp_part body_window( const std::string &menu_header,
bool show_all, bool precise,
int normal_bonus, int head_bonus, int torso_bonus,
float bleed, float bite, float infect, float bandage_power, float disinfectant_power ) const;
bodypart_str_id body_window( const std::string &menu_header,
bool show_all, bool precise,
int normal_bonus, int head_bonus, int torso_bonus,
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( const bodypart_id &bp, bool bleed, bool bite, bool infect ) const;
Expand Down Expand Up @@ -1629,7 +1629,6 @@ class Character : public Creature, public location_visitable<Character>
bool male = true;

location_vector<item> worn;
std::array<int, num_hp_parts> damage_bandaged, damage_disinfected;
// Means player sit inside vehicle on the tile he is now
bool in_vehicle = false;
bool hauling = false;
Expand Down
7 changes: 0 additions & 7 deletions src/explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,6 @@ void ExplosionProcess::project_shrapnel( const tripoint position )
// Humans get hit in all body parts
if( critter->is_player() ) {
for( bodypart_id bp : bps ) {
if( Character::bp_to_hp( bp.id() ) == num_hp_parts ) {
continue;
}
// TODO: Apply projectile effects
// TODO: Penalize low coverage armor
// Halve damage to be closer to what monsters take
Expand Down Expand Up @@ -1121,10 +1118,6 @@ static std::map<const Creature *, int> legacy_shrapnel( const tripoint &src,
// Humans get hit in all body parts
if( critter->is_player() ) {
for( bodypart_id bp : bps ) {
// TODO: This shouldn't be needed, get_bps should do it
if( Character::bp_to_hp( bp.id() ) == num_hp_parts ) {
continue;
}
// TODO: Apply projectile effects
// TODO: Penalize low coverage armor
// Halve damage to be closer to what monsters take
Expand Down
6 changes: 3 additions & 3 deletions src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5250,9 +5250,9 @@ void iexamine::autodoc( player &p, const tripoint &examp )
patient.add_effect( effect_disinfected, 1_turns, bp_healed );
effect &e = patient.get_effect( effect_disinfected, bp_healed );
e.set_duration( e.get_int_dur_factor() * disinfectant_intensity );
hp_part target_part = player::bp_to_hp( bp_healed );
patient.damage_disinfected[target_part] =
patient.get_part_hp_max( bp_healed ) - patient.get_part_hp_cur( bp_healed );
bodypart_str_id target_part = player::bp_to_hp( bp_healed );
bodypart &part = patient.get_part( target_part );
part.set_damage_disinfected( part.get_hp_max() - part.get_hp_cur() );

}
}
Expand Down
Loading

0 comments on commit 37a1f76

Please sign in to comment.