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

Change body_part to bodypart_id in deal_damage #39890

Merged
merged 2 commits into from
Apr 26, 2020
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
96 changes: 39 additions & 57 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -8401,7 +8401,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 ) ) {
Expand All @@ -8413,6 +8413,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 );
Expand All @@ -8421,8 +8423,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 );
}
}

Expand Down Expand Up @@ -8466,51 +8468,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 );
Expand Down Expand Up @@ -8546,7 +8528,7 @@ dealt_damage_instance Character::deal_damage( Creature *source, body_part bp,
if( get_option<bool>( "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();
}
}
Expand All @@ -8559,12 +8541,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." ) );
}
Expand Down Expand Up @@ -8686,7 +8668,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<hp_part>( i ) );
const bodypart_id bp = convert_bp( hp_to_bp( static_cast<hp_part>( i ) ) ).id();
int ddam = vary ? dam * rng( 100 - vary, 100 ) / 100 : dam;
int cut = 0;
auto damage = damage_instance::physical( ddam, cut, 0 );
Expand Down
2 changes: 1 addition & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ class Character : public Creature, public visitable<Character>
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 );
Expand Down
22 changes: 12 additions & 10 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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() ) {
Expand All @@ -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;
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,26 +320,26 @@ static void do_blast( const tripoint &p, const float power,
_( "<npcname> 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<blastable_part, 6> 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();
Expand Down
36 changes: 18 additions & 18 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4496,15 +4496,15 @@ void game::knockback( std::vector<tripoint> &traj, int stun, int dam_mult )
add_msg( _( "%s was stunned!" ), targ->name );
}

std::array<body_part, 8> 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<bodypart_id, 8> 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 ) );
}
Expand Down Expand Up @@ -4570,15 +4570,15 @@ void game::knockback( std::vector<tripoint> &traj, int stun, int dam_mult )
force_remaining );
}
u.add_effect( effect_stunned, 1_turns * force_remaining );
std::array<body_part, 8> 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<bodypart_id, 8> 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 ) );
}
Expand Down Expand Up @@ -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
Expand All @@ -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 ) ) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>( vol * .5 ) ) ) );
}
u.remove_weapon();
Expand Down
Loading