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

Contents

1 Top of file
2 learnwand
3 bhitm
4 probe_monster
5 get_obj_location
6 get_mon_location
7 montraits
8 get_container_location
9 revive
10 revive_egg
11 unturn_dead
12 cancel_item
13 drain_item
14 obj_resists
15 obj_shudders
16 polyuse
17 create_polymon
18 do_osshock
19 poly_obj
20 stone_to_flesh_obj
21 bhito
22 bhitpile
23 zappable
24 zapnodir
25 backfire
26 dozap
27 zapyourself
28 ubreatheu
29 lightdamage
30 flashburn
31 zap_steed
32 cancel_monst
33 zap_updown
34 zapsetup
35 zapwrapup
36 weffects
37 spell_damage_bonus
38 spell_hit_bonus
39 exclam
40 hit
41 miss
42 skiprange
43 bhit
44 boomhit
45 zhitm
46 zhitu
47 burn_floor_objects
48 zap_hit
49 disintegrate_mon
50 buzz
51 dobuzz
52 melt_ice
53 start_melt_ice_timeout
54 melt_ice_away
55 zap_over_floor
56 fracture_rock
57 break_statue
58 destroy_item
59 destroy_mitem
60 resist
61 wishcmdassist
62 makewish

Top of file
&nbsp;/* NetHack 3.6	zap.c	$NHDT-Date: 1524470244 2018/04/23 07:57:24 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.275 $ */
&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;
&nbsp;/* Disintegration rays have special treatment; corpses are never left.
&nbsp; * But the routine which calculates the damage is separate from the routine
&nbsp; * which kills the monster.  The damage routine returns this cookie to
&nbsp; * indicate that the monster should be disintegrated.
&nbsp; */
&nbsp;#define MAGIC_COOKIE 1000
&nbsp;
&nbsp;static NEARDATA boolean obj_zapped;
&nbsp;static NEARDATA int poly_zapped;
&nbsp;
&nbsp;extern boolean notonhead; /* for long worms */
&nbsp;
&nbsp;/* kludge to use mondied instead of killed */
&nbsp;extern boolean m_using;
&nbsp;
&nbsp;STATIC_DCL void FDECL(polyuse, (struct obj *, int, int));
&nbsp;STATIC_DCL void FDECL(create_polymon, (struct obj *, int));
&nbsp;STATIC_DCL int FDECL(stone_to_flesh_obj, (struct obj *));
&nbsp;STATIC_DCL boolean FDECL(zap_updown, (struct obj *));
&nbsp;STATIC_DCL void FDECL(zhitu, (int, int, const char *, XCHAR_P, XCHAR_P));
&nbsp;STATIC_DCL void FDECL(revive_egg, (struct obj *));
&nbsp;STATIC_DCL boolean FDECL(zap_steed, (struct obj *));
&nbsp;STATIC_DCL void FDECL(skiprange, (int, int *, int *));
&nbsp;
&nbsp;STATIC_DCL int FDECL(zap_hit, (int, int));
&nbsp;STATIC_OVL void FDECL(disintegrate_mon, (struct monst *, int, const char *));
&nbsp;STATIC_DCL void FDECL(backfire, (struct obj *));
&nbsp;STATIC_DCL int FDECL(spell_hit_bonus, (int));
&nbsp;
&nbsp;#define ZT_MAGIC_MISSILE (AD_MAGM - 1)
&nbsp;#define ZT_FIRE (AD_FIRE - 1)
&nbsp;#define ZT_COLD (AD_COLD - 1)
&nbsp;#define ZT_SLEEP (AD_SLEE - 1)
&nbsp;#define ZT_DEATH (AD_DISN - 1) /* or disintegration */
&nbsp;#define ZT_LIGHTNING (AD_ELEC - 1)
&nbsp;#define ZT_POISON_GAS (AD_DRST - 1)
&nbsp;#define ZT_ACID (AD_ACID - 1)
&nbsp;/* 8 and 9 are currently unassigned */
&nbsp;
&nbsp;#define ZT_WAND(x) (x)
&nbsp;#define ZT_SPELL(x) (10 + (x))
&nbsp;#define ZT_BREATH(x) (20 + (x))
&nbsp;
&nbsp;#define is_hero_spell(type) ((type) &gt;= 10 &amp;&amp; (type) &lt; 20)
&nbsp;
&nbsp;#define M_IN_WATER(ptr) \
&nbsp;    ((ptr)-&gt;mlet == S_EEL || amphibious(ptr) || is_swimmer(ptr))
&nbsp;
&nbsp;STATIC_VAR const char are_blinded_by_the_flash[] =
&nbsp;    "are blinded by the flash!";
&nbsp;
&nbsp;const char *const flash_types[] =       /* also used in buzzmu(mcastu.c) */
&nbsp;    {
&nbsp;        "magic missile", /* Wands must be 0-9 */
&nbsp;        "bolt of fire", "bolt of cold", "sleep ray", "death ray",
&nbsp;        "bolt of lightning", "", "", "", "",
&nbsp;
&nbsp;        "magic missile", /* Spell equivalents must be 10-19 */
&nbsp;        "fireball", "cone of cold", "sleep ray", "finger of death",
&nbsp;        "bolt of lightning", /* there is no spell, used for retribution */
&nbsp;        "", "", "", "",
&nbsp;
&nbsp;        "blast of missiles", /* Dragon breath equivalents 20-29*/
&nbsp;        "blast of fire", "blast of frost", "blast of sleep gas",
&nbsp;        "blast of disintegration", "blast of lightning",
&nbsp;        "blast of poison gas", "blast of acid", "", ""
&nbsp;    };
&nbsp;
&nbsp;/*
&nbsp; * Recognizing unseen wands by zapping:  in 3.4.3 and earlier, zapping
&nbsp; * most wand types while blind would add that type to the discoveries
&nbsp; * list even if it had never been seen (ie, picked up while blinded
&nbsp; * and shown in inventory as simply "a wand").  This behavior has been
&nbsp; * changed; now such wands won't be discovered.  But if the type is
&nbsp; * already discovered, then the individual wand whose effect was just
&nbsp; * observed will be flagged as if seen.  [You already know wands of
&nbsp; * striking; you zap "a wand" and observe striking effect (presumably
&nbsp; * by sound or touch); it'll become shown in inventory as "a wand of
&nbsp; * striking".]
&nbsp; *
&nbsp; * Unfortunately, the new behavior isn't really correct either.  There
&nbsp; * should be an `eknown' bit for "effect known" added for wands (and
&nbsp; * for potions since quaffing one of a stack is similar) so that the
&nbsp; * particular wand which has been zapped would have its type become
&nbsp; * known (it would change from "a wand" to "a wand of striking", for
&nbsp; * example) without the type becoming discovered or other unknown wands
&nbsp; * of that type showing additional information.  When blindness ends,
&nbsp; * all objects in inventory with the eknown bit set would be discovered
&nbsp; * and other items of the same type would become known as such.
&nbsp; */
&nbsp;
learnwand
&nbsp;/* wand discovery gets special handling when hero is blinded */
&nbsp;void
&nbsp;learnwand(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    /* For a wand (or wand-like tool) zapped by the player, if the
&nbsp;       effect was observable (determined by caller; usually seen, but
&nbsp;       possibly heard or felt if the hero is blinded) then discover the
&nbsp;       object type provided that the object itself is known (as more
&nbsp;       than just "a wand").  If object type is already discovered and
&nbsp;       we observed the effect, mark the individual wand as having been
&nbsp;       seen.  Suppress spells (which use fake spellbook object for `obj')
&nbsp;       so that casting a spell won't re-discover its forgotten book. */
&nbsp;    if (obj-&gt;oclass != SPBOOK_CLASS) {
&nbsp;        /* if type already discovered, treat this item has having been seen
&nbsp;           even if hero is currently blinded (skips redundant makeknown) */
&nbsp;        if (objects[obj-&gt;otyp].oc_name_known) {
&nbsp;            obj-&gt;dknown = 1; /* will usually be set already */
&nbsp;
&nbsp;        /* otherwise discover it if item itself has been or can be seen */
&nbsp;        } else {
&nbsp;            /* in case it was picked up while blind and then zapped without
&nbsp;               examining inventory after regaining sight (bypassing xname) */
&nbsp;            if (!Blind)
&nbsp;                obj-&gt;dknown = 1;
&nbsp;            /* make the discovery iff we know what we're manipulating */
&nbsp;            if (obj-&gt;dknown)
&nbsp;                makeknown(obj-&gt;otyp);
&nbsp;        }
&nbsp;    }
&nbsp;}
&nbsp;
&nbsp;/* Routines for IMMEDIATE wands and spells. */
bhitm
&nbsp;/* bhitm: monster mtmp was hit by the effect of wand or spell otmp */
&nbsp;int
&nbsp;bhitm(mtmp, otmp)
&nbsp;struct monst *mtmp;
&nbsp;struct obj *otmp;
&nbsp;{
&nbsp;    boolean wake = TRUE; /* Most 'zaps' should wake monster */
&nbsp;    boolean reveal_invis = FALSE, learn_it = FALSE;
&nbsp;    boolean dbldam = Role_if(PM_KNIGHT) &amp;&amp; u.uhave.questart;
&nbsp;    boolean helpful_gesture = FALSE;
&nbsp;    int dmg, otyp = otmp-&gt;otyp;
&nbsp;    const char *zap_type_text = "spell";
&nbsp;    struct obj *obj;
&nbsp;    boolean disguised_mimic = (mtmp-&gt;data-&gt;mlet == S_MIMIC
&nbsp;                               &amp;&amp; mtmp-&gt;m_ap_type != M_AP_NOTHING);
&nbsp;
&nbsp;    if (u.uswallow &amp;&amp; mtmp == u.ustuck)
&nbsp;        reveal_invis = FALSE;
&nbsp;
&nbsp;    notonhead = (mtmp-&gt;mx != bhitpos.x || mtmp-&gt;my != bhitpos.y);
&nbsp;    switch (otyp) {
&nbsp;    case WAN_STRIKING:
&nbsp;        zap_type_text = "wand";
&nbsp;    /* fall through */
&nbsp;    case SPE_FORCE_BOLT:
&nbsp;        reveal_invis = TRUE;
&nbsp;        if (disguised_mimic)
&nbsp;            seemimic(mtmp);
&nbsp;        if (resists_magm(mtmp)) { /* match effect on player */
&nbsp;            shieldeff(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;            pline("Boing!");
&nbsp;            break; /* skip makeknown */
&nbsp;        } else if (u.uswallow || rnd(20) &lt; 10 + find_mac(mtmp)) {
&nbsp;            dmg = d(2, 12);
&nbsp;            if (dbldam)
&nbsp;                dmg *= 2;
&nbsp;            if (otyp == SPE_FORCE_BOLT)
&nbsp;                dmg = spell_damage_bonus(dmg);
&nbsp;            hit(zap_type_text, mtmp, exclam(dmg));
&nbsp;            (void) resist(mtmp, otmp-&gt;oclass, dmg, TELL);
&nbsp;        } else
&nbsp;            miss(zap_type_text, mtmp);
&nbsp;        learn_it = TRUE;
&nbsp;        break;
&nbsp;    case WAN_SLOW_MONSTER:
&nbsp;    case SPE_SLOW_MONSTER:
&nbsp;        if (!resist(mtmp, otmp-&gt;oclass, 0, NOTELL)) {
&nbsp;            if (disguised_mimic)
&nbsp;                seemimic(mtmp);
&nbsp;            mon_adjust_speed(mtmp, -1, otmp);
&nbsp;            m_dowear(mtmp, FALSE); /* might want speed boots */
&nbsp;            if (u.uswallow &amp;&amp; (mtmp == u.ustuck) &amp;&amp; is_whirly(mtmp-&gt;data)) {
&nbsp;                You("disrupt %s!", mon_nam(mtmp));
&nbsp;                pline("A huge hole opens up...");
&nbsp;                expels(mtmp, mtmp-&gt;data, TRUE);
&nbsp;            }
&nbsp;        }
&nbsp;        break;
&nbsp;    case WAN_SPEED_MONSTER:
&nbsp;        if (!resist(mtmp, otmp-&gt;oclass, 0, NOTELL)) {
&nbsp;            if (disguised_mimic)
&nbsp;                seemimic(mtmp);
&nbsp;            mon_adjust_speed(mtmp, 1, otmp);
&nbsp;            m_dowear(mtmp, FALSE); /* might want speed boots */
&nbsp;        }
&nbsp;        if (mtmp-&gt;mtame)
&nbsp;            helpful_gesture = TRUE;
&nbsp;        break;
&nbsp;    case WAN_UNDEAD_TURNING:
&nbsp;    case SPE_TURN_UNDEAD:
&nbsp;        wake = FALSE;
&nbsp;        if (unturn_dead(mtmp))
&nbsp;            wake = TRUE;
&nbsp;        if (is_undead(mtmp-&gt;data) || is_vampshifter(mtmp)) {
&nbsp;            reveal_invis = TRUE;
&nbsp;            wake = TRUE;
&nbsp;            dmg = rnd(8);
&nbsp;            if (dbldam)
&nbsp;                dmg *= 2;
&nbsp;            if (otyp == SPE_TURN_UNDEAD)
&nbsp;                dmg = spell_damage_bonus(dmg);
&nbsp;            context.bypasses = TRUE; /* for make_corpse() */
&nbsp;            if (!resist(mtmp, otmp-&gt;oclass, dmg, NOTELL)) {
&nbsp;                if (mtmp-&gt;mhp &gt; 0)
&nbsp;                    monflee(mtmp, 0, FALSE, TRUE);
&nbsp;            }
&nbsp;        }
&nbsp;        break;
&nbsp;    case WAN_POLYMORPH:
&nbsp;    case SPE_POLYMORPH:
&nbsp;    case POT_POLYMORPH:
&nbsp;        if (resists_magm(mtmp)) {
&nbsp;            /* magic resistance protects from polymorph traps, so make
&nbsp;               it guard against involuntary polymorph attacks too... */
&nbsp;            shieldeff(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;        } else if (!resist(mtmp, otmp-&gt;oclass, 0, NOTELL)) {
&nbsp;            boolean polyspot = (otyp != POT_POLYMORPH),
&nbsp;                    give_msg = (!Hallucination
&nbsp;                                &amp;&amp; (canseemon(mtmp)
&nbsp;                                    || (u.uswallow &amp;&amp; mtmp == u.ustuck)));
&nbsp;
&nbsp;            /* dropped inventory (due to death by system shock,
&nbsp;               or loss of wielded weapon and/or worn armor due to
&nbsp;               limitations of new shape) won't be hit by this zap */
&nbsp;            if (polyspot)
&nbsp;                for (obj = mtmp-&gt;minvent; obj; obj = obj-&gt;nobj)
&nbsp;                    bypass_obj(obj);
&nbsp;            /* natural shapechangers aren't affected by system shock
&nbsp;               (unless protection from shapechangers is interfering
&nbsp;               with their metabolism...) */
&nbsp;            if (mtmp-&gt;cham == NON_PM &amp;&amp; !rn2(25)) {
&nbsp;                if (canseemon(mtmp)) {
&nbsp;                    pline("%s shudders!", Monnam(mtmp));
&nbsp;                    learn_it = TRUE;
&nbsp;                }
&nbsp;                /* context.bypasses = TRUE; ## for make_corpse() */
&nbsp;                /* no corpse after system shock */
&nbsp;                xkilled(mtmp, XKILL_GIVEMSG | XKILL_NOCORPSE);
&nbsp;            } else if (newcham(mtmp, (struct permonst *) 0,
&nbsp;                               polyspot, give_msg) != 0
&nbsp;                       /* if shapechange failed because there aren't
&nbsp;                          enough eligible candidates (most likely for
&nbsp;                          vampshifter), try reverting to original form */
&nbsp;                       || (mtmp-&gt;cham &gt;= LOW_PM
&nbsp;                           &amp;&amp; newcham(mtmp, &amp;mons[mtmp-&gt;cham],
&nbsp;                                      polyspot, give_msg) != 0)) {
&nbsp;                if (give_msg &amp;&amp; (canspotmon(mtmp)
&nbsp;                                 || (u.uswallow &amp;&amp; mtmp == u.ustuck)))
&nbsp;                    learn_it = TRUE;
&nbsp;            }
&nbsp;        }
&nbsp;        break;
&nbsp;    case WAN_CANCELLATION:
&nbsp;    case SPE_CANCELLATION:
&nbsp;        if (disguised_mimic)
&nbsp;            seemimic(mtmp);
&nbsp;        (void) cancel_monst(mtmp, otmp, TRUE, TRUE, FALSE);
&nbsp;        break;
&nbsp;    case WAN_TELEPORTATION:
&nbsp;    case SPE_TELEPORT_AWAY:
&nbsp;        if (disguised_mimic)
&nbsp;            seemimic(mtmp);
&nbsp;        reveal_invis = !u_teleport_mon(mtmp, TRUE);
&nbsp;        break;
&nbsp;    case WAN_MAKE_INVISIBLE: {
&nbsp;        int oldinvis = mtmp-&gt;minvis;
&nbsp;        char nambuf[BUFSZ];
&nbsp;
&nbsp;        if (disguised_mimic)
&nbsp;            seemimic(mtmp);
&nbsp;        /* format monster's name before altering its visibility */
&nbsp;        Strcpy(nambuf, Monnam(mtmp));
&nbsp;        mon_set_minvis(mtmp);
&nbsp;        if (!oldinvis &amp;&amp; knowninvisible(mtmp)) {
&nbsp;            pline("%s turns transparent!", nambuf);
&nbsp;            reveal_invis = TRUE;
&nbsp;            learn_it = TRUE;
&nbsp;        }
&nbsp;        break;
&nbsp;    }
&nbsp;    case WAN_LOCKING:
&nbsp;    case SPE_WIZARD_LOCK:
&nbsp;        wake = closeholdingtrap(mtmp, &amp;learn_it);
&nbsp;        break;
&nbsp;    case WAN_PROBING:
&nbsp;        wake = FALSE;
&nbsp;        reveal_invis = TRUE;
&nbsp;        probe_monster(mtmp);
&nbsp;        learn_it = TRUE;
&nbsp;        break;
&nbsp;    case WAN_OPENING:
&nbsp;    case SPE_KNOCK:
&nbsp;        wake = FALSE; /* don't want immediate counterattack */
&nbsp;        if (u.uswallow &amp;&amp; mtmp == u.ustuck) {
&nbsp;            if (is_animal(mtmp-&gt;data)) {
&nbsp;                if (Blind)
&nbsp;                    You_feel("a sudden rush of air!");
&nbsp;                else
&nbsp;                    pline("%s opens its mouth!", Monnam(mtmp));
&nbsp;            }
&nbsp;            expels(mtmp, mtmp-&gt;data, TRUE);
&nbsp;            /* zap which hits steed will only release saddle if it
&nbsp;               doesn't hit a holding or falling trap; playability
&nbsp;               here overrides the more logical target ordering */
&nbsp;        } else if (openholdingtrap(mtmp, &amp;learn_it)) {
&nbsp;            break;
&nbsp;        } else if (openfallingtrap(mtmp, TRUE, &amp;learn_it)) {
&nbsp;            /* mtmp might now be on the migrating monsters list */
&nbsp;            break;
&nbsp;        } else if ((obj = which_armor(mtmp, W_SADDLE)) != 0) {
&nbsp;            char buf[BUFSZ];
&nbsp;
&nbsp;            Sprintf(buf, "%s %s", s_suffix(Monnam(mtmp)),
&nbsp;                    distant_name(obj, xname));
&nbsp;            if (cansee(mtmp-&gt;mx, mtmp-&gt;my)) {
&nbsp;                if (!canspotmon(mtmp))
&nbsp;                    Strcpy(buf, An(distant_name(obj, xname)));
&nbsp;                pline("%s falls to the %s.", buf,
&nbsp;                      surface(mtmp-&gt;mx, mtmp-&gt;my));
&nbsp;            } else if (canspotmon(mtmp)) {
&nbsp;                pline("%s falls off.", buf);
&nbsp;            }
&nbsp;            obj_extract_self(obj);
&nbsp;            mdrop_obj(mtmp, obj, FALSE);
&nbsp;        }
&nbsp;        break;
&nbsp;    case SPE_HEALING:
&nbsp;    case SPE_EXTRA_HEALING:
&nbsp;        reveal_invis = TRUE;
&nbsp;        if (mtmp-&gt;data != &amp;mons[PM_PESTILENCE]) {
&nbsp;            wake = FALSE; /* wakeup() makes the target angry */
&nbsp;            mtmp-&gt;mhp += d(6, otyp == SPE_EXTRA_HEALING ? 8 : 4);
&nbsp;            if (mtmp-&gt;mhp &gt; mtmp-&gt;mhpmax)
&nbsp;                mtmp-&gt;mhp = mtmp-&gt;mhpmax;
&nbsp;            if (mtmp-&gt;mblinded) {
&nbsp;                mtmp-&gt;mblinded = 0;
&nbsp;                mtmp-&gt;mcansee = 1;
&nbsp;            }
&nbsp;            if (canseemon(mtmp)) {
&nbsp;                if (disguised_mimic) {
&nbsp;                    if (is_obj_mappear(mtmp,STRANGE_OBJECT)) {
&nbsp;                        /* it can do better now */
&nbsp;                        set_mimic_sym(mtmp);
&nbsp;                        newsym(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;                    } else
&nbsp;                        mimic_hit_msg(mtmp, otyp);
&nbsp;                } else
&nbsp;                    pline("%s looks%s better.", Monnam(mtmp),
&nbsp;                          otyp == SPE_EXTRA_HEALING ? " much" : "");
&nbsp;            }
&nbsp;            if (mtmp-&gt;mtame || mtmp-&gt;mpeaceful) {
&nbsp;                adjalign(Role_if(PM_HEALER) ? 1 : sgn(u.ualign.type));
&nbsp;            }
&nbsp;        } else { /* Pestilence */
&nbsp;            /* Pestilence will always resist; damage is half of 3d{4,8} */
&nbsp;            (void) resist(mtmp, otmp-&gt;oclass,
&nbsp;                          d(3, otyp == SPE_EXTRA_HEALING ? 8 : 4), TELL);
&nbsp;        }
&nbsp;        break;
&nbsp;    case WAN_LIGHT: /* (broken wand) */
&nbsp;        if (flash_hits_mon(mtmp, otmp)) {
&nbsp;            learn_it = TRUE;
&nbsp;            reveal_invis = TRUE;
&nbsp;        }
&nbsp;        break;
&nbsp;    case WAN_SLEEP: /* (broken wand) */
&nbsp;        /* [wakeup() doesn't rouse victims of temporary sleep,
&nbsp;           so it's okay to leave `wake' set to TRUE here] */
&nbsp;        reveal_invis = TRUE;
&nbsp;        if (sleep_monst(mtmp, d(1 + otmp-&gt;spe, 12), WAND_CLASS))
&nbsp;            slept_monst(mtmp);
&nbsp;        if (!Blind)
&nbsp;            learn_it = TRUE;
&nbsp;        break;
&nbsp;    case SPE_STONE_TO_FLESH:
&nbsp;        if (monsndx(mtmp-&gt;data) == PM_STONE_GOLEM) {
&nbsp;            char *name = Monnam(mtmp);
&nbsp;
&nbsp;            /* turn into flesh golem */
&nbsp;            if (newcham(mtmp, &amp;mons[PM_FLESH_GOLEM], FALSE, FALSE)) {
&nbsp;                if (canseemon(mtmp))
&nbsp;                    pline("%s turns to flesh!", name);
&nbsp;            } else {
&nbsp;                if (canseemon(mtmp))
&nbsp;                    pline("%s looks rather fleshy for a moment.", name);
&nbsp;            }
&nbsp;        } else
&nbsp;            wake = FALSE;
&nbsp;        break;
&nbsp;    case SPE_DRAIN_LIFE:
&nbsp;        if (disguised_mimic)
&nbsp;            seemimic(mtmp);
&nbsp;        dmg = monhp_per_lvl(mtmp);
&nbsp;        if (dbldam)
&nbsp;            dmg *= 2;
&nbsp;        if (otyp == SPE_DRAIN_LIFE)
&nbsp;            dmg = spell_damage_bonus(dmg);
&nbsp;        if (resists_drli(mtmp)) {
&nbsp;            shieldeff(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;        } else if (!resist(mtmp, otmp-&gt;oclass, dmg, NOTELL) &amp;&amp; mtmp-&gt;mhp &gt; 0) {
&nbsp;            mtmp-&gt;mhp -= dmg;
&nbsp;            mtmp-&gt;mhpmax -= dmg;
&nbsp;            /* die if already level 0, regardless of hit points */
&nbsp;            if (mtmp-&gt;mhp &lt;= 0 || mtmp-&gt;mhpmax &lt;= 0 || mtmp-&gt;m_lev &lt; 1) {
&nbsp;                killed(mtmp);
&nbsp;            } else {
&nbsp;                mtmp-&gt;m_lev--;
&nbsp;                if (canseemon(mtmp))
&nbsp;                    pline("%s suddenly seems weaker!", Monnam(mtmp));
&nbsp;            }
&nbsp;        }
&nbsp;        break;
&nbsp;    case WAN_NOTHING:
&nbsp;        wake = FALSE;
&nbsp;        break;
&nbsp;    default:
&nbsp;        impossible("What an interesting effect (%d)", otyp);
&nbsp;        break;
&nbsp;    }
&nbsp;    if (wake) {
&nbsp;        if (mtmp-&gt;mhp &gt; 0) {
&nbsp;            wakeup(mtmp, helpful_gesture ? FALSE : TRUE);
&nbsp;            m_respond(mtmp);
&nbsp;            if (mtmp-&gt;isshk &amp;&amp; !*u.ushops)
&nbsp;                hot_pursuit(mtmp);
&nbsp;        } else if (mtmp-&gt;m_ap_type)
&nbsp;            seemimic(mtmp); /* might unblock if mimicing a boulder/door */
&nbsp;    }
&nbsp;    /* note: bhitpos won't be set if swallowed, but that's okay since
&nbsp;     * reveal_invis will be false.  We can't use mtmp-&gt;mx, my since it
&nbsp;     * might be an invisible worm hit on the tail.
&nbsp;     */
&nbsp;    if (reveal_invis) {
&nbsp;        if (mtmp-&gt;mhp &gt; 0 &amp;&amp; cansee(bhitpos.x, bhitpos.y)
&nbsp;            &amp;&amp; !canspotmon(mtmp))
&nbsp;            map_invisible(bhitpos.x, bhitpos.y);
&nbsp;    }
&nbsp;    /* if effect was observable then discover the wand type provided
&nbsp;       that the wand itself has been seen */
&nbsp;    if (learn_it)
&nbsp;        learnwand(otmp);
&nbsp;    return 0;
&nbsp;}
&nbsp;
probe_monster
&nbsp;void
&nbsp;probe_monster(mtmp)
&nbsp;struct monst *mtmp;
&nbsp;{
&nbsp;    struct obj *otmp;
&nbsp;
&nbsp;    mstatusline(mtmp);
&nbsp;    if (notonhead)
&nbsp;        return; /* don't show minvent for long worm tail */
&nbsp;
&nbsp;    if (mtmp-&gt;minvent) {
&nbsp;        for (otmp = mtmp-&gt;minvent; otmp; otmp = otmp-&gt;nobj) {
&nbsp;            otmp-&gt;dknown = 1; /* treat as "seen" */
&nbsp;            if (Is_container(otmp) || otmp-&gt;otyp == STATUE) {
&nbsp;                otmp-&gt;lknown = 1;
&nbsp;                if (!SchroedingersBox(otmp))
&nbsp;                    otmp-&gt;cknown = 1;
&nbsp;            }
&nbsp;        }
&nbsp;        (void) display_minventory(mtmp, MINV_ALL | MINV_NOLET | PICK_NONE,
&nbsp;                                  (char *) 0);
&nbsp;    } else {
&nbsp;        pline("%s is not carrying anything%s.", noit_Monnam(mtmp),
&nbsp;              (u.uswallow &amp;&amp; mtmp == u.ustuck) ? " besides you" : "");
&nbsp;    }
&nbsp;}
&nbsp;
get_obj_location
&nbsp;/*
&nbsp; * Return the object's physical location.  This only makes sense for
&nbsp; * objects that are currently on the level (i.e. migrating objects
&nbsp; * are nowhere).  By default, only things that can be seen (in hero's
&nbsp; * inventory, monster's inventory, or on the ground) are reported.
&nbsp; * By adding BURIED_TOO and/or CONTAINED_TOO flags, you can also get
&nbsp; * the location of buried and contained objects.  Note that if an
&nbsp; * object is carried by a monster, its reported position may change
&nbsp; * from turn to turn.  This function returns FALSE if the position
&nbsp; * is not available or subject to the constraints above.
&nbsp; */
&nbsp;boolean
&nbsp;get_obj_location(obj, xp, yp, locflags)
&nbsp;struct obj *obj;
&nbsp;xchar *xp, *yp;
&nbsp;int locflags;
&nbsp;{
&nbsp;    switch (obj-&gt;where) {
&nbsp;    case OBJ_INVENT:
&nbsp;        *xp = u.ux;
&nbsp;        *yp = u.uy;
&nbsp;        return TRUE;
&nbsp;    case OBJ_FLOOR:
&nbsp;        *xp = obj-&gt;ox;
&nbsp;        *yp = obj-&gt;oy;
&nbsp;        return TRUE;
&nbsp;    case OBJ_MINVENT:
&nbsp;        if (obj-&gt;ocarry-&gt;mx) {
&nbsp;            *xp = obj-&gt;ocarry-&gt;mx;
&nbsp;            *yp = obj-&gt;ocarry-&gt;my;
&nbsp;            return TRUE;
&nbsp;        }
&nbsp;        break; /* !mx =&gt; migrating monster */
&nbsp;    case OBJ_BURIED:
&nbsp;        if (locflags &amp; BURIED_TOO) {
&nbsp;            *xp = obj-&gt;ox;
&nbsp;            *yp = obj-&gt;oy;
&nbsp;            return TRUE;
&nbsp;        }
&nbsp;        break;
&nbsp;    case OBJ_CONTAINED:
&nbsp;        if (locflags &amp; CONTAINED_TOO)
&nbsp;            return get_obj_location(obj-&gt;ocontainer, xp, yp, locflags);
&nbsp;        break;
&nbsp;    }
&nbsp;    *xp = *yp = 0;
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
get_mon_location
&nbsp;boolean
&nbsp;get_mon_location(mon, xp, yp, locflags)
&nbsp;struct monst *mon;
&nbsp;xchar *xp, *yp;
&nbsp;int locflags; /* non-zero means get location even if monster is buried */
&nbsp;{
&nbsp;    if (mon == &amp;youmonst) {
&nbsp;        *xp = u.ux;
&nbsp;        *yp = u.uy;
&nbsp;        return TRUE;
&nbsp;    } else if (mon-&gt;mx &gt; 0 &amp;&amp; (!mon-&gt;mburied || locflags)) {
&nbsp;        *xp = mon-&gt;mx;
&nbsp;        *yp = mon-&gt;my;
&nbsp;        return TRUE;
&nbsp;    } else { /* migrating or buried */
&nbsp;        *xp = *yp = 0;
&nbsp;        return FALSE;
&nbsp;    }
&nbsp;}
&nbsp;
montraits
&nbsp;/* used by revive() and animate_statue() */
&nbsp;struct monst *
&nbsp;montraits(obj, cc)
&nbsp;struct obj *obj;
&nbsp;coord *cc;
&nbsp;{
&nbsp;    struct monst *mtmp = (struct monst *) 0;
&nbsp;    struct monst *mtmp2 = (struct monst *) 0;
&nbsp;
&nbsp;    if (has_omonst(obj))
&nbsp;        mtmp2 = get_mtraits(obj, TRUE);
&nbsp;    if (mtmp2) {
&nbsp;        /* save_mtraits() validated mtmp2-&gt;mnum */
&nbsp;        mtmp2-&gt;data = &amp;mons[mtmp2-&gt;mnum];
&nbsp;        if (mtmp2-&gt;mhpmax &lt;= 0 &amp;&amp; !is_rider(mtmp2-&gt;data))
&nbsp;            return (struct monst *) 0;
&nbsp;        mtmp = makemon(mtmp2-&gt;data, cc-&gt;x, cc-&gt;y,
&nbsp;                       NO_MINVENT | MM_NOWAIT | MM_NOCOUNTBIRTH);
&nbsp;        if (!mtmp)
&nbsp;            return mtmp;
&nbsp;
&nbsp;        /* heal the monster */
&nbsp;        if (mtmp-&gt;mhpmax &gt; mtmp2-&gt;mhpmax &amp;&amp; is_rider(mtmp2-&gt;data))
&nbsp;            mtmp2-&gt;mhpmax = mtmp-&gt;mhpmax;
&nbsp;        mtmp2-&gt;mhp = mtmp2-&gt;mhpmax;
&nbsp;        /* Get these ones from mtmp */
&nbsp;        mtmp2-&gt;minvent = mtmp-&gt;minvent; /*redundant*/
&nbsp;        /* monster ID is available if the monster died in the current
&nbsp;           game, but will be zero if the corpse was in a bones level
&nbsp;           (we cleared it when loading bones) */
&nbsp;        if (mtmp-&gt;m_id) {
&nbsp;            mtmp2-&gt;m_id = mtmp-&gt;m_id;
&nbsp;            /* might be bringing quest leader back to life */
&nbsp;            if (quest_status.leader_is_dead
&nbsp;                /* leader_is_dead implies leader_m_id is valid */
&nbsp;                &amp;&amp; mtmp2-&gt;m_id == quest_status.leader_m_id)
&nbsp;                quest_status.leader_is_dead = FALSE;
&nbsp;        }
&nbsp;        mtmp2-&gt;mx = mtmp-&gt;mx;
&nbsp;        mtmp2-&gt;my = mtmp-&gt;my;
&nbsp;        mtmp2-&gt;mux = mtmp-&gt;mux;
&nbsp;        mtmp2-&gt;muy = mtmp-&gt;muy;
&nbsp;        mtmp2-&gt;mw = mtmp-&gt;mw;
&nbsp;        mtmp2-&gt;wormno = mtmp-&gt;wormno;
&nbsp;        mtmp2-&gt;misc_worn_check = mtmp-&gt;misc_worn_check;
&nbsp;        mtmp2-&gt;weapon_check = mtmp-&gt;weapon_check;
&nbsp;        mtmp2-&gt;mtrapseen = mtmp-&gt;mtrapseen;
&nbsp;        mtmp2-&gt;mflee = mtmp-&gt;mflee;
&nbsp;        mtmp2-&gt;mburied = mtmp-&gt;mburied;
&nbsp;        mtmp2-&gt;mundetected = mtmp-&gt;mundetected;
&nbsp;        mtmp2-&gt;mfleetim = mtmp-&gt;mfleetim;
&nbsp;        mtmp2-&gt;mlstmv = mtmp-&gt;mlstmv;
&nbsp;        mtmp2-&gt;m_ap_type = mtmp-&gt;m_ap_type;
&nbsp;        /* set these ones explicitly */
&nbsp;        mtmp2-&gt;mrevived = 1;
&nbsp;        mtmp2-&gt;mavenge = 0;
&nbsp;        mtmp2-&gt;meating = 0;
&nbsp;        mtmp2-&gt;mleashed = 0;
&nbsp;        mtmp2-&gt;mtrapped = 0;
&nbsp;        mtmp2-&gt;msleeping = 0;
&nbsp;        mtmp2-&gt;mfrozen = 0;
&nbsp;        mtmp2-&gt;mcanmove = 1;
&nbsp;        /* most cancelled monsters return to normal,
&nbsp;           but some need to stay cancelled */
&nbsp;        if (!dmgtype(mtmp2-&gt;data, AD_SEDU)
&nbsp;            &amp;&amp; (!SYSOPT_SEDUCE || !dmgtype(mtmp2-&gt;data, AD_SSEX)))
&nbsp;            mtmp2-&gt;mcan = 0;
&nbsp;        mtmp2-&gt;mcansee = 1; /* set like in makemon */
&nbsp;        mtmp2-&gt;mblinded = 0;
&nbsp;        mtmp2-&gt;mstun = 0;
&nbsp;        mtmp2-&gt;mconf = 0;
&nbsp;        /* when traits are for a shopeekper, dummy monster 'mtmp' won't
&nbsp;           have necessary eshk data for replmon() -&gt; replshk() */
&nbsp;        if (mtmp2-&gt;isshk) {
&nbsp;            neweshk(mtmp);
&nbsp;            *ESHK(mtmp) = *ESHK(mtmp2);
&nbsp;            if (ESHK(mtmp2)-&gt;bill_p != 0
&nbsp;                &amp;&amp; ESHK(mtmp2)-&gt;bill_p != (struct bill_x *) -1000)
&nbsp;                ESHK(mtmp)-&gt;bill_p = &amp;(ESHK(mtmp)-&gt;bill[0]);
&nbsp;            mtmp-&gt;isshk = 1;
&nbsp;        }
&nbsp;        replmon(mtmp, mtmp2);
&nbsp;        newsym(mtmp2-&gt;mx, mtmp2-&gt;my); /* Might now be invisible */
&nbsp;
&nbsp;        /* in case Protection_from_shape_changers is different
&nbsp;           now than it was when the traits were stored */
&nbsp;        restore_cham(mtmp2);
&nbsp;    }
&nbsp;    return mtmp2;
&nbsp;}
&nbsp;
get_container_location
&nbsp;/*
&nbsp; * get_container_location() returns the following information
&nbsp; * about the outermost container:
&nbsp; * loc argument gets set to:
&nbsp; *      OBJ_INVENT      if in hero's inventory; return 0.
&nbsp; *      OBJ_FLOOR       if on the floor; return 0.
&nbsp; *      OBJ_BURIED      if buried; return 0.
&nbsp; *      OBJ_MINVENT     if in monster's inventory; return monster.
&nbsp; * container_nesting is updated with the nesting depth of the containers
&nbsp; * if applicable.
&nbsp; */
&nbsp;struct monst *
&nbsp;get_container_location(obj, loc, container_nesting)
&nbsp;struct obj *obj;
&nbsp;int *loc;
&nbsp;int *container_nesting;
&nbsp;{
&nbsp;    if (!obj || !loc)
&nbsp;        return 0;
&nbsp;
&nbsp;    if (container_nesting)
&nbsp;        *container_nesting = 0;
&nbsp;    while (obj &amp;&amp; obj-&gt;where == OBJ_CONTAINED) {
&nbsp;        if (container_nesting)
&nbsp;            *container_nesting += 1;
&nbsp;        obj = obj-&gt;ocontainer;
&nbsp;    }
&nbsp;    if (obj) {
&nbsp;        *loc = obj-&gt;where; /* outermost container's location */
&nbsp;        if (obj-&gt;where == OBJ_MINVENT)
&nbsp;            return obj-&gt;ocarry;
&nbsp;    }
&nbsp;    return (struct monst *) 0;
&nbsp;}
&nbsp;
revive
&nbsp;/*
&nbsp; * Attempt to revive the given corpse, return the revived monster if
&nbsp; * successful.  Note: this does NOT use up the corpse if it fails.
&nbsp; * If corpse-&gt;quan is more than 1, only one corpse will be affected
&nbsp; * and only one monster will be resurrected.
&nbsp; */
&nbsp;struct monst *
&nbsp;revive(corpse, by_hero)
&nbsp;struct obj *corpse;
&nbsp;boolean by_hero;
&nbsp;{
&nbsp;    struct monst *mtmp = 0;
&nbsp;    struct permonst *mptr;
&nbsp;    struct obj *container;
&nbsp;    coord xy;
&nbsp;    xchar x, y;
&nbsp;    boolean one_of;
&nbsp;    int montype, container_nesting = 0;
&nbsp;
&nbsp;    if (corpse-&gt;otyp != CORPSE) {
&nbsp;        impossible("Attempting to revive %s?", xname(corpse));
&nbsp;        return (struct monst *) 0;
&nbsp;    }
&nbsp;
&nbsp;    x = y = 0;
&nbsp;    if (corpse-&gt;where != OBJ_CONTAINED) {
&nbsp;        /* only for invent, minvent, or floor */
&nbsp;        container = 0;
&nbsp;        (void) get_obj_location(corpse, &amp;x, &amp;y, 0);
&nbsp;    } else {
&nbsp;        /* deal with corpses in [possibly nested] containers */
&nbsp;        struct monst *carrier;
&nbsp;        int holder = OBJ_FREE;
&nbsp;
&nbsp;        container = corpse-&gt;ocontainer;
&nbsp;        carrier =
&nbsp;            get_container_location(container, &amp;holder, &amp;container_nesting);
&nbsp;        switch (holder) {
&nbsp;        case OBJ_MINVENT:
&nbsp;            x = carrier-&gt;mx, y = carrier-&gt;my;
&nbsp;            break;
&nbsp;        case OBJ_INVENT:
&nbsp;            x = u.ux, y = u.uy;
&nbsp;            break;
&nbsp;        case OBJ_FLOOR:
&nbsp;            (void) get_obj_location(corpse, &amp;x, &amp;y, CONTAINED_TOO);
&nbsp;            break;
&nbsp;        default:
&nbsp;            break; /* x,y are 0 */
&nbsp;        }
&nbsp;    }
&nbsp;    if (!x || !y
&nbsp;        /* Rules for revival from containers:
&nbsp;         *  - the container cannot be locked
&nbsp;         *  - the container cannot be heavily nested (&gt;2 is arbitrary)
&nbsp;         *  - the container cannot be a statue or bag of holding
&nbsp;         *    (except in very rare cases for the latter)
&nbsp;         */
&nbsp;        || (container &amp;&amp; (container-&gt;olocked || container_nesting &gt; 2
&nbsp;                          || container-&gt;otyp == STATUE
&nbsp;                          || (container-&gt;otyp == BAG_OF_HOLDING &amp;&amp; rn2(40)))))
&nbsp;        return (struct monst *) 0;
&nbsp;
&nbsp;    /* record the object's location now that we're sure where it is */
&nbsp;    corpse-&gt;ox = x, corpse-&gt;oy = y;
&nbsp;
&nbsp;    /* prepare for the monster */
&nbsp;    montype = corpse-&gt;corpsenm;
&nbsp;    mptr = &amp;mons[montype];
&nbsp;    /* [should probably handle recorporealization first; if corpse and
&nbsp;       ghost are at same location, revived creature shouldn't be bumped
&nbsp;       to an adjacent spot by ghost which joins with it] */
&nbsp;    if (MON_AT(x, y)) {
&nbsp;        if (enexto(&amp;xy, x, y, mptr))
&nbsp;            x = xy.x, y = xy.y;
&nbsp;    }
&nbsp;
&nbsp;    if ((mons[montype].mlet == S_EEL &amp;&amp; !IS_POOL(levl[x][y].typ))
&nbsp;        || (mons[montype].mlet == S_TROLL
&nbsp;            &amp;&amp; uwep &amp;&amp; uwep-&gt;oartifact == ART_TROLLSBANE)) {
&nbsp;        if (by_hero &amp;&amp; cansee(x,y))
&nbsp;            pline("%s twitches feebly.",
&nbsp;                upstart(corpse_xname(corpse, (const char *) 0, CXN_PFX_THE)));
&nbsp;        return (struct monst *) 0;
&nbsp;    }
&nbsp;
&nbsp;    if (cant_revive(&amp;montype, TRUE, corpse)) {
&nbsp;        /* make a zombie or doppelganger instead */
&nbsp;        /* note: montype has changed; mptr keeps old value for newcham() */
&nbsp;        mtmp = makemon(&amp;mons[montype], x, y, NO_MINVENT | MM_NOWAIT);
&nbsp;        if (mtmp) {
&nbsp;            /* skip ghost handling */
&nbsp;            if (has_omid(corpse))
&nbsp;                free_omid(corpse);
&nbsp;            if (has_omonst(corpse))
&nbsp;                free_omonst(corpse);
&nbsp;            if (mtmp-&gt;cham == PM_DOPPELGANGER) {
&nbsp;                /* change shape to match the corpse */
&nbsp;                (void) newcham(mtmp, mptr, FALSE, FALSE);
&nbsp;            } else if (mtmp-&gt;data-&gt;mlet == S_ZOMBIE) {
&nbsp;                mtmp-&gt;mhp = mtmp-&gt;mhpmax = 100;
&nbsp;                mon_adjust_speed(mtmp, 2, (struct obj *) 0); /* MFAST */
&nbsp;            }
&nbsp;        }
&nbsp;    } else if (has_omonst(corpse)) {
&nbsp;        /* use saved traits */
&nbsp;        xy.x = x, xy.y = y;
&nbsp;        mtmp = montraits(corpse, &amp;xy);
&nbsp;        if (mtmp &amp;&amp; mtmp-&gt;mtame &amp;&amp; !mtmp-&gt;isminion)
&nbsp;            wary_dog(mtmp, TRUE);
&nbsp;    } else {
&nbsp;        /* make a new monster */
&nbsp;        mtmp = makemon(mptr, x, y, NO_MINVENT | MM_NOWAIT | MM_NOCOUNTBIRTH);
&nbsp;    }
&nbsp;    if (!mtmp)
&nbsp;        return (struct monst *) 0;
&nbsp;
&nbsp;    /* hiders shouldn't already be re-hidden when they revive */
&nbsp;    if (mtmp-&gt;mundetected) {
&nbsp;        mtmp-&gt;mundetected = 0;
&nbsp;        newsym(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;    }
&nbsp;    if (mtmp-&gt;m_ap_type)
&nbsp;        seemimic(mtmp);
&nbsp;
&nbsp;    one_of = (corpse-&gt;quan &gt; 1L);
&nbsp;    if (one_of)
&nbsp;        corpse = splitobj(corpse, 1L);
&nbsp;
&nbsp;    /* if this is caused by the hero there might be a shop charge */
&nbsp;    if (by_hero) {
&nbsp;        struct monst *shkp = 0;
&nbsp;
&nbsp;        x = corpse-&gt;ox, y = corpse-&gt;oy;
&nbsp;        if (costly_spot(x, y)
&nbsp;            &amp;&amp; (carried(corpse) ? corpse-&gt;unpaid : !corpse-&gt;no_charge))
&nbsp;            shkp = shop_keeper(*in_rooms(x, y, SHOPBASE));
&nbsp;
&nbsp;        if (cansee(x, y)) {
&nbsp;            char buf[BUFSZ];
&nbsp;            unsigned pfx = CXN_PFX_THE;
&nbsp;
&nbsp;            Strcpy(buf, one_of ? "one of " : "");
&nbsp;            if (carried(corpse) &amp;&amp; !corpse-&gt;unpaid) {
&nbsp;                Strcat(buf, "your ");
&nbsp;                pfx = CXN_NO_PFX;
&nbsp;            }
&nbsp;            if (one_of)
&nbsp;                corpse-&gt;quan++; /* force plural */
&nbsp;            Strcat(buf, corpse_xname(corpse, (const char *) 0, pfx));
&nbsp;            if (one_of) /* could be simplified to ''corpse-&gt;quan = 1L;'' */
&nbsp;                corpse-&gt;quan--;
&nbsp;            pline("%s glows iridescently.", upstart(buf));
&nbsp;        } else if (shkp) {
&nbsp;            /* need some prior description of the corpse since
&nbsp;               stolen_value() will refer to the object as "it" */
&nbsp;            pline("A corpse is resuscitated.");
&nbsp;        }
&nbsp;        /* don't charge for shopkeeper's own corpse if we just revived him */
&nbsp;        if (shkp &amp;&amp; mtmp != shkp)
&nbsp;            (void) stolen_value(corpse, x, y, (boolean) shkp-&gt;mpeaceful,
&nbsp;                                FALSE);
&nbsp;
&nbsp;        /* [we don't give any comparable message about the corpse for
&nbsp;           the !by_hero case because caller might have already done so] */
&nbsp;    }
&nbsp;
&nbsp;    /* handle recorporealization of an active ghost */
&nbsp;    if (has_omid(corpse)) {
&nbsp;        unsigned m_id;
&nbsp;        struct monst *ghost;
&nbsp;        struct obj *otmp;
&nbsp;
&nbsp;        (void) memcpy((genericptr_t) &amp;m_id, (genericptr_t) OMID(corpse),
&nbsp;                      sizeof m_id);
&nbsp;        ghost = find_mid(m_id, FM_FMON);
&nbsp;        if (ghost &amp;&amp; ghost-&gt;data == &amp;mons[PM_GHOST]) {
&nbsp;            if (canseemon(ghost))
&nbsp;                pline("%s is suddenly drawn into its former body!",
&nbsp;                      Monnam(ghost));
&nbsp;            /* transfer the ghost's inventory along with it */
&nbsp;            while ((otmp = ghost-&gt;minvent) != 0) {
&nbsp;                obj_extract_self(otmp);
&nbsp;                add_to_minv(mtmp, otmp);
&nbsp;            }
&nbsp;            /* tame the revived monster if its ghost was tame */
&nbsp;            if (ghost-&gt;mtame &amp;&amp; !mtmp-&gt;mtame) {
&nbsp;                if (tamedog(mtmp, (struct obj *) 0)) {
&nbsp;                    /* ghost's edog data is ignored */
&nbsp;                    mtmp-&gt;mtame = ghost-&gt;mtame;
&nbsp;                }
&nbsp;            }
&nbsp;            /* was ghost, now alive, it's all very confusing */
&nbsp;            mtmp-&gt;mconf = 1;
&nbsp;            /* separate ghost monster no longer exists */
&nbsp;            mongone(ghost);
&nbsp;        }
&nbsp;        free_omid(corpse);
&nbsp;    }
&nbsp;
&nbsp;    /* monster retains its name */
&nbsp;    if (has_oname(corpse) &amp;&amp; !unique_corpstat(mtmp-&gt;data))
&nbsp;        mtmp = christen_monst(mtmp, ONAME(corpse));
&nbsp;    /* partially eaten corpse yields wounded monster */
&nbsp;    if (corpse-&gt;oeaten)
&nbsp;        mtmp-&gt;mhp = eaten_stat(mtmp-&gt;mhp, corpse);
&nbsp;    /* track that this monster was revived at least once */
&nbsp;    mtmp-&gt;mrevived = 1;
&nbsp;
&nbsp;    /* finally, get rid of the corpse--it's gone now */
&nbsp;    switch (corpse-&gt;where) {
&nbsp;    case OBJ_INVENT:
&nbsp;        useup(corpse);
&nbsp;        break;
&nbsp;    case OBJ_FLOOR:
&nbsp;        /* in case MON_AT+enexto for invisible mon */
&nbsp;        x = corpse-&gt;ox, y = corpse-&gt;oy;
&nbsp;        /* not useupf(), which charges */
&nbsp;        if (corpse-&gt;quan &gt; 1L)
&nbsp;            corpse = splitobj(corpse, 1L);
&nbsp;        delobj(corpse);
&nbsp;        newsym(x, y);
&nbsp;        break;
&nbsp;    case OBJ_MINVENT:
&nbsp;        m_useup(corpse-&gt;ocarry, corpse);
&nbsp;        break;
&nbsp;    case OBJ_CONTAINED:
&nbsp;        obj_extract_self(corpse);
&nbsp;        obfree(corpse, (struct obj *) 0);
&nbsp;        break;
&nbsp;    default:
&nbsp;        panic("revive");
&nbsp;    }
&nbsp;
&nbsp;    return mtmp;
&nbsp;}
&nbsp;
revive_egg
&nbsp;STATIC_OVL void
&nbsp;revive_egg(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    /*
&nbsp;     * Note: generic eggs with corpsenm set to NON_PM will never hatch.
&nbsp;     */
&nbsp;    if (obj-&gt;otyp != EGG)
&nbsp;        return;
&nbsp;    if (obj-&gt;corpsenm != NON_PM &amp;&amp; !dead_species(obj-&gt;corpsenm, TRUE))
&nbsp;        attach_egg_hatch_timeout(obj, 0L);
&nbsp;}
&nbsp;
unturn_dead
&nbsp;/* try to revive all corpses and eggs carried by `mon' */
&nbsp;int
&nbsp;unturn_dead(mon)
&nbsp;struct monst *mon;
&nbsp;{
&nbsp;    struct obj *otmp, *otmp2;
&nbsp;    struct monst *mtmp2;
&nbsp;    char owner[BUFSZ], corpse[BUFSZ];
&nbsp;    boolean youseeit;
&nbsp;    int res = 0;
&nbsp;
&nbsp;    youseeit = (mon == &amp;youmonst) ? TRUE : canseemon(mon);
&nbsp;    otmp2 = (mon == &amp;youmonst) ? invent : mon-&gt;minvent;
&nbsp;    owner[0] = corpse[0] = '\0'; /* lint suppression */
&nbsp;
&nbsp;    while ((otmp = otmp2) != 0) {
&nbsp;        otmp2 = otmp-&gt;nobj;
&nbsp;        if (otmp-&gt;otyp == EGG)
&nbsp;            revive_egg(otmp);
&nbsp;        if (otmp-&gt;otyp != CORPSE)
&nbsp;            continue;
&nbsp;        /* save the name; the object is liable to go away */
&nbsp;        if (youseeit) {
&nbsp;            Strcpy(corpse,
&nbsp;                   corpse_xname(otmp, (const char *) 0, CXN_SINGULAR));
&nbsp;            Shk_Your(owner, otmp); /* includes a trailing space */
&nbsp;        }
&nbsp;
&nbsp;        /* for a stack, only one is revived */
&nbsp;        if ((mtmp2 = revive(otmp, !context.mon_moving)) != 0) {
&nbsp;            ++res;
&nbsp;            if (youseeit)
&nbsp;                pline("%s%s suddenly comes alive!", owner, corpse);
&nbsp;            else if (canseemon(mtmp2))
&nbsp;                pline("%s suddenly appears!", Amonnam(mtmp2));
&nbsp;        }
&nbsp;    }
&nbsp;    return res;
&nbsp;}
&nbsp;
cancel_item
&nbsp;/* cancel obj, possibly carried by you or a monster */
&nbsp;void
&nbsp;cancel_item(obj)
&nbsp;register struct obj *obj;
&nbsp;{
&nbsp;    boolean u_ring = (obj == uleft || obj == uright);
&nbsp;    int otyp = obj-&gt;otyp;
&nbsp;
&nbsp;    switch (otyp) {
&nbsp;    case RIN_GAIN_STRENGTH:
&nbsp;        if ((obj-&gt;owornmask &amp; W_RING) &amp;&amp; u_ring) {
&nbsp;            ABON(A_STR) -= obj-&gt;spe;
&nbsp;            context.botl = 1;
&nbsp;        }
&nbsp;        break;
&nbsp;    case RIN_GAIN_CONSTITUTION:
&nbsp;        if ((obj-&gt;owornmask &amp; W_RING) &amp;&amp; u_ring) {
&nbsp;            ABON(A_CON) -= obj-&gt;spe;
&nbsp;            context.botl = 1;
&nbsp;        }
&nbsp;        break;
&nbsp;    case RIN_ADORNMENT:
&nbsp;        if ((obj-&gt;owornmask &amp; W_RING) &amp;&amp; u_ring) {
&nbsp;            ABON(A_CHA) -= obj-&gt;spe;
&nbsp;            context.botl = 1;
&nbsp;        }
&nbsp;        break;
&nbsp;    case RIN_INCREASE_ACCURACY:
&nbsp;        if ((obj-&gt;owornmask &amp; W_RING) &amp;&amp; u_ring)
&nbsp;            u.uhitinc -= obj-&gt;spe;
&nbsp;        break;
&nbsp;    case RIN_INCREASE_DAMAGE:
&nbsp;        if ((obj-&gt;owornmask &amp; W_RING) &amp;&amp; u_ring)
&nbsp;            u.udaminc -= obj-&gt;spe;
&nbsp;        break;
&nbsp;    case GAUNTLETS_OF_DEXTERITY:
&nbsp;        if ((obj-&gt;owornmask &amp; W_ARMG) &amp;&amp; (obj == uarmg)) {
&nbsp;            ABON(A_DEX) -= obj-&gt;spe;
&nbsp;            context.botl = 1;
&nbsp;        }
&nbsp;        break;
&nbsp;    case HELM_OF_BRILLIANCE:
&nbsp;        if ((obj-&gt;owornmask &amp; W_ARMH) &amp;&amp; (obj == uarmh)) {
&nbsp;            ABON(A_INT) -= obj-&gt;spe;
&nbsp;            ABON(A_WIS) -= obj-&gt;spe;
&nbsp;            context.botl = 1;
&nbsp;        }
&nbsp;        break;
&nbsp;        /* case RIN_PROTECTION:  not needed */
&nbsp;    }
&nbsp;    if (objects[otyp].oc_magic
&nbsp;        || (obj-&gt;spe &amp;&amp; (obj-&gt;oclass == ARMOR_CLASS
&nbsp;                         || obj-&gt;oclass == WEAPON_CLASS || is_weptool(obj)))
&nbsp;        || otyp == POT_ACID
&nbsp;        || otyp == POT_SICKNESS
&nbsp;        || (otyp == POT_WATER &amp;&amp; (obj-&gt;blessed || obj-&gt;cursed))) {
&nbsp;        if (obj-&gt;spe != ((obj-&gt;oclass == WAND_CLASS) ? -1 : 0)
&nbsp;            &amp;&amp; otyp != WAN_CANCELLATION /* can't cancel cancellation */
&nbsp;            &amp;&amp; otyp != MAGIC_LAMP /* cancelling doesn't remove djinni */
&nbsp;            &amp;&amp; otyp != CANDELABRUM_OF_INVOCATION) {
&nbsp;            costly_alteration(obj, COST_CANCEL);
&nbsp;            obj-&gt;spe = (obj-&gt;oclass == WAND_CLASS) ? -1 : 0;
&nbsp;        }
&nbsp;        switch (obj-&gt;oclass) {
&nbsp;        case SCROLL_CLASS:
&nbsp;            costly_alteration(obj, COST_CANCEL);
&nbsp;            obj-&gt;otyp = SCR_BLANK_PAPER;
&nbsp;            obj-&gt;spe = 0;
&nbsp;            break;
&nbsp;        case SPBOOK_CLASS:
&nbsp;            if (otyp != SPE_CANCELLATION &amp;&amp; otyp != SPE_NOVEL
&nbsp;                &amp;&amp; otyp != SPE_BOOK_OF_THE_DEAD) {
&nbsp;                costly_alteration(obj, COST_CANCEL);
&nbsp;                obj-&gt;otyp = SPE_BLANK_PAPER;
&nbsp;            }
&nbsp;            break;
&nbsp;        case POTION_CLASS:
&nbsp;            costly_alteration(obj,
&nbsp;                              (otyp != POT_WATER)
&nbsp;                                  ? COST_CANCEL
&nbsp;                                  : obj-&gt;cursed ? COST_UNCURS : COST_UNBLSS);
&nbsp;            if (otyp == POT_SICKNESS || otyp == POT_SEE_INVISIBLE) {
&nbsp;                /* sickness is "biologically contaminated" fruit juice;
&nbsp;                   cancel it and it just becomes fruit juice...
&nbsp;                   whereas see invisible tastes like "enchanted" fruit
&nbsp;                   juice, it similarly cancels */
&nbsp;                obj-&gt;otyp = POT_FRUIT_JUICE;
&nbsp;            } else {
&nbsp;                obj-&gt;otyp = POT_WATER;
&nbsp;                obj-&gt;odiluted = 0; /* same as any other water */
&nbsp;            }
&nbsp;            break;
&nbsp;        }
&nbsp;    }
&nbsp;    unbless(obj);
&nbsp;    uncurse(obj);
&nbsp;    return;
&nbsp;}
&nbsp;
drain_item
&nbsp;/* Remove a positive enchantment or charge from obj,
&nbsp; * possibly carried by you or a monster
&nbsp; */
&nbsp;boolean
&nbsp;drain_item(obj, by_you)
&nbsp;struct obj *obj;
&nbsp;boolean by_you;
&nbsp;{
&nbsp;    boolean u_ring;
&nbsp;
&nbsp;    /* Is this a charged/enchanted object? */
&nbsp;    if (!obj
&nbsp;        || (!objects[obj-&gt;otyp].oc_charged &amp;&amp; obj-&gt;oclass != WEAPON_CLASS
&nbsp;            &amp;&amp; obj-&gt;oclass != ARMOR_CLASS &amp;&amp; !is_weptool(obj))
&nbsp;        || obj-&gt;spe &lt;= 0)
&nbsp;        return FALSE;
&nbsp;    if (defends(AD_DRLI, obj) || defends_when_carried(AD_DRLI, obj)
&nbsp;        || obj_resists(obj, 10, 90))
&nbsp;        return FALSE;
&nbsp;
&nbsp;    /* Charge for the cost of the object */
&nbsp;    if (by_you)
&nbsp;        costly_alteration(obj, COST_DRAIN);
&nbsp;
&nbsp;    /* Drain the object and any implied effects */
&nbsp;    obj-&gt;spe--;
&nbsp;    u_ring = (obj == uleft) || (obj == uright);
&nbsp;    switch (obj-&gt;otyp) {
&nbsp;    case RIN_GAIN_STRENGTH:
&nbsp;        if ((obj-&gt;owornmask &amp; W_RING) &amp;&amp; u_ring) {
&nbsp;            ABON(A_STR)--;
&nbsp;            context.botl = 1;
&nbsp;        }
&nbsp;        break;
&nbsp;    case RIN_GAIN_CONSTITUTION:
&nbsp;        if ((obj-&gt;owornmask &amp; W_RING) &amp;&amp; u_ring) {
&nbsp;            ABON(A_CON)--;
&nbsp;            context.botl = 1;
&nbsp;        }
&nbsp;        break;
&nbsp;    case RIN_ADORNMENT:
&nbsp;        if ((obj-&gt;owornmask &amp; W_RING) &amp;&amp; u_ring) {
&nbsp;            ABON(A_CHA)--;
&nbsp;            context.botl = 1;
&nbsp;        }
&nbsp;        break;
&nbsp;    case RIN_INCREASE_ACCURACY:
&nbsp;        if ((obj-&gt;owornmask &amp; W_RING) &amp;&amp; u_ring)
&nbsp;            u.uhitinc--;
&nbsp;        break;
&nbsp;    case RIN_INCREASE_DAMAGE:
&nbsp;        if ((obj-&gt;owornmask &amp; W_RING) &amp;&amp; u_ring)
&nbsp;            u.udaminc--;
&nbsp;        break;
&nbsp;    case RIN_PROTECTION:
&nbsp;        if (u_ring)
&nbsp;            context.botl = 1; /* bot() will recalc u.uac */
&nbsp;        break;
&nbsp;    case HELM_OF_BRILLIANCE:
&nbsp;        if ((obj-&gt;owornmask &amp; W_ARMH) &amp;&amp; (obj == uarmh)) {
&nbsp;            ABON(A_INT)--;
&nbsp;            ABON(A_WIS)--;
&nbsp;            context.botl = 1;
&nbsp;        }
&nbsp;        break;
&nbsp;    case GAUNTLETS_OF_DEXTERITY:
&nbsp;        if ((obj-&gt;owornmask &amp; W_ARMG) &amp;&amp; (obj == uarmg)) {
&nbsp;            ABON(A_DEX)--;
&nbsp;            context.botl = 1;
&nbsp;        }
&nbsp;        break;
&nbsp;    default:
&nbsp;        break;
&nbsp;    }
&nbsp;    if (context.botl)
&nbsp;        bot();
&nbsp;    if (carried(obj))
&nbsp;        update_inventory();
&nbsp;    return TRUE;
&nbsp;}
&nbsp;
obj_resists
&nbsp;boolean
&nbsp;obj_resists(obj, ochance, achance)
&nbsp;struct obj *obj;
&nbsp;int ochance, achance; /* percent chance for ordinary objects, artifacts */
&nbsp;{
&nbsp;    if (obj-&gt;otyp == AMULET_OF_YENDOR
&nbsp;        || obj-&gt;otyp == SPE_BOOK_OF_THE_DEAD
&nbsp;        || obj-&gt;otyp == CANDELABRUM_OF_INVOCATION
&nbsp;        || obj-&gt;otyp == BELL_OF_OPENING
&nbsp;        || (obj-&gt;otyp == CORPSE &amp;&amp; is_rider(&amp;mons[obj-&gt;corpsenm]))) {
&nbsp;        return TRUE;
&nbsp;    } else {
&nbsp;        int chance = rn2(100);
&nbsp;
&nbsp;        return (boolean) (chance &lt; (obj-&gt;oartifact ? achance : ochance));
&nbsp;    }
&nbsp;}
&nbsp;
obj_shudders
&nbsp;boolean
&nbsp;obj_shudders(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    int zap_odds;
&nbsp;
&nbsp;    if (context.bypasses &amp;&amp; obj-&gt;bypass)
&nbsp;        return FALSE;
&nbsp;
&nbsp;    if (obj-&gt;oclass == WAND_CLASS)
&nbsp;        zap_odds = 3; /* half-life = 2 zaps */
&nbsp;    else if (obj-&gt;cursed)
&nbsp;        zap_odds = 3; /* half-life = 2 zaps */
&nbsp;    else if (obj-&gt;blessed)
&nbsp;        zap_odds = 12; /* half-life = 8 zaps */
&nbsp;    else
&nbsp;        zap_odds = 8; /* half-life = 6 zaps */
&nbsp;
&nbsp;    /* adjust for "large" quantities of identical things */
&nbsp;    if (obj-&gt;quan &gt; 4L)
&nbsp;        zap_odds /= 2;
&nbsp;
&nbsp;    return (boolean) !rn2(zap_odds);
&nbsp;}
&nbsp;
polyuse
&nbsp;/* Use up at least minwt number of things made of material mat.
&nbsp; * There's also a chance that other stuff will be used up.  Finally,
&nbsp; * there's a random factor here to keep from always using the stuff
&nbsp; * at the top of the pile.
&nbsp; */
&nbsp;STATIC_OVL void
&nbsp;polyuse(objhdr, mat, minwt)
&nbsp;struct obj *objhdr;
&nbsp;int mat, minwt;
&nbsp;{
&nbsp;    register struct obj *otmp, *otmp2;
&nbsp;
&nbsp;    for (otmp = objhdr; minwt &gt; 0 &amp;&amp; otmp; otmp = otmp2) {
&nbsp;        otmp2 = otmp-&gt;nexthere;
&nbsp;        if (context.bypasses &amp;&amp; otmp-&gt;bypass)
&nbsp;            continue;
&nbsp;        if (otmp == uball || otmp == uchain)
&nbsp;            continue;
&nbsp;        if (obj_resists(otmp, 0, 0))
&nbsp;            continue; /* preserve unique objects */
&nbsp;#ifdef MAIL
&nbsp;        if (otmp-&gt;otyp == SCR_MAIL)
&nbsp;            continue;
&nbsp;#endif
&nbsp;
&nbsp;        if (((int) objects[otmp-&gt;otyp].oc_material == mat)
&nbsp;            == (rn2(minwt + 1) != 0)) {
&nbsp;            /* appropriately add damage to bill */
&nbsp;            if (costly_spot(otmp-&gt;ox, otmp-&gt;oy)) {
&nbsp;                if (*u.ushops)
&nbsp;                    addtobill(otmp, FALSE, FALSE, FALSE);
&nbsp;                else
&nbsp;                    (void) stolen_value(otmp, otmp-&gt;ox, otmp-&gt;oy, FALSE,
&nbsp;                                        FALSE);
&nbsp;            }
&nbsp;            if (otmp-&gt;quan &lt; LARGEST_INT)
&nbsp;                minwt -= (int) otmp-&gt;quan;
&nbsp;            else
&nbsp;                minwt = 0;
&nbsp;            delobj(otmp);
&nbsp;        }
&nbsp;    }
&nbsp;}
&nbsp;
create_polymon
&nbsp;/*
&nbsp; * Polymorph some of the stuff in this pile into a monster, preferably
&nbsp; * a golem of the kind okind.
&nbsp; */
&nbsp;STATIC_OVL void
&nbsp;create_polymon(obj, okind)
&nbsp;struct obj *obj;
&nbsp;int okind;
&nbsp;{
&nbsp;    struct permonst *mdat = (struct permonst *) 0;
&nbsp;    struct monst *mtmp;
&nbsp;    const char *material;
&nbsp;    int pm_index;
&nbsp;
&nbsp;    if (context.bypasses) {
&nbsp;        /* this is approximate because the "no golems" !obj-&gt;nexthere
&nbsp;           check below doesn't understand bypassed objects; but it
&nbsp;           should suffice since bypassed objects always end up as a
&nbsp;           consecutive group at the top of their pile */
&nbsp;        while (obj &amp;&amp; obj-&gt;bypass)
&nbsp;            obj = obj-&gt;nexthere;
&nbsp;    }
&nbsp;
&nbsp;    /* no golems if you zap only one object -- not enough stuff */
&nbsp;    if (!obj || (!obj-&gt;nexthere &amp;&amp; obj-&gt;quan == 1L))
&nbsp;        return;
&nbsp;
&nbsp;    /* some of these choices are arbitrary */
&nbsp;    switch (okind) {
&nbsp;    case IRON:
&nbsp;    case METAL:
&nbsp;    case MITHRIL:
&nbsp;        pm_index = PM_IRON_GOLEM;
&nbsp;        material = "metal ";
&nbsp;        break;
&nbsp;    case COPPER:
&nbsp;    case SILVER:
&nbsp;    case PLATINUM:
&nbsp;    case GEMSTONE:
&nbsp;    case MINERAL:
&nbsp;        pm_index = rn2(2) ? PM_STONE_GOLEM : PM_CLAY_GOLEM;
&nbsp;        material = "lithic ";
&nbsp;        break;
&nbsp;    case 0:
&nbsp;    case FLESH:
&nbsp;        /* there is no flesh type, but all food is type 0, so we use it */
&nbsp;        pm_index = PM_FLESH_GOLEM;
&nbsp;        material = "organic ";
&nbsp;        break;
&nbsp;    case WOOD:
&nbsp;        pm_index = PM_WOOD_GOLEM;
&nbsp;        material = "wood ";
&nbsp;        break;
&nbsp;    case LEATHER:
&nbsp;        pm_index = PM_LEATHER_GOLEM;
&nbsp;        material = "leather ";
&nbsp;        break;
&nbsp;    case CLOTH:
&nbsp;        pm_index = PM_ROPE_GOLEM;
&nbsp;        material = "cloth ";
&nbsp;        break;
&nbsp;    case BONE:
&nbsp;        pm_index = PM_SKELETON; /* nearest thing to "bone golem" */
&nbsp;        material = "bony ";
&nbsp;        break;
&nbsp;    case GOLD:
&nbsp;        pm_index = PM_GOLD_GOLEM;
&nbsp;        material = "gold ";
&nbsp;        break;
&nbsp;    case GLASS:
&nbsp;        pm_index = PM_GLASS_GOLEM;
&nbsp;        material = "glassy ";
&nbsp;        break;
&nbsp;    case PAPER:
&nbsp;        pm_index = PM_PAPER_GOLEM;
&nbsp;        material = "paper ";
&nbsp;        break;
&nbsp;    default:
&nbsp;        /* if all else fails... */
&nbsp;        pm_index = PM_STRAW_GOLEM;
&nbsp;        material = "";
&nbsp;        break;
&nbsp;    }
&nbsp;
&nbsp;    if (!(mvitals[pm_index].mvflags &amp; G_GENOD))
&nbsp;        mdat = &amp;mons[pm_index];
&nbsp;
&nbsp;    mtmp = makemon(mdat, obj-&gt;ox, obj-&gt;oy, NO_MM_FLAGS);
&nbsp;    polyuse(obj, okind, (int) mons[pm_index].cwt);
&nbsp;
&nbsp;    if (mtmp &amp;&amp; cansee(mtmp-&gt;mx, mtmp-&gt;my)) {
&nbsp;        pline("Some %sobjects meld, and %s arises from the pile!", material,
&nbsp;              a_monnam(mtmp));
&nbsp;    }
&nbsp;}
&nbsp;
do_osshock
&nbsp;/* Assumes obj is on the floor. */
&nbsp;void
&nbsp;do_osshock(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    long i;
&nbsp;
&nbsp;#ifdef MAIL
&nbsp;    if (obj-&gt;otyp == SCR_MAIL)
&nbsp;        return;
&nbsp;#endif
&nbsp;    obj_zapped = TRUE;
&nbsp;
&nbsp;    if (poly_zapped &lt; 0) {
&nbsp;        /* some may metamorphosize */
&nbsp;        for (i = obj-&gt;quan; i; i--)
&nbsp;            if (!rn2(Luck + 45)) {
&nbsp;                poly_zapped = objects[obj-&gt;otyp].oc_material;
&nbsp;                break;
&nbsp;            }
&nbsp;    }
&nbsp;
&nbsp;    /* if quan &gt; 1 then some will survive intact */
&nbsp;    if (obj-&gt;quan &gt; 1L) {
&nbsp;        if (obj-&gt;quan &gt; LARGEST_INT)
&nbsp;            obj = splitobj(obj, (long) rnd(30000));
&nbsp;        else
&nbsp;            obj = splitobj(obj, (long) rnd((int) obj-&gt;quan - 1));
&nbsp;    }
&nbsp;
&nbsp;    /* appropriately add damage to bill */
&nbsp;    if (costly_spot(obj-&gt;ox, obj-&gt;oy)) {
&nbsp;        if (*u.ushops)
&nbsp;            addtobill(obj, FALSE, FALSE, FALSE);
&nbsp;        else
&nbsp;            (void) stolen_value(obj, obj-&gt;ox, obj-&gt;oy, FALSE, FALSE);
&nbsp;    }
&nbsp;
&nbsp;    /* zap the object */
&nbsp;    delobj(obj);
&nbsp;}
&nbsp;
&nbsp;/* classes of items whose current charge count carries over across polymorph
&nbsp; */
&nbsp;static const char charged_objs[] = { WAND_CLASS, WEAPON_CLASS, ARMOR_CLASS,
&nbsp;                                     '\0' };
&nbsp;
poly_obj
&nbsp;/*
&nbsp; * Polymorph the object to the given object ID.  If the ID is STRANGE_OBJECT
&nbsp; * then pick random object from the source's class (this is the standard
&nbsp; * "polymorph" case).  If ID is set to a specific object, inhibit fusing
&nbsp; * n objects into 1.  This could have been added as a flag, but currently
&nbsp; * it is tied to not being the standard polymorph case. The new polymorphed
&nbsp; * object replaces obj in its link chains.  Return value is a pointer to
&nbsp; * the new object.
&nbsp; *
&nbsp; * This should be safe to call for an object anywhere.
&nbsp; */
&nbsp;struct obj *
&nbsp;poly_obj(obj, id)
&nbsp;struct obj *obj;
&nbsp;int id;
&nbsp;{
&nbsp;    struct obj *otmp;
&nbsp;    xchar ox, oy;
&nbsp;    boolean can_merge = (id == STRANGE_OBJECT);
&nbsp;    int obj_location = obj-&gt;where;
&nbsp;
&nbsp;    if (obj-&gt;otyp == BOULDER)
&nbsp;        sokoban_guilt();
&nbsp;    if (id == STRANGE_OBJECT) { /* preserve symbol */
&nbsp;        int try_limit = 3;
&nbsp;        unsigned magic_obj = objects[obj-&gt;otyp].oc_magic;
&nbsp;
&nbsp;        if (obj-&gt;otyp == UNICORN_HORN &amp;&amp; obj-&gt;degraded_horn)
&nbsp;            magic_obj = 0;
&nbsp;        /* Try up to 3 times to make the magic-or-not status of
&nbsp;           the new item be the same as it was for the old one. */
&nbsp;        otmp = (struct obj *) 0;
&nbsp;        do {
&nbsp;            if (otmp)
&nbsp;                delobj(otmp);
&nbsp;            otmp = mkobj(obj-&gt;oclass, FALSE);
&nbsp;        } while (--try_limit &gt; 0
&nbsp;                 &amp;&amp; objects[otmp-&gt;otyp].oc_magic != magic_obj);
&nbsp;    } else {
&nbsp;        /* literally replace obj with this new thing */
&nbsp;        otmp = mksobj(id, FALSE, FALSE);
&nbsp;/* Actually more things use corpsenm but they polymorph differently */
&nbsp;#define USES_CORPSENM(typ) \
&nbsp;    ((typ) == CORPSE || (typ) == STATUE || (typ) == FIGURINE)
&nbsp;
&nbsp;        if (USES_CORPSENM(obj-&gt;otyp) &amp;&amp; USES_CORPSENM(id))
&nbsp;            set_corpsenm(otmp, obj-&gt;corpsenm);
&nbsp;#undef USES_CORPSENM
&nbsp;    }
&nbsp;
&nbsp;    /* preserve quantity */
&nbsp;    otmp-&gt;quan = obj-&gt;quan;
&nbsp;    /* preserve the shopkeepers (lack of) interest */
&nbsp;    otmp-&gt;no_charge = obj-&gt;no_charge;
&nbsp;    /* preserve inventory letter if in inventory */
&nbsp;    if (obj_location == OBJ_INVENT)
&nbsp;        otmp-&gt;invlet = obj-&gt;invlet;
&nbsp;#ifdef MAIL
&nbsp;    /* You can't send yourself 100 mail messages and then
&nbsp;     * polymorph them into useful scrolls
&nbsp;     */
&nbsp;    if (obj-&gt;otyp == SCR_MAIL) {
&nbsp;        otmp-&gt;otyp = SCR_MAIL;
&nbsp;        otmp-&gt;spe = 1;
&nbsp;    }
&nbsp;#endif
&nbsp;
&nbsp;    /* avoid abusing eggs laid by you */
&nbsp;    if (obj-&gt;otyp == EGG &amp;&amp; obj-&gt;spe) {
&nbsp;        int mnum, tryct = 100;
&nbsp;
&nbsp;        /* first, turn into a generic egg */
&nbsp;        if (otmp-&gt;otyp == EGG)
&nbsp;            kill_egg(otmp);
&nbsp;        else {
&nbsp;            otmp-&gt;otyp = EGG;
&nbsp;            otmp-&gt;owt = weight(otmp);
&nbsp;        }
&nbsp;        otmp-&gt;corpsenm = NON_PM;
&nbsp;        otmp-&gt;spe = 0;
&nbsp;
&nbsp;        /* now change it into something laid by the hero */
&nbsp;        while (tryct--) {
&nbsp;            mnum = can_be_hatched(random_monster());
&nbsp;            if (mnum != NON_PM &amp;&amp; !dead_species(mnum, TRUE)) {
&nbsp;                otmp-&gt;spe = 1;            /* laid by hero */
&nbsp;                set_corpsenm(otmp, mnum); /* also sets hatch timer */
&nbsp;                break;
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* keep special fields (including charges on wands) */
&nbsp;    if (index(charged_objs, otmp-&gt;oclass))
&nbsp;        otmp-&gt;spe = obj-&gt;spe;
&nbsp;    otmp-&gt;recharged = obj-&gt;recharged;
&nbsp;
&nbsp;    otmp-&gt;cursed = obj-&gt;cursed;
&nbsp;    otmp-&gt;blessed = obj-&gt;blessed;
&nbsp;
&nbsp;    if (erosion_matters(otmp)) {
&nbsp;        if (is_flammable(otmp) || is_rustprone(otmp))
&nbsp;            otmp-&gt;oeroded = obj-&gt;oeroded;
&nbsp;        if (is_corrodeable(otmp) || is_rottable(otmp))
&nbsp;            otmp-&gt;oeroded2 = obj-&gt;oeroded2;
&nbsp;        if (is_damageable(otmp))
&nbsp;            otmp-&gt;oerodeproof = obj-&gt;oerodeproof;
&nbsp;    }
&nbsp;
&nbsp;    /* Keep chest/box traps and poisoned ammo if we may */
&nbsp;    if (obj-&gt;otrapped &amp;&amp; Is_box(otmp))
&nbsp;        otmp-&gt;otrapped = TRUE;
&nbsp;
&nbsp;    if (obj-&gt;opoisoned &amp;&amp; is_poisonable(otmp))
&nbsp;        otmp-&gt;opoisoned = TRUE;
&nbsp;
&nbsp;    if (id == STRANGE_OBJECT &amp;&amp; obj-&gt;otyp == CORPSE) {
&nbsp;        /* turn crocodile corpses into shoes */
&nbsp;        if (obj-&gt;corpsenm == PM_CROCODILE) {
&nbsp;            otmp-&gt;otyp = LOW_BOOTS;
&nbsp;            otmp-&gt;oclass = ARMOR_CLASS;
&nbsp;            otmp-&gt;spe = 0;
&nbsp;            otmp-&gt;oeroded = 0;
&nbsp;            otmp-&gt;oerodeproof = TRUE;
&nbsp;            otmp-&gt;quan = 1L;
&nbsp;            otmp-&gt;cursed = FALSE;
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* no box contents --KAA */
&nbsp;    if (Has_contents(otmp))
&nbsp;        delete_contents(otmp);
&nbsp;
&nbsp;    /* 'n' merged objects may be fused into 1 object */
&nbsp;    if (otmp-&gt;quan &gt; 1L &amp;&amp; (!objects[otmp-&gt;otyp].oc_merge
&nbsp;                            || (can_merge &amp;&amp; otmp-&gt;quan &gt; (long) rn2(1000))))
&nbsp;        otmp-&gt;quan = 1L;
&nbsp;
&nbsp;    switch (otmp-&gt;oclass) {
&nbsp;    case TOOL_CLASS:
&nbsp;        if (otmp-&gt;otyp == MAGIC_LAMP) {
&nbsp;            otmp-&gt;otyp = OIL_LAMP;
&nbsp;            otmp-&gt;age = 1500L; /* "best" oil lamp possible */
&nbsp;        } else if (otmp-&gt;otyp == MAGIC_MARKER) {
&nbsp;            otmp-&gt;recharged = 1; /* degraded quality */
&nbsp;        }
&nbsp;        /* don't care about the recharge count of other tools */
&nbsp;        break;
&nbsp;
&nbsp;    case WAND_CLASS:
&nbsp;        while (otmp-&gt;otyp == WAN_WISHING || otmp-&gt;otyp == WAN_POLYMORPH)
&nbsp;            otmp-&gt;otyp = rnd_class(WAN_LIGHT, WAN_LIGHTNING);
&nbsp;        /* altering the object tends to degrade its quality
&nbsp;           (analogous to spellbook `read count' handling) */
&nbsp;        if ((int) otmp-&gt;recharged &lt; rn2(7)) /* recharge_limit */
&nbsp;            otmp-&gt;recharged++;
&nbsp;        break;
&nbsp;
&nbsp;    case POTION_CLASS:
&nbsp;        while (otmp-&gt;otyp == POT_POLYMORPH)
&nbsp;            otmp-&gt;otyp = rnd_class(POT_GAIN_ABILITY, POT_WATER);
&nbsp;        break;
&nbsp;
&nbsp;    case SPBOOK_CLASS:
&nbsp;        while (otmp-&gt;otyp == SPE_POLYMORPH)
&nbsp;            otmp-&gt;otyp = rnd_class(SPE_DIG, SPE_BLANK_PAPER);
&nbsp;        /* reduce spellbook abuse; non-blank books degrade */
&nbsp;        if (otmp-&gt;otyp != SPE_BLANK_PAPER) {
&nbsp;            otmp-&gt;spestudied = obj-&gt;spestudied + 1;
&nbsp;            if (otmp-&gt;spestudied &gt; MAX_SPELL_STUDY) {
&nbsp;                otmp-&gt;otyp = SPE_BLANK_PAPER;
&nbsp;                /* writing a new book over it will yield an unstudied
&nbsp;                   one; re-polymorphing this one as-is may or may not
&nbsp;                   get something non-blank */
&nbsp;                otmp-&gt;spestudied = rn2(otmp-&gt;spestudied);
&nbsp;            }
&nbsp;        }
&nbsp;        break;
&nbsp;
&nbsp;    case GEM_CLASS:
&nbsp;        if (otmp-&gt;quan &gt; (long) rnd(4)
&nbsp;            &amp;&amp; objects[obj-&gt;otyp].oc_material == MINERAL
&nbsp;            &amp;&amp; objects[otmp-&gt;otyp].oc_material != MINERAL) {
&nbsp;            otmp-&gt;otyp = ROCK; /* transmutation backfired */
&nbsp;            otmp-&gt;quan /= 2L;  /* some material has been lost */
&nbsp;        }
&nbsp;        break;
&nbsp;    }
&nbsp;
&nbsp;    /* update the weight */
&nbsp;    otmp-&gt;owt = weight(otmp);
&nbsp;
&nbsp;    /* handle polymorph of worn item: stone-to-flesh cast on self can
&nbsp;       affect multiple objects at once, but their new forms won't
&nbsp;       produce any side-effects; a single worn item dipped into potion
&nbsp;       of polymorph can produce side-effects but those won't yield out
&nbsp;       of sequence messages because current polymorph is finished */
&nbsp;    if (obj_location == OBJ_INVENT &amp;&amp; obj-&gt;owornmask) {
&nbsp;        long old_wornmask = obj-&gt;owornmask &amp; ~(W_ART | W_ARTI),
&nbsp;             new_wornmask = wearslot(otmp);
&nbsp;        boolean was_twohanded = bimanual(obj), was_twoweap = u.twoweap;
&nbsp;
&nbsp;        remove_worn_item(obj, TRUE);
&nbsp;        /* if the new form can be worn in the same slot, make it so
&nbsp;           [possible extension:  if it could be worn in some other
&nbsp;           slot which is currently unfilled, wear it there instead] */
&nbsp;        if ((old_wornmask &amp; W_QUIVER) != 0L) {
&nbsp;            setuqwep(otmp);
&nbsp;        } else if ((old_wornmask &amp; W_SWAPWEP) != 0L) {
&nbsp;            if (was_twohanded || !bimanual(otmp))
&nbsp;                setuswapwep(otmp);
&nbsp;            if (was_twoweap &amp;&amp; uswapwep)
&nbsp;                u.twoweap = TRUE;
&nbsp;        } else if ((old_wornmask &amp; W_WEP) != 0L) {
&nbsp;            if (was_twohanded || !bimanual(otmp) || !uarms)
&nbsp;                setuwep(otmp);
&nbsp;            if (was_twoweap &amp;&amp; uwep &amp;&amp; !bimanual(uwep))
&nbsp;                u.twoweap = TRUE;
&nbsp;        } else if ((old_wornmask &amp; new_wornmask) != 0L) {
&nbsp;            new_wornmask &amp;= old_wornmask;
&nbsp;            setworn(otmp, new_wornmask);
&nbsp;            set_wear(otmp); /* Armor_on() for side-effects */
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* ** we are now done adjusting the object ** */
&nbsp;
&nbsp;    /* swap otmp for obj */
&nbsp;    replace_object(obj, otmp);
&nbsp;    if (obj_location == OBJ_INVENT) {
&nbsp;        /*
&nbsp;         * We may need to do extra adjustments for the hero if we're
&nbsp;         * messing with the hero's inventory.  The following calls are
&nbsp;         * equivalent to calling freeinv on obj and addinv on otmp,
&nbsp;         * while doing an in-place swap of the actual objects.
&nbsp;         */
&nbsp;        freeinv_core(obj);
&nbsp;        addinv_core1(otmp);
&nbsp;        addinv_core2(otmp);
&nbsp;    } else if (obj_location == OBJ_FLOOR) {
&nbsp;        ox = otmp-&gt;ox, oy = otmp-&gt;oy; /* set by replace_object() */
&nbsp;        if (obj-&gt;otyp == BOULDER &amp;&amp; otmp-&gt;otyp != BOULDER
&nbsp;            &amp;&amp; !does_block(ox, oy, &amp;levl[ox][oy]))
&nbsp;            unblock_point(ox, oy);
&nbsp;        else if (obj-&gt;otyp != BOULDER &amp;&amp; otmp-&gt;otyp == BOULDER)
&nbsp;            /* (checking does_block() here would be redundant) */
&nbsp;            block_point(ox, oy);
&nbsp;    }
&nbsp;
&nbsp;    if ((!carried(otmp) || obj-&gt;unpaid)
&nbsp;        &amp;&amp; get_obj_location(otmp, &amp;ox, &amp;oy, BURIED_TOO | CONTAINED_TOO)
&nbsp;        &amp;&amp; costly_spot(ox, oy)) {
&nbsp;        register struct monst *shkp =
&nbsp;            shop_keeper(*in_rooms(ox, oy, SHOPBASE));
&nbsp;
&nbsp;        if ((!obj-&gt;no_charge
&nbsp;             || (Has_contents(obj)
&nbsp;                 &amp;&amp; (contained_cost(obj, shkp, 0L, FALSE, FALSE) != 0L)))
&nbsp;            &amp;&amp; inhishop(shkp)) {
&nbsp;            if (shkp-&gt;mpeaceful) {
&nbsp;                if (*u.ushops
&nbsp;                    &amp;&amp; *in_rooms(u.ux, u.uy, 0)
&nbsp;                           == *in_rooms(shkp-&gt;mx, shkp-&gt;my, 0)
&nbsp;                    &amp;&amp; !costly_spot(u.ux, u.uy)) {
&nbsp;                    make_angry_shk(shkp, ox, oy);
&nbsp;                } else {
&nbsp;                    pline("%s gets angry!", Monnam(shkp));
&nbsp;                    hot_pursuit(shkp);
&nbsp;                }
&nbsp;            } else
&nbsp;                Norep("%s is furious!", Monnam(shkp));
&nbsp;        }
&nbsp;    }
&nbsp;    delobj(obj);
&nbsp;    return otmp;
&nbsp;}
&nbsp;
stone_to_flesh_obj
&nbsp;/* stone-to-flesh spell hits and maybe transforms or animates obj */
&nbsp;STATIC_OVL int
&nbsp;stone_to_flesh_obj(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    int res = 1; /* affected object by default */
&nbsp;    struct permonst *ptr;
&nbsp;    struct monst *mon, *shkp;
&nbsp;    struct obj *item;
&nbsp;    xchar oox, ooy;
&nbsp;    boolean smell = FALSE, golem_xform = FALSE;
&nbsp;
&nbsp;    if (objects[obj-&gt;otyp].oc_material != MINERAL
&nbsp;        &amp;&amp; objects[obj-&gt;otyp].oc_material != GEMSTONE)
&nbsp;        return 0;
&nbsp;    /* Heart of Ahriman usually resists; ordinary items rarely do */
&nbsp;    if (obj_resists(obj, 2, 98))
&nbsp;        return 0;
&nbsp;
&nbsp;    (void) get_obj_location(obj, &amp;oox, &amp;ooy, 0);
&nbsp;    /* add more if stone objects are added.. */
&nbsp;    switch (objects[obj-&gt;otyp].oc_class) {
&nbsp;    case ROCK_CLASS: /* boulders and statues */
&nbsp;    case TOOL_CLASS: /* figurines */
&nbsp;        if (obj-&gt;otyp == BOULDER) {
&nbsp;            obj = poly_obj(obj, HUGE_CHUNK_OF_MEAT);
&nbsp;            smell = TRUE;
&nbsp;        } else if (obj-&gt;otyp == STATUE || obj-&gt;otyp == FIGURINE) {
&nbsp;            ptr = &amp;mons[obj-&gt;corpsenm];
&nbsp;            if (is_golem(ptr)) {
&nbsp;                golem_xform = (ptr != &amp;mons[PM_FLESH_GOLEM]);
&nbsp;            } else if (vegetarian(ptr)) {
&nbsp;                /* Don't animate monsters that aren't flesh */
&nbsp;                obj = poly_obj(obj, MEATBALL);
&nbsp;                smell = TRUE;
&nbsp;                break;
&nbsp;            }
&nbsp;            if (obj-&gt;otyp == STATUE) {
&nbsp;                /* animate_statue() forces all golems to become flesh golems */
&nbsp;                mon = animate_statue(obj, oox, ooy, ANIMATE_SPELL, (int *) 0);
&nbsp;            } else { /* (obj-&gt;otyp == FIGURINE) */
&nbsp;                if (golem_xform)
&nbsp;                    ptr = &amp;mons[PM_FLESH_GOLEM];
&nbsp;                mon = makemon(ptr, oox, ooy, NO_MINVENT);
&nbsp;                if (mon) {
&nbsp;                    if (costly_spot(oox, ooy)
&nbsp;                        &amp;&amp; (carried(obj) ? obj-&gt;unpaid : !obj-&gt;no_charge)) {
&nbsp;                        shkp = shop_keeper(*in_rooms(oox, ooy, SHOPBASE));
&nbsp;                        stolen_value(obj, oox, ooy,
&nbsp;                                     (shkp &amp;&amp; shkp-&gt;mpeaceful), FALSE);
&nbsp;                    }
&nbsp;                    if (obj-&gt;timed)
&nbsp;                        obj_stop_timers(obj);
&nbsp;                    if (carried(obj))
&nbsp;                        useup(obj);
&nbsp;                    else
&nbsp;                        delobj(obj);
&nbsp;                    if (cansee(mon-&gt;mx, mon-&gt;my))
&nbsp;                        pline_The("figurine %sanimates!",
&nbsp;                                  golem_xform ? "turns to flesh and " : "");
&nbsp;                }
&nbsp;            }
&nbsp;            if (mon) {
&nbsp;                ptr = mon-&gt;data;
&nbsp;                /* this golem handling is redundant... */
&nbsp;                if (is_golem(ptr) &amp;&amp; ptr != &amp;mons[PM_FLESH_GOLEM])
&nbsp;                    (void) newcham(mon, &amp;mons[PM_FLESH_GOLEM], TRUE, FALSE);
&nbsp;            } else if ((ptr-&gt;geno &amp; (G_NOCORPSE | G_UNIQ)) != 0) {
&nbsp;                /* didn't revive but can't leave corpse either */
&nbsp;                res = 0;
&nbsp;            } else {
&nbsp;                /* unlikely to get here since genociding monsters also
&nbsp;                   sets the G_NOCORPSE flag; drop statue's contents */
&nbsp;                while ((item = obj-&gt;cobj) != 0) {
&nbsp;                    bypass_obj(item); /* make stone-to-flesh miss it */
&nbsp;                    obj_extract_self(item);
&nbsp;                    place_object(item, oox, ooy);
&nbsp;                }
&nbsp;                obj = poly_obj(obj, CORPSE);
&nbsp;            }
&nbsp;        } else { /* miscellaneous tool or unexpected rock... */
&nbsp;            res = 0;
&nbsp;        }
&nbsp;        break;
&nbsp;    /* maybe add weird things to become? */
&nbsp;    case RING_CLASS: /* some of the rings are stone */
&nbsp;        obj = poly_obj(obj, MEAT_RING);
&nbsp;        smell = TRUE;
&nbsp;        break;
&nbsp;    case WAND_CLASS: /* marble wand */
&nbsp;        obj = poly_obj(obj, MEAT_STICK);
&nbsp;        smell = TRUE;
&nbsp;        break;
&nbsp;    case GEM_CLASS: /* stones &amp; gems */
&nbsp;        obj = poly_obj(obj, MEATBALL);
&nbsp;        smell = TRUE;
&nbsp;        break;
&nbsp;    case WEAPON_CLASS: /* crysknife */
&nbsp;        /*FALLTHRU*/
&nbsp;    default:
&nbsp;        res = 0;
&nbsp;        break;
&nbsp;    }
&nbsp;
&nbsp;    if (smell) {
&nbsp;        /* non-meat eaters smell meat, meat eaters smell its flavor;
&nbsp;           monks are considered non-meat eaters regardless of behavior;
&nbsp;           other roles are non-meat eaters if they haven't broken
&nbsp;           vegetarian conduct yet (or if poly'd into non-carnivorous/
&nbsp;           non-omnivorous form, regardless of whether it's herbivorous,
&nbsp;           non-eating, or something stranger) */
&nbsp;        if (Role_if(PM_MONK) || !u.uconduct.unvegetarian
&nbsp;            || !carnivorous(youmonst.data))
&nbsp;            Norep("You smell the odor of meat.");
&nbsp;        else
&nbsp;            Norep("You smell a delicious smell.");
&nbsp;    }
&nbsp;    newsym(oox, ooy);
&nbsp;    return res;
&nbsp;}
&nbsp;
bhito
&nbsp;/*
&nbsp; * Object obj was hit by the effect of the wand/spell otmp.  Return
&nbsp; * non-zero if the wand/spell had any effect.
&nbsp; */
&nbsp;int
&nbsp;bhito(obj, otmp)
&nbsp;struct obj *obj, *otmp;
&nbsp;{
&nbsp;    int res = 1; /* affected object by default */
&nbsp;    boolean learn_it = FALSE, maybelearnit;
&nbsp;
&nbsp;    /* fundamental: a wand effect hitting itself doesn't do anything;
&nbsp;       otherwise we need to guard against accessing otmp after something
&nbsp;       strange has happened to it (along the lines of polymorph or
&nbsp;       stone-to-flesh [which aren't good examples since polymorph wands
&nbsp;       aren't affected by polymorph zaps and stone-to-flesh isn't
&nbsp;       available in wand form, but the concept still applies...]) */
&nbsp;    if (obj == otmp)
&nbsp;        return 0;
&nbsp;
&nbsp;    if (obj-&gt;bypass) {
&nbsp;        /* The bypass bit is currently only used as follows:
&nbsp;         *
&nbsp;         * POLYMORPH - When a monster being polymorphed drops something
&nbsp;         *             from its inventory as a result of the change.
&nbsp;         *             If the items fall to the floor, they are not
&nbsp;         *             subject to direct subsequent polymorphing
&nbsp;         *             themselves on that same zap. This makes it
&nbsp;         *             consistent with items that remain in the
&nbsp;         *             monster's inventory. They are not polymorphed
&nbsp;         *             either.
&nbsp;         * UNDEAD_TURNING - When an undead creature gets killed via
&nbsp;         *             undead turning, prevent its corpse from being
&nbsp;         *             immediately revived by the same effect.
&nbsp;         * STONE_TO_FLESH - If a statue can't be revived, its
&nbsp;         *             contents get dropped before turning it into
&nbsp;         *             meat; prevent those contents from being hit.
&nbsp;         * retouch_equipment() - bypass flag is used to track which
&nbsp;         *             items have been handled (bhito isn't involved).
&nbsp;         * menu_drop(), askchain() - inventory traversal where multiple
&nbsp;         *             Drop can alter the invent chain while traversal
&nbsp;         *             is in progress (bhito isn't involved).
&nbsp;         *
&nbsp;         * The bypass bit on all objects is reset each turn, whenever
&nbsp;         * context.bypasses is set.
&nbsp;         *
&nbsp;         * We check the obj-&gt;bypass bit above AND context.bypasses
&nbsp;         * as a safeguard against any stray occurrence left in an obj
&nbsp;         * struct someplace, although that should never happen.
&nbsp;         */
&nbsp;        if (context.bypasses) {
&nbsp;            return 0;
&nbsp;        } else {
&nbsp;            debugpline1("%s for a moment.", Tobjnam(obj, "pulsate"));
&nbsp;            obj-&gt;bypass = 0;
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /*
&nbsp;     * Some parts of this function expect the object to be on the floor
&nbsp;     * obj-&gt;{ox,oy} to be valid.  The exception to this (so far) is
&nbsp;     * for the STONE_TO_FLESH spell.
&nbsp;     */
&nbsp;    if (!(obj-&gt;where == OBJ_FLOOR || otmp-&gt;otyp == SPE_STONE_TO_FLESH))
&nbsp;        impossible("bhito: obj is not floor or Stone To Flesh spell");
&nbsp;
&nbsp;    if (obj == uball) {
&nbsp;        res = 0;
&nbsp;    } else if (obj == uchain) {
&nbsp;        if (otmp-&gt;otyp == WAN_OPENING || otmp-&gt;otyp == SPE_KNOCK) {
&nbsp;            learn_it = TRUE;
&nbsp;            unpunish();
&nbsp;        } else
&nbsp;            res = 0;
&nbsp;    } else
&nbsp;        switch (otmp-&gt;otyp) {
&nbsp;        case WAN_POLYMORPH:
&nbsp;        case SPE_POLYMORPH:
&nbsp;            if (obj-&gt;otyp == WAN_POLYMORPH || obj-&gt;otyp == SPE_POLYMORPH
&nbsp;                || obj-&gt;otyp == POT_POLYMORPH || obj_resists(obj, 5, 95)) {
&nbsp;                res = 0;
&nbsp;                break;
&nbsp;            }
&nbsp;            /* KMH, conduct */
&nbsp;            u.uconduct.polypiles++;
&nbsp;            /* any saved lock context will be dangerously obsolete */
&nbsp;            if (Is_box(obj))
&nbsp;                (void) boxlock(obj, otmp);
&nbsp;
&nbsp;            if (obj_shudders(obj)) {
&nbsp;                boolean cover =
&nbsp;                    ((obj == level.objects[u.ux][u.uy]) &amp;&amp; u.uundetected
&nbsp;                     &amp;&amp; hides_under(youmonst.data));
&nbsp;
&nbsp;                if (cansee(obj-&gt;ox, obj-&gt;oy))
&nbsp;                    learn_it = TRUE;
&nbsp;                do_osshock(obj);
&nbsp;                /* eek - your cover might have been blown */
&nbsp;                if (cover)
&nbsp;                    (void) hideunder(&amp;youmonst);
&nbsp;                break;
&nbsp;            }
&nbsp;            obj = poly_obj(obj, STRANGE_OBJECT);
&nbsp;            newsym(obj-&gt;ox, obj-&gt;oy);
&nbsp;            break;
&nbsp;        case WAN_PROBING:
&nbsp;            res = !obj-&gt;dknown;
&nbsp;            /* target object has now been "seen (up close)" */
&nbsp;            obj-&gt;dknown = 1;
&nbsp;            if (Is_container(obj) || obj-&gt;otyp == STATUE) {
&nbsp;                obj-&gt;cknown = obj-&gt;lknown = 1;
&nbsp;                if (!obj-&gt;cobj) {
&nbsp;                    boolean catbox = SchroedingersBox(obj);
&nbsp;
&nbsp;                    /* we don't want to force alive vs dead
&nbsp;                       determination for Schroedinger's Cat here,
&nbsp;                       so just make probing be inconclusive for it */
&nbsp;                    if (catbox)
&nbsp;                        obj-&gt;cknown = 0;
&nbsp;                    pline("%s empty.", Tobjnam(obj, catbox ? "seem" : "are"));
&nbsp;                } else {
&nbsp;                    struct obj *o;
&nbsp;                    /* view contents (not recursively) */
&nbsp;                    for (o = obj-&gt;cobj; o; o = o-&gt;nobj)
&nbsp;                        o-&gt;dknown = 1; /* "seen", even if blind */
&nbsp;                    (void) display_cinventory(obj);
&nbsp;                }
&nbsp;                res = 1;
&nbsp;            }
&nbsp;            if (res)
&nbsp;                learn_it = TRUE;
&nbsp;            break;
&nbsp;        case WAN_STRIKING:
&nbsp;        case SPE_FORCE_BOLT:
&nbsp;            /* learn the type if you see or hear something break
&nbsp;               (the sound could be implicit) */
&nbsp;            maybelearnit = cansee(obj-&gt;ox, obj-&gt;oy) || !Deaf;
&nbsp;            if (obj-&gt;otyp == BOULDER) {
&nbsp;                if (cansee(obj-&gt;ox, obj-&gt;oy))
&nbsp;                    pline_The("boulder falls apart.");
&nbsp;                else
&nbsp;                    You_hear("a crumbling sound.");
&nbsp;                fracture_rock(obj);
&nbsp;            } else if (obj-&gt;otyp == STATUE) {
&nbsp;                if (break_statue(obj)) {
&nbsp;                    if (cansee(obj-&gt;ox, obj-&gt;oy)) {
&nbsp;                        if (Hallucination)
&nbsp;                            pline_The("%s shatters.", rndmonnam(NULL));
&nbsp;                        else
&nbsp;                            pline_The("statue shatters.");
&nbsp;                    } else
&nbsp;                        You_hear("a crumbling sound.");
&nbsp;                }
&nbsp;            } else {
&nbsp;                int oox = obj-&gt;ox;
&nbsp;                int ooy = obj-&gt;oy;
&nbsp;                if (context.mon_moving
&nbsp;                        ? !breaks(obj, obj-&gt;ox, obj-&gt;oy)
&nbsp;                        : !hero_breaks(obj, obj-&gt;ox, obj-&gt;oy, FALSE))
&nbsp;                    maybelearnit = FALSE; /* nothing broke */
&nbsp;                else
&nbsp;                    newsym_force(oox,ooy);
&nbsp;                res = 0;
&nbsp;            }
&nbsp;            if (maybelearnit)
&nbsp;                learn_it = TRUE;
&nbsp;            break;
&nbsp;        case WAN_CANCELLATION:
&nbsp;        case SPE_CANCELLATION:
&nbsp;            cancel_item(obj);
&nbsp;#ifdef TEXTCOLOR
&nbsp;            newsym(obj-&gt;ox, obj-&gt;oy); /* might change color */
&nbsp;#endif
&nbsp;            break;
&nbsp;        case SPE_DRAIN_LIFE:
&nbsp;            (void) drain_item(obj, TRUE);
&nbsp;            break;
&nbsp;        case WAN_TELEPORTATION:
&nbsp;        case SPE_TELEPORT_AWAY:
&nbsp;            (void) rloco(obj);
&nbsp;            break;
&nbsp;        case WAN_MAKE_INVISIBLE:
&nbsp;            break;
&nbsp;        case WAN_UNDEAD_TURNING:
&nbsp;        case SPE_TURN_UNDEAD:
&nbsp;            if (obj-&gt;otyp == EGG) {
&nbsp;                revive_egg(obj);
&nbsp;            } else if (obj-&gt;otyp == CORPSE) {
&nbsp;                int corpsenm = corpse_revive_type(obj);
&nbsp;
&nbsp;                res = !!revive(obj, TRUE);
&nbsp;                if (res &amp;&amp; Role_if(PM_HEALER)) {
&nbsp;                    if (Hallucination &amp;&amp; !Deaf) {
&nbsp;                        You_hear("the sound of a defibrillator.");
&nbsp;                        learn_it = TRUE;
&nbsp;                    } else if (!Blind) {
&nbsp;                        You("observe %s %s change dramatically.",
&nbsp;                            s_suffix(an(mons[corpsenm].mname)),
&nbsp;                            nonliving(&amp;mons[corpsenm]) ? "motility"
&nbsp;                                                       : "health");
&nbsp;                        learn_it = TRUE;
&nbsp;                    }
&nbsp;                    if (learn_it)
&nbsp;                        exercise(A_WIS, TRUE);
&nbsp;                }
&nbsp;            }
&nbsp;            break;
&nbsp;        case WAN_OPENING:
&nbsp;        case SPE_KNOCK:
&nbsp;        case WAN_LOCKING:
&nbsp;        case SPE_WIZARD_LOCK:
&nbsp;            if (Is_box(obj))
&nbsp;                res = boxlock(obj, otmp);
&nbsp;            else
&nbsp;                res = 0;
&nbsp;            if (res)
&nbsp;                learn_it = TRUE;
&nbsp;            break;
&nbsp;        case WAN_SLOW_MONSTER: /* no effect on objects */
&nbsp;        case SPE_SLOW_MONSTER:
&nbsp;        case WAN_SPEED_MONSTER:
&nbsp;        case WAN_NOTHING:
&nbsp;        case SPE_HEALING:
&nbsp;        case SPE_EXTRA_HEALING:
&nbsp;            res = 0;
&nbsp;            break;
&nbsp;        case SPE_STONE_TO_FLESH:
&nbsp;            res = stone_to_flesh_obj(obj);
&nbsp;            break;
&nbsp;        default:
&nbsp;            impossible("What an interesting effect (%d)", otmp-&gt;otyp);
&nbsp;            break;
&nbsp;        }
&nbsp;    /* if effect was observable then discover the wand type provided
&nbsp;       that the wand itself has been seen */
&nbsp;    if (learn_it)
&nbsp;        learnwand(otmp);
&nbsp;    return res;
&nbsp;}
&nbsp;
bhitpile
&nbsp;/* returns nonzero if something was hit */
&nbsp;int
&nbsp;bhitpile(obj, fhito, tx, ty, zz)
&nbsp;struct obj *obj;
&nbsp;int FDECL((*fhito), (OBJ_P, OBJ_P));
&nbsp;int tx, ty;
&nbsp;schar zz;
&nbsp;{
&nbsp;    int hitanything = 0;
&nbsp;    register struct obj *otmp, *next_obj;
&nbsp;
&nbsp;    if (obj-&gt;otyp == SPE_FORCE_BOLT || obj-&gt;otyp == WAN_STRIKING) {
&nbsp;        struct trap *t = t_at(tx, ty);
&nbsp;
&nbsp;        /* We can't settle for the default calling sequence of
&nbsp;           bhito(otmp) -&gt; break_statue(otmp) -&gt; activate_statue_trap(ox,oy)
&nbsp;           because that last call might end up operating on our `next_obj'
&nbsp;           (below), rather than on the current object, if it happens to
&nbsp;           encounter a statue which mustn't become animated. */
&nbsp;        if (t &amp;&amp; t-&gt;ttyp == STATUE_TRAP
&nbsp;            &amp;&amp; activate_statue_trap(t, tx, ty, TRUE))
&nbsp;            learnwand(obj);
&nbsp;    }
&nbsp;
&nbsp;    poly_zapped = -1;
&nbsp;    for (otmp = level.objects[tx][ty]; otmp; otmp = next_obj) {
&nbsp;        next_obj = otmp-&gt;nexthere;
&nbsp;        /* for zap downwards, don't hit object poly'd hero is hiding under */
&nbsp;        if (zz &gt; 0 &amp;&amp; u.uundetected &amp;&amp; otmp == level.objects[u.ux][u.uy]
&nbsp;            &amp;&amp; hides_under(youmonst.data))
&nbsp;            continue;
&nbsp;
&nbsp;        hitanything += (*fhito)(otmp, obj);
&nbsp;    }
&nbsp;    if (poly_zapped &gt;= 0)
&nbsp;        create_polymon(level.objects[tx][ty], poly_zapped);
&nbsp;
&nbsp;    return hitanything;
&nbsp;}
&nbsp;
zappable
&nbsp;/*
&nbsp; * zappable - returns 1 if zap is available, 0 otherwise.
&nbsp; *            it removes a charge from the wand if zappable.
&nbsp; * added by GAN 11/03/86
&nbsp; */
&nbsp;int
&nbsp;zappable(wand)
&nbsp;register struct obj *wand;
&nbsp;{
&nbsp;    if (wand-&gt;spe &lt; 0 || (wand-&gt;spe == 0 &amp;&amp; rn2(121)))
&nbsp;        return 0;
&nbsp;    if (wand-&gt;spe == 0)
&nbsp;        You("wrest one last charge from the worn-out wand.");
&nbsp;    wand-&gt;spe--;
&nbsp;    return 1;
&nbsp;}
&nbsp;
zapnodir
&nbsp;/*
&nbsp; * zapnodir - zaps a NODIR wand/spell.
&nbsp; * added by GAN 11/03/86
&nbsp; */
&nbsp;void
&nbsp;zapnodir(obj)
&nbsp;register struct obj *obj;
&nbsp;{
&nbsp;    boolean known = FALSE;
&nbsp;
&nbsp;    switch (obj-&gt;otyp) {
&nbsp;    case WAN_LIGHT:
&nbsp;    case SPE_LIGHT:
&nbsp;        litroom(TRUE, obj);
&nbsp;        if (!Blind)
&nbsp;            known = TRUE;
&nbsp;        if (lightdamage(obj, TRUE, 5))
&nbsp;            known = TRUE;
&nbsp;        break;
&nbsp;    case WAN_SECRET_DOOR_DETECTION:
&nbsp;    case SPE_DETECT_UNSEEN:
&nbsp;        if (!findit())
&nbsp;            return;
&nbsp;        if (!Blind)
&nbsp;            known = TRUE;
&nbsp;        break;
&nbsp;    case WAN_CREATE_MONSTER:
&nbsp;        known = create_critters(rn2(23) ? 1 : rn1(7, 2),
&nbsp;                                (struct permonst *) 0, FALSE);
&nbsp;        break;
&nbsp;    case WAN_WISHING:
&nbsp;        known = TRUE;
&nbsp;        if (Luck + rn2(5) &lt; 0) {
&nbsp;            pline("Unfortunately, nothing happens.");
&nbsp;            break;
&nbsp;        }
&nbsp;        makewish();
&nbsp;        break;
&nbsp;    case WAN_ENLIGHTENMENT:
&nbsp;        known = TRUE;
&nbsp;        You_feel("self-knowledgeable...");
&nbsp;        display_nhwindow(WIN_MESSAGE, FALSE);
&nbsp;        enlightenment(MAGICENLIGHTENMENT, ENL_GAMEINPROGRESS);
&nbsp;        pline_The("feeling subsides.");
&nbsp;        exercise(A_WIS, TRUE);
&nbsp;        break;
&nbsp;    }
&nbsp;    if (known) {
&nbsp;        if (!objects[obj-&gt;otyp].oc_name_known)
&nbsp;            more_experienced(0, 10);
&nbsp;        /* effect was observable; discover the wand type provided
&nbsp;           that the wand itself has been seen */
&nbsp;        learnwand(obj);
&nbsp;    }
&nbsp;}
&nbsp;
backfire
&nbsp;STATIC_OVL void
&nbsp;backfire(otmp)
&nbsp;struct obj *otmp;
&nbsp;{
&nbsp;    int dmg;
&nbsp;
&nbsp;    otmp-&gt;in_use = TRUE; /* in case losehp() is fatal */
&nbsp;    pline("%s suddenly explodes!", The(xname(otmp)));
&nbsp;    dmg = d(otmp-&gt;spe + 2, 6);
&nbsp;    losehp(Maybe_Half_Phys(dmg), "exploding wand", KILLED_BY_AN);
&nbsp;    useup(otmp);
&nbsp;}
&nbsp;
&nbsp;static NEARDATA const char zap_syms[] = { WAND_CLASS, 0 };
&nbsp;
dozap
&nbsp;/* 'z' command (or 'y' if numbed_pad==-1) */
&nbsp;int
&nbsp;dozap()
&nbsp;{
&nbsp;    register struct obj *obj;
&nbsp;    int damage;
&nbsp;
&nbsp;    if (check_capacity((char *) 0))
&nbsp;        return 0;
&nbsp;    obj = getobj(zap_syms, "zap");
&nbsp;    if (!obj)
&nbsp;        return 0;
&nbsp;
&nbsp;    check_unpaid(obj);
&nbsp;
&nbsp;    /* zappable addition done by GAN 11/03/86 */
&nbsp;    if (!zappable(obj))
&nbsp;        pline1(nothing_happens);
&nbsp;    else if (obj-&gt;cursed &amp;&amp; !rn2(WAND_BACKFIRE_CHANCE)) {
&nbsp;        backfire(obj); /* the wand blows up in your face! */
&nbsp;        exercise(A_STR, FALSE);
&nbsp;        return 1;
&nbsp;    } else if (!(objects[obj-&gt;otyp].oc_dir == NODIR) &amp;&amp; !getdir((char *) 0)) {
&nbsp;        if (!Blind)
&nbsp;            pline("%s glows and fades.", The(xname(obj)));
&nbsp;        /* make him pay for knowing !NODIR */
&nbsp;    } else if (!u.dx &amp;&amp; !u.dy &amp;&amp; !u.dz
&nbsp;               &amp;&amp; !(objects[obj-&gt;otyp].oc_dir == NODIR)) {
&nbsp;        if ((damage = zapyourself(obj, TRUE)) != 0) {
&nbsp;            char buf[BUFSZ];
&nbsp;
&nbsp;            Sprintf(buf, "zapped %sself with a wand", uhim());
&nbsp;            losehp(Maybe_Half_Phys(damage), buf, NO_KILLER_PREFIX);
&nbsp;        }
&nbsp;    } else {
&nbsp;        /*      Are we having fun yet?
&nbsp;         * weffects -&gt; buzz(obj-&gt;otyp) -&gt; zhitm (temple priest) -&gt;
&nbsp;         * attack -&gt; hitum -&gt; known_hitum -&gt; ghod_hitsu -&gt;
&nbsp;         * buzz(AD_ELEC) -&gt; destroy_item(WAND_CLASS) -&gt;
&nbsp;         * useup -&gt; obfree -&gt; dealloc_obj -&gt; free(obj)
&nbsp;         */
&nbsp;        current_wand = obj;
&nbsp;        weffects(obj);
&nbsp;        obj = current_wand;
&nbsp;        current_wand = 0;
&nbsp;    }
&nbsp;    if (obj &amp;&amp; obj-&gt;spe &lt; 0) {
&nbsp;        pline("%s to dust.", Tobjnam(obj, "turn"));
&nbsp;        useup(obj);
&nbsp;    }
&nbsp;    update_inventory(); /* maybe used a charge */
&nbsp;    return 1;
&nbsp;}
&nbsp;
zapyourself
&nbsp;int
&nbsp;zapyourself(obj, ordinary)
&nbsp;struct obj *obj;
&nbsp;boolean ordinary;
&nbsp;{
&nbsp;    boolean learn_it = FALSE;
&nbsp;    int damage = 0;
&nbsp;
&nbsp;    switch (obj-&gt;otyp) {
&nbsp;    case WAN_STRIKING:
&nbsp;    case SPE_FORCE_BOLT:
&nbsp;        learn_it = TRUE;
&nbsp;        if (Antimagic) {
&nbsp;            shieldeff(u.ux, u.uy);
&nbsp;            pline("Boing!");
&nbsp;        } else {
&nbsp;            if (ordinary) {
&nbsp;                You("bash yourself!");
&nbsp;                damage = d(2, 12);
&nbsp;            } else
&nbsp;                damage = d(1 + obj-&gt;spe, 6);
&nbsp;            exercise(A_STR, FALSE);
&nbsp;        }
&nbsp;        break;
&nbsp;
&nbsp;    case WAN_LIGHTNING:
&nbsp;        learn_it = TRUE;
&nbsp;        if (!Shock_resistance) {
&nbsp;            You("shock yourself!");
&nbsp;            damage = d(12, 6);
&nbsp;            exercise(A_CON, FALSE);
&nbsp;        } else {
&nbsp;            shieldeff(u.ux, u.uy);
&nbsp;            You("zap yourself, but seem unharmed.");
&nbsp;            ugolemeffects(AD_ELEC, d(12, 6));
&nbsp;        }
&nbsp;        destroy_item(WAND_CLASS, AD_ELEC);
&nbsp;        destroy_item(RING_CLASS, AD_ELEC);
&nbsp;        (void) flashburn((long) rnd(100));
&nbsp;        break;
&nbsp;
&nbsp;    case SPE_FIREBALL:
&nbsp;        You("explode a fireball on top of yourself!");
&nbsp;        explode(u.ux, u.uy, 11, d(6, 6), WAND_CLASS, EXPL_FIERY);
&nbsp;        break;
&nbsp;    case WAN_FIRE:
&nbsp;    case FIRE_HORN:
&nbsp;        learn_it = TRUE;
&nbsp;        if (Fire_resistance) {
&nbsp;            shieldeff(u.ux, u.uy);
&nbsp;            You_feel("rather warm.");
&nbsp;            ugolemeffects(AD_FIRE, d(12, 6));
&nbsp;        } else {
&nbsp;            pline("You've set yourself afire!");
&nbsp;            damage = d(12, 6);
&nbsp;        }
&nbsp;        burn_away_slime();
&nbsp;        (void) burnarmor(&amp;youmonst);
&nbsp;        destroy_item(SCROLL_CLASS, AD_FIRE);
&nbsp;        destroy_item(POTION_CLASS, AD_FIRE);
&nbsp;        destroy_item(SPBOOK_CLASS, AD_FIRE);
&nbsp;        destroy_item(FOOD_CLASS, AD_FIRE); /* only slime for now */
&nbsp;        break;
&nbsp;
&nbsp;    case WAN_COLD:
&nbsp;    case SPE_CONE_OF_COLD:
&nbsp;    case FROST_HORN:
&nbsp;        learn_it = TRUE;
&nbsp;        if (Cold_resistance) {
&nbsp;            shieldeff(u.ux, u.uy);
&nbsp;            You_feel("a little chill.");
&nbsp;            ugolemeffects(AD_COLD, d(12, 6));
&nbsp;        } else {
&nbsp;            You("imitate a popsicle!");
&nbsp;            damage = d(12, 6);
&nbsp;        }
&nbsp;        destroy_item(POTION_CLASS, AD_COLD);
&nbsp;        break;
&nbsp;
&nbsp;    case WAN_MAGIC_MISSILE:
&nbsp;    case SPE_MAGIC_MISSILE:
&nbsp;        learn_it = TRUE;
&nbsp;        if (Antimagic) {
&nbsp;            shieldeff(u.ux, u.uy);
&nbsp;            pline_The("missiles bounce!");
&nbsp;        } else {
&nbsp;            damage = d(4, 6);
&nbsp;            pline("Idiot!  You've shot yourself!");
&nbsp;        }
&nbsp;        break;
&nbsp;
&nbsp;    case WAN_POLYMORPH:
&nbsp;    case SPE_POLYMORPH:
&nbsp;        if (!Unchanging) {
&nbsp;            learn_it = TRUE;
&nbsp;            polyself(0);
&nbsp;        }
&nbsp;        break;
&nbsp;
&nbsp;    case WAN_CANCELLATION:
&nbsp;    case SPE_CANCELLATION:
&nbsp;        (void) cancel_monst(&amp;youmonst, obj, TRUE, FALSE, TRUE);
&nbsp;        break;
&nbsp;
&nbsp;    case SPE_DRAIN_LIFE:
&nbsp;        if (!Drain_resistance) {
&nbsp;            learn_it = TRUE; /* (no effect for spells...) */
&nbsp;            losexp("life drainage");
&nbsp;        }
&nbsp;        damage = 0; /* No additional damage */
&nbsp;        break;
&nbsp;
&nbsp;    case WAN_MAKE_INVISIBLE: {
&nbsp;        /* have to test before changing HInvis but must change
&nbsp;         * HInvis before doing newsym().
&nbsp;         */
&nbsp;        int msg = !Invis &amp;&amp; !Blind &amp;&amp; !BInvis;
&nbsp;
&nbsp;        if (BInvis &amp;&amp; uarmc-&gt;otyp == MUMMY_WRAPPING) {
&nbsp;            /* A mummy wrapping absorbs it and protects you */
&nbsp;            You_feel("rather itchy under %s.", yname(uarmc));
&nbsp;            break;
&nbsp;        }
&nbsp;        if (ordinary || !rn2(10)) { /* permanent */
&nbsp;            HInvis |= FROMOUTSIDE;
&nbsp;        } else { /* temporary */
&nbsp;            incr_itimeout(&amp;HInvis, d(obj-&gt;spe, 250));
&nbsp;        }
&nbsp;        if (msg) {
&nbsp;            learn_it = TRUE;
&nbsp;            newsym(u.ux, u.uy);
&nbsp;            self_invis_message();
&nbsp;        }
&nbsp;        break;
&nbsp;    }
&nbsp;
&nbsp;    case WAN_SPEED_MONSTER:
&nbsp;        if (!(HFast &amp; INTRINSIC)) {
&nbsp;            learn_it = TRUE;
&nbsp;            if (!Fast)
&nbsp;                You("speed up.");
&nbsp;            else
&nbsp;                Your("quickness feels more natural.");
&nbsp;            exercise(A_DEX, TRUE);
&nbsp;        }
&nbsp;        HFast |= FROMOUTSIDE;
&nbsp;        break;
&nbsp;
&nbsp;    case WAN_SLEEP:
&nbsp;    case SPE_SLEEP:
&nbsp;        learn_it = TRUE;
&nbsp;        if (Sleep_resistance) {
&nbsp;            shieldeff(u.ux, u.uy);
&nbsp;            You("don't feel sleepy!");
&nbsp;        } else {
&nbsp;            pline_The("sleep ray hits you!");
&nbsp;            fall_asleep(-rnd(50), TRUE);
&nbsp;        }
&nbsp;        break;
&nbsp;
&nbsp;    case WAN_SLOW_MONSTER:
&nbsp;    case SPE_SLOW_MONSTER:
&nbsp;        if (HFast &amp; (TIMEOUT | INTRINSIC)) {
&nbsp;            learn_it = TRUE;
&nbsp;            u_slow_down();
&nbsp;        }
&nbsp;        break;
&nbsp;
&nbsp;    case WAN_TELEPORTATION:
&nbsp;    case SPE_TELEPORT_AWAY:
&nbsp;        tele();
&nbsp;        /* same criteria as when mounted (zap_steed) */
&nbsp;        if ((Teleport_control &amp;&amp; !Stunned) || !couldsee(u.ux0, u.uy0)
&nbsp;            || distu(u.ux0, u.uy0) &gt;= 16)
&nbsp;            learn_it = TRUE;
&nbsp;        break;
&nbsp;
&nbsp;    case WAN_DEATH:
&nbsp;    case SPE_FINGER_OF_DEATH:
&nbsp;        if (nonliving(youmonst.data) || is_demon(youmonst.data)) {
&nbsp;            pline((obj-&gt;otyp == WAN_DEATH)
&nbsp;                      ? "The wand shoots an apparently harmless beam at you."
&nbsp;                      : "You seem no deader than before.");
&nbsp;            break;
&nbsp;        }
&nbsp;        learn_it = TRUE;
&nbsp;        Sprintf(killer.name, "shot %sself with a death ray", uhim());
&nbsp;        killer.format = NO_KILLER_PREFIX;
&nbsp;        You("irradiate yourself with pure energy!");
&nbsp;        You("die.");
&nbsp;        /* They might survive with an amulet of life saving */
&nbsp;        done(DIED);
&nbsp;        break;
&nbsp;    case WAN_UNDEAD_TURNING:
&nbsp;    case SPE_TURN_UNDEAD:
&nbsp;        learn_it = TRUE;
&nbsp;        (void) unturn_dead(&amp;youmonst);
&nbsp;        if (is_undead(youmonst.data)) {
&nbsp;            You_feel("frightened and %sstunned.",
&nbsp;                     Stunned ? "even more " : "");
&nbsp;            make_stunned((HStun &amp; TIMEOUT) + (long) rnd(30), FALSE);
&nbsp;        } else
&nbsp;            You("shudder in dread.");
&nbsp;        break;
&nbsp;    case SPE_HEALING:
&nbsp;    case SPE_EXTRA_HEALING:
&nbsp;        learn_it = TRUE; /* (no effect for spells...) */
&nbsp;        healup(d(6, obj-&gt;otyp == SPE_EXTRA_HEALING ? 8 : 4), 0, FALSE,
&nbsp;               (obj-&gt;otyp == SPE_EXTRA_HEALING));
&nbsp;        You_feel("%sbetter.", obj-&gt;otyp == SPE_EXTRA_HEALING ? "much " : "");
&nbsp;        break;
&nbsp;    case WAN_LIGHT: /* (broken wand) */
&nbsp;        /* assert( !ordinary ); */
&nbsp;        damage = d(obj-&gt;spe, 25);
&nbsp;        /*FALLTHRU*/
&nbsp;    case EXPENSIVE_CAMERA:
&nbsp;        if (!damage)
&nbsp;            damage = 5;
&nbsp;        damage = lightdamage(obj, ordinary, damage);
&nbsp;        damage += rnd(25);
&nbsp;        if (flashburn((long) damage))
&nbsp;            learn_it = TRUE;
&nbsp;        damage = 0; /* reset */
&nbsp;        break;
&nbsp;    case WAN_OPENING:
&nbsp;    case SPE_KNOCK:
&nbsp;        if (Punished) {
&nbsp;            learn_it = TRUE;
&nbsp;            unpunish();
&nbsp;        }
&nbsp;        if (u.utrap) { /* escape web or bear trap */
&nbsp;            (void) openholdingtrap(&amp;youmonst, &amp;learn_it);
&nbsp;        } else {
&nbsp;            struct obj *otmp;
&nbsp;            /* unlock carried boxes */
&nbsp;            for (otmp = invent; otmp; otmp = otmp-&gt;nobj)
&nbsp;                if (Is_box(otmp))
&nbsp;                    (void) boxlock(otmp, obj);
&nbsp;            /* trigger previously escaped trapdoor */
&nbsp;            (void) openfallingtrap(&amp;youmonst, TRUE, &amp;learn_it);
&nbsp;        }
&nbsp;        break;
&nbsp;    case WAN_LOCKING:
&nbsp;    case SPE_WIZARD_LOCK:
&nbsp;        if (!u.utrap) {
&nbsp;            (void) closeholdingtrap(&amp;youmonst, &amp;learn_it);
&nbsp;        }
&nbsp;        break;
&nbsp;    case WAN_DIGGING:
&nbsp;    case SPE_DIG:
&nbsp;    case SPE_DETECT_UNSEEN:
&nbsp;    case WAN_NOTHING:
&nbsp;        break;
&nbsp;    case WAN_PROBING: {
&nbsp;        struct obj *otmp;
&nbsp;
&nbsp;        for (otmp = invent; otmp; otmp = otmp-&gt;nobj) {
&nbsp;            otmp-&gt;dknown = 1;
&nbsp;            if (Is_container(otmp) || otmp-&gt;otyp == STATUE) {
&nbsp;                otmp-&gt;lknown = 1;
&nbsp;                if (!SchroedingersBox(otmp))
&nbsp;                    otmp-&gt;cknown = 1;
&nbsp;            }
&nbsp;        }
&nbsp;        learn_it = TRUE;
&nbsp;        ustatusline();
&nbsp;        break;
&nbsp;    }
&nbsp;    case SPE_STONE_TO_FLESH: {
&nbsp;        struct obj *otmp, *onxt;
&nbsp;        boolean didmerge;
&nbsp;
&nbsp;        if (u.umonnum == PM_STONE_GOLEM) {
&nbsp;            learn_it = TRUE;
&nbsp;            (void) polymon(PM_FLESH_GOLEM);
&nbsp;        }
&nbsp;        if (Stoned) {
&nbsp;            learn_it = TRUE;
&nbsp;            fix_petrification(); /* saved! */
&nbsp;        }
&nbsp;        /* but at a cost.. */
&nbsp;        for (otmp = invent; otmp; otmp = onxt) {
&nbsp;            onxt = otmp-&gt;nobj;
&nbsp;            if (bhito(otmp, obj))
&nbsp;                learn_it = TRUE;
&nbsp;        }
&nbsp;        /*
&nbsp;         * It is possible that we can now merge some inventory.
&nbsp;         * Do a highly paranoid merge.  Restart from the beginning
&nbsp;         * until no merges.
&nbsp;         */
&nbsp;        do {
&nbsp;            didmerge = FALSE;
&nbsp;            for (otmp = invent; !didmerge &amp;&amp; otmp; otmp = otmp-&gt;nobj)
&nbsp;                for (onxt = otmp-&gt;nobj; onxt; onxt = onxt-&gt;nobj)
&nbsp;                    if (merged(&amp;otmp, &amp;onxt)) {
&nbsp;                        didmerge = TRUE;
&nbsp;                        break;
&nbsp;                    }
&nbsp;        } while (didmerge);
&nbsp;        break;
&nbsp;    }
&nbsp;    default:
&nbsp;        impossible("zapyourself: object %d used?", obj-&gt;otyp);
&nbsp;        break;
&nbsp;    }
&nbsp;    /* if effect was observable then discover the wand type provided
&nbsp;       that the wand itself has been seen */
&nbsp;    if (learn_it)
&nbsp;        learnwand(obj);
&nbsp;    return damage;
&nbsp;}
&nbsp;
ubreatheu
&nbsp;/* called when poly'd hero uses breath attack against self */
&nbsp;void
&nbsp;ubreatheu(mattk)
&nbsp;struct attack *mattk;
&nbsp;{
&nbsp;    int dtyp = 20 + mattk-&gt;adtyp - 1;      /* breath by hero */
&nbsp;    const char *fltxt = flash_types[dtyp]; /* blast of 

<something> */
&nbsp;
&nbsp;    zhitu(dtyp, mattk-&gt;damn, fltxt, u.ux, u.uy);
&nbsp;}
&nbsp;
lightdamage
&nbsp;/* light damages hero in gremlin form */
&nbsp;int
&nbsp;lightdamage(obj, ordinary, amt)
&nbsp;struct obj *obj;  /* item making light (fake book if spell) */
&nbsp;boolean ordinary; /* wand/camera zap vs wand destruction */
&nbsp;int amt;          /* pseudo-damage used to determine blindness duration */
&nbsp;{
&nbsp;    char buf[BUFSZ];
&nbsp;    const char *how;
&nbsp;    int dmg = amt;
&nbsp;
&nbsp;    if (dmg &amp;&amp; youmonst.data == &amp;mons[PM_GREMLIN]) {
&nbsp;        /* reduce high values (from destruction of wand with many charges) */
&nbsp;        dmg = rnd(dmg);
&nbsp;        if (dmg &gt; 10)
&nbsp;            dmg = 10 + rnd(dmg - 10);
&nbsp;        if (dmg &gt; 20)
&nbsp;            dmg = 20;
&nbsp;        pline("Ow, that light hurts%c", (dmg &gt; 2 || u.mh &lt;= 5) ? '!' : '.');
&nbsp;        /* [composing killer/reason is superfluous here; if fatal, cause
&nbsp;           of death will always be "killed while stuck in creature form"] */
&nbsp;        if (obj-&gt;oclass == SCROLL_CLASS || obj-&gt;oclass == SPBOOK_CLASS)
&nbsp;            ordinary = FALSE; /* say blasted rather than zapped */
&nbsp;        how = (obj-&gt;oclass != SPBOOK_CLASS)
&nbsp;                  ? (const char *) ansimpleoname(obj)
&nbsp;                  : "spell of light";
&nbsp;        Sprintf(buf, "%s %sself with %s", ordinary ? "zapped" : "blasted",
&nbsp;                uhim(), how);
&nbsp;        /* might rehumanize(); could be fatal, but only for Unchanging */
&nbsp;        losehp(Maybe_Half_Phys(dmg), buf, NO_KILLER_PREFIX);
&nbsp;    }
&nbsp;    return dmg;
&nbsp;}
&nbsp;
flashburn
&nbsp;/* light[ning] causes blindness */
&nbsp;boolean
&nbsp;flashburn(duration)
&nbsp;long duration;
&nbsp;{
&nbsp;    if (!resists_blnd(&amp;youmonst)) {
&nbsp;        You(are_blinded_by_the_flash);
&nbsp;        make_blinded(duration, FALSE);
&nbsp;        if (!Blind)
&nbsp;            Your1(vision_clears);
&nbsp;        return TRUE;
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
zap_steed
&nbsp;/* you've zapped a wand downwards while riding
&nbsp; * Return TRUE if the steed was hit by the wand.
&nbsp; * Return FALSE if the steed was not hit by the wand.
&nbsp; */
&nbsp;STATIC_OVL boolean
&nbsp;zap_steed(obj)
&nbsp;struct obj *obj; /* wand or spell */
&nbsp;{
&nbsp;    int steedhit = FALSE;
&nbsp;
&nbsp;    bhitpos.x = u.usteed-&gt;mx, bhitpos.y = u.usteed-&gt;my;
&nbsp;    notonhead = FALSE;
&nbsp;    switch (obj-&gt;otyp) {
&nbsp;    /*
&nbsp;     * Wands that are allowed to hit the steed
&nbsp;     * Carefully test the results of any that are
&nbsp;     * moved here from the bottom section.
&nbsp;     */
&nbsp;    case WAN_PROBING:
&nbsp;        probe_monster(u.usteed);
&nbsp;        learnwand(obj);
&nbsp;        steedhit = TRUE;
&nbsp;        break;
&nbsp;    case WAN_TELEPORTATION:
&nbsp;    case SPE_TELEPORT_AWAY:
&nbsp;        /* you go together */
&nbsp;        tele();
&nbsp;        /* same criteria as when unmounted (zapyourself) */
&nbsp;        if ((Teleport_control &amp;&amp; !Stunned) || !couldsee(u.ux0, u.uy0)
&nbsp;            || distu(u.ux0, u.uy0) &gt;= 16)
&nbsp;            learnwand(obj);
&nbsp;        steedhit = TRUE;
&nbsp;        break;
&nbsp;
&nbsp;    /* Default processing via bhitm() for these */
&nbsp;    case SPE_CURE_SICKNESS:
&nbsp;    case WAN_MAKE_INVISIBLE:
&nbsp;    case WAN_CANCELLATION:
&nbsp;    case SPE_CANCELLATION:
&nbsp;    case WAN_POLYMORPH:
&nbsp;    case SPE_POLYMORPH:
&nbsp;    case WAN_STRIKING:
&nbsp;    case SPE_FORCE_BOLT:
&nbsp;    case WAN_SLOW_MONSTER:
&nbsp;    case SPE_SLOW_MONSTER:
&nbsp;    case WAN_SPEED_MONSTER:
&nbsp;    case SPE_HEALING:
&nbsp;    case SPE_EXTRA_HEALING:
&nbsp;    case SPE_DRAIN_LIFE:
&nbsp;    case WAN_OPENING:
&nbsp;    case SPE_KNOCK:
&nbsp;        (void) bhitm(u.usteed, obj);
&nbsp;        steedhit = TRUE;
&nbsp;        break;
&nbsp;
&nbsp;    default:
&nbsp;        steedhit = FALSE;
&nbsp;        break;
&nbsp;    }
&nbsp;    return steedhit;
&nbsp;}
&nbsp;
cancel_monst
&nbsp;/*
&nbsp; * cancel a monster (possibly the hero).  inventory is cancelled only
&nbsp; * if the monster is zapping itself directly, since otherwise the
&nbsp; * effect is too strong.  currently non-hero monsters do not zap
&nbsp; * themselves with cancellation.
&nbsp; */
&nbsp;boolean
&nbsp;cancel_monst(mdef, obj, youattack, allow_cancel_kill, self_cancel)
&nbsp;register struct monst *mdef;
&nbsp;register struct obj *obj;
&nbsp;boolean youattack, allow_cancel_kill, self_cancel;
&nbsp;{
&nbsp;    boolean youdefend = (mdef == &amp;youmonst);
&nbsp;    static const char writing_vanishes[] =
&nbsp;        "Some writing vanishes from %s head!";
&nbsp;    static const char your[] = "your"; /* should be extern */
&nbsp;
&nbsp;    if (youdefend ? (!youattack &amp;&amp; Antimagic)
&nbsp;                  : resist(mdef, obj-&gt;oclass, 0, NOTELL))
&nbsp;        return FALSE; /* resisted cancellation */
&nbsp;
&nbsp;    if (self_cancel) { /* 1st cancel inventory */
&nbsp;        struct obj *otmp;
&nbsp;
&nbsp;        for (otmp = (youdefend ? invent : mdef-&gt;minvent); otmp;
&nbsp;             otmp = otmp-&gt;nobj)
&nbsp;            cancel_item(otmp);
&nbsp;        if (youdefend) {
&nbsp;            context.botl = 1; /* potential AC change */
&nbsp;            find_ac();
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* now handle special cases */
&nbsp;    if (youdefend) {
&nbsp;        if (Upolyd) {
&nbsp;            if ((u.umonnum == PM_CLAY_GOLEM) &amp;&amp; !Blind)
&nbsp;                pline(writing_vanishes, your);
&nbsp;
&nbsp;            if (Unchanging)
&nbsp;                Your("amulet grows hot for a moment, then cools.");
&nbsp;            else
&nbsp;                rehumanize();
&nbsp;        }
&nbsp;    } else {
&nbsp;        mdef-&gt;mcan = TRUE;
&nbsp;
&nbsp;        if (is_were(mdef-&gt;data) &amp;&amp; mdef-&gt;data-&gt;mlet != S_HUMAN)
&nbsp;            were_change(mdef);
&nbsp;
&nbsp;        if (mdef-&gt;data == &amp;mons[PM_CLAY_GOLEM]) {
&nbsp;            if (canseemon(mdef))
&nbsp;                pline(writing_vanishes, s_suffix(mon_nam(mdef)));
&nbsp;
&nbsp;            if (allow_cancel_kill) {
&nbsp;                if (youattack)
&nbsp;                    killed(mdef);
&nbsp;                else
&nbsp;                    monkilled(mdef, "", AD_SPEL);
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;    return TRUE;
&nbsp;}
&nbsp;
zap_updown
&nbsp;/* you've zapped an immediate type wand up or down */
&nbsp;STATIC_OVL boolean
&nbsp;zap_updown(obj)
&nbsp;struct obj *obj; /* wand or spell */
&nbsp;{
&nbsp;    boolean striking = FALSE, disclose = FALSE;
&nbsp;    int x, y, xx, yy, ptmp;
&nbsp;    struct obj *otmp;
&nbsp;    struct engr *e;
&nbsp;    struct trap *ttmp;
&nbsp;    char buf[BUFSZ];
&nbsp;
&nbsp;    /* some wands have special effects other than normal bhitpile */
&nbsp;    /* drawbridge might change <u.ux,u.uy> */
&nbsp;    x = xx = u.ux;     /* <x,y> is zap location */
&nbsp;    y = yy = u.uy;     /* <xx,yy> is drawbridge (portcullis) position */
&nbsp;    ttmp = t_at(x, y); /* trap if there is one */
&nbsp;
&nbsp;    switch (obj-&gt;otyp) {
&nbsp;    case WAN_PROBING:
&nbsp;        ptmp = 0;
&nbsp;        if (u.dz &lt; 0) {
&nbsp;            You("probe towards the %s.", ceiling(x, y));
&nbsp;        } else {
&nbsp;            ptmp += bhitpile(obj, bhito, x, y, u.dz);
&nbsp;            You("probe beneath the %s.", surface(x, y));
&nbsp;            ptmp += display_binventory(x, y, TRUE);
&nbsp;        }
&nbsp;        if (!ptmp)
&nbsp;            Your("probe reveals nothing.");
&nbsp;        return TRUE; /* we've done our own bhitpile */
&nbsp;    case WAN_OPENING:
&nbsp;    case SPE_KNOCK:
&nbsp;        /* up or down, but at closed portcullis only */
&nbsp;        if (is_db_wall(x, y) &amp;&amp; find_drawbridge(&amp;xx, &amp;yy)) {
&nbsp;            open_drawbridge(xx, yy);
&nbsp;            disclose = TRUE;
&nbsp;        } else if (u.dz &gt; 0 &amp;&amp; (x == xdnstair &amp;&amp; y == ydnstair)
&nbsp;                   /* can't use the stairs down to quest level 2 until
&nbsp;                      leader "unlocks" them; give feedback if you try */
&nbsp;                   &amp;&amp; on_level(&amp;u.uz, &amp;qstart_level) &amp;&amp; !ok_to_quest()) {
&nbsp;            pline_The("stairs seem to ripple momentarily.");
&nbsp;            disclose = TRUE;
&nbsp;        }
&nbsp;        /* down will release you from bear trap or web */
&nbsp;        if (u.dz &gt; 0 &amp;&amp; u.utrap) {
&nbsp;            (void) openholdingtrap(&amp;youmonst, &amp;disclose);
&nbsp;            /* down will trigger trapdoor, hole, or [spiked-] pit */
&nbsp;        } else if (u.dz &gt; 0 &amp;&amp; !u.utrap) {
&nbsp;            (void) openfallingtrap(&amp;youmonst, FALSE, &amp;disclose);
&nbsp;        }
&nbsp;        break;
&nbsp;    case WAN_STRIKING:
&nbsp;    case SPE_FORCE_BOLT:
&nbsp;        striking = TRUE;
&nbsp;        /*FALLTHRU*/
&nbsp;    case WAN_LOCKING:
&nbsp;    case SPE_WIZARD_LOCK:
&nbsp;        /* down at open bridge or up or down at open portcullis */
&nbsp;        if (((levl[x][y].typ == DRAWBRIDGE_DOWN)
&nbsp;                 ? (u.dz &gt; 0)
&nbsp;                 : (is_drawbridge_wall(x, y) &gt;= 0 &amp;&amp; !is_db_wall(x, y)))
&nbsp;            &amp;&amp; find_drawbridge(&amp;xx, &amp;yy)) {
&nbsp;            if (!striking)
&nbsp;                close_drawbridge(xx, yy);
&nbsp;            else
&nbsp;                destroy_drawbridge(xx, yy);
&nbsp;            disclose = TRUE;
&nbsp;        } else if (striking &amp;&amp; u.dz &lt; 0 &amp;&amp; rn2(3) &amp;&amp; !Is_airlevel(&amp;u.uz)
&nbsp;                   &amp;&amp; !Is_waterlevel(&amp;u.uz) &amp;&amp; !Underwater
&nbsp;                   &amp;&amp; !Is_qstart(&amp;u.uz)) {
&nbsp;            int dmg;
&nbsp;            /* similar to zap_dig() */
&nbsp;            pline("A rock is dislodged from the %s and falls on your %s.",
&nbsp;                  ceiling(x, y), body_part(HEAD));
&nbsp;            dmg = rnd((uarmh &amp;&amp; is_metallic(uarmh)) ? 2 : 6);
&nbsp;            losehp(Maybe_Half_Phys(dmg), "falling rock", KILLED_BY_AN);
&nbsp;            if ((otmp = mksobj_at(ROCK, x, y, FALSE, FALSE)) != 0) {
&nbsp;                (void) xname(otmp); /* set dknown, maybe bknown */
&nbsp;                stackobj(otmp);
&nbsp;            }
&nbsp;            newsym(x, y);
&nbsp;        } else if (u.dz &gt; 0 &amp;&amp; ttmp) {
&nbsp;            if (!striking &amp;&amp; closeholdingtrap(&amp;youmonst, &amp;disclose)) {
&nbsp;                ; /* now stuck in web or bear trap */
&nbsp;            } else if (striking &amp;&amp; ttmp-&gt;ttyp == TRAPDOOR) {
&nbsp;                /* striking transforms trapdoor into hole */
&nbsp;                if (Blind &amp;&amp; !ttmp-&gt;tseen) {
&nbsp;                    pline("%s beneath you shatters.", Something);
&nbsp;                } else if (!ttmp-&gt;tseen) { /* =&gt; !Blind */
&nbsp;                    pline("There's a trapdoor beneath you; it shatters.");
&nbsp;                } else {
&nbsp;                    pline("The trapdoor beneath you shatters.");
&nbsp;                    disclose = TRUE;
&nbsp;                }
&nbsp;                ttmp-&gt;ttyp = HOLE;
&nbsp;                ttmp-&gt;tseen = 1;
&nbsp;                newsym(x, y);
&nbsp;                /* might fall down hole */
&nbsp;                dotrap(ttmp, 0);
&nbsp;            } else if (!striking &amp;&amp; ttmp-&gt;ttyp == HOLE) {
&nbsp;                /* locking transforms hole into trapdoor */
&nbsp;                ttmp-&gt;ttyp = TRAPDOOR;
&nbsp;                if (Blind || !ttmp-&gt;tseen) {
&nbsp;                    pline("Some %s swirls beneath you.",
&nbsp;                          is_ice(x, y) ? "frost" : "dust");
&nbsp;                } else {
&nbsp;                    ttmp-&gt;tseen = 1;
&nbsp;                    newsym(x, y);
&nbsp;                    pline("A trapdoor appears beneath you.");
&nbsp;                    disclose = TRUE;
&nbsp;                }
&nbsp;                /* hadn't fallen down hole; won't fall now */
&nbsp;            }
&nbsp;        }
&nbsp;        break;
&nbsp;    case SPE_STONE_TO_FLESH:
&nbsp;        if (Is_airlevel(&amp;u.uz) || Is_waterlevel(&amp;u.uz) || Underwater
&nbsp;            || (Is_qstart(&amp;u.uz) &amp;&amp; u.dz &lt; 0)) {
&nbsp;            pline1(nothing_happens);
&nbsp;        } else if (u.dz &lt; 0) { /* we should do more... */
&nbsp;            pline("Blood drips on your %s.", body_part(FACE));
&nbsp;        } else if (u.dz &gt; 0 &amp;&amp; !OBJ_AT(u.ux, u.uy)) {
&nbsp;            /*
&nbsp;            Print this message only if there wasn't an engraving
&nbsp;            affected here.  If water or ice, act like waterlevel case.
&nbsp;            */
&nbsp;            e = engr_at(u.ux, u.uy);
&nbsp;            if (!(e &amp;&amp; e-&gt;engr_type == ENGRAVE)) {
&nbsp;                if (is_pool(u.ux, u.uy) || is_ice(u.ux, u.uy))
&nbsp;                    pline1(nothing_happens);
&nbsp;                else
&nbsp;                    pline("Blood %ss %s your %s.",
&nbsp;                          is_lava(u.ux, u.uy) ? "boil" : "pool",
&nbsp;                          Levitation ? "beneath" : "at",
&nbsp;                          makeplural(body_part(FOOT)));
&nbsp;            }
&nbsp;        }
&nbsp;        break;
&nbsp;    default:
&nbsp;        break;
&nbsp;    }
&nbsp;
&nbsp;    if (u.dz &gt; 0) {
&nbsp;        /* zapping downward */
&nbsp;        (void) bhitpile(obj, bhito, x, y, u.dz);
&nbsp;
&nbsp;        /* subset of engraving effects; none sets `disclose' */
&nbsp;        if ((e = engr_at(x, y)) != 0 &amp;&amp; e-&gt;engr_type != HEADSTONE) {
&nbsp;            switch (obj-&gt;otyp) {
&nbsp;            case WAN_POLYMORPH:
&nbsp;            case SPE_POLYMORPH:
&nbsp;                del_engr(e);
&nbsp;                make_engr_at(x, y, random_engraving(buf), moves, (xchar) 0);
&nbsp;                break;
&nbsp;            case WAN_CANCELLATION:
&nbsp;            case SPE_CANCELLATION:
&nbsp;            case WAN_MAKE_INVISIBLE:
&nbsp;                del_engr(e);
&nbsp;                break;
&nbsp;            case WAN_TELEPORTATION:
&nbsp;            case SPE_TELEPORT_AWAY:
&nbsp;                rloc_engr(e);
&nbsp;                break;
&nbsp;            case SPE_STONE_TO_FLESH:
&nbsp;                if (e-&gt;engr_type == ENGRAVE) {
&nbsp;                    /* only affects things in stone */
&nbsp;                    pline_The(Hallucination
&nbsp;                                  ? "floor runs like butter!"
&nbsp;                                  : "edges on the floor get smoother.");
&nbsp;                    wipe_engr_at(x, y, d(2, 4), TRUE);
&nbsp;                }
&nbsp;                break;
&nbsp;            case WAN_STRIKING:
&nbsp;            case SPE_FORCE_BOLT:
&nbsp;                wipe_engr_at(x, y, d(2, 4), TRUE);
&nbsp;                break;
&nbsp;            default:
&nbsp;                break;
&nbsp;            }
&nbsp;        }
&nbsp;    } else if (u.dz &lt; 0) {
&nbsp;        /* zapping upward */
&nbsp;
&nbsp;        /* game flavor: if you're hiding under "something"
&nbsp;         * a zap upward should hit that "something".
&nbsp;         */
&nbsp;        if (u.uundetected &amp;&amp; hides_under(youmonst.data)) {
&nbsp;            int hitit = 0;
&nbsp;            otmp = level.objects[u.ux][u.uy];
&nbsp;
&nbsp;            if (otmp)
&nbsp;                hitit = bhito(otmp, obj);
&nbsp;            if (hitit) {
&nbsp;                (void) hideunder(&amp;youmonst);
&nbsp;                disclose = TRUE;
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    return disclose;
&nbsp;}
&nbsp;
zapsetup
&nbsp;/* used by do_break_wand() was well as by weffects() */
&nbsp;void
&nbsp;zapsetup()
&nbsp;{
&nbsp;    obj_zapped = FALSE;
&nbsp;}
&nbsp;
zapwrapup
&nbsp;void
&nbsp;zapwrapup()
&nbsp;{
&nbsp;    /* if do_osshock() set obj_zapped while polying, give a message now */
&nbsp;    if (obj_zapped)
&nbsp;        You_feel("shuddering vibrations.");
&nbsp;    obj_zapped = FALSE;
&nbsp;}
&nbsp;
weffects
&nbsp;/* called for various wand and spell effects - M. Stephenson */
&nbsp;void
&nbsp;weffects(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    int otyp = obj-&gt;otyp;
&nbsp;    boolean disclose = FALSE, was_unkn = !objects[otyp].oc_name_known;
&nbsp;
&nbsp;    exercise(A_WIS, TRUE);
&nbsp;    if (u.usteed &amp;&amp; (objects[otyp].oc_dir != NODIR) &amp;&amp; !u.dx &amp;&amp; !u.dy
&nbsp;        &amp;&amp; (u.dz &gt; 0) &amp;&amp; zap_steed(obj)) {
&nbsp;        disclose = TRUE;
&nbsp;    } else if (objects[otyp].oc_dir == IMMEDIATE) {
&nbsp;        zapsetup(); /* reset obj_zapped */
&nbsp;        if (u.uswallow) {
&nbsp;            (void) bhitm(u.ustuck, obj);
&nbsp;            /* [how about `bhitpile(u.ustuck-&gt;minvent)' effect?] */
&nbsp;        } else if (u.dz) {
&nbsp;            disclose = zap_updown(obj);
&nbsp;        } else {
&nbsp;            (void) bhit(u.dx, u.dy, rn1(8, 6), ZAPPED_WAND, bhitm, bhito,
&nbsp;                        &amp;obj);
&nbsp;        }
&nbsp;        zapwrapup(); /* give feedback for obj_zapped */
&nbsp;
&nbsp;    } else if (objects[otyp].oc_dir == NODIR) {
&nbsp;        zapnodir(obj);
&nbsp;
&nbsp;    } else {
&nbsp;        /* neither immediate nor directionless */
&nbsp;
&nbsp;        if (otyp == WAN_DIGGING || otyp == SPE_DIG)
&nbsp;            zap_dig();
&nbsp;        else if (otyp &gt;= SPE_MAGIC_MISSILE &amp;&amp; otyp &lt;= SPE_FINGER_OF_DEATH)
&nbsp;            buzz(otyp - SPE_MAGIC_MISSILE + 10, u.ulevel / 2 + 1, u.ux, u.uy,
&nbsp;                 u.dx, u.dy);
&nbsp;        else if (otyp &gt;= WAN_MAGIC_MISSILE &amp;&amp; otyp &lt;= WAN_LIGHTNING)
&nbsp;            buzz(otyp - WAN_MAGIC_MISSILE,
&nbsp;                 (otyp == WAN_MAGIC_MISSILE) ? 2 : 6, u.ux, u.uy, u.dx, u.dy);
&nbsp;        else
&nbsp;            impossible("weffects: unexpected spell or wand");
&nbsp;        disclose = TRUE;
&nbsp;    }
&nbsp;    if (disclose) {
&nbsp;        learnwand(obj);
&nbsp;        if (was_unkn)
&nbsp;            more_experienced(0, 10);
&nbsp;    }
&nbsp;    return;
&nbsp;}
&nbsp;
spell_damage_bonus
&nbsp;/* augment damage for a spell dased on the hero's intelligence (and level) */
&nbsp;int
&nbsp;spell_damage_bonus(dmg)
&nbsp;int dmg; /* base amount to be adjusted by bonus or penalty */
&nbsp;{
&nbsp;    int intell = ACURR(A_INT);
&nbsp;
&nbsp;    /* Punish low intelligence before low level else low intelligence
&nbsp;       gets punished only when high level */
&nbsp;    if (intell &lt;= 9) {
&nbsp;        /* -3 penalty, but never reduce combined amount below 1
&nbsp;           (if dmg is 0 for some reason, we're careful to leave it there) */
&nbsp;        if (dmg &gt; 1)
&nbsp;            dmg = (dmg &lt;= 3) ? 1 : dmg - 3;
&nbsp;    } else if (intell &lt;= 13 || u.ulevel &lt; 5)
&nbsp;        ; /* no bonus or penalty; dmg remains same */
&nbsp;    else if (intell &lt;= 18)
&nbsp;        dmg += 1;
&nbsp;    else if (intell &lt;= 24 || u.ulevel &lt; 14)
&nbsp;        dmg += 2;
&nbsp;    else
&nbsp;        dmg += 3; /* Int 25 */
&nbsp;
&nbsp;    return dmg;
&nbsp;}
&nbsp;
spell_hit_bonus
&nbsp;/*
&nbsp; * Generate the to hit bonus for a spell.  Based on the hero's skill in
&nbsp; * spell class and dexterity.
&nbsp; */
&nbsp;STATIC_OVL int
&nbsp;spell_hit_bonus(skill)
&nbsp;int skill;
&nbsp;{
&nbsp;    int hit_bon = 0;
&nbsp;    int dex = ACURR(A_DEX);
&nbsp;
&nbsp;    switch (P_SKILL(spell_skilltype(skill))) {
&nbsp;    case P_ISRESTRICTED:
&nbsp;    case P_UNSKILLED:
&nbsp;        hit_bon = -4;
&nbsp;        break;
&nbsp;    case P_BASIC:
&nbsp;        hit_bon = 0;
&nbsp;        break;
&nbsp;    case P_SKILLED:
&nbsp;        hit_bon = 2;
&nbsp;        break;
&nbsp;    case P_EXPERT:
&nbsp;        hit_bon = 3;
&nbsp;        break;
&nbsp;    }
&nbsp;
&nbsp;    if (dex &lt; 4)
&nbsp;        hit_bon -= 3;
&nbsp;    else if (dex &lt; 6)
&nbsp;        hit_bon -= 2;
&nbsp;    else if (dex &lt; 8)
&nbsp;        hit_bon -= 1;
&nbsp;    else if (dex &lt; 14)
&nbsp;        /* Will change when print stuff below removed */
&nbsp;        hit_bon -= 0;
&nbsp;    else
&nbsp;        /* Even increment for dextrous heroes (see weapon.c abon) */
&nbsp;        hit_bon += dex - 14;
&nbsp;
&nbsp;    return hit_bon;
&nbsp;}
&nbsp;
exclam
&nbsp;const char *
&nbsp;exclam(force)
&nbsp;int force;
&nbsp;{
&nbsp;    /* force == 0 occurs e.g. with sleep ray */
&nbsp;    /* note that large force is usual with wands so that !! would
&nbsp;            require information about hand/weapon/wand */
&nbsp;    return (const char *) ((force &lt; 0) ? "?" : (force &lt;= 4) ? "." : "!");
&nbsp;}
&nbsp;
hit
&nbsp;void
&nbsp;hit(str, mtmp, force)
&nbsp;const char *str;
&nbsp;struct monst *mtmp;
&nbsp;const char *force; /* usually either "." or "!" */
&nbsp;{
&nbsp;    if ((!cansee(bhitpos.x, bhitpos.y) &amp;&amp; !canspotmon(mtmp)
&nbsp;         &amp;&amp; !(u.uswallow &amp;&amp; mtmp == u.ustuck)) || !flags.verbose)
&nbsp;        pline("%s %s it.", The(str), vtense(str, "hit"));
&nbsp;    else
&nbsp;        pline("%s %s %s%s", The(str), vtense(str, "hit"),
&nbsp;              mon_nam(mtmp), force);
&nbsp;}
&nbsp;
miss
&nbsp;void
&nbsp;miss(str, mtmp)
&nbsp;register const char *str;
&nbsp;register struct monst *mtmp;
&nbsp;{
&nbsp;    pline(
&nbsp;        "%s %s %s.", The(str), vtense(str, "miss"),
&nbsp;        ((cansee(bhitpos.x, bhitpos.y) || canspotmon(mtmp)) &amp;&amp; flags.verbose)
&nbsp;            ? mon_nam(mtmp)
&nbsp;            : "it");
&nbsp;}
&nbsp;
skiprange
&nbsp;STATIC_OVL void
&nbsp;skiprange(range, skipstart, skipend)
&nbsp;int range, *skipstart, *skipend;
&nbsp;{
&nbsp;    int tr = (range / 4);
&nbsp;    int tmp = range - ((tr &gt; 0) ? rnd(tr) : 0);
&nbsp;
&nbsp;    *skipstart = tmp;
&nbsp;    *skipend = tmp - ((tmp / 4) * rnd(3));
&nbsp;    if (*skipend &gt;= tmp)
&nbsp;        *skipend = tmp - 1;
&nbsp;}
&nbsp;
bhit
&nbsp;/*
&nbsp; *  Called for the following distance effects:
&nbsp; *      when a weapon is thrown (weapon == THROWN_WEAPON)
&nbsp; *      when an object is kicked (KICKED_WEAPON)
&nbsp; *      when an IMMEDIATE wand is zapped (ZAPPED_WAND)
&nbsp; *      when a light beam is flashed (FLASHED_LIGHT)
&nbsp; *      when a mirror is applied (INVIS_BEAM)
&nbsp; *  A thrown/kicked object falls down at end of its range or when a monster
&nbsp; *  is hit.  The variable 'bhitpos' is set to the final position of the weapon
&nbsp; *  thrown/zapped.  The ray of a wand may affect (by calling a provided
&nbsp; *  function) several objects and monsters on its path.  The return value
&nbsp; *  is the monster hit (weapon != ZAPPED_WAND), or a null monster pointer.
&nbsp; *
&nbsp; * Thrown and kicked objects (THROWN_WEAPON or KICKED_WEAPON) may be
&nbsp; * destroyed and *pobj set to NULL to indicate this.
&nbsp; *
&nbsp; *  Check !u.uswallow before calling bhit().
&nbsp; *  This function reveals the absence of a remembered invisible monster in
&nbsp; *  necessary cases (throwing or kicking weapons).  The presence of a real
&nbsp; *  one is revealed for a weapon, but if not a weapon is left up to fhitm().
&nbsp; */
&nbsp;struct monst *
&nbsp;bhit(ddx, ddy, range, weapon, fhitm, fhito, pobj)
&nbsp;register int ddx, ddy, range;          /* direction and range */
&nbsp;int weapon;                            /* see values in hack.h */
&nbsp;int FDECL((*fhitm), (MONST_P, OBJ_P)), /* fns called when mon/obj hit */
&nbsp;    FDECL((*fhito), (OBJ_P, OBJ_P));
&nbsp;struct obj **pobj; /* object tossed/used, set to NULL
&nbsp;                    * if object is destroyed */
&nbsp;{
&nbsp;    struct monst *mtmp;
&nbsp;    struct obj *obj = *pobj;
&nbsp;    uchar typ;
&nbsp;    boolean shopdoor = FALSE, point_blank = TRUE;
&nbsp;    boolean in_skip = FALSE, allow_skip = FALSE;
&nbsp;    int skiprange_start = 0, skiprange_end = 0, skipcount = 0;
&nbsp;
&nbsp;    if (weapon == KICKED_WEAPON) {
&nbsp;        /* object starts one square in front of player */
&nbsp;        bhitpos.x = u.ux + ddx;
&nbsp;        bhitpos.y = u.uy + ddy;
&nbsp;        range--;
&nbsp;    } else {
&nbsp;        bhitpos.x = u.ux;
&nbsp;        bhitpos.y = u.uy;
&nbsp;    }
&nbsp;
&nbsp;    if (weapon == THROWN_WEAPON &amp;&amp; obj &amp;&amp; obj-&gt;otyp == ROCK) {
&nbsp;        skiprange(range, &amp;skiprange_start, &amp;skiprange_end);
&nbsp;        allow_skip = !rn2(3);
&nbsp;    }
&nbsp;
&nbsp;    if (weapon == FLASHED_LIGHT) {
&nbsp;        tmp_at(DISP_BEAM, cmap_to_glyph(S_flashbeam));
&nbsp;    } else if (weapon != ZAPPED_WAND &amp;&amp; weapon != INVIS_BEAM)
&nbsp;        tmp_at(DISP_FLASH, obj_to_glyph(obj));
&nbsp;
&nbsp;    while (range-- &gt; 0) {
&nbsp;        int x, y;
&nbsp;
&nbsp;        bhitpos.x += ddx;
&nbsp;        bhitpos.y += ddy;
&nbsp;        x = bhitpos.x;
&nbsp;        y = bhitpos.y;
&nbsp;
&nbsp;        if (!isok(x, y)) {
&nbsp;            bhitpos.x -= ddx;
&nbsp;            bhitpos.y -= ddy;
&nbsp;            break;
&nbsp;        }
&nbsp;
&nbsp;        if (is_pick(obj) &amp;&amp; inside_shop(x, y)
&nbsp;            &amp;&amp; (mtmp = shkcatch(obj, x, y)) != 0) {
&nbsp;            tmp_at(DISP_END, 0);
&nbsp;            return mtmp;
&nbsp;        }
&nbsp;
&nbsp;        typ = levl[bhitpos.x][bhitpos.y].typ;
&nbsp;
&nbsp;        /* iron bars will block anything big enough */
&nbsp;        if ((weapon == THROWN_WEAPON || weapon == KICKED_WEAPON)
&nbsp;            &amp;&amp; typ == IRONBARS
&nbsp;            &amp;&amp; hits_bars(pobj, x - ddx, y - ddy, bhitpos.x, bhitpos.y,
&nbsp;                         point_blank ? 0 : !rn2(5), 1)) {
&nbsp;            /* caveat: obj might now be null... */
&nbsp;            obj = *pobj;
&nbsp;            bhitpos.x -= ddx;
&nbsp;            bhitpos.y -= ddy;
&nbsp;            break;
&nbsp;        }
&nbsp;
&nbsp;        if (weapon == ZAPPED_WAND &amp;&amp; find_drawbridge(&amp;x, &amp;y)) {
&nbsp;            boolean learn_it = FALSE;
&nbsp;
&nbsp;            switch (obj-&gt;otyp) {
&nbsp;            case WAN_OPENING:
&nbsp;            case SPE_KNOCK:
&nbsp;                if (is_db_wall(bhitpos.x, bhitpos.y)) {
&nbsp;                    if (cansee(x, y) || cansee(bhitpos.x, bhitpos.y))
&nbsp;                        learn_it = TRUE;
&nbsp;                    open_drawbridge(x, y);
&nbsp;                }
&nbsp;                break;
&nbsp;            case WAN_LOCKING:
&nbsp;            case SPE_WIZARD_LOCK:
&nbsp;                if ((cansee(x, y) || cansee(bhitpos.x, bhitpos.y))
&nbsp;                    &amp;&amp; levl[x][y].typ == DRAWBRIDGE_DOWN)
&nbsp;                    learn_it = TRUE;
&nbsp;                close_drawbridge(x, y);
&nbsp;                break;
&nbsp;            case WAN_STRIKING:
&nbsp;            case SPE_FORCE_BOLT:
&nbsp;                if (typ != DRAWBRIDGE_UP)
&nbsp;                    destroy_drawbridge(x, y);
&nbsp;                learn_it = TRUE;
&nbsp;                break;
&nbsp;            }
&nbsp;            if (learn_it)
&nbsp;                learnwand(obj);
&nbsp;        }
&nbsp;
&nbsp;        mtmp = m_at(bhitpos.x, bhitpos.y);
&nbsp;
&nbsp;        /*
&nbsp;         * skipping rocks
&nbsp;         *
&nbsp;         * skiprange_start is only set if this is a thrown rock
&nbsp;         */
&nbsp;        if (skiprange_start &amp;&amp; (range == skiprange_start) &amp;&amp; allow_skip) {
&nbsp;            if (is_pool(bhitpos.x, bhitpos.y) &amp;&amp; !mtmp) {
&nbsp;                in_skip = TRUE;
&nbsp;                if (!Blind)
&nbsp;                    pline("%s %s%s.", Yname2(obj), otense(obj, "skip"),
&nbsp;                          skipcount ? " again" : "");
&nbsp;                else
&nbsp;                    You_hear("%s skip.", yname(obj));
&nbsp;                skipcount++;
&nbsp;            } else if (skiprange_start &gt; skiprange_end + 1) {
&nbsp;                --skiprange_start;
&nbsp;            }
&nbsp;        }
&nbsp;        if (in_skip) {
&nbsp;            if (range &lt;= skiprange_end) {
&nbsp;                in_skip = FALSE;
&nbsp;                if (range &gt; 3) /* another bounce? */
&nbsp;                    skiprange(range, &amp;skiprange_start, &amp;skiprange_end);
&nbsp;            } else if (mtmp &amp;&amp; M_IN_WATER(mtmp-&gt;data)) {
&nbsp;                if ((!Blind &amp;&amp; canseemon(mtmp)) || sensemon(mtmp))
&nbsp;                    pline("%s %s over %s.", Yname2(obj), otense(obj, "pass"),
&nbsp;                          mon_nam(mtmp));
&nbsp;            }
&nbsp;        }
&nbsp;
&nbsp;        if (mtmp &amp;&amp; !(in_skip &amp;&amp; M_IN_WATER(mtmp-&gt;data))) {
&nbsp;            notonhead = (bhitpos.x != mtmp-&gt;mx || bhitpos.y != mtmp-&gt;my);
&nbsp;            if (weapon == FLASHED_LIGHT) {
&nbsp;                /* FLASHED_LIGHT hitting invisible monster should
&nbsp;                   pass through instead of stop so we call
&nbsp;                   flash_hits_mon() directly rather than returning
&nbsp;                   mtmp back to caller.  That allows the flash to
&nbsp;                   keep on going.  Note that we use mtmp-&gt;minvis
&nbsp;                   not canspotmon() because it makes no difference
&nbsp;                   whether the hero can see the monster or not. */
&nbsp;                if (mtmp-&gt;minvis) {
&nbsp;                    obj-&gt;ox = u.ux, obj-&gt;oy = u.uy;
&nbsp;                    (void) flash_hits_mon(mtmp, obj);
&nbsp;                } else {
&nbsp;                    tmp_at(DISP_END, 0);
&nbsp;                    return mtmp; /* caller will call flash_hits_mon */
&nbsp;                }
&nbsp;            } else if (weapon == INVIS_BEAM) {
&nbsp;                /* Like FLASHED_LIGHT, INVIS_BEAM should continue
&nbsp;                   through invisible targets; unlike it, we aren't
&nbsp;                   prepared for multiple hits so just get first one
&nbsp;                   that's either visible or could see its invisible
&nbsp;                   self.  [No tmp_at() cleanup is needed here.] */
&nbsp;                if (!mtmp-&gt;minvis || perceives(mtmp-&gt;data))
&nbsp;                    return mtmp;
&nbsp;            } else if (weapon != ZAPPED_WAND) {
&nbsp;                /* THROWN_WEAPON, KICKED_WEAPON */
&nbsp;                tmp_at(DISP_END, 0);
&nbsp;                if (cansee(bhitpos.x, bhitpos.y) &amp;&amp; !canspotmon(mtmp))
&nbsp;                    map_invisible(bhitpos.x, bhitpos.y);
&nbsp;                return mtmp;
&nbsp;            } else {
&nbsp;                /* ZAPPED_WAND */
&nbsp;                (*fhitm)(mtmp, obj);
&nbsp;                range -= 3;
&nbsp;            }
&nbsp;        } else {
&nbsp;            if (weapon == ZAPPED_WAND &amp;&amp; obj-&gt;otyp == WAN_PROBING
&nbsp;                &amp;&amp; glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph)) {
&nbsp;                unmap_object(bhitpos.x, bhitpos.y);
&nbsp;                newsym(x, y);
&nbsp;            }
&nbsp;        }
&nbsp;        if (fhito) {
&nbsp;            if (bhitpile(obj, fhito, bhitpos.x, bhitpos.y, 0))
&nbsp;                range--;
&nbsp;        } else {
&nbsp;            if (weapon == KICKED_WEAPON
&nbsp;                &amp;&amp; ((obj-&gt;oclass == COIN_CLASS
&nbsp;                     &amp;&amp; OBJ_AT(bhitpos.x, bhitpos.y))
&nbsp;                    || ship_object(obj, bhitpos.x, bhitpos.y,
&nbsp;                                   costly_spot(bhitpos.x, bhitpos.y)))) {
&nbsp;                tmp_at(DISP_END, 0);
&nbsp;                return (struct monst *) 0;
&nbsp;            }
&nbsp;        }
&nbsp;        if (weapon == ZAPPED_WAND &amp;&amp; (IS_DOOR(typ) || typ == SDOOR)) {
&nbsp;            switch (obj-&gt;otyp) {
&nbsp;            case WAN_OPENING:
&nbsp;            case WAN_LOCKING:
&nbsp;            case WAN_STRIKING:
&nbsp;            case SPE_KNOCK:
&nbsp;            case SPE_WIZARD_LOCK:
&nbsp;            case SPE_FORCE_BOLT:
&nbsp;                if (doorlock(obj, bhitpos.x, bhitpos.y)) {
&nbsp;                    if (cansee(bhitpos.x, bhitpos.y)
&nbsp;                        || (obj-&gt;otyp == WAN_STRIKING &amp;&amp; !Deaf))
&nbsp;                        learnwand(obj);
&nbsp;                    if (levl[bhitpos.x][bhitpos.y].doormask == D_BROKEN
&nbsp;                        &amp;&amp; *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE)) {
&nbsp;                        shopdoor = TRUE;
&nbsp;                        add_damage(bhitpos.x, bhitpos.y, SHOP_DOOR_COST);
&nbsp;                    }
&nbsp;                }
&nbsp;                break;
&nbsp;            }
&nbsp;        }
&nbsp;        if (!ZAP_POS(typ) || closed_door(bhitpos.x, bhitpos.y)) {
&nbsp;            bhitpos.x -= ddx;
&nbsp;            bhitpos.y -= ddy;
&nbsp;            break;
&nbsp;        }
&nbsp;        if (weapon != ZAPPED_WAND &amp;&amp; weapon != INVIS_BEAM) {
&nbsp;            /* 'I' present but no monster: erase */
&nbsp;            /* do this before the tmp_at() */
&nbsp;            if (glyph_is_invisible(levl[bhitpos.x][bhitpos.y].glyph)
&nbsp;                &amp;&amp; cansee(x, y)) {
&nbsp;                unmap_object(bhitpos.x, bhitpos.y);
&nbsp;                newsym(x, y);
&nbsp;            }
&nbsp;            tmp_at(bhitpos.x, bhitpos.y);
&nbsp;            delay_output();
&nbsp;            /* kicked objects fall in pools */
&nbsp;            if ((weapon == KICKED_WEAPON)
&nbsp;                &amp;&amp; (is_pool(bhitpos.x, bhitpos.y)
&nbsp;                    || is_lava(bhitpos.x, bhitpos.y)))
&nbsp;                break;
&nbsp;            if (IS_SINK(typ) &amp;&amp; weapon != FLASHED_LIGHT)
&nbsp;                break; /* physical objects fall onto sink */
&nbsp;        }
&nbsp;        /* limit range of ball so hero won't make an invalid move */
&nbsp;        if (weapon == THROWN_WEAPON &amp;&amp; range &gt; 0
&nbsp;            &amp;&amp; obj-&gt;otyp == HEAVY_IRON_BALL) {
&nbsp;            struct obj *bobj;
&nbsp;            struct trap *t;
&nbsp;
&nbsp;            if ((bobj = sobj_at(BOULDER, x, y)) != 0) {
&nbsp;                if (cansee(x, y))
&nbsp;                    pline("%s hits %s.", The(distant_name(obj, xname)),
&nbsp;                          an(xname(bobj)));
&nbsp;                range = 0;
&nbsp;            } else if (obj == uball) {
&nbsp;                if (!test_move(x - ddx, y - ddy, ddx, ddy, TEST_MOVE)) {
&nbsp;                    /* nb: it didn't hit anything directly */
&nbsp;                    if (cansee(x, y))
&nbsp;                        pline("%s jerks to an abrupt halt.",
&nbsp;                              The(distant_name(obj, xname))); /* lame */
&nbsp;                    range = 0;
&nbsp;                } else if (Sokoban &amp;&amp; (t = t_at(x, y)) != 0
&nbsp;                           &amp;&amp; (t-&gt;ttyp == PIT || t-&gt;ttyp == SPIKED_PIT
&nbsp;                               || t-&gt;ttyp == HOLE || t-&gt;ttyp == TRAPDOOR)) {
&nbsp;                    /* hero falls into the trap, so ball stops */
&nbsp;                    range = 0;
&nbsp;                }
&nbsp;            }
&nbsp;        }
&nbsp;
&nbsp;        /* thrown/kicked missile has moved away from its starting spot */
&nbsp;        point_blank = FALSE; /* affects passing through iron bars */
&nbsp;    }
&nbsp;
&nbsp;    if (weapon != ZAPPED_WAND &amp;&amp; weapon != INVIS_BEAM)
&nbsp;        tmp_at(DISP_END, 0);
&nbsp;
&nbsp;    if (shopdoor)
&nbsp;        pay_for_damage("destroy", FALSE);
&nbsp;
&nbsp;    return (struct monst *) 0;
&nbsp;}
&nbsp;
boomhit
&nbsp;/* process thrown boomerang, which travels a curving path...
&nbsp; * A multi-shot volley ought to have all missiles in flight at once,
&nbsp; * but we're called separately for each one.  We terminate the volley
&nbsp; * early on a failed catch since continuing to throw after being hit
&nbsp; * is too obviously silly.
&nbsp; */
&nbsp;struct monst *
&nbsp;boomhit(obj, dx, dy)
&nbsp;struct obj *obj;
&nbsp;int dx, dy;
&nbsp;{
&nbsp;    register int i, ct;
&nbsp;    int boom; /* showsym[] index  */
&nbsp;    struct monst *mtmp;
&nbsp;    boolean counterclockwise = TRUE; /* right-handed throw */
&nbsp;
&nbsp;    /* counterclockwise traversal patterns:
&nbsp;     *  ..........................54.................................
&nbsp;     *  ..................43.....6..3....765.........................
&nbsp;     *  ..........32.....5..2...7...2...8...4....87..................
&nbsp;     *  .........4..1....6..1...8..1....9...3...9..6.....98..........
&nbsp;     *  ..21@....5...@...7..@....9@......@12....@...5...@..7.....@9..
&nbsp;     *  .3...9....6..9....89.....................1..4...1..6....1..8.
&nbsp;     *  .4...8.....78.............................23....2..5...2...7.
&nbsp;     *  ..567............................................34....3..6..
&nbsp;     *  ........................................................45...
&nbsp;     * (invert rows for corresponding clockwise patterns)
&nbsp;     */
&nbsp;
&nbsp;    bhitpos.x = u.ux;
&nbsp;    bhitpos.y = u.uy;
&nbsp;    boom = counterclockwise ? S_boomleft : S_boomright;
&nbsp;    for (i = 0; i &lt; 8; i++)
&nbsp;        if (xdir[i] == dx &amp;&amp; ydir[i] == dy)
&nbsp;            break;
&nbsp;    tmp_at(DISP_FLASH, cmap_to_glyph(boom));
&nbsp;    for (ct = 0; ct &lt; 10; ct++) {
&nbsp;        i = (i + 8) % 8;                          /* 0..7 (8 -&gt; 0, -1 -&gt; 7) */
&nbsp;        boom = (S_boomleft + S_boomright - boom); /* toggle */
&nbsp;        tmp_at(DISP_CHANGE, cmap_to_glyph(boom)); /* change glyph */
&nbsp;        dx = xdir[i];
&nbsp;        dy = ydir[i];
&nbsp;        bhitpos.x += dx;
&nbsp;        bhitpos.y += dy;
&nbsp;        if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
&nbsp;            m_respond(mtmp);
&nbsp;            tmp_at(DISP_END, 0);
&nbsp;            return mtmp;
&nbsp;        }
&nbsp;        if (!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ)
&nbsp;            || closed_door(bhitpos.x, bhitpos.y)) {
&nbsp;            bhitpos.x -= dx;
&nbsp;            bhitpos.y -= dy;
&nbsp;            break;
&nbsp;        }
&nbsp;        if (bhitpos.x == u.ux &amp;&amp; bhitpos.y == u.uy) { /* ct == 9 */
&nbsp;            if (Fumbling || rn2(20) &gt;= ACURR(A_DEX)) {
&nbsp;                /* we hit ourselves */
&nbsp;                (void) thitu(10 + obj-&gt;spe, dmgval(obj, &amp;youmonst), &amp;obj,
&nbsp;                             "boomerang");
&nbsp;                endmultishot(TRUE);
&nbsp;                break;
&nbsp;            } else { /* we catch it */
&nbsp;                tmp_at(DISP_END, 0);
&nbsp;                You("skillfully catch the boomerang.");
&nbsp;                return &amp;youmonst
&nbsp;            }
&nbsp;        }
&nbsp;        tmp_at(bhitpos.x, bhitpos.y);
&nbsp;        delay_output();
&nbsp;        if (IS_SINK(levl[bhitpos.x][bhitpos.y].typ)) {
&nbsp;            if (!Deaf)
&nbsp;                pline("Klonk!");
&nbsp;            break; /* boomerang falls on sink */
&nbsp;        }
&nbsp;        /* ct==0, initial position, we want next delta to be same;
&nbsp;           ct==5, opposite position, repeat delta undoes first one */
&nbsp;        if (ct % 5 != 0)
&nbsp;            i += (counterclockwise ? -1 : 1);
&nbsp;    }
&nbsp;    tmp_at(DISP_END, 0); /* do not leave last symbol */
&nbsp;    return (struct monst *) 0;
&nbsp;}
&nbsp;
zhitm
&nbsp;/* used by buzz(); also used by munslime(muse.c); returns damage applied
&nbsp;   to mon; note: caller is responsible for killing mon if damage is fatal */
&nbsp;int
&nbsp;zhitm(mon, type, nd, ootmp)
&nbsp;register struct monst *mon;
&nbsp;register int type, nd;
&nbsp;struct obj **ootmp; /* to return worn armor for caller to disintegrate */
&nbsp;{
&nbsp;    register int tmp = 0;
&nbsp;    register int abstype = abs(type) % 10;
&nbsp;    boolean sho_shieldeff = FALSE;
&nbsp;    boolean spellcaster = is_hero_spell(type); /* maybe get a bonus! */
&nbsp;
&nbsp;    *ootmp = (struct obj *) 0;
&nbsp;    switch (abstype) {
&nbsp;    case ZT_MAGIC_MISSILE:
&nbsp;        if (resists_magm(mon)) {
&nbsp;            sho_shieldeff = TRUE;
&nbsp;            break;
&nbsp;        }
&nbsp;        tmp = d(nd, 6);
&nbsp;        if (spellcaster)
&nbsp;            tmp = spell_damage_bonus(tmp);
&nbsp;        break;
&nbsp;    case ZT_FIRE:
&nbsp;        if (resists_fire(mon)) {
&nbsp;            sho_shieldeff = TRUE;
&nbsp;            break;
&nbsp;        }
&nbsp;        tmp = d(nd, 6);
&nbsp;        if (resists_cold(mon))
&nbsp;            tmp += 7;
&nbsp;        if (spellcaster)
&nbsp;            tmp = spell_damage_bonus(tmp);
&nbsp;        if (burnarmor(mon)) {
&nbsp;            if (!rn2(3))
&nbsp;                (void) destroy_mitem(mon, POTION_CLASS, AD_FIRE);
&nbsp;            if (!rn2(3))
&nbsp;                (void) destroy_mitem(mon, SCROLL_CLASS, AD_FIRE);
&nbsp;            if (!rn2(5))
&nbsp;                (void) destroy_mitem(mon, SPBOOK_CLASS, AD_FIRE);
&nbsp;            destroy_mitem(mon, FOOD_CLASS, AD_FIRE); /* carried slime */
&nbsp;        }
&nbsp;        break;
&nbsp;    case ZT_COLD:
&nbsp;        if (resists_cold(mon)) {
&nbsp;            sho_shieldeff = TRUE;
&nbsp;            break;
&nbsp;        }
&nbsp;        tmp = d(nd, 6);
&nbsp;        if (resists_fire(mon))
&nbsp;            tmp += d(nd, 3);
&nbsp;        if (spellcaster)
&nbsp;            tmp = spell_damage_bonus(tmp);
&nbsp;        if (!rn2(3))
&nbsp;            (void) destroy_mitem(mon, POTION_CLASS, AD_COLD);
&nbsp;        break;
&nbsp;    case ZT_SLEEP:
&nbsp;        tmp = 0;
&nbsp;        (void) sleep_monst(mon, d(nd, 25),
&nbsp;                           type == ZT_WAND(ZT_SLEEP) ? WAND_CLASS : '\0');
&nbsp;        break;
&nbsp;    case ZT_DEATH:                              /* death/disintegration */
&nbsp;        if (abs(type) != ZT_BREATH(ZT_DEATH)) { /* death */
&nbsp;            if (mon-&gt;data == &amp;mons[PM_DEATH]) {
&nbsp;                mon-&gt;mhpmax += mon-&gt;mhpmax / 2;
&nbsp;                if (mon-&gt;mhpmax &gt;= MAGIC_COOKIE)
&nbsp;                    mon-&gt;mhpmax = MAGIC_COOKIE - 1;
&nbsp;                mon-&gt;mhp = mon-&gt;mhpmax;
&nbsp;                tmp = 0;
&nbsp;                break;
&nbsp;            }
&nbsp;            if (nonliving(mon-&gt;data) || is_demon(mon-&gt;data)
&nbsp;                || is_vampshifter(mon) || resists_magm(mon)) {
&nbsp;                /* similar to player */
&nbsp;                sho_shieldeff = TRUE;
&nbsp;                break;
&nbsp;            }
&nbsp;            type = -1; /* so they don't get saving throws */
&nbsp;        } else {
&nbsp;            struct obj *otmp2;
&nbsp;
&nbsp;            if (resists_disint(mon)) {
&nbsp;                sho_shieldeff = TRUE;
&nbsp;            } else if (mon-&gt;misc_worn_check &amp; W_ARMS) {
&nbsp;                /* destroy shield; victim survives */
&nbsp;                *ootmp = which_armor(mon, W_ARMS);
&nbsp;            } else if (mon-&gt;misc_worn_check &amp; W_ARM) {
&nbsp;                /* destroy body armor, also cloak if present */
&nbsp;                *ootmp = which_armor(mon, W_ARM);
&nbsp;                if ((otmp2 = which_armor(mon, W_ARMC)) != 0)
&nbsp;                    m_useup(mon, otmp2);
&nbsp;            } else {
&nbsp;                /* no body armor, victim dies; destroy cloak
&nbsp;                   and shirt now in case target gets life-saved */
&nbsp;                tmp = MAGIC_COOKIE;
&nbsp;                if ((otmp2 = which_armor(mon, W_ARMC)) != 0)
&nbsp;                    m_useup(mon, otmp2);
&nbsp;                if ((otmp2 = which_armor(mon, W_ARMU)) != 0)
&nbsp;                    m_useup(mon, otmp2);
&nbsp;            }
&nbsp;            type = -1; /* no saving throw wanted */
&nbsp;            break;     /* not ordinary damage */
&nbsp;        }
&nbsp;        tmp = mon-&gt;mhp + 1;
&nbsp;        break;
&nbsp;    case ZT_LIGHTNING:
&nbsp;        if (resists_elec(mon)) {
&nbsp;            sho_shieldeff = TRUE;
&nbsp;            tmp = 0;
&nbsp;            /* can still blind the monster */
&nbsp;        } else
&nbsp;            tmp = d(nd, 6);
&nbsp;        if (spellcaster)
&nbsp;            tmp = spell_damage_bonus(tmp);
&nbsp;        if (!resists_blnd(mon)
&nbsp;            &amp;&amp; !(type &gt; 0 &amp;&amp; u.uswallow &amp;&amp; mon == u.ustuck)) {
&nbsp;            register unsigned rnd_tmp = rnd(50);
&nbsp;            mon-&gt;mcansee = 0;
&nbsp;            if ((mon-&gt;mblinded + rnd_tmp) &gt; 127)
&nbsp;                mon-&gt;mblinded = 127;
&nbsp;            else
&nbsp;                mon-&gt;mblinded += rnd_tmp;
&nbsp;        }
&nbsp;        if (!rn2(3))
&nbsp;            (void) destroy_mitem(mon, WAND_CLASS, AD_ELEC);
&nbsp;        /* not actually possible yet */
&nbsp;        if (!rn2(3))
&nbsp;            (void) destroy_mitem(mon, RING_CLASS, AD_ELEC);
&nbsp;        break;
&nbsp;    case ZT_POISON_GAS:
&nbsp;        if (resists_poison(mon)) {
&nbsp;            sho_shieldeff = TRUE;
&nbsp;            break;
&nbsp;        }
&nbsp;        tmp = d(nd, 6);
&nbsp;        break;
&nbsp;    case ZT_ACID:
&nbsp;        if (resists_acid(mon)) {
&nbsp;            sho_shieldeff = TRUE;
&nbsp;            break;
&nbsp;        }
&nbsp;        tmp = d(nd, 6);
&nbsp;        if (!rn2(6))
&nbsp;            acid_damage(MON_WEP(mon));
&nbsp;        if (!rn2(6))
&nbsp;            erode_armor(mon, ERODE_CORRODE);
&nbsp;        break;
&nbsp;    }
&nbsp;    if (sho_shieldeff)
&nbsp;        shieldeff(mon-&gt;mx, mon-&gt;my);
&nbsp;    if (is_hero_spell(type) &amp;&amp; (Role_if(PM_KNIGHT) &amp;&amp; u.uhave.questart))
&nbsp;        tmp *= 2;
&nbsp;    if (tmp &gt; 0 &amp;&amp; type &gt;= 0
&nbsp;        &amp;&amp; resist(mon, type &lt; ZT_SPELL(0) ? WAND_CLASS : '\0', 0, NOTELL))
&nbsp;        tmp /= 2;
&nbsp;    if (tmp &lt; 0)
&nbsp;        tmp = 0; /* don't allow negative damage */
&nbsp;    debugpline3("zapped monster hp = %d (= %d - %d)", mon-&gt;mhp - tmp,
&nbsp;                mon-&gt;mhp, tmp);
&nbsp;    mon-&gt;mhp -= tmp;
&nbsp;    return tmp;
&nbsp;}
&nbsp;
zhitu
&nbsp;STATIC_OVL void
&nbsp;zhitu(type, nd, fltxt, sx, sy)
&nbsp;int type, nd;
&nbsp;const char *fltxt;
&nbsp;xchar sx, sy;
&nbsp;{
&nbsp;    int dam = 0, abstyp = abs(type);
&nbsp;
&nbsp;    switch (abstyp % 10) {
&nbsp;    case ZT_MAGIC_MISSILE:
&nbsp;        if (Antimagic) {
&nbsp;            shieldeff(sx, sy);
&nbsp;            pline_The("missiles bounce off!");
&nbsp;        } else {
&nbsp;            dam = d(nd, 6);
&nbsp;            exercise(A_STR, FALSE);
&nbsp;        }
&nbsp;        break;
&nbsp;    case ZT_FIRE:
&nbsp;        if (Fire_resistance) {
&nbsp;            shieldeff(sx, sy);
&nbsp;            You("don't feel hot!");
&nbsp;            ugolemeffects(AD_FIRE, d(nd, 6));
&nbsp;        } else {
&nbsp;            dam = d(nd, 6);
&nbsp;        }
&nbsp;        burn_away_slime();
&nbsp;        if (burnarmor(&amp;youmonst)) { /* "body hit" */
&nbsp;            if (!rn2(3))
&nbsp;                destroy_item(POTION_CLASS, AD_FIRE);
&nbsp;            if (!rn2(3))
&nbsp;                destroy_item(SCROLL_CLASS, AD_FIRE);
&nbsp;            if (!rn2(5))
&nbsp;                destroy_item(SPBOOK_CLASS, AD_FIRE);
&nbsp;            destroy_item(FOOD_CLASS, AD_FIRE);
&nbsp;        }
&nbsp;        break;
&nbsp;    case ZT_COLD:
&nbsp;        if (Cold_resistance) {
&nbsp;            shieldeff(sx, sy);
&nbsp;            You("don't feel cold.");
&nbsp;            ugolemeffects(AD_COLD, d(nd, 6));
&nbsp;        } else {
&nbsp;            dam = d(nd, 6);
&nbsp;        }
&nbsp;        if (!rn2(3))
&nbsp;            destroy_item(POTION_CLASS, AD_COLD);
&nbsp;        break;
&nbsp;    case ZT_SLEEP:
&nbsp;        if (Sleep_resistance) {
&nbsp;            shieldeff(u.ux, u.uy);
&nbsp;            You("don't feel sleepy.");
&nbsp;        } else {
&nbsp;            fall_asleep(-d(nd, 25), TRUE); /* sleep ray */
&nbsp;        }
&nbsp;        break;
&nbsp;    case ZT_DEATH:
&nbsp;        if (abstyp == ZT_BREATH(ZT_DEATH)) {
&nbsp;            if (Disint_resistance) {
&nbsp;                You("are not disintegrated.");
&nbsp;                break;
&nbsp;            } else if (uarms) {
&nbsp;                /* destroy shield; other possessions are safe */
&nbsp;                (void) destroy_arm(uarms);
&nbsp;                break;
&nbsp;            } else if (uarm) {
&nbsp;                /* destroy suit; if present, cloak goes too */
&nbsp;                if (uarmc)
&nbsp;                    (void) destroy_arm(uarmc);
&nbsp;                (void) destroy_arm(uarm);
&nbsp;                break;
&nbsp;            }
&nbsp;            /* no shield or suit, you're dead; wipe out cloak
&nbsp;               and/or shirt in case of life-saving or bones */
&nbsp;            if (uarmc)
&nbsp;                (void) destroy_arm(uarmc);
&nbsp;            if (uarmu)
&nbsp;                (void) destroy_arm(uarmu);
&nbsp;        } else if (nonliving(youmonst.data) || is_demon(youmonst.data)) {
&nbsp;            shieldeff(sx, sy);
&nbsp;            You("seem unaffected.");
&nbsp;            break;
&nbsp;        } else if (Antimagic) {
&nbsp;            shieldeff(sx, sy);
&nbsp;            You("aren't affected.");
&nbsp;            break;
&nbsp;        }
&nbsp;        killer.format = KILLED_BY_AN;
&nbsp;        Strcpy(killer.name, fltxt ? fltxt : "");
&nbsp;        /* when killed by disintegration breath, don't leave corpse */
&nbsp;        u.ugrave_arise = (type == -ZT_BREATH(ZT_DEATH)) ? -3 : NON_PM;
&nbsp;        done(DIED);
&nbsp;        return; /* lifesaved */
&nbsp;    case ZT_LIGHTNING:
&nbsp;        if (Shock_resistance) {
&nbsp;            shieldeff(sx, sy);
&nbsp;            You("aren't affected.");
&nbsp;            ugolemeffects(AD_ELEC, d(nd, 6));
&nbsp;        } else {
&nbsp;            dam = d(nd, 6);
&nbsp;            exercise(A_CON, FALSE);
&nbsp;        }
&nbsp;        if (!rn2(3))
&nbsp;            destroy_item(WAND_CLASS, AD_ELEC);
&nbsp;        if (!rn2(3))
&nbsp;            destroy_item(RING_CLASS, AD_ELEC);
&nbsp;        break;
&nbsp;    case ZT_POISON_GAS:
&nbsp;        poisoned("blast", A_DEX, "poisoned blast", 15, FALSE);
&nbsp;        break;
&nbsp;    case ZT_ACID:
&nbsp;        if (Acid_resistance) {
&nbsp;            pline_The("%s doesn't hurt.", hliquid("acid"));
&nbsp;            dam = 0;
&nbsp;        } else {
&nbsp;            pline_The("%s burns!", hliquid("acid"));
&nbsp;            dam = d(nd, 6);
&nbsp;            exercise(A_STR, FALSE);
&nbsp;        }
&nbsp;        /* using two weapons at once makes both of them more vulnerable */
&nbsp;        if (!rn2(u.twoweap ? 3 : 6))
&nbsp;            acid_damage(uwep);
&nbsp;        if (u.twoweap &amp;&amp; !rn2(3))
&nbsp;            acid_damage(uswapwep);
&nbsp;        if (!rn2(6))
&nbsp;            erode_armor(&amp;youmonst, ERODE_CORRODE);
&nbsp;        break;
&nbsp;    }
&nbsp;
&nbsp;    /* Half_spell_damage protection yields half-damage for wands &amp; spells,
&nbsp;       including hero's own ricochets; breath attacks do full damage */
&nbsp;    if (dam &amp;&amp; Half_spell_damage &amp;&amp; !(abstyp &gt;= 20 &amp;&amp; abstyp &lt;= 29))
&nbsp;        dam = (dam + 1) / 2;
&nbsp;    losehp(dam, fltxt, KILLED_BY_AN);
&nbsp;    return;
&nbsp;}
&nbsp;
burn_floor_objects
&nbsp;/*
&nbsp; * burn objects (such as scrolls and spellbooks) on floor
&nbsp; * at position x,y; return the number of objects burned
&nbsp; */
&nbsp;int
&nbsp;burn_floor_objects(x, y, give_feedback, u_caused)
&nbsp;int x, y;
&nbsp;boolean give_feedback; /* caller needs to decide about visibility checks */
&nbsp;boolean u_caused;
&nbsp;{
&nbsp;    struct obj *obj, *obj2;
&nbsp;    long i, scrquan, delquan;
&nbsp;    char buf1[BUFSZ], buf2[BUFSZ];
&nbsp;    int cnt = 0;
&nbsp;
&nbsp;    for (obj = level.objects[x][y]; obj; obj = obj2) {
&nbsp;        obj2 = obj-&gt;nexthere;
&nbsp;        if (obj-&gt;oclass == SCROLL_CLASS || obj-&gt;oclass == SPBOOK_CLASS
&nbsp;            || (obj-&gt;oclass == FOOD_CLASS
&nbsp;                &amp;&amp; obj-&gt;otyp == GLOB_OF_GREEN_SLIME)) {
&nbsp;            if (obj-&gt;otyp == SCR_FIRE || obj-&gt;otyp == SPE_FIREBALL
&nbsp;                || obj_resists(obj, 2, 100))
&nbsp;                continue;
&nbsp;            scrquan = obj-&gt;quan; /* number present */
&nbsp;            delquan = 0L;        /* number to destroy */
&nbsp;            for (i = scrquan; i &gt; 0L; i--)
&nbsp;                if (!rn2(3))
&nbsp;                    delquan++;
&nbsp;            if (delquan) {
&nbsp;                /* save name before potential delobj() */
&nbsp;                if (give_feedback) {
&nbsp;                    obj-&gt;quan = 1L;
&nbsp;                    Strcpy(buf1, (x == u.ux &amp;&amp; y == u.uy)
&nbsp;                                     ? xname(obj)
&nbsp;                                     : distant_name(obj, xname));
&nbsp;                    obj-&gt;quan = 2L;
&nbsp;                    Strcpy(buf2, (x == u.ux &amp;&amp; y == u.uy)
&nbsp;                                     ? xname(obj)
&nbsp;                                     : distant_name(obj, xname));
&nbsp;                    obj-&gt;quan = scrquan;
&nbsp;                }
&nbsp;                /* useupf(), which charges, only if hero caused damage */
&nbsp;                if (u_caused)
&nbsp;                    useupf(obj, delquan);
&nbsp;                else if (delquan &lt; scrquan)
&nbsp;                    obj-&gt;quan -= delquan;
&nbsp;                else
&nbsp;                    delobj(obj);
&nbsp;                cnt += delquan;
&nbsp;                if (give_feedback) {
&nbsp;                    if (delquan &gt; 1L)
&nbsp;                        pline("%ld %s burn.", delquan, buf2);
&nbsp;                    else
&nbsp;                        pline("%s burns.", An(buf1));
&nbsp;                }
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;    return cnt;
&nbsp;}
&nbsp;
zap_hit
&nbsp;/* will zap/spell/breath attack score a hit against armor class `ac'? */
&nbsp;STATIC_OVL int
&nbsp;zap_hit(ac, type)
&nbsp;int ac;
&nbsp;int type; /* either hero cast spell type or 0 */
&nbsp;{
&nbsp;    int chance = rn2(20);
&nbsp;    int spell_bonus = type ? spell_hit_bonus(type) : 0;
&nbsp;
&nbsp;    /* small chance for naked target to avoid being hit */
&nbsp;    if (!chance)
&nbsp;        return rnd(10) &lt; ac + spell_bonus;
&nbsp;
&nbsp;    /* very high armor protection does not achieve invulnerability */
&nbsp;    ac = AC_VALUE(ac);
&nbsp;
&nbsp;    return (3 - chance &lt; ac + spell_bonus);
&nbsp;}
&nbsp;
disintegrate_mon
&nbsp;STATIC_OVL void
&nbsp;disintegrate_mon(mon, type, fltxt)
&nbsp;struct monst *mon;
&nbsp;int type; /* hero vs other */
&nbsp;const char *fltxt;
&nbsp;{
&nbsp;    struct obj *otmp, *otmp2, *m_amulet = mlifesaver(mon);
&nbsp;
&nbsp;    if (canseemon(mon)) {
&nbsp;        if (!m_amulet)
&nbsp;            pline("%s is disintegrated!", Monnam(mon));
&nbsp;        else
&nbsp;            hit(fltxt, mon, "!");
&nbsp;    }
&nbsp;
&nbsp;/* note: worn amulet of life saving must be preserved in order to operate */
&nbsp;#define oresist_disintegration(obj)                                       \
&nbsp;    (objects[obj-&gt;otyp].oc_oprop == DISINT_RES || obj_resists(obj, 5, 50) \
&nbsp;     || is_quest_artifact(obj) || obj == m_amulet)
&nbsp;
&nbsp;    for (otmp = mon-&gt;minvent; otmp; otmp = otmp2) {
&nbsp;        otmp2 = otmp-&gt;nobj;
&nbsp;        if (!oresist_disintegration(otmp)) {
&nbsp;            if (otmp-&gt;owornmask) {
&nbsp;                /* in case monster's life gets saved */
&nbsp;                mon-&gt;misc_worn_check &amp;= ~otmp-&gt;owornmask;
&nbsp;                if (otmp-&gt;owornmask &amp; W_WEP)
&nbsp;                    setmnotwielded(mon, otmp);
&nbsp;                /* also dismounts hero if this object is steed's saddle */
&nbsp;                update_mon_intrinsics(mon, otmp, FALSE, TRUE);
&nbsp;                otmp-&gt;owornmask = 0L;
&nbsp;            }
&nbsp;            obj_extract_self(otmp);
&nbsp;            obfree(otmp, (struct obj *) 0);
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;#undef oresist_disintegration
&nbsp;
&nbsp;    if (type &lt; 0)
&nbsp;        monkilled(mon, (char *) 0, -AD_RBRE);
&nbsp;    else
&nbsp;        xkilled(mon, XKILL_NOMSG | XKILL_NOCORPSE);
&nbsp;}
&nbsp;
buzz
&nbsp;void
&nbsp;buzz(type, nd, sx, sy, dx, dy)
&nbsp;int type, nd;
&nbsp;xchar sx, sy;
&nbsp;int dx, dy;
&nbsp;{
&nbsp;    dobuzz(type, nd, sx, sy, dx, dy, TRUE);
&nbsp;}
&nbsp;
dobuzz
&nbsp;/*
&nbsp; * type ==   0 to   9 : you shooting a wand
&nbsp; * type ==  10 to  19 : you casting a spell
&nbsp; * type ==  20 to  29 : you breathing as a monster
&nbsp; * type == -10 to -19 : monster casting spell
&nbsp; * type == -20 to -29 : monster breathing at you
&nbsp; * type == -30 to -39 : monster shooting a wand
&nbsp; * called with dx = dy = 0 with vertical bolts
&nbsp; */
&nbsp;void
&nbsp;dobuzz(type, nd, sx, sy, dx, dy, say)
&nbsp;register int type, nd;
&nbsp;register xchar sx, sy;
&nbsp;register int dx, dy;
&nbsp;boolean say; /* Announce out of sight hit/miss events if true */
&nbsp;{
&nbsp;    int range, abstype = abs(type) % 10;
&nbsp;    register xchar lsx, lsy;
&nbsp;    struct monst *mon;
&nbsp;    coord save_bhitpos;
&nbsp;    boolean shopdamage = FALSE;
&nbsp;    const char *fltxt;
&nbsp;    struct obj *otmp;
&nbsp;    int spell_type;
&nbsp;
&nbsp;    /* if its a Hero Spell then get its SPE_TYPE */
&nbsp;    spell_type = is_hero_spell(type) ? SPE_MAGIC_MISSILE + abstype : 0;
&nbsp;
&nbsp;    fltxt = flash_types[(type &lt;= -30) ? abstype : abs(type)];
&nbsp;    if (u.uswallow) {
&nbsp;        register int tmp;
&nbsp;
&nbsp;        if (type &lt; 0)
&nbsp;            return;
&nbsp;        tmp = zhitm(u.ustuck, type, nd, &amp;otmp);
&nbsp;        if (!u.ustuck)
&nbsp;            u.uswallow = 0;
&nbsp;        else
&nbsp;            pline("%s rips into %s%s", The(fltxt), mon_nam(u.ustuck),
&nbsp;                  exclam(tmp));
&nbsp;        /* Using disintegration from the inside only makes a hole... */
&nbsp;        if (tmp == MAGIC_COOKIE)
&nbsp;            u.ustuck-&gt;mhp = 0;
&nbsp;        if (u.ustuck-&gt;mhp &lt; 1)
&nbsp;            killed(u.ustuck);
&nbsp;        return;
&nbsp;    }
&nbsp;    if (type &lt; 0)
&nbsp;        newsym(u.ux, u.uy);
&nbsp;    range = rn1(7, 7);
&nbsp;    if (dx == 0 &amp;&amp; dy == 0)
&nbsp;        range = 1;
&nbsp;    save_bhitpos = bhitpos;
&nbsp;
&nbsp;    tmp_at(DISP_BEAM, zapdir_to_glyph(dx, dy, abstype));
&nbsp;    while (range-- &gt; 0) {
&nbsp;        lsx = sx;
&nbsp;        sx += dx;
&nbsp;        lsy = sy;
&nbsp;        sy += dy;
&nbsp;        if (!isok(sx, sy) || levl[sx][sy].typ == STONE)
&nbsp;            goto make_bounce;
&nbsp;
&nbsp;        mon = m_at(sx, sy);
&nbsp;        if (cansee(sx, sy)) {
&nbsp;            /* reveal/unreveal invisible monsters before tmp_at() */
&nbsp;            if (mon &amp;&amp; !canspotmon(mon))
&nbsp;                map_invisible(sx, sy);
&nbsp;            else if (!mon)
&nbsp;                (void) unmap_invisible(sx, sy);
&nbsp;            if (ZAP_POS(levl[sx][sy].typ)
&nbsp;                || (isok(lsx, lsy) &amp;&amp; cansee(lsx, lsy)))
&nbsp;                tmp_at(sx, sy);
&nbsp;            delay_output(); /* wait a little */
&nbsp;        }
&nbsp;
&nbsp;        /* hit() and miss() need bhitpos to match the target */
&nbsp;        bhitpos.x = sx, bhitpos.y = sy;
&nbsp;        /* Fireballs only damage when they explode */
&nbsp;        if (type != ZT_SPELL(ZT_FIRE))
&nbsp;            range += zap_over_floor(sx, sy, type, &amp;shopdamage, 0);
&nbsp;
&nbsp;        if (mon) {
&nbsp;            if (type == ZT_SPELL(ZT_FIRE))
&nbsp;                break;
&nbsp;            if (type &gt;= 0)
&nbsp;                mon-&gt;mstrategy &amp;= ~STRAT_WAITMASK;
&nbsp;        buzzmonst:
&nbsp;            notonhead = (mon-&gt;mx != bhitpos.x || mon-&gt;my != bhitpos.y);
&nbsp;            if (zap_hit(find_mac(mon), spell_type)) {
&nbsp;                if (mon_reflects(mon, (char *) 0)) {
&nbsp;                    if (cansee(mon-&gt;mx, mon-&gt;my)) {
&nbsp;                        hit(fltxt, mon, exclam(0));
&nbsp;                        shieldeff(mon-&gt;mx, mon-&gt;my);
&nbsp;                        (void) mon_reflects(mon,
&nbsp;                                            "But it reflects from %s %s!");
&nbsp;                    }
&nbsp;                    dx = -dx;
&nbsp;                    dy = -dy;
&nbsp;                } else {
&nbsp;                    boolean mon_could_move = mon-&gt;mcanmove;
&nbsp;                    int tmp = zhitm(mon, type, nd, &amp;otmp);
&nbsp;
&nbsp;                    if (is_rider(mon-&gt;data)
&nbsp;                        &amp;&amp; abs(type) == ZT_BREATH(ZT_DEATH)) {
&nbsp;                        if (canseemon(mon)) {
&nbsp;                            hit(fltxt, mon, ".");
&nbsp;                            pline("%s disintegrates.", Monnam(mon));
&nbsp;                            pline("%s body reintegrates before your %s!",
&nbsp;                                  s_suffix(Monnam(mon)),
&nbsp;                                  (eyecount(youmonst.data) == 1)
&nbsp;                                      ? body_part(EYE)
&nbsp;                                      : makeplural(body_part(EYE)));
&nbsp;                            pline("%s resurrects!", Monnam(mon));
&nbsp;                        }
&nbsp;                        mon-&gt;mhp = mon-&gt;mhpmax;
&nbsp;                        break; /* Out of while loop */
&nbsp;                    }
&nbsp;                    if (mon-&gt;data == &amp;mons[PM_DEATH] &amp;&amp; abstype == ZT_DEATH) {
&nbsp;                        if (canseemon(mon)) {
&nbsp;                            hit(fltxt, mon, ".");
&nbsp;                            pline("%s absorbs the deadly %s!", Monnam(mon),
&nbsp;                                  type == ZT_BREATH(ZT_DEATH) ? "blast"
&nbsp;                                                              : "ray");
&nbsp;                            pline("It seems even stronger than before.");
&nbsp;                        }
&nbsp;                        break; /* Out of while loop */
&nbsp;                    }
&nbsp;
&nbsp;                    if (tmp == MAGIC_COOKIE) { /* disintegration */
&nbsp;                        disintegrate_mon(mon, type, fltxt);
&nbsp;                    } else if (mon-&gt;mhp &lt; 1) {
&nbsp;                        if (type &lt; 0) {
&nbsp;                            /* mon has just been killed by another monster */
&nbsp;                            monkilled(mon, fltxt, AD_RBRE);
&nbsp;                        } else {
&nbsp;                            int xkflags = XKILL_GIVEMSG; /* killed(mon); */
&nbsp;
&nbsp;                            /* killed by hero; we know 'type' isn't negative;
&nbsp;                               if it's fire, highly flammable monsters leave
&nbsp;                               no corpse; don't bother reporting that they
&nbsp;                               "burn completely" -- unnecessary verbosity */
&nbsp;                            if ((type % 10 == ZT_FIRE)
&nbsp;                                /* paper golem or straw golem */
&nbsp;                                &amp;&amp; completelyburns(mon-&gt;data))
&nbsp;                                xkflags |= XKILL_NOCORPSE;
&nbsp;                            xkilled(mon, xkflags);
&nbsp;                        }
&nbsp;                    } else {
&nbsp;                        if (!otmp) {
&nbsp;                            /* normal non-fatal hit */
&nbsp;                            if (say || canseemon(mon))
&nbsp;                                hit(fltxt, mon, exclam(tmp));
&nbsp;                        } else {
&nbsp;                            /* some armor was destroyed; no damage done */
&nbsp;                            if (canseemon(mon))
&nbsp;                                pline("%s %s is disintegrated!",
&nbsp;                                      s_suffix(Monnam(mon)),
&nbsp;                                      distant_name(otmp, xname));
&nbsp;                            m_useup(mon, otmp);
&nbsp;                        }
&nbsp;                        if (mon_could_move &amp;&amp; !mon-&gt;mcanmove) /* ZT_SLEEP */
&nbsp;                            slept_monst(mon);
&nbsp;                    }
&nbsp;                }
&nbsp;                range -= 2;
&nbsp;            } else {
&nbsp;                if (say || canseemon(mon))
&nbsp;                    miss(fltxt, mon);
&nbsp;            }
&nbsp;        } else if (sx == u.ux &amp;&amp; sy == u.uy &amp;&amp; range &gt;= 0) {
&nbsp;            nomul(0);
&nbsp;            if (u.usteed &amp;&amp; !rn2(3) &amp;&amp; !mon_reflects(u.usteed, (char *) 0)) {
&nbsp;                mon = u.usteed;
&nbsp;                goto buzzmonst;
&nbsp;            } else if (zap_hit((int) u.uac, 0)) {
&nbsp;                range -= 2;
&nbsp;                pline("%s hits you!", The(fltxt));
&nbsp;                if (Reflecting) {
&nbsp;                    if (!Blind) {
&nbsp;                        (void) ureflects("But %s reflects from your %s!",
&nbsp;                                         "it");
&nbsp;                    } else
&nbsp;                        pline("For some reason you are not affected.");
&nbsp;                    dx = -dx;
&nbsp;                    dy = -dy;
&nbsp;                    shieldeff(sx, sy);
&nbsp;                } else {
&nbsp;                    zhitu(type, nd, fltxt, sx, sy);
&nbsp;                }
&nbsp;            } else if (!Blind) {
&nbsp;                pline("%s whizzes by you!", The(fltxt));
&nbsp;            } else if (abstype == ZT_LIGHTNING) {
&nbsp;                Your("%s tingles.", body_part(ARM));
&nbsp;            }
&nbsp;            if (abstype == ZT_LIGHTNING)
&nbsp;                (void) flashburn((long) d(nd, 50));
&nbsp;            stop_occupation();
&nbsp;            nomul(0);
&nbsp;        }
&nbsp;
&nbsp;        if (!ZAP_POS(levl[sx][sy].typ)
&nbsp;            || (closed_door(sx, sy) &amp;&amp; range &gt;= 0)) {
&nbsp;            int bounce, bchance;
&nbsp;            uchar rmn;
&nbsp;            boolean fireball;
&nbsp;
&nbsp;        make_bounce:
&nbsp;            bchance = (levl[sx][sy].typ == STONE) ? 10
&nbsp;                : (In_mines(&amp;u.uz) &amp;&amp; IS_WALL(levl[sx][sy].typ)) ? 20
&nbsp;                : 75;
&nbsp;            bounce = 0;
&nbsp;            fireball = (type == ZT_SPELL(ZT_FIRE));
&nbsp;            if ((--range &gt; 0 &amp;&amp; isok(lsx, lsy) &amp;&amp; cansee(lsx, lsy))
&nbsp;                || fireball) {
&nbsp;                if (Is_airlevel(&amp;u.uz)) { /* nothing to bounce off of */
&nbsp;                    pline_The("%s vanishes into the aether!", fltxt);
&nbsp;                    if (fireball)
&nbsp;                        type = ZT_WAND(ZT_FIRE); /* skip pending fireball */
&nbsp;                    break;
&nbsp;                } else if (fireball) {
&nbsp;                    sx = lsx;
&nbsp;                    sy = lsy;
&nbsp;                    break; /* fireballs explode before the obstacle */
&nbsp;                } else
&nbsp;                    pline_The("%s bounces!", fltxt);
&nbsp;            }
&nbsp;            if (!dx || !dy || !rn2(bchance)) {
&nbsp;                dx = -dx;
&nbsp;                dy = -dy;
&nbsp;            } else {
&nbsp;                if (isok(sx, lsy) &amp;&amp; ZAP_POS(rmn = levl[sx][lsy].typ)
&nbsp;                    &amp;&amp; !closed_door(sx, lsy)
&nbsp;                    &amp;&amp; (IS_ROOM(rmn) || (isok(sx + dx, lsy)
&nbsp;                                         &amp;&amp; ZAP_POS(levl[sx + dx][lsy].typ))))
&nbsp;                    bounce = 1;
&nbsp;                if (isok(lsx, sy) &amp;&amp; ZAP_POS(rmn = levl[lsx][sy].typ)
&nbsp;                    &amp;&amp; !closed_door(lsx, sy)
&nbsp;                    &amp;&amp; (IS_ROOM(rmn) || (isok(lsx, sy + dy)
&nbsp;                                         &amp;&amp; ZAP_POS(levl[lsx][sy + dy].typ))))
&nbsp;                    if (!bounce || rn2(2))
&nbsp;                        bounce = 2;
&nbsp;
&nbsp;                switch (bounce) {
&nbsp;                case 0:
&nbsp;                    dx = -dx;
&nbsp;                    /*FALLTHRU*/
&nbsp;                case 1:
&nbsp;                    dy = -dy;
&nbsp;                    break;
&nbsp;                case 2:
&nbsp;                    dx = -dx;
&nbsp;                    break;
&nbsp;                }
&nbsp;                tmp_at(DISP_CHANGE, zapdir_to_glyph(dx, dy, abstype));
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;    tmp_at(DISP_END, 0);
&nbsp;    if (type == ZT_SPELL(ZT_FIRE))
&nbsp;        explode(sx, sy, type, d(12, 6), 0, EXPL_FIERY);
&nbsp;    if (shopdamage)
&nbsp;        pay_for_damage(abstype == ZT_FIRE
&nbsp;                          ? "burn away"
&nbsp;                          : abstype == ZT_COLD
&nbsp;                             ? "shatter"
&nbsp;                             /* "damage" indicates wall rather than door */
&nbsp;                             : abstype == ZT_ACID
&nbsp;                                ? "damage"
&nbsp;                                : abstype == ZT_DEATH
&nbsp;                                   ? "disintegrate"
&nbsp;                                   : "destroy",
&nbsp;                       FALSE);
&nbsp;    bhitpos = save_bhitpos;
&nbsp;}
&nbsp;
melt_ice
&nbsp;void
&nbsp;melt_ice(x, y, msg)
&nbsp;xchar x, y;
&nbsp;const char *msg;
&nbsp;{
&nbsp;    struct rm *lev = &amp;levl[x][y];
&nbsp;    struct obj *otmp;
&nbsp;
&nbsp;    if (!msg)
&nbsp;        msg = "The ice crackles and melts.";
&nbsp;    if (lev-&gt;typ == DRAWBRIDGE_UP || lev-&gt;typ == DRAWBRIDGE_DOWN) {
&nbsp;        lev-&gt;drawbridgemask &amp;= ~DB_ICE; /* revert to DB_MOAT */
&nbsp;    } else { /* lev-&gt;typ == ICE */
&nbsp;#ifdef STUPID
&nbsp;        if (lev-&gt;icedpool == ICED_POOL)
&nbsp;            lev-&gt;typ = POOL;
&nbsp;        else
&nbsp;            lev-&gt;typ = MOAT;
&nbsp;#else
&nbsp;        lev-&gt;typ = (lev-&gt;icedpool == ICED_POOL ? POOL : MOAT);
&nbsp;#endif
&nbsp;        lev-&gt;icedpool = 0;
&nbsp;    }
&nbsp;    spot_stop_timers(x, y, MELT_ICE_AWAY); /* no more ice to melt away */
&nbsp;    obj_ice_effects(x, y, FALSE);
&nbsp;    unearth_objs(x, y);
&nbsp;    if (Underwater)
&nbsp;        vision_recalc(1);
&nbsp;    newsym(x, y);
&nbsp;    if (cansee(x, y))
&nbsp;        Norep("%s", msg);
&nbsp;    if ((otmp = sobj_at(BOULDER, x, y)) != 0) {
&nbsp;        if (cansee(x, y))
&nbsp;            pline("%s settles...", An(xname(otmp)));
&nbsp;        do {
&nbsp;            obj_extract_self(otmp); /* boulder isn't being pushed */
&nbsp;            if (!boulder_hits_pool(otmp, x, y, FALSE))
&nbsp;                impossible("melt_ice: no pool?");
&nbsp;            /* try again if there's another boulder and pool didn't fill */
&nbsp;        } while (is_pool(x, y) &amp;&amp; (otmp = sobj_at(BOULDER, x, y)) != 0);
&nbsp;        newsym(x, y);
&nbsp;    }
&nbsp;    if (x == u.ux &amp;&amp; y == u.uy)
&nbsp;        spoteffects(TRUE); /* possibly drown, notice objects */
&nbsp;}
&nbsp;
&nbsp;#define MIN_ICE_TIME 50
&nbsp;#define MAX_ICE_TIME 2000
start_melt_ice_timeout
&nbsp;/*
&nbsp; * Usually start a melt_ice timer; sometimes the ice will become
&nbsp; * permanent instead.
&nbsp; */
&nbsp;void
&nbsp;start_melt_ice_timeout(x, y, min_time)
&nbsp;xchar x, y;
&nbsp;long min_time; /* <x,y>'s old melt timeout (deleted by time we get here) */
&nbsp;{
&nbsp;    int when;
&nbsp;    long where;
&nbsp;
&nbsp;    when = (int) min_time;
&nbsp;    if (when &lt; MIN_ICE_TIME - 1)
&nbsp;        when = MIN_ICE_TIME - 1;
&nbsp;
&nbsp;    /* random timeout; surrounding ice locations ought to be a factor... */
&nbsp;    while (++when &lt;= MAX_ICE_TIME)
&nbsp;        if (!rn2((MAX_ICE_TIME - when) + MIN_ICE_TIME))
&nbsp;            break;
&nbsp;
&nbsp;    /* if we're within MAX_ICE_TIME, install a melt timer;
&nbsp;       otherwise, omit it to leave this ice permanent */
&nbsp;    if (when &lt;= MAX_ICE_TIME) {
&nbsp;        where = ((long) x &lt;&lt; 16) | (long) y;
&nbsp;        (void) start_timer((long) when, TIMER_LEVEL, MELT_ICE_AWAY,
&nbsp;                           long_to_any(where));
&nbsp;    }
&nbsp;}
&nbsp;#undef MIN_ICE_TIME
&nbsp;#undef MAX_ICE_TIME
&nbsp;
melt_ice_away
&nbsp;/*
&nbsp; * Called when ice has melted completely away.
&nbsp; */
&nbsp;void
&nbsp;melt_ice_away(arg, timeout)
&nbsp;anything *arg;
&nbsp;long timeout UNUSED;
&nbsp;{
&nbsp;    xchar x, y;
&nbsp;    long where = arg-&gt;a_long;
&nbsp;
&nbsp;    y = (xchar) (where &amp; 0xFFFF);
&nbsp;    x = (xchar) ((where &gt;&gt; 16) &amp; 0xFFFF);
&nbsp;    /* melt_ice does newsym when appropriate */
&nbsp;    melt_ice(x, y, "Some ice melts away.");
&nbsp;}
&nbsp;
zap_over_floor
&nbsp;/* Burn floor scrolls, evaporate pools, etc... in a single square.
&nbsp; * Used both for normal bolts of fire, cold, etc... and for fireballs.
&nbsp; * Sets shopdamage to TRUE if a shop door is destroyed, and returns the
&nbsp; * amount by which range is reduced (the latter is just ignored by fireballs)
&nbsp; */
&nbsp;int
&nbsp;zap_over_floor(x, y, type, shopdamage, exploding_wand_typ)
&nbsp;xchar x, y;
&nbsp;int type;
&nbsp;boolean *shopdamage;
&nbsp;short exploding_wand_typ;
&nbsp;{
&nbsp;    const char *zapverb;
&nbsp;    struct monst *mon;
&nbsp;    struct trap *t;
&nbsp;    struct rm *lev = &amp;levl[x][y];
&nbsp;    boolean see_it = cansee(x, y), yourzap;
&nbsp;    int rangemod = 0, abstype = abs(type) % 10;
&nbsp;
&nbsp;    switch (abstype) {
&nbsp;    case ZT_FIRE:
&nbsp;        t = t_at(x, y);
&nbsp;        if (t &amp;&amp; t-&gt;ttyp == WEB) {
&nbsp;            /* a burning web is too flimsy to notice if you can't see it */
&nbsp;            if (see_it)
&nbsp;                Norep("A web bursts into flames!");
&nbsp;            (void) delfloortrap(t);
&nbsp;            if (see_it)
&nbsp;                newsym(x, y);
&nbsp;        }
&nbsp;        if (is_ice(x, y)) {
&nbsp;            melt_ice(x, y, (char *) 0);
&nbsp;        } else if (is_pool(x, y)) {
&nbsp;            const char *msgtxt = "You hear hissing gas.";
&nbsp;
&nbsp;            if (lev-&gt;typ != POOL) { /* MOAT or DRAWBRIDGE_UP */
&nbsp;                if (see_it)
&nbsp;                    msgtxt = "Some water evaporates.";
&nbsp;            } else {
&nbsp;                rangemod -= 3;
&nbsp;                lev-&gt;typ = ROOM;
&nbsp;                t = maketrap(x, y, PIT);
&nbsp;                if (t)
&nbsp;                    t-&gt;tseen = 1;
&nbsp;                if (see_it)
&nbsp;                    msgtxt = "The water evaporates.";
&nbsp;            }
&nbsp;            Norep("%s", msgtxt);
&nbsp;            if (lev-&gt;typ == ROOM)
&nbsp;                newsym(x, y);
&nbsp;        } else if (IS_FOUNTAIN(lev-&gt;typ)) {
&nbsp;            if (see_it)
&nbsp;                pline("Steam billows from the fountain.");
&nbsp;            rangemod -= 1;
&nbsp;            dryup(x, y, type &gt; 0);
&nbsp;        }
&nbsp;        break; /* ZT_FIRE */
&nbsp;
&nbsp;    case ZT_COLD:
&nbsp;        if (is_pool(x, y) || is_lava(x, y)) {
&nbsp;            boolean lava = is_lava(x, y),
&nbsp;                    moat = is_moat(x, y);
&nbsp;
&nbsp;            if (lev-&gt;typ == WATER) {
&nbsp;                /* For now, don't let WATER freeze. */
&nbsp;                if (see_it)
&nbsp;                    pline_The("%s freezes for a moment.", hliquid("water"));
&nbsp;                else
&nbsp;                    You_hear("a soft crackling.");
&nbsp;                rangemod -= 1000; /* stop */
&nbsp;            } else {
&nbsp;                char buf[BUFSZ];
&nbsp;
&nbsp;                Strcpy(buf, waterbody_name(x, y)); /* for MOAT */
&nbsp;                rangemod -= 3;
&nbsp;                if (lev-&gt;typ == DRAWBRIDGE_UP) {
&nbsp;                    lev-&gt;drawbridgemask &amp;= ~DB_UNDER; /* clear lava */
&nbsp;                    lev-&gt;drawbridgemask |= (lava ? DB_FLOOR : DB_ICE);
&nbsp;                } else {
&nbsp;                    if (!lava)
&nbsp;                        lev-&gt;icedpool = (lev-&gt;typ == POOL) ? ICED_POOL
&nbsp;                                                           : ICED_MOAT;
&nbsp;                    lev-&gt;typ = lava ? ROOM : ICE;
&nbsp;                }
&nbsp;                bury_objs(x, y);
&nbsp;                if (see_it) {
&nbsp;                    if (lava)
&nbsp;                        Norep("The %s cools and solidifies.", hliquid("lava"));
&nbsp;                    else if (moat)
&nbsp;                        Norep("The %s is bridged with ice!", buf);
&nbsp;                    else
&nbsp;                        Norep("The %s freezes.", hliquid("water"));
&nbsp;                    newsym(x, y);
&nbsp;                } else if (!lava)
&nbsp;                    You_hear("a crackling sound.");
&nbsp;
&nbsp;                if (x == u.ux &amp;&amp; y == u.uy) {
&nbsp;                    if (u.uinwater) { /* not just `if (Underwater)' */
&nbsp;                        /* leave the no longer existent water */
&nbsp;                        u.uinwater = 0;
&nbsp;                        u.uundetected = 0;
&nbsp;                        docrt();
&nbsp;                        vision_full_recalc = 1;
&nbsp;                    } else if (u.utrap &amp;&amp; u.utraptype == TT_LAVA) {
&nbsp;                        if (Passes_walls) {
&nbsp;                            u.utrap = 0;
&nbsp;                            You("pass through the now-solid rock.");
&nbsp;                        } else {
&nbsp;                            u.utrap = rn1(50, 20);
&nbsp;                            u.utraptype = TT_INFLOOR;
&nbsp;                            You("are firmly stuck in the cooling rock.");
&nbsp;                        }
&nbsp;                    }
&nbsp;                } else if ((mon = m_at(x, y)) != 0) {
&nbsp;                    /* probably ought to do some hefty damage to any
&nbsp;                       non-ice creature caught in freezing water;
&nbsp;                       at a minimum, eels are forced out of hiding */
&nbsp;                    if (is_swimmer(mon-&gt;data) &amp;&amp; mon-&gt;mundetected) {
&nbsp;                        mon-&gt;mundetected = 0;
&nbsp;                        newsym(x, y);
&nbsp;                    }
&nbsp;                }
&nbsp;                if (!lava) {
&nbsp;                    start_melt_ice_timeout(x, y, 0L);
&nbsp;                    obj_ice_effects(x, y, TRUE);
&nbsp;                }
&nbsp;            } /* ?WATER */
&nbsp;
&nbsp;        } else if (is_ice(x, y)) {
&nbsp;            long melt_time;
&nbsp;
&nbsp;            /* Already ice here, so just firm it up. */
&nbsp;            /* Now ensure that only ice that is already timed is affected */
&nbsp;            if ((melt_time = spot_time_left(x, y, MELT_ICE_AWAY)) != 0L) {
&nbsp;                spot_stop_timers(x, y, MELT_ICE_AWAY);
&nbsp;                start_melt_ice_timeout(x, y, melt_time);
&nbsp;            }
&nbsp;        }
&nbsp;        break; /* ZT_COLD */
&nbsp;
&nbsp;    case ZT_POISON_GAS:
&nbsp;        (void) create_gas_cloud(x, y, 1, 8);
&nbsp;        break;
&nbsp;
&nbsp;    case ZT_ACID:
&nbsp;        if (lev-&gt;typ == IRONBARS) {
&nbsp;            if ((lev-&gt;wall_info &amp; W_NONDIGGABLE) != 0) {
&nbsp;                if (see_it)
&nbsp;                    Norep("The %s corrode somewhat but remain intact.",
&nbsp;                          defsyms[S_bars].explanation);
&nbsp;                /* but nothing actually happens... */
&nbsp;            } else {
&nbsp;                rangemod -= 3;
&nbsp;                if (see_it)
&nbsp;                    Norep("The %s melt.", defsyms[S_bars].explanation);
&nbsp;                if (*in_rooms(x, y, SHOPBASE)) {
&nbsp;                    /* in case we ever have a shop bounded by bars */
&nbsp;                    lev-&gt;typ = ROOM;
&nbsp;                    if (see_it)
&nbsp;                        newsym(x, y);
&nbsp;                    add_damage(x, y, (type &gt;= 0) ? SHOP_BARS_COST : 0L);
&nbsp;                    if (type &gt;= 0)
&nbsp;                        *shopdamage = TRUE;
&nbsp;                } else {
&nbsp;                    lev-&gt;typ = DOOR;
&nbsp;                    lev-&gt;doormask = D_NODOOR;
&nbsp;                    if (see_it)
&nbsp;                        newsym(x, y);
&nbsp;                }
&nbsp;            }
&nbsp;        }
&nbsp;        break; /* ZT_ACID */
&nbsp;
&nbsp;    default:
&nbsp;        break;
&nbsp;    }
&nbsp;
&nbsp;    /* set up zap text for possible door feedback; for exploding wand, we
&nbsp;       want "the blast" rather than "your blast" even if hero caused it */
&nbsp;    yourzap = (type &gt;= 0 &amp;&amp; !exploding_wand_typ);
&nbsp;    zapverb = "blast"; /* breath attack or wand explosion */
&nbsp;    if (!exploding_wand_typ) {
&nbsp;        if (abs(type) &lt; ZT_SPELL(0))
&nbsp;            zapverb = "bolt"; /* wand zap */
&nbsp;        else if (abs(type) &lt; ZT_BREATH(0))
&nbsp;            zapverb = "spell";
&nbsp;    }
&nbsp;
&nbsp;    /* secret door gets revealed, converted into regular door */
&nbsp;    if (levl[x][y].typ == SDOOR) {
&nbsp;        cvt_sdoor_to_door(&amp;levl[x][y]); /* .typ = DOOR */
&nbsp;        /* target spot will now pass closed_door() test below
&nbsp;           (except on rogue level) */
&nbsp;        newsym(x, y);
&nbsp;        if (see_it)
&nbsp;            pline("%s %s reveals a secret door.",
&nbsp;                  yourzap ? "Your" : "The", zapverb);
&nbsp;        else if (Is_rogue_level(&amp;u.uz))
&nbsp;            draft_message(FALSE); /* "You feel a draft." (open doorway) */
&nbsp;    }
&nbsp;
&nbsp;    /* regular door absorbs remaining zap range, possibly gets destroyed */
&nbsp;    if (closed_door(x, y)) {
&nbsp;        int new_doormask = -1;
&nbsp;        const char *see_txt = 0, *sense_txt = 0, *hear_txt = 0;
&nbsp;
&nbsp;        rangemod = -1000;
&nbsp;        switch (abstype) {
&nbsp;        case ZT_FIRE:
&nbsp;            new_doormask = D_NODOOR;
&nbsp;            see_txt = "The door is consumed in flames!";
&nbsp;            sense_txt = "smell smoke.";
&nbsp;            break;
&nbsp;        case ZT_COLD:
&nbsp;            new_doormask = D_NODOOR;
&nbsp;            see_txt = "The door freezes and shatters!";
&nbsp;            sense_txt = "feel cold.";
&nbsp;            break;
&nbsp;        case ZT_DEATH:
&nbsp;            /* death spells/wands don't disintegrate */
&nbsp;            if (abs(type) != ZT_BREATH(ZT_DEATH))
&nbsp;                goto def_case;
&nbsp;            new_doormask = D_NODOOR;
&nbsp;            see_txt = "The door disintegrates!";
&nbsp;            hear_txt = "crashing wood.";
&nbsp;            break;
&nbsp;        case ZT_LIGHTNING:
&nbsp;            new_doormask = D_BROKEN;
&nbsp;            see_txt = "The door splinters!";
&nbsp;            hear_txt = "crackling.";
&nbsp;            break;
&nbsp;        default:
&nbsp;        def_case:
&nbsp;            if (exploding_wand_typ &gt; 0) {
&nbsp;                /* Magical explosion from misc exploding wand */
&nbsp;                if (exploding_wand_typ == WAN_STRIKING) {
&nbsp;                    new_doormask = D_BROKEN;
&nbsp;                    see_txt = "The door crashes open!";
&nbsp;                    sense_txt = "feel a burst of cool air.";
&nbsp;                    break;
&nbsp;                }
&nbsp;            }
&nbsp;            if (see_it) {
&nbsp;                /* "the door absorbs the blast" would be
&nbsp;                   inaccurate for an exploding wand since
&nbsp;                   other adjacent locations still get hit */
&nbsp;                if (exploding_wand_typ)
&nbsp;                    pline_The("door remains intact.");
&nbsp;                else
&nbsp;                    pline_The("door absorbs %s %s!", yourzap ? "your" : "the",
&nbsp;                              zapverb);
&nbsp;            } else
&nbsp;                You_feel("vibrations.");
&nbsp;            break;
&nbsp;        }
&nbsp;        if (new_doormask &gt;= 0) { /* door gets broken */
&nbsp;            if (*in_rooms(x, y, SHOPBASE)) {
&nbsp;                if (type &gt;= 0) {
&nbsp;                    add_damage(x, y, SHOP_DOOR_COST);
&nbsp;                    *shopdamage = TRUE;
&nbsp;                } else /* caused by monster */
&nbsp;                    add_damage(x, y, 0L);
&nbsp;            }
&nbsp;            lev-&gt;doormask = new_doormask;
&nbsp;            unblock_point(x, y); /* vision */
&nbsp;            if (see_it) {
&nbsp;                pline1(see_txt);
&nbsp;                newsym(x, y);
&nbsp;            } else if (sense_txt) {
&nbsp;                You1(sense_txt);
&nbsp;            } else if (hear_txt)
&nbsp;                You_hear1(hear_txt);
&nbsp;            if (picking_at(x, y)) {
&nbsp;                stop_occupation();
&nbsp;                reset_pick();
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    if (OBJ_AT(x, y) &amp;&amp; abstype == ZT_FIRE)
&nbsp;        if (burn_floor_objects(x, y, FALSE, type &gt; 0) &amp;&amp; couldsee(x, y)) {
&nbsp;            newsym(x, y);
&nbsp;            You("%s of smoke.", !Blind ? "see a puff" : "smell a whiff");
&nbsp;        }
&nbsp;    if ((mon = m_at(x, y)) != 0) {
&nbsp;        wakeup(mon, FALSE);
&nbsp;        if (type &gt;= 0) {
&nbsp;            setmangry(mon, TRUE);
&nbsp;            if (mon-&gt;ispriest &amp;&amp; *in_rooms(mon-&gt;mx, mon-&gt;my, TEMPLE))
&nbsp;                ghod_hitsu(mon);
&nbsp;            if (mon-&gt;isshk &amp;&amp; !*u.ushops)
&nbsp;                hot_pursuit(mon);
&nbsp;        }
&nbsp;    }
&nbsp;    return rangemod;
&nbsp;}
&nbsp;
fracture_rock
&nbsp;/* fractured by pick-axe or wand of striking */
&nbsp;void
&nbsp;fracture_rock(obj)
&nbsp;register struct obj *obj; /* no texts here! */
&nbsp;{
&nbsp;    xchar x, y;
&nbsp;    boolean by_you = !context.mon_moving;
&nbsp;
&nbsp;    if (by_you &amp;&amp; get_obj_location(obj, &amp;x, &amp;y, 0) &amp;&amp; costly_spot(x, y)) {
&nbsp;        struct monst *shkp = 0;
&nbsp;        char objroom = *in_rooms(x, y, SHOPBASE);
&nbsp;
&nbsp;        if (billable(&amp;shkp, obj, objroom, FALSE)) {
&nbsp;            /* shop message says "you owe <shk> &lt;$&gt; for it!" so we need
&nbsp;               to precede that with a message explaining what "it" is */
&nbsp;            You("fracture %s %s.", s_suffix(shkname(shkp)), xname(obj));
&nbsp;            breakobj(obj, x, y, TRUE, FALSE); /* charges for shop goods */
&nbsp;        }
&nbsp;    }
&nbsp;    if (by_you &amp;&amp; obj-&gt;otyp == BOULDER)
&nbsp;        sokoban_guilt();
&nbsp;
&nbsp;    obj-&gt;otyp = ROCK;
&nbsp;    obj-&gt;oclass = GEM_CLASS;
&nbsp;    obj-&gt;quan = (long) rn1(60, 7);
&nbsp;    obj-&gt;owt = weight(obj);
&nbsp;    obj-&gt;dknown = obj-&gt;bknown = obj-&gt;rknown = 0;
&nbsp;    obj-&gt;known = objects[obj-&gt;otyp].oc_uses_known ? 0 : 1;
&nbsp;    dealloc_oextra(obj);
&nbsp;
&nbsp;    if (obj-&gt;where == OBJ_FLOOR) {
&nbsp;        obj_extract_self(obj); /* move rocks back on top */
&nbsp;        place_object(obj, obj-&gt;ox, obj-&gt;oy);
&nbsp;        if (!does_block(obj-&gt;ox, obj-&gt;oy, &amp;levl[obj-&gt;ox][obj-&gt;oy]))
&nbsp;            unblock_point(obj-&gt;ox, obj-&gt;oy);
&nbsp;        if (cansee(obj-&gt;ox, obj-&gt;oy))
&nbsp;            newsym(obj-&gt;ox, obj-&gt;oy);
&nbsp;    }
&nbsp;}
&nbsp;
break_statue
&nbsp;/* handle statue hit by striking/force bolt/pick-axe */
&nbsp;boolean
&nbsp;break_statue(obj)
&nbsp;register struct obj *obj;
&nbsp;{
&nbsp;    /* [obj is assumed to be on floor, so no get_obj_location() needed] */
&nbsp;    struct trap *trap = t_at(obj-&gt;ox, obj-&gt;oy);
&nbsp;    struct obj *item;
&nbsp;    boolean by_you = !context.mon_moving;
&nbsp;
&nbsp;    if (trap &amp;&amp; trap-&gt;ttyp == STATUE_TRAP
&nbsp;        &amp;&amp; activate_statue_trap(trap, obj-&gt;ox, obj-&gt;oy, TRUE))
&nbsp;        return FALSE;
&nbsp;    /* drop any objects contained inside the statue */
&nbsp;    while ((item = obj-&gt;cobj) != 0) {
&nbsp;        obj_extract_self(item);
&nbsp;        place_object(item, obj-&gt;ox, obj-&gt;oy);
&nbsp;    }
&nbsp;    if (by_you &amp;&amp; Role_if(PM_ARCHEOLOGIST) &amp;&amp; (obj-&gt;spe &amp; STATUE_HISTORIC)) {
&nbsp;        You_feel("guilty about damaging such a historic statue.");
&nbsp;        adjalign(-1);
&nbsp;    }
&nbsp;    obj-&gt;spe = 0;
&nbsp;    fracture_rock(obj);
&nbsp;    return TRUE;
&nbsp;}
&nbsp;
&nbsp;/*
&nbsp; * destroy_strings[dindx][0:singular,1:plural,2:killer_reason]
&nbsp; *      [0] freezing potion
&nbsp; *      [1] boiling potion other than oil
&nbsp; *      [2] boiling potion of oil
&nbsp; *      [3] burning scroll
&nbsp; *      [4] burning spellbook
&nbsp; *      [5] shocked ring
&nbsp; *      [6] shocked wand
&nbsp; * (books, rings, and wands don't stack so don't need plural form;
&nbsp; *  crumbling ring doesn't do damage so doesn't need killer reason)
&nbsp; */
&nbsp;const char *const destroy_strings[][3] = {
&nbsp;    /* also used in trap.c */
&nbsp;    { "freezes and shatters", "freeze and shatter", "shattered potion" },
&nbsp;    { "boils and explodes", "boil and explode", "boiling potion" },
&nbsp;    { "ignites and explodes", "ignite and explode", "exploding potion" },
&nbsp;    { "catches fire and burns", "catch fire and burn", "burning scroll" },
&nbsp;    { "catches fire and burns", "", "burning book" },
&nbsp;    { "turns to dust and vanishes", "", "" },
&nbsp;    { "breaks apart and explodes", "", "exploding wand" },
&nbsp;};
&nbsp;
destroy_item
&nbsp;void
&nbsp;destroy_item(osym, dmgtyp)
&nbsp;register int osym, dmgtyp;
&nbsp;{
&nbsp;    register struct obj *obj, *obj2;
&nbsp;    int dmg, xresist, skip;
&nbsp;    long i, cnt, quan;
&nbsp;    int dindx;
&nbsp;    const char *mult;
&nbsp;    boolean physical_damage;
&nbsp;
&nbsp;    for (obj = invent; obj; obj = obj2) {
&nbsp;        obj2 = obj-&gt;nobj;
&nbsp;        physical_damage = FALSE;
&nbsp;        if (obj-&gt;oclass != osym)
&nbsp;            continue; /* test only objs of type osym */
&nbsp;        if (obj-&gt;oartifact)
&nbsp;            continue; /* don't destroy artifacts */
&nbsp;        if (obj-&gt;in_use &amp;&amp; obj-&gt;quan == 1L)
&nbsp;            continue; /* not available */
&nbsp;        xresist = skip = 0;
&nbsp;        /* lint suppression */
&nbsp;        dmg = dindx = 0;
&nbsp;        quan = 0L;
&nbsp;
&nbsp;        switch (dmgtyp) {
&nbsp;        case AD_COLD:
&nbsp;            if (osym == POTION_CLASS &amp;&amp; obj-&gt;otyp != POT_OIL) {
&nbsp;                quan = obj-&gt;quan;
&nbsp;                dindx = 0;
&nbsp;                dmg = rnd(4);
&nbsp;            } else
&nbsp;                skip++;
&nbsp;            break;
&nbsp;        case AD_FIRE:
&nbsp;            xresist = (Fire_resistance &amp;&amp; obj-&gt;oclass != POTION_CLASS
&nbsp;                       &amp;&amp; obj-&gt;otyp != GLOB_OF_GREEN_SLIME);
&nbsp;
&nbsp;            if (obj-&gt;otyp == SCR_FIRE || obj-&gt;otyp == SPE_FIREBALL)
&nbsp;                skip++;
&nbsp;            if (obj-&gt;otyp == SPE_BOOK_OF_THE_DEAD) {
&nbsp;                skip++;
&nbsp;                if (!Blind)
&nbsp;                    pline("%s glows a strange %s, but remains intact.",
&nbsp;                          The(xname(obj)), hcolor("dark red"));
&nbsp;            }
&nbsp;            quan = obj-&gt;quan;
&nbsp;            switch (osym) {
&nbsp;            case POTION_CLASS:
&nbsp;                dindx = (obj-&gt;otyp != POT_OIL) ? 1 : 2;
&nbsp;                dmg = rnd(6);
&nbsp;                break;
&nbsp;            case SCROLL_CLASS:
&nbsp;                dindx = 3;
&nbsp;                dmg = 1;
&nbsp;                break;
&nbsp;            case SPBOOK_CLASS:
&nbsp;                dindx = 4;
&nbsp;                dmg = 1;
&nbsp;                break;
&nbsp;            case FOOD_CLASS:
&nbsp;                if (obj-&gt;otyp == GLOB_OF_GREEN_SLIME) {
&nbsp;                    dindx = 1; /* boil and explode */
&nbsp;                    dmg = (obj-&gt;owt + 19) / 20;
&nbsp;                } else {
&nbsp;                    skip++;
&nbsp;                }
&nbsp;                break;
&nbsp;            default:
&nbsp;                skip++;
&nbsp;                break;
&nbsp;            }
&nbsp;            break;
&nbsp;        case AD_ELEC:
&nbsp;            xresist = (Shock_resistance &amp;&amp; obj-&gt;oclass != RING_CLASS);
&nbsp;            quan = obj-&gt;quan;
&nbsp;            switch (osym) {
&nbsp;            case RING_CLASS:
&nbsp;                if (obj-&gt;otyp == RIN_SHOCK_RESISTANCE) {
&nbsp;                    skip++;
&nbsp;                    break;
&nbsp;                }
&nbsp;                dindx = 5;
&nbsp;                dmg = 0;
&nbsp;                break;
&nbsp;            case WAND_CLASS:
&nbsp;                if (obj-&gt;otyp == WAN_LIGHTNING) {
&nbsp;                    skip++;
&nbsp;                    break;
&nbsp;                }
&nbsp;#if 0
&nbsp;                if (obj == current_wand) {  skip++;  break;  }
&nbsp;#endif
&nbsp;                dindx = 6;
&nbsp;                dmg = rnd(10);
&nbsp;                break;
&nbsp;            default:
&nbsp;                skip++;
&nbsp;                break;
&nbsp;            }
&nbsp;            break;
&nbsp;        default:
&nbsp;            skip++;
&nbsp;            break;
&nbsp;        }
&nbsp;        if (!skip) {
&nbsp;            if (obj-&gt;in_use)
&nbsp;                --quan; /* one will be used up elsewhere */
&nbsp;            for (i = cnt = 0L; i &lt; quan; i++)
&nbsp;                if (!rn2(3))
&nbsp;                    cnt++;
&nbsp;
&nbsp;            if (!cnt)
&nbsp;                continue;
&nbsp;            mult = (cnt == 1L)
&nbsp;                   ? (quan == 1L) ? "Your"                        /* 1 of 1 */
&nbsp;                                  : "One of your"                 /* 1 of N */
&nbsp;                   : (cnt &lt; quan) ? "Some of your"                /* n of N */
&nbsp;                                  : (quan == 2L) ? "Both of your" /* 2 of 2 */
&nbsp;                                                 : "All of your"; /* N of N */
&nbsp;            pline("%s %s %s!", mult, xname(obj),
&nbsp;                  destroy_strings[dindx][(cnt &gt; 1L)]);
&nbsp;            if (osym == POTION_CLASS &amp;&amp; dmgtyp != AD_COLD) {
&nbsp;                if (!breathless(youmonst.data) || haseyes(youmonst.data))
&nbsp;                    potionbreathe(obj);
&nbsp;            }
&nbsp;            if (obj-&gt;owornmask) {
&nbsp;                if (obj-&gt;owornmask &amp; W_RING) /* ring being worn */
&nbsp;                    Ring_gone(obj);
&nbsp;                else
&nbsp;                    setnotworn(obj);
&nbsp;            }
&nbsp;            if (obj == current_wand)
&nbsp;                current_wand = 0; /* destroyed */
&nbsp;            for (i = 0; i &lt; cnt; i++)
&nbsp;                useup(obj);
&nbsp;            if (dmg) {
&nbsp;                if (xresist)
&nbsp;                    You("aren't hurt!");
&nbsp;                else {
&nbsp;                    const char *how = destroy_strings[dindx][2];
&nbsp;                    boolean one = (cnt == 1L);
&nbsp;
&nbsp;                    if (dmgtyp == AD_FIRE &amp;&amp; osym == FOOD_CLASS)
&nbsp;                        how = "exploding glob of slime";
&nbsp;                    if (physical_damage)
&nbsp;                        dmg = Maybe_Half_Phys(dmg);
&nbsp;                    losehp(dmg, one ? how : (const char *) makeplural(how),
&nbsp;                           one ? KILLED_BY_AN : KILLED_BY);
&nbsp;                    exercise(A_STR, FALSE);
&nbsp;                }
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;    return;
&nbsp;}
&nbsp;
destroy_mitem
&nbsp;int
&nbsp;destroy_mitem(mtmp, osym, dmgtyp)
&nbsp;struct monst *mtmp;
&nbsp;int osym, dmgtyp;
&nbsp;{
&nbsp;    struct obj *obj, *obj2;
&nbsp;    int skip, tmp = 0;
&nbsp;    long i, cnt, quan;
&nbsp;    int dindx;
&nbsp;    boolean vis;
&nbsp;
&nbsp;    if (mtmp == &amp;youmonst) { /* this simplifies artifact_hit() */
&nbsp;        destroy_item(osym, dmgtyp);
&nbsp;        return 0; /* arbitrary; value doesn't matter to artifact_hit() */
&nbsp;    }
&nbsp;
&nbsp;    vis = canseemon(mtmp);
&nbsp;    for (obj = mtmp-&gt;minvent; obj; obj = obj2) {
&nbsp;        obj2 = obj-&gt;nobj;
&nbsp;        if (obj-&gt;oclass != osym)
&nbsp;            continue; /* test only objs of type osym */
&nbsp;        skip = 0;
&nbsp;        quan = 0L;
&nbsp;        dindx = 0;
&nbsp;
&nbsp;        switch (dmgtyp) {
&nbsp;        case AD_COLD:
&nbsp;            if (osym == POTION_CLASS &amp;&amp; obj-&gt;otyp != POT_OIL) {
&nbsp;                quan = obj-&gt;quan;
&nbsp;                dindx = 0;
&nbsp;                tmp++;
&nbsp;            } else
&nbsp;                skip++;
&nbsp;            break;
&nbsp;        case AD_FIRE:
&nbsp;            if (obj-&gt;otyp == SCR_FIRE || obj-&gt;otyp == SPE_FIREBALL)
&nbsp;                skip++;
&nbsp;            if (obj-&gt;otyp == SPE_BOOK_OF_THE_DEAD) {
&nbsp;                skip++;
&nbsp;                if (vis)
&nbsp;                    pline("%s glows a strange %s, but remains intact.",
&nbsp;                          The(distant_name(obj, xname)), hcolor("dark red"));
&nbsp;            }
&nbsp;            quan = obj-&gt;quan;
&nbsp;            switch (osym) {
&nbsp;            case POTION_CLASS:
&nbsp;                dindx = (obj-&gt;otyp != POT_OIL) ? 1 : 2;
&nbsp;                tmp++;
&nbsp;                break;
&nbsp;            case SCROLL_CLASS:
&nbsp;                dindx = 3;
&nbsp;                tmp++;
&nbsp;                break;
&nbsp;            case SPBOOK_CLASS:
&nbsp;                dindx = 4;
&nbsp;                tmp++;
&nbsp;                break;
&nbsp;            case FOOD_CLASS:
&nbsp;                if (obj-&gt;otyp == GLOB_OF_GREEN_SLIME) {
&nbsp;                    dindx = 1; /* boil and explode */
&nbsp;                    tmp += (obj-&gt;owt + 19) / 20;
&nbsp;                } else {
&nbsp;                    skip++;
&nbsp;                }
&nbsp;                break;
&nbsp;            default:
&nbsp;                skip++;
&nbsp;                break;
&nbsp;            }
&nbsp;            break;
&nbsp;        case AD_ELEC:
&nbsp;            quan = obj-&gt;quan;
&nbsp;            switch (osym) {
&nbsp;            case RING_CLASS:
&nbsp;                if (obj-&gt;otyp == RIN_SHOCK_RESISTANCE) {
&nbsp;                    skip++;
&nbsp;                    break;
&nbsp;                }
&nbsp;                dindx = 5;
&nbsp;                break;
&nbsp;            case WAND_CLASS:
&nbsp;                if (obj-&gt;otyp == WAN_LIGHTNING) {
&nbsp;                    skip++;
&nbsp;                    break;
&nbsp;                }
&nbsp;                dindx = 6;
&nbsp;                tmp++;
&nbsp;                break;
&nbsp;            default:
&nbsp;                skip++;
&nbsp;                break;
&nbsp;            }
&nbsp;            break;
&nbsp;        default:
&nbsp;            skip++;
&nbsp;            break;
&nbsp;        }
&nbsp;        if (!skip) {
&nbsp;            for (i = cnt = 0L; i &lt; quan; i++)
&nbsp;                if (!rn2(3))
&nbsp;                    cnt++;
&nbsp;
&nbsp;            if (!cnt)
&nbsp;                continue;
&nbsp;            if (vis)
&nbsp;                pline("%s%s %s!",
&nbsp;                      (cnt == obj-&gt;quan) ? "" : (cnt &gt; 1L) ? "Some of "
&nbsp;                                                           : "One of ",
&nbsp;                      (cnt == obj-&gt;quan) ? Yname2(obj) : yname(obj),
&nbsp;                      destroy_strings[dindx][(cnt &gt; 1L)]);
&nbsp;            for (i = 0; i &lt; cnt; i++)
&nbsp;                m_useup(mtmp, obj);
&nbsp;        }
&nbsp;    }
&nbsp;    return tmp;
&nbsp;}
&nbsp;
resist
&nbsp;int
&nbsp;resist(mtmp, oclass, damage, tell)
&nbsp;struct monst *mtmp;
&nbsp;char oclass;
&nbsp;int damage, tell;
&nbsp;{
&nbsp;    int resisted;
&nbsp;    int alev, dlev;
&nbsp;
&nbsp;    /* attack level */
&nbsp;    switch (oclass) {
&nbsp;    case WAND_CLASS:
&nbsp;        alev = 12;
&nbsp;        break;
&nbsp;    case TOOL_CLASS:
&nbsp;        alev = 10;
&nbsp;        break; /* instrument */
&nbsp;    case WEAPON_CLASS:
&nbsp;        alev = 10;
&nbsp;        break; /* artifact */
&nbsp;    case SCROLL_CLASS:
&nbsp;        alev = 9;
&nbsp;        break;
&nbsp;    case POTION_CLASS:
&nbsp;        alev = 6;
&nbsp;        break;
&nbsp;    case RING_CLASS:
&nbsp;        alev = 5;
&nbsp;        break;
&nbsp;    default:
&nbsp;        alev = u.ulevel;
&nbsp;        break; /* spell */
&nbsp;    }
&nbsp;    /* defense level */
&nbsp;    dlev = (int) mtmp-&gt;m_lev;
&nbsp;    if (dlev &gt; 50)
&nbsp;        dlev = 50;
&nbsp;    else if (dlev &lt; 1)
&nbsp;        dlev = is_mplayer(mtmp-&gt;data) ? u.ulevel : 1;
&nbsp;
&nbsp;    resisted = rn2(100 + alev - dlev) &lt; mtmp-&gt;data-&gt;mr;
&nbsp;    if (resisted) {
&nbsp;        if (tell) {
&nbsp;            shieldeff(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;            pline("%s resists!", Monnam(mtmp));
&nbsp;        }
&nbsp;        damage = (damage + 1) / 2;
&nbsp;    }
&nbsp;
&nbsp;    if (damage) {
&nbsp;        mtmp-&gt;mhp -= damage;
&nbsp;        if (mtmp-&gt;mhp &lt; 1) {
&nbsp;            if (m_using)
&nbsp;                monkilled(mtmp, "", AD_RBRE);
&nbsp;            else
&nbsp;                killed(mtmp);
&nbsp;        }
&nbsp;    }
&nbsp;    return resisted;
&nbsp;}
&nbsp;
&nbsp;#define MAXWISHTRY 5
&nbsp;
wishcmdassist
&nbsp;STATIC_OVL void
&nbsp;wishcmdassist(triesleft)
&nbsp;int triesleft;
&nbsp;{
&nbsp;    static NEARDATA const char *
&nbsp;        wishinfo[] = {
&nbsp;  "Wish details:",
&nbsp;  "",
&nbsp;  "Enter the name of an object, such as \"potion of monster detection\",",
&nbsp;  "\"scroll labeled README\", \"elven mithril-coat\", or \"Grimtooth\"",
&nbsp;  "(without the quotes).",
&nbsp;  "",
&nbsp;  "For object types which come in stacks, you may specify a plural name",
&nbsp;  "such as \"potions of healing\", or specify a count, such as \"1000 gold",
&nbsp;  "pieces\", although that aspect of your wish might not be granted.",
&nbsp;  "",
&nbsp;  "You may also specify various prefix values which might be used to",
&nbsp;  "modify the item, such as \"uncursed\" or \"rustproof\" or \"+1\".",
&nbsp;  "Most modifiers shown when viewing your inventory can be specified.",
&nbsp;  "",
&nbsp;  "You may specify 'nothing' to explicitly decline this wish.",
&nbsp;  0,
&nbsp;    },
&nbsp;        preserve_wishless[] = "Doing so will preserve 'wishless' conduct.",
&nbsp;        retry_info[] =
&nbsp;                    "If you specify an unrecognized object name %s%s time%s,",
&nbsp;        retry_too[] = "a randomly chosen item will be granted.",
&nbsp;        suppress_cmdassist[] =
&nbsp;            "(Suppress this assistance with !cmdassist in your config file.)",
&nbsp;        *cardinals[] = { "zero",  "one",  "two", "three", "four", "five" },
&nbsp;        too_many[] = "too many";
&nbsp;    int i;
&nbsp;    winid win;
&nbsp;    char buf[BUFSZ];
&nbsp;
&nbsp;    win = create_nhwindow(NHW_TEXT);
&nbsp;    if (!win)
&nbsp;        return;
&nbsp;    for (i = 0; i &lt; SIZE(wishinfo) - 1; ++i)
&nbsp;        putstr(win, 0, wishinfo[i]);
&nbsp;    if (!u.uconduct.wishes)
&nbsp;        putstr(win, 0, preserve_wishless);
&nbsp;    putstr(win, 0, "");
&nbsp;    Sprintf(buf, retry_info,
&nbsp;            (triesleft &gt;= 0 &amp;&amp; triesleft &lt; SIZE(cardinals))
&nbsp;               ? cardinals[triesleft]
&nbsp;               : too_many,
&nbsp;            (triesleft &lt; MAXWISHTRY) ? " more" : "",
&nbsp;            plur(triesleft));
&nbsp;    putstr(win, 0, buf);
&nbsp;    putstr(win, 0, retry_too);
&nbsp;    putstr(win, 0, "");
&nbsp;    if (iflags.cmdassist)
&nbsp;        putstr(win, 0, suppress_cmdassist);
&nbsp;    display_nhwindow(win, FALSE);
&nbsp;    destroy_nhwindow(win);
&nbsp;}
&nbsp;
makewish
&nbsp;void
&nbsp;makewish()
&nbsp;{
&nbsp;    static char buf[BUFSZ] = DUMMY;
&nbsp;    char promptbuf[BUFSZ];
&nbsp;    struct obj *otmp, nothing;
&nbsp;    int tries = 0;
&nbsp;
&nbsp;    promptbuf[0] = '\0';
&nbsp;    nothing = zeroobj; /* lint suppression; only its address matters */
&nbsp;    if (flags.verbose)
&nbsp;        You("may wish for an object.");
&nbsp;retry:
&nbsp;    Strcpy(promptbuf, "For what do you wish");
&nbsp;    if (iflags.cmdassist &amp;&amp; tries &gt; 0)
&nbsp;        Strcat(promptbuf, " (enter 'help' for assistance)");
&nbsp;    Strcat(promptbuf, "?");
&nbsp;    getlin(promptbuf, buf);
&nbsp;    (void) mungspaces(buf);
&nbsp;    if (buf[0] == '\033') {
&nbsp;        buf[0] = '\0';
&nbsp;    } else if (!strcmpi(buf, "help")) {
&nbsp;        wishcmdassist(MAXWISHTRY - tries);
&nbsp;        goto retry;
&nbsp;    }
&nbsp;    /*
&nbsp;     *  Note: if they wished for and got a non-object successfully,
&nbsp;     *  otmp == &amp;zeroobj.  That includes gold, or an artifact that
&nbsp;     *  has been denied.  Wishing for "nothing" requires a separate
&nbsp;     *  value to remain distinct.
&nbsp;     */
&nbsp;    otmp = readobjnam(buf, &amp;nothing);
&nbsp;    if (!otmp) {
&nbsp;        pline("Nothing fitting that description exists in the game.");
&nbsp;        if (++tries &lt; MAXWISHTRY)
&nbsp;            goto retry;
&nbsp;        pline1(thats_enough_tries);
&nbsp;        otmp = readobjnam((char *) 0, (struct obj *) 0);
&nbsp;        if (!otmp)
&nbsp;            return; /* for safety; should never happen */
&nbsp;    } else if (otmp == &amp;nothing) {
&nbsp;        /* explicitly wished for "nothing", presumably attempting
&nbsp;           to retain wishless conduct */
&nbsp;        return;
&nbsp;    }
&nbsp;
&nbsp;    /* KMH, conduct */
&nbsp;    u.uconduct.wishes++;
&nbsp;
&nbsp;    if (otmp != &amp;zeroobj) {
&nbsp;        const char
&nbsp;            *verb = ((Is_airlevel(&amp;u.uz) || u.uinwater) ? "slip" : "drop"),
&nbsp;            *oops_msg = (u.uswallow
&nbsp;                         ? "Oops!  %s out of your reach!"
&nbsp;                         : (Is_airlevel(&amp;u.uz) || Is_waterlevel(&amp;u.uz)
&nbsp;                            || levl[u.ux][u.uy].typ &lt; IRONBARS
&nbsp;                            || levl[u.ux][u.uy].typ &gt;= ICE)
&nbsp;                            ? "Oops!  %s away from you!"
&nbsp;                            : "Oops!  %s to the floor!");
&nbsp;
&nbsp;        /* The(aobjnam()) is safe since otmp is unidentified -dlc */
&nbsp;        (void) hold_another_object(otmp, oops_msg,
&nbsp;                                   The(aobjnam(otmp, verb)),
&nbsp;                                   (const char *) 0);
&nbsp;        u.ublesscnt += rn1(100, 50); /* the gods take notice */
&nbsp;    }
&nbsp;}
&nbsp;
&nbsp;/*zap.c*/

</shk></x,y></xx,yy></x,y></u.ux,u.uy></something>