# Source:NetHack 3.6.1/src/artifact.c
Below is the full text to artifact.c from the source code of NetHack 3.6.1. To link to a particular line, write [[Source:NetHack 3.6.1/src/artifact.c#line123]], for example.

Contents

1 Top of file
2 hack_artifacts
3 init_artifacts
4 save_artifacts
5 restore_artifacts
6 artiname
7 mk_artifact
8 artifact_name
9 exist_artifact
10 artifact_exists
11 nartifact_exist
12 spec_ability
13 confers_luck
14 arti_reflects
15 shade_glare
16 restrict_name
17 attacks
18 defends
19 defends_when_carried
20 protects
21 set_artifact_intrinsic
22 touch_artifact
23 arti_immune
24 bane_applies
25 spec_applies
26 spec_m2
27 spec_abon
28 spec_dbon
29 discover_artifact
30 undiscovered_artifact
31 disp_artifact_discoveries
32 Mb_hit
33 artifact_hit
34 doinvoke
35 arti_invoke
36 finesse_ahriman
37 artifact_light
38 arti_speak
39 artifact_has_invprop
40 arti_cost
41 abil_to_adtyp
42 abil_to_spfx
43 what_gives
44 glow_color
45 Sting_effects
46 retouch_object
47 untouchable
48 retouch_equipment
49 count_surround_traps
50 mkot_trap_warn
51 is_magic_key
52 has_magic_key

Top of file
&nbsp;/* NetHack 3.6	artifact.c	$NHDT-Date: 1509836679 2017/11/04 23:04:39 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.106 $ */
&nbsp;/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
&nbsp;/*-Copyright (c) Robert Patrick Rankin, 2013. */
&nbsp;/* NetHack may be freely redistributed.  See license for details. */

The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

&nbsp;
&nbsp;#include "hack.h"
&nbsp;#include "artifact.h"
&nbsp;#include "artilist.h"
&nbsp;
&nbsp;/*
&nbsp; * Note:  both artilist[] and artiexist[] have a dummy element #0,
&nbsp; *        so loops over them should normally start at #1.  The primary
&nbsp; *        exception is the save &amp; restore code, which doesn't care about
&nbsp; *        the contents, just the total size.
&nbsp; */
&nbsp;
&nbsp;extern boolean notonhead; /* for long worms */
&nbsp;
&nbsp;#define get_artifact(o) \
&nbsp;    (((o) &amp;&amp; (o)-&gt;oartifact) ? &amp;artilist[(int) (o)-&gt;oartifact] : 0)
&nbsp;
&nbsp;STATIC_DCL boolean FDECL(bane_applies, (const struct artifact *,
&nbsp;                                        struct monst *));
&nbsp;STATIC_DCL int FDECL(spec_applies, (const struct artifact *, struct monst *));
&nbsp;STATIC_DCL int FDECL(arti_invoke, (struct obj *));
&nbsp;STATIC_DCL boolean FDECL(Mb_hit, (struct monst * magr, struct monst *mdef,
&nbsp;                                struct obj *, int *, int, BOOLEAN_P, char *));
&nbsp;STATIC_DCL unsigned long FDECL(abil_to_spfx, (long *));
&nbsp;STATIC_DCL uchar FDECL(abil_to_adtyp, (long *));
&nbsp;STATIC_DCL boolean FDECL(untouchable, (struct obj *, BOOLEAN_P));
&nbsp;STATIC_DCL int FDECL(count_surround_traps, (int, int));
&nbsp;
&nbsp;/* The amount added to the victim's total hit points to insure that the
&nbsp;   victim will be killed even after damage bonus/penalty adjustments.
&nbsp;   Most such penalties are small, and 200 is plenty; the exception is
&nbsp;   half physical damage.  3.3.1 and previous versions tried to use a very
&nbsp;   large number to account for this case; now, we just compute the fatal
&nbsp;   damage by adding it to 2 times the total hit points instead of 1 time.
&nbsp;   Note: this will still break if they have more than about half the number
&nbsp;   of hit points that will fit in a 15 bit integer. */
&nbsp;#define FATAL_DAMAGE_MODIFIER 200
&nbsp;
&nbsp;/* coordinate effects from spec_dbon() with messages in artifact_hit() */
&nbsp;STATIC_OVL int spec_dbon_applies = 0;
&nbsp;
&nbsp;/* flags including which artifacts have already been created */
&nbsp;static boolean artiexist[1 + NROFARTIFACTS + 1];
&nbsp;/* and a discovery list for them (no dummy first entry here) */
&nbsp;STATIC_OVL xchar artidisco[NROFARTIFACTS];
&nbsp;
&nbsp;STATIC_DCL void NDECL(hack_artifacts);
&nbsp;STATIC_DCL boolean FDECL(attacks, (int, struct obj *));
&nbsp;
hack_artifacts
&nbsp;/* handle some special cases; must be called after u_init() */
&nbsp;STATIC_OVL void
&nbsp;hack_artifacts()
&nbsp;{
&nbsp;    struct artifact *art;
&nbsp;    int alignmnt = aligns[flags.initalign].value;
&nbsp;
&nbsp;    /* Fix up the alignments of "gift" artifacts */
&nbsp;    for (art = artilist + 1; art-&gt;otyp; art++)
&nbsp;        if (art-&gt;role == Role_switch &amp;&amp; art-&gt;alignment != A_NONE)
&nbsp;            art-&gt;alignment = alignmnt;
&nbsp;
&nbsp;    /* Excalibur can be used by any lawful character, not just knights */
&nbsp;    if (!Role_if(PM_KNIGHT))
&nbsp;        artilist[ART_EXCALIBUR].role = NON_PM;
&nbsp;
&nbsp;    /* Fix up the quest artifact */
&nbsp;    if (urole.questarti) {
&nbsp;        artilist[urole.questarti].alignment = alignmnt;
&nbsp;        artilist[urole.questarti].role = Role_switch;
&nbsp;    }
&nbsp;    return;
&nbsp;}
&nbsp;
init_artifacts
&nbsp;/* zero out the artifact existence list */
&nbsp;void
&nbsp;init_artifacts()
&nbsp;{
&nbsp;    (void) memset((genericptr_t) artiexist, 0, sizeof artiexist);
&nbsp;    (void) memset((genericptr_t) artidisco, 0, sizeof artidisco);
&nbsp;    hack_artifacts();
&nbsp;}
&nbsp;
save_artifacts
&nbsp;void
&nbsp;save_artifacts(fd)
&nbsp;int fd;
&nbsp;{
&nbsp;    bwrite(fd, (genericptr_t) artiexist, sizeof artiexist);
&nbsp;    bwrite(fd, (genericptr_t) artidisco, sizeof artidisco);
&nbsp;}
&nbsp;
restore_artifacts
&nbsp;void
&nbsp;restore_artifacts(fd)
&nbsp;int fd;
&nbsp;{
&nbsp;    mread(fd, (genericptr_t) artiexist, sizeof artiexist);
&nbsp;    mread(fd, (genericptr_t) artidisco, sizeof artidisco);
&nbsp;    hack_artifacts(); /* redo non-saved special cases */
&nbsp;}
&nbsp;
artiname
&nbsp;const char *
&nbsp;artiname(artinum)
&nbsp;int artinum;
&nbsp;{
&nbsp;    if (artinum &lt;= 0 || artinum &gt; NROFARTIFACTS)
&nbsp;        return "";
&nbsp;    return artilist[artinum].name;
&nbsp;}
&nbsp;
mk_artifact
&nbsp;/*
&nbsp;   Make an artifact.  If a specific alignment is specified, then an object of
&nbsp;   the appropriate alignment is created from scratch, or 0 is returned if
&nbsp;   none is available.  (If at least one aligned artifact has already been
&nbsp;   given, then unaligned ones also become eligible for this.)
&nbsp;   If no alignment is given, then 'otmp' is converted
&nbsp;   into an artifact of matching type, or returned as-is if that's not
&nbsp;   possible.
&nbsp;   For the 2nd case, caller should use ``obj = mk_artifact(obj, A_NONE);''
&nbsp;   for the 1st, ``obj = mk_artifact((struct obj *)0, some_alignment);''.
&nbsp; */
&nbsp;struct obj *
&nbsp;mk_artifact(otmp, alignment)
&nbsp;struct obj *otmp;   /* existing object; ignored if alignment specified */
&nbsp;aligntyp alignment; /* target alignment, or A_NONE */
&nbsp;{
&nbsp;    const struct artifact *a;
&nbsp;    int m, n, altn;
&nbsp;    boolean by_align = (alignment != A_NONE);
&nbsp;    short o_typ = (by_align || !otmp) ? 0 : otmp-&gt;otyp;
&nbsp;    boolean unique = !by_align &amp;&amp; otmp &amp;&amp; objects[o_typ].oc_unique;
&nbsp;    short eligible[NROFARTIFACTS];
&nbsp;
&nbsp;    n = altn = 0;    /* no candidates found yet */
&nbsp;    eligible[0] = 0; /* lint suppression */
&nbsp;    /* gather eligible artifacts */
&nbsp;    for (m = 1, a = &amp;artilist[m]; a-&gt;otyp; a++, m++) {
&nbsp;        if (artiexist[m])
&nbsp;            continue;
&nbsp;        if ((a-&gt;spfx &amp; SPFX_NOGEN) || unique)
&nbsp;            continue;
&nbsp;
&nbsp;        if (!by_align) {
&nbsp;            /* looking for a particular type of item; not producing a
&nbsp;               divine gift so we don't care about role's first choice */
&nbsp;            if (a-&gt;otyp == o_typ)
&nbsp;                eligible[n++] = m;
&nbsp;            continue; /* move on to next possibility */
&nbsp;        }
&nbsp;
&nbsp;        /* we're looking for an alignment-specific item
&nbsp;           suitable for hero's role+race */
&nbsp;        if ((a-&gt;alignment == alignment || a-&gt;alignment == A_NONE)
&nbsp;            /* avoid enemies' equipment */
&nbsp;            &amp;&amp; (a-&gt;race == NON_PM || !race_hostile(&amp;mons[a-&gt;race]))) {
&nbsp;            /* when a role-specific first choice is available, use it */
&nbsp;            if (Role_if(a-&gt;role)) {
&nbsp;                /* make this be the only possibility in the list */
&nbsp;                eligible[0] = m;
&nbsp;                n = 1;
&nbsp;                break; /* skip all other candidates */
&nbsp;            }
&nbsp;            /* found something to consider for random selection */
&nbsp;            if (a-&gt;alignment != A_NONE || u.ugifts &gt; 0) {
&nbsp;                /* right alignment, or non-aligned with at least 1
&nbsp;                   previous gift bestowed, makes this one viable */
&nbsp;                eligible[n++] = m;
&nbsp;            } else {
&nbsp;                /* non-aligned with no previous gifts;
&nbsp;                   if no candidates have been found yet, record
&nbsp;                   this one as a[nother] fallback possibility in
&nbsp;                   case all aligned candidates have been used up
&nbsp;                   (via wishing, naming, bones, random generation) */
&nbsp;                if (!n)
&nbsp;                    eligible[altn++] = m;
&nbsp;                /* [once a regular candidate is found, the list
&nbsp;                   is overwritten and `altn' becomes irrelevant] */
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* resort to fallback list if main list was empty */
&nbsp;    if (!n)
&nbsp;        n = altn;
&nbsp;
&nbsp;    if (n) {
&nbsp;        /* found at least one candidate; pick one at random */
&nbsp;        m = eligible[rn2(n)]; /* [0..n-1] */
&nbsp;        a = &amp;artilist[m];
&nbsp;
&nbsp;        /* make an appropriate object if necessary, then christen it */
&nbsp;        if (by_align)
&nbsp;            otmp = mksobj((int) a-&gt;otyp, TRUE, FALSE);
&nbsp;
&nbsp;        if (otmp) {
&nbsp;            otmp = oname(otmp, a-&gt;name);
&nbsp;            otmp-&gt;oartifact = m;
&nbsp;            artiexist[m] = TRUE;
&nbsp;        }
&nbsp;    } else {
&nbsp;        /* nothing appropriate could be found; return original object */
&nbsp;        if (by_align)
&nbsp;            otmp = 0; /* (there was no original object) */
&nbsp;    }
&nbsp;    return otmp;
&nbsp;}
&nbsp;
artifact_name
&nbsp;/*
&nbsp; * Returns the full name (with articles and correct capitalization) of an
&nbsp; * artifact named "name" if one exists, or NULL, it not.
&nbsp; * The given name must be rather close to the real name for it to match.
&nbsp; * The object type of the artifact is returned in otyp if the return value
&nbsp; * is non-NULL.
&nbsp; */
&nbsp;const char *
&nbsp;artifact_name(name, otyp)
&nbsp;const char *name;
&nbsp;short *otyp;
&nbsp;{
&nbsp;    register const struct artifact *a;
&nbsp;    register const char *aname;
&nbsp;
&nbsp;    if (!strncmpi(name, "the ", 4))
&nbsp;        name += 4;
&nbsp;
&nbsp;    for (a = artilist + 1; a-&gt;otyp; a++) {
&nbsp;        aname = a-&gt;name;
&nbsp;        if (!strncmpi(aname, "the ", 4))
&nbsp;            aname += 4;
&nbsp;        if (!strcmpi(name, aname)) {
&nbsp;            *otyp = a-&gt;otyp;
&nbsp;            return a-&gt;name;
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    return (char *) 0;
&nbsp;}
&nbsp;
exist_artifact
&nbsp;boolean
&nbsp;exist_artifact(otyp, name)
&nbsp;int otyp;
&nbsp;const char *name;
&nbsp;{
&nbsp;    register const struct artifact *a;
&nbsp;    boolean *arex;
&nbsp;
&nbsp;    if (otyp &amp;&amp; *name)
&nbsp;        for (a = artilist + 1, arex = artiexist + 1; a-&gt;otyp; a++, arex++)
&nbsp;            if ((int) a-&gt;otyp == otyp &amp;&amp; !strcmp(a-&gt;name, name))
&nbsp;                return *arex;
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
artifact_exists
&nbsp;void
&nbsp;artifact_exists(otmp, name, mod)
&nbsp;struct obj *otmp;
&nbsp;const char *name;
&nbsp;boolean mod;
&nbsp;{
&nbsp;    register const struct artifact *a;
&nbsp;
&nbsp;    if (otmp &amp;&amp; *name)
&nbsp;        for (a = artilist + 1; a-&gt;otyp; a++)
&nbsp;            if (a-&gt;otyp == otmp-&gt;otyp &amp;&amp; !strcmp(a-&gt;name, name)) {
&nbsp;                register int m = (int) (a - artilist);
&nbsp;                otmp-&gt;oartifact = (char) (mod ? m : 0);
&nbsp;                otmp-&gt;age = 0;
&nbsp;                if (otmp-&gt;otyp == RIN_INCREASE_DAMAGE)
&nbsp;                    otmp-&gt;spe = 0;
&nbsp;                artiexist[m] = mod;
&nbsp;                break;
&nbsp;            }
&nbsp;    return;
&nbsp;}
&nbsp;
nartifact_exist
&nbsp;int
&nbsp;nartifact_exist()
&nbsp;{
&nbsp;    int a = 0;
&nbsp;    int n = SIZE(artiexist);
&nbsp;
&nbsp;    while (n &gt; 1)
&nbsp;        if (artiexist[--n])
&nbsp;            a++;
&nbsp;
&nbsp;    return a;
&nbsp;}
&nbsp;
spec_ability
&nbsp;boolean
&nbsp;spec_ability(otmp, abil)
&nbsp;struct obj *otmp;
&nbsp;unsigned long abil;
&nbsp;{
&nbsp;    const struct artifact *arti = get_artifact(otmp);
&nbsp;
&nbsp;    return (boolean) (arti &amp;&amp; (arti-&gt;spfx &amp; abil) != 0L);
&nbsp;}
&nbsp;
confers_luck
&nbsp;/* used so that callers don't need to known about SPFX_ codes */
&nbsp;boolean
&nbsp;confers_luck(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    /* might as well check for this too */
&nbsp;    if (obj-&gt;otyp == LUCKSTONE)
&nbsp;        return TRUE;
&nbsp;
&nbsp;    return (boolean) (obj-&gt;oartifact &amp;&amp; spec_ability(obj, SPFX_LUCK));
&nbsp;}
&nbsp;
arti_reflects
&nbsp;/* used to check whether a monster is getting reflection from an artifact */
&nbsp;boolean
&nbsp;arti_reflects(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    const struct artifact *arti = get_artifact(obj);
&nbsp;
&nbsp;    if (arti) {
&nbsp;        /* while being worn */
&nbsp;        if ((obj-&gt;owornmask &amp; ~W_ART) &amp;&amp; (arti-&gt;spfx &amp; SPFX_REFLECT))
&nbsp;            return TRUE;
&nbsp;        /* just being carried */
&nbsp;        if (arti-&gt;cspfx &amp; SPFX_REFLECT)
&nbsp;            return TRUE;
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
shade_glare
&nbsp;/* decide whether this obj is effective when attacking against shades;
&nbsp;   does not consider the bonus for blessed objects versus undead */
&nbsp;boolean
&nbsp;shade_glare(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    const struct artifact *arti;
&nbsp;
&nbsp;    /* any silver object is effective */
&nbsp;    if (objects[obj-&gt;otyp].oc_material == SILVER)
&nbsp;        return TRUE;
&nbsp;    /* non-silver artifacts with bonus against undead also are effective */
&nbsp;    arti = get_artifact(obj);
&nbsp;    if (arti &amp;&amp; (arti-&gt;spfx &amp; SPFX_DFLAG2) &amp;&amp; arti-&gt;mtype == M2_UNDEAD)
&nbsp;        return TRUE;
&nbsp;    /* [if there was anything with special bonus against noncorporeals,
&nbsp;       it would be effective too] */
&nbsp;    /* otherwise, harmless to shades */
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
restrict_name
&nbsp;/* returns 1 if name is restricted for otmp-&gt;otyp */
&nbsp;boolean
&nbsp;restrict_name(otmp, name)
&nbsp;struct obj *otmp;
&nbsp;const char *name;
&nbsp;{
&nbsp;    register const struct artifact *a;
&nbsp;    const char *aname, *odesc, *other;
&nbsp;    boolean sametype[NUM_OBJECTS];
&nbsp;    int i, lo, hi, otyp = otmp-&gt;otyp, ocls = objects[otyp].oc_class;
&nbsp;
&nbsp;    if (!*name)
&nbsp;        return FALSE;
&nbsp;    if (!strncmpi(name, "the ", 4))
&nbsp;        name += 4;
&nbsp;
&nbsp;    /* decide what types of objects are the same as otyp;
&nbsp;       if it's been discovered, then only itself matches;
&nbsp;       otherwise, include all other undiscovered objects
&nbsp;       of the same class which have the same description
&nbsp;       or share the same pool of shuffled descriptions */
&nbsp;    (void) memset((genericptr_t) sametype, 0, sizeof sametype); /* FALSE */
&nbsp;    sametype[otyp] = TRUE;
&nbsp;    if (!objects[otyp].oc_name_known
&nbsp;        &amp;&amp; (odesc = OBJ_DESCR(objects[otyp])) != 0) {
&nbsp;        obj_shuffle_range(otyp, &amp;lo, &amp;hi);
&nbsp;        for (i = bases[ocls]; i &lt; NUM_OBJECTS; i++) {
&nbsp;            if (objects[i].oc_class != ocls)
&nbsp;                break;
&nbsp;            if (!objects[i].oc_name_known
&nbsp;                &amp;&amp; (other = OBJ_DESCR(objects[i])) != 0
&nbsp;                &amp;&amp; (!strcmp(odesc, other) || (i &gt;= lo &amp;&amp; i &lt;= hi)))
&nbsp;                sametype[i] = TRUE;
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* Since almost every artifact is SPFX_RESTR, it doesn't cost
&nbsp;       us much to do the string comparison before the spfx check.
&nbsp;       Bug fix:  don't name multiple elven daggers "Sting".
&nbsp;     */
&nbsp;    for (a = artilist + 1; a-&gt;otyp; a++) {
&nbsp;        if (!sametype[a-&gt;otyp])
&nbsp;            continue;
&nbsp;        aname = a-&gt;name;
&nbsp;        if (!strncmpi(aname, "the ", 4))
&nbsp;            aname += 4;
&nbsp;        if (!strcmp(aname, name))
&nbsp;            return (boolean) ((a-&gt;spfx &amp; (SPFX_NOGEN | SPFX_RESTR)) != 0
&nbsp;                              || otmp-&gt;quan &gt; 1L);
&nbsp;    }
&nbsp;
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
attacks
&nbsp;STATIC_OVL boolean
&nbsp;attacks(adtyp, otmp)
&nbsp;int adtyp;
&nbsp;struct obj *otmp;
&nbsp;{
&nbsp;    register const struct artifact *weap;
&nbsp;
&nbsp;    if ((weap = get_artifact(otmp)) != 0)
&nbsp;        return (boolean) (weap-&gt;attk.adtyp == adtyp);
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
defends
&nbsp;boolean
&nbsp;defends(adtyp, otmp)
&nbsp;int adtyp;
&nbsp;struct obj *otmp;
&nbsp;{
&nbsp;    register const struct artifact *weap;
&nbsp;
&nbsp;    if ((weap = get_artifact(otmp)) != 0)
&nbsp;        return (boolean) (weap-&gt;defn.adtyp == adtyp);
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
defends_when_carried
&nbsp;/* used for monsters */
&nbsp;boolean
&nbsp;defends_when_carried(adtyp, otmp)
&nbsp;int adtyp;
&nbsp;struct obj *otmp;
&nbsp;{
&nbsp;    register const struct artifact *weap;
&nbsp;
&nbsp;    if ((weap = get_artifact(otmp)) != 0)
&nbsp;        return (boolean) (weap-&gt;cary.adtyp == adtyp);
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
protects
&nbsp;/* determine whether an item confers Protection */
&nbsp;boolean
&nbsp;protects(otmp, being_worn)
&nbsp;struct obj *otmp;
&nbsp;boolean being_worn;
&nbsp;{
&nbsp;    const struct artifact *arti;
&nbsp;
&nbsp;    if (being_worn &amp;&amp; objects[otmp-&gt;otyp].oc_oprop == PROTECTION)
&nbsp;        return TRUE;
&nbsp;    arti = get_artifact(otmp);
&nbsp;    if (!arti)
&nbsp;        return FALSE;
&nbsp;    return (boolean) ((arti-&gt;cspfx &amp; SPFX_PROTECT) != 0
&nbsp;                      || (being_worn &amp;&amp; (arti-&gt;spfx &amp; SPFX_PROTECT) != 0));
&nbsp;}
&nbsp;
set_artifact_intrinsic
&nbsp;/*
&nbsp; * a potential artifact has just been worn/wielded/picked-up or
&nbsp; * unworn/unwielded/dropped.  Pickup/drop only set/reset the W_ART mask.
&nbsp; */
&nbsp;void
&nbsp;set_artifact_intrinsic(otmp, on, wp_mask)
&nbsp;struct obj *otmp;
&nbsp;boolean on;
&nbsp;long wp_mask;
&nbsp;{
&nbsp;    long *mask = 0;
&nbsp;    register const struct artifact *art, *oart = get_artifact(otmp);
&nbsp;    register struct obj *obj;
&nbsp;    register uchar dtyp;
&nbsp;    register long spfx;
&nbsp;
&nbsp;    if (!oart)
&nbsp;        return;
&nbsp;
&nbsp;    /* effects from the defn field */
&nbsp;    dtyp = (wp_mask != W_ART) ? oart-&gt;defn.adtyp : oart-&gt;cary.adtyp;
&nbsp;
&nbsp;    if (dtyp == AD_FIRE)
&nbsp;        mask = &amp;EFire_resistance;
&nbsp;    else if (dtyp == AD_COLD)
&nbsp;        mask = &amp;ECold_resistance;
&nbsp;    else if (dtyp == AD_ELEC)
&nbsp;        mask = &amp;EShock_resistance;
&nbsp;    else if (dtyp == AD_MAGM)
&nbsp;        mask = &amp;EAntimagic
&nbsp;    else if (dtyp == AD_DISN)
&nbsp;        mask = &amp;EDisint_resistance;
&nbsp;    else if (dtyp == AD_DRST)
&nbsp;        mask = &amp;EPoison_resistance;
&nbsp;    else if (dtyp == AD_DRLI)
&nbsp;        mask = &amp;EDrain_resistance;
&nbsp;
&nbsp;    if (mask &amp;&amp; wp_mask == W_ART &amp;&amp; !on) {
&nbsp;        /* find out if some other artifact also confers this intrinsic;
&nbsp;           if so, leave the mask alone */
&nbsp;        for (obj = invent; obj; obj = obj-&gt;nobj) {
&nbsp;            if (obj != otmp &amp;&amp; obj-&gt;oartifact) {
&nbsp;                art = get_artifact(obj);
&nbsp;                if (art &amp;&amp; art-&gt;cary.adtyp == dtyp) {
&nbsp;                    mask = (long *) 0;
&nbsp;                    break;
&nbsp;                }
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;    if (mask) {
&nbsp;        if (on)
&nbsp;            *mask |= wp_mask;
&nbsp;        else
&nbsp;            *mask &amp;= ~wp_mask;
&nbsp;    }
&nbsp;
&nbsp;    /* intrinsics from the spfx field; there could be more than one */
&nbsp;    spfx = (wp_mask != W_ART) ? oart-&gt;spfx : oart-&gt;cspfx;
&nbsp;    if (spfx &amp;&amp; wp_mask == W_ART &amp;&amp; !on) {
&nbsp;        /* don't change any spfx also conferred by other artifacts */
&nbsp;        for (obj = invent; obj; obj = obj-&gt;nobj)
&nbsp;            if (obj != otmp &amp;&amp; obj-&gt;oartifact) {
&nbsp;                art = get_artifact(obj);
&nbsp;                if (art)
&nbsp;                    spfx &amp;= ~art-&gt;cspfx;
&nbsp;            }
&nbsp;    }
&nbsp;
&nbsp;    if (spfx &amp; SPFX_SEARCH) {
&nbsp;        if (on)
&nbsp;            ESearching |= wp_mask;
&nbsp;        else
&nbsp;            ESearching &amp;= ~wp_mask;
&nbsp;    }
&nbsp;    if (spfx &amp; SPFX_HALRES) {
&nbsp;        /* make_hallucinated must (re)set the mask itself to get
&nbsp;         * the display right */
&nbsp;        /* restoring needed because this is the only artifact intrinsic
&nbsp;         * that can print a message--need to guard against being printed
&nbsp;         * when restoring a game
&nbsp;         */
&nbsp;        (void) make_hallucinated((long) !on, restoring ? FALSE : TRUE,
&nbsp;                                 wp_mask);
&nbsp;    }
&nbsp;    if (spfx &amp; SPFX_ESP) {
&nbsp;        if (on)
&nbsp;            ETelepat |= wp_mask;
&nbsp;        else
&nbsp;            ETelepat &amp;= ~wp_mask;
&nbsp;        see_monsters();
&nbsp;    }
&nbsp;    if (spfx &amp; SPFX_STLTH) {
&nbsp;        if (on)
&nbsp;            EStealth |= wp_mask;
&nbsp;        else
&nbsp;            EStealth &amp;= ~wp_mask;
&nbsp;    }
&nbsp;    if (spfx &amp; SPFX_REGEN) {
&nbsp;        if (on)
&nbsp;            ERegeneration |= wp_mask;
&nbsp;        else
&nbsp;            ERegeneration &amp;= ~wp_mask;
&nbsp;    }
&nbsp;    if (spfx &amp; SPFX_TCTRL) {
&nbsp;        if (on)
&nbsp;            ETeleport_control |= wp_mask;
&nbsp;        else
&nbsp;            ETeleport_control &amp;= ~wp_mask;
&nbsp;    }
&nbsp;    if (spfx &amp; SPFX_WARN) {
&nbsp;        if (spec_m2(otmp)) {
&nbsp;            if (on) {
&nbsp;                EWarn_of_mon |= wp_mask;
&nbsp;                context.warntype.obj |= spec_m2(otmp);
&nbsp;            } else {
&nbsp;                EWarn_of_mon &amp;= ~wp_mask;
&nbsp;                context.warntype.obj &amp;= ~spec_m2(otmp);
&nbsp;            }
&nbsp;            see_monsters();
&nbsp;        } else {
&nbsp;            if (on)
&nbsp;                EWarning |= wp_mask;
&nbsp;            else
&nbsp;                EWarning &amp;= ~wp_mask;
&nbsp;        }
&nbsp;    }
&nbsp;    if (spfx &amp; SPFX_EREGEN) {
&nbsp;        if (on)
&nbsp;            EEnergy_regeneration |= wp_mask;
&nbsp;        else
&nbsp;            EEnergy_regeneration &amp;= ~wp_mask;
&nbsp;    }
&nbsp;    if (spfx &amp; SPFX_HSPDAM) {
&nbsp;        if (on)
&nbsp;            EHalf_spell_damage |= wp_mask;
&nbsp;        else
&nbsp;            EHalf_spell_damage &amp;= ~wp_mask;
&nbsp;    }
&nbsp;    if (spfx &amp; SPFX_HPHDAM) {
&nbsp;        if (on)
&nbsp;            EHalf_physical_damage |= wp_mask;
&nbsp;        else
&nbsp;            EHalf_physical_damage &amp;= ~wp_mask;
&nbsp;    }
&nbsp;    if (spfx &amp; SPFX_XRAY) {
&nbsp;        /* this assumes that no one else is using xray_range */
&nbsp;        if (on)
&nbsp;            u.xray_range = 3;
&nbsp;        else
&nbsp;            u.xray_range = -1;
&nbsp;        vision_full_recalc = 1;
&nbsp;    }
&nbsp;    if ((spfx &amp; SPFX_REFLECT) &amp;&amp; (wp_mask &amp; W_WEP)) {
&nbsp;        if (on)
&nbsp;            EReflecting |= wp_mask;
&nbsp;        else
&nbsp;            EReflecting &amp;= ~wp_mask;
&nbsp;    }
&nbsp;    if (spfx &amp; SPFX_PROTECT) {
&nbsp;        if (on)
&nbsp;            EProtection |= wp_mask;
&nbsp;        else
&nbsp;            EProtection &amp;= ~wp_mask;
&nbsp;    }
&nbsp;
&nbsp;    if (wp_mask == W_ART &amp;&amp; !on &amp;&amp; oart-&gt;inv_prop) {
&nbsp;        /* might have to turn off invoked power too */
&nbsp;        if (oart-&gt;inv_prop &lt;= LAST_PROP
&nbsp;            &amp;&amp; (u.uprops[oart-&gt;inv_prop].extrinsic &amp; W_ARTI))
&nbsp;            (void) arti_invoke(otmp);
&nbsp;    }
&nbsp;}
&nbsp;
&nbsp;/* touch_artifact()'s return value isn't sufficient to tell whether it
&nbsp;   dished out damage, and tracking changes to u.uhp, u.mh, Lifesaved
&nbsp;   when trying to avoid second wounding is too cumbersome */
&nbsp;STATIC_VAR boolean touch_blasted; /* for retouch_object() */
&nbsp;
touch_artifact
&nbsp;/*
&nbsp; * creature (usually hero) tries to touch (pick up or wield) an artifact obj.
&nbsp; * Returns 0 if the object refuses to be touched.
&nbsp; * This routine does not change any object chains.
&nbsp; * Ignores such things as gauntlets, assuming the artifact is not
&nbsp; * fooled by such trappings.
&nbsp; */
&nbsp;int
&nbsp;touch_artifact(obj, mon)
&nbsp;struct obj *obj;
&nbsp;struct monst *mon;
&nbsp;{
&nbsp;    register const struct artifact *oart = get_artifact(obj);
&nbsp;    boolean badclass, badalign, self_willed, yours;
&nbsp;
&nbsp;    touch_blasted = FALSE;
&nbsp;    if (!oart)
&nbsp;        return 1;
&nbsp;
&nbsp;    yours = (mon == &amp;youmonst);
&nbsp;    /* all quest artifacts are self-willed; if this ever changes, `badclass'
&nbsp;       will have to be extended to explicitly include quest artifacts */
&nbsp;    self_willed = ((oart-&gt;spfx &amp; SPFX_INTEL) != 0);
&nbsp;    if (yours) {
&nbsp;        badclass = self_willed
&nbsp;                   &amp;&amp; ((oart-&gt;role != NON_PM &amp;&amp; !Role_if(oart-&gt;role))
&nbsp;                       || (oart-&gt;race != NON_PM &amp;&amp; !Race_if(oart-&gt;race)));
&nbsp;        badalign = ((oart-&gt;spfx &amp; SPFX_RESTR) != 0
&nbsp;                    &amp;&amp; oart-&gt;alignment != A_NONE
&nbsp;                    &amp;&amp; (oart-&gt;alignment != u.ualign.type
&nbsp;                        || u.ualign.record &lt; 0));
&nbsp;    } else if (!is_covetous(mon-&gt;data) &amp;&amp; !is_mplayer(mon-&gt;data)) {
&nbsp;        badclass = self_willed &amp;&amp; oart-&gt;role != NON_PM
&nbsp;                   &amp;&amp; oart != &amp;artilist[ART_EXCALIBUR];
&nbsp;        badalign = (oart-&gt;spfx &amp; SPFX_RESTR) &amp;&amp; oart-&gt;alignment != A_NONE
&nbsp;                   &amp;&amp; (oart-&gt;alignment != mon_aligntyp(mon));
&nbsp;    } else { /* an M3_WANTSxxx monster or a fake player */
&nbsp;        /* special monsters trying to take the Amulet, invocation tools or
&nbsp;           quest item can touch anything except `spec_applies' artifacts */
&nbsp;        badclass = badalign = FALSE;
&nbsp;    }
&nbsp;    /* weapons which attack specific categories of monsters are
&nbsp;       bad for them even if their alignments happen to match */
&nbsp;    if (!badalign)
&nbsp;        badalign = bane_applies(oart, mon);
&nbsp;
&nbsp;    if (((badclass || badalign) &amp;&amp; self_willed)
&nbsp;        || (badalign &amp;&amp; (!yours || !rn2(4)))) {
&nbsp;        int dmg, tmp;
&nbsp;        char buf[BUFSZ];
&nbsp;
&nbsp;        if (!yours)
&nbsp;            return 0;
&nbsp;        You("are blasted by %s power!", s_suffix(the(xname(obj))));
&nbsp;        touch_blasted = TRUE;
&nbsp;        dmg = d((Antimagic ? 2 : 4), (self_willed ? 10 : 4));
&nbsp;        /* add half (maybe quarter) of the usual silver damage bonus */
&nbsp;        if (objects[obj-&gt;otyp].oc_material == SILVER &amp;&amp; Hate_silver)
&nbsp;            tmp = rnd(10), dmg += Maybe_Half_Phys(tmp);
&nbsp;        Sprintf(buf, "touching %s", oart-&gt;name);
&nbsp;        losehp(dmg, buf, KILLED_BY); /* magic damage, not physical */
&nbsp;        exercise(A_WIS, FALSE);
&nbsp;    }
&nbsp;
&nbsp;    /* can pick it up unless you're totally non-synch'd with the artifact */
&nbsp;    if (badclass &amp;&amp; badalign &amp;&amp; self_willed) {
&nbsp;        if (yours) {
&nbsp;            if (!carried(obj))
&nbsp;                pline("%s your grasp!", Tobjnam(obj, "evade"));
&nbsp;            else
&nbsp;                pline("%s beyond your control!", Tobjnam(obj, "are"));
&nbsp;        }
&nbsp;        return 0;
&nbsp;    }
&nbsp;
&nbsp;    return 1;
&nbsp;}
&nbsp;
arti_immune
&nbsp;/* decide whether an artifact itself is vulnerable to a particular type
&nbsp;   of erosion damage, independent of the properties of its bearer */
&nbsp;boolean
&nbsp;arti_immune(obj, dtyp)
&nbsp;struct obj *obj;
&nbsp;int dtyp;
&nbsp;{
&nbsp;    register const struct artifact *weap = get_artifact(obj);
&nbsp;
&nbsp;    if (!weap)
&nbsp;        return FALSE;
&nbsp;    if (dtyp == AD_PHYS)
&nbsp;        return FALSE; /* nothing is immune to phys dmg */
&nbsp;    return (boolean) (weap-&gt;attk.adtyp == dtyp
&nbsp;                      || weap-&gt;defn.adtyp == dtyp
&nbsp;                      || weap-&gt;cary.adtyp == dtyp);
&nbsp;}
&nbsp;
bane_applies
&nbsp;STATIC_OVL boolean
&nbsp;bane_applies(oart, mon)
&nbsp;const struct artifact *oart;
&nbsp;struct monst *mon;
&nbsp;{
&nbsp;    struct artifact atmp;
&nbsp;
&nbsp;    if (oart &amp;&amp; (oart-&gt;spfx &amp; SPFX_DBONUS) != 0) {
&nbsp;        atmp = *oart;
&nbsp;        atmp.spfx &amp;= SPFX_DBONUS; /* clear other spfx fields */
&nbsp;        if (spec_applies(&amp;atmp, mon))
&nbsp;            return TRUE;
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
spec_applies
&nbsp;/* decide whether an artifact's special attacks apply against mtmp */
&nbsp;STATIC_OVL int
&nbsp;spec_applies(weap, mtmp)
&nbsp;register const struct artifact *weap;
&nbsp;struct monst *mtmp;
&nbsp;{
&nbsp;    struct permonst *ptr;
&nbsp;    boolean yours;
&nbsp;
&nbsp;    if (!(weap-&gt;spfx &amp; (SPFX_DBONUS | SPFX_ATTK)))
&nbsp;        return (weap-&gt;attk.adtyp == AD_PHYS);
&nbsp;
&nbsp;    yours = (mtmp == &amp;youmonst);
&nbsp;    ptr = mtmp-&gt;data;
&nbsp;
&nbsp;    if (weap-&gt;spfx &amp; SPFX_DMONS) {
&nbsp;        return (ptr == &amp;mons[(int) weap-&gt;mtype]);
&nbsp;    } else if (weap-&gt;spfx &amp; SPFX_DCLAS) {
&nbsp;        return (weap-&gt;mtype == (unsigned long) ptr-&gt;mlet);
&nbsp;    } else if (weap-&gt;spfx &amp; SPFX_DFLAG1) {
&nbsp;        return ((ptr-&gt;mflags1 &amp; weap-&gt;mtype) != 0L);
&nbsp;    } else if (weap-&gt;spfx &amp; SPFX_DFLAG2) {
&nbsp;        return ((ptr-&gt;mflags2 &amp; weap-&gt;mtype)
&nbsp;                || (yours
&nbsp;                    &amp;&amp; ((!Upolyd &amp;&amp; (urace.selfmask &amp; weap-&gt;mtype))
&nbsp;                        || ((weap-&gt;mtype &amp; M2_WERE) &amp;&amp; u.ulycn &gt;= LOW_PM))));
&nbsp;    } else if (weap-&gt;spfx &amp; SPFX_DALIGN) {
&nbsp;        return yours ? (u.ualign.type != weap-&gt;alignment)
&nbsp;                     : (ptr-&gt;maligntyp == A_NONE
&nbsp;                        || sgn(ptr-&gt;maligntyp) != weap-&gt;alignment);
&nbsp;    } else if (weap-&gt;spfx &amp; SPFX_ATTK) {
&nbsp;        struct obj *defending_weapon = (yours ? uwep : MON_WEP(mtmp));
&nbsp;
&nbsp;        if (defending_weapon &amp;&amp; defending_weapon-&gt;oartifact
&nbsp;            &amp;&amp; defends((int) weap-&gt;attk.adtyp, defending_weapon))
&nbsp;            return FALSE;
&nbsp;        switch (weap-&gt;attk.adtyp) {
&nbsp;        case AD_FIRE:
&nbsp;            return !(yours ? Fire_resistance : resists_fire(mtmp));
&nbsp;        case AD_COLD:
&nbsp;            return !(yours ? Cold_resistance : resists_cold(mtmp));
&nbsp;        case AD_ELEC:
&nbsp;            return !(yours ? Shock_resistance : resists_elec(mtmp));
&nbsp;        case AD_MAGM:
&nbsp;        case AD_STUN:
&nbsp;            return !(yours ? Antimagic : (rn2(100) &lt; ptr-&gt;mr));
&nbsp;        case AD_DRST:
&nbsp;            return !(yours ? Poison_resistance : resists_poison(mtmp));
&nbsp;        case AD_DRLI:
&nbsp;            return !(yours ? Drain_resistance : resists_drli(mtmp));
&nbsp;        case AD_STON:
&nbsp;            return !(yours ? Stone_resistance : resists_ston(mtmp));
&nbsp;        default:
&nbsp;            impossible("Weird weapon special attack.");
&nbsp;        }
&nbsp;    }
&nbsp;    return 0;
&nbsp;}
&nbsp;
spec_m2
&nbsp;/* return the M2 flags of monster that an artifact's special attacks apply
&nbsp; * against */
&nbsp;long
&nbsp;spec_m2(otmp)
&nbsp;struct obj *otmp;
&nbsp;{
&nbsp;    const struct artifact *artifact = get_artifact(otmp);
&nbsp;
&nbsp;    if (artifact)
&nbsp;        return artifact-&gt;mtype;
&nbsp;    return 0L;
&nbsp;}
&nbsp;
spec_abon
&nbsp;/* special attack bonus */
&nbsp;int
&nbsp;spec_abon(otmp, mon)
&nbsp;struct obj *otmp;
&nbsp;struct monst *mon;
&nbsp;{
&nbsp;    const struct artifact *weap = get_artifact(otmp);
&nbsp;
&nbsp;    /* no need for an extra check for `NO_ATTK' because this will
&nbsp;       always return 0 for any artifact which has that attribute */
&nbsp;
&nbsp;    if (weap &amp;&amp; weap-&gt;attk.damn &amp;&amp; spec_applies(weap, mon))
&nbsp;        return rnd((int) weap-&gt;attk.damn);
&nbsp;    return 0;
&nbsp;}
&nbsp;
spec_dbon
&nbsp;/* special damage bonus */
&nbsp;int
&nbsp;spec_dbon(otmp, mon, tmp)
&nbsp;struct obj *otmp;
&nbsp;struct monst *mon;
&nbsp;int tmp;
&nbsp;{
&nbsp;    register const struct artifact *weap = get_artifact(otmp);
&nbsp;
&nbsp;    if (!weap || (weap-&gt;attk.adtyp == AD_PHYS /* check for `NO_ATTK' */
&nbsp;                  &amp;&amp; weap-&gt;attk.damn == 0 &amp;&amp; weap-&gt;attk.damd == 0))
&nbsp;        spec_dbon_applies = FALSE;
&nbsp;    else if (otmp-&gt;oartifact == ART_GRIMTOOTH)
&nbsp;        /* Grimtooth has SPFX settings to warn against elves but we want its
&nbsp;           damage bonus to apply to all targets, so bypass spec_applies() */
&nbsp;        spec_dbon_applies = TRUE;
&nbsp;    else
&nbsp;        spec_dbon_applies = spec_applies(weap, mon);
&nbsp;
&nbsp;    if (spec_dbon_applies)
&nbsp;        return weap-&gt;attk.damd ? rnd((int) weap-&gt;attk.damd) : max(tmp, 1);
&nbsp;    return 0;
&nbsp;}
&nbsp;
discover_artifact
&nbsp;/* add identified artifact to discoveries list */
&nbsp;void
&nbsp;discover_artifact(m)
&nbsp;xchar m;
&nbsp;{
&nbsp;    int i;
&nbsp;
&nbsp;    /* look for this artifact in the discoveries list;
&nbsp;       if we hit an empty slot then it's not present, so add it */
&nbsp;    for (i = 0; i &lt; NROFARTIFACTS; i++)
&nbsp;        if (artidisco[i] == 0 || artidisco[i] == m) {
&nbsp;            artidisco[i] = m;
&nbsp;            return;
&nbsp;        }
&nbsp;    /* there is one slot per artifact, so we should never reach the
&nbsp;       end without either finding the artifact or an empty slot... */
&nbsp;    impossible("couldn't discover artifact (%d)", (int) m);
&nbsp;}
&nbsp;
undiscovered_artifact
&nbsp;/* used to decide whether an artifact has been fully identified */
&nbsp;boolean
&nbsp;undiscovered_artifact(m)
&nbsp;xchar m;
&nbsp;{
&nbsp;    int i;
&nbsp;
&nbsp;    /* look for this artifact in the discoveries list;
&nbsp;       if we hit an empty slot then it's undiscovered */
&nbsp;    for (i = 0; i &lt; NROFARTIFACTS; i++)
&nbsp;        if (artidisco[i] == m)
&nbsp;            return FALSE;
&nbsp;        else if (artidisco[i] == 0)
&nbsp;            break;
&nbsp;    return TRUE;
&nbsp;}
&nbsp;
disp_artifact_discoveries
&nbsp;/* display a list of discovered artifacts; return their count */
&nbsp;int
&nbsp;disp_artifact_discoveries(tmpwin)
&nbsp;winid tmpwin; /* supplied by dodiscover() */
&nbsp;{
&nbsp;    int i, m, otyp;
&nbsp;    char buf[BUFSZ];
&nbsp;
&nbsp;    for (i = 0; i &lt; NROFARTIFACTS; i++) {
&nbsp;        if (artidisco[i] == 0)
&nbsp;            break; /* empty slot implies end of list */
&nbsp;        if (tmpwin == WIN_ERR)
&nbsp;            continue; /* for WIN_ERR, we just count */
&nbsp;
&nbsp;        if (i == 0)
&nbsp;            putstr(tmpwin, iflags.menu_headings, "Artifacts");
&nbsp;        m = artidisco[i];
&nbsp;        otyp = artilist[m].otyp;
&nbsp;        Sprintf(buf, "  %s [%s %s]", artiname(m),
&nbsp;                align_str(artilist[m].alignment), simple_typename(otyp));
&nbsp;        putstr(tmpwin, 0, buf);
&nbsp;    }
&nbsp;    return i;
&nbsp;}
&nbsp;
Mb_hit
&nbsp;/*
&nbsp; * Magicbane's intrinsic magic is incompatible with normal
&nbsp; * enchantment magic.  Thus, its effects have a negative
&nbsp; * dependence on spe.  Against low mr victims, it typically
&nbsp; * does "double athame" damage, 2d4.  Occasionally, it will
&nbsp; * cast unbalancing magic which effectively averages out to
&nbsp; * 4d4 damage (3d4 against high mr victims), for spe = 0.
&nbsp; *
&nbsp; * Prior to 3.4.1, the cancel (aka purge) effect always
&nbsp; * included the scare effect too; now it's one or the other.
&nbsp; * Likewise, the stun effect won't be combined with either
&nbsp; * of those two; it will be chosen separately or possibly
&nbsp; * used as a fallback when scare or cancel fails.
&nbsp; *
&nbsp; * [Historical note: a change to artifact_hit() for 3.4.0
&nbsp; * unintentionally made all of Magicbane's special effects
&nbsp; * be blocked if the defender successfully saved against a
&nbsp; * stun attack.  As of 3.4.1, those effects can occur but
&nbsp; * will be slightly less likely than they were in 3.3.x.]
&nbsp; */
&nbsp;
&nbsp;enum mb_effect_indices {
&nbsp;    MB_INDEX_PROBE = 0,
&nbsp;    MB_INDEX_STUN,
&nbsp;    MB_INDEX_SCARE,
&nbsp;    MB_INDEX_CANCEL,
&nbsp;
&nbsp;    NUM_MB_INDICES
&nbsp;};
&nbsp;
&nbsp;#define MB_MAX_DIEROLL 8 /* rolls above this aren't magical */
&nbsp;static const char *const mb_verb[2][NUM_MB_INDICES] = {
&nbsp;    { "probe", "stun", "scare", "cancel" },
&nbsp;    { "prod", "amaze", "tickle", "purge" },
&nbsp;};
&nbsp;
&nbsp;/* called when someone is being hit by Magicbane */
&nbsp;STATIC_OVL boolean
&nbsp;Mb_hit(magr, mdef, mb, dmgptr, dieroll, vis, hittee)
&nbsp;struct monst *magr, *mdef; /* attacker and defender */
&nbsp;struct obj *mb;            /* Magicbane */
&nbsp;int *dmgptr;               /* extra damage target will suffer */
&nbsp;int dieroll;               /* d20 that has already scored a hit */
&nbsp;boolean vis;               /* whether the action can be seen */
&nbsp;char *hittee;              /* target's name: "you" or mon_nam(mdef) */
&nbsp;{
&nbsp;    struct permonst *old_uasmon;
&nbsp;    const char *verb, *fakename;
&nbsp;    boolean youattack = (magr == &amp;youmonst), youdefend = (mdef == &amp;youmonst),
&nbsp;            resisted = FALSE, do_stun, do_confuse, result;
&nbsp;    int attack_indx, scare_dieroll = MB_MAX_DIEROLL / 2;
&nbsp;
&nbsp;    result = FALSE; /* no message given yet */
&nbsp;    /* the most severe effects are less likely at higher enchantment */
&nbsp;    if (mb-&gt;spe &gt;= 3)
&nbsp;        scare_dieroll /= (1 &lt;&lt; (mb-&gt;spe / 3));
&nbsp;    /* if target successfully resisted the artifact damage bonus,
&nbsp;       reduce overall likelihood of the assorted special effects */
&nbsp;    if (!spec_dbon_applies)
&nbsp;        dieroll += 1;
&nbsp;
&nbsp;    /* might stun even when attempting a more severe effect, but
&nbsp;       in that case it will only happen if the other effect fails;
&nbsp;       extra damage will apply regardless; 3.4.1: sometimes might
&nbsp;       just probe even when it hasn't been enchanted */
&nbsp;    do_stun = (max(mb-&gt;spe, 0) &lt; rn2(spec_dbon_applies ? 11 : 7));
&nbsp;
&nbsp;    /* the special effects also boost physical damage; increments are
&nbsp;       generally cumulative, but since the stun effect is based on a
&nbsp;       different criterium its damage might not be included; the base
&nbsp;       damage is either 1d4 (athame) or 2d4 (athame+spec_dbon) depending
&nbsp;       on target's resistance check against AD_STUN (handled by caller)
&nbsp;       [note that a successful save against AD_STUN doesn't actually
&nbsp;       prevent the target from ending up stunned] */
&nbsp;    attack_indx = MB_INDEX_PROBE;
&nbsp;    *dmgptr += rnd(4); /* (2..3)d4 */
&nbsp;    if (do_stun) {
&nbsp;        attack_indx = MB_INDEX_STUN;
&nbsp;        *dmgptr += rnd(4); /* (3..4)d4 */
&nbsp;    }
&nbsp;    if (dieroll &lt;= scare_dieroll) {
&nbsp;        attack_indx = MB_INDEX_SCARE;
&nbsp;        *dmgptr += rnd(4); /* (3..5)d4 */
&nbsp;    }
&nbsp;    if (dieroll &lt;= (scare_dieroll / 2)) {
&nbsp;        attack_indx = MB_INDEX_CANCEL;
&nbsp;        *dmgptr += rnd(4); /* (4..6)d4 */
&nbsp;    }
&nbsp;
&nbsp;    /* give the hit message prior to inflicting the effects */
&nbsp;    verb = mb_verb[!!Hallucination][attack_indx];
&nbsp;    if (youattack || youdefend || vis) {
&nbsp;        result = TRUE;
&nbsp;        pline_The("magic-absorbing blade %s %s!",
&nbsp;                  vtense((const char *) 0, verb), hittee);
&nbsp;        /* assume probing has some sort of noticeable feedback
&nbsp;           even if it is being done by one monster to another */
&nbsp;        if (attack_indx == MB_INDEX_PROBE &amp;&amp; !canspotmon(mdef))
&nbsp;            map_invisible(mdef-&gt;mx, mdef-&gt;my);
&nbsp;    }
&nbsp;
&nbsp;    /* now perform special effects */
&nbsp;    switch (attack_indx) {
&nbsp;    case MB_INDEX_CANCEL:
&nbsp;        old_uasmon = youmonst.data;
&nbsp;        /* No mdef-&gt;mcan check: even a cancelled monster can be polymorphed
&nbsp;         * into a golem, and the "cancel" effect acts as if some magical
&nbsp;         * energy remains in spellcasting defenders to be absorbed later.
&nbsp;         */
&nbsp;        if (!cancel_monst(mdef, mb, youattack, FALSE, FALSE)) {
&nbsp;            resisted = TRUE;
&nbsp;        } else {
&nbsp;            do_stun = FALSE;
&nbsp;            if (youdefend) {
&nbsp;                if (youmonst.data != old_uasmon)
&nbsp;                    *dmgptr = 0; /* rehumanized, so no more damage */
&nbsp;                if (u.uenmax &gt; 0) {
&nbsp;                    You("lose magical energy!");
&nbsp;                    u.uenmax--;
&nbsp;                    if (u.uen &gt; 0)
&nbsp;                        u.uen--;
&nbsp;                    context.botl = 1;
&nbsp;                }
&nbsp;            } else {
&nbsp;                if (mdef-&gt;data == &amp;mons[PM_CLAY_GOLEM])
&nbsp;                    mdef-&gt;mhp = 1; /* cancelled clay golems will die */
&nbsp;                if (youattack &amp;&amp; attacktype(mdef-&gt;data, AT_MAGC)) {
&nbsp;                    You("absorb magical energy!");
&nbsp;                    u.uenmax++;
&nbsp;                    u.uen++;
&nbsp;                    context.botl = 1;
&nbsp;                }
&nbsp;            }
&nbsp;        }
&nbsp;        break;
&nbsp;
&nbsp;    case MB_INDEX_SCARE:
&nbsp;        if (youdefend) {
&nbsp;            if (Antimagic) {
&nbsp;                resisted = TRUE;
&nbsp;            } else {
&nbsp;                nomul(-3);
&nbsp;                multi_reason = "being scared stiff";
&nbsp;                nomovemsg = "";
&nbsp;                if (magr &amp;&amp; magr == u.ustuck &amp;&amp; sticks(youmonst.data)) {
&nbsp;                    u.ustuck = (struct monst *) 0;
&nbsp;                    You("release %s!", mon_nam(magr));
&nbsp;                }
&nbsp;            }
&nbsp;        } else {
&nbsp;            if (rn2(2) &amp;&amp; resist(mdef, WEAPON_CLASS, 0, NOTELL))
&nbsp;                resisted = TRUE;
&nbsp;            else
&nbsp;                monflee(mdef, 3, FALSE, (mdef-&gt;mhp &gt; *dmgptr));
&nbsp;        }
&nbsp;        if (!resisted)
&nbsp;            do_stun = FALSE;
&nbsp;        break;
&nbsp;
&nbsp;    case MB_INDEX_STUN:
&nbsp;        do_stun = TRUE; /* (this is redundant...) */
&nbsp;        break;
&nbsp;
&nbsp;    case MB_INDEX_PROBE:
&nbsp;        if (youattack &amp;&amp; (mb-&gt;spe == 0 || !rn2(3 * abs(mb-&gt;spe)))) {
&nbsp;            pline_The("%s is insightful.", verb);
&nbsp;            /* pre-damage status */
&nbsp;            probe_monster(mdef);
&nbsp;        }
&nbsp;        break;
&nbsp;    }
&nbsp;    /* stun if that was selected and a worse effect didn't occur */
&nbsp;    if (do_stun) {
&nbsp;        if (youdefend)
&nbsp;            make_stunned(((HStun &amp; TIMEOUT) + 3L), FALSE);
&nbsp;        else
&nbsp;            mdef-&gt;mstun = 1;
&nbsp;        /* avoid extra stun message below if we used mb_verb["stun"] above */
&nbsp;        if (attack_indx == MB_INDEX_STUN)
&nbsp;            do_stun = FALSE;
&nbsp;    }
&nbsp;    /* lastly, all this magic can be confusing... */
&nbsp;    do_confuse = !rn2(12);
&nbsp;    if (do_confuse) {
&nbsp;        if (youdefend)
&nbsp;            make_confused((HConfusion &amp; TIMEOUT) + 4L, FALSE);
&nbsp;        else
&nbsp;            mdef-&gt;mconf = 1;
&nbsp;    }
&nbsp;
&nbsp;    /* now give message(s) describing side-effects;
&nbsp;       don't let vtense() be fooled by assigned name ending in 's' */
&nbsp;    fakename = youdefend ? "you" : "mon";
&nbsp;    if (youattack || youdefend || vis) {
&nbsp;        (void) upstart(hittee); /* capitalize */
&nbsp;        if (resisted) {
&nbsp;            pline("%s %s!", hittee, vtense(fakename, "resist"));
&nbsp;            shieldeff(youdefend ? u.ux : mdef-&gt;mx,
&nbsp;                      youdefend ? u.uy : mdef-&gt;my);
&nbsp;        }
&nbsp;        if ((do_stun || do_confuse) &amp;&amp; flags.verbose) {
&nbsp;            char buf[BUFSZ];
&nbsp;
&nbsp;            buf[0] = '\0';
&nbsp;            if (do_stun)
&nbsp;                Strcat(buf, "stunned");
&nbsp;            if (do_stun &amp;&amp; do_confuse)
&nbsp;                Strcat(buf, " and ");
&nbsp;            if (do_confuse)
&nbsp;                Strcat(buf, "confused");
&nbsp;            pline("%s %s %s%c", hittee, vtense(fakename, "are"), buf,
&nbsp;                  (do_stun &amp;&amp; do_confuse) ? '!' : '.');
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    return result;
&nbsp;}
&nbsp;
artifact_hit
&nbsp;/* Function used when someone attacks someone else with an artifact
&nbsp; * weapon.  Only adds the special (artifact) damage, and returns a 1 if it
&nbsp; * did something special (in which case the caller won't print the normal
&nbsp; * hit message).  This should be called once upon every artifact attack;
&nbsp; * dmgval() no longer takes artifact bonuses into account.  Possible
&nbsp; * extension: change the killer so that when an orc kills you with
&nbsp; * Stormbringer it's "killed by Stormbringer" instead of "killed by an orc".
&nbsp; */
&nbsp;boolean
&nbsp;artifact_hit(magr, mdef, otmp, dmgptr, dieroll)
&nbsp;struct monst *magr, *mdef;
&nbsp;struct obj *otmp;
&nbsp;int *dmgptr;
&nbsp;int dieroll; /* needed for Magicbane and vorpal blades */
&nbsp;{
&nbsp;    boolean youattack = (magr == &amp;youmonst);
&nbsp;    boolean youdefend = (mdef == &amp;youmonst);
&nbsp;    boolean vis = (!youattack &amp;&amp; magr &amp;&amp; cansee(magr-&gt;mx, magr-&gt;my))
&nbsp;                  || (!youdefend &amp;&amp; cansee(mdef-&gt;mx, mdef-&gt;my))
&nbsp;                  || (youattack &amp;&amp; u.uswallow &amp;&amp; mdef == u.ustuck &amp;&amp; !Blind);
&nbsp;    boolean realizes_damage;
&nbsp;    const char *wepdesc;
&nbsp;    static const char you[] = "you";
&nbsp;    char hittee[BUFSZ];
&nbsp;
&nbsp;    Strcpy(hittee, youdefend ? you : mon_nam(mdef));
&nbsp;
&nbsp;    /* The following takes care of most of the damage, but not all--
&nbsp;     * the exception being for level draining, which is specially
&nbsp;     * handled.  Messages are done in this function, however.
&nbsp;     */
&nbsp;    *dmgptr += spec_dbon(otmp, mdef, *dmgptr);
&nbsp;
&nbsp;    if (youattack &amp;&amp; youdefend) {
&nbsp;        impossible("attacking yourself with weapon?");
&nbsp;        return FALSE;
&nbsp;    }
&nbsp;
&nbsp;    realizes_damage = (youdefend || vis
&nbsp;                       /* feel the effect even if not seen */
&nbsp;                       || (youattack &amp;&amp; mdef == u.ustuck));
&nbsp;
&nbsp;    /* the four basic attacks: fire, cold, shock and missiles */
&nbsp;    if (attacks(AD_FIRE, otmp)) {
&nbsp;        if (realizes_damage)
&nbsp;            pline_The("fiery blade %s %s%c",
&nbsp;                      !spec_dbon_applies
&nbsp;                          ? "hits"
&nbsp;                          : (mdef-&gt;data == &amp;mons[PM_WATER_ELEMENTAL])
&nbsp;                                ? "vaporizes part of"
&nbsp;                                : "burns",
&nbsp;                      hittee, !spec_dbon_applies ? '.' : '!');
&nbsp;        if (!rn2(4))
&nbsp;            (void) destroy_mitem(mdef, POTION_CLASS, AD_FIRE);
&nbsp;        if (!rn2(4))
&nbsp;            (void) destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE);
&nbsp;        if (!rn2(7))
&nbsp;            (void) destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE);
&nbsp;        if (youdefend &amp;&amp; Slimed)
&nbsp;            burn_away_slime();
&nbsp;        return realizes_damage;
&nbsp;    }
&nbsp;    if (attacks(AD_COLD, otmp)) {
&nbsp;        if (realizes_damage)
&nbsp;            pline_The("ice-cold blade %s %s%c",
&nbsp;                      !spec_dbon_applies ? "hits" : "freezes", hittee,
&nbsp;                      !spec_dbon_applies ? '.' : '!');
&nbsp;        if (!rn2(4))
&nbsp;            (void) destroy_mitem(mdef, POTION_CLASS, AD_COLD);
&nbsp;        return realizes_damage;
&nbsp;    }
&nbsp;    if (attacks(AD_ELEC, otmp)) {
&nbsp;        if (realizes_damage)
&nbsp;            pline_The("massive hammer hits%s %s%c",
&nbsp;                      !spec_dbon_applies ? "" : "!  Lightning strikes",
&nbsp;                      hittee, !spec_dbon_applies ? '.' : '!');
&nbsp;        if (!rn2(5))
&nbsp;            (void) destroy_mitem(mdef, RING_CLASS, AD_ELEC);
&nbsp;        if (!rn2(5))
&nbsp;            (void) destroy_mitem(mdef, WAND_CLASS, AD_ELEC);
&nbsp;        return realizes_damage;
&nbsp;    }
&nbsp;    if (attacks(AD_MAGM, otmp)) {
&nbsp;        if (realizes_damage)
&nbsp;            pline_The("imaginary widget hits%s %s%c",
&nbsp;                      !spec_dbon_applies
&nbsp;                          ? ""
&nbsp;                          : "!  A hail of magic missiles strikes",
&nbsp;                      hittee, !spec_dbon_applies ? '.' : '!');
&nbsp;        return realizes_damage;
&nbsp;    }
&nbsp;
&nbsp;    if (attacks(AD_STUN, otmp) &amp;&amp; dieroll &lt;= MB_MAX_DIEROLL) {
&nbsp;        /* Magicbane's special attacks (possibly modifies hittee[]) */
&nbsp;        return Mb_hit(magr, mdef, otmp, dmgptr, dieroll, vis, hittee);
&nbsp;    }
&nbsp;
&nbsp;    if (!spec_dbon_applies) {
&nbsp;        /* since damage bonus didn't apply, nothing more to do;
&nbsp;           no further attacks have side-effects on inventory */
&nbsp;        return FALSE;
&nbsp;    }
&nbsp;
&nbsp;    /* We really want "on a natural 20" but Nethack does it in */
&nbsp;    /* reverse from AD&amp;D. */
&nbsp;    if (spec_ability(otmp, SPFX_BEHEAD)) {
&nbsp;        if (otmp-&gt;oartifact == ART_TSURUGI_OF_MURAMASA &amp;&amp; dieroll == 1) {
&nbsp;            wepdesc = "The razor-sharp blade";
&nbsp;            /* not really beheading, but so close, why add another SPFX */
&nbsp;            if (youattack &amp;&amp; u.uswallow &amp;&amp; mdef == u.ustuck) {
&nbsp;                You("slice %s wide open!", mon_nam(mdef));
&nbsp;                *dmgptr = 2 * mdef-&gt;mhp + FATAL_DAMAGE_MODIFIER;
&nbsp;                return TRUE;
&nbsp;            }
&nbsp;            if (!youdefend) {
&nbsp;                /* allow normal cutworm() call to add extra damage */
&nbsp;                if (notonhead)
&nbsp;                    return FALSE;
&nbsp;
&nbsp;                if (bigmonst(mdef-&gt;data)) {
&nbsp;                    if (youattack)
&nbsp;                        You("slice deeply into %s!", mon_nam(mdef));
&nbsp;                    else if (vis)
&nbsp;                        pline("%s cuts deeply into %s!", Monnam(magr),
&nbsp;                              hittee);
&nbsp;                    *dmgptr *= 2;
&nbsp;                    return TRUE;
&nbsp;                }
&nbsp;                *dmgptr = 2 * mdef-&gt;mhp + FATAL_DAMAGE_MODIFIER;
&nbsp;                pline("%s cuts %s in half!", wepdesc, mon_nam(mdef));
&nbsp;                otmp-&gt;dknown = TRUE;
&nbsp;                return TRUE;
&nbsp;            } else {
&nbsp;                if (bigmonst(youmonst.data)) {
&nbsp;                    pline("%s cuts deeply into you!",
&nbsp;                          magr ? Monnam(magr) : wepdesc);
&nbsp;                    *dmgptr *= 2;
&nbsp;                    return TRUE;
&nbsp;                }
&nbsp;
&nbsp;                /* Players with negative AC's take less damage instead
&nbsp;                 * of just not getting hit.  We must add a large enough
&nbsp;                 * value to the damage so that this reduction in
&nbsp;                 * damage does not prevent death.
&nbsp;                 */
&nbsp;                *dmgptr = 2 * (Upolyd ? u.mh : u.uhp) + FATAL_DAMAGE_MODIFIER;
&nbsp;                pline("%s cuts you in half!", wepdesc);
&nbsp;                otmp-&gt;dknown = TRUE;
&nbsp;                return TRUE;
&nbsp;            }
&nbsp;        } else if (otmp-&gt;oartifact == ART_VORPAL_BLADE
&nbsp;                   &amp;&amp; (dieroll == 1 || mdef-&gt;data == &amp;mons[PM_JABBERWOCK])) {
&nbsp;            static const char *const behead_msg[2] = { "%s beheads %s!",
&nbsp;                                                       "%s decapitates %s!" };
&nbsp;
&nbsp;            if (youattack &amp;&amp; u.uswallow &amp;&amp; mdef == u.ustuck)
&nbsp;                return FALSE;
&nbsp;            wepdesc = artilist[ART_VORPAL_BLADE].name;
&nbsp;            if (!youdefend) {
&nbsp;                if (!has_head(mdef-&gt;data) || notonhead || u.uswallow) {
&nbsp;                    if (youattack)
&nbsp;                        pline("Somehow, you miss %s wildly.", mon_nam(mdef));
&nbsp;                    else if (vis)
&nbsp;                        pline("Somehow, %s misses wildly.", mon_nam(magr));
&nbsp;                    *dmgptr = 0;
&nbsp;                    return (boolean) (youattack || vis);
&nbsp;                }
&nbsp;                if (noncorporeal(mdef-&gt;data) || amorphous(mdef-&gt;data)) {
&nbsp;                    pline("%s slices through %s %s.", wepdesc,
&nbsp;                          s_suffix(mon_nam(mdef)), mbodypart(mdef, NECK));
&nbsp;                    return TRUE;
&nbsp;                }
&nbsp;                *dmgptr = 2 * mdef-&gt;mhp + FATAL_DAMAGE_MODIFIER;
&nbsp;                pline(behead_msg[rn2(SIZE(behead_msg))], wepdesc,
&nbsp;                      mon_nam(mdef));
&nbsp;                if (Hallucination &amp;&amp; !flags.female)
&nbsp;                    pline("Good job Henry, but that wasn't Anne.");
&nbsp;                otmp-&gt;dknown = TRUE;
&nbsp;                return TRUE;
&nbsp;            } else {
&nbsp;                if (!has_head(youmonst.data)) {
&nbsp;                    pline("Somehow, %s misses you wildly.",
&nbsp;                          magr ? mon_nam(magr) : wepdesc);
&nbsp;                    *dmgptr = 0;
&nbsp;                    return TRUE;
&nbsp;                }
&nbsp;                if (noncorporeal(youmonst.data) || amorphous(youmonst.data)) {
&nbsp;                    pline("%s slices through your %s.", wepdesc,
&nbsp;                          body_part(NECK));
&nbsp;                    return TRUE;
&nbsp;                }
&nbsp;                *dmgptr = 2 * (Upolyd ? u.mh : u.uhp) + FATAL_DAMAGE_MODIFIER;
&nbsp;                pline(behead_msg[rn2(SIZE(behead_msg))], wepdesc, "you");
&nbsp;                otmp-&gt;dknown = TRUE;
&nbsp;                /* Should amulets fall off? */
&nbsp;                return TRUE;
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;    if (spec_ability(otmp, SPFX_DRLI)) {
&nbsp;        /* some non-living creatures (golems, vortices) are
&nbsp;           vulnerable to life drain effects */
&nbsp;        const char *life = nonliving(mdef-&gt;data) ? "animating force" : "life";
&nbsp;
&nbsp;        if (!youdefend) {
&nbsp;            if (vis) {
&nbsp;                if (otmp-&gt;oartifact == ART_STORMBRINGER)
&nbsp;                    pline_The("%s blade draws the %s from %s!",
&nbsp;                              hcolor(NH_BLACK), life, mon_nam(mdef));
&nbsp;                else
&nbsp;                    pline("%s draws the %s from %s!",
&nbsp;                          The(distant_name(otmp, xname)), life,
&nbsp;                          mon_nam(mdef));
&nbsp;            }
&nbsp;            if (mdef-&gt;m_lev == 0) {
&nbsp;                *dmgptr = 2 * mdef-&gt;mhp + FATAL_DAMAGE_MODIFIER;
&nbsp;            } else {
&nbsp;                int drain = monhp_per_lvl(mdef);
&nbsp;
&nbsp;                *dmgptr += drain;
&nbsp;                mdef-&gt;mhpmax -= drain;
&nbsp;                mdef-&gt;m_lev--;
&nbsp;                drain /= 2;
&nbsp;                if (drain)
&nbsp;                    healup(drain, 0, FALSE, FALSE);
&nbsp;            }
&nbsp;            return vis;
&nbsp;        } else { /* youdefend */
&nbsp;            int oldhpmax = u.uhpmax;
&nbsp;
&nbsp;            if (Blind)
&nbsp;                You_feel("an %s drain your %s!",
&nbsp;                         (otmp-&gt;oartifact == ART_STORMBRINGER)
&nbsp;                            ? "unholy blade"
&nbsp;                            : "object",
&nbsp;                         life);
&nbsp;            else if (otmp-&gt;oartifact == ART_STORMBRINGER)
&nbsp;                pline_The("%s blade drains your %s!", hcolor(NH_BLACK), life);
&nbsp;            else
&nbsp;                pline("%s drains your %s!", The(distant_name(otmp, xname)),
&nbsp;                      life);
&nbsp;            losexp("life drainage");
&nbsp;            if (magr &amp;&amp; magr-&gt;mhp &lt; magr-&gt;mhpmax) {
&nbsp;                magr-&gt;mhp += (oldhpmax - u.uhpmax) / 2;
&nbsp;                if (magr-&gt;mhp &gt; magr-&gt;mhpmax)
&nbsp;                    magr-&gt;mhp = magr-&gt;mhpmax;
&nbsp;            }
&nbsp;            return TRUE;
&nbsp;        }
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
&nbsp;static NEARDATA const char recharge_type[] = { ALLOW_COUNT, ALL_CLASSES, 0 };
&nbsp;static NEARDATA const char invoke_types[] = { ALL_CLASSES, 0 };
&nbsp;/* #invoke: an "ugly check" filters out most objects */
&nbsp;
doinvoke
&nbsp;/* the #invoke command */
&nbsp;int
&nbsp;doinvoke()
&nbsp;{
&nbsp;    struct obj *obj;
&nbsp;
&nbsp;    obj = getobj(invoke_types, "invoke");
&nbsp;    if (!obj)
&nbsp;        return 0;
&nbsp;    if (!retouch_object(&amp;obj, FALSE))
&nbsp;        return 1;
&nbsp;    return arti_invoke(obj);
&nbsp;}
&nbsp;
arti_invoke
&nbsp;STATIC_OVL int
&nbsp;arti_invoke(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    register const struct artifact *oart = get_artifact(obj);
&nbsp;    if (!obj) {
&nbsp;        impossible("arti_invoke without obj");
&nbsp;        return 0;
&nbsp;    }
&nbsp;    if (!oart || !oart-&gt;inv_prop) {
&nbsp;        if (obj-&gt;otyp == CRYSTAL_BALL)
&nbsp;            use_crystal_ball(&amp;obj);
&nbsp;        else
&nbsp;            pline1(nothing_happens);
&nbsp;        return 1;
&nbsp;    }
&nbsp;
&nbsp;    if (oart-&gt;inv_prop &gt; LAST_PROP) {
&nbsp;        /* It's a special power, not "just" a property */
&nbsp;        if (obj-&gt;age &gt; monstermoves) {
&nbsp;            /* the artifact is tired :-) */
&nbsp;            You_feel("that %s %s ignoring you.", the(xname(obj)),
&nbsp;                     otense(obj, "are"));
&nbsp;            /* and just got more so; patience is essential... */
&nbsp;            obj-&gt;age += (long) d(3, 10);
&nbsp;            return 1;
&nbsp;        }
&nbsp;        obj-&gt;age = monstermoves + rnz(100);
&nbsp;
&nbsp;        switch (oart-&gt;inv_prop) {
&nbsp;        case TAMING: {
&nbsp;            struct obj pseudo;
&nbsp;
&nbsp;            pseudo =
&nbsp;                zeroobj; /* neither cursed nor blessed, zero oextra too */
&nbsp;            pseudo.otyp = SCR_TAMING;
&nbsp;            (void) seffects(&amp;pseudo);
&nbsp;            break;
&nbsp;        }
&nbsp;        case HEALING: {
&nbsp;            int healamt = (u.uhpmax + 1 - u.uhp) / 2;
&nbsp;            long creamed = (long) u.ucreamed;
&nbsp;
&nbsp;            if (Upolyd)
&nbsp;                healamt = (u.mhmax + 1 - u.mh) / 2;
&nbsp;            if (healamt || Sick || Slimed || Blinded &gt; creamed)
&nbsp;                You_feel("better.");
&nbsp;            else
&nbsp;                goto nothing_special;
&nbsp;            if (healamt &gt; 0) {
&nbsp;                if (Upolyd)
&nbsp;                    u.mh += healamt;
&nbsp;                else
&nbsp;                    u.uhp += healamt;
&nbsp;            }
&nbsp;            if (Sick)
&nbsp;                make_sick(0L, (char *) 0, FALSE, SICK_ALL);
&nbsp;            if (Slimed)
&nbsp;                make_slimed(0L, (char *) 0);
&nbsp;            if (Blinded &gt; creamed)
&nbsp;                make_blinded(creamed, FALSE);
&nbsp;            context.botl = 1;
&nbsp;            break;
&nbsp;        }
&nbsp;        case ENERGY_BOOST: {
&nbsp;            int epboost = (u.uenmax + 1 - u.uen) / 2;
&nbsp;            if (epboost &gt; 120)
&nbsp;                epboost = 120; /* arbitrary */
&nbsp;            else if (epboost &lt; 12)
&nbsp;                epboost = u.uenmax - u.uen;
&nbsp;            if (epboost) {
&nbsp;                You_feel("re-energized.");
&nbsp;                u.uen += epboost;
&nbsp;                context.botl = 1;
&nbsp;            } else
&nbsp;                goto nothing_special;
&nbsp;            break;
&nbsp;        }
&nbsp;        case UNTRAP: {
&nbsp;            if (!untrap(TRUE)) {
&nbsp;                obj-&gt;age = 0; /* don't charge for changing their mind */
&nbsp;                return 0;
&nbsp;            }
&nbsp;            break;
&nbsp;        }
&nbsp;        case CHARGE_OBJ: {
&nbsp;            struct obj *otmp = getobj(recharge_type, "charge");
&nbsp;            boolean b_effect;
&nbsp;
&nbsp;            if (!otmp) {
&nbsp;                obj-&gt;age = 0;
&nbsp;                return 0;
&nbsp;            }
&nbsp;            b_effect = (obj-&gt;blessed &amp;&amp; (oart-&gt;role == Role_switch
&nbsp;                                         || oart-&gt;role == NON_PM));
&nbsp;            recharge(otmp, b_effect ? 1 : obj-&gt;cursed ? -1 : 0);
&nbsp;            update_inventory();
&nbsp;            break;
&nbsp;        }
&nbsp;        case LEV_TELE:
&nbsp;            level_tele();
&nbsp;            break;
&nbsp;        case CREATE_PORTAL: {
&nbsp;            int i, num_ok_dungeons, last_ok_dungeon = 0;
&nbsp;            d_level newlev;
&nbsp;            extern int n_dgns; /* from dungeon.c */
&nbsp;            winid tmpwin = create_nhwindow(NHW_MENU);
&nbsp;            anything any;
&nbsp;
&nbsp;            any = zeroany; /* set all bits to zero */
&nbsp;            start_menu(tmpwin);
&nbsp;            /* use index+1 (cant use 0) as identifier */
&nbsp;            for (i = num_ok_dungeons = 0; i &lt; n_dgns; i++) {
&nbsp;                if (!dungeons[i].dunlev_ureached)
&nbsp;                    continue;
&nbsp;                any.a_int = i + 1;
&nbsp;                add_menu(tmpwin, NO_GLYPH, &amp;any, 0, 0, ATR_NONE,
&nbsp;                         dungeons[i].dname, MENU_UNSELECTED);
&nbsp;                num_ok_dungeons++;
&nbsp;                last_ok_dungeon = i;
&nbsp;            }
&nbsp;            end_menu(tmpwin, "Open a portal to which dungeon?");
&nbsp;            if (num_ok_dungeons &gt; 1) {
&nbsp;                /* more than one entry; display menu for choices */
&nbsp;                menu_item *selected;
&nbsp;                int n;
&nbsp;
&nbsp;                n = select_menu(tmpwin, PICK_ONE, &amp;selected);
&nbsp;                if (n &lt;= 0) {
&nbsp;                    destroy_nhwindow(tmpwin);
&nbsp;                    goto nothing_special;
&nbsp;                }
&nbsp;                i = selected[0].item.a_int - 1;
&nbsp;                free((genericptr_t) selected);
&nbsp;            } else
&nbsp;                i = last_ok_dungeon; /* also first &amp; only OK dungeon */
&nbsp;            destroy_nhwindow(tmpwin);
&nbsp;
&nbsp;            /*
&nbsp;             * i is now index into dungeon structure for the new dungeon.
&nbsp;             * Find the closest level in the given dungeon, open
&nbsp;             * a use-once portal to that dungeon and go there.
&nbsp;             * The closest level is either the entry or dunlev_ureached.
&nbsp;             */
&nbsp;            newlev.dnum = i;
&nbsp;            if (dungeons[i].depth_start &gt;= depth(&amp;u.uz))
&nbsp;                newlev.dlevel = dungeons[i].entry_lev;
&nbsp;            else
&nbsp;                newlev.dlevel = dungeons[i].dunlev_ureached;
&nbsp;
&nbsp;            if (u.uhave.amulet || In_endgame(&amp;u.uz) || In_endgame(&amp;newlev)
&nbsp;                || newlev.dnum == u.uz.dnum || !next_to_u()) {
&nbsp;                You_feel("very disoriented for a moment.");
&nbsp;            } else {
&nbsp;                if (!Blind)
&nbsp;                    You("are surrounded by a shimmering sphere!");
&nbsp;                else
&nbsp;                    You_feel("weightless for a moment.");
&nbsp;                goto_level(&amp;newlev, FALSE, FALSE, FALSE);
&nbsp;            }
&nbsp;            break;
&nbsp;        }
&nbsp;        case ENLIGHTENING:
&nbsp;            enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS);
&nbsp;            break;
&nbsp;        case CREATE_AMMO: {
&nbsp;            struct obj *otmp = mksobj(ARROW, TRUE, FALSE);
&nbsp;
&nbsp;            if (!otmp)
&nbsp;                goto nothing_special;
&nbsp;            otmp-&gt;blessed = obj-&gt;blessed;
&nbsp;            otmp-&gt;cursed = obj-&gt;cursed;
&nbsp;            otmp-&gt;bknown = obj-&gt;bknown;
&nbsp;            if (obj-&gt;blessed) {
&nbsp;                if (otmp-&gt;spe &lt; 0)
&nbsp;                    otmp-&gt;spe = 0;
&nbsp;                otmp-&gt;quan += rnd(10);
&nbsp;            } else if (obj-&gt;cursed) {
&nbsp;                if (otmp-&gt;spe &gt; 0)
&nbsp;                    otmp-&gt;spe = 0;
&nbsp;            } else
&nbsp;                otmp-&gt;quan += rnd(5);
&nbsp;            otmp-&gt;owt = weight(otmp);
&nbsp;            otmp = hold_another_object(otmp, "Suddenly %s out.",
&nbsp;                                       aobjnam(otmp, "fall"), (char *) 0);
&nbsp;            break;
&nbsp;        }
&nbsp;        }
&nbsp;    } else {
&nbsp;        long eprop = (u.uprops[oart-&gt;inv_prop].extrinsic ^= W_ARTI),
&nbsp;             iprop = u.uprops[oart-&gt;inv_prop].intrinsic;
&nbsp;        boolean on = (eprop &amp; W_ARTI) != 0; /* true if prop just set */
&nbsp;
&nbsp;        if (on &amp;&amp; obj-&gt;age &gt; monstermoves) {
&nbsp;            /* the artifact is tired :-) */
&nbsp;            u.uprops[oart-&gt;inv_prop].extrinsic ^= W_ARTI;
&nbsp;            You_feel("that %s %s ignoring you.", the(xname(obj)),
&nbsp;                     otense(obj, "are"));
&nbsp;            /* can't just keep repeatedly trying */
&nbsp;            obj-&gt;age += (long) d(3, 10);
&nbsp;            return 1;
&nbsp;        } else if (!on) {
&nbsp;            /* when turning off property, determine downtime */
&nbsp;            /* arbitrary for now until we can tune this -dlc */
&nbsp;            obj-&gt;age = monstermoves + rnz(100);
&nbsp;        }
&nbsp;
&nbsp;        if ((eprop &amp; ~W_ARTI) || iprop) {
&nbsp;        nothing_special:
&nbsp;            /* you had the property from some other source too */
&nbsp;            if (carried(obj))
&nbsp;                You_feel("a surge of power, but nothing seems to happen.");
&nbsp;            return 1;
&nbsp;        }
&nbsp;        switch (oart-&gt;inv_prop) {
&nbsp;        case CONFLICT:
&nbsp;            if (on)
&nbsp;                You_feel("like a rabble-rouser.");
&nbsp;            else
&nbsp;                You_feel("the tension decrease around you.");
&nbsp;            break;
&nbsp;        case LEVITATION:
&nbsp;            if (on) {
&nbsp;                float_up();
&nbsp;                spoteffects(FALSE);
&nbsp;            } else
&nbsp;                (void) float_down(I_SPECIAL | TIMEOUT, W_ARTI);
&nbsp;            break;
&nbsp;        case INVIS:
&nbsp;            if (BInvis || Blind)
&nbsp;                goto nothing_special;
&nbsp;            newsym(u.ux, u.uy);
&nbsp;            if (on)
&nbsp;                Your("body takes on a %s transparency...",
&nbsp;                     Hallucination ? "normal" : "strange");
&nbsp;            else
&nbsp;                Your("body seems to unfade...");
&nbsp;            break;
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    return 1;
&nbsp;}
&nbsp;
finesse_ahriman
&nbsp;/* will freeing this object from inventory cause levitation to end? */
&nbsp;boolean
&nbsp;finesse_ahriman(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    const struct artifact *oart;
&nbsp;    struct prop save_Lev;
&nbsp;    boolean result;
&nbsp;
&nbsp;    /* if we aren't levitating or this isn't an artifact which confers
&nbsp;       levitation via #invoke then freeinv() won't toggle levitation */
&nbsp;    if (!Levitation || (oart = get_artifact(obj)) == 0
&nbsp;        || oart-&gt;inv_prop != LEVITATION || !(ELevitation &amp; W_ARTI))
&nbsp;        return FALSE;
&nbsp;
&nbsp;    /* arti_invoke(off) -&gt; float_down() clears I_SPECIAL|TIMEOUT &amp; W_ARTI;
&nbsp;       probe ahead to see whether that actually results in floating down;
&nbsp;       (this assumes that there aren't two simultaneously invoked artifacts
&nbsp;       both conferring levitation--safe, since if there were two of them,
&nbsp;       invoking the 2nd would negate the 1st rather than stack with it) */
&nbsp;    save_Lev = u.uprops[LEVITATION];
&nbsp;    HLevitation &amp;= ~(I_SPECIAL | TIMEOUT);
&nbsp;    ELevitation &amp;= ~W_ARTI;
&nbsp;    result = (boolean) !Levitation;
&nbsp;    u.uprops[LEVITATION] = save_Lev;
&nbsp;    return result;
&nbsp;}
&nbsp;
artifact_light
&nbsp;/* WAC return TRUE if artifact is always lit */
&nbsp;boolean
&nbsp;artifact_light(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    return (boolean) (get_artifact(obj) &amp;&amp; obj-&gt;oartifact == ART_SUNSWORD);
&nbsp;}
&nbsp;
arti_speak
&nbsp;/* KMH -- Talking artifacts are finally implemented */
&nbsp;void
&nbsp;arti_speak(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    register const struct artifact *oart = get_artifact(obj);
&nbsp;    const char *line;
&nbsp;    char buf[BUFSZ];
&nbsp;
&nbsp;    /* Is this a speaking artifact? */
&nbsp;    if (!oart || !(oart-&gt;spfx &amp; SPFX_SPEAK))
&nbsp;        return;
&nbsp;
&nbsp;    line = getrumor(bcsign(obj), buf, TRUE);
&nbsp;    if (!*line)
&nbsp;        line = "NetHack rumors file closed for renovation.";
&nbsp;    pline("%s:", Tobjnam(obj, "whisper"));
&nbsp;    verbalize1(line);
&nbsp;    return;
&nbsp;}
&nbsp;
artifact_has_invprop
&nbsp;boolean
&nbsp;artifact_has_invprop(otmp, inv_prop)
&nbsp;struct obj *otmp;
&nbsp;uchar inv_prop;
&nbsp;{
&nbsp;    const struct artifact *arti = get_artifact(otmp);
&nbsp;
&nbsp;    return (boolean) (arti &amp;&amp; (arti-&gt;inv_prop == inv_prop));
&nbsp;}
&nbsp;
arti_cost
&nbsp;/* Return the price sold to the hero of a given artifact or unique item */
&nbsp;long
&nbsp;arti_cost(otmp)
&nbsp;struct obj *otmp;
&nbsp;{
&nbsp;    if (!otmp-&gt;oartifact)
&nbsp;        return (long) objects[otmp-&gt;otyp].oc_cost;
&nbsp;    else if (artilist[(int) otmp-&gt;oartifact].cost)
&nbsp;        return artilist[(int) otmp-&gt;oartifact].cost;
&nbsp;    else
&nbsp;        return (100L * (long) objects[otmp-&gt;otyp].oc_cost);
&nbsp;}
&nbsp;
abil_to_adtyp
&nbsp;STATIC_OVL uchar
&nbsp;abil_to_adtyp(abil)
&nbsp;long *abil;
&nbsp;{
&nbsp;    struct abil2adtyp_tag {
&nbsp;        long *abil;
&nbsp;        uchar adtyp;
&nbsp;    } abil2adtyp[] = {
&nbsp;        { &amp;EFire_resistance, AD_FIRE },
&nbsp;        { &amp;ECold_resistance, AD_COLD },
&nbsp;        { &amp;EShock_resistance, AD_ELEC },
&nbsp;        { &amp;EAntimagic, AD_MAGM },
&nbsp;        { &amp;EDisint_resistance, AD_DISN },
&nbsp;        { &amp;EPoison_resistance, AD_DRST },
&nbsp;        { &amp;EDrain_resistance, AD_DRLI },
&nbsp;    };
&nbsp;    int k;
&nbsp;
&nbsp;    for (k = 0; k &lt; SIZE(abil2adtyp); k++) {
&nbsp;        if (abil2adtyp[k].abil == abil)
&nbsp;            return abil2adtyp[k].adtyp;
&nbsp;    }
&nbsp;    return 0;
&nbsp;}
&nbsp;
abil_to_spfx
&nbsp;STATIC_OVL unsigned long
&nbsp;abil_to_spfx(abil)
&nbsp;long *abil;
&nbsp;{
&nbsp;    static const struct abil2spfx_tag {
&nbsp;        long *abil;
&nbsp;        unsigned long spfx;
&nbsp;    } abil2spfx[] = {
&nbsp;        { &amp;ESearching, SPFX_SEARCH },
&nbsp;        { &amp;EHalluc_resistance, SPFX_HALRES },
&nbsp;        { &amp;ETelepat, SPFX_ESP },
&nbsp;        { &amp;EStealth, SPFX_STLTH },
&nbsp;        { &amp;ERegeneration, SPFX_REGEN },
&nbsp;        { &amp;ETeleport_control, SPFX_TCTRL },
&nbsp;        { &amp;EWarn_of_mon, SPFX_WARN },
&nbsp;        { &amp;EWarning, SPFX_WARN },
&nbsp;        { &amp;EEnergy_regeneration, SPFX_EREGEN },
&nbsp;        { &amp;EHalf_spell_damage, SPFX_HSPDAM },
&nbsp;        { &amp;EHalf_physical_damage, SPFX_HPHDAM },
&nbsp;        { &amp;EReflecting, SPFX_REFLECT },
&nbsp;    };
&nbsp;    int k;
&nbsp;
&nbsp;    for (k = 0; k &lt; SIZE(abil2spfx); k++) {
&nbsp;        if (abil2spfx[k].abil == abil)
&nbsp;            return abil2spfx[k].spfx;
&nbsp;    }
&nbsp;    return 0L;
&nbsp;}
&nbsp;
what_gives
&nbsp;/*
&nbsp; * Return the first item that is conveying a particular intrinsic.
&nbsp; */
&nbsp;struct obj *
&nbsp;what_gives(abil)
&nbsp;long *abil;
&nbsp;{
&nbsp;    struct obj *obj;
&nbsp;    uchar dtyp;
&nbsp;    unsigned long spfx;
&nbsp;    long wornbits;
&nbsp;    long wornmask = (W_ARM | W_ARMC | W_ARMH | W_ARMS
&nbsp;                     | W_ARMG | W_ARMF | W_ARMU
&nbsp;                     | W_AMUL | W_RINGL | W_RINGR | W_TOOL
&nbsp;                     | W_ART | W_ARTI);
&nbsp;
&nbsp;    if (u.twoweap)
&nbsp;        wornmask |= W_SWAPWEP;
&nbsp;    dtyp = abil_to_adtyp(abil);
&nbsp;    spfx = abil_to_spfx(abil);
&nbsp;    wornbits = (wornmask &amp; *abil);
&nbsp;
&nbsp;    for (obj = invent; obj; obj = obj-&gt;nobj) {
&nbsp;        if (obj-&gt;oartifact
&nbsp;            &amp;&amp; (abil != &amp;EWarn_of_mon || context.warntype.obj)) {
&nbsp;            const struct artifact *art = get_artifact(obj);
&nbsp;
&nbsp;            if (art) {
&nbsp;                if (dtyp) {
&nbsp;                    if (art-&gt;cary.adtyp == dtyp /* carried */
&nbsp;                        || (art-&gt;defn.adtyp == dtyp /* defends while worn */
&nbsp;                            &amp;&amp; (obj-&gt;owornmask &amp; ~(W_ART | W_ARTI))))
&nbsp;                        return obj;
&nbsp;                }
&nbsp;                if (spfx) {
&nbsp;                    /* property conferred when carried */
&nbsp;                    if ((art-&gt;cspfx &amp; spfx) == spfx)
&nbsp;                        return obj;
&nbsp;                    /* property conferred when wielded or worn */
&nbsp;                    if ((art-&gt;spfx &amp; spfx) == spfx &amp;&amp; obj-&gt;owornmask)
&nbsp;                        return obj;
&nbsp;                }
&nbsp;            }
&nbsp;        } else {
&nbsp;            if (wornbits &amp;&amp; wornbits == (wornmask &amp; obj-&gt;owornmask))
&nbsp;                return obj;
&nbsp;        }
&nbsp;    }
&nbsp;    return (struct obj *) 0;
&nbsp;}
&nbsp;
glow_color
&nbsp;const char *
&nbsp;glow_color(arti_indx)
&nbsp;int arti_indx;
&nbsp;{
&nbsp;    int colornum = artilist[arti_indx].acolor;
&nbsp;    const char *colorstr = clr2colorname(colornum);
&nbsp;
&nbsp;    return hcolor(colorstr);
&nbsp;}
&nbsp;
Sting_effects
&nbsp;/* use for warning "glow" for Sting, Orcrist, and Grimtooth */
&nbsp;void
&nbsp;Sting_effects(orc_count)
&nbsp;int orc_count; /* new count (warn_obj_cnt is old count); -1 is a flag value */
&nbsp;{
&nbsp;    if (uwep
&nbsp;        &amp;&amp; (uwep-&gt;oartifact == ART_STING
&nbsp;            || uwep-&gt;oartifact == ART_ORCRIST
&nbsp;            || uwep-&gt;oartifact == ART_GRIMTOOTH)) {
&nbsp;        if (orc_count == -1 &amp;&amp; warn_obj_cnt &gt; 0) {
&nbsp;            /* -1 means that blindness has just been toggled; give a
&nbsp;               'continue' message that eventual 'stop' message will match */
&nbsp;            pline("%s is %s.", bare_artifactname(uwep),
&nbsp;                  !Blind ? "glowing" : "quivering");
&nbsp;        } else if (orc_count &gt; 0 &amp;&amp; warn_obj_cnt == 0) {
&nbsp;            /* 'start' message */
&nbsp;            if (!Blind)
&nbsp;                pline("%s %s %s!", bare_artifactname(uwep),
&nbsp;                      otense(uwep, "glow"), glow_color(uwep-&gt;oartifact));
&nbsp;            else
&nbsp;                pline("%s quivers slightly.", bare_artifactname(uwep));
&nbsp;        } else if (orc_count == 0 &amp;&amp; warn_obj_cnt &gt; 0) {
&nbsp;            /* 'stop' message */
&nbsp;            pline("%s stops %s.", bare_artifactname(uwep),
&nbsp;                  !Blind ? "glowing" : "quivering");
&nbsp;        }
&nbsp;    }
&nbsp;}
&nbsp;
retouch_object
&nbsp;/* called when hero is wielding/applying/invoking a carried item, or
&nbsp;   after undergoing a transformation (alignment change, lycanthropy,
&nbsp;   polymorph) which might affect item access */
&nbsp;int
&nbsp;retouch_object(objp, loseit)
&nbsp;struct obj **objp; /* might be destroyed or unintentionally dropped */
&nbsp;boolean loseit;    /* whether to drop it if hero can longer touch it */
&nbsp;{
&nbsp;    struct obj *obj = *objp;
&nbsp;
&nbsp;    if (touch_artifact(obj, &amp;youmonst)) {
&nbsp;        char buf[BUFSZ];
&nbsp;        int dmg = 0, tmp;
&nbsp;        boolean ag = (objects[obj-&gt;otyp].oc_material == SILVER &amp;&amp; Hate_silver),
&nbsp;                bane = bane_applies(get_artifact(obj), &amp;youmonst);
&nbsp;
&nbsp;        /* nothing else to do if hero can successfully handle this object */
&nbsp;        if (!ag &amp;&amp; !bane)
&nbsp;            return 1;
&nbsp;
&nbsp;        /* hero can't handle this object, but didn't get touch_artifact()'s
&nbsp;           "

<obj> evades your grasp|control" message; give an alternate one */
&nbsp;        You_cant("handle %s%s!", yname(obj),
&nbsp;                 obj-&gt;owornmask ? " anymore" : "");
&nbsp;        /* also inflict damage unless touch_artifact() already did so */
&nbsp;        if (!touch_blasted) {
&nbsp;            /* damage is somewhat arbitrary; half the usual 1d20 physical
&nbsp;               for silver, 1d10 magical for <foo>bane, potentially both */
&nbsp;            if (ag)
&nbsp;                tmp = rnd(10), dmg += Maybe_Half_Phys(tmp);
&nbsp;            if (bane)
&nbsp;                dmg += rnd(10);
&nbsp;            Sprintf(buf, "handling %s", killer_xname(obj));
&nbsp;            losehp(dmg, buf, KILLED_BY);
&nbsp;            exercise(A_CON, FALSE);
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* removing a worn item might result in loss of levitation,
&nbsp;       dropping the hero onto a polymorph trap or into water or
&nbsp;       lava and potentially dropping or destroying the item */
&nbsp;    if (obj-&gt;owornmask) {
&nbsp;        struct obj *otmp;
&nbsp;
&nbsp;        remove_worn_item(obj, FALSE);
&nbsp;        for (otmp = invent; otmp; otmp = otmp-&gt;nobj)
&nbsp;            if (otmp == obj)
&nbsp;                break;
&nbsp;        if (!otmp)
&nbsp;            *objp = obj = 0;
&nbsp;    }
&nbsp;
&nbsp;    /* if we still have it and caller wants us to drop it, do so now */
&nbsp;    if (loseit &amp;&amp; obj) {
&nbsp;        if (Levitation) {
&nbsp;            freeinv(obj);
&nbsp;            hitfloor(obj);
&nbsp;        } else {
&nbsp;            /* dropx gives a message iff item lands on an altar */
&nbsp;            if (!IS_ALTAR(levl[u.ux][u.uy].typ))
&nbsp;                pline("%s to the %s.", Tobjnam(obj, "fall"),
&nbsp;                      surface(u.ux, u.uy));
&nbsp;            dropx(obj);
&nbsp;        }
&nbsp;        *objp = obj = 0; /* no longer in inventory */
&nbsp;    }
&nbsp;    return 0;
&nbsp;}
&nbsp;
untouchable
&nbsp;/* an item which is worn/wielded or an artifact which conveys
&nbsp;   something via being carried or which has an #invoke effect
&nbsp;   currently in operation undergoes a touch test; if it fails,
&nbsp;   it will be unworn/unwielded and revoked but not dropped */
&nbsp;STATIC_OVL boolean
&nbsp;untouchable(obj, drop_untouchable)
&nbsp;struct obj *obj;
&nbsp;boolean drop_untouchable;
&nbsp;{
&nbsp;    struct artifact *art;
&nbsp;    boolean beingworn, carryeffect, invoked;
&nbsp;    long wearmask = ~(W_QUIVER | (u.twoweap ? 0L : W_SWAPWEP) | W_BALL);
&nbsp;
&nbsp;    beingworn = ((obj-&gt;owornmask &amp; wearmask) != 0L
&nbsp;                 /* some items in use don't have any wornmask setting */
&nbsp;                 || (obj-&gt;oclass == TOOL_CLASS
&nbsp;                     &amp;&amp; (obj-&gt;lamplit || (obj-&gt;otyp == LEASH &amp;&amp; obj-&gt;leashmon)
&nbsp;                         || (Is_container(obj) &amp;&amp; Has_contents(obj)))));
&nbsp;
&nbsp;    if ((art = get_artifact(obj)) != 0) {
&nbsp;        carryeffect = (art-&gt;cary.adtyp || art-&gt;cspfx);
&nbsp;        invoked = (art-&gt;inv_prop &gt; 0 &amp;&amp; art-&gt;inv_prop &lt;= LAST_PROP
&nbsp;                   &amp;&amp; (u.uprops[art-&gt;inv_prop].extrinsic &amp; W_ARTI) != 0L);
&nbsp;    } else {
&nbsp;        carryeffect = invoked = FALSE;
&nbsp;    }
&nbsp;
&nbsp;    if (beingworn || carryeffect || invoked) {
&nbsp;        if (!retouch_object(&amp;obj, drop_untouchable)) {
&nbsp;            /* "<artifact> is beyond your control" or "you can't handle
&nbsp;               <object>" has been given and it is now unworn/unwielded
&nbsp;               and possibly dropped (depending upon caller); if dropped,
&nbsp;               carried effect was turned off, else we leave that alone;
&nbsp;               we turn off invocation property here if still carried */
&nbsp;            if (invoked &amp;&amp; obj)
&nbsp;                arti_invoke(obj); /* reverse #invoke */
&nbsp;            return TRUE;
&nbsp;        }
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
retouch_equipment
&nbsp;/* check all items currently in use (mostly worn) for touchability */
&nbsp;void
&nbsp;retouch_equipment(dropflag)
&nbsp;int dropflag; /* 0==don't drop, 1==drop all, 2==drop weapon */
&nbsp;{
&nbsp;    static int nesting = 0; /* recursion control */
&nbsp;    struct obj *obj;
&nbsp;    boolean dropit, had_gloves = (uarmg != 0);
&nbsp;    int had_rings = (!!uleft + !!uright);
&nbsp;
&nbsp;    /*
&nbsp;     * We can potentially be called recursively if losing/unwearing
&nbsp;     * an item causes worn helm of opposite alignment to come off or
&nbsp;     * be destroyed.
&nbsp;     *
&nbsp;     * BUG: if the initial call was due to putting on a helm of
&nbsp;     * opposite alignment and it does come off to trigger recursion,
&nbsp;     * after the inner call executes, the outer call will finish
&nbsp;     * using the non-helm alignment rather than the helm alignment
&nbsp;     * which triggered this in the first place.
&nbsp;     */
&nbsp;    if (!nesting++)
&nbsp;        clear_bypasses(); /* init upon initial entry */
&nbsp;
&nbsp;    dropit = (dropflag &gt; 0); /* drop all or drop weapon */
&nbsp;    /* check secondary weapon first, before possibly unwielding primary */
&nbsp;    if (u.twoweap) {
&nbsp;        bypass_obj(uswapwep); /* so loop below won't process it again */
&nbsp;        (void) untouchable(uswapwep, dropit);
&nbsp;    }
&nbsp;    /* check primary weapon next so that they're handled together */
&nbsp;    if (uwep) {
&nbsp;        bypass_obj(uwep); /* so loop below won't process it again */
&nbsp;        (void) untouchable(uwep, dropit);
&nbsp;    }
&nbsp;
&nbsp;    /* in case someone is daft enough to add artifact or silver saddle */
&nbsp;    if (u.usteed &amp;&amp; (obj = which_armor(u.usteed, W_SADDLE)) != 0) {
&nbsp;        /* untouchable() calls retouch_object() which expects an object in
&nbsp;           hero's inventory, but remove_worn_item() will be harmless for
&nbsp;           saddle and we're suppressing drop, so this works as intended */
&nbsp;        if (untouchable(obj, FALSE))
&nbsp;            dismount_steed(DISMOUNT_THROWN);
&nbsp;    }
&nbsp;    /*
&nbsp;     * TODO?  Force off gloves if either or both rings are going to
&nbsp;     * become unworn; force off cloak [suit] before suit [shirt].
&nbsp;     * The torso handling is hypothetical; the case for gloves is
&nbsp;     * not, due to the possibility of unwearing silver rings.
&nbsp;     */
&nbsp;
&nbsp;    dropit = (dropflag == 1); /* all untouchable items */
&nbsp;    /* loss of levitation (silver ring, or Heart of Ahriman invocation)
&nbsp;       might cause hero to lose inventory items (by dropping into lava,
&nbsp;       for instance), so inventory traversal needs to rescan the whole
&nbsp;       invent chain each time it moves on to another object; we use bypass
&nbsp;       handling to keep track of which items have already been processed */
&nbsp;    while ((obj = nxt_unbypassed_obj(invent)) != 0)
&nbsp;        (void) untouchable(obj, dropit);
&nbsp;
&nbsp;    if (had_rings != (!!uleft + !!uright) &amp;&amp; uarmg &amp;&amp; uarmg-&gt;cursed)
&nbsp;        uncurse(uarmg); /* temporary? hack for ring removal plausibility */
&nbsp;    if (had_gloves &amp;&amp; !uarmg)
&nbsp;        selftouch("After losing your gloves, you");
&nbsp;
&nbsp;    if (!--nesting)
&nbsp;        clear_bypasses(); /* reset upon final exit */
&nbsp;}
&nbsp;
&nbsp;static int mkot_trap_warn_count = 0;
&nbsp;
count_surround_traps
&nbsp;STATIC_OVL int
&nbsp;count_surround_traps(x, y)
&nbsp;int x, y;
&nbsp;{
&nbsp;    struct rm *levp;
&nbsp;    struct obj *otmp;
&nbsp;    struct trap *ttmp;
&nbsp;    int dx, dy, glyph, ret = 0;
&nbsp;
&nbsp;    for (dx = x - 1; dx &lt; x + 2; ++dx)
&nbsp;        for (dy = y - 1; dy &lt; y + 2; ++dy) {
&nbsp;            if (!isok(dx, dy))
&nbsp;                continue;
&nbsp;            /* If a trap is shown here, don't count it; the hero
&nbsp;             * should be expecting it.  But if there is a trap here
&nbsp;             * that's not shown, either undiscovered or covered by
&nbsp;             * something, do count it.
&nbsp;             */
&nbsp;            glyph = glyph_at(dx, dy);
&nbsp;            if (glyph_is_trap(glyph))
&nbsp;                continue;
&nbsp;            if ((ttmp = t_at(dx, dy)) != 0) {
&nbsp;                ++ret;
&nbsp;                continue;
&nbsp;            }
&nbsp;            levp = &amp;levl[dx][dy];
&nbsp;            if (IS_DOOR(levp-&gt;typ) &amp;&amp; (levp-&gt;doormask &amp; D_TRAPPED) != 0) {
&nbsp;                ++ret;
&nbsp;                continue;
&nbsp;            }
&nbsp;            for (otmp = level.objects[dx][dy]; otmp; otmp = otmp-&gt;nexthere)
&nbsp;                if (Is_container(otmp) &amp;&amp; otmp-&gt;otrapped) {
&nbsp;                    ++ret; /* we're counting locations, so just */
&nbsp;                    break; /* count the first one in a pile     */
&nbsp;                }
&nbsp;        }
&nbsp;    /*
&nbsp;     * [Shouldn't we also check inventory for a trapped container?
&nbsp;     * Even if its trap has already been found, there's no 'tknown'
&nbsp;     * flag to help hero remember that so we have nothing comparable
&nbsp;     * to a shown glyph to justify skipping it.]
&nbsp;     */
&nbsp;    return ret;
&nbsp;}
&nbsp;
mkot_trap_warn
&nbsp;/* sense adjacent traps if wielding MKoT without wearing gloves */
&nbsp;void
&nbsp;mkot_trap_warn()
&nbsp;{
&nbsp;    static const char *const heat[7] = {
&nbsp;        "cool", "slightly warm", "warm", "very warm",
&nbsp;        "hot", "very hot", "like fire"
&nbsp;    };
&nbsp;
&nbsp;    if (!uarmg &amp;&amp; uwep &amp;&amp; uwep-&gt;oartifact == ART_MASTER_KEY_OF_THIEVERY) {
&nbsp;        int idx, ntraps = count_surround_traps(u.ux, u.uy);
&nbsp;
&nbsp;        if (ntraps != mkot_trap_warn_count) {
&nbsp;            idx = min(ntraps, SIZE(heat) - 1);
&nbsp;            pline_The("Key feels %s%c", heat[idx], (ntraps &gt; 3) ? '!' : '.');
&nbsp;        }
&nbsp;        mkot_trap_warn_count = ntraps;
&nbsp;    } else
&nbsp;        mkot_trap_warn_count = 0;
&nbsp;}
&nbsp;
is_magic_key
&nbsp;/* Master Key is magic key if its bless/curse state meets our criteria:
&nbsp;   not cursed for rogues or blessed for non-rogues */
&nbsp;boolean
&nbsp;is_magic_key(mon, obj)
&nbsp;struct monst *mon; /* if null, non-rogue is assumed */
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    if (((obj &amp;&amp; obj-&gt;oartifact == ART_MASTER_KEY_OF_THIEVERY)
&nbsp;         &amp;&amp; ((mon == &amp;youmonst) ? Role_if(PM_ROGUE)
&nbsp;                                : (mon &amp;&amp; mon-&gt;data == &amp;mons[PM_ROGUE])))
&nbsp;        ? !obj-&gt;cursed : obj-&gt;blessed)
&nbsp;        return TRUE;
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
has_magic_key
&nbsp;/* figure out whether 'mon' (usually youmonst) is carrying the magic key */
&nbsp;struct obj *
&nbsp;has_magic_key(mon)
&nbsp;struct monst *mon; /* if null, hero assumed */
&nbsp;{
&nbsp;    struct obj *o;
&nbsp;    short key = artilist[ART_MASTER_KEY_OF_THIEVERY].otyp;
&nbsp;
&nbsp;    if (!mon)
&nbsp;        mon = &amp;youmonst
&nbsp;    for (o = ((mon == &amp;youmonst) ? invent : mon-&gt;minvent); o;
&nbsp;         o = nxtobj(o, key, FALSE)) {
&nbsp;        if (is_magic_key(mon, o))
&nbsp;            return o;
&nbsp;    }
&nbsp;    return (struct obj *) 0;
&nbsp;}
&nbsp;
&nbsp;/*artifact.c*/

</object></artifact></foo></obj>