diff --git a/data/test/scenarios/test_unit_map.cfg b/data/test/scenarios/test_unit_map.cfg index 9d782df6365..fd204a3cb8a 100644 --- a/data/test/scenarios/test_unit_map.cfg +++ b/data/test/scenarios/test_unit_map.cfg @@ -122,6 +122,26 @@ [/do_command] {ASSERT_NO_9_5} + [event] + name = pre attack + first_time_only = yes + {ASSERT_YES_9_5} + [move_unit] + x,y=9,5 + to_x,to_y=10,5 + [/move_unit] + [/event] + + [event] + name = attack + first_time_only = yes + {ASSERT_NO_9_5} + [move_unit] + x,y=10,5 + to_x,to_y=9,5 + [/move_unit] + [/event] + {UNIT 2 "Spearman" 9 5 (id=steve7)} {ASSERT_YES_9_5} [do_command] diff --git a/src/actions/attack.cpp b/src/actions/attack.cpp index d92bb3c3b27..4dc45028228 100644 --- a/src/actions/attack.cpp +++ b/src/actions/attack.cpp @@ -1367,6 +1367,25 @@ void attack::perform() return; } + bc_.reset(new battle_context(units_, a_.loc_, d_.loc_, a_.weapon_, d_.weapon_)); + + a_stats_ = &bc_->get_attacker_stats(); + d_stats_ = &bc_->get_defender_stats(); + + if(a_stats_->weapon) { + a_.weap_id_ = a_stats_->weapon->id(); + } + + if(d_stats_->weapon) { + d_.weap_id_ = d_stats_->weapon->id(); + } + + try { + fire_event("pre_attack"); + } catch(const attack_end_exception&) { + return; + } + a_.get_unit().set_facing(a_.loc_.get_relative_dir(d_.loc_)); d_.get_unit().set_facing(d_.loc_.get_relative_dir(a_.loc_)); @@ -1383,32 +1402,17 @@ void attack::perform() // If the attacker was invisible, she isn't anymore! a_.get_unit().set_state(unit::STATE_UNCOVERED, true); - bc_.reset(new battle_context(units_, a_.loc_, d_.loc_, a_.weapon_, d_.weapon_)); - - a_stats_ = &bc_->get_attacker_stats(); - d_stats_ = &bc_->get_defender_stats(); - if(a_stats_->disable) { LOG_NG << "attack::perform(): tried to attack with a disabled attack."; return; } - if(a_stats_->weapon) { - a_.weap_id_ = a_stats_->weapon->id(); - } - - if(d_stats_->weapon) { - d_.weap_id_ = d_stats_->weapon->id(); - } - try { fire_event("attack"); } catch(const attack_end_exception&) { return; } - refresh_bc(); - DBG_NG << "getting attack statistics"; statistics::attack_context attack_stats( a_.get_unit(), d_.get_unit(), a_stats_->chance_to_hit, d_stats_->chance_to_hit);