From: Pasi Kallinen Date: Mon, 30 Nov 2020 18:32:38 +0000 (+0200) Subject: Unify ad_sgld X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bfe773812e41d9c6d7e3a8308c8e57eb9fc6fc9a;p=nethack Unify ad_sgld --- diff --git a/include/extern.h b/include/extern.h index 7d9907bab..8456059c1 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2764,6 +2764,7 @@ E void FDECL(mhitm_ad_fire, (struct monst *, struct attack *, struct monst *, st E void FDECL(mhitm_ad_cold, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); E void FDECL(mhitm_ad_elec, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); E void FDECL(mhitm_ad_acid, (struct monst *, struct attack *, struct monst *, struct mhitm_data *)); +E void FDECL(mhitm_ad_sgld, (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 f5e15a533..6b21059df 100644 --- a/src/mhitm.c +++ b/src/mhitm.c @@ -1193,32 +1193,9 @@ int dieroll; } break; case AD_SGLD: - mhm.damage = 0; - if (magr->mcan) - break; - /* technically incorrect; no check for stealing gold from - * between mdef's feet... - */ - { - struct obj *gold = findgold(mdef->minvent); - - if (!gold) - break; - obj_extract_self(gold); - add_to_minv(magr, gold); - } - mdef->mstrategy &= ~STRAT_WAITFORU; - if (g.vis && canseemon(mdef)) { - Strcpy(buf, Monnam(magr)); - pline("%s steals some gold from %s.", buf, mon_nam(mdef)); - } - if (!tele_restrict(magr)) { - boolean couldspot = canspotmon(magr); - - (void) rloc(magr, TRUE); - if (g.vis && couldspot && !canspotmon(magr)) - pline("%s suddenly disappears!", buf); - } + mhitm_ad_sgld(magr, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_DRLI: /* drain life */ mhitm_ad_drli(magr, mattk, mdef, &mhm); diff --git a/src/mhitu.c b/src/mhitu.c index 1e45dadcc..e012a7196 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -1330,11 +1330,9 @@ register struct attack *mattk; } break; case AD_SGLD: - hitmsg(mtmp, mattk); - if (g.youmonst.data->mlet == mdat->mlet) - break; - if (!mtmp->mcan) - stealgold(mtmp); + mhitm_ad_sgld(mtmp, mattk, &g.youmonst, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_SSEX: diff --git a/src/uhitm.c b/src/uhitm.c index 330342f7e..176912b04 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -2262,6 +2262,74 @@ struct mhitm_data *mhm; } } +void +mhitm_ad_sgld(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 */ + struct obj *mongold = findgold(mdef->minvent); + + if (mongold) { + obj_extract_self(mongold); + if (merge_choice(g.invent, mongold) || inv_cnt(FALSE) < 52) { + addinv(mongold); + Your("purse feels heavier."); + } else { + You("grab %s's gold, but find no room in your knapsack.", + mon_nam(mdef)); + dropy(mongold); + } + } + exercise(A_DEX, TRUE); + mhm->damage = 0; + } else if (mdef == &g.youmonst) { + /* mhitu */ + hitmsg(magr, mattk); + if (pd->mlet == pa->mlet) + return; + if (!magr->mcan) + stealgold(magr); + } else { + /* mhitm */ + char buf[BUFSZ]; + + mhm->damage = 0; + if (magr->mcan) + return; + /* technically incorrect; no check for stealing gold from + * between mdef's feet... + */ + { + struct obj *gold = findgold(mdef->minvent); + + if (!gold) + return; + obj_extract_self(gold); + add_to_minv(magr, gold); + } + mdef->mstrategy &= ~STRAT_WAITFORU; + if (g.vis && canseemon(mdef)) { + Strcpy(buf, Monnam(magr)); + pline("%s steals some gold from %s.", buf, mon_nam(mdef)); + } + if (!tele_restrict(magr)) { + boolean couldspot = canspotmon(magr); + + (void) rloc(magr, TRUE); + if (g.vis && couldspot && !canspotmon(magr)) + pline("%s suddenly disappears!", buf); + } + } +} + + /* Template for monster hits monster for AD_FOO. - replace "break" with return @@ -2297,7 +2365,6 @@ int specialdmg; /* blessed and/or silver bonus against various things */ register struct permonst *pd = mdef->data; int armpro; boolean negated; - struct obj *mongold; struct mhitm_data mhm; mhm.damage = d((int) mattk->damn, (int) mattk->damd); mhm.hitflags = MM_MISS; @@ -2394,22 +2461,9 @@ int specialdmg; /* blessed and/or silver bonus against various things */ mhm.damage = 0; break; case AD_SGLD: - /* This you as a leprechaun, so steal - real gold only, no lesser coins */ - mongold = findgold(mdef->minvent); - if (mongold) { - obj_extract_self(mongold); - if (merge_choice(g.invent, mongold) || inv_cnt(FALSE) < 52) { - addinv(mongold); - Your("purse feels heavier."); - } else { - You("grab %s's gold, but find no room in your knapsack.", - mon_nam(mdef)); - dropy(mongold); - } - } - exercise(A_DEX, TRUE); - mhm.damage = 0; + mhitm_ad_sgld(&g.youmonst, mattk, mdef, &mhm); + if (mhm.done) + return mhm.hitflags; break; case AD_TLPT: if (mhm.damage <= 0)