From: Pasi Kallinen Date: Fri, 12 Aug 2022 16:37:34 +0000 (+0300) Subject: Macros for checking is object artifact X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9be2e581b70a68a7f5461ab6fd19cdd4ef10d959;p=nethack Macros for checking is object artifact --- diff --git a/include/obj.h b/include/obj.h index 7c716d821..237f48bc3 100644 --- a/include/obj.h +++ b/include/obj.h @@ -391,6 +391,9 @@ struct obj { #define is_mines_prize(o) ((o)->o_id == g.context.achieveo.mines_prize_oid) #define is_soko_prize(o) ((o)->o_id == g.context.achieveo.soko_prize_oid) +#define is_art(o,art) ((o) && (o)->oartifact == (art)) +#define u_wield_art(art) is_art(uwep, art) + /* Flags for get_obj_location(). */ #define CONTAINED_TOO 0x1 #define BURIED_TOO 0x2 diff --git a/src/artifact.c b/src/artifact.c index 96e636f41..14019ba3a 100644 --- a/src/artifact.c +++ b/src/artifact.c @@ -987,7 +987,7 @@ spec_dbon(struct obj *otmp, struct monst *mon, int tmp) if (!weap || (weap->attk.adtyp == AD_PHYS /* check for `NO_ATTK' */ && weap->attk.damn == 0 && weap->attk.damd == 0)) g.spec_dbon_applies = FALSE; - else if (otmp->oartifact == ART_GRIMTOOTH) + else if (is_art(otmp, ART_GRIMTOOTH)) /* Grimtooth has SPFX settings to warn against elves but we want its damage bonus to apply to all targets, so bypass spec_applies() */ g.spec_dbon_applies = TRUE; @@ -1428,7 +1428,7 @@ artifact_hit(struct monst *magr, struct monst *mdef, struct obj *otmp, /* We really want "on a natural 20" but Nethack does it in */ /* reverse from AD&D. */ if (spec_ability(otmp, SPFX_BEHEAD)) { - if (otmp->oartifact == ART_TSURUGI_OF_MURAMASA && dieroll == 1) { + if (is_art(otmp, ART_TSURUGI_OF_MURAMASA) && dieroll == 1) { wepdesc = "The razor-sharp blade"; /* not really beheading, but so close, why add another SPFX */ if (youattack && engulfing_u(mdef)) { @@ -1472,7 +1472,7 @@ artifact_hit(struct monst *magr, struct monst *mdef, struct obj *otmp, otmp->dknown = TRUE; return TRUE; } - } else if (otmp->oartifact == ART_VORPAL_BLADE + } else if (is_art(otmp, ART_VORPAL_BLADE) && (dieroll == 1 || mdef->data == &mons[PM_JABBERWOCK])) { static const char *const behead_msg[2] = { "%s beheads %s!", "%s decapitates %s!" }; @@ -1543,7 +1543,7 @@ artifact_hit(struct monst *magr, struct monst *mdef, struct obj *otmp, the result won't be printed */ char *otmpname = distant_name(otmp, xname); - if (otmp->oartifact == ART_STORMBRINGER) + if (is_art(otmp, ART_STORMBRINGER)) pline_The("%s blade draws the %s from %s!", hcolor(NH_BLACK), life, mon_nam(mdef)); else @@ -1576,7 +1576,7 @@ artifact_hit(struct monst *magr, struct monst *mdef, struct obj *otmp, if (Blind) { You_feel("an %s drain your %s!", - (otmp->oartifact == ART_STORMBRINGER) + is_art(otmp, ART_STORMBRINGER) ? "unholy blade" : "object", life); @@ -1585,7 +1585,7 @@ artifact_hit(struct monst *magr, struct monst *mdef, struct obj *otmp, the result won't be printed */ char *otmpname = distant_name(otmp, xname); - if (otmp->oartifact == ART_STORMBRINGER) + if (is_art(otmp, ART_STORMBRINGER)) pline_The("%s blade drains your %s!", hcolor(NH_BLACK), life); else @@ -1976,7 +1976,7 @@ artifact_light(struct obj *obj) && (obj->owornmask & W_ARM) != 0L) return TRUE; - return (boolean) (get_artifact(obj) && obj->oartifact == ART_SUNSWORD); + return (boolean) (get_artifact(obj) && is_art(obj, ART_SUNSWORD)); } /* KMH -- Talking artifacts are finally implemented */ @@ -2164,10 +2164,9 @@ glow_verb(int count, /* 0 means blind rather than no applicable creatures */ void Sting_effects(int orc_count) /* new count (warn_obj_cnt is old count); -1 is a flag value */ { - if (uwep - && (uwep->oartifact == ART_STING - || uwep->oartifact == ART_ORCRIST - || uwep->oartifact == ART_GRIMTOOTH)) { + if (u_wield_art(ART_STING) + || u_wield_art(ART_ORCRIST) + || u_wield_art(ART_GRIMTOOTH)) { int oldstr = glow_strength(g.warn_obj_cnt), newstr = glow_strength(orc_count); @@ -2450,7 +2449,7 @@ mkot_trap_warn(void) "hot", "very hot", "like fire" }; - if (!uarmg && uwep && uwep->oartifact == ART_MASTER_KEY_OF_THIEVERY) { + if (!uarmg && u_wield_art(ART_MASTER_KEY_OF_THIEVERY)) { int idx, ntraps = count_surround_traps(u.ux, u.uy); if (ntraps != g.mkot_trap_warn_count) { @@ -2468,7 +2467,7 @@ boolean is_magic_key(struct monst *mon, /* if null, non-rogue is assumed */ struct obj *obj) { - if (obj && obj->oartifact == ART_MASTER_KEY_OF_THIEVERY) { + if (is_art(obj, ART_MASTER_KEY_OF_THIEVERY)) { if ((mon == &g.youmonst) ? Role_if(PM_ROGUE) : (mon && mon->data == &mons[PM_ROGUE])) return !obj->cursed; /* a rogue; non-cursed suffices for magic */ diff --git a/src/attrib.c b/src/attrib.c index 7809d3228..b74fcf5ab 100644 --- a/src/attrib.c +++ b/src/attrib.c @@ -879,8 +879,7 @@ from_what(int propidx) /* special cases can have negative values */ replace this with what_blocks() comparable to what_gives() */ switch (-propidx) { case BLINDED: - if (ublindf - && ublindf->oartifact == ART_EYES_OF_THE_OVERWORLD) + if (is_art(ublindf, ART_EYES_OF_THE_OVERWORLD)) Sprintf(buf, because_of, bare_artifactname(ublindf)); break; case INVIS: @@ -1082,7 +1081,7 @@ acurr(int x) || u.umonnum == PM_AMOROUS_DEMON)) return (schar) 18; } else if (x == A_CON) { - if (uwep && uwep->oartifact == ART_OGRESMASHER) + if (u_wield_art(ART_OGRESMASHER)) return (schar) 25; } else if (x == A_INT || x == A_WIS) { /* yes, this may raise int/wis if player is sufficiently @@ -1129,7 +1128,7 @@ extremeattr(int attrindx) /* does attrindx's value match its max or min? */ if (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER) lolimit = hilimit; } else if (attrindx == A_CON) { - if (uwep && uwep->oartifact == ART_OGRESMASHER) + if (u_wield_art(ART_OGRESMASHER)) lolimit = hilimit; } /* this exception is hypothetical; the only other worn item affecting diff --git a/src/dokick.c b/src/dokick.c index 95cc3f117..1236dc690 100644 --- a/src/dokick.c +++ b/src/dokick.c @@ -567,7 +567,7 @@ really_kick_object(coordxy x, coordxy y) } /* Mjollnir is magically too heavy to kick */ - if (g.kickedobj->oartifact == ART_MJOLLNIR) + if (is_art(g.kickedobj, ART_MJOLLNIR)) range = 1; /* see if the object has a place to move into */ diff --git a/src/dothrow.c b/src/dothrow.c index e751ff1e9..a75fac95f 100644 --- a/src/dothrow.c +++ b/src/dothrow.c @@ -115,11 +115,11 @@ throw_obj(struct obj *obj, int shotlimit) if (!canletgo(obj, "throw")) { return ECMD_OK; } - if (obj->oartifact == ART_MJOLLNIR && obj != uwep) { + if (is_art(obj, ART_MJOLLNIR) && obj != uwep) { pline("%s must be wielded before it can be thrown.", The(xname(obj))); return ECMD_OK; } - if ((obj->oartifact == ART_MJOLLNIR && ACURR(A_STR) < STR19(25)) + if ((is_art(obj, ART_MJOLLNIR) && ACURR(A_STR) < STR19(25)) || (obj->otyp == BOULDER && !throws_rocks(g.youmonst.data))) { pline("It's too heavy."); return ECMD_TIME; @@ -1524,7 +1524,7 @@ throwit(struct obj *obj, if (obj->otyp == BOULDER) range = 20; /* you must be giant */ - else if (obj->oartifact == ART_MJOLLNIR) + else if (is_art(obj, ART_MJOLLNIR)) range = (range + 1) / 2; /* it's heavy */ else if (tethered_weapon) /* primary weapon is aklys */ /* if an aklys is going to return, range is limited by the diff --git a/src/engrave.c b/src/engrave.c index 55c4bdbdb..975b79a09 100644 --- a/src/engrave.c +++ b/src/engrave.c @@ -837,7 +837,7 @@ doengrave(void) break; case WEAPON_CLASS: - if (otmp->oartifact == ART_FIRE_BRAND) + if (is_art(otmp, ART_FIRE_BRAND)) type = BURN; else if (is_blade(otmp)) { if ((int) otmp->spe > -3) diff --git a/src/hack.c b/src/hack.c index e85939985..fbd682e0b 100644 --- a/src/hack.c +++ b/src/hack.c @@ -1441,7 +1441,7 @@ trapmove( climb_pit(); break; case TT_WEB: - if (uwep && uwep->oartifact == ART_STING) { + if (u_wield_art(ART_STING)) { /* escape trap but don't move and don't destroy it */ u.utrap = 0; /* caller will call reset_utrap() */ pline("Sting cuts through the web!"); @@ -1747,7 +1747,7 @@ domove_fight_web(coordxy x, coordxy y) if (g.context.forcefight && trap && trap->ttyp == WEB && trap->tseen && uwep) { - if (uwep->oartifact == ART_STING) { + if (u_wield_art(ART_STING)) { /* guaranteed success */ pline("%s cuts through the web!", bare_artifactname(uwep)); diff --git a/src/insight.c b/src/insight.c index 0a1d3e73d..3dfada4ad 100644 --- a/src/insight.c +++ b/src/insight.c @@ -801,7 +801,7 @@ one_characteristic(int mode, int final, int attrindx) case A_DEX: break; case A_CON: - if (uwep && uwep->oartifact == ART_OGRESMASHER && uwep->cursed) + if (u_wield_art(ART_OGRESMASHER) && uwep->cursed) hide_innate_value = TRUE; break; case A_INT: diff --git a/src/makemon.c b/src/makemon.c index 87f0a9809..9b9e6cc04 100644 --- a/src/makemon.c +++ b/src/makemon.c @@ -1359,8 +1359,7 @@ makemon( if (is_dprince(ptr) && ptr->msound == MS_BRIBE) { mtmp->mpeaceful = mtmp->minvis = mtmp->perminvis = 1; mtmp->mavenge = 0; - if (uwep && (uwep->oartifact == ART_EXCALIBUR - || uwep->oartifact == ART_DEMONBANE)) + if (u_wield_art(ART_EXCALIBUR) || u_wield_art(ART_DEMONBANE)) mtmp->mpeaceful = mtmp->mtame = FALSE; } if (mndx == PM_RAVEN && uwep && uwep->otyp == BEC_DE_CORBIN) diff --git a/src/mhitu.c b/src/mhitu.c index 610948bf2..27c2c9de9 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -366,8 +366,8 @@ getmattk(struct monst *magr, struct monst *mdef, && (magr->mcan || (weap && ((weap->otyp == CORPSE && touch_petrifies(&mons[weap->corpsenm])) - || weap->oartifact == ART_STORMBRINGER - || weap->oartifact == ART_VORPAL_BLADE)))) { + || is_art(weap, ART_STORMBRINGER) + || is_art(weap, ART_VORPAL_BLADE))))) { *alt_attk_buf = *attk; attk = alt_attk_buf; attk->adtyp = AD_PHYS; diff --git a/src/minion.c b/src/minion.c index 9fd819e15..c3645cb88 100644 --- a/src/minion.c +++ b/src/minion.c @@ -66,7 +66,7 @@ msummon(struct monst *mon) if (mon) { ptr = mon->data; - if (uwep && uwep->oartifact == ART_DEMONBANE && is_demon(ptr)) { + if (u_wield_art(ART_DEMONBANE) && is_demon(ptr)) { if (canseemon(mon)) pline("%s looks puzzled for a moment.", Monnam(mon)); return 0; @@ -259,8 +259,7 @@ demon_talk(register struct monst *mtmp) { long cash, demand, offer; - if (uwep && (uwep->oartifact == ART_EXCALIBUR - || uwep->oartifact == ART_DEMONBANE)) { + if (u_wield_art(ART_EXCALIBUR) || u_wield_art(ART_DEMONBANE)) { if (canspotmon(mtmp)) pline("%s looks very angry.", Amonnam(mtmp)); else diff --git a/src/mondata.c b/src/mondata.c index da0f2f840..764be9124 100644 --- a/src/mondata.c +++ b/src/mondata.c @@ -424,7 +424,7 @@ can_be_strangled(struct monst* mon) boolean can_track(register struct permonst* ptr) { - if (uwep && uwep->oartifact == ART_EXCALIBUR) + if (u_wield_art(ART_EXCALIBUR)) return TRUE; else return (boolean) haseyes(ptr); diff --git a/src/mplayer.c b/src/mplayer.c index 5def5e45c..966e00e5f 100644 --- a/src/mplayer.c +++ b/src/mplayer.c @@ -266,7 +266,7 @@ mk_mplayer(struct permonst *ptr, coordxy x, coordxy y, boolean special) && monmightthrowwep(otmp)) otmp->quan += (long) rn2(is_spear(otmp) ? 4 : 8); /* mplayers knew better than to overenchant Magicbane */ - if (otmp->oartifact == ART_MAGICBANE) + if (is_art(otmp, ART_MAGICBANE)) otmp->spe = rnd(4); (void) mpickobj(mtmp, otmp); } diff --git a/src/pray.c b/src/pray.c index 5d56f867f..3f5847f94 100644 --- a/src/pray.c +++ b/src/pray.c @@ -794,8 +794,8 @@ gcrownu(void) /* 3.3.[01] had this in the A_NEUTRAL case, preventing chaotic wizards from receiving a spellbook */ if (Role_if(PM_WIZARD) - && (!uwep || (uwep->oartifact != ART_VORPAL_BLADE - && uwep->oartifact != ART_STORMBRINGER)) + && !u_wield_art(ART_VORPAL_BLADE) + && !u_wield_art(ART_STORMBRINGER) && !carrying(SPE_FINGER_OF_DEATH)) { class_gift = SPE_FINGER_OF_DEATH; } else if (Role_if(PM_MONK) && (!uwep || !uwep->oartifact) @@ -816,7 +816,7 @@ gcrownu(void) break; case A_NEUTRAL: u.uevent.uhand_of_elbereth = 2; - in_hand = (uwep && uwep->oartifact == ART_VORPAL_BLADE); + in_hand = u_wield_art(ART_VORPAL_BLADE); already_exists = exist_artifact(LONG_SWORD, artiname(ART_VORPAL_BLADE)); verbalize("Thou shalt be my Envoy of Balance!"); @@ -825,7 +825,7 @@ gcrownu(void) break; case A_CHAOTIC: u.uevent.uhand_of_elbereth = 3; - in_hand = (uwep && uwep->oartifact == ART_STORMBRINGER); + in_hand = u_wield_art(ART_STORMBRINGER); already_exists = exist_artifact(RUNESWORD, artiname(ART_STORMBRINGER)); what = (((already_exists && !in_hand) || class_gift != STRANGE_OBJECT) ? "take lives" @@ -874,7 +874,7 @@ gcrownu(void) Your("sword shines brightly for a moment."); obj = oname(obj, artiname(ART_EXCALIBUR), ONAME_GIFT | ONAME_KNOW_ARTI); - if (obj && obj->oartifact == ART_EXCALIBUR) { + if (is_art(obj, ART_EXCALIBUR)) { u.ugifts++; livelog_printf(LL_DIVINEGIFT | LL_ARTIFACT, "had %s wielded %s transformed into %s", @@ -883,7 +883,7 @@ gcrownu(void) } /* acquire Excalibur's skill regardless of weapon or gift */ unrestrict_weapon_skill(P_LONG_SWORD); - if (obj && obj->oartifact == ART_EXCALIBUR) + if (is_art(obj, ART_EXCALIBUR)) discover_artifact(ART_EXCALIBUR); break; case A_NEUTRAL: @@ -906,7 +906,7 @@ gcrownu(void) } /* acquire Vorpal Blade's skill regardless of weapon or gift */ unrestrict_weapon_skill(P_LONG_SWORD); - if (obj && obj->oartifact == ART_VORPAL_BLADE) + if (is_art(obj, ART_VORPAL_BLADE)) discover_artifact(ART_VORPAL_BLADE); break; case A_CHAOTIC: { @@ -932,7 +932,7 @@ gcrownu(void) } /* acquire Stormbringer's skill regardless of weapon or gift */ unrestrict_weapon_skill(P_BROAD_SWORD); - if (obj && obj->oartifact == ART_STORMBRINGER) + if (is_art(obj, ART_STORMBRINGER)) discover_artifact(ART_STORMBRINGER); break; } diff --git a/src/read.c b/src/read.c index 50cc1611f..5089314a6 100644 --- a/src/read.c +++ b/src/read.c @@ -522,7 +522,7 @@ doread(void) "became literate by reading a coin's engravings"); return ECMD_TIME; - } else if (scroll->oartifact == ART_ORB_OF_FATE) { + } else if (is_art(scroll, ART_ORB_OF_FATE)) { if (Blind) You("feel the engraved signature:"); else diff --git a/src/sit.c b/src/sit.c index 14d387821..737d857f0 100644 --- a/src/sit.c +++ b/src/sit.c @@ -384,7 +384,7 @@ rndcurse(void) struct obj *otmp; static const char mal_aura[] = "feel a malignant aura surround %s."; - if (uwep && (uwep->oartifact == ART_MAGICBANE) && rn2(20)) { + if (u_wield_art(ART_MAGICBANE) && rn2(20)) { You(mal_aura, "the magic-absorbing blade"); return; } diff --git a/src/trap.c b/src/trap.c index 5901eeb7a..3ba2729a5 100644 --- a/src/trap.c +++ b/src/trap.c @@ -2084,7 +2084,7 @@ trapeffect_anti_magic( if (Half_physical_damage || Half_spell_damage) dmgval2 += rnd(4); /* give Magicbane wielder dose of own medicine */ - if (uwep && uwep->oartifact == ART_MAGICBANE) + if (u_wield_art(ART_MAGICBANE)) dmgval2 += rnd(4); /* having an artifact--other than own quest one--which confers magic resistance simply by being carried @@ -2130,7 +2130,7 @@ trapeffect_anti_magic( int dmgval2 = rnd(4); if ((otmp = MON_WEP(mtmp)) != 0 - && otmp->oartifact == ART_MAGICBANE) + && is_art(otmp, ART_MAGICBANE)) dmgval2 += rnd(4); for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) if (otmp->oartifact diff --git a/src/uhitm.c b/src/uhitm.c index 6f6aecc81..568f54517 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -253,7 +253,7 @@ attack_checks( if (flags.confirm && mtmp->mpeaceful && !Confusion && !Hallucination && !Stunned) { /* Intelligent chaotic weapons (Stormbringer) want blood */ - if (wep && wep->oartifact == ART_STORMBRINGER) { + if (is_art(wep, ART_STORMBRINGER)) { g.override_confirmation = TRUE; return FALSE; } @@ -409,7 +409,7 @@ do_attack(struct monst *mtmp) */ /* Intelligent chaotic weapons (Stormbringer) want blood */ if (is_safemon(mtmp) && !g.context.forcefight) { - if (!uwep || uwep->oartifact != ART_STORMBRINGER) { + if (!u_wield_art(ART_STORMBRINGER)) { /* There are some additional considerations: this won't work * if in a shop or Punished or you miss a random roll or * if you can walk thru walls and your pet cannot (KAA) or @@ -690,7 +690,7 @@ hitum(struct monst *mon, struct attack *uattk) /* Cleaver attacks three spots, 'mon' and one on either side of 'mon'; it can't be part of dual-wielding but we guard against that anyway; cleave return value reflects status of primary target ('mon') */ - if (uwep && uwep->oartifact == ART_CLEAVER && !u.twoweap + if (u_wield_art(ART_CLEAVER) && !u.twoweap && !u.uswallow && !u.ustuck && !NODIAG(u.umonnum)) return hitum_cleave(mon, uattk); @@ -874,7 +874,7 @@ hmon_hitmon( if (!train_weapon_skill || mon == u.ustuck || u.twoweap /* Cleaver can hit up to three targets at once so don't let it also hit from behind or shatter foes' weapons */ - || (hand_to_hand && obj->oartifact == ART_CLEAVER)) { + || (hand_to_hand && is_art(obj, ART_CLEAVER))) { ; /* no special bonuses */ } else if (mon->mflee && Role_if(PM_ROGUE) && !Upolyd /* multi-shot throwing is too powerful here */ @@ -4585,7 +4585,7 @@ m_is_steadfast(struct monst *mtmp) || (!is_u && (is_flyer(mtmp->data) || is_floater(mtmp->data)))) return FALSE; - if (otmp && otmp->oartifact == ART_GIANTSLAYER) + if (is_art(otmp, ART_GIANTSLAYER)) return TRUE; return FALSE; } diff --git a/src/wield.c b/src/wield.c index defc62f57..82ae46dc0 100644 --- a/src/wield.c +++ b/src/wield.c @@ -112,8 +112,8 @@ setuwep(struct obj *obj) pline("%s shining.", Tobjnam(olduwep, "stop")); } if (uwep == obj - && ((uwep && uwep->oartifact == ART_OGRESMASHER) - || (olduwep && olduwep->oartifact == ART_OGRESMASHER))) + && (u_wield_art(ART_OGRESMASHER) + || is_art(olduwep, ART_OGRESMASHER))) g.context.botl = 1; /* Note: Explicitly wielding a pick-axe will not give a "bashing" * message. Wielding one via 'a'pplying it will. @@ -1003,7 +1003,7 @@ chwepon(struct obj *otmp, int amount) * addition adverse reaction on Magicbane whose effects are * spe dependent. Give an obscure clue here. */ - if (uwep->oartifact == ART_MAGICBANE && uwep->spe >= 0) { + if (u_wield_art(ART_MAGICBANE) && uwep->spe >= 0) { Your("right %s %sches!", body_part(HAND), (((amount > 1) && (uwep->spe > 1)) ? "flin" : "it")); }