From: Pasi Kallinen Date: Mon, 30 Nov 2020 20:32:50 +0000 (+0200) Subject: Unify ad_slee X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eb5508ba5880b51af73312b64253a96ce9b3fe2d;p=nethack Unify ad_slee --- diff --git a/include/extern.h b/include/extern.h index 748921103..17bde2525 100644 --- a/include/extern.h +++ b/include/extern.h @@ -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, diff --git a/src/mhitm.c b/src/mhitm.c index bb183bd64..c242af935 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -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); diff --git a/src/mhitu.c b/src/mhitu.c index 57c159e71..0f05f7550 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -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); diff --git a/src/uhitm.c b/src/uhitm.c index 548eba081..6db992626 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -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)