]> granicus.if.org Git - nethack/commitdiff
Unify ad_plys
authorPasi Kallinen <paxed@alt.org>
Mon, 30 Nov 2020 20:25:37 +0000 (22:25 +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 b6c72b17844483a0079854ee3e90e1c902a9d029..748921103607de30d042c4a854decdbcdbb97404 100644 (file)
@@ -2773,6 +2773,7 @@ E void FDECL(mhitm_ad_drst, (struct monst *, struct attack *, struct monst *, st
 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 void FDECL(mhitm_ad_wrap, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
+E void FDECL(mhitm_ad_plys, (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 95a096918fc053348ab5cde2639ec6c2e59144b3..bb183bd640e8866333843a228d5f88f51a2c8db5 100644 (file)
@@ -1092,13 +1092,9 @@ int dieroll;
         }
         break;
     case AD_PLYS:
-        if (!cancelled && mdef->mcanmove) {
-            if (g.vis && canspotmon(mdef)) {
-                Strcpy(buf, Monnam(mdef));
-                pline("%s is frozen by %s.", buf, mon_nam(magr));
-            }
-            paralyze_monst(mdef, rnd(10));
-        }
+        mhitm_ad_plys(magr, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_SLOW:
         if (!cancelled && mdef->mspeed != MSLOW) {
index ad05ad186400ca92540d8058415a1bac458e1423..57c159e7190a1602fa1c76f9693e7430f4db1e58 100644 (file)
@@ -1141,21 +1141,9 @@ register struct attack *mattk;
             return mhm.hitflags;
         break;
     case AD_PLYS:
-        hitmsg(mtmp, mattk);
-        if (uncancelled && g.multi >= 0 && !rn2(3)) {
-            if (Free_action) {
-                You("momentarily stiffen.");
-            } else {
-                if (Blind)
-                    You("are frozen!");
-                else
-                    You("are frozen by %s!", mon_nam(mtmp));
-                g.nomovemsg = You_can_move_again;
-                nomul(-rnd(10));
-                g.multi_reason = "paralyzed by a monster";
-                exercise(A_DEX, FALSE);
-            }
-        }
+        mhitm_ad_plys(mtmp, mattk, &g.youmonst, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_DRLI: /* drain life */
         mhitm_ad_drli(mtmp, mattk, &g.youmonst, &mhm);
index 3950f4c7b475a9a46347be7c61c37ada98b7c9f8..548eba08170734ed69459a56c1d76549962bb907 100644 (file)
@@ -2851,6 +2851,63 @@ struct mhitm_data *mhm;
     }
 }
 
+void
+mhitm_ad_plys(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 && mdef->mcanmove && !rn2(3) && mhm->damage < mdef->mhp) {
+            if (!Blind)
+                pline("%s is frozen by you!", Monnam(mdef));
+            paralyze_monst(mdef, rnd(10));
+        }
+    } else if (mdef == &g.youmonst) {
+        /* mhitu */
+        int armpro = magic_negation(mdef);
+        boolean uncancelled = !magr->mcan && (rn2(10) >= 3 * armpro);
+
+        hitmsg(magr, mattk);
+        if (uncancelled && g.multi >= 0 && !rn2(3)) {
+            if (Free_action) {
+                You("momentarily stiffen.");
+            } else {
+                if (Blind)
+                    You("are frozen!");
+                else
+                    You("are frozen by %s!", mon_nam(magr));
+                g.nomovemsg = You_can_move_again;
+                nomul(-rnd(10));
+                g.multi_reason = "paralyzed by a monster";
+                exercise(A_DEX, FALSE);
+            }
+        }
+    } else {
+        /* mhitm */
+        int armpro = magic_negation(mdef);
+        boolean cancelled = magr->mcan || !(rn2(10) >= 3 * armpro);
+
+        if (!cancelled && mdef->mcanmove) {
+            if (g.vis && canspotmon(mdef)) {
+                char buf[BUFSZ];
+                Strcpy(buf, Monnam(mdef));
+                pline("%s is frozen by %s.", buf, mon_nam(magr));
+            }
+            paralyze_monst(mdef, rnd(10));
+        }
+    }
+}
+
+
 
 /* Template for monster hits monster for AD_FOO.
    - replace "break" with return
@@ -2867,12 +2924,22 @@ struct mhitm_data *mhm;
 
     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);
+
         /* TODO */
     } else if (mdef == &g.youmonst) {
         /* mhitu */
+        int armpro = magic_negation(mdef);
+        boolean uncancelled = !magr->mcan && (rn2(10) >= 3 * armpro);
+
         /* TODO */
     } else {
         /* mhitm */
+        int armpro = magic_negation(mdef);
+        boolean cancelled = magr->mcan || !(rn2(10) >= 3 * armpro);
+
         /* TODO */
     }
 }
@@ -3049,11 +3116,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */
             return mhm.hitflags;
         break;
     case AD_PLYS:
-        if (!negated && mdef->mcanmove && !rn2(3) && mhm.damage < mdef->mhp) {
-            if (!Blind)
-                pline("%s is frozen by you!", Monnam(mdef));
-            paralyze_monst(mdef, rnd(10));
-        }
+        mhitm_ad_plys(&g.youmonst, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_SLEE:
         if (!negated && !mdef->msleeping && sleep_monst(mdef, rnd(10), -1)) {