Skip to content

Commit

Permalink
on_hit
Browse files Browse the repository at this point in the history
  • Loading branch information
Fris0uman committed Apr 27, 2020
1 parent 57de862 commit 8c07242
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8337,7 +8337,7 @@ void Character::did_hit( Creature &target )
enchantment_cache.cast_hit_you( *this, target );
}

void Character::on_hit( Creature *source, body_part /*bp_hit*/,
void Character::on_hit( Creature *source, bodypart_id /*bp_hit*/,
float /*difficulty*/, dealt_projectile_attack const *const /*proj*/ )
{
enchantment_cache.cast_hit_me( *this, source );
Expand Down
2 changes: 1 addition & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ class Character : public Creature, public visitable<Character>
public:

// any side effects that might happen when the Character is hit
void on_hit( Creature *source, body_part /*bp_hit*/,
void on_hit( Creature *source, bodypart_id /*bp_hit*/,
float /*difficulty*/, dealt_projectile_attack const * /*proj*/ ) override;
// any side effects that might happen when the Character hits a Creature
void did_hit( Creature &target );
Expand Down
2 changes: 1 addition & 1 deletion src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ void Creature::deal_melee_hit( Creature *source, int hit_spread, bool critical_h
mod_moves( -stab_moves );
}

on_hit( source, bp_token ); // trigger on-gethit events
on_hit( source, bp_hit ); // trigger on-gethit events
dealt_dam = deal_damage( source, bp_hit, d );
dealt_dam.bp_hit = bp_token;
}
Expand Down
2 changes: 1 addition & 1 deletion src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class Creature
* This creature just got hit by an attack - possibly special/ranged attack - from source.
* Players should train dodge, possibly counter-attack somehow.
*/
virtual void on_hit( Creature *source, body_part bp_hit = num_bp,
virtual void on_hit( Creature *source, bodypart_id bp_hit,
float difficulty = INT_MIN, dealt_projectile_attack const *proj = nullptr ) = 0;

virtual bool digging() const;
Expand Down
2 changes: 1 addition & 1 deletion src/mattack_actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ bool melee_actor::call( monster &z ) const
target->select_body_part( &z, hitspread ) :
*body_parts.pick();

target->on_hit( &z, bp_hit );
target->on_hit( &z, convert_bp( bp_hit ).id() );
dealt_damage_instance dealt_damage = target->deal_damage( &z, convert_bp( bp_hit ).id(), damage );
dealt_damage.bp_hit = bp_hit;

Expand Down
2 changes: 1 addition & 1 deletion src/melee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ void Character::melee_attack( Creature &t, bool allow_special, const matec_id &f
did_hit( t );
if( t.as_character() ) {
dealt_projectile_attack dp = dealt_projectile_attack();
t.as_character()->on_hit( this, body_part::num_bp, 0.0f, &dp );
t.as_character()->on_hit( this, bodypart_id( "num_bp" ), 0.0f, &dp );
}
return;
}
Expand Down
42 changes: 21 additions & 21 deletions src/monattack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ bool mattack::acid_barf( monster *z )
body_part_name_accusative( hit ) );
}

target->on_hit( z, hit, z->type->melee_skill );
target->on_hit( z, convert_bp( hit ).id(), z->type->melee_skill );

return true;
}
Expand Down Expand Up @@ -1823,7 +1823,7 @@ bool mattack::fungus_inject( monster *z )
body_part_name_accusative( hit->token ) );
}

target->on_hit( z, hit->token, z->type->melee_skill );
target->on_hit( z, hit, z->type->melee_skill );
g->u.check_dead_state();

return true;
Expand Down Expand Up @@ -1881,7 +1881,7 @@ bool mattack::fungus_bristle( monster *z )
body_part_name_accusative( hit->token ) );
}

target->on_hit( z, hit->token, z->type->melee_skill );
target->on_hit( z, hit, z->type->melee_skill );

return true;
}
Expand Down Expand Up @@ -2046,7 +2046,7 @@ bool mattack::fungus_fortify( monster *z )
body_part_name_accusative( hit->token ) );
}

target->on_hit( z, hit->token, z->type->melee_skill );
target->on_hit( z, hit, z->type->melee_skill );
g->u.check_dead_state();
return true;
}
Expand Down Expand Up @@ -2087,7 +2087,7 @@ bool mattack::impale( monster *z )
_( "The %1$s impales <npcname>'s torso!" ),
z->name() );

target->on_hit( z, bp_torso, z->type->melee_skill );
target->on_hit( z, bodypart_id( "torso" ), z->type->melee_skill );
if( one_in( 60 / ( dam + 20 ) ) ) {
if( target->is_player() || target->is_npc() ) {
target->as_character()->make_bleed( bp_torso, rng( 75_turns, 125_turns ), true );
Expand Down Expand Up @@ -2548,7 +2548,7 @@ bool mattack::tentacle( monster *z )
//~ 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->token ), dam );
g->u.deal_damage( z, hit, damage_instance( DT_BASH, dam ) );
target->on_hit( z, hit->token, z->type->melee_skill );
target->on_hit( z, hit, z->type->melee_skill );
g->u.check_dead_state();

return true;
Expand Down Expand Up @@ -4108,7 +4108,7 @@ bool mattack::stretch_bite( monster *z )
body_part_name_accusative( hit_token ) );
}

target->on_hit( z, hit_token, z->type->melee_skill );
target->on_hit( z, hit, z->type->melee_skill );

return true;
}
Expand Down Expand Up @@ -4188,7 +4188,7 @@ 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->token ), dam );
target->on_hit( z, hit->token, z->type->melee_skill );
target->on_hit( z, hit, z->type->melee_skill );

return true;
}
Expand Down Expand Up @@ -4315,7 +4315,7 @@ bool mattack::lunge( monster *z )
if( one_in( 6 ) ) {
target->add_effect( effect_downed, 3_turns );
}
target->on_hit( z, hit->token, z->type->melee_skill );
target->on_hit( z, hit, z->type->melee_skill );
target->check_dead_state();
return true;
}
Expand Down Expand Up @@ -4383,7 +4383,7 @@ bool mattack::longswipe( monster *z )
z->name(),
body_part_name_accusative( hit->token ) );
}
target->on_hit( z, hit->token, z->type->melee_skill );
target->on_hit( z, hit, z->type->melee_skill );
return true;
}
return false;
Expand Down Expand Up @@ -4423,7 +4423,7 @@ bool mattack::longswipe( monster *z )
z->name(),
body_part_name_accusative( bp_head ) );
}
target->on_hit( z, bp_head, z->type->melee_skill );
target->on_hit( z, bodypart_id( "head" ), z->type->melee_skill );
target->check_dead_state();

return true;
Expand Down Expand Up @@ -5141,31 +5141,31 @@ bool mattack::bio_op_takedown( monster *z )
return true;
}
// Yes, it has the CQC bionic.
body_part hit = num_bp;
bodypart_id hit( "num_bp" );
if( one_in( 2 ) ) {
hit = bp_leg_l;
hit = bodypart_id( "leg_l" );
} else {
hit = bp_leg_r;
hit = bodypart_id( "leg_r" );
}
// Weak kick to start with, knocks you off your footing

// TODO: Literally "The zombie kicks" vvvvv | Fix message or comment why Literally.
//~ 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, convert_bp( hit ).id(), damage_instance( DT_BASH, dam ) );
body_part_name_accusative( hit->token ), dam );
foe->deal_damage( z, hit, 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 ) ) {
if( one_in( 4 ) ) {
hit = bp_head;
hit = bodypart_id( "head" );
// 50% damage buff for the headshot.
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, bodypart_id( "head" ), damage_instance( DT_BASH, dam ) );
} else {
hit = bp_torso;
hit = bodypart_id( "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, bodypart_id( "torso" ), damage_instance( DT_BASH, dam ) );
Expand All @@ -5176,7 +5176,7 @@ bool mattack::bio_op_takedown( monster *z )
foe->martial_arts_data.selected_has_weapon( foe->weapon.typeId() ) ) &&
!thrown_by_judo( z ) ) {
// Saved by the tentacle-bracing! :)
hit = bp_torso;
hit = bodypart_id( "torso" );
dam = rng( 3, 9 );
target->add_msg_if_player( m_bad, _( "and slams you for %d damage!" ), dam );
foe->deal_damage( z, bodypart_id( "torso" ), damage_instance( DT_BASH, dam ) );
Expand Down Expand Up @@ -5262,7 +5262,7 @@ bool mattack::bio_op_impale( monster *z )
_( "but fails to penetrate <npcname>'s armor!" ) );
}

target->on_hit( z, hit->token, z->type->melee_skill );
target->on_hit( z, hit, z->type->melee_skill );
foe->check_dead_state();

return true;
Expand Down Expand Up @@ -5704,7 +5704,7 @@ bool mattack::stretch_attack( monster *z )
body_part_name_accusative( hit->token ) );
}

target->on_hit( z, hit->token, z->type->melee_skill );
target->on_hit( z, hit, z->type->melee_skill );

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,7 @@ void monster::deal_projectile_attack( Creature *source, dealt_projectile_attack

if( !is_hallucination() && attack.hit_critter == this ) {
// Maybe TODO: Get difficulty from projectile speed/size/missed_by
on_hit( source, bp_torso, INT_MIN, &attack );
on_hit( source, bodypart_id( "torso" ), INT_MIN, &attack );
}
}

Expand Down Expand Up @@ -2794,7 +2794,7 @@ void monster::on_dodge( Creature *, float )
// Currently does nothing, later should handle faction relations
}

void monster::on_hit( Creature *source, body_part,
void monster::on_hit( Creature *source, bodypart_id,
float, dealt_projectile_attack const *const proj )
{
if( is_hallucination() ) {
Expand Down
2 changes: 1 addition & 1 deletion src/monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ class monster : public Creature
// We just dodged an attack from something
void on_dodge( Creature *source, float difficulty ) override;
// Something hit us (possibly null source)
void on_hit( Creature *source, body_part bp_hit = num_bp,
void on_hit( Creature *source, bodypart_id bp_hit,
float difficulty = INT_MIN, dealt_projectile_attack const *proj = nullptr ) override;

/** Resets a given special to its monster type cooldown value */
Expand Down
10 changes: 6 additions & 4 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,14 +997,16 @@ void player::on_dodge( Creature *source, float difficulty )
}
}

void player::on_hit( Creature *source, body_part bp_hit,
void player::on_hit( Creature *source, bodypart_id bp_hit,
float /*difficulty*/, dealt_projectile_attack const *const proj )
{
check_dead_state();
if( source == nullptr || proj != nullptr ) {
return;
}

const body_part bp_hit_token = bp_hit->token;

bool u_see = g->u.sees( *this );
if( has_active_bionic( bionic_id( "bio_ods" ) ) && get_power_level() > 5_kJ ) {
if( is_player() ) {
Expand All @@ -1022,7 +1024,7 @@ void player::on_hit( Creature *source, body_part bp_hit,
// Should hit body part used for attack
source->deal_damage( this, bodypart_id( "torso" ), ods_shock_damage );
}
if( !wearing_something_on( bp_hit ) &&
if( !wearing_something_on( bp_hit_token ) &&
( has_trait( trait_SPINES ) || has_trait( trait_QUILLS ) ) ) {
int spine = rng( 1, has_trait( trait_QUILLS ) ? 20 : 8 );
if( !is_player() ) {
Expand All @@ -1040,7 +1042,7 @@ void player::on_hit( Creature *source, body_part bp_hit,
spine_damage.add_damage( DT_STAB, spine );
source->deal_damage( this, bodypart_id( "torso" ), spine_damage );
}
if( ( !( wearing_something_on( bp_hit ) ) ) && ( has_trait( trait_THORNS ) ) &&
if( ( !( wearing_something_on( bp_hit_token ) ) ) && ( has_trait( trait_THORNS ) ) &&
( !( source->has_weapon() ) ) ) {
if( !is_player() ) {
if( u_see ) {
Expand All @@ -1057,7 +1059,7 @@ void player::on_hit( Creature *source, body_part bp_hit,
// so safer to target the torso
source->deal_damage( this, bodypart_id( "torso" ), thorn_damage );
}
if( ( !( wearing_something_on( bp_hit ) ) ) && ( has_trait( trait_CF_HAIR ) ) ) {
if( ( !( wearing_something_on( bp_hit_token ) ) ) && ( has_trait( trait_CF_HAIR ) ) ) {
if( !is_player() ) {
if( u_see ) {
add_msg( _( "%1$s gets a load of %2$s's %3$s stuck in!" ), source->disp_name(),
Expand Down
2 changes: 1 addition & 1 deletion src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class player : public Character
/** Called after the player has successfully dodged an attack */
void on_dodge( Creature *source, float difficulty ) override;
/** Handles special defenses from an attack that hit us (source can be null) */
void on_hit( Creature *source, body_part bp_hit = num_bp,
void on_hit( Creature *source, bodypart_id bp_hit,
float difficulty = INT_MIN, dealt_projectile_attack const *proj = nullptr ) override;


Expand Down

0 comments on commit 8c07242

Please sign in to comment.