]> granicus.if.org Git - nethack/commitdiff
Unify ad_slee
authorPasi Kallinen <paxed@alt.org>
Mon, 30 Nov 2020 20:32:50 +0000 (22:32 +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 748921103607de30d042c4a854decdbcdbb97404..17bde25254af521c2e2d8faad326a9f2d2885d87 100644 (file)
@@ -2774,6 +2774,7 @@ E void FDECL(mhitm_ad_drin, (struct monst *, struct attack *, struct monst *, st
 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 void FDECL(mhitm_ad_slee, (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 bb183bd640e8866333843a228d5f88f51a2c8db5..c242af935ff70348f4c02148d5cfc08e93811b57 100644 (file)
@@ -1081,15 +1081,9 @@ int dieroll;
             return mhm.hitflags;
         break;
     case AD_SLEE:
-        if (!cancelled && !mdef->msleeping
-            && sleep_monst(mdef, rnd(10), -1)) {
-            if (g.vis && canspotmon(mdef)) {
-                Strcpy(buf, Monnam(mdef));
-                pline("%s is put to sleep by %s.", buf, mon_nam(magr));
-            }
-            mdef->mstrategy &= ~STRAT_WAITFORU;
-            slept_monst(mdef);
-        }
+        mhitm_ad_slee(magr, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_PLYS:
         mhitm_ad_plys(magr, mattk, mdef, &mhm);
index 57c159e7190a1602fa1c76f9693e7430f4db1e58..0f05f7550569f0ca0801d7aac67ad04618ebd191 100644 (file)
@@ -1112,16 +1112,9 @@ register struct attack *mattk;
             return mhm.hitflags;
         break;
     case AD_SLEE:
-        hitmsg(mtmp, mattk);
-        if (uncancelled && g.multi >= 0 && !rn2(5)) {
-            if (Sleep_resistance)
-                break;
-            fall_asleep(-rnd(10), TRUE);
-            if (Blind)
-                You("are put to sleep!");
-            else
-                You("are put to sleep by %s!", mon_nam(mtmp));
-        }
+        mhitm_ad_slee(mtmp, mattk, &g.youmonst, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_BLND:
         mhitm_ad_blnd(mtmp, mattk, &g.youmonst, &mhm);
index 548eba08170734ed69459a56c1d76549962bb907..6db99262685e6f08245a8a6ba645d531d02ed4ac 100644 (file)
@@ -2907,6 +2907,59 @@ struct mhitm_data *mhm;
     }
 }
 
+void
+mhitm_ad_slee(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->msleeping && sleep_monst(mdef, rnd(10), -1)) {
+            if (!Blind)
+                pline("%s is put to sleep by you!", Monnam(mdef));
+            slept_monst(mdef);
+        }
+    } 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(5)) {
+            if (Sleep_resistance)
+                return;
+            fall_asleep(-rnd(10), TRUE);
+            if (Blind)
+                You("are put to sleep!");
+            else
+                You("are put to sleep by %s!", mon_nam(magr));
+        }
+    } else {
+        /* mhitm */
+        int armpro = magic_negation(mdef);
+        boolean cancelled = magr->mcan || !(rn2(10) >= 3 * armpro);
+
+        if (!cancelled && !mdef->msleeping
+            && sleep_monst(mdef, rnd(10), -1)) {
+            if (g.vis && canspotmon(mdef)) {
+                char buf[BUFSZ];
+                Strcpy(buf, Monnam(mdef));
+                pline("%s is put to sleep by %s.", buf, mon_nam(magr));
+            }
+            mdef->mstrategy &= ~STRAT_WAITFORU;
+            slept_monst(mdef);
+        }
+    }
+}
+
 
 
 /* Template for monster hits monster for AD_FOO.
@@ -3121,11 +3174,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */
             return mhm.hitflags;
         break;
     case AD_SLEE:
-        if (!negated && !mdef->msleeping && sleep_monst(mdef, rnd(10), -1)) {
-            if (!Blind)
-                pline("%s is put to sleep by you!", Monnam(mdef));
-            slept_monst(mdef);
-        }
+        mhitm_ad_slee(&g.youmonst, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_SLIM:
         if (negated)