From dba9aaf424eba2a01ee3ca54c4b5d6d7c06bef80 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Mon, 30 Nov 2020 21:22:58 +0200 Subject: [PATCH] Unify ad_curs --- include/extern.h | 1 + src/mhitm.c | 31 ++------------- src/mhitu.c | 21 ++-------- src/uhitm.c | 101 +++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 95 insertions(+), 59 deletions(-) diff --git a/include/extern.h b/include/extern.h index 40cbd2fab..8bfa0465f 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2767,6 +2767,7 @@ E void FDECL(mhitm_ad_acid, (struct monst *, struct attack *, struct monst *, st E void FDECL(mhitm_ad_sgld, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); E void FDECL(mhitm_ad_tlpt, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); E void FDECL(mhitm_ad_blnd, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); +E void FDECL(mhitm_ad_curs, (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 97fc90f6d..5a4bfa4bd 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -1138,34 +1138,9 @@ int dieroll; mhm.damage = 0; break; case AD_CURS: - if (!night() && (pa == &mons[PM_GREMLIN])) - break; - if (!magr->mcan && !rn2(10)) { - mdef->mcan = 1; /* cancelled regardless of lifesave */ - mdef->mstrategy &= ~STRAT_WAITFORU; - if (is_were(pd) && pd->mlet != S_HUMAN) - were_change(mdef); - if (pd == &mons[PM_CLAY_GOLEM]) { - if (g.vis && canseemon(mdef)) { - pline("Some writing vanishes from %s head!", - s_suffix(mon_nam(mdef))); - pline("%s is destroyed!", Monnam(mdef)); - } - mondied(mdef); - if (!DEADMONSTER(mdef)) - return 0; - else if (mdef->mtame && !g.vis) - You(brief_feeling, "strangely sad"); - return (MM_DEF_DIED - | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); - } - if (!Deaf) { - if (!g.vis) - You_hear("laughter."); - else if (canseemon(magr)) - pline("%s chuckles.", Monnam(magr)); - } - } + mhitm_ad_curs(magr, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_SGLD: mhitm_ad_sgld(magr, mattk, mdef, &mhm); diff --git a/src/mhitu.c b/src/mhitu.c index e0f3da06d..d4d61a87f 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -1482,24 +1482,9 @@ register struct attack *mattk; } break; case AD_CURS: - hitmsg(mtmp, mattk); - if (!night() && mdat == &mons[PM_GREMLIN]) - break; - if (!mtmp->mcan && !rn2(10)) { - if (!Deaf) { - if (Blind) - You_hear("laughter."); - else - pline("%s chuckles.", Monnam(mtmp)); - } - if (u.umonnum == PM_CLAY_GOLEM) { - pline("Some writing vanishes from your head!"); - /* KMH -- this is okay with unchanging */ - rehumanize(); - break; - } - attrcurse(); - } + mhitm_ad_curs(mtmp, mattk, &g.youmonst, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_STUN: hitmsg(mtmp, mattk); diff --git a/src/uhitm.c b/src/uhitm.c index 2148d458b..eca8843b6 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -5,6 +5,9 @@ #include "hack.h" +static const char brief_feeling[] = + "have a %s feeling for a moment, then it passes."; + static boolean FDECL(known_hitum, (struct monst *, struct obj *, int *, int, int, struct attack *, int)); static boolean FDECL(theft_petrifies, (struct obj *)); @@ -2481,6 +2484,88 @@ struct mhitm_data *mhm; } } +void +mhitm_ad_curs(magr, mattk, mdef, mhm) +struct monst *magr; +struct attack *mattk; +struct monst *mdef; +struct mhitm_data *mhm; +{ + struct permonst *pa = magr->data; + struct permonst *pd = mdef->data; + + if (magr == &g.youmonst) { + /* uhitm */ + if (night() && !rn2(10) && !mdef->mcan) { + if (pd == &mons[PM_CLAY_GOLEM]) { + if (!Blind) + pline("Some writing vanishes from %s head!", + s_suffix(mon_nam(mdef))); + xkilled(mdef, XKILL_NOMSG); + /* Don't return yet; keep hp<1 and mhm.damage=0 for pet msg */ + } else { + mdef->mcan = 1; + You("chuckle."); + } + } + mhm->damage = 0; + } else if (mdef == &g.youmonst) { + /* mhitu */ + hitmsg(magr, mattk); + if (!night() && pa == &mons[PM_GREMLIN]) + return; + if (!magr->mcan && !rn2(10)) { + if (!Deaf) { + if (Blind) + You_hear("laughter."); + else + pline("%s chuckles.", Monnam(magr)); + } + if (u.umonnum == PM_CLAY_GOLEM) { + pline("Some writing vanishes from your head!"); + /* KMH -- this is okay with unchanging */ + rehumanize(); + return; + } + attrcurse(); + } + } else { + /* mhitm */ + if (!night() && (pa == &mons[PM_GREMLIN])) + return; + if (!magr->mcan && !rn2(10)) { + mdef->mcan = 1; /* cancelled regardless of lifesave */ + mdef->mstrategy &= ~STRAT_WAITFORU; + if (is_were(pd) && pd->mlet != S_HUMAN) + were_change(mdef); + if (pd == &mons[PM_CLAY_GOLEM]) { + if (g.vis && canseemon(mdef)) { + pline("Some writing vanishes from %s head!", + s_suffix(mon_nam(mdef))); + pline("%s is destroyed!", Monnam(mdef)); + } + mondied(mdef); + if (!DEADMONSTER(mdef)) { + mhm->hitflags = MM_MISS; + mhm->done = TRUE; + return; + } + else if (mdef->mtame && !g.vis) + You(brief_feeling, "strangely sad"); + mhm->hitflags = (MM_DEF_DIED | (grow_up(magr, mdef) ? 0 : MM_AGR_DIED)); + mhm->done = TRUE; + return; + } + if (!Deaf) { + if (!g.vis) + You_hear("laughter."); + else if (canseemon(magr)) + pline("%s chuckles.", Monnam(magr)); + } + } + } +} + /* Template for monster hits monster for AD_FOO. - replace "break" with return - replace "return" with mhm->done = TRUE @@ -2626,19 +2711,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */ return mhm.hitflags; break; case AD_CURS: - if (night() && !rn2(10) && !mdef->mcan) { - if (pd == &mons[PM_CLAY_GOLEM]) { - if (!Blind) - pline("Some writing vanishes from %s head!", - s_suffix(mon_nam(mdef))); - xkilled(mdef, XKILL_NOMSG); - /* Don't return yet; keep hp<1 and mhm.damage=0 for pet msg */ - } else { - mdef->mcan = 1; - You("chuckle."); - } - } - mhm.damage = 0; + mhitm_ad_curs(&g.youmonst, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_DRLI: /* drain life */ mhitm_ad_drli(&g.youmonst, mattk, mdef, &mhm);