]> granicus.if.org Git - nethack/commitdiff
Unify ad_wrap
authorPasi Kallinen <paxed@alt.org>
Mon, 30 Nov 2020 20:06:53 +0000 (22:06 +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 cddedb6e2622785e7b1ca7cce8d1e01a32636b48..b6c72b17844483a0079854ee3e90e1c902a9d029 100644 (file)
@@ -2772,6 +2772,7 @@ E void FDECL(mhitm_ad_curs, (struct monst *, struct attack *, struct monst *, st
 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 void FDECL(mhitm_ad_wrap, (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 3502bd4c7cdbea3b6529e80b885d7c947923167b..95a096918fc053348ab5cde2639ec6c2e59144b3 100644 (file)
@@ -1250,9 +1250,10 @@ int dieroll;
         if (mhm.done)
             return mhm.hitflags;
         break;
-    case AD_WRAP: /* monsters cannot grab one another, it's too hard */
-        if (magr->mcan)
-            mhm.damage = 0;
+    case AD_WRAP:
+        mhitm_ad_wrap(magr, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_ENCH:
         /* there's no msomearmor() function, so just do damage */
index fe9b0257bb0dd4823ddf8d6d08198b726f7e05ab..ad05ad186400ca92540d8058415a1bac458e1423 100644 (file)
@@ -1239,38 +1239,9 @@ register struct attack *mattk;
             return mhm.hitflags;
         break;
     case AD_WRAP:
-        if ((!mtmp->mcan || u.ustuck == mtmp) && !sticks(g.youmonst.data)) {
-            if (!u.ustuck && !rn2(10)) {
-                if (u_slip_free(mtmp, mattk)) {
-                    mhm.damage = 0;
-                } else {
-                    set_ustuck(mtmp); /* before message, for botl update */
-                    pline("%s swings itself around you!", Monnam(mtmp));
-                }
-            } else if (u.ustuck == mtmp) {
-                if (is_pool(mtmp->mx, mtmp->my) && !Swimming && !Amphibious) {
-                    boolean moat = (levl[mtmp->mx][mtmp->my].typ != POOL)
-                                   && (levl[mtmp->mx][mtmp->my].typ != WATER)
-                                   && !Is_medusa_level(&u.uz)
-                                   && !Is_waterlevel(&u.uz);
-
-                    pline("%s drowns you...", Monnam(mtmp));
-                    g.killer.format = KILLED_BY_AN;
-                    Sprintf(g.killer.name, "%s by %s",
-                            moat ? "moat" : "pool of water",
-                            an(mtmp->data->mname));
-                    done(DROWNING);
-                } else if (mattk->aatyp == AT_HUGS) {
-                    You("are being crushed.");
-                }
-            } else {
-                mhm.damage = 0;
-                if (flags.verbose)
-                    pline("%s brushes against your %s.", Monnam(mtmp),
-                          body_part(LEG));
-            }
-        } else
-            mhm.damage = 0;
+        mhitm_ad_wrap(mtmp, mattk, &g.youmonst, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_WERE:
         hitmsg(mtmp, mattk);
index 567412b864e13c8d28945c8897a49e0c3553e959..3950f4c7b475a9a46347be7c61c37ada98b7c9f8 100644 (file)
@@ -2775,6 +2775,82 @@ struct mhitm_data *mhm;
     }
 }
 
+void
+mhitm_ad_wrap(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 */
+        if (!sticks(pd)) {
+            if (!u.ustuck && !rn2(10)) {
+                if (m_slips_free(mdef, mattk)) {
+                    mhm->damage = 0;
+                } else {
+                    You("swing yourself around %s!", mon_nam(mdef));
+                    set_ustuck(mdef);
+                }
+            } else if (u.ustuck == mdef) {
+                /* Monsters don't wear amulets of magical breathing */
+                if (is_pool(u.ux, u.uy) && !is_swimmer(pd)
+                    && !amphibious(pd)) {
+                    You("drown %s...", mon_nam(mdef));
+                    mhm->damage = mdef->mhp;
+                } else if (mattk->aatyp == AT_HUGS)
+                    pline("%s is being crushed.", Monnam(mdef));
+            } else {
+                mhm->damage = 0;
+                if (flags.verbose)
+                    You("brush against %s %s.", s_suffix(mon_nam(mdef)),
+                        mbodypart(mdef, LEG));
+            }
+        } else
+            mhm->damage = 0;
+    } else if (mdef == &g.youmonst) {
+        /* mhitu */
+        if ((!magr->mcan || u.ustuck == magr) && !sticks(pd)) {
+            if (!u.ustuck && !rn2(10)) {
+                if (u_slip_free(magr, mattk)) {
+                    mhm->damage = 0;
+                } else {
+                    set_ustuck(magr); /* before message, for botl update */
+                    pline("%s swings itself around you!", Monnam(magr));
+                }
+            } else if (u.ustuck == magr) {
+                if (is_pool(magr->mx, magr->my) && !Swimming && !Amphibious) {
+                    boolean moat = (levl[magr->mx][magr->my].typ != POOL)
+                                   && (levl[magr->mx][magr->my].typ != WATER)
+                                   && !Is_medusa_level(&u.uz)
+                                   && !Is_waterlevel(&u.uz);
+
+                    pline("%s drowns you...", Monnam(magr));
+                    g.killer.format = KILLED_BY_AN;
+                    Sprintf(g.killer.name, "%s by %s",
+                            moat ? "moat" : "pool of water",
+                            an(magr->data->mname));
+                    done(DROWNING);
+                } else if (mattk->aatyp == AT_HUGS) {
+                    You("are being crushed.");
+                }
+            } else {
+                mhm->damage = 0;
+                if (flags.verbose)
+                    pline("%s brushes against your %s.", Monnam(magr),
+                          body_part(LEG));
+            }
+        } else
+            mhm->damage = 0;
+    } else {
+        /* mhitm */
+        if (magr->mcan)
+            mhm->damage = 0;
+    }
+}
+
 
 /* Template for monster hits monster for AD_FOO.
    - replace "break" with return
@@ -2968,30 +3044,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */
             return mhm.hitflags;
         break;
     case AD_WRAP:
-        if (!sticks(pd)) {
-            if (!u.ustuck && !rn2(10)) {
-                if (m_slips_free(mdef, mattk)) {
-                    mhm.damage = 0;
-                } else {
-                    You("swing yourself around %s!", mon_nam(mdef));
-                    set_ustuck(mdef);
-                }
-            } else if (u.ustuck == mdef) {
-                /* Monsters don't wear amulets of magical breathing */
-                if (is_pool(u.ux, u.uy) && !is_swimmer(pd)
-                    && !amphibious(pd)) {
-                    You("drown %s...", mon_nam(mdef));
-                    mhm.damage = mdef->mhp;
-                } else if (mattk->aatyp == AT_HUGS)
-                    pline("%s is being crushed.", Monnam(mdef));
-            } else {
-                mhm.damage = 0;
-                if (flags.verbose)
-                    You("brush against %s %s.", s_suffix(mon_nam(mdef)),
-                        mbodypart(mdef, LEG));
-            }
-        } else
-            mhm.damage = 0;
+        mhitm_ad_wrap(&g.youmonst, mattk, mdef, &mhm);
+        if (mhm.done)
+            return mhm.hitflags;
         break;
     case AD_PLYS:
         if (!negated && mdef->mcanmove && !rn2(3) && mhm.damage < mdef->mhp) {