From 1bf0e4e233a37d3e53167e432573f39fcb6712bf Mon Sep 17 00:00:00 2001 From: inogenous <123803852+inogenous@users.noreply.github.com> Date: Sat, 16 Dec 2023 13:02:34 +0100 Subject: [PATCH] Bugfix: Show correct bodypart in grabs Updates the message `The fat zombie grabs your right arm` so that the bodypart being used is the same bodypart that is used for the actual grab effect. Before, there could be cases where the message displayed a different bodypart than what was actually grabbed since `bp_id` might be changed by the call to `target->block_hit` after `do_grab` had completed. --- src/mattack_actors.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mattack_actors.cpp b/src/mattack_actors.cpp index 353921156e8c8..3f2167950abeb 100644 --- a/src/mattack_actors.cpp +++ b/src/mattack_actors.cpp @@ -745,6 +745,7 @@ bool melee_actor::call( monster &z ) const // We need to do some calculations in the main function - we might mutate bp_hit // But first we need to handle exclusive grabs etc. + std::optional grabbed_bp_id; if( is_grab ) { int eff_grab_strength = grab_data.grab_strength == -1 ? z.get_grab_strength() : grab_data.grab_strength; @@ -831,6 +832,7 @@ bool melee_actor::call( monster &z ) const } else if( result == 0 ) { return true; } + grabbed_bp_id = bp_id; } // Damage instance calculation @@ -870,7 +872,7 @@ bool melee_actor::call( monster &z ) const sfx::get_heard_angle( z.pos() ) ); target->add_msg_player_or_npc( msg_type, no_dmg_msg_u, get_option( "LOG_MONSTER_ATTACK_MONSTER" ) ? no_dmg_msg_npc : to_translation( "" ), - mon_name, body_part_name_accusative( bp_id ) ); + mon_name, body_part_name_accusative( grabbed_bp_id.value_or( bp_id ) ) ); if( !effects_require_dmg ) { for( const mon_effect_data &eff : effects ) { if( x_in_y( eff.chance, 100 ) ) {