From: Pasi Kallinen Date: Mon, 30 Nov 2020 20:25:37 +0000 (+0200) Subject: Unify ad_plys X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=654220f84054a5fe130256588a01b4972224e576;p=nethack Unify ad_plys --- diff --git a/include/extern.h b/include/extern.h index b6c72b178..748921103 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2773,6 +2773,7 @@ E void FDECL(mhitm_ad_drst, (struct monst *, struct attack *, struct monst *, st 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 void FDECL(mhitm_ad_plys, (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 95a096918..bb183bd64 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -1092,13 +1092,9 @@ int dieroll; } break; case AD_PLYS: - if (!cancelled && mdef->mcanmove) { - if (g.vis && canspotmon(mdef)) { - Strcpy(buf, Monnam(mdef)); - pline("%s is frozen by %s.", buf, mon_nam(magr)); - } - paralyze_monst(mdef, rnd(10)); - } + mhitm_ad_plys(magr, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_SLOW: if (!cancelled && mdef->mspeed != MSLOW) { diff --git a/src/mhitu.c b/src/mhitu.c index ad05ad186..57c159e71 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -1141,21 +1141,9 @@ register struct attack *mattk; return mhm.hitflags; break; case AD_PLYS: - hitmsg(mtmp, mattk); - if (uncancelled && g.multi >= 0 && !rn2(3)) { - if (Free_action) { - You("momentarily stiffen."); - } else { - if (Blind) - You("are frozen!"); - else - You("are frozen by %s!", mon_nam(mtmp)); - g.nomovemsg = You_can_move_again; - nomul(-rnd(10)); - g.multi_reason = "paralyzed by a monster"; - exercise(A_DEX, FALSE); - } - } + mhitm_ad_plys(mtmp, mattk, &g.youmonst, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_DRLI: /* drain life */ mhitm_ad_drli(mtmp, mattk, &g.youmonst, &mhm); diff --git a/src/uhitm.c b/src/uhitm.c index 3950f4c7b..548eba081 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -2851,6 +2851,63 @@ struct mhitm_data *mhm; } } +void +mhitm_ad_plys(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->mcanmove && !rn2(3) && mhm->damage < mdef->mhp) { + if (!Blind) + pline("%s is frozen by you!", Monnam(mdef)); + paralyze_monst(mdef, rnd(10)); + } + } 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(3)) { + if (Free_action) { + You("momentarily stiffen."); + } else { + if (Blind) + You("are frozen!"); + else + You("are frozen by %s!", mon_nam(magr)); + g.nomovemsg = You_can_move_again; + nomul(-rnd(10)); + g.multi_reason = "paralyzed by a monster"; + exercise(A_DEX, FALSE); + } + } + } else { + /* mhitm */ + int armpro = magic_negation(mdef); + boolean cancelled = magr->mcan || !(rn2(10) >= 3 * armpro); + + if (!cancelled && mdef->mcanmove) { + if (g.vis && canspotmon(mdef)) { + char buf[BUFSZ]; + Strcpy(buf, Monnam(mdef)); + pline("%s is frozen by %s.", buf, mon_nam(magr)); + } + paralyze_monst(mdef, rnd(10)); + } + } +} + + /* Template for monster hits monster for AD_FOO. - replace "break" with return @@ -2867,12 +2924,22 @@ struct mhitm_data *mhm; 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); + /* TODO */ } else if (mdef == &g.youmonst) { /* mhitu */ + int armpro = magic_negation(mdef); + boolean uncancelled = !magr->mcan && (rn2(10) >= 3 * armpro); + /* TODO */ } else { /* mhitm */ + int armpro = magic_negation(mdef); + boolean cancelled = magr->mcan || !(rn2(10) >= 3 * armpro); + /* TODO */ } } @@ -3049,11 +3116,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */ return mhm.hitflags; break; case AD_PLYS: - if (!negated && mdef->mcanmove && !rn2(3) && mhm.damage < mdef->mhp) { - if (!Blind) - pline("%s is frozen by you!", Monnam(mdef)); - paralyze_monst(mdef, rnd(10)); - } + mhitm_ad_plys(&g.youmonst, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_SLEE: if (!negated && !mdef->msleeping && sleep_monst(mdef, rnd(10), -1)) {