From bfb8931188dd3d33f139895e91303ee923f17391 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Mon, 30 Nov 2020 22:00:35 +0200 Subject: [PATCH] Unify ad_stck --- include/extern.h | 1 + src/mhitm.c | 5 +++-- src/mhitu.c | 7 +++---- src/uhitm.c | 41 +++++++++++++++++++++++++++++++++++++++-- 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/include/extern.h b/include/extern.h index 86d9b02b0..cddedb6e2 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2771,6 +2771,7 @@ E void FDECL(mhitm_ad_blnd, (struct monst *, struct attack *, struct monst *, st E void FDECL(mhitm_ad_curs, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); 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 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 89626bc4b..3502bd4c7 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -1246,8 +1246,9 @@ int dieroll; } break; case AD_STCK: - if (cancelled) - mhm.damage = 0; + mhitm_ad_stck(magr, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_WRAP: /* monsters cannot grab one another, it's too hard */ if (magr->mcan) diff --git a/src/mhitu.c b/src/mhitu.c index 61ed015a3..fe9b0257b 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -1234,10 +1234,9 @@ register struct attack *mattk; } break; case AD_STCK: - hitmsg(mtmp, mattk); - if (uncancelled && !u.ustuck && !sticks(g.youmonst.data)) { - set_ustuck(mtmp); - } + mhitm_ad_stck(mtmp, mattk, &g.youmonst, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_WRAP: if ((!mtmp->mcan || u.ustuck == mtmp) && !sticks(g.youmonst.data)) { diff --git a/src/uhitm.c b/src/uhitm.c index 53a5dd45f..567412b86 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -2739,6 +2739,42 @@ struct mhitm_data *mhm; } } +void +mhitm_ad_stck(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 && !sticks(pd) && distu(mdef->mx, mdef->my) <= 2) + u.ustuck = mdef; /* it's now stuck to you */ + } else if (mdef == &g.youmonst) { + /* mhitu */ + int armpro = magic_negation(mdef); + boolean uncancelled = !magr->mcan && (rn2(10) >= 3 * armpro); + + hitmsg(magr, mattk); + if (uncancelled && !u.ustuck && !sticks(pd)) { + set_ustuck(magr); + } + } else { + /* mhitm */ + int armpro = magic_negation(mdef); + boolean cancelled = magr->mcan || !(rn2(10) >= 3 * armpro); + + if (cancelled) + mhm->damage = 0; + } +} + /* Template for monster hits monster for AD_FOO. - replace "break" with return @@ -2927,8 +2963,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */ return mhm.hitflags; break; case AD_STCK: - if (!negated && !sticks(pd) && distu(mdef->mx, mdef->my) <= 2) - u.ustuck = mdef; /* it's now stuck to you */ + mhitm_ad_stck(&g.youmonst, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_WRAP: if (!sticks(pd)) {