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

index 44f3f2523334a216b2472123d80bf90b72d1804f..6082a1537339678c47b6c576743dedc21b9ed3e9 100644 (file)
@@ -2783,6 +2783,7 @@ E void FDECL(mhitm_ad_conf, (struct monst *, struct attack *, struct monst *, st
 E void FDECL(mhitm_ad_poly, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_famn, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
 E void FDECL(mhitm_ad_pest, (struct monst *, struct attack *, struct monst *, struct mhitm_data *));
+E void FDECL(mhitm_ad_deth, (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 8f2d7c12f082412065a296cf398f2a78cbd1a0e0..0ea507b211d07fb70c219503056846984c558b6e 100644 (file)
@@ -90,6 +90,7 @@ struct mhitm_data {
     int damage;
     int hitflags; /* MM_DEF_DIED | MM_AGR_DIED | ... */
     boolean done;
+    boolean permdmg;
 };
 
 /*
index 69ba4405c460395a2462e077615bc0d2c6840c1f..9d35199a692350e1cd2fcc2d4e40749b74d5d3dd 100644 (file)
@@ -863,6 +863,7 @@ int dieroll;
     struct mhitm_data mhm;
     mhm.damage = d((int) mattk->damn, (int) mattk->damd);
     mhm.hitflags = MM_MISS;
+    mhm.permdmg = 0;
 
     if ((touch_petrifies(pd) /* or flesh_petrifies() */
          || (mattk->adtyp == AD_DGST && pd == &mons[PM_MEDUSA]))
index d38c76b0a32f3cf005360f446e9f79b75a43f257..614b3d9dec37777b36dfbdb7a8e09ee8e07710b7 100644 (file)
@@ -967,12 +967,13 @@ register struct attack *mattk;
 {
     struct permonst *mdat = mtmp->data;
     int uncancelled, ptmp;
-    int armpro, permdmg, tmphp;
+    int armpro, tmphp;
     char buf[BUFSZ];
     struct permonst *olduasmon = g.youmonst.data;
     int res;
     struct mhitm_data mhm;
     mhm.hitflags = MM_MISS;
+    mhm.permdmg = 0;
 
     if (!canspotmon(mtmp))
         map_invisible(mtmp->mx, mtmp->my);
@@ -1012,7 +1013,6 @@ register struct attack *mattk;
     armpro = magic_negation(&g.youmonst);
     uncancelled = !mtmp->mcan && (rn2(10) >= 3 * armpro);
 
-    permdmg = 0;
     /*  Now, adjust damages via resistances or specific attacks */
     switch (mattk->adtyp) {
     case AD_PHYS:
@@ -1423,39 +1423,9 @@ register struct attack *mattk;
             return mhm.hitflags;
         break;
     case AD_DETH:
-        pline("%s reaches out with its deadly touch.", Monnam(mtmp));
-        if (is_undead(g.youmonst.data)) {
-            /* Still does normal damage */
-            pline("Was that the touch of death?");
-            break;
-        }
-        switch (rn2(20)) {
-        case 19:
-        case 18:
-        case 17:
-            if (!Antimagic) {
-                g.killer.format = KILLED_BY_AN;
-                Strcpy(g.killer.name, "touch of death");
-                done(DIED);
-                mhm.damage = 0;
-                break;
-            }
-            /*FALLTHRU*/
-        default: /* case 16: ... case 5: */
-            You_feel("your life force draining away...");
-            permdmg = 1; /* actual damage done below */
-            break;
-        case 4:
-        case 3:
-        case 2:
-        case 1:
-        case 0:
-            if (Antimagic)
-                shieldeff(u.ux, u.uy);
-            pline("Lucky for you, it didn't work!");
-            mhm.damage = 0;
-            break;
-        }
+        mhitm_ad_deth(mtmp, mattk, &g.youmonst, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_PEST:
         mhitm_ad_pest(mtmp, mattk, &g.youmonst, &mhm);
@@ -1509,7 +1479,7 @@ register struct attack *mattk;
                     || is_vampshifter(mtmp))))
             mhm.damage = (mhm.damage + 1) / 2;
 
-        if (permdmg) { /* Death's life force drain */
+        if (mhm.permdmg) { /* Death's life force drain */
             int lowerlimit, *hpmax_p;
             /*
              * Apply some of the damage to permanent hit points:
@@ -1520,13 +1490,13 @@ register struct attack *mattk;
              *  otherwise        0..50%
              * Never reduces hpmax below 1 hit point per level.
              */
-            permdmg = rn2(mhm.damage / 2 + 1);
+            mhm.permdmg = rn2(mhm.damage / 2 + 1);
             if (Upolyd || u.uhpmax > 25 * u.ulevel)
-                permdmg = mhm.damage;
+                mhm.permdmg = mhm.damage;
             else if (u.uhpmax > 10 * u.ulevel)
-                permdmg += mhm.damage / 2;
+                mhm.permdmg += mhm.damage / 2;
             else if (u.uhpmax > 5 * u.ulevel)
-                permdmg += mhm.damage / 4;
+                mhm.permdmg += mhm.damage / 4;
 
             if (Upolyd) {
                 hpmax_p = &u.mhmax;
@@ -1536,8 +1506,8 @@ register struct attack *mattk;
                 hpmax_p = &u.uhpmax;
                 lowerlimit = u.ulevel;
             }
-            if (*hpmax_p - permdmg > lowerlimit)
-                *hpmax_p -= permdmg;
+            if (*hpmax_p - mhm.permdmg > lowerlimit)
+                *hpmax_p -= mhm.permdmg;
             else if (*hpmax_p > lowerlimit)
                 *hpmax_p = lowerlimit;
             /* else unlikely...
index e71050b677b48ec9060abd31e66251cf91ceb542..4f5ead337065b030d7293416433da8e1f502658f 100644 (file)
@@ -3264,6 +3264,59 @@ struct mhitm_data *mhm;
     }
 }
 
+void
+mhitm_ad_deth(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 */
+        mhm->damage = 0;
+    } else if (mdef == &g.youmonst) {
+        /* mhitu */
+        pline("%s reaches out with its deadly touch.", Monnam(magr));
+        if (is_undead(pd)) {
+            /* Still does normal damage */
+            pline("Was that the touch of death?");
+            return;
+        }
+        switch (rn2(20)) {
+        case 19:
+        case 18:
+        case 17:
+            if (!Antimagic) {
+                g.killer.format = KILLED_BY_AN;
+                Strcpy(g.killer.name, "touch of death");
+                done(DIED);
+                mhm->damage = 0;
+                return;
+            }
+            /*FALLTHRU*/
+        default: /* case 16: ... case 5: */
+            You_feel("your life force draining away...");
+            mhm->permdmg = 1; /* actual damage done below */
+            return;
+        case 4:
+        case 3:
+        case 2:
+        case 1:
+        case 0:
+            if (Antimagic)
+                shieldeff(u.ux, u.uy);
+            pline("Lucky for you, it didn't work!");
+            mhm->damage = 0;
+            return;
+        }
+    } else {
+        /* mhitm */
+        mhm->damage = 0;
+    }
+}
+
 
 /* Template for monster hits monster for AD_FOO.
    - replace "break" with return
@@ -3312,6 +3365,7 @@ int specialdmg; /* blessed and/or silver bonus against various things */
     struct mhitm_data mhm;
     mhm.damage = d((int) mattk->damn, (int) mattk->damd);
     mhm.hitflags = MM_MISS;
+    mhm.permdmg = 0;
 
     armpro = magic_negation(mdef);
     /* since hero can't be cancelled, only defender's armor applies */