]> granicus.if.org Git - nethack/commitdiff
Unify ad_drst
authorPasi Kallinen <paxed@alt.org>
Mon, 30 Nov 2020 19:41:28 +0000 (21:41 +0200)
committerPasi Kallinen <paxed@alt.org>
Fri, 4 Dec 2020 07:30:16 +0000 (09:30 +0200)
include/extern.h
src/mhitm.c
src/mhitu.c
src/uhitm.c

index 8bfa0465f6c0fd129a904b35af16ba999c098efa..6abcd8d1cdd5fcb00598f4f8078e4788a0345330 100644 (file)
@@ -2768,6 +2768,7 @@ E void FDECL(mhitm_ad_sgld, (struct monst *, struct attack *, struct monst *, st
 E void FDECL(mhitm_ad_tlpt, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_blnd, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 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 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 5a4bfa4bd7d0485606ac5f429e30508da733ac69..8361d54907f0e57c5aa8832428e2ccf88a9d4fcc 100644 (file)
@@ -1216,24 +1216,9 @@ int dieroll;
     case AD_DRST:
     case AD_DRDX:
     case AD_DRCO:
-        if (!cancelled && !rn2(8)) {
-            if (g.vis && canspotmon(magr))
-                pline("%s %s was poisoned!", s_suffix(Monnam(magr)),
-                      mpoisons_subj(magr, mattk));
-            if (resists_poison(mdef)) {
-                if (g.vis && canspotmon(mdef) && canspotmon(magr))
-                    pline_The("poison doesn't seem to affect %s.",
-                              mon_nam(mdef));
-            } else {
-                if (rn2(10))
-                    mhm.damage += rn1(10, 6);
-                else {
-                    if (g.vis && canspotmon(mdef))
-                        pline_The("poison was deadly...");
-                    mhm.damage = mdef->mhp;
-                }
-            }
-        }
+        mhitm_ad_drst(magr, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_DRIN:
         if (g.notonhead || !has_head(pd)) {
index d4d61a87f99bc03bde7147d6ee7373878a48f08a..8036df8208e4969cf90166544cbe8b737927daf1 100644 (file)
@@ -1130,20 +1130,11 @@ register struct attack *mattk;
             return mhm.hitflags;
         break;
     case AD_DRST:
-        ptmp = A_STR;
-        goto dopois;
     case AD_DRDX:
-        ptmp = A_DEX;
-        goto dopois;
     case AD_DRCO:
-        ptmp = A_CON;
- dopois:
-        hitmsg(mtmp, mattk);
-        if (uncancelled && !rn2(8)) {
-            Sprintf(buf, "%s %s", s_suffix(Monnam(mtmp)),
-                    mpoisons_subj(mtmp, mattk));
-            poisoned(buf, ptmp, mdat->mname, 30, FALSE);
-        }
+        mhitm_ad_drst(mtmp, mattk, &g.youmonst, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_DRIN:
         hitmsg(mtmp, mattk);
index eca8843b68c3d16838db02fc2322f42ee1806aa0..d0b526e9ff0c0fc35b5787d601769f5d66cfcb3e 100644 (file)
@@ -2566,6 +2566,78 @@ struct mhitm_data *mhm;
     }
 }
 
+void
+mhitm_ad_drst(magr, mattk, mdef, mhm)
+struct monst *magr;
+struct attack *mattk;
+struct monst *mdef;
+struct mhitm_data *mhm;
+{
+    struct permonst *pa = magr->data;
+    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 && !rn2(8)) {
+            Your("%s was poisoned!", mpoisons_subj(magr, mattk));
+            if (resists_poison(mdef)) {
+                pline_The("poison doesn't seem to affect %s.", mon_nam(mdef));
+            } else {
+                if (!rn2(10)) {
+                    Your("poison was deadly...");
+                    mhm->damage = mdef->mhp;
+                } else
+                    mhm->damage += rn1(10, 6);
+            }
+        }
+    } else if (mdef == &g.youmonst) {
+        /* mhitu */
+        int armpro = magic_negation(mdef);
+        boolean uncancelled = !magr->mcan && (rn2(10) >= 3 * armpro);
+        int ptmp;
+        char buf[BUFSZ];
+
+        switch (mattk->adtyp) {
+        case AD_DRST: ptmp = A_STR; break;
+        case AD_DRDX: ptmp = A_DEX; break;
+        case AD_DRCO: ptmp = A_CON; break;
+        }
+        hitmsg(magr, mattk);
+        if (uncancelled && !rn2(8)) {
+            Sprintf(buf, "%s %s", s_suffix(Monnam(magr)),
+                    mpoisons_subj(magr, mattk));
+            poisoned(buf, ptmp, pa->mname, 30, FALSE);
+        }
+    } else {
+        /* mhitm */
+        int armpro = magic_negation(mdef);
+        boolean cancelled = magr->mcan || !(rn2(10) >= 3 * armpro);
+
+        if (!cancelled && !rn2(8)) {
+            if (g.vis && canspotmon(magr))
+                pline("%s %s was poisoned!", s_suffix(Monnam(magr)),
+                      mpoisons_subj(magr, mattk));
+            if (resists_poison(mdef)) {
+                if (g.vis && canspotmon(mdef) && canspotmon(magr))
+                    pline_The("poison doesn't seem to affect %s.",
+                              mon_nam(mdef));
+            } else {
+                if (rn2(10))
+                    mhm->damage += rn1(10, 6);
+                else {
+                    if (g.vis && canspotmon(mdef))
+                        pline_The("poison was deadly...");
+                    mhm->damage = mdef->mhp;
+                }
+            }
+        }
+    }
+}
+
 /* Template for monster hits monster for AD_FOO.
    - replace "break" with return
    - replace "return" with mhm->done = TRUE
@@ -2743,18 +2815,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */
     case AD_DRST:
     case AD_DRDX:
     case AD_DRCO:
-        if (!negated && !rn2(8)) {
-            Your("%s was poisoned!", mpoisons_subj(&g.youmonst, mattk));
-            if (resists_poison(mdef)) {
-                pline_The("poison doesn't seem to affect %s.", mon_nam(mdef));
-            } else {
-                if (!rn2(10)) {
-                    Your("poison was deadly...");
-                    mhm.damage = mdef->mhp;
-                } else
-                    mhm.damage += rn1(10, 6);
-            }
-        }
+        mhitm_ad_drst(&g.youmonst, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_DRIN: {
         struct obj *helmet;