diff options
author | Charles Otto <ottochar@gmail.com> | 2009-11-14 15:16:20 -0500 |
---|---|---|
committer | Charles Otto <ottochar@gmail.com> | 2009-11-14 15:18:05 -0500 |
commit | 94f5f2f5190977bdb792bb94752836f4d76016dc (patch) | |
tree | 4ecab492dd345c0675d652955786b8fcd3925b37 /crawl-ref/source/fight.cc | |
parent | 94b9505063ae8907948a0e2b2ea3633499a94a77 (diff) | |
download | crawl-ref-94f5f2f5190977bdb792bb94752836f4d76016dc.tar.gz crawl-ref-94f5f2f5190977bdb792bb94752836f4d76016dc.zip |
Fix an issue with noise generation in melee combat
Noise generated by attacking in melee range is handled by
melee_attack::handle_noise. handle_noise was using defender->pos() as
the point of origin for the noise, but defender->pos() is not reliable
in some situations, if a monster is killed its position is reset to
zero. I added a coord_def parameter to handle_noise to use as the point
of origin instead of trying to use defender->pos and made all calls to
handle_monster store the defender's position prior to damage being
applied.
Aside from creating noise in the wrong area calling noisy with a
position of (0, 0) can cause an assertion failure at mon-behv.cc,
line 1609 in some situations.
Diffstat (limited to 'crawl-ref/source/fight.cc')
-rw-r--r-- | crawl-ref/source/fight.cc | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc index bc90cc39de..0090ce03e0 100644 --- a/crawl-ref/source/fight.cc +++ b/crawl-ref/source/fight.cc @@ -583,6 +583,8 @@ bool melee_attack::attack() identify_mimic(attacker); identify_mimic(defender); + coord_def defender_pos = defender->pos(); + if (attacker->atype() == ACT_PLAYER && defender->atype() == ACT_MONSTER) { if (stop_attack_prompt(defender_as_monster(), false, attacker->pos())) @@ -715,7 +717,7 @@ bool melee_attack::attack() if (attacker->atype() == ACT_PLAYER) { - handle_noise(); + handle_noise(defender_pos); if (damage_brand == SPWPN_CHAOS) chaos_affects_attacker(); @@ -988,6 +990,7 @@ bool melee_attack::player_aux_unarmed() bool simple_miss_message = false; std::string miss_verb; + coord_def defender_pos = defender->pos(); if (can_do_unarmed) { if (you.species == SP_NAGA) @@ -1262,7 +1265,7 @@ bool melee_attack::player_aux_unarmed() make_hungry(2, true); - handle_noise(); + handle_noise(defender_pos); alert_nearby_monsters(); // XXX We're clobbering did_hit @@ -3451,7 +3454,7 @@ bool melee_attack::apply_damage_brand() // // * Randart property to make randart weapons louder or softer when // they hit. -void melee_attack::handle_noise() +void melee_attack::handle_noise(const coord_def & pos) { // Successful stabs make no noise. if (stab_attempt) @@ -3467,7 +3470,7 @@ void melee_attack::handle_noise() level = std::max(1, level); if (level > 0) - noisy(level, defender->pos(), attacker->mindex()); + noisy(level, pos, attacker->mindex()); noise_factor = 0; extra_noise = 0; @@ -5142,7 +5145,7 @@ void melee_attack::mons_perform_attack_rounds() { const int nrounds = attacker_as_monster()->has_hydra_multi_attack() ? attacker_as_monster()->number : 4; - const coord_def pos = defender->pos(); + coord_def pos = defender->pos(); const bool was_delayed = you_are_delayed(); // Melee combat, tell attacker to wield its melee weapon. @@ -5152,7 +5155,8 @@ void melee_attack::mons_perform_attack_rounds() for (attack_number = 0; attack_number < nrounds; ++attack_number) { // Handle noise from previous round. - handle_noise(); + if(attack_number > 0) + handle_noise(pos); // Monster went away? if (!defender->alive() || defender->pos() != pos) @@ -5184,6 +5188,7 @@ void melee_attack::mons_perform_attack_rounds() { defender = mons; end = false; + pos = mons->pos(); break; } } @@ -5521,7 +5526,7 @@ void melee_attack::mons_perform_attack_rounds() } // Handle noise from last round. - handle_noise(); + handle_noise(pos); if (def_copy) delete def_copy; |