Skip to content

Commit

Permalink
Fix: skipping attacks if hero moved away.
Browse files Browse the repository at this point in the history
From EvilHack commits 76c41f049a3dfba2cb6c9ea5d864ea0c70cd84a4 and 6a76d5f0c0b83e1e0dee05de6fbb65a819119b1c.
---
From NetHack 3.7 git commits 4b78763 and 85137bb (modified):

'While polymorphed and underwater, an eel bite killed the hero who
rehumaized and crawled out of the water, then the eel continued with
its second attack and "wrapped itself around you" even though no
longer adjacent.  That's a long reach....

| ...@.
| .;}..
| .}}..

Make any additional attacks silently miss if hero changes location
during the attack sequence of a monster who has pinpointed the hero.'

Resolves EvilHack issue #147 (The piranha attacks you without knowing your
location?)
  • Loading branch information
elunna committed Sep 26, 2023
1 parent fd889b2 commit 8ec306d
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/mhitu.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,19 +607,23 @@ register struct monst *mtmp;
struct attack *mattk, alt_attk;
int i, j, k = 0, tmp, ftmp, sum[NATTK];
struct permonst *mdat = mtmp->data;
/*
* ranged: Is it near you? Affects your actions.
* ranged2: Does it think it's near you? Affects its actions.
* foundyou: Is it attacking you or your image?
* youseeit: Can you observe the attack? It might be attacking your
* image around the corner, or invisible, or you might be blind.
* skipnonmagc: Are further physical attack attempts useless? (After
* a wild miss--usually due to attacking displaced image. Avoids
* excessively verbose miss feedback when monster can do multiple
* attacks and would miss the same wrong spot each time.)
*/
struct obj * marmf = which_armor(mtmp, W_ARMF);
boolean ranged = (distu(mtmp->mx, mtmp->my) > 3);
/* Is it near you? Affects your actions */
boolean range2 = !monnear(mtmp, mtmp->mux, mtmp->muy);
/* Does it think it's near you? Affects its actions */
boolean foundyou = (mtmp->mux == u.ux && mtmp->muy == u.uy);
/* Is it attacking you or your image? */
boolean youseeit = canseemon(mtmp);
/* Might be attacking your image around the corner, or
* invisible, or you might be blind....
*/
boolean skipnonmagc = FALSE;
/* Are further physical attack attempts useless? */
boolean firstfoundyou, skipnonmagc = FALSE;

if (!ranged)
nomul(0);
Expand Down Expand Up @@ -975,9 +979,14 @@ register struct monst *mtmp;
k = 100;
}

firstfoundyou = foundyou;

for (i = 0; i < NATTK; i++) {
sum[i] = 0;
mon_currwep = (struct obj *)0;
if (i > 0 && firstfoundyou /* previous attack might have moved hero */
&& (mtmp->mux != u.ux || mtmp->muy != u.uy))
continue; /* fill in sum[] with 'miss' but skip other actions */
mon_currwep = (struct obj *) 0;
mattk = getmattk(mtmp, &youmonst, i, sum, &alt_attk);
if ((u.uswallow && mattk->aatyp != AT_ENGL)
|| (skipnonmagc && mattk->aatyp != AT_MAGC))
Expand Down

0 comments on commit 8ec306d

Please sign in to comment.