From 24088ae3c38e8b458f8941249fca48033994a102 Mon Sep 17 00:00:00 2001 From: Fris0uman <41293484+Fris0uman@users.noreply.github.com> Date: Mon, 27 Apr 2020 00:20:18 +0200 Subject: [PATCH] Change body_part to bodypart_id in deal_damage (#39890) * Change body_part to bodypart_id in deal_damage * missing bp_token --- src/character.cpp | 96 +++++++--------- src/character.h | 2 +- src/creature.cpp | 22 ++-- src/creature.h | 2 +- src/explosion.cpp | 16 +-- src/game.cpp | 36 +++--- src/handle_action.cpp | 4 +- src/iuse.cpp | 4 +- src/map.cpp | 44 ++++---- src/map_field.cpp | 44 ++++---- src/mattack_actors.cpp | 2 +- src/melee.cpp | 12 +- src/monattack.cpp | 138 ++++++++++++----------- src/mondefense.cpp | 7 +- src/monmove.cpp | 2 +- src/player.cpp | 14 +-- src/player_hardcoded_effects.cpp | 3 +- src/trapfunc.cpp | 185 ++++++++++++++++--------------- 18 files changed, 318 insertions(+), 315 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index b98b23a4b3927..6bf4b0cfa7268 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -1157,39 +1157,39 @@ void Character::forced_dismount() } const int dodge = get_dodge(); const int damage = std::max( 0, rng( 1, 20 ) - rng( dodge, dodge * 2 ) ); - body_part hit = num_bp; + bodypart_id hit( "num_bp" ); switch( rng( 1, 10 ) ) { case 1: if( one_in( 2 ) ) { - hit = bp_foot_l; + hit = bodypart_id( "foot_l" ); } else { - hit = bp_foot_r; + hit = bodypart_id( "foot_r" ); } break; case 2: case 3: case 4: if( one_in( 2 ) ) { - hit = bp_leg_l; + hit = bodypart_id( "leg_l" ); } else { - hit = bp_leg_r; + hit = bodypart_id( "leg_r" ); } break; case 5: case 6: case 7: if( one_in( 2 ) ) { - hit = bp_arm_l; + hit = bodypart_id( "arm_l" ); } else { - hit = bp_arm_r; + hit = bodypart_id( "arm_r" ); } break; case 8: case 9: - hit = bp_torso; + hit = bodypart_id( "torso" ); break; case 10: - hit = bp_head; + hit = bodypart_id( "head" ); break; } if( damage > 0 ) { @@ -8398,7 +8398,7 @@ void Character::apply_damage( Creature *source, bodypart_id hurt, int dam, const } } -dealt_damage_instance Character::deal_damage( Creature *source, body_part bp, +dealt_damage_instance Character::deal_damage( Creature *source, bodypart_id bp, const damage_instance &d ) { if( has_trait( trait_DEBUG_NODMG ) ) { @@ -8410,6 +8410,8 @@ dealt_damage_instance Character::deal_damage( Creature *source, body_part bp, //block reduction should be by applied this point int dam = dealt_dams.total_damage(); + const body_part bp_token = bp->token; + // TODO: Pre or post blit hit tile onto "this"'s location here if( dam > 0 && g->u.sees( pos() ) ) { g->draw_hit_player( *this, dam ); @@ -8418,8 +8420,8 @@ dealt_damage_instance Character::deal_damage( Creature *source, body_part bp, //monster hits player melee SCT.add( point( posx(), posy() ), direction_from( point_zero, point( posx() - source->posx(), posy() - source->posy() ) ), - get_hp_bar( dam, get_hp_max( player::bp_to_hp( bp ) ) ).first, m_bad, - body_part_name( bp ), m_neutral ); + get_hp_bar( dam, get_hp_max( player::bp_to_hp( bp_token ) ) ).first, m_bad, + body_part_name( bp_token ), m_neutral ); } } @@ -8463,51 +8465,31 @@ dealt_damage_instance Character::deal_damage( Creature *source, body_part bp, damage_instance acidblood_damage; acidblood_damage.add_damage( DT_ACID, rng( 4, 16 ) ); if( !one_in( 4 ) ) { - source->deal_damage( this, bp_arm_l, acidblood_damage ); - source->deal_damage( this, bp_arm_r, acidblood_damage ); + source->deal_damage( this, bodypart_id( "arm_l" ), acidblood_damage ); + source->deal_damage( this, bodypart_id( "arm_r" ), acidblood_damage ); } else { - source->deal_damage( this, bp_torso, acidblood_damage ); - source->deal_damage( this, bp_head, acidblood_damage ); + source->deal_damage( this, bodypart_id( "torso" ), acidblood_damage ); + source->deal_damage( this, bodypart_id( "head" ), acidblood_damage ); } } int recoil_mul = 100; - switch( bp ) { - case bp_eyes: - if( dam > 5 || cut_dam > 0 ) { - const time_duration minblind = std::max( 1_turns, 1_turns * ( dam + cut_dam ) / 10 ); - const time_duration maxblind = std::min( 5_turns, 1_turns * ( dam + cut_dam ) / 4 ); - add_effect( effect_blind, rng( minblind, maxblind ) ); - } - break; - case bp_torso: - break; - case bp_hand_l: - // Fall through to arms - case bp_arm_l: - // Hit to arms/hands are really bad to our aim - case bp_hand_r: - // Fall through to arms - case bp_arm_r: - recoil_mul = 200; - break; - case bp_foot_l: - // Fall through to legs - case bp_leg_l: - break; - case bp_foot_r: - // Fall through to legs - case bp_leg_r: - break; - case bp_mouth: - // Fall through to head damage - case bp_head: - // TODO: Some daze maybe? Move drain? - break; - default: - debugmsg( "Wacky body part hit!" ); + + if( bp == bodypart_id( "eyes" ) ) { + if( dam > 5 || cut_dam > 0 ) { + const time_duration minblind = std::max( 1_turns, 1_turns * ( dam + cut_dam ) / 10 ); + const time_duration maxblind = std::min( 5_turns, 1_turns * ( dam + cut_dam ) / 4 ); + add_effect( effect_blind, rng( minblind, maxblind ) ); + } + } else if( bp == bodypart_id( "hand_l" ) || bp == bodypart_id( "arm_l" ) || + bp == bodypart_id( "hand_r" ) || bp == bodypart_id( "arm_r" ) ) { + recoil_mul = 200; + } else if( bp == bodypart_id( "num_bp" ) ) { + debugmsg( "Wacky body part hit!" ); } + + // TODO: Scale with damage in a way that makes sense for power armors, plate armor and naked skin. recoil += recoil_mul * weapon.volume() / 250_ml; recoil = std::min( MAX_RECOIL, recoil ); @@ -8541,7 +8523,7 @@ dealt_damage_instance Character::deal_damage( Creature *source, body_part bp, if( get_option( "FILTHY_WOUNDS" ) ) { int sum_cover = 0; for( const item &i : worn ) { - if( i.covers( bp ) && i.is_filthy() ) { + if( i.covers( bp_token ) && i.is_filthy() ) { sum_cover += i.get_coverage(); } } @@ -8554,12 +8536,12 @@ dealt_damage_instance Character::deal_damage( Creature *source, body_part bp, const int combined_dam = dealt_dams.type_damage( DT_BASH ) + ( cut_type_dam * 4 ); const int infection_chance = ( combined_dam * sum_cover ) / 100; if( x_in_y( infection_chance, 100 ) ) { - if( has_effect( effect_bite, bp ) ) { - add_effect( effect_bite, 40_minutes, bp, true ); - } else if( has_effect( effect_infected, bp ) ) { - add_effect( effect_infected, 25_minutes, bp, true ); + if( has_effect( effect_bite, bp_token ) ) { + add_effect( effect_bite, 40_minutes, bp_token, true ); + } else if( has_effect( effect_infected, bp_token ) ) { + add_effect( effect_infected, 25_minutes, bp_token, true ); } else { - add_effect( effect_bite, 1_turns, bp, true ); + add_effect( effect_bite, 1_turns, bp_token, true ); } add_msg_if_player( _( "Filth from your clothing has implanted deep in the wound." ) ); } @@ -8681,7 +8663,7 @@ int Character::hitall( int dam, int vary, Creature *source ) { int damage_taken = 0; for( int i = 0; i < num_hp_parts; i++ ) { - const body_part bp = hp_to_bp( static_cast( i ) ); + const bodypart_id bp = convert_bp( hp_to_bp( static_cast( i ) ) ).id(); int ddam = vary ? dam * rng( 100 - vary, 100 ) / 100 : dam; int cut = 0; auto damage = damage_instance::physical( ddam, cut, 0 ); diff --git a/src/character.h b/src/character.h index fa9a532ec4a18..db4ee113ee036 100644 --- a/src/character.h +++ b/src/character.h @@ -701,7 +701,7 @@ class Character : public Creature, public visitable void apply_damage( Creature *source, bodypart_id hurt, int dam, bool bypass_med = false ) override; /** Calls Creature::deal_damage and handles damaged effects (waking up, etc.) */ - dealt_damage_instance deal_damage( Creature *source, body_part bp, + dealt_damage_instance deal_damage( Creature *source, bodypart_id bp, const damage_instance &d ) override; /** Reduce healing effect intensity, return initial intensity of the effect */ int reduce_healing_effect( const efftype_id &eff_id, int remove_med, body_part hurt ); diff --git a/src/creature.cpp b/src/creature.cpp index 4cafc2bb02f5b..dcc29fb5133d8 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -509,8 +509,9 @@ void Creature::deal_melee_hit( Creature *source, int hit_spread, bool critical_h } } damage_instance d = dam; // copy, since we will mutate in block_hit - body_part bp_hit = select_body_part( source, hit_spread ); - block_hit( source, bp_hit, d ); + const bodypart_id bp_hit = convert_bp( select_body_part( source, hit_spread ) ).id(); + body_part bp_token = bp_hit->token; + block_hit( source, bp_token, d ); // Bashing critical if( critical_hit && !is_immune_effect( effect_stunned ) ) { @@ -540,9 +541,9 @@ void Creature::deal_melee_hit( Creature *source, int hit_spread, bool critical_h mod_moves( -stab_moves ); } - on_hit( source, bp_hit ); // trigger on-gethit events + on_hit( source, bp_token ); // trigger on-gethit events dealt_dam = deal_damage( source, bp_hit, d ); - dealt_dam.bp_hit = bp_hit; + dealt_dam.bp_hit = bp_token; } /** @@ -686,7 +687,8 @@ void Creature::deal_projectile_attack( Creature *source, dealt_projectile_attack } } - dealt_dam = deal_damage( source, bp_hit, impact ); + const bodypart_id bp_hit_id = convert_bp( bp_hit ).id(); + dealt_dam = deal_damage( source, bp_hit_id, impact ); dealt_dam.bp_hit = bp_hit; // Apply ammo effects to target. @@ -817,7 +819,7 @@ void Creature::deal_projectile_attack( Creature *source, dealt_projectile_attack attack.missed_by = goodhit; } -dealt_damage_instance Creature::deal_damage( Creature *source, body_part bp, +dealt_damage_instance Creature::deal_damage( Creature *source, bodypart_id bp, const damage_instance &dam ) { if( is_dead_state() ) { @@ -828,13 +830,13 @@ dealt_damage_instance Creature::deal_damage( Creature *source, body_part bp, damage_instance d = dam; // copy, since we will mutate in absorb_hit dealt_damage_instance dealt_dams; - - absorb_hit( bp, d ); + const body_part bp_token = bp->token; + absorb_hit( bp_token, d ); // Add up all the damage units dealt for( const auto &it : d.damage_units ) { int cur_damage = 0; - deal_damage_handle_type( it, bp, cur_damage, total_pain ); + deal_damage_handle_type( it, bp_token, cur_damage, total_pain ); if( cur_damage > 0 ) { dealt_dams.dealt_dams[ it.type ] += cur_damage; total_damage += cur_damage; @@ -843,7 +845,7 @@ dealt_damage_instance Creature::deal_damage( Creature *source, body_part bp, mod_pain( total_pain ); - apply_damage( source, convert_bp( bp ).id(), total_damage ); + apply_damage( source, bp, total_damage ); return dealt_dams; } void Creature::deal_damage_handle_type( const damage_unit &du, body_part bp, int &damage, diff --git a/src/creature.h b/src/creature.h index 382286652c4c5..6830f5cefdfda 100644 --- a/src/creature.h +++ b/src/creature.h @@ -254,7 +254,7 @@ class Creature * @param bp The attacked body part * @param dam The damage dealt */ - virtual dealt_damage_instance deal_damage( Creature *source, body_part bp, + virtual dealt_damage_instance deal_damage( Creature *source, bodypart_id bp, const damage_instance &dam ); // for each damage type, how much gets through and how much pain do we // accrue? mutates damage and pain diff --git a/src/explosion.cpp b/src/explosion.cpp index 83e539086b976..3d4e0af5ac2ae 100644 --- a/src/explosion.cpp +++ b/src/explosion.cpp @@ -320,26 +320,26 @@ static void do_blast( const tripoint &p, const float power, _( " is caught in the explosion!" ) ); struct blastable_part { - body_part bp; + bodypart_id bp; float low_mul; float high_mul; float armor_mul; }; static const std::array blast_parts = { { - { bp_torso, 2.0f, 3.0f, 0.5f }, - { bp_head, 2.0f, 3.0f, 0.5f }, + { bodypart_id( "torso" ), 2.0f, 3.0f, 0.5f }, + { bodypart_id( "head" ), 2.0f, 3.0f, 0.5f }, // Hit limbs harder so that it hurts more without being much more deadly - { bp_leg_l, 2.0f, 3.5f, 0.4f }, - { bp_leg_r, 2.0f, 3.5f, 0.4f }, - { bp_arm_l, 2.0f, 3.5f, 0.4f }, - { bp_arm_r, 2.0f, 3.5f, 0.4f }, + { bodypart_id( "leg_l" ), 2.0f, 3.5f, 0.4f }, + { bodypart_id( "leg_r" ), 2.0f, 3.5f, 0.4f }, + { bodypart_id( "arm_l" ), 2.0f, 3.5f, 0.4f }, + { bodypart_id( "arm_r" ), 2.0f, 3.5f, 0.4f }, } }; for( const auto &blp : blast_parts ) { const int part_dam = rng( force * blp.low_mul, force * blp.high_mul ); - const std::string hit_part_name = body_part_name_accusative( blp.bp ); + const std::string hit_part_name = body_part_name_accusative( blp.bp->token ); const auto dmg_instance = damage_instance( DT_BASH, part_dam, 0, blp.armor_mul ); const auto result = pl->deal_damage( nullptr, blp.bp, dmg_instance ); const int res_dmg = result.total_damage(); diff --git a/src/game.cpp b/src/game.cpp index 5325f8f36ec74..eefcdebc56d94 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -4496,15 +4496,15 @@ void game::knockback( std::vector &traj, int stun, int dam_mult ) add_msg( _( "%s was stunned!" ), targ->name ); } - std::array bps = {{ - bp_head, - bp_arm_l, bp_arm_r, - bp_hand_l, bp_hand_r, - bp_torso, - bp_leg_l, bp_leg_r + std::array bps = {{ + bodypart_id( "head" ), + bodypart_id( "arm_l" ), bodypart_id( "arm_r" ), + bodypart_id( "hand_l" ), bodypart_id( "hand_r" ), + bodypart_id( "torso" ), + bodypart_id( "leg_l" ), bodypart_id( "leg_r" ) } }; - for( auto &bp : bps ) { + for( const bodypart_id &bp : bps ) { if( one_in( 2 ) ) { targ->deal_damage( nullptr, bp, damage_instance( DT_BASH, force_remaining * dam_mult ) ); } @@ -4570,15 +4570,15 @@ void game::knockback( std::vector &traj, int stun, int dam_mult ) force_remaining ); } u.add_effect( effect_stunned, 1_turns * force_remaining ); - std::array bps = {{ - bp_head, - bp_arm_l, bp_arm_r, - bp_hand_l, bp_hand_r, - bp_torso, - bp_leg_l, bp_leg_r + std::array bps = {{ + bodypart_id( "head" ), + bodypart_id( "arm_l" ), bodypart_id( "arm_r" ), + bodypart_id( "hand_l" ), bodypart_id( "hand_r" ), + bodypart_id( "torso" ), + bodypart_id( "leg_l" ), bodypart_id( "leg_r" ) } }; - for( auto &bp : bps ) { + for( const bodypart_id &bp : bps ) { if( one_in( 2 ) ) { u.deal_damage( nullptr, bp, damage_instance( DT_BASH, force_remaining * dam_mult ) ); } @@ -9264,13 +9264,13 @@ point game::place_player( const tripoint &dest_loc ) add_msg( m_bad, _( "You hurt your left foot on the %s!" ), m.has_flag_ter( "ROUGH", dest_loc ) ? m.tername( dest_loc ) : m.furnname( dest_loc ) ); - u.deal_damage( nullptr, bp_foot_l, damage_instance( DT_CUT, 1 ) ); + u.deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, 1 ) ); } if( one_in( 5 ) && u.get_armor_bash( bp_foot_r ) < rng( 2, 5 ) ) { add_msg( m_bad, _( "You hurt your right foot on the %s!" ), m.has_flag_ter( "ROUGH", dest_loc ) ? m.tername( dest_loc ) : m.furnname( dest_loc ) ); - u.deal_damage( nullptr, bp_foot_l, damage_instance( DT_CUT, 1 ) ); + u.deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, 1 ) ); } } ///\EFFECT_DEX increases chance of avoiding cuts on sharp terrain @@ -9281,11 +9281,11 @@ point game::place_player( const tripoint &dest_loc ) add_msg( _( "Your %s gets cut!" ), u.mounted_creature->get_name() ); u.mounted_creature->apply_damage( nullptr, bodypart_id( "torso" ), rng( 1, 10 ) ); } else { - body_part bp = random_body_part(); + const bodypart_id bp = u.get_random_body_part(); if( u.deal_damage( nullptr, bp, damage_instance( DT_CUT, rng( 1, 10 ) ) ).total_damage() > 0 ) { //~ 1$s - bodypart name in accusative, 2$s is terrain name. add_msg( m_bad, _( "You cut your %1$s on the %2$s!" ), - body_part_name_accusative( bp ), + body_part_name_accusative( bp->token ), m.has_flag_ter( "SHARP", dest_loc ) ? m.tername( dest_loc ) : m.furnname( dest_loc ) ); if( ( u.has_trait( trait_INFRESIST ) ) && ( one_in( 1024 ) ) ) { diff --git a/src/handle_action.cpp b/src/handle_action.cpp index 50ed993b408b3..68e9919cb3fb0 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -801,10 +801,10 @@ static void smash() add_msg( m_bad, _( "Your %s shatters!" ), u.weapon.tname() ); u.weapon.spill_contents( u.pos() ); sounds::sound( u.pos(), 24, sounds::sound_t::combat, "CRACK!", true, "smash", "glass" ); - u.deal_damage( nullptr, bp_hand_r, damage_instance( DT_CUT, rng( 0, vol ) ) ); + u.deal_damage( nullptr, bodypart_id( "hand_r" ), damage_instance( DT_CUT, rng( 0, vol ) ) ); if( vol > 20 ) { // Hurt left arm too, if it was big - u.deal_damage( nullptr, bp_hand_l, damage_instance( DT_CUT, rng( 0, + u.deal_damage( nullptr, bodypart_id( "hand_l" ), damage_instance( DT_CUT, rng( 0, static_cast( vol * .5 ) ) ) ); } u.remove_weapon(); diff --git a/src/iuse.cpp b/src/iuse.cpp index d9d24dc24c14e..8f3dc24634b58 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -1587,7 +1587,7 @@ static int petfood( player &p, item &it, Petfood animal_food_type ) switch( animal_food_type ) { case DOGFOOD: if( mon.type->id == mon_dog_thing ) { - p.deal_damage( &mon, bp_hand_r, damage_instance( DT_CUT, rng( 1, 10 ) ) ); + p.deal_damage( &mon, bodypart_id( "hand_r" ), damage_instance( DT_CUT, rng( 1, 10 ) ) ); p.add_msg_if_player( m_bad, _( "You want to feed it the dog food, but it bites your fingers!" ) ); if( one_in( 5 ) ) { p.add_msg_if_player( @@ -4010,7 +4010,7 @@ int iuse::tazer( player *p, item *it, bool, const tripoint &pos ) } else { // TODO: Maybe - Execute an attack and maybe zap something other than torso // Maybe, because it's torso (heart) that fails when zapped with electricity - int dam = target->deal_damage( p, bp_torso, damage_instance( DT_ELECTRIC, rng( 5, + int dam = target->deal_damage( p, bodypart_id( "torso" ), damage_instance( DT_ELECTRIC, rng( 5, 25 ) ) ).total_damage(); if( dam > 0 ) { p->add_msg_player_or_npc( m_good, diff --git a/src/map.cpp b/src/map.cpp index aaf2214840214..9a3427a17dbd8 100755 --- a/src/map.cpp +++ b/src/map.cpp @@ -2035,12 +2035,18 @@ void map::drop_furniture( const tripoint &p ) player *pl = dynamic_cast( critter ); monster *mon = dynamic_cast( critter ); if( pl != nullptr ) { - pl->deal_damage( nullptr, bp_torso, damage_instance( DT_BASH, rng( dmg / 3, dmg ), 0, 0.5f ) ); - pl->deal_damage( nullptr, bp_head, damage_instance( DT_BASH, rng( dmg / 3, dmg ), 0, 0.5f ) ); - pl->deal_damage( nullptr, bp_leg_l, damage_instance( DT_BASH, rng( dmg / 2, dmg ), 0, 0.4f ) ); - pl->deal_damage( nullptr, bp_leg_r, damage_instance( DT_BASH, rng( dmg / 2, dmg ), 0, 0.4f ) ); - pl->deal_damage( nullptr, bp_arm_l, damage_instance( DT_BASH, rng( dmg / 2, dmg ), 0, 0.4f ) ); - pl->deal_damage( nullptr, bp_arm_r, damage_instance( DT_BASH, rng( dmg / 2, dmg ), 0, 0.4f ) ); + pl->deal_damage( nullptr, bodypart_id( "torso" ), damage_instance( DT_BASH, rng( dmg / 3, dmg ), 0, + 0.5f ) ); + pl->deal_damage( nullptr, bodypart_id( "head" ), damage_instance( DT_BASH, rng( dmg / 3, dmg ), 0, + 0.5f ) ); + pl->deal_damage( nullptr, bodypart_id( "leg_l" ), damage_instance( DT_BASH, rng( dmg / 2, dmg ), 0, + 0.4f ) ); + pl->deal_damage( nullptr, bodypart_id( "leg_r" ), damage_instance( DT_BASH, rng( dmg / 2, dmg ), 0, + 0.4f ) ); + pl->deal_damage( nullptr, bodypart_id( "arm_l" ), damage_instance( DT_BASH, rng( dmg / 2, dmg ), 0, + 0.4f ) ); + pl->deal_damage( nullptr, bodypart_id( "arm_r" ), damage_instance( DT_BASH, rng( dmg / 2, dmg ), 0, + 0.4f ) ); } else if( mon != nullptr ) { // TODO: Monster's armor and size - don't crush hulks with chairs mon->apply_damage( nullptr, bodypart_id( "torso" ), rng( dmg, dmg * 2 ) ); @@ -3383,20 +3389,20 @@ void map::crush( const tripoint &p ) // TODO: Make this depend on the ceiling material const int dam = rng( 0, 40 ); // Torso and head take the brunt of the blow - body_part hit = bp_head; - crushed_player->deal_damage( nullptr, hit, damage_instance( DT_BASH, dam * .25 ) ); - hit = bp_torso; - crushed_player->deal_damage( nullptr, hit, damage_instance( DT_BASH, dam * .45 ) ); + crushed_player->deal_damage( nullptr, bodypart_id( "head" ), damage_instance( DT_BASH, + dam * .25 ) ); + crushed_player->deal_damage( nullptr, bodypart_id( "torso" ), damage_instance( DT_BASH, + dam * .45 ) ); // Legs take the next most through transferred force - hit = bp_leg_l; - crushed_player->deal_damage( nullptr, hit, damage_instance( DT_BASH, dam * .10 ) ); - hit = bp_leg_r; - crushed_player->deal_damage( nullptr, hit, damage_instance( DT_BASH, dam * .10 ) ); + crushed_player->deal_damage( nullptr, bodypart_id( "leg_l" ), damage_instance( DT_BASH, + dam * .10 ) ); + crushed_player->deal_damage( nullptr, bodypart_id( "leg_r" ), damage_instance( DT_BASH, + dam * .10 ) ); // Arms take the least - hit = bp_arm_l; - crushed_player->deal_damage( nullptr, hit, damage_instance( DT_BASH, dam * .05 ) ); - hit = bp_arm_r; - crushed_player->deal_damage( nullptr, hit, damage_instance( DT_BASH, dam * .05 ) ); + crushed_player->deal_damage( nullptr, bodypart_id( "arm_l" ), damage_instance( DT_BASH, + dam * .05 ) ); + crushed_player->deal_damage( nullptr, bodypart_id( "arm_r" ), damage_instance( DT_BASH, + dam * .05 ) ); // Pin whoever got hit crushed_player->add_effect( effect_crushed, 1_turns, num_bp, true ); @@ -3406,7 +3412,7 @@ void map::crush( const tripoint &p ) if( monster *const monhit = g->critter_at( p ) ) { // 25 ~= 60 * .45 (torso) - monhit->deal_damage( nullptr, bp_torso, damage_instance( DT_BASH, rng( 0, 25 ) ) ); + monhit->deal_damage( nullptr, bodypart_id( "torso" ), damage_instance( DT_BASH, rng( 0, 25 ) ) ); // Pin whoever got hit monhit->add_effect( effect_crushed, 1_turns, num_bp, true ); diff --git a/src/map_field.cpp b/src/map_field.cpp index 37dd3d944ea6d..a29d3381279c7 100644 --- a/src/map_field.cpp +++ b/src/map_field.cpp @@ -124,7 +124,8 @@ int map::burn_body_part( player &u, field_entry &cur, body_part bp, const int sc const int damage = rng( 1, scale + intensity ); // A bit ugly, but better than being annoyed by acid when in hazmat if( u.get_armor_type( DT_ACID, bp ) < damage ) { - const dealt_damage_instance ddi = u.deal_damage( nullptr, bp, damage_instance( DT_ACID, damage ) ); + const dealt_damage_instance ddi = u.deal_damage( nullptr, convert_bp( bp ).id(), + damage_instance( DT_ACID, damage ) ); total_damage += ddi.total_damage(); } // Represents acid seeping in rather than being splashed on @@ -1127,14 +1128,14 @@ bool map::process_fields_in_submap( submap *const current_submap, add_item_or_charges( newp, tmp ); if( g->u.pos() == newp ) { add_msg( m_bad, _( "A %s hits you!" ), tmp.tname() ); - body_part hit = random_body_part(); + const bodypart_id hit = g->u.get_random_body_part(); g->u.deal_damage( nullptr, hit, damage_instance( DT_BASH, 6 ) ); g->u.check_dead_state(); } if( npc *const p = g->critter_at( newp ) ) { // TODO: combine with player character code above - body_part hit = random_body_part(); + const bodypart_id hit = g->u.get_random_body_part(); p->deal_damage( nullptr, hit, damage_instance( DT_BASH, 6 ) ); if( g->u.sees( newp ) ) { add_msg( _( "A %1$s hits %2$s!" ), tmp.tname(), p->name ); @@ -1479,33 +1480,34 @@ void map::player_in_field( player &u ) const int burn_min = adjusted_intensity; const int burn_max = 3 * adjusted_intensity + 3; - std::list parts_burned; + std::list parts_burned; int msg_num = adjusted_intensity - 1; if( !u.is_on_ground() ) { switch( adjusted_intensity ) { case 3: - parts_burned.push_back( bp_hand_l ); - parts_burned.push_back( bp_hand_r ); - parts_burned.push_back( bp_arm_l ); - parts_burned.push_back( bp_arm_r ); + parts_burned.push_back( bodypart_id( "hand_l" ) ); + parts_burned.push_back( bodypart_id( "hand_r" ) ); + parts_burned.push_back( bodypart_id( "arm_l" ) ); + parts_burned.push_back( bodypart_id( "arm_r" ) ); /* fallthrough */ case 2: - parts_burned.push_back( bp_torso ); + parts_burned.push_back( bodypart_id( "torso" ) ); /* fallthrough */ case 1: - parts_burned.push_back( bp_foot_l ); - parts_burned.push_back( bp_foot_r ); - parts_burned.push_back( bp_leg_l ); - parts_burned.push_back( bp_leg_r ); + parts_burned.push_back( bodypart_id( "foot_l" ) ); + parts_burned.push_back( bodypart_id( "foot_r" ) ); + parts_burned.push_back( bodypart_id( "leg_l" ) ); + parts_burned.push_back( bodypart_id( "leg_r" ) ); } } else { // Lying in the fire is BAAAD news, hits every body part. msg_num = 3; - parts_burned.assign( all_body_parts.begin(), all_body_parts.end() ); + const std::vector all_parts = u.get_all_body_parts(); + parts_burned.assign( all_parts.begin(), all_parts.end() ); } int total_damage = 0; - for( body_part part_burned : parts_burned ) { + for( const bodypart_id part_burned : parts_burned ) { const dealt_damage_instance dealt = u.deal_damage( nullptr, part_burned, damage_instance( DT_HEAT, rng( burn_min, burn_max ) ) ); total_damage += dealt.type_damage( DT_HEAT ); @@ -1563,9 +1565,9 @@ void map::player_in_field( player &u ) !u.is_wearing( "rm13_armor_on" ) ) { u.add_msg_player_or_npc( m_bad, _( "You're torched by flames!" ), _( " is torched by flames!" ) ); - u.deal_damage( nullptr, bp_leg_l, damage_instance( DT_HEAT, rng( 2, 6 ) ) ); - u.deal_damage( nullptr, bp_leg_r, damage_instance( DT_HEAT, rng( 2, 6 ) ) ); - u.deal_damage( nullptr, bp_torso, damage_instance( DT_HEAT, rng( 4, 9 ) ) ); + u.deal_damage( nullptr, bodypart_id( "leg_l" ), damage_instance( DT_HEAT, rng( 2, 6 ) ) ); + u.deal_damage( nullptr, bodypart_id( "leg_r" ), damage_instance( DT_HEAT, rng( 2, 6 ) ) ); + u.deal_damage( nullptr, bodypart_id( "torso" ), damage_instance( DT_HEAT, rng( 4, 9 ) ) ); u.check_dead_state(); } else { u.add_msg_player_or_npc( _( "These flames do not burn you." ), @@ -1578,7 +1580,7 @@ void map::player_in_field( player &u ) if( !u.is_elec_immune() ) { int total_damage = 0; for( size_t i = 0; i < num_hp_parts; i++ ) { - const body_part bp = player::hp_to_bp( static_cast( i ) ); + const bodypart_id bp = convert_bp( player::hp_to_bp( static_cast( i ) ) ).id(); const int dmg = rng( 1, cur.get_field_intensity() ); total_damage += u.deal_damage( nullptr, bp, damage_instance( DT_ELECTRIC, dmg ) ).total_damage(); } @@ -1773,7 +1775,7 @@ void map::monster_in_field( monster &z ) if( cur_field_type == fd_acid ) { if( !z.flies() ) { const int d = rng( cur.get_field_intensity(), cur.get_field_intensity() * 3 ); - z.deal_damage( nullptr, bp_torso, damage_instance( DT_ACID, d ) ); + z.deal_damage( nullptr, bodypart_id( "torso" ), damage_instance( DT_ACID, d ) ); z.check_dead_state(); } @@ -1926,7 +1928,7 @@ void map::monster_in_field( monster &z ) } if( cur_field_type == fd_electricity ) { // We don't want to increase dam, but deal a separate hit so that it can apply effects - z.deal_damage( nullptr, bp_torso, + z.deal_damage( nullptr, bodypart_id( "torso" ), damage_instance( DT_ELECTRIC, rng( 1, cur.get_field_intensity() * 3 ) ) ); } if( cur_field_type == fd_fatigue ) { diff --git a/src/mattack_actors.cpp b/src/mattack_actors.cpp index 16808ca6a5f8d..7b0887c63a509 100644 --- a/src/mattack_actors.cpp +++ b/src/mattack_actors.cpp @@ -303,7 +303,7 @@ bool melee_actor::call( monster &z ) const *body_parts.pick(); target->on_hit( &z, bp_hit ); - dealt_damage_instance dealt_damage = target->deal_damage( &z, bp_hit, damage ); + dealt_damage_instance dealt_damage = target->deal_damage( &z, convert_bp( bp_hit ).id(), damage ); dealt_damage.bp_hit = bp_hit; int damage_total = dealt_damage.total_damage(); diff --git a/src/melee.cpp b/src/melee.cpp index bafe9e385c1fa..1ce7d8db6e972 100644 --- a/src/melee.cpp +++ b/src/melee.cpp @@ -1781,9 +1781,11 @@ std::string Character::melee_special_effects( Creature &t, damage_instance &d, i //Hurting the wielder from poorly-chosen weapons if( weap.has_flag( "HURT_WHEN_WIELDED" ) && x_in_y( 2, 3 ) ) { add_msg_if_player( m_bad, _( "The %s cuts your hand!" ), weap.tname() ); - deal_damage( nullptr, bp_hand_r, damage_instance::physical( 0, weap.damage_melee( DT_CUT ), 0 ) ); + deal_damage( nullptr, bodypart_id( "hand_r" ), damage_instance::physical( 0, + weap.damage_melee( DT_CUT ), 0 ) ); if( weap.is_two_handed( *this ) ) { // Hurt left hand too, if it was big - deal_damage( nullptr, bp_hand_l, damage_instance::physical( 0, weap.damage_melee( DT_CUT ), 0 ) ); + deal_damage( nullptr, bodypart_id( "hand_l" ), damage_instance::physical( 0, + weap.damage_melee( DT_CUT ), 0 ) ); } } @@ -1805,10 +1807,12 @@ std::string Character::melee_special_effects( Creature &t, damage_instance &d, i // Dump its contents on the ground weap.contents.spill_contents( pos() ); // Take damage - deal_damage( nullptr, bp_arm_r, damage_instance::physical( 0, rng( 0, vol * 2 ), 0 ) ); + deal_damage( nullptr, bodypart_id( "arm_r" ), damage_instance::physical( 0, rng( 0, vol * 2 ), + 0 ) ); if( weap.is_two_handed( *this ) ) { // Hurt left arm too, if it was big //redeclare shatter_dam because deal_damage mutates it - deal_damage( nullptr, bp_arm_l, damage_instance::physical( 0, rng( 0, vol * 2 ), 0 ) ); + deal_damage( nullptr, bodypart_id( "arm_l" ), damage_instance::physical( 0, rng( 0, vol * 2 ), + 0 ) ); } d.add_damage( DT_CUT, rng( 0, 5 + static_cast( vol * 1.5 ) ) ); // Hurt the monster extra remove_weapon(); diff --git a/src/monattack.cpp b/src/monattack.cpp index df4b7740ee968..bc4c76f656849 100644 --- a/src/monattack.cpp +++ b/src/monattack.cpp @@ -635,7 +635,8 @@ bool mattack::acid_barf( monster *z ) body_part hit = target->get_random_body_part()->token; int dam = rng( 5, 12 ); - dam = target->deal_damage( z, hit, damage_instance( DT_ACID, dam ) ).total_damage(); + dam = target->deal_damage( z, convert_bp( hit ).id(), damage_instance( DT_ACID, + dam ) ).total_damage(); target->add_env_effect( effect_corroding, hit, 5, time_duration::from_turns( dam / 2 + 5 ), hit ); if( dam > 0 ) { @@ -1429,7 +1430,7 @@ bool mattack::growplants( monster *z ) //~ %s is bodypart name in accusative. _( "A tree bursts forth from the earth and pierces 's %s!" ), body_part_name_accusative( hit ) ); - critter->deal_damage( z, hit, damage_instance( DT_STAB, rng( 10, 30 ) ) ); + critter->deal_damage( z, convert_bp( hit ).id(), damage_instance( DT_STAB, rng( 10, 30 ) ) ); } // 1 in 5 chance of making existing vegetation grow larger @@ -1464,7 +1465,7 @@ bool mattack::growplants( monster *z ) //~ %s is bodypart name in accusative. _( "Underbrush grows into a tree, and it pierces 's %s!" ), body_part_name_accusative( hit ) ); - critter->deal_damage( z, hit, damage_instance( DT_STAB, rng( 10, 30 ) ) ); + critter->deal_damage( z, convert_bp( hit ).id(), damage_instance( DT_STAB, rng( 10, 30 ) ) ); } } } @@ -1511,13 +1512,13 @@ bool mattack::vine( monster *z ) return true; } - body_part bphit = critter->get_random_body_part()->token; + bodypart_id bphit = critter->get_random_body_part(); critter->add_msg_player_or_npc( m_bad, //~ 1$s monster name(vine), 2$s bodypart in accusative _( "The %1$s lashes your %2$s!" ), _( "The %1$s lashes 's %2$s!" ), z->name(), - body_part_name_accusative( bphit ) ); + body_part_name_accusative( bphit->token ) ); damage_instance d; d.add_damage( DT_CUT, 8 ); d.add_damage( DT_BASH, 8 ); @@ -1803,14 +1804,14 @@ bool mattack::fungus_inject( monster *z ) return true; } - body_part hit = target->get_random_body_part()->token; + const bodypart_id hit = target->get_random_body_part(); int dam = rng( 5, 11 ); dam = g->u.deal_damage( z, hit, damage_instance( DT_CUT, dam ) ).total_damage(); if( dam > 0 ) { //~ 1$s is monster name, 2$s bodypart in accusative add_msg( m_bad, _( "The %1$s sinks its point into your %2$s!" ), z->name(), - body_part_name_accusative( hit ) ); + body_part_name_accusative( hit->token ) ); if( one_in( 10 - dam ) ) { g->u.add_effect( effect_fungus, 10_minutes, num_bp, true ); @@ -1819,10 +1820,10 @@ bool mattack::fungus_inject( monster *z ) } else { //~ 1$s is monster name, 2$s bodypart in accusative add_msg( _( "The %1$s strikes your %2$s, but your armor protects you." ), z->name(), - body_part_name_accusative( hit ) ); + body_part_name_accusative( hit->token ) ); } - target->on_hit( z, hit, z->type->melee_skill ); + target->on_hit( z, hit->token, z->type->melee_skill ); g->u.check_dead_state(); return true; @@ -1858,7 +1859,7 @@ bool mattack::fungus_bristle( monster *z ) return true; } - body_part hit = target->get_random_body_part()->token; + const bodypart_id hit = target->get_random_body_part(); int dam = rng( 7, 16 ); dam = target->deal_damage( z, hit, damage_instance( DT_CUT, dam ) ).total_damage(); @@ -1866,7 +1867,7 @@ bool mattack::fungus_bristle( monster *z ) //~ 1$s is monster name, 2$s bodypart in accusative target->add_msg_if_player( m_bad, _( "The %1$s sinks several needlelike barbs into your %2$s!" ), z->name(), - body_part_name_accusative( hit ) ); + body_part_name_accusative( hit->token ) ); if( one_in( 15 - dam ) ) { target->add_effect( effect_fungus, 20_minutes, num_bp, true ); @@ -1877,10 +1878,10 @@ bool mattack::fungus_bristle( monster *z ) //~ 1$s is monster name, 2$s bodypart in accusative target->add_msg_if_player( _( "The %1$s slashes your %2$s, but your armor protects you." ), z->name(), - body_part_name_accusative( hit ) ); + body_part_name_accusative( hit->token ) ); } - target->on_hit( z, hit, z->type->melee_skill ); + target->on_hit( z, hit->token, z->type->melee_skill ); return true; } @@ -2003,7 +2004,7 @@ bool mattack::fungus_fortify( monster *z ) //~ %s is bodypart name in accusative. add_msg( m_bad, _( "A fungal tendril bursts forth from the earth and pierces your %s!" ), body_part_name_accusative( hit ) ); - g->u.deal_damage( z, hit, damage_instance( DT_CUT, rng( 5, 11 ) ) ); + g->u.deal_damage( z, convert_bp( hit ).id(), damage_instance( DT_CUT, rng( 5, 11 ) ) ); g->u.check_dead_state(); // Probably doesn't have spores available *just* yet. Let's be nice. } else if( monster *const tendril = g->place_critter_at( mon_fungal_tendril, hit_pos ) ) { @@ -2029,23 +2030,23 @@ bool mattack::fungus_fortify( monster *z ) } // TODO: 21 damage with no chance to critical isn't scary - body_part hit = target->get_random_body_part()->token; + const bodypart_id hit = target->get_random_body_part(); int dam = rng( 15, 21 ); dam = g->u.deal_damage( z, hit, damage_instance( DT_STAB, dam ) ).total_damage(); if( dam > 0 ) { //~ 1$s is monster name, 2$s bodypart in accusative add_msg( m_bad, _( "The %1$s sinks its point into your %2$s!" ), z->name(), - body_part_name_accusative( hit ) ); + body_part_name_accusative( hit->token ) ); g->u.add_effect( effect_fungus, 40_minutes, num_bp, true ); add_msg( m_warning, _( "You feel millions of live spores pumping into you…" ) ); } else { //~ 1$s is monster name, 2$s bodypart in accusative add_msg( _( "The %1$s strikes your %2$s, but your armor protects you." ), z->name(), - body_part_name_accusative( hit ) ); + body_part_name_accusative( hit->token ) ); } - target->on_hit( z, hit, z->type->melee_skill ); + target->on_hit( z, hit->token, z->type->melee_skill ); g->u.check_dead_state(); return true; } @@ -2074,7 +2075,8 @@ bool mattack::impale( monster *z ) return true; } - int dam = target->deal_damage( z, bp_torso, damage_instance( DT_STAB, rng( 10, 20 ), rng( 5, 15 ), + int dam = target->deal_damage( z, bodypart_id( "torso" ), damage_instance( DT_STAB, rng( 10, 20 ), + rng( 5, 15 ), .5 ) ).total_damage(); if( dam > 0 ) { auto msg_type = target == &g->u ? m_bad : m_info; @@ -2541,12 +2543,12 @@ bool mattack::tentacle( monster *z ) return true; } - body_part hit = target->get_random_body_part()->token; + const bodypart_id hit = target->get_random_body_part(); int dam = rng( 10, 20 ); //~ 1$s is bodypart name, 2$d is damage value. - add_msg( m_bad, _( "Your %1$s is hit for %2$d damage!" ), body_part_name( hit ), dam ); + add_msg( m_bad, _( "Your %1$s is hit for %2$d damage!" ), body_part_name( hit->token ), dam ); g->u.deal_damage( z, hit, damage_instance( DT_BASH, dam ) ); - target->on_hit( z, hit, z->type->melee_skill ); + target->on_hit( z, hit->token, z->type->melee_skill ); g->u.check_dead_state(); return true; @@ -3241,7 +3243,7 @@ void mattack::taze( monster *z, Creature *target ) return; } - int dam = target->deal_damage( z, bp_torso, damage_instance( DT_ELECTRIC, rng( 1, + int dam = target->deal_damage( z, bodypart_id( "torso" ), damage_instance( DT_ELECTRIC, rng( 1, 5 ) ) ).total_damage(); if( dam == 0 ) { target->add_msg_player_or_npc( _( "The %s unsuccessfully attempts to shock you." ), @@ -4074,7 +4076,8 @@ bool mattack::stretch_bite( monster *z ) return true; } - body_part hit = target->get_random_body_part()->token; + const bodypart_id hit = target->get_random_body_part(); + const body_part hit_token = hit->token; // More damage due to the speed of the moving head int dam = rng( 5, 15 ); dam = target->deal_damage( z, hit, damage_instance( DT_STAB, dam ) ).total_damage(); @@ -4087,25 +4090,25 @@ bool mattack::stretch_bite( monster *z ) //~ 1$s is monster name, 2$s bodypart in accusative _( "The %1$s's teeth sink into 's %2$s!" ), z->name(), - body_part_name_accusative( hit ) ); + body_part_name_accusative( hit_token ) ); if( one_in( 16 - dam ) ) { - if( target->has_effect( effect_bite, hit ) ) { - target->add_effect( effect_bite, 40_minutes, hit, true ); - } else if( target->has_effect( effect_infected, hit ) ) { - target->add_effect( effect_infected, 25_minutes, hit, true ); + if( target->has_effect( effect_bite, hit_token ) ) { + target->add_effect( effect_bite, 40_minutes, hit_token, true ); + } else if( target->has_effect( effect_infected, hit_token ) ) { + target->add_effect( effect_infected, 25_minutes, hit_token, true ); } else { - target->add_effect( effect_bite, 1_turns, hit, true ); + target->add_effect( effect_bite, 1_turns, hit_token, true ); } } } else { target->add_msg_player_or_npc( _( "The %1$s's head hits your %2$s, but glances off your armor!" ), _( "The %1$s's head hits 's %2$s, but glances off armor!" ), z->name(), - body_part_name_accusative( hit ) ); + body_part_name_accusative( hit_token ) ); } - target->on_hit( z, hit, z->type->melee_skill ); + target->on_hit( z, hit_token, z->type->melee_skill ); return true; } @@ -4174,7 +4177,7 @@ bool mattack::flesh_golem( monster *z ) target->on_dodge( z, z->type->melee_skill * 2 ); return true; } - body_part hit = target->get_random_body_part()->token; + const bodypart_id hit = target->get_random_body_part(); // TODO: 10 bashing damage doesn't sound like a "massive claw" but a mediocre punch int dam = rng( 5, 10 ); target->deal_damage( z, hit, damage_instance( DT_BASH, dam ) ); @@ -4184,8 +4187,8 @@ bool mattack::flesh_golem( monster *z ) //~ 1$s is bodypart name, 2$d is damage value. target->add_msg_if_player( m_bad, _( "Your %1$s is battered for %2$d damage!" ), - body_part_name( hit ), dam ); - target->on_hit( z, hit, z->type->melee_skill ); + body_part_name( hit->token ), dam ); + target->on_hit( z, hit->token, z->type->melee_skill ); return true; } @@ -4294,7 +4297,7 @@ bool mattack::lunge( monster *z ) target->on_dodge( z, z->type->melee_skill * 2 ); return true; } - body_part hit = target->get_random_body_part()->token; + const bodypart_id hit = target->get_random_body_part(); int dam = rng( 3, 7 ); dam = target->deal_damage( z, hit, damage_instance( DT_BASH, dam ) ).total_damage(); if( dam > 0 ) { @@ -4302,17 +4305,17 @@ bool mattack::lunge( monster *z ) target->add_msg_player_or_npc( msg_type, _( "The %1$s lunges at your %2$s, battering it for %3$d damage!" ), _( "The %1$s lunges at 's %2$s, battering it for %3$d damage!" ), - z->name(), body_part_name( hit ), dam ); + z->name(), body_part_name( hit->token ), dam ); } else { target->add_msg_player_or_npc( _( "The %1$s lunges at your %2$s, but your armor prevents injury!" ), _( "The %1$s lunges at 's %2$s, but their armor prevents injury!" ), z->name(), - body_part_name_accusative( hit ) ); + body_part_name_accusative( hit->token ) ); } if( one_in( 6 ) ) { target->add_effect( effect_downed, 3_turns ); } - target->on_hit( z, hit, z->type->melee_skill ); + target->on_hit( z, hit->token, z->type->melee_skill ); target->check_dead_state(); return true; } @@ -4362,7 +4365,7 @@ bool mattack::longswipe( monster *z ) target->on_dodge( z, z->type->melee_skill * 2 ); return true; } - body_part hit = target->get_random_body_part()->token; + const bodypart_id hit = target->get_random_body_part(); int dam = rng( 3, 7 ); dam = target->deal_damage( z, hit, damage_instance( DT_CUT, dam ) ).total_damage(); if( dam > 0 ) { @@ -4372,15 +4375,15 @@ bool mattack::longswipe( monster *z ) _( "The %1$s thrusts a claw at your %2$s, slashing it for %3$d damage!" ), //~ 1$s is bodypart name, 2$d is damage value. _( "The %1$s thrusts a claw at 's %2$s, slashing it for %3$d damage!" ), - z->name(), body_part_name( hit ), dam ); + z->name(), body_part_name( hit->token ), dam ); } else { target->add_msg_player_or_npc( _( "The %1$s thrusts a claw at your %2$s, but glances off your armor!" ), _( "The %1$s thrusts a claw at 's %2$s, but glances off armor!" ), z->name(), - body_part_name_accusative( hit ) ); + body_part_name_accusative( hit->token ) ); } - target->on_hit( z, hit, z->type->melee_skill ); + target->on_hit( z, hit->token, z->type->melee_skill ); return true; } return false; @@ -4398,9 +4401,10 @@ bool mattack::longswipe( monster *z ) target->on_dodge( z, z->type->melee_skill * 2 ); return true; } - body_part hit = bp_head; + int dam = rng( 6, 10 ); - dam = target->deal_damage( z, hit, damage_instance( DT_CUT, dam ) ).total_damage(); + dam = target->deal_damage( z, bodypart_id( "head" ), damage_instance( DT_CUT, + dam ) ).total_damage(); if( dam > 0 ) { auto msg_type = target == &g->u ? m_bad : m_warning; target->add_msg_player_or_npc( msg_type, @@ -4408,18 +4412,18 @@ bool mattack::longswipe( monster *z ) _( "The %1$s slashes at 's neck, cutting their throat for %2$d damage!" ), z->name(), dam ); if( target->is_player() || target->is_npc() ) { - target->as_character()->make_bleed( hit, 10_minutes ); + target->as_character()->make_bleed( bp_head, 10_minutes ); } else { - target->add_effect( effect_bleed, 10_minutes, hit ); + target->add_effect( effect_bleed, 10_minutes, bp_head ); } } else { target->add_msg_player_or_npc( _( "The %1$s slashes at your %2$s, but glances off your armor!" ), _( "The %1$s slashes at 's %2$s, but glances off armor!" ), z->name(), - body_part_name_accusative( hit ) ); + body_part_name_accusative( bp_head ) ); } - target->on_hit( z, hit, z->type->melee_skill ); + target->on_hit( z, bp_head, z->type->melee_skill ); target->check_dead_state(); return true; @@ -4601,8 +4605,8 @@ bool mattack::thrown_by_judo( monster *z ) // Discounted electric damage for quick flip damage_instance shock; shock.add_damage( DT_ELECTRIC, rng( 1, 3 ) ); - foe->deal_damage( z, bp_arm_l, shock ); - foe->deal_damage( z, bp_arm_r, shock ); + foe->deal_damage( z, bodypart_id( "arm_l" ), shock ); + foe->deal_damage( z, bodypart_id( "arm_r" ), shock ); foe->check_dead_state(); } // Monster is down, @@ -4853,7 +4857,7 @@ bool mattack::evolve_kill_strike( monster *z ) damage.mult_damage( 1.33f ); damage.add( damage_instance( DT_STAB, dice( z->type->melee_dice, z->type->melee_sides ), rng( 5, 15 ), 1.0, 0.5 ) ); - int damage_dealt = target->deal_damage( z, bp_torso, damage ).total_damage(); + int damage_dealt = target->deal_damage( z, bodypart_id( "torso" ), damage ).total_damage(); if( damage_dealt > 0 ) { auto msg_type = target == &g->u ? m_bad : m_warning; target->add_msg_player_or_npc( msg_type, @@ -5126,9 +5130,9 @@ bool mattack::bio_op_takedown( monster *z ) // Handle mons earlier - less to check for dam = rng( 6, 18 ); // Always aim for the torso - target->deal_damage( z, bp_torso, damage_instance( DT_BASH, dam ) ); + target->deal_damage( z, bodypart_id( "torso" ), damage_instance( DT_BASH, dam ) ); // Two hits - "leg" and torso - target->deal_damage( z, bp_torso, damage_instance( DT_BASH, dam ) ); + target->deal_damage( z, bodypart_id( "torso" ), damage_instance( DT_BASH, dam ) ); target->add_effect( effect_downed, 3_turns ); if( seen ) { add_msg( _( "%1$s slams %2$s to the ground!" ), z->name(), target->disp_name() ); @@ -5149,7 +5153,7 @@ bool mattack::bio_op_takedown( monster *z ) //~ 1$s is bodypart name in accusative, 2$d is damage value. target->add_msg_if_player( m_bad, _( "The zombie kicks your %1$s for %2$d damage…" ), body_part_name_accusative( hit ), dam ); - foe->deal_damage( z, hit, damage_instance( DT_BASH, dam ) ); + foe->deal_damage( z, convert_bp( hit ).id(), damage_instance( DT_BASH, dam ) ); // At this point, Judo or Tentacle Bracing can make this much less painful if( !foe->is_throw_immune() ) { if( !target->is_immune_effect( effect_downed ) ) { @@ -5159,12 +5163,12 @@ bool mattack::bio_op_takedown( monster *z ) dam = rng( 9, 21 ); target->add_msg_if_player( m_bad, _( "and slams you, face first, to the ground for %d damage!" ), dam ); - foe->deal_damage( z, hit, damage_instance( DT_BASH, dam ) ); + foe->deal_damage( z, bodypart_id( "head" ), damage_instance( DT_BASH, dam ) ); } else { hit = bp_torso; dam = rng( 6, 18 ); target->add_msg_if_player( m_bad, _( "and slams you to the ground for %d damage!" ), dam ); - foe->deal_damage( z, hit, damage_instance( DT_BASH, dam ) ); + foe->deal_damage( z, bodypart_id( "torso" ), damage_instance( DT_BASH, dam ) ); } foe->add_effect( effect_downed, 3_turns ); } @@ -5175,7 +5179,7 @@ bool mattack::bio_op_takedown( monster *z ) hit = bp_torso; dam = rng( 3, 9 ); target->add_msg_if_player( m_bad, _( "and slams you for %d damage!" ), dam ); - foe->deal_damage( z, hit, damage_instance( DT_BASH, dam ) ); + foe->deal_damage( z, bodypart_id( "torso" ), damage_instance( DT_BASH, dam ) ); } target->on_hit( z, hit, z->type->melee_skill ); foe->check_dead_state(); @@ -5228,7 +5232,7 @@ bool mattack::bio_op_impale( monster *z ) if( foe == nullptr ) { // Handle mons earlier - less to check for - target->deal_damage( z, bp_torso, damage_instance( DT_STAB, dam ) ); + target->deal_damage( z, bodypart_id( "torso" ), damage_instance( DT_STAB, dam ) ); if( do_bleed ) { target->add_effect( effect_bleed, rng( 75_turns, 125_turns ), bp_torso, true ); } @@ -5239,26 +5243,26 @@ bool mattack::bio_op_impale( monster *z ) return true; } - body_part hit = target->get_random_body_part()->token; + const bodypart_id hit = target->get_random_body_part(); t_dam = foe->deal_damage( z, hit, damage_instance( DT_STAB, dam ) ).total_damage(); target->add_msg_player_or_npc( _( "The %1$s tries to impale your %s…" ), _( "The %1$s tries to impale 's %s…" ), - z->name(), body_part_name_accusative( hit ) ); + z->name(), body_part_name_accusative( hit->token ) ); if( t_dam > 0 ) { target->add_msg_if_player( m_bad, _( "and deals %d damage!" ), t_dam ); if( do_bleed ) { - target->as_character()->make_bleed( hit, rng( 75_turns, 125_turns ), true ); + target->as_character()->make_bleed( hit->token, rng( 75_turns, 125_turns ), true ); } } else { target->add_msg_player_or_npc( _( "but fails to penetrate your armor!" ), _( "but fails to penetrate 's armor!" ) ); } - target->on_hit( z, hit, z->type->melee_skill ); + target->on_hit( z, hit->token, z->type->melee_skill ); foe->check_dead_state(); return true; @@ -5679,7 +5683,7 @@ bool mattack::stretch_attack( monster *z ) return true; } - body_part hit = target->get_random_body_part()->token; + const bodypart_id hit = target->get_random_body_part(); dam = target->deal_damage( z, hit, damage_instance( DT_STAB, dam ) ).total_damage(); if( dam > 0 ) { @@ -5690,17 +5694,17 @@ bool mattack::stretch_attack( monster *z ) //~ 1$s is monster name, 2$s bodypart in accusative _( "The %1$s arm pierces 's %2$s!" ), z->name(), - body_part_name_accusative( hit ) ); + body_part_name_accusative( hit->token ) ); target->check_dead_state(); } else { target->add_msg_player_or_npc( _( "The %1$s arm hits your %2$s, but glances off your armor!" ), _( "The %1$s hits 's %2$s, but glances off armor!" ), z->name(), - body_part_name_accusative( hit ) ); + body_part_name_accusative( hit->token ) ); } - target->on_hit( z, hit, z->type->melee_skill ); + target->on_hit( z, hit->token, z->type->melee_skill ); return true; } diff --git a/src/mondefense.cpp b/src/mondefense.cpp index 658fd17115db5..7b98d39da7d8f 100644 --- a/src/mondefense.cpp +++ b/src/mondefense.cpp @@ -86,8 +86,8 @@ void mdefense::zapback( monster &m, Creature *const source, const damage_instance shock { DT_ELECTRIC, static_cast( rng( 1, 5 ) ) }; - source->deal_damage( &m, bp_arm_l, shock ); - source->deal_damage( &m, bp_arm_r, shock ); + source->deal_damage( &m, bodypart_id( "arm_l" ), shock ); + source->deal_damage( &m, bodypart_id( "arm_r" ), shock ); source->check_dead_state(); } @@ -118,7 +118,8 @@ void mdefense::acidsplash( monster &m, Creature *const source, const damage_instance acid_burn{ DT_ACID, static_cast( rng( 1, 5 ) ) }; - source->deal_damage( &m, one_in( 2 ) ? bp_hand_l : bp_hand_r, acid_burn ); + source->deal_damage( &m, one_in( 2 ) ? bodypart_id( "hand_l" ) : bodypart_id( "hand_r" ), + acid_burn ); source->add_msg_if_player( m_bad, _( "Acid covering %s burns your hand!" ), m.disp_name() ); } } diff --git a/src/monmove.cpp b/src/monmove.cpp index a133d78a82d67..07505cd7dc267 100644 --- a/src/monmove.cpp +++ b/src/monmove.cpp @@ -1847,7 +1847,7 @@ void monster::knock_back_to( const tripoint &to ) if( npc *const p = g->critter_at( to ) ) { apply_damage( p, bodypart_id( "torso" ), 3 ); add_effect( effect_stunned, 1_turns ); - p->deal_damage( this, bp_torso, damage_instance( DT_BASH, type->size ) ); + p->deal_damage( this, bodypart_id( "torso" ), damage_instance( DT_BASH, type->size ) ); if( u_see ) { add_msg( _( "The %1$s bounces off %2$s!" ), name(), p->name ); } diff --git a/src/player.cpp b/src/player.cpp index 2adfed4d36394..4df0f49b83b34 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -1020,7 +1020,7 @@ void player::on_hit( Creature *source, body_part bp_hit, damage_instance ods_shock_damage; ods_shock_damage.add_damage( DT_ELECTRIC, shock * 5 ); // Should hit body part used for attack - source->deal_damage( this, bp_torso, ods_shock_damage ); + source->deal_damage( this, bodypart_id( "torso" ), ods_shock_damage ); } if( !wearing_something_on( bp_hit ) && ( has_trait( trait_SPINES ) || has_trait( trait_QUILLS ) ) ) { @@ -1038,7 +1038,7 @@ void player::on_hit( Creature *source, body_part bp_hit, } damage_instance spine_damage; spine_damage.add_damage( DT_STAB, spine ); - source->deal_damage( this, bp_torso, spine_damage ); + source->deal_damage( this, bodypart_id( "torso" ), spine_damage ); } if( ( !( wearing_something_on( bp_hit ) ) ) && ( has_trait( trait_THORNS ) ) && ( !( source->has_weapon() ) ) ) { @@ -1055,7 +1055,7 @@ void player::on_hit( Creature *source, body_part bp_hit, thorn_damage.add_damage( DT_CUT, thorn ); // In general, critters don't have separate limbs // so safer to target the torso - source->deal_damage( this, bp_torso, thorn_damage ); + source->deal_damage( this, bodypart_id( "torso" ), thorn_damage ); } if( ( !( wearing_something_on( bp_hit ) ) ) && ( has_trait( trait_CF_HAIR ) ) ) { if( !is_player() ) { @@ -1311,7 +1311,7 @@ int player::impact( const int force, const tripoint &p ) int total_dealt = 0; if( mod * effective_force >= 5 ) { for( int i = 0; i < num_hp_parts; i++ ) { - const body_part bp = hp_to_bp( static_cast( i ) ); + const bodypart_id bp = convert_bp( hp_to_bp( static_cast( i ) ) ).id(); const int bash = effective_force * rng( 60, 100 ) / 100; damage_instance di; di.add_damage( DT_BASH, bash, 0, armor_eff, mod ); @@ -1357,7 +1357,7 @@ void player::knock_back_to( const tripoint &to ) // First, see if we hit a monster if( monster *const critter = g->critter_at( to ) ) { - deal_damage( critter, bp_torso, damage_instance( DT_BASH, critter->type->size ) ); + deal_damage( critter, bodypart_id( "torso" ), damage_instance( DT_BASH, critter->type->size ) ); add_effect( effect_stunned, 1_turns ); /** @EFFECT_STR_MAX allows knocked back player to knock back, damage, stun some monsters */ if( ( str_max - 6 ) / 4 > critter->type->size ) { @@ -1376,9 +1376,9 @@ void player::knock_back_to( const tripoint &to ) } if( npc *const np = g->critter_at( to ) ) { - deal_damage( np, bp_torso, damage_instance( DT_BASH, np->get_size() ) ); + deal_damage( np, bodypart_id( "torso" ), damage_instance( DT_BASH, np->get_size() ) ); add_effect( effect_stunned, 1_turns ); - np->deal_damage( this, bp_torso, damage_instance( DT_BASH, 3 ) ); + np->deal_damage( this, bodypart_id( "torso" ), damage_instance( DT_BASH, 3 ) ); add_msg_player_or_npc( _( "You bounce off %s!" ), _( " bounces off %s!" ), np->name ); np->check_dead_state(); diff --git a/src/player_hardcoded_effects.cpp b/src/player_hardcoded_effects.cpp index ac97fa484a345..98b40396bec51 100644 --- a/src/player_hardcoded_effects.cpp +++ b/src/player_hardcoded_effects.cpp @@ -116,7 +116,8 @@ static const trait_id trait_WATERSLEEP( "WATERSLEEP" ); static void eff_fun_onfire( player &u, effect &it ) { const int intense = it.get_intensity(); - u.deal_damage( nullptr, it.get_bp(), damage_instance( DT_HEAT, rng( intense, intense * 2 ) ) ); + u.deal_damage( nullptr, convert_bp( it.get_bp() ).id(), damage_instance( DT_HEAT, rng( intense, + intense * 2 ) ) ); } static void eff_fun_spores( player &u, effect &it ) { diff --git a/src/trapfunc.cpp b/src/trapfunc.cpp index 2674dbd704d2d..4c22589c36775 100644 --- a/src/trapfunc.cpp +++ b/src/trapfunc.cpp @@ -114,8 +114,8 @@ bool trapfunc::glass( const tripoint &p, Creature *c, item * ) z->moves -= 80; } if( dmg > 0 ) { - c->deal_damage( nullptr, bp_foot_l, damage_instance( DT_CUT, dmg ) ); - c->deal_damage( nullptr, bp_foot_r, damage_instance( DT_CUT, dmg ) ); + c->deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, dmg ) ); + c->deal_damage( nullptr, bodypart_id( "foot_r" ), damage_instance( DT_CUT, dmg ) ); c->check_dead_state(); } } @@ -146,7 +146,7 @@ bool trapfunc::beartrap( const tripoint &p, Creature *c, item * ) g->m.remove_trap( p ); if( c != nullptr ) { // What got hit? - const body_part hit = one_in( 2 ) ? bp_leg_l : bp_leg_r; + const bodypart_id hit = one_in( 2 ) ? bodypart_id( "leg_l" ) : bodypart_id( "leg_r" ); // Messages c->add_msg_player_or_npc( m_bad, _( "A bear trap closes on your foot!" ), @@ -155,7 +155,7 @@ bool trapfunc::beartrap( const tripoint &p, Creature *c, item * ) add_msg( m_warning, _( "Your %s is caught by a beartrap!" ), c->get_name() ); } // Actual effects - c->add_effect( effect_beartrap, 1_turns, hit, true ); + c->add_effect( effect_beartrap, 1_turns, hit->token, true ); damage_instance d; d.add_damage( DT_BASH, 12 ); d.add_damage( DT_CUT, 18 ); @@ -197,11 +197,11 @@ bool trapfunc::board( const tripoint &, Creature *c, item * ) } else { z->moves -= 80; } - z->deal_damage( nullptr, bp_foot_l, damage_instance( DT_CUT, rng( 3, 5 ) ) ); - z->deal_damage( nullptr, bp_foot_r, damage_instance( DT_CUT, rng( 3, 5 ) ) ); + z->deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, rng( 3, 5 ) ) ); + z->deal_damage( nullptr, bodypart_id( "foot_r" ), damage_instance( DT_CUT, rng( 3, 5 ) ) ); } else { - c->deal_damage( nullptr, bp_foot_l, damage_instance( DT_CUT, rng( 6, 10 ) ) ); - c->deal_damage( nullptr, bp_foot_r, damage_instance( DT_CUT, rng( 6, 10 ) ) ); + c->deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, rng( 6, 10 ) ) ); + c->deal_damage( nullptr, bodypart_id( "foot_r" ), damage_instance( DT_CUT, rng( 6, 10 ) ) ); if( ( n->has_trait( trait_INFRESIST ) ) && ( one_in( 256 ) ) ) { n->add_effect( effect_tetanus, 1_turns, num_bp, true ); } else if( ( !n->has_trait( trait_INFIMMUNE ) || !n->has_trait( trait_INFRESIST ) ) && @@ -232,11 +232,11 @@ bool trapfunc::caltrops( const tripoint &, Creature *c, item * ) } else { z->moves -= 80; } - c->deal_damage( nullptr, bp_foot_l, damage_instance( DT_CUT, rng( 9, 15 ) ) ); - c->deal_damage( nullptr, bp_foot_r, damage_instance( DT_CUT, rng( 9, 15 ) ) ); + c->deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, rng( 9, 15 ) ) ); + c->deal_damage( nullptr, bodypart_id( "foot_r" ), damage_instance( DT_CUT, rng( 9, 15 ) ) ); } else { - c->deal_damage( nullptr, bp_foot_l, damage_instance( DT_CUT, rng( 9, 30 ) ) ); - c->deal_damage( nullptr, bp_foot_r, damage_instance( DT_CUT, rng( 9, 30 ) ) ); + c->deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, rng( 9, 30 ) ) ); + c->deal_damage( nullptr, bodypart_id( "foot_r" ), damage_instance( DT_CUT, rng( 9, 30 ) ) ); } c->check_dead_state(); return true; @@ -256,11 +256,11 @@ bool trapfunc::caltrops_glass( const tripoint &p, Creature *c, item * ) monster *z = dynamic_cast( c ); if( z != nullptr ) { z->moves -= 80; - c->deal_damage( nullptr, bp_foot_l, damage_instance( DT_CUT, rng( 9, 15 ) ) ); - c->deal_damage( nullptr, bp_foot_r, damage_instance( DT_CUT, rng( 9, 15 ) ) ); + c->deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, rng( 9, 15 ) ) ); + c->deal_damage( nullptr, bodypart_id( "foot_r" ), damage_instance( DT_CUT, rng( 9, 15 ) ) ); } else { - c->deal_damage( nullptr, bp_foot_l, damage_instance( DT_CUT, rng( 9, 30 ) ) ); - c->deal_damage( nullptr, bp_foot_r, damage_instance( DT_CUT, rng( 9, 30 ) ) ); + c->deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, rng( 9, 30 ) ) ); + c->deal_damage( nullptr, bodypart_id( "foot_r" ), damage_instance( DT_CUT, rng( 9, 30 ) ) ); } c->check_dead_state(); if( g->u.sees( p ) ) { @@ -304,7 +304,7 @@ bool trapfunc::tripwire( const tripoint &p, Creature *c, item * ) z->stumble(); } if( rng( 0, 10 ) > z->get_dodge() ) { - z->deal_damage( nullptr, bp_torso, damage_instance( DT_TRUE, rng( 1, 4 ) ) ); + z->deal_damage( nullptr, bodypart_id( "torso" ), damage_instance( DT_TRUE, rng( 1, 4 ) ) ); } } else if( n != nullptr ) { std::vector valid; @@ -345,22 +345,22 @@ bool trapfunc::crossbow( const tripoint &p, Creature *c, item * ) if( n != nullptr ) { ///\EFFECT_DODGE reduces chance of being hit by crossbow trap if( !one_in( 4 ) && rng( 8, 20 ) > n->get_dodge() ) { - body_part hit = num_bp; + bodypart_id hit = bodypart_id( " num_bp" ); switch( rng( 1, 10 ) ) { case 1: if( one_in( 2 ) ) { - hit = bp_foot_l; + hit = bodypart_id( "foot_l" ); } else { - hit = bp_foot_r; + hit = bodypart_id( "foot_r" ); } break; case 2: case 3: case 4: if( one_in( 2 ) ) { - hit = bp_leg_l; + hit = bodypart_id( "leg_l" ); } else { - hit = bp_leg_r; + hit = bodypart_id( "leg_r" ); } break; case 5: @@ -368,14 +368,14 @@ bool trapfunc::crossbow( const tripoint &p, Creature *c, item * ) case 7: case 8: case 9: - hit = bp_torso; + hit = bodypart_id( "torso" ); break; case 10: - hit = bp_head; + hit = bodypart_id( "head" ); break; } //~ %s is bodypart - n->add_msg_if_player( m_bad, _( "Your %s is hit!" ), body_part_name( hit ) ); + n->add_msg_if_player( m_bad, _( "Your %s is hit!" ), body_part_name( hit->token ) ); c->deal_damage( nullptr, hit, damage_instance( DT_CUT, rng( 20, 30 ) ) ); add_bolt = !one_in( 10 ); } else { @@ -407,7 +407,7 @@ bool trapfunc::crossbow( const tripoint &p, Creature *c, item * ) if( seen ) { add_msg( m_bad, _( "A bolt shoots out and hits the %s!" ), z->name() ); } - z->deal_damage( nullptr, bp_torso, damage_instance( DT_CUT, rng( 20, 30 ) ) ); + z->deal_damage( nullptr, bodypart_id( "torso" ), damage_instance( DT_CUT, rng( 20, 30 ) ) ); add_bolt = !one_in( 10 ); } else if( seen ) { add_msg( m_neutral, _( "A bolt shoots out, but misses the %s." ), z->name() ); @@ -445,22 +445,22 @@ bool trapfunc::shotgun( const tripoint &p, Creature *c, item * ) } ///\EFFECT_DODGE reduces chance of being hit by shotgun trap if( rng( 5, 50 ) > n->get_dodge() ) { - body_part hit = num_bp; + bodypart_id hit = bodypart_id( "num_bp" ); switch( rng( 1, 10 ) ) { case 1: if( one_in( 2 ) ) { - hit = bp_foot_l; + hit = bodypart_id( "foot_l" ); } else { - hit = bp_foot_r; + hit = bodypart_id( "foot_r" ); } break; case 2: case 3: case 4: if( one_in( 2 ) ) { - hit = bp_leg_l; + hit = bodypart_id( "leg_l" ); } else { - hit = bp_leg_r; + hit = bodypart_id( "leg_r" ); } break; case 5: @@ -468,14 +468,14 @@ bool trapfunc::shotgun( const tripoint &p, Creature *c, item * ) case 7: case 8: case 9: - hit = bp_torso; + hit = bodypart_id( "torso" ); break; case 10: - hit = bp_head; + hit = bodypart_id( "head" ); break; } //~ %s is bodypart - n->add_msg_if_player( m_bad, _( "Your %s is hit!" ), body_part_name( hit ) ); + n->add_msg_if_player( m_bad, _( "Your %s is hit!" ), body_part_name( hit->token ) ); c->deal_damage( nullptr, hit, damage_instance( DT_CUT, rng( 40 * shots, 60 * shots ) ) ); } else { n->add_msg_player_or_npc( m_neutral, _( "You dodge the shot!" ), @@ -508,7 +508,8 @@ bool trapfunc::shotgun( const tripoint &p, Creature *c, item * ) if( seen ) { add_msg( m_bad, _( "A shotgun fires and hits the %s!" ), z->name() ); } - z->deal_damage( nullptr, bp_torso, damage_instance( DT_CUT, rng( 40 * shots, 60 * shots ) ) ); + z->deal_damage( nullptr, bodypart_id( "torso" ), damage_instance( DT_CUT, rng( 40 * shots, + 60 * shots ) ) ); } c->check_dead_state(); } @@ -532,7 +533,7 @@ bool trapfunc::blade( const tripoint &, Creature *c, item * ) damage_instance d; d.add_damage( DT_BASH, 12 ); d.add_damage( DT_CUT, 30 ); - c->deal_damage( nullptr, bp_torso, d ); + c->deal_damage( nullptr, bodypart_id( "torso" ), d ); c->check_dead_state(); return true; } @@ -545,7 +546,7 @@ bool trapfunc::snare_light( const tripoint &p, Creature *c, item * ) return false; } // Determine what gets hit - const body_part hit = one_in( 2 ) ? bp_leg_l : bp_leg_r; + const bodypart_id hit = one_in( 2 ) ? bodypart_id( "leg_l" ) : bodypart_id( "leg_r" ); // Messages if( c->has_effect( effect_ridden ) ) { add_msg( m_bad, _( "A snare closes on your %s's leg!" ), c->get_name() ); @@ -554,7 +555,7 @@ bool trapfunc::snare_light( const tripoint &p, Creature *c, item * ) _( "A snare closes on s leg." ) ); // Actual effects - c->add_effect( effect_lightsnare, 1_turns, hit, true ); + c->add_effect( effect_lightsnare, 1_turns, hit->token, true ); monster *z = dynamic_cast( c ); if( z != nullptr && z->type->size == MS_TINY ) { z->deal_damage( nullptr, hit, damage_instance( DT_BASH, 10 ) ); @@ -571,16 +572,16 @@ bool trapfunc::snare_heavy( const tripoint &p, Creature *c, item * ) return false; } // Determine what got hit - const body_part hit = one_in( 2 ) ? bp_leg_l : bp_leg_r; + const bodypart_id hit = one_in( 2 ) ? bodypart_id( "leg_l" ) : bodypart_id( "leg_r" ); if( c->has_effect( effect_ridden ) ) { add_msg( m_bad, _( "A snare closes on your %s's leg!" ), c->get_name() ); } //~ %s is bodypart name in accusative. c->add_msg_player_or_npc( m_bad, _( "A snare closes on your %s." ), - _( "A snare closes on s %s." ), body_part_name_accusative( hit ) ); + _( "A snare closes on s %s." ), body_part_name_accusative( hit->token ) ); // Actual effects - c->add_effect( effect_heavysnare, 1_turns, hit, true ); + c->add_effect( effect_heavysnare, 1_turns, hit->token, true ); monster *z = dynamic_cast( c ); player *n = dynamic_cast( c ); if( n != nullptr ) { @@ -665,8 +666,8 @@ bool trapfunc::goo( const tripoint &p, Creature *c, item * ) n->add_env_effect( effect_slimed, bp_foot_r, 6, 2_minutes ); if( one_in( 3 ) ) { n->add_msg_if_player( m_bad, _( "The acidic goo eats away at your feet." ) ); - n->deal_damage( nullptr, bp_foot_l, damage_instance( DT_CUT, 5 ) ); - n->deal_damage( nullptr, bp_foot_r, damage_instance( DT_CUT, 5 ) ); + n->deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, 5 ) ); + n->deal_damage( nullptr, bodypart_id( "foot_r" ), damage_instance( DT_CUT, 5 ) ); n->check_dead_state(); } return true; @@ -711,16 +712,16 @@ bool trapfunc::dissector( const tripoint &p, Creature *c, item * ) // distribute damage amongst player and horse if( z->has_effect( effect_ridden ) && z->mounted_player ) { Character *ch = z->mounted_player; - ch->deal_damage( nullptr, bp_head, damage_instance( DT_CUT, 15 ) ); - ch->deal_damage( nullptr, bp_torso, damage_instance( DT_CUT, 20 ) ); - ch->deal_damage( nullptr, bp_arm_r, damage_instance( DT_CUT, 12 ) ); - ch->deal_damage( nullptr, bp_arm_l, damage_instance( DT_CUT, 12 ) ); - ch->deal_damage( nullptr, bp_hand_r, damage_instance( DT_CUT, 10 ) ); - ch->deal_damage( nullptr, bp_hand_l, damage_instance( DT_CUT, 10 ) ); - ch->deal_damage( nullptr, bp_leg_r, damage_instance( DT_CUT, 12 ) ); - ch->deal_damage( nullptr, bp_leg_r, damage_instance( DT_CUT, 12 ) ); - ch->deal_damage( nullptr, bp_foot_l, damage_instance( DT_CUT, 10 ) ); - ch->deal_damage( nullptr, bp_foot_r, damage_instance( DT_CUT, 10 ) ); + ch->deal_damage( nullptr, bodypart_id( "head" ), damage_instance( DT_CUT, 15 ) ); + ch->deal_damage( nullptr, bodypart_id( "torso" ), damage_instance( DT_CUT, 20 ) ); + ch->deal_damage( nullptr, bodypart_id( "arm_r" ), damage_instance( DT_CUT, 12 ) ); + ch->deal_damage( nullptr, bodypart_id( "arm_l" ), damage_instance( DT_CUT, 12 ) ); + ch->deal_damage( nullptr, bodypart_id( "hand_r" ), damage_instance( DT_CUT, 10 ) ); + ch->deal_damage( nullptr, bodypart_id( "hand_l" ), damage_instance( DT_CUT, 10 ) ); + ch->deal_damage( nullptr, bodypart_id( "leg_r" ), damage_instance( DT_CUT, 12 ) ); + ch->deal_damage( nullptr, bodypart_id( "leg_r" ), damage_instance( DT_CUT, 12 ) ); + ch->deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, 10 ) ); + ch->deal_damage( nullptr, bodypart_id( "foot_r" ), damage_instance( DT_CUT, 10 ) ); if( g->u.sees( p ) ) { ch->add_msg_player_or_npc( m_bad, _( "Electrical beams emit from the floor and slice your flesh!" ), _( "Electrical beams emit from the floor and slice s flesh!" ) ); @@ -734,16 +735,16 @@ bool trapfunc::dissector( const tripoint &p, Creature *c, item * ) if( g->u.sees( p ) ) { add_msg( m_bad, _( "Electrical beams emit from the floor and slice the %s!" ), c->get_name() ); } - c->deal_damage( nullptr, bp_head, damage_instance( DT_CUT, 15 ) ); - c->deal_damage( nullptr, bp_torso, damage_instance( DT_CUT, 20 ) ); - c->deal_damage( nullptr, bp_arm_r, damage_instance( DT_CUT, 12 ) ); - c->deal_damage( nullptr, bp_arm_l, damage_instance( DT_CUT, 12 ) ); - c->deal_damage( nullptr, bp_hand_r, damage_instance( DT_CUT, 10 ) ); - c->deal_damage( nullptr, bp_hand_l, damage_instance( DT_CUT, 10 ) ); - c->deal_damage( nullptr, bp_leg_r, damage_instance( DT_CUT, 12 ) ); - c->deal_damage( nullptr, bp_leg_r, damage_instance( DT_CUT, 12 ) ); - c->deal_damage( nullptr, bp_foot_l, damage_instance( DT_CUT, 10 ) ); - c->deal_damage( nullptr, bp_foot_r, damage_instance( DT_CUT, 10 ) ); + c->deal_damage( nullptr, bodypart_id( "head" ), damage_instance( DT_CUT, 15 ) ); + c->deal_damage( nullptr, bodypart_id( "torso" ), damage_instance( DT_CUT, 20 ) ); + c->deal_damage( nullptr, bodypart_id( "arm_r" ), damage_instance( DT_CUT, 12 ) ); + c->deal_damage( nullptr, bodypart_id( "arm_l" ), damage_instance( DT_CUT, 12 ) ); + c->deal_damage( nullptr, bodypart_id( "hand_r" ), damage_instance( DT_CUT, 10 ) ); + c->deal_damage( nullptr, bodypart_id( "hand_l" ), damage_instance( DT_CUT, 10 ) ); + c->deal_damage( nullptr, bodypart_id( "leg_r" ), damage_instance( DT_CUT, 12 ) ); + c->deal_damage( nullptr, bodypart_id( "leg_r" ), damage_instance( DT_CUT, 12 ) ); + c->deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_CUT, 10 ) ); + c->deal_damage( nullptr, bodypart_id( "foot_r" ), damage_instance( DT_CUT, 10 ) ); c->check_dead_state(); return true; @@ -778,8 +779,8 @@ bool trapfunc::pit( const tripoint &p, Creature *c, item * ) n->add_msg_if_player( m_bad, _( "You hurt yourself!" ) ); // like the message says \-: n->hurtall( rng( static_cast( damage / 2 ), damage ), n ); - n->deal_damage( nullptr, bp_leg_l, damage_instance( DT_BASH, damage ) ); - n->deal_damage( nullptr, bp_leg_r, damage_instance( DT_BASH, damage ) ); + n->deal_damage( nullptr, bodypart_id( "leg_l" ), damage_instance( DT_BASH, damage ) ); + n->deal_damage( nullptr, bodypart_id( "leg_r" ), damage_instance( DT_BASH, damage ) ); } else { n->add_msg_if_player( _( "You land nimbly." ) ); } @@ -789,8 +790,8 @@ bool trapfunc::pit( const tripoint &p, Creature *c, item * ) add_msg( m_bad, _( "Your %s falls into a pit!" ), z->get_name() ); g->u.forced_dismount(); } - z->deal_damage( nullptr, bp_leg_l, damage_instance( DT_BASH, eff * rng( 10, 20 ) ) ); - z->deal_damage( nullptr, bp_leg_r, damage_instance( DT_BASH, eff * rng( 10, 20 ) ) ); + z->deal_damage( nullptr, bodypart_id( "leg_l" ), damage_instance( DT_BASH, eff * rng( 10, 20 ) ) ); + z->deal_damage( nullptr, bodypart_id( "leg_r" ), damage_instance( DT_BASH, eff * rng( 10, 20 ) ) ); } c->check_dead_state(); return true; @@ -823,19 +824,19 @@ bool trapfunc::pit_spikes( const tripoint &p, Creature *c, item * ) } else if( 0 == damage || rng( 5, 30 ) < dodge ) { n->add_msg_if_player( _( "You avoid the spikes within." ) ); } else { - body_part hit = num_bp; + bodypart_id hit( "num_bp" ); switch( rng( 1, 10 ) ) { case 1: - hit = bp_leg_l; + hit = bodypart_id( "leg_l" ); break; case 2: - hit = bp_leg_r; + hit = bodypart_id( "leg_r" ); break; case 3: - hit = bp_arm_l; + hit = bodypart_id( "arm_l" ); break; case 4: - hit = bp_arm_r; + hit = bodypart_id( "arm_r" ); break; case 5: case 6: @@ -843,11 +844,11 @@ bool trapfunc::pit_spikes( const tripoint &p, Creature *c, item * ) case 8: case 9: case 10: - hit = bp_torso; + hit = bodypart_id( "torso" ); break; } n->add_msg_if_player( m_bad, _( "The spikes impale your %s!" ), - body_part_name_accusative( hit ) ); + body_part_name_accusative( hit->token ) ); n->deal_damage( nullptr, hit, damage_instance( DT_CUT, damage ) ); if( ( n->has_trait( trait_INFRESIST ) ) && ( one_in( 256 ) ) ) { n->add_effect( effect_tetanus, 1_turns, num_bp, true ); @@ -861,7 +862,7 @@ bool trapfunc::pit_spikes( const tripoint &p, Creature *c, item * ) add_msg( m_bad, _( "Your %s falls into a pit!" ), z->get_name() ); g->u.forced_dismount(); } - z->deal_damage( nullptr, bp_torso, damage_instance( DT_CUT, rng( 20, 50 ) ) ); + z->deal_damage( nullptr, bodypart_id( "torso" ), damage_instance( DT_CUT, rng( 20, 50 ) ) ); } c->check_dead_state(); if( one_in( 4 ) ) { @@ -906,35 +907,35 @@ bool trapfunc::pit_glass( const tripoint &p, Creature *c, item * ) } else if( 0 == damage || rng( 5, 30 ) < dodge ) { n->add_msg_if_player( _( "You avoid the glass shards within." ) ); } else { - body_part hit = num_bp; + bodypart_id hit( " num_bp" ); switch( rng( 1, 10 ) ) { case 1: - hit = bp_leg_l; + hit = bodypart_id( "leg_l" ); break; case 2: - hit = bp_leg_r; + hit = bodypart_id( "leg_r" ); break; case 3: - hit = bp_arm_l; + hit = bodypart_id( "arm_l" ); break; case 4: - hit = bp_arm_r; + hit = bodypart_id( "arm_r" ); break; case 5: - hit = bp_foot_l; + hit = bodypart_id( "foot_l" ); break; case 6: - hit = bp_foot_r; + hit = bodypart_id( "foot_r" ); break; case 7: case 8: case 9: case 10: - hit = bp_torso; + hit = bodypart_id( "torso" ); break; } n->add_msg_if_player( m_bad, _( "The glass shards slash your %s!" ), - body_part_name_accusative( hit ) ); + body_part_name_accusative( hit->token ) ); n->deal_damage( nullptr, hit, damage_instance( DT_CUT, damage ) ); if( ( n->has_trait( trait_INFRESIST ) ) && ( one_in( 256 ) ) ) { n->add_effect( effect_tetanus, 1_turns, num_bp, true ); @@ -948,7 +949,7 @@ bool trapfunc::pit_glass( const tripoint &p, Creature *c, item * ) add_msg( m_bad, _( "Your %s falls into a pit!" ), z->get_name() ); g->u.forced_dismount(); } - z->deal_damage( nullptr, bp_torso, damage_instance( DT_CUT, rng( 20, 50 ) ) ); + z->deal_damage( nullptr, bodypart_id( "torso" ), damage_instance( DT_CUT, rng( 20, 50 ) ) ); } c->check_dead_state(); if( one_in( 5 ) ) { @@ -976,10 +977,10 @@ bool trapfunc::lava( const tripoint &p, Creature *c, item * ) monster *z = dynamic_cast( c ); player *n = dynamic_cast( c ); if( n != nullptr ) { - n->deal_damage( nullptr, bp_foot_l, damage_instance( DT_HEAT, 20 ) ); - n->deal_damage( nullptr, bp_foot_r, damage_instance( DT_HEAT, 20 ) ); - n->deal_damage( nullptr, bp_leg_l, damage_instance( DT_HEAT, 20 ) ); - n->deal_damage( nullptr, bp_leg_r, damage_instance( DT_HEAT, 20 ) ); + n->deal_damage( nullptr, bodypart_id( "foot_l" ), damage_instance( DT_HEAT, 20 ) ); + n->deal_damage( nullptr, bodypart_id( "foot_r" ), damage_instance( DT_HEAT, 20 ) ); + n->deal_damage( nullptr, bodypart_id( "leg_l" ), damage_instance( DT_HEAT, 20 ) ); + n->deal_damage( nullptr, bodypart_id( "leg_r" ), damage_instance( DT_HEAT, 20 ) ); } else if( z != nullptr ) { if( z->has_effect( effect_ridden ) ) { add_msg( m_bad, _( "Your %s is burned by the lava!" ), z->get_name() ); @@ -1001,7 +1002,7 @@ bool trapfunc::lava( const tripoint &p, Creature *c, item * ) if( z->made_of( material_id( "kevlar" ) ) || z->made_of( material_id( "steel" ) ) ) { dam = 5; } - z->deal_damage( nullptr, bp_torso, damage_instance( DT_HEAT, dam ) ); + z->deal_damage( nullptr, bodypart_id( "torso" ), damage_instance( DT_HEAT, dam ) ); } c->check_dead_state(); return true; @@ -1284,7 +1285,7 @@ bool trapfunc::glow( const tripoint &p, Creature *c, item * ) player *n = dynamic_cast( c ); if( z != nullptr ) { if( one_in( 3 ) ) { - z->deal_damage( nullptr, bp_torso, damage_instance( DT_ACID, rng( 5, 10 ) ) ); + z->deal_damage( nullptr, bodypart_id( "torso" ), damage_instance( DT_ACID, rng( 5, 10 ) ) ); z->set_speed_base( z->get_speed_base() * 0.9 ); } if( z->has_effect( effect_ridden ) ) { @@ -1392,7 +1393,7 @@ bool trapfunc::drain( const tripoint &, Creature *c, item * ) if( n != nullptr ) { n->hurtall( 1, nullptr ); } else if( z != nullptr ) { - z->deal_damage( nullptr, bp_torso, damage_instance( DT_TRUE, 1 ) ); + z->deal_damage( nullptr, bodypart_id( "torso" ), damage_instance( DT_TRUE, 1 ) ); } c->check_dead_state(); return true;