]> granicus.if.org Git - nethack/commitdiff
fix github issue #408 - stuck to distant mimic
authorPatR <rankin@nethack.org>
Mon, 9 Nov 2020 00:07:42 +0000 (16:07 -0800)
committerPatR <rankin@nethack.org>
Mon, 9 Nov 2020 00:07:42 +0000 (16:07 -0800)
Attacking a concealed mimic at range by applying a polearm
could make the hero be stuck to that mimic in addition to
bringing it out of hiding.  Only do that when adjacent.

This also adds a new sanity check when setting u.ustuck.
It may get triggered by other sticking activity since only
attacking has been tested.  The check must be explicitly
enabled by setting the wizard mode 'sanity_check' option.

Fixes #408

doc/fixes37.0
src/mon.c
src/uhitm.c

index 455db9ee2e0dbcadf73c7301824157e29acc4c15..9774892e71aab40e7f247354d9f7d585047273f3 100644 (file)
@@ -1,4 +1,4 @@
-NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.348 $ $NHDT-Date: 1604620981 2020/11/06 00:03:01 $
+NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.349 $ $NHDT-Date: 1604880453 2020/11/09 00:07:33 $
 
 General Fixes and Modified Features
 -----------------------------------
@@ -288,6 +288,8 @@ hero poly'd into rust monster could implicitly eat bars when adjacent by
        can explicitly eat them via 'e' after moving onto their spot
 monster hiding under an egg that hatched was kept hidden
 restful sleep regenerates hit points
+attacking non-adjacent concealed mimic by applying a polearm would make the
+       hero be stuck to that mimic
 
 
 Fixes to 3.7.0-x Problems that Were Exposed Via git Repository
index d6e9e24a0d24916fac66c35fa14e1e95dfa86965..44097e22154fbca11d36700b7200e1b5ce534de5 100644 (file)
--- a/src/mon.c
+++ b/src/mon.c
@@ -1,4 +1,4 @@
-/* NetHack 3.7 mon.c   $NHDT-Date: 1600933441 2020/09/24 07:44:01 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.348 $ */
+/* NetHack 3.7 mon.c   $NHDT-Date: 1604880454 2020/11/09 00:07:34 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.351 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Derek S. Ray, 2015. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -2575,6 +2575,12 @@ void
 set_ustuck(mtmp)
 struct monst *mtmp;
 {
+    if (iflags.sanity_check || iflags.debug_fuzzer) {
+        if (mtmp && distu(mtmp->mx, mtmp->my) > 2)
+            impossible("Sticking to %s at distu %d?",
+                       mon_nam(mtmp), distu(mtmp->mx, mtmp->my));
+    }
+
     g.context.botl = 1;
     u.ustuck = mtmp;
 }
index 53a82d7d3dbc1e0140ba407c8bf6c17dc5b716d9..7ad48d82e39fa96b2d5cf7d596038732306f7381 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 uhitm.c $NHDT-Date: 1596498221 2020/08/03 23:43:41 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.240 $ */
+/* NetHack 3.7 uhitm.c $NHDT-Date: 1604880456 2020/11/09 00:07:36 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.242 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2012. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -141,10 +141,10 @@ struct obj *wep; /* uwep for attack(), null for kick_monster() */
         /* if it was an invisible mimic, treat it as if we stumbled
          * onto a visible mimic
          */
-        if (M_AP_TYPE(mtmp) && !Protection_from_shape_changers
-            /* applied pole-arm attack is too far to get stuck */
-            && distu(mtmp->mx, mtmp->my) <= 2) {
-            if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK))
+        if (M_AP_TYPE(mtmp) && !Protection_from_shape_changers) {
+            if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK)
+                /* applied pole-arm attack is too far to get stuck */
+                && distu(mtmp->mx, mtmp->my) <= 2)
                 set_ustuck(mtmp);
         }
         /* #H7329 - if hero is on engraved "Elbereth", this will end up
@@ -2007,7 +2007,7 @@ int specialdmg; /* blessed and/or silver bonus against various things */
         break;
     }
     case AD_STCK:
-        if (!negated && !sticks(pd))
+        if (!negated && !sticks(pd) && distu(mdef->mx, mdef->my) <= 2)
             u.ustuck = mdef; /* it's now stuck to you */
         break;
     case AD_WRAP:
@@ -3133,7 +3133,9 @@ struct monst *mtmp;
 {
     const char *fmt = "Wait!  That's %s!", *generic = "a monster", *what = 0;
 
-    if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK))
+    if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK)
+        /* must be adjacent; attack via polearm could be from farther away */
+        && distu(mtmp->mx, mtmp->my) <= 2)
         set_ustuck(mtmp);
 
     if (Blind) {