From: Pasi Kallinen Date: Mon, 30 Nov 2020 20:50:56 +0000 (+0200) Subject: Unify ad_slow X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=558ec78b3a7474532931ce24bd28a8e09bb1b94f;p=nethack Unify ad_slow --- diff --git a/include/extern.h b/include/extern.h index 161e17258..414e1d0f8 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2777,6 +2777,7 @@ E void FDECL(mhitm_ad_plys, (struct monst *, struct attack *, struct monst *, st E void FDECL(mhitm_ad_slee, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); E void FDECL(mhitm_ad_slim, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); E void FDECL(mhitm_ad_ench, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); +E void FDECL(mhitm_ad_slow, (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 db2dfa4ee..ffb11fe1f 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -1091,14 +1091,9 @@ int dieroll; return mhm.hitflags; break; case AD_SLOW: - if (!cancelled && mdef->mspeed != MSLOW) { - unsigned int oldspeed = mdef->mspeed; - - mon_adjust_speed(mdef, -1, (struct obj *) 0); - mdef->mstrategy &= ~STRAT_WAITFORU; - if (mdef->mspeed != oldspeed && g.vis && canspotmon(mdef)) - pline("%s slows down.", Monnam(mdef)); - } + mhitm_ad_slow(magr, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_CONF: /* Since confusing another monster doesn't have a real time diff --git a/src/mhitu.c b/src/mhitu.c index cb26e2cb0..dcee2988d 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -1409,9 +1409,9 @@ register struct attack *mattk; return mhm.hitflags; break; case AD_SLOW: - hitmsg(mtmp, mattk); - if (uncancelled && HFast && !defends(AD_SLOW, uwep) && !rn2(4)) - u_slow_down(); + mhitm_ad_slow(mtmp, mattk, &g.youmonst, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_DREN: mhitm_ad_dren(mtmp, mattk, &g.youmonst, &mhm); diff --git a/src/uhitm.c b/src/uhitm.c index 171ea78ea..16bf66c34 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -3093,6 +3093,53 @@ struct mhitm_data *mhm; } } +void +mhitm_ad_slow(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->mspeed != MSLOW) { + unsigned int oldspeed = mdef->mspeed; + + mon_adjust_speed(mdef, -1, (struct obj *) 0); + if (mdef->mspeed != oldspeed && canseemon(mdef)) + pline("%s slows down.", Monnam(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 && HFast && !defends(AD_SLOW, uwep) && !rn2(4)) + u_slow_down(); + } else { + /* mhitm */ + int armpro = magic_negation(mdef); + boolean cancelled = magr->mcan || !(rn2(10) >= 3 * armpro); + + if (!cancelled && mdef->mspeed != MSLOW) { + unsigned int oldspeed = mdef->mspeed; + + mon_adjust_speed(mdef, -1, (struct obj *) 0); + mdef->mstrategy &= ~STRAT_WAITFORU; + if (mdef->mspeed != oldspeed && g.vis && canspotmon(mdef)) + pline("%s slows down.", Monnam(mdef)); + } + } +} + + /* Template for monster hits monster for AD_FOO. - replace "break" with return - replace "return" with mhm->done = TRUE @@ -3320,13 +3367,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */ return mhm.hitflags; break; case AD_SLOW: - if (!negated && mdef->mspeed != MSLOW) { - unsigned int oldspeed = mdef->mspeed; - - mon_adjust_speed(mdef, -1, (struct obj *) 0); - if (mdef->mspeed != oldspeed && canseemon(mdef)) - pline("%s slows down.", Monnam(mdef)); - } + mhitm_ad_slow(&g.youmonst, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_CONF: if (!mdef->mconf) {