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

refactor: Remove usage of hp_part from bandaging and disinfection #5647

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@
int level_cap = std::min<int>( MAX_SKILL,
( static_cast<int>( corpse->size ) + ( cbms.size() * 2 + 1 ) ) );
int size_mult = corpse->size > creature_size::medium ? ( corpse->size * corpse->size ) : 8;
int practice_amt = ( size_mult + 1 ) * ( ( time_to_cut / 150 ) + 1 ) *

Check warning on line 1300 in src/activity_handlers.cpp

View workflow job for this annotation

GitHub Actions / build

performing an implicit widening conversion to type 'size_type' (aka 'unsigned long') of a multiplication performed in type 'int' [bugprone-implicit-widening-of-multiplication-result]
( cbms.size() * cbms.size() / 2 + 1 );
p->practice( skill_firstaid, practice_amt, level_cap );
add_msg( m_debug, "Experience: %d, Level cap: %d, Time to cut: %d", practice_amt, level_cap,
Expand Down Expand Up @@ -1640,7 +1640,7 @@

// 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 @@
// 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 @@ -709,7 +706,7 @@

for( const auto &blast_part : blast_parts ) {
const int part_dam = rng( blast_damage * blast_part.low_mul, blast_damage * blast_part.high_mul );
const std::string hit_part_name = body_part_name_accusative( blast_part.bp->token );

Check warning on line 709 in src/explosion.cpp

View workflow job for this annotation

GitHub Actions / build

unused local variable 'hit_part_name' of type 'const std::string' (aka 'const basic_string<char>') [bugprone-unused-local-non-trivial-variable]
const auto dmg_instance = damage_instance( DT_BASH, part_dam, 0, blast_part.armor_mul );
const auto result = player_ptr->deal_damage( emitter.value_or( nullptr ), blast_part.bp,
dmg_instance );
Expand Down Expand Up @@ -1121,10 +1118,6 @@
// 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 Expand Up @@ -1165,7 +1158,7 @@
blast_center + tripoint( raw_blast_radius, raw_blast_radius, z_levels_affected )
);

static std::vector<dist_point_pair> blast_map( MAPSIZE_X * MAPSIZE_Y );

Check warning on line 1161 in src/explosion.cpp

View workflow job for this annotation

GitHub Actions / build

performing an implicit widening conversion to type 'size_type' (aka 'unsigned long') of a multiplication performed in type 'int' [bugprone-implicit-widening-of-multiplication-result]
static std::map<tripoint, nc_color> explosion_colors;
blast_map.clear();
explosion_colors.clear();
Expand Down
6 changes: 3 additions & 3 deletions src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4242,7 +4242,7 @@
int distance = INT_MAX;
gas_units = 0;

for( const tripoint &tmp : here.points_in_radius( center, SEEX * 2 ) ) {

Check warning on line 4245 in src/iexamine.cpp

View workflow job for this annotation

GitHub Actions / build

performing an implicit widening conversion to type 'size_t' (aka 'unsigned long') of a multiplication performed in type 'int' [bugprone-implicit-widening-of-multiplication-result]
if( here.ter( tmp ) != ter_str_id( "t_gas_tank" ) ) {
continue;
}
Expand Down Expand Up @@ -5250,9 +5250,9 @@
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
Loading