From: Pasi Kallinen Date: Mon, 30 Nov 2020 20:06:53 +0000 (+0200) Subject: Unify ad_wrap X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7914237fbfd6b0b5460f54164fc60e81ae718d99;p=nethack Unify ad_wrap --- diff --git a/include/extern.h b/include/extern.h index cddedb6e2..b6c72b178 100644 --- a/include/extern.h +++ b/include/extern.h @@ -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, diff --git a/src/mhitm.c b/src/mhitm.c index 3502bd4c7..95a096918 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -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 */ diff --git a/src/mhitu.c b/src/mhitu.c index fe9b0257b..ad05ad186 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -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); diff --git a/src/uhitm.c b/src/uhitm.c index 567412b86..3950f4c7b 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -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) {