]> granicus.if.org Git - nethack/commitdiff
Unify ad_stck
authorPasi Kallinen <paxed@alt.org>
Mon, 30 Nov 2020 20:00:35 +0000 (22:00 +0200)
committerPasi Kallinen <paxed@alt.org>
Fri, 4 Dec 2020 07:30:17 +0000 (09:30 +0200)
include/extern.h
src/mhitm.c
src/mhitu.c
src/uhitm.c

index 86d9b02b001e39ec17df74b7ab8b6728eee6af58..cddedb6e2622785e7b1ca7cce8d1e01a32636b48 100644 (file)
@@ -2771,6 +2771,7 @@ E void FDECL(mhitm_ad_blnd, (struct monst *, struct attack *, struct monst *, st
 E void FDECL(mhitm_ad_curs, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_drst, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_drin, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
+E void FDECL(mhitm_ad_stck, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E int FDECL(damageum, (struct monst *, struct attack *, int));
 E void FDECL(missum, (struct monst *, struct attack *, BOOLEAN_P));
 E int FDECL(passive, (struct monst *, struct obj *, BOOLEAN_P, int,
index 89626bc4b6e54da37c815e04317470e9548bf2af..3502bd4c7cdbea3b6529e80b885d7c947923167b 100644 (file)
@@ -1246,8 +1246,9 @@ int dieroll;
         }
         break;
     case AD_STCK:
-        if (cancelled)
-            mhm.damage = 0;
+        mhitm_ad_stck(magr, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_WRAP: /* monsters cannot grab one another, it's too hard */
         if (magr->mcan)
index 61ed015a39af49c08731f1cf9be9e39a0b69df6e..fe9b0257bb0dd4823ddf8d6d08198b726f7e05ab 100644 (file)
@@ -1234,10 +1234,9 @@ register struct attack *mattk;
         }
         break;
     case AD_STCK:
-        hitmsg(mtmp, mattk);
-        if (uncancelled && !u.ustuck && !sticks(g.youmonst.data)) {
-            set_ustuck(mtmp);
-        }
+        mhitm_ad_stck(mtmp, mattk, &g.youmonst, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_WRAP:
         if ((!mtmp->mcan || u.ustuck == mtmp) && !sticks(g.youmonst.data)) {
index 53a5dd45ffcd0d53aa30ce8ebac9cb50002ad68a..567412b864e13c8d28945c8897a49e0c3553e959 100644 (file)
@@ -2739,6 +2739,42 @@ struct mhitm_data *mhm;
     }
 }
 
+void
+mhitm_ad_stck(magr, mattk, mdef, mhm)
+struct monst *magr;
+struct attack *mattk;
+struct monst *mdef;
+struct mhitm_data *mhm;
+{
+    struct permonst *pd = mdef->data;
+
+    if (magr == &g.youmonst) {
+        /* uhitm */
+        int armpro = magic_negation(mdef);
+        /* since hero can't be cancelled, only defender's armor applies */
+        boolean negated = !(rn2(10) >= 3 * armpro);
+
+        if (!negated && !sticks(pd) && distu(mdef->mx, mdef->my) <= 2)
+            u.ustuck = mdef; /* it's now stuck to you */
+    } else if (mdef == &g.youmonst) {
+        /* mhitu */
+        int armpro = magic_negation(mdef);
+        boolean uncancelled = !magr->mcan && (rn2(10) >= 3 * armpro);
+
+        hitmsg(magr, mattk);
+        if (uncancelled && !u.ustuck && !sticks(pd)) {
+            set_ustuck(magr);
+        }
+    } else {
+        /* mhitm */
+        int armpro = magic_negation(mdef);
+        boolean cancelled = magr->mcan || !(rn2(10) >= 3 * armpro);
+
+        if (cancelled)
+            mhm->damage = 0;
+    }
+}
+
 
 /* Template for monster hits monster for AD_FOO.
    - replace "break" with return
@@ -2927,8 +2963,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */
             return mhm.hitflags;
         break;
     case AD_STCK:
-        if (!negated && !sticks(pd) && distu(mdef->mx, mdef->my) <= 2)
-            u.ustuck = mdef; /* it's now stuck to you */
+        mhitm_ad_stck(&g.youmonst, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_WRAP:
         if (!sticks(pd)) {