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

Contents

1 Top of file
2 thitu
3 drop_throw
4 monmulti
5 monshoot
6 ohitmon
7 m_throw
8 thrwmm
9 spitmm
10 breamm
11 m_useupall
12 m_useup
13 thrwmu
14 spitmu
15 breamu
16 linedup
17 m_lined_up
18 lined_up
19 m_carrying
20 hit_bars
21 hits_bars

Top of file
&nbsp;/* NetHack 3.6	mthrowu.c	$NHDT-Date: 1514152830 2017/12/24 22:00:30 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.73 $ */
&nbsp;/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
&nbsp;/*-Copyright (c) Pasi Kallinen, 2016. */
&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;STATIC_DCL int FDECL(monmulti, (struct monst *, struct obj *, struct obj *));
&nbsp;STATIC_DCL void FDECL(monshoot, (struct monst *, struct obj *, struct obj *));
&nbsp;STATIC_DCL int FDECL(drop_throw, (struct obj *, BOOLEAN_P, int, int));
&nbsp;STATIC_DCL boolean FDECL(m_lined_up, (struct monst *, struct monst *));
&nbsp;
&nbsp;#define URETREATING(x, y) \
&nbsp;    (distmin(u.ux, u.uy, x, y) &gt; distmin(u.ux0, u.uy0, x, y))
&nbsp;
&nbsp;#define POLE_LIM 5 /* How far monsters can use pole-weapons */
&nbsp;
&nbsp;#define PET_MISSILE_RANGE2 36 /* Square of distance within which pets shoot */
&nbsp;
&nbsp;/*
&nbsp; * Keep consistent with breath weapons in zap.c, and AD_* in monattk.h.
&nbsp; */
&nbsp;STATIC_OVL NEARDATA const char *breathwep[] = {
&nbsp;    "fragments", "fire", "frost", "sleep gas", "a disintegration blast",
&nbsp;    "lightning", "poison gas", "acid", "strange breath #8",
&nbsp;    "strange breath #9"
&nbsp;};
&nbsp;
&nbsp;extern boolean notonhead; /* for long worms */
&nbsp;STATIC_VAR int mesg_given; /* for m_throw()/thitu() 'miss' message */
&nbsp;
thitu
&nbsp;/* hero is hit by something other than a monster */
&nbsp;int
&nbsp;thitu(tlev, dam, objp, name)
&nbsp;int tlev, dam;
&nbsp;struct obj **objp;
&nbsp;const char *name; /* if null, then format `*objp' */
&nbsp;{
&nbsp;    struct obj *obj = objp ? *objp : 0;
&nbsp;    const char *onm, *knm;
&nbsp;    boolean is_acid;
&nbsp;    int kprefix = KILLED_BY_AN, dieroll;
&nbsp;    char onmbuf[BUFSZ], knmbuf[BUFSZ];
&nbsp;
&nbsp;    if (!name) {
&nbsp;        if (!obj)
&nbsp;            panic("thitu: name &amp; obj both null?");
&nbsp;        name = strcpy(onmbuf,
&nbsp;                      (obj-&gt;quan &gt; 1L) ? doname(obj) : mshot_xname(obj));
&nbsp;        knm = strcpy(knmbuf, killer_xname(obj));
&nbsp;        kprefix = KILLED_BY; /* killer_name supplies "an" if warranted */
&nbsp;    } else {
&nbsp;        knm = name;
&nbsp;        /* [perhaps ought to check for plural here to] */
&nbsp;        if (!strncmpi(name, "the ", 4) || !strncmpi(name, "an ", 3)
&nbsp;            || !strncmpi(name, "a ", 2))
&nbsp;            kprefix = KILLED_BY;
&nbsp;    }
&nbsp;    onm = (obj &amp;&amp; obj_is_pname(obj)) ? the(name)
&nbsp;          : (obj &amp;&amp; obj-&gt;quan &gt; 1L) ? name
&nbsp;            : an(name);
&nbsp;    is_acid = (obj &amp;&amp; obj-&gt;otyp == ACID_VENOM);
&nbsp;
&nbsp;    if (u.uac + tlev &lt;= (dieroll = rnd(20))) {
&nbsp;        ++mesg_given;
&nbsp;        if (Blind || !flags.verbose) {
&nbsp;            pline("It misses.");
&nbsp;        } else if (u.uac + tlev &lt;= dieroll - 2) {
&nbsp;            if (onm != onmbuf)
&nbsp;                Strcpy(onmbuf, onm); /* [modifiable buffer for upstart()] */
&nbsp;            pline("%s %s you.", upstart(onmbuf), vtense(onmbuf, "miss"));
&nbsp;        } else
&nbsp;            You("are almost hit by %s.", onm);
&nbsp;        return 0;
&nbsp;    } else {
&nbsp;        if (Blind || !flags.verbose)
&nbsp;            You("are hit%s", exclam(dam));
&nbsp;        else
&nbsp;            You("are hit by %s%s", onm, exclam(dam));
&nbsp;
&nbsp;        if (is_acid &amp;&amp; Acid_resistance) {
&nbsp;            pline("It doesn't seem to hurt you.");
&nbsp;        } else if (obj &amp;&amp; obj-&gt;oclass == POTION_CLASS) {
&nbsp;            /* an explosion which scatters objects might hit hero with one
&nbsp;               (potions deliberately thrown at hero are handled by m_throw) */
&nbsp;            potionhit(&amp;youmonst, obj, POTHIT_OTHER_THROW);
&nbsp;            *objp = obj = 0; /* potionhit() uses up the potion */
&nbsp;        } else {
&nbsp;            if (obj &amp;&amp; objects[obj-&gt;otyp].oc_material == SILVER
&nbsp;                &amp;&amp; Hate_silver) {
&nbsp;                /* extra damage already applied by dmgval() */
&nbsp;                pline_The("silver sears your flesh!");
&nbsp;                exercise(A_CON, FALSE);
&nbsp;            }
&nbsp;            if (is_acid)
&nbsp;                pline("It burns!");
&nbsp;            losehp(dam, knm, kprefix); /* acid damage */
&nbsp;            exercise(A_STR, FALSE);
&nbsp;        }
&nbsp;        return 1;
&nbsp;    }
&nbsp;}
&nbsp;
drop_throw
&nbsp;/* Be sure this corresponds with what happens to player-thrown objects in
&nbsp; * dothrow.c (for consistency). --KAA
&nbsp; * Returns 0 if object still exists (not destroyed).
&nbsp; */
&nbsp;STATIC_OVL int
&nbsp;drop_throw(obj, ohit, x, y)
&nbsp;register struct obj *obj;
&nbsp;boolean ohit;
&nbsp;int x, y;
&nbsp;{
&nbsp;    int retvalu = 1;
&nbsp;    int create;
&nbsp;    struct monst *mtmp;
&nbsp;    struct trap *t;
&nbsp;
&nbsp;    if (obj-&gt;otyp == CREAM_PIE || obj-&gt;oclass == VENOM_CLASS
&nbsp;        || (ohit &amp;&amp; obj-&gt;otyp == EGG))
&nbsp;        create = 0;
&nbsp;    else if (ohit &amp;&amp; (is_multigen(obj) || obj-&gt;otyp == ROCK))
&nbsp;        create = !rn2(3);
&nbsp;    else
&nbsp;        create = 1;
&nbsp;
&nbsp;    if (create &amp;&amp; !((mtmp = m_at(x, y)) != 0 &amp;&amp; mtmp-&gt;mtrapped
&nbsp;                    &amp;&amp; (t = t_at(x, y)) != 0
&nbsp;                    &amp;&amp; (t-&gt;ttyp == PIT || t-&gt;ttyp == SPIKED_PIT))) {
&nbsp;        int objgone = 0;
&nbsp;
&nbsp;        if (down_gate(x, y) != -1)
&nbsp;            objgone = ship_object(obj, x, y, FALSE);
&nbsp;        if (!objgone) {
&nbsp;            if (!flooreffects(obj, x, y, "fall")) {
&nbsp;                place_object(obj, x, y);
&nbsp;                if (!mtmp &amp;&amp; x == u.ux &amp;&amp; y == u.uy)
&nbsp;                    mtmp = &amp;youmonst
&nbsp;                if (mtmp &amp;&amp; ohit)
&nbsp;                    passive_obj(mtmp, obj, (struct attack *) 0);
&nbsp;                stackobj(obj);
&nbsp;                retvalu = 0;
&nbsp;            }
&nbsp;        }
&nbsp;    } else
&nbsp;        obfree(obj, (struct obj *) 0);
&nbsp;    return retvalu;
&nbsp;}
&nbsp;
&nbsp;/* The monster that's being shot at when one monster shoots at another */
&nbsp;STATIC_OVL struct monst *target = 0;
&nbsp;/* The monster that's doing the shooting/throwing */
&nbsp;STATIC_OVL struct monst *archer = 0;
&nbsp;
monmulti
&nbsp;/* calculate multishot volley count for mtmp throwing otmp (if not ammo) or
&nbsp;   shooting otmp with mwep (if otmp is ammo and mwep appropriate launcher) */
&nbsp;STATIC_OVL int
&nbsp;monmulti(mtmp, otmp, mwep)
&nbsp;struct monst *mtmp;
&nbsp;struct obj *otmp, *mwep;
&nbsp;{
&nbsp;    int skill = (int) objects[otmp-&gt;otyp].oc_skill;
&nbsp;    int multishot = 1;
&nbsp;
&nbsp;    if (otmp-&gt;quan &gt; 1L /* no point checking if there's only 1 */
&nbsp;        /* ammo requires corresponding launcher be wielded */
&nbsp;        &amp;&amp; (is_ammo(otmp)
&nbsp;               ? matching_launcher(otmp, mwep)
&nbsp;               /* otherwise any stackable (non-ammo) weapon */
&nbsp;               : otmp-&gt;oclass == WEAPON_CLASS)
&nbsp;        &amp;&amp; !mtmp-&gt;mconf) {
&nbsp;        /* Assumes lords are skilled, princes are expert */
&nbsp;        if (is_prince(mtmp-&gt;data))
&nbsp;            multishot += 2;
&nbsp;        else if (is_lord(mtmp-&gt;data))
&nbsp;            multishot++;
&nbsp;        /* fake players treated as skilled (regardless of role limits) */
&nbsp;        else if (is_mplayer(mtmp-&gt;data))
&nbsp;            multishot++;
&nbsp;
&nbsp;        /* this portion is different from hero multishot; from slash'em?
&nbsp;         */
&nbsp;        /* Elven Craftsmanship makes for light, quick bows */
&nbsp;        if (otmp-&gt;otyp == ELVEN_ARROW &amp;&amp; !otmp-&gt;cursed)
&nbsp;            multishot++;
&nbsp;        if (ammo_and_launcher(otmp, uwep) &amp;&amp; mwep-&gt;otyp == ELVEN_BOW
&nbsp;            &amp;&amp; !mwep-&gt;cursed)
&nbsp;            multishot++;
&nbsp;        /* 1/3 of launcher enchantment */
&nbsp;        if (ammo_and_launcher(otmp, mwep) &amp;&amp; mwep-&gt;spe &gt; 1)
&nbsp;            multishot += (long) rounddiv(mwep-&gt;spe, 3);
&nbsp;        /* Some randomness */
&nbsp;        multishot = (long) rnd((int) multishot);
&nbsp;
&nbsp;        /* class bonus */
&nbsp;        switch (monsndx(mtmp-&gt;data)) {
&nbsp;        case PM_CAVEMAN: /* give bonus for low-tech gear */
&nbsp;            if (skill == -P_SLING || skill == P_SPEAR)
&nbsp;                multishot++;
&nbsp;            break;
&nbsp;        case PM_MONK: /* allow higher volley count */
&nbsp;            if (skill == -P_SHURIKEN)
&nbsp;                multishot++;
&nbsp;            break;
&nbsp;        case PM_RANGER:
&nbsp;            if (skill != P_DAGGER)
&nbsp;                multishot++;
&nbsp;            break;
&nbsp;        case PM_ROGUE:
&nbsp;            if (skill == P_DAGGER)
&nbsp;                multishot++;
&nbsp;            break;
&nbsp;        case PM_NINJA:
&nbsp;            if (skill == -P_SHURIKEN || skill == -P_DART)
&nbsp;                multishot++;
&nbsp;            /*FALLTHRU*/
&nbsp;        case PM_SAMURAI:
&nbsp;            if (otmp-&gt;otyp == YA &amp;&amp; mwep-&gt;otyp == YUMI)
&nbsp;                multishot++;
&nbsp;            break;
&nbsp;        default:
&nbsp;            break;
&nbsp;        }
&nbsp;        /* racial bonus */
&nbsp;        if ((is_elf(mtmp-&gt;data) &amp;&amp; otmp-&gt;otyp == ELVEN_ARROW
&nbsp;            &amp;&amp; mwep-&gt;otyp == ELVEN_BOW)
&nbsp;            || (is_orc(mtmp-&gt;data) &amp;&amp; otmp-&gt;otyp == ORCISH_ARROW
&nbsp;                &amp;&amp; mwep-&gt;otyp == ORCISH_BOW)
&nbsp;            || (is_gnome(mtmp-&gt;data) &amp;&amp; otmp-&gt;otyp == CROSSBOW_BOLT
&nbsp;                &amp;&amp; mwep-&gt;otyp == CROSSBOW))
&nbsp;            multishot++;
&nbsp;    }
&nbsp;
&nbsp;    if (otmp-&gt;quan &lt; multishot)
&nbsp;        multishot = (int) otmp-&gt;quan;
&nbsp;    if (multishot &lt; 1)
&nbsp;        multishot = 1;
&nbsp;    return multishot;
&nbsp;}
&nbsp;
monshoot
&nbsp;/* mtmp throws otmp, or shoots otmp with mwep, at hero or at monster mtarg */
&nbsp;STATIC_OVL void
&nbsp;monshoot(mtmp, otmp, mwep)
&nbsp;struct monst *mtmp;
&nbsp;struct obj *otmp, *mwep;
&nbsp;{
&nbsp;    struct monst *mtarg = target;
&nbsp;    int dm = distmin(mtmp-&gt;mx, mtmp-&gt;my,
&nbsp;                     mtarg ? mtarg-&gt;mx : mtmp-&gt;mux,
&nbsp;                     mtarg ? mtarg-&gt;my : mtmp-&gt;muy),
&nbsp;        multishot = monmulti(mtmp, otmp, mwep);
&nbsp;        /*
&nbsp;         * Caller must have called linedup() to set up tbx, tby.
&nbsp;         */
&nbsp;
&nbsp;    if (canseemon(mtmp)) {
&nbsp;        const char *onm;
&nbsp;        char onmbuf[BUFSZ], trgbuf[BUFSZ];
&nbsp;
&nbsp;        if (multishot &gt; 1) {
&nbsp;            /* "N arrows"; multishot &gt; 1 implies otmp-&gt;quan &gt; 1, so
&nbsp;               xname()'s result will already be pluralized */
&nbsp;            Sprintf(onmbuf, "%d %s", multishot, xname(otmp));
&nbsp;            onm = onmbuf;
&nbsp;        } else {
&nbsp;            /* "an arrow" */
&nbsp;            onm = singular(otmp, xname);
&nbsp;            onm = obj_is_pname(otmp) ? the(onm) : an(onm);
&nbsp;        }
&nbsp;        m_shot.s = ammo_and_launcher(otmp, mwep) ? TRUE : FALSE;
&nbsp;        Strcpy(trgbuf, mtarg ? mon_nam(mtarg) : "");
&nbsp;        if (!strcmp(trgbuf, "it"))
&nbsp;            Strcpy(trgbuf, humanoid(mtmp-&gt;data) ? "someone" : something);
&nbsp;        pline("%s %s %s%s%s!", Monnam(mtmp),
&nbsp;              m_shot.s ? "shoots" : "throws", onm,
&nbsp;              mtarg ? " at " : "", trgbuf);
&nbsp;        m_shot.o = otmp-&gt;otyp;
&nbsp;    } else {
&nbsp;        m_shot.o = STRANGE_OBJECT; /* don't give multishot feedback */
&nbsp;    }
&nbsp;    m_shot.n = multishot;
&nbsp;    for (m_shot.i = 1; m_shot.i &lt;= m_shot.n; m_shot.i++) {
&nbsp;        m_throw(mtmp, mtmp-&gt;mx, mtmp-&gt;my, sgn(tbx), sgn(tby), dm, otmp);
&nbsp;        /* conceptually all N missiles are in flight at once, but
&nbsp;           if mtmp gets killed (shot kills adjacent gas spore and
&nbsp;           triggers explosion, perhaps), inventory will be dropped
&nbsp;           and otmp might go away via merging into another stack */
&nbsp;        if (mtmp-&gt;mhp &lt;= 0 &amp;&amp; m_shot.i &lt; m_shot.n)
&nbsp;            /* cancel pending shots (perhaps ought to give a message here
&nbsp;               since we gave one above about throwing/shooting N missiles) */
&nbsp;            break; /* endmultishot(FALSE); */
&nbsp;    }
&nbsp;    /* reset 'm_shot' */
&nbsp;    m_shot.n = m_shot.i = 0;
&nbsp;    m_shot.o = STRANGE_OBJECT;
&nbsp;    m_shot.s = FALSE;
&nbsp;}
&nbsp;
ohitmon
&nbsp;/* an object launched by someone/thing other than player attacks a monster;
&nbsp;   return 1 if the object has stopped moving (hit or its range used up) */
&nbsp;int
&nbsp;ohitmon(mtmp, otmp, range, verbose)
&nbsp;struct monst *mtmp; /* accidental target, located at 

<bhitpos.x,.y> */
&nbsp;struct obj *otmp;   /* missile; might be destroyed by drop_throw */
&nbsp;int range;          /* how much farther will object travel if it misses;
&nbsp;                       use -1 to signify to keep going even after hit,
&nbsp;                       unless it's gone (used for rolling_boulder_traps) */
&nbsp;boolean verbose;    /* give message(s) even when you can't see what happened */
&nbsp;{
&nbsp;    int damage, tmp;
&nbsp;    boolean vis, ismimic;
&nbsp;    int objgone = 1;
&nbsp;    struct obj *mon_launcher = archer ? MON_WEP(archer) : NULL;
&nbsp;
&nbsp;    notonhead = (bhitpos.x != mtmp-&gt;mx || bhitpos.y != mtmp-&gt;my);
&nbsp;    ismimic = mtmp-&gt;m_ap_type &amp;&amp; mtmp-&gt;m_ap_type != M_AP_MONSTER;
&nbsp;    vis = cansee(bhitpos.x, bhitpos.y);
&nbsp;
&nbsp;    tmp = 5 + find_mac(mtmp) + omon_adj(mtmp, otmp, FALSE);
&nbsp;    /* High level monsters will be more likely to hit */
&nbsp;    /* This check applies only if this monster is the target
&nbsp;     * the archer was aiming at. */
&nbsp;    if (archer &amp;&amp; target == mtmp) {
&nbsp;        if (archer-&gt;m_lev &gt; 5)
&nbsp;            tmp += archer-&gt;m_lev - 5;
&nbsp;        if (mon_launcher &amp;&amp; mon_launcher-&gt;oartifact)
&nbsp;            tmp += spec_abon(mon_launcher, mtmp);
&nbsp;    }
&nbsp;    if (tmp &lt; rnd(20)) {
&nbsp;        if (!ismimic) {
&nbsp;            if (vis)
&nbsp;                miss(distant_name(otmp, mshot_xname), mtmp);
&nbsp;            else if (verbose &amp;&amp; !target)
&nbsp;                pline("It is missed.");
&nbsp;        }
&nbsp;        if (!range) { /* Last position; object drops */
&nbsp;            (void) drop_throw(otmp, 0, mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;            return 1;
&nbsp;        }
&nbsp;    } else if (otmp-&gt;oclass == POTION_CLASS) {
&nbsp;        if (ismimic)
&nbsp;            seemimic(mtmp);
&nbsp;        mtmp-&gt;msleeping = 0;
&nbsp;        if (vis)
&nbsp;            otmp-&gt;dknown = 1;
&nbsp;        /* probably thrown by a monster rather than 'other', but the
&nbsp;           distinction only matters when hitting the hero */
&nbsp;        potionhit(mtmp, otmp, POTHIT_OTHER_THROW);
&nbsp;        return 1;
&nbsp;    } else {
&nbsp;        damage = dmgval(otmp, mtmp);
&nbsp;        if (otmp-&gt;otyp == ACID_VENOM &amp;&amp; resists_acid(mtmp))
&nbsp;            damage = 0;
&nbsp;        if (ismimic)
&nbsp;            seemimic(mtmp);
&nbsp;        mtmp-&gt;msleeping = 0;
&nbsp;        if (vis) {
&nbsp;            if (otmp-&gt;otyp == EGG)
&nbsp;                pline("Splat! %s is hit with %s egg!", Monnam(mtmp),
&nbsp;                      otmp-&gt;known ? an(mons[otmp-&gt;corpsenm].mname) : "an");
&nbsp;            else
&nbsp;                hit(distant_name(otmp, mshot_xname), mtmp, exclam(damage));
&nbsp;        } else if (verbose &amp;&amp; !target)
&nbsp;            pline("%s%s is hit%s", (otmp-&gt;otyp == EGG) ? "Splat! " : "",
&nbsp;                  Monnam(mtmp), exclam(damage));
&nbsp;
&nbsp;        if (otmp-&gt;opoisoned &amp;&amp; is_poisonable(otmp)) {
&nbsp;            if (resists_poison(mtmp)) {
&nbsp;                if (vis)
&nbsp;                    pline_The("poison doesn't seem to affect %s.",
&nbsp;                              mon_nam(mtmp));
&nbsp;            } else {
&nbsp;                if (rn2(30)) {
&nbsp;                    damage += rnd(6);
&nbsp;                } else {
&nbsp;                    if (vis)
&nbsp;                        pline_The("poison was deadly...");
&nbsp;                    damage = mtmp-&gt;mhp;
&nbsp;                }
&nbsp;            }
&nbsp;        }
&nbsp;        if (objects[otmp-&gt;otyp].oc_material == SILVER
&nbsp;            &amp;&amp; mon_hates_silver(mtmp)) {
&nbsp;            if (vis)
&nbsp;                pline_The("silver sears %s flesh!", s_suffix(mon_nam(mtmp)));
&nbsp;            else if (verbose &amp;&amp; !target)
&nbsp;                pline("Its flesh is seared!");
&nbsp;        }
&nbsp;        if (otmp-&gt;otyp == ACID_VENOM &amp;&amp; cansee(mtmp-&gt;mx, mtmp-&gt;my)) {
&nbsp;            if (resists_acid(mtmp)) {
&nbsp;                if (vis || (verbose &amp;&amp; !target))
&nbsp;                    pline("%s is unaffected.", Monnam(mtmp));
&nbsp;            } else {
&nbsp;                if (vis)
&nbsp;                    pline_The("%s burns %s!", hliquid("acid"), mon_nam(mtmp));
&nbsp;                else if (verbose &amp;&amp; !target)
&nbsp;                    pline("It is burned!");
&nbsp;            }
&nbsp;        }
&nbsp;        if (otmp-&gt;otyp == EGG &amp;&amp; touch_petrifies(&amp;mons[otmp-&gt;corpsenm])) {
&nbsp;            if (!munstone(mtmp, TRUE))
&nbsp;                minstapetrify(mtmp, TRUE);
&nbsp;            if (resists_ston(mtmp))
&nbsp;                damage = 0;
&nbsp;        }
&nbsp;
&nbsp;        if (mtmp-&gt;mhp &gt; 0) { /* might already be dead (if petrified) */
&nbsp;            mtmp-&gt;mhp -= damage;
&nbsp;            if (mtmp-&gt;mhp &lt; 1) {
&nbsp;                if (vis || (verbose &amp;&amp; !target))
&nbsp;                    pline("%s is %s!", Monnam(mtmp),
&nbsp;                          (nonliving(mtmp-&gt;data) || is_vampshifter(mtmp)
&nbsp;                           || !canspotmon(mtmp)) ? "destroyed" : "killed");
&nbsp;                /* don't blame hero for unknown rolling boulder trap */
&nbsp;                if (!context.mon_moving &amp;&amp; (otmp-&gt;otyp != BOULDER
&nbsp;                                            || range &gt;= 0 || otmp-&gt;otrapped))
&nbsp;                    xkilled(mtmp, XKILL_NOMSG);
&nbsp;                else
&nbsp;                    mondied(mtmp);
&nbsp;            }
&nbsp;        }
&nbsp;
&nbsp;        /* blinding venom and cream pie do 0 damage, but verify
&nbsp;           that the target is still alive anyway */
&nbsp;        if (mtmp-&gt;mhp &gt; 0
&nbsp;            &amp;&amp; can_blnd((struct monst *) 0, mtmp,
&nbsp;                        (uchar) ((otmp-&gt;otyp == BLINDING_VENOM) ? AT_SPIT
&nbsp;                                                                : AT_WEAP),
&nbsp;                        otmp)) {
&nbsp;            if (vis &amp;&amp; mtmp-&gt;mcansee)
&nbsp;                pline("%s is blinded by %s.", Monnam(mtmp), the(xname(otmp)));
&nbsp;            mtmp-&gt;mcansee = 0;
&nbsp;            tmp = (int) mtmp-&gt;mblinded + rnd(25) + 20;
&nbsp;            if (tmp &gt; 127)
&nbsp;                tmp = 127;
&nbsp;            mtmp-&gt;mblinded = tmp;
&nbsp;        }
&nbsp;
&nbsp;        objgone = drop_throw(otmp, 1, bhitpos.x, bhitpos.y);
&nbsp;        if (!objgone &amp;&amp; range == -1) { /* special case */
&nbsp;            obj_extract_self(otmp);    /* free it for motion again */
&nbsp;            return 0;
&nbsp;        }
&nbsp;        return 1;
&nbsp;    }
&nbsp;    return 0;
&nbsp;}
&nbsp;
&nbsp;#define MT_FLIGHTCHECK(pre)                                             \
&nbsp;    (/* missile hits edge of screen */                                  \
&nbsp;     !isok(bhitpos.x + dx, bhitpos.y + dy)                              \
&nbsp;     /* missile hits the wall */                                        \
&nbsp;     || IS_ROCK(levl[bhitpos.x + dx][bhitpos.y + dy].typ)               \
&nbsp;     /* missile hit closed door */                                      \
&nbsp;     || closed_door(bhitpos.x + dx, bhitpos.y + dy)                     \
&nbsp;     /* missile might hit iron bars */                                  \
&nbsp;     /* the random chance for small objects hitting bars is */          \
&nbsp;     /* skipped when reaching them at point blank range */              \
&nbsp;     || (levl[bhitpos.x + dx][bhitpos.y + dy].typ == IRONBARS           \
&nbsp;         &amp;&amp; hits_bars(&amp;singleobj,                                       \
&nbsp;                      bhitpos.x, bhitpos.y,                             \
&nbsp;                      bhitpos.x + dx, bhitpos.y + dy,                   \
&nbsp;                      ((pre) ? 0 : !rn2(5)), 0))                        \
&nbsp;     /* Thrown objects "sink" */                                        \
&nbsp;     || (!(pre) &amp;&amp; IS_SINK(levl[bhitpos.x][bhitpos.y].typ)))
&nbsp;
m_throw
&nbsp;void
&nbsp;m_throw(mon, x, y, dx, dy, range, obj)
&nbsp;struct monst *mon;       /* launching monster */
&nbsp;int x, y, dx, dy, range; /* launch point, direction, and range */
&nbsp;struct obj *obj;         /* missile (or stack providing it) */
&nbsp;{
&nbsp;    struct monst *mtmp;
&nbsp;    struct obj *singleobj;
&nbsp;    char sym = obj-&gt;oclass;
&nbsp;    int hitu = 0, oldumort, blindinc = 0;
&nbsp;
&nbsp;    bhitpos.x = x;
&nbsp;    bhitpos.y = y;
&nbsp;    notonhead = FALSE; /* reset potentially stale value */
&nbsp;
&nbsp;    if (obj-&gt;quan == 1L) {
&nbsp;        /*
&nbsp;         * Remove object from minvent.  This cannot be done later on;
&nbsp;         * what if the player dies before then, leaving the monster
&nbsp;         * with 0 daggers?  (This caused the infamous 2^32-1 orcish
&nbsp;         * dagger bug).
&nbsp;         *
&nbsp;         * VENOM is not in minvent - it should already be OBJ_FREE.
&nbsp;         * The extract below does nothing.
&nbsp;         */
&nbsp;
&nbsp;        /* not possibly_unwield, which checks the object's */
&nbsp;        /* location, not its existence */
&nbsp;        if (MON_WEP(mon) == obj)
&nbsp;            setmnotwielded(mon, obj);
&nbsp;        obj_extract_self(obj);
&nbsp;        singleobj = obj;
&nbsp;        obj = (struct obj *) 0;
&nbsp;    } else {
&nbsp;        singleobj = splitobj(obj, 1L);
&nbsp;        obj_extract_self(singleobj);
&nbsp;    }
&nbsp;
&nbsp;    singleobj-&gt;owornmask = 0; /* threw one of multiple weapons in hand? */
&nbsp;
&nbsp;    if ((singleobj-&gt;cursed || singleobj-&gt;greased) &amp;&amp; (dx || dy) &amp;&amp; !rn2(7)) {
&nbsp;        if (canseemon(mon) &amp;&amp; flags.verbose) {
&nbsp;            if (is_ammo(singleobj))
&nbsp;                pline("%s misfires!", Monnam(mon));
&nbsp;            else
&nbsp;                pline("%s as %s throws it!", Tobjnam(singleobj, "slip"),
&nbsp;                      mon_nam(mon));
&nbsp;        }
&nbsp;        dx = rn2(3) - 1;
&nbsp;        dy = rn2(3) - 1;
&nbsp;        /* check validity of new direction */
&nbsp;        if (!dx &amp;&amp; !dy) {
&nbsp;            (void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y);
&nbsp;            return;
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    if (MT_FLIGHTCHECK(TRUE)) {
&nbsp;        (void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y);
&nbsp;        return;
&nbsp;    }
&nbsp;    mesg_given = 0; /* a 'missile misses' message has not yet been shown */
&nbsp;
&nbsp;    /* Note: drop_throw may destroy singleobj.  Since obj must be destroyed
&nbsp;     * early to avoid the dagger bug, anyone who modifies this code should
&nbsp;     * be careful not to use either one after it's been freed.
&nbsp;     */
&nbsp;    if (sym)
&nbsp;        tmp_at(DISP_FLASH, obj_to_glyph(singleobj));
&nbsp;    while (range-- &gt; 0) { /* Actually the loop is always exited by break */
&nbsp;        bhitpos.x += dx;
&nbsp;        bhitpos.y += dy;
&nbsp;        if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
&nbsp;            if (ohitmon(mtmp, singleobj, range, TRUE))
&nbsp;                break;
&nbsp;        } else if (bhitpos.x == u.ux &amp;&amp; bhitpos.y == u.uy) {
&nbsp;            if (multi)
&nbsp;                nomul(0);
&nbsp;
&nbsp;            if (singleobj-&gt;oclass == GEM_CLASS
&nbsp;                &amp;&amp; singleobj-&gt;otyp &lt;= LAST_GEM + 9 /* 9 glass colors */
&nbsp;                &amp;&amp; is_unicorn(youmonst.data)) {
&nbsp;                if (singleobj-&gt;otyp &gt; LAST_GEM) {
&nbsp;                    You("catch the %s.", xname(singleobj));
&nbsp;                    You("are not interested in %s junk.",
&nbsp;                        s_suffix(mon_nam(mon)));
&nbsp;                    makeknown(singleobj-&gt;otyp);
&nbsp;                    dropy(singleobj);
&nbsp;                } else {
&nbsp;                    You(
&nbsp;                     "accept %s gift in the spirit in which it was intended.",
&nbsp;                        s_suffix(mon_nam(mon)));
&nbsp;                    (void) hold_another_object(singleobj,
&nbsp;                                               "You catch, but drop, %s.",
&nbsp;                                               xname(singleobj),
&nbsp;                                               "You catch:");
&nbsp;                }
&nbsp;                break;
&nbsp;            }
&nbsp;            if (singleobj-&gt;oclass == POTION_CLASS) {
&nbsp;                if (!Blind)
&nbsp;                    singleobj-&gt;dknown = 1;
&nbsp;                potionhit(&amp;youmonst, singleobj, POTHIT_MONST_THROW);
&nbsp;                break;
&nbsp;            }
&nbsp;            oldumort = u.umortality;
&nbsp;            switch (singleobj-&gt;otyp) {
&nbsp;                int dam, hitv;
&nbsp;            case EGG:
&nbsp;                if (!touch_petrifies(&amp;mons[singleobj-&gt;corpsenm])) {
&nbsp;                    impossible("monster throwing egg type %d",
&nbsp;                               singleobj-&gt;corpsenm);
&nbsp;                    hitu = 0;
&nbsp;                    break;
&nbsp;                }
&nbsp;            /* fall through */
&nbsp;            case CREAM_PIE:
&nbsp;            case BLINDING_VENOM:
&nbsp;                hitu = thitu(8, 0, &amp;singleobj, (char *) 0);
&nbsp;                break;
&nbsp;            default:
&nbsp;                dam = dmgval(singleobj, &amp;youmonst);
&nbsp;                hitv = 3 - distmin(u.ux, u.uy, mon-&gt;mx, mon-&gt;my);
&nbsp;                if (hitv &lt; -4)
&nbsp;                    hitv = -4;
&nbsp;                if (is_elf(mon-&gt;data)
&nbsp;                    &amp;&amp; objects[singleobj-&gt;otyp].oc_skill == P_BOW) {
&nbsp;                    hitv++;
&nbsp;                    if (MON_WEP(mon) &amp;&amp; MON_WEP(mon)-&gt;otyp == ELVEN_BOW)
&nbsp;                        hitv++;
&nbsp;                    if (singleobj-&gt;otyp == ELVEN_ARROW)
&nbsp;                        dam++;
&nbsp;                }
&nbsp;                if (bigmonst(youmonst.data))
&nbsp;                    hitv++;
&nbsp;                hitv += 8 + singleobj-&gt;spe;
&nbsp;                if (dam &lt; 1)
&nbsp;                    dam = 1;
&nbsp;                hitu = thitu(hitv, dam, &amp;singleobj, (char *) 0);
&nbsp;            }
&nbsp;            if (hitu &amp;&amp; singleobj-&gt;opoisoned &amp;&amp; is_poisonable(singleobj)) {
&nbsp;                char onmbuf[BUFSZ], knmbuf[BUFSZ];
&nbsp;
&nbsp;                Strcpy(onmbuf, xname(singleobj));
&nbsp;                Strcpy(knmbuf, killer_xname(singleobj));
&nbsp;                poisoned(onmbuf, A_STR, knmbuf,
&nbsp;                         /* if damage triggered life-saving,
&nbsp;                            poison is limited to attrib loss */
&nbsp;                         (u.umortality &gt; oldumort) ? 0 : 10, TRUE);
&nbsp;            }
&nbsp;            if (hitu &amp;&amp; can_blnd((struct monst *) 0, &amp;youmonst,
&nbsp;                                 (uchar) ((singleobj-&gt;otyp == BLINDING_VENOM)
&nbsp;                                             ? AT_SPIT
&nbsp;                                             : AT_WEAP),
&nbsp;                                 singleobj)) {
&nbsp;                blindinc = rnd(25);
&nbsp;                if (singleobj-&gt;otyp == CREAM_PIE) {
&nbsp;                    if (!Blind)
&nbsp;                        pline("Yecch!  You've been creamed.");
&nbsp;                    else
&nbsp;                        pline("There's %s sticky all over your %s.",
&nbsp;                              something, body_part(FACE));
&nbsp;                } else if (singleobj-&gt;otyp == BLINDING_VENOM) {
&nbsp;                    const char *eyes = body_part(EYE);
&nbsp;
&nbsp;                    if (eyecount(youmonst.data) != 1)
&nbsp;                        eyes = makeplural(eyes);
&nbsp;                    /* venom in the eyes */
&nbsp;                    if (!Blind)
&nbsp;                        pline_The("venom blinds you.");
&nbsp;                    else
&nbsp;                        Your("%s %s.", eyes, vtense(eyes, "sting"));
&nbsp;                }
&nbsp;            }
&nbsp;            if (hitu &amp;&amp; singleobj-&gt;otyp == EGG) {
&nbsp;                if (!Stoned &amp;&amp; !Stone_resistance
&nbsp;                    &amp;&amp; !(poly_when_stoned(youmonst.data)
&nbsp;                         &amp;&amp; polymon(PM_STONE_GOLEM))) {
&nbsp;                    make_stoned(5L, (char *) 0, KILLED_BY, "");
&nbsp;                }
&nbsp;            }
&nbsp;            stop_occupation();
&nbsp;            if (hitu) {
&nbsp;                (void) drop_throw(singleobj, hitu, u.ux, u.uy);
&nbsp;                break;
&nbsp;            }
&nbsp;        }
&nbsp;        if (!range /* reached end of path */
&nbsp;            || MT_FLIGHTCHECK(FALSE)) {
&nbsp;            if (singleobj) { /* hits_bars might have destroyed it */
&nbsp;                if (m_shot.n &gt; 1
&nbsp;                    &amp;&amp; (!mesg_given || bhitpos.x != u.ux || bhitpos.y != u.uy)
&nbsp;                    &amp;&amp; (cansee(bhitpos.x, bhitpos.y)
&nbsp;                        || (archer &amp;&amp; canseemon(archer))))
&nbsp;                    pline("%s misses.", The(mshot_xname(singleobj)));
&nbsp;                (void) drop_throw(singleobj, 0, bhitpos.x, bhitpos.y);
&nbsp;            }
&nbsp;            break;
&nbsp;        }
&nbsp;        tmp_at(bhitpos.x, bhitpos.y);
&nbsp;        delay_output();
&nbsp;    }
&nbsp;    tmp_at(bhitpos.x, bhitpos.y);
&nbsp;    delay_output();
&nbsp;    tmp_at(DISP_END, 0);
&nbsp;    mesg_given = 0; /* reset */
&nbsp;
&nbsp;    if (blindinc) {
&nbsp;        u.ucreamed += blindinc;
&nbsp;        make_blinded(Blinded + (long) blindinc, FALSE);
&nbsp;        if (!Blind)
&nbsp;            Your1(vision_clears);
&nbsp;    }
&nbsp;}
&nbsp;
&nbsp;#undef MT_FLIGHTCHECK
&nbsp;
thrwmm
&nbsp;/* Monster throws item at another monster */
&nbsp;int
&nbsp;thrwmm(mtmp, mtarg)
&nbsp;struct monst *mtmp, *mtarg;
&nbsp;{
&nbsp;    struct obj *otmp, *mwep;
&nbsp;    register xchar x, y;
&nbsp;    boolean ispole;
&nbsp;
&nbsp;    /* Polearms won't be applied by monsters against other monsters */
&nbsp;    if (mtmp-&gt;weapon_check == NEED_WEAPON || !MON_WEP(mtmp)) {
&nbsp;        mtmp-&gt;weapon_check = NEED_RANGED_WEAPON;
&nbsp;        /* mon_wield_item resets weapon_check as appropriate */
&nbsp;        if (mon_wield_item(mtmp) != 0)
&nbsp;            return 0;
&nbsp;    }
&nbsp;
&nbsp;    /* Pick a weapon */
&nbsp;    otmp = select_rwep(mtmp);
&nbsp;    if (!otmp)
&nbsp;        return 0;
&nbsp;    ispole = is_pole(otmp);
&nbsp;
&nbsp;    x = mtmp-&gt;mx;
&nbsp;    y = mtmp-&gt;my;
&nbsp;
&nbsp;    mwep = MON_WEP(mtmp); /* wielded weapon */
&nbsp;
&nbsp;    if (!ispole &amp;&amp; m_lined_up(mtarg, mtmp)) {
&nbsp;        int chance = max(BOLT_LIM - distmin(x, y, mtarg-&gt;mx, mtarg-&gt;my), 1);
&nbsp;
&nbsp;        if (!mtarg-&gt;mflee || !rn2(chance)) {
&nbsp;            if (ammo_and_launcher(otmp, mwep)
&nbsp;                &amp;&amp; dist2(mtmp-&gt;mx, mtmp-&gt;my, mtarg-&gt;mx, mtarg-&gt;my)
&nbsp;                   &gt; PET_MISSILE_RANGE2)
&nbsp;                return 0; /* Out of range */
&nbsp;            /* Set target monster */
&nbsp;            target = mtarg;
&nbsp;            archer = mtmp;
&nbsp;            monshoot(mtmp, otmp, mwep); /* multishot shooting or throwing */
&nbsp;            archer = target = (struct monst *) 0;
&nbsp;            nomul(0);
&nbsp;            return 1;
&nbsp;        }
&nbsp;    }
&nbsp;    return 0;
&nbsp;}
&nbsp;
spitmm
&nbsp;/* monster spits substance at monster */
&nbsp;int
&nbsp;spitmm(mtmp, mattk, mtarg)
&nbsp;struct monst *mtmp, *mtarg;
&nbsp;struct attack *mattk;
&nbsp;{
&nbsp;    struct obj *otmp;
&nbsp;
&nbsp;    if (mtmp-&gt;mcan) {
&nbsp;        if (!Deaf)
&nbsp;            pline("A dry rattle comes from %s throat.",
&nbsp;                  s_suffix(mon_nam(mtmp)));
&nbsp;        return 0;
&nbsp;    }
&nbsp;    if (m_lined_up(mtarg, mtmp)) {
&nbsp;        switch (mattk-&gt;adtyp) {
&nbsp;        case AD_BLND:
&nbsp;        case AD_DRST:
&nbsp;            otmp = mksobj(BLINDING_VENOM, TRUE, FALSE);
&nbsp;            break;
&nbsp;        default:
&nbsp;            impossible("bad attack type in spitmu");
&nbsp;            /* fall through */
&nbsp;        case AD_ACID:
&nbsp;            otmp = mksobj(ACID_VENOM, TRUE, FALSE);
&nbsp;            break;
&nbsp;        }
&nbsp;        if (!rn2(BOLT_LIM-distmin(mtmp-&gt;mx,mtmp-&gt;my,mtarg-&gt;mx,mtarg-&gt;my))) {
&nbsp;            if (canseemon(mtmp))
&nbsp;                pline("%s spits venom!", Monnam(mtmp));
&nbsp;            target = mtarg;
&nbsp;            m_throw(mtmp, mtmp-&gt;mx, mtmp-&gt;my, sgn(tbx), sgn(tby),
&nbsp;                    distmin(mtmp-&gt;mx,mtmp-&gt;my,mtarg-&gt;mx,mtarg-&gt;my), otmp);
&nbsp;            target = (struct monst *)0;
&nbsp;            nomul(0);
&nbsp;
&nbsp;            /* If this is a pet, it'll get hungry. Minions and
&nbsp;             * spell beings won't hunger */
&nbsp;            if (mtmp-&gt;mtame &amp;&amp; !mtmp-&gt;isminion) {
&nbsp;                struct edog *dog = EDOG(mtmp);
&nbsp;
&nbsp;                /* Hunger effects will catch up next move */
&nbsp;                if (dog-&gt;hungrytime &gt; 1)
&nbsp;                    dog-&gt;hungrytime -= 5;
&nbsp;            }
&nbsp;
&nbsp;            return 1;
&nbsp;        }
&nbsp;    }
&nbsp;    return 0;
&nbsp;}
&nbsp;
breamm
&nbsp;/* monster breathes at monster (ranged) */
&nbsp;int
&nbsp;breamm(mtmp, mattk, mtarg)
&nbsp;struct monst *mtmp, *mtarg;
&nbsp;struct attack  *mattk;
&nbsp;{
&nbsp;    /* if new breath types are added, change AD_ACID to max type */
&nbsp;    int typ = (mattk-&gt;adtyp == AD_RBRE) ? rnd(AD_ACID) : mattk-&gt;adtyp ;
&nbsp;
&nbsp;    if (m_lined_up(mtarg, mtmp)) {
&nbsp;        if (mtmp-&gt;mcan) {
&nbsp;            if (!Deaf) {
&nbsp;                if (canseemon(mtmp))
&nbsp;                    pline("%s coughs.", Monnam(mtmp));
&nbsp;                else
&nbsp;                    You_hear("a cough.");
&nbsp;            }
&nbsp;            return 0;
&nbsp;        }
&nbsp;        if (!mtmp-&gt;mspec_used &amp;&amp; rn2(3)) {
&nbsp;            if ((typ &gt;= AD_MAGM) &amp;&amp; (typ &lt;= AD_ACID)) {
&nbsp;                if (canseemon(mtmp))
&nbsp;                    pline("%s breathes %s!", Monnam(mtmp), breathwep[typ - 1]);
&nbsp;                dobuzz((int) (-20 - (typ - 1)), (int)mattk-&gt;damn,
&nbsp;                       mtmp-&gt;mx, mtmp-&gt;my, sgn(tbx), sgn(tby), FALSE);
&nbsp;                nomul(0);
&nbsp;                /* breath runs out sometimes. Also, give monster some
&nbsp;                 * cunning; don't breath if the target fell asleep.
&nbsp;                 */
&nbsp;                mtmp-&gt;mspec_used = 6 + rn2(18);
&nbsp;
&nbsp;                /* If this is a pet, it'll get hungry. Minions and
&nbsp;                 * spell beings won't hunger */
&nbsp;                if (mtmp-&gt;mtame &amp;&amp; !mtmp-&gt;isminion) {
&nbsp;                    struct edog *dog = EDOG(mtmp);
&nbsp;
&nbsp;                    /* Hunger effects will catch up next move */
&nbsp;                    if (dog-&gt;hungrytime &gt;= 10)
&nbsp;                        dog-&gt;hungrytime -= 10;
&nbsp;                }
&nbsp;            } else impossible("Breath weapon %d used", typ-1);
&nbsp;        } else
&nbsp;            return 0;
&nbsp;    }
&nbsp;    return 1;
&nbsp;}
&nbsp;
&nbsp;
&nbsp;
m_useupall
&nbsp;/* remove an entire item from a monster's inventory; destroy that item */
&nbsp;void
&nbsp;m_useupall(mon, obj)
&nbsp;struct monst *mon;
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    obj_extract_self(obj);
&nbsp;    if (obj-&gt;owornmask) {
&nbsp;        if (obj == MON_WEP(mon))
&nbsp;            mwepgone(mon);
&nbsp;        mon-&gt;misc_worn_check &amp;= ~obj-&gt;owornmask;
&nbsp;        update_mon_intrinsics(mon, obj, FALSE, FALSE);
&nbsp;        obj-&gt;owornmask = 0L;
&nbsp;    }
&nbsp;    obfree(obj, (struct obj *) 0);
&nbsp;}
&nbsp;
m_useup
&nbsp;/* remove one instance of an item from a monster's inventory */
&nbsp;void
&nbsp;m_useup(mon, obj)
&nbsp;struct monst *mon;
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    if (obj-&gt;quan &gt; 1L) {
&nbsp;        obj-&gt;quan--;
&nbsp;        obj-&gt;owt = weight(obj);
&nbsp;    } else {
&nbsp;        m_useupall(mon, obj);
&nbsp;    }
&nbsp;}
&nbsp;
thrwmu
&nbsp;/* monster attempts ranged weapon attack against player */
&nbsp;void
&nbsp;thrwmu(mtmp)
&nbsp;struct monst *mtmp;
&nbsp;{
&nbsp;    struct obj *otmp, *mwep;
&nbsp;    xchar x, y;
&nbsp;    const char *onm;
&nbsp;
&nbsp;    /* Rearranged beginning so monsters can use polearms not in a line */
&nbsp;    if (mtmp-&gt;weapon_check == NEED_WEAPON || !MON_WEP(mtmp)) {
&nbsp;        mtmp-&gt;weapon_check = NEED_RANGED_WEAPON;
&nbsp;        /* mon_wield_item resets weapon_check as appropriate */
&nbsp;        if (mon_wield_item(mtmp) != 0)
&nbsp;            return;
&nbsp;    }
&nbsp;
&nbsp;    /* Pick a weapon */
&nbsp;    otmp = select_rwep(mtmp);
&nbsp;    if (!otmp)
&nbsp;        return;
&nbsp;
&nbsp;    if (is_pole(otmp)) {
&nbsp;        int dam, hitv;
&nbsp;
&nbsp;        if (otmp != MON_WEP(mtmp))
&nbsp;            return; /* polearm must be wielded */
&nbsp;        if (dist2(mtmp-&gt;mx, mtmp-&gt;my, mtmp-&gt;mux, mtmp-&gt;muy) &gt; POLE_LIM
&nbsp;            || !couldsee(mtmp-&gt;mx, mtmp-&gt;my))
&nbsp;            return; /* Out of range, or intervening wall */
&nbsp;
&nbsp;        if (canseemon(mtmp)) {
&nbsp;            onm = xname(otmp);
&nbsp;            pline("%s thrusts %s.", Monnam(mtmp),
&nbsp;                  obj_is_pname(otmp) ? the(onm) : an(onm));
&nbsp;        }
&nbsp;
&nbsp;        dam = dmgval(otmp, &amp;youmonst);
&nbsp;        hitv = 3 - distmin(u.ux, u.uy, mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;        if (hitv &lt; -4)
&nbsp;            hitv = -4;
&nbsp;        if (bigmonst(youmonst.data))
&nbsp;            hitv++;
&nbsp;        hitv += 8 + otmp-&gt;spe;
&nbsp;        if (dam &lt; 1)
&nbsp;            dam = 1;
&nbsp;
&nbsp;        (void) thitu(hitv, dam, &amp;otmp, (char *) 0);
&nbsp;        stop_occupation();
&nbsp;        return;
&nbsp;    }
&nbsp;
&nbsp;    x = mtmp-&gt;mx;
&nbsp;    y = mtmp-&gt;my;
&nbsp;    /* If you are coming toward the monster, the monster
&nbsp;     * should try to soften you up with missiles.  If you are
&nbsp;     * going away, you are probably hurt or running.  Give
&nbsp;     * chase, but if you are getting too far away, throw.
&nbsp;     */
&nbsp;    if (!lined_up(mtmp)
&nbsp;        || (URETREATING(x, y)
&nbsp;            &amp;&amp; rn2(BOLT_LIM - distmin(x, y, mtmp-&gt;mux, mtmp-&gt;muy))))
&nbsp;        return;
&nbsp;
&nbsp;    mwep = MON_WEP(mtmp); /* wielded weapon */
&nbsp;    monshoot(mtmp, otmp, mwep); /* multishot shooting or throwing */
&nbsp;    nomul(0);
&nbsp;}
&nbsp;
spitmu
&nbsp;/* monster spits substance at you */
&nbsp;int
&nbsp;spitmu(mtmp, mattk)
&nbsp;struct monst *mtmp;
&nbsp;struct attack *mattk;
&nbsp;{
&nbsp;    struct obj *otmp;
&nbsp;
&nbsp;    if (mtmp-&gt;mcan) {
&nbsp;        if (!Deaf)
&nbsp;            pline("A dry rattle comes from %s throat.",
&nbsp;                  s_suffix(mon_nam(mtmp)));
&nbsp;        return 0;
&nbsp;    }
&nbsp;    if (lined_up(mtmp)) {
&nbsp;        switch (mattk-&gt;adtyp) {
&nbsp;        case AD_BLND:
&nbsp;        case AD_DRST:
&nbsp;            otmp = mksobj(BLINDING_VENOM, TRUE, FALSE);
&nbsp;            break;
&nbsp;        default:
&nbsp;            impossible("bad attack type in spitmu");
&nbsp;        /* fall through */
&nbsp;        case AD_ACID:
&nbsp;            otmp = mksobj(ACID_VENOM, TRUE, FALSE);
&nbsp;            break;
&nbsp;        }
&nbsp;        if (!rn2(BOLT_LIM
&nbsp;                 - distmin(mtmp-&gt;mx, mtmp-&gt;my, mtmp-&gt;mux, mtmp-&gt;muy))) {
&nbsp;            if (canseemon(mtmp))
&nbsp;                pline("%s spits venom!", Monnam(mtmp));
&nbsp;            m_throw(mtmp, mtmp-&gt;mx, mtmp-&gt;my, sgn(tbx), sgn(tby),
&nbsp;                    distmin(mtmp-&gt;mx, mtmp-&gt;my, mtmp-&gt;mux, mtmp-&gt;muy), otmp);
&nbsp;            nomul(0);
&nbsp;            return 0;
&nbsp;        } else {
&nbsp;            obj_extract_self(otmp);
&nbsp;            obfree(otmp, (struct obj *) 0);
&nbsp;        }
&nbsp;    }
&nbsp;    return 0;
&nbsp;}
&nbsp;
breamu
&nbsp;/* monster breathes at you (ranged) */
&nbsp;int
&nbsp;breamu(mtmp, mattk)
&nbsp;struct monst *mtmp;
&nbsp;struct attack *mattk;
&nbsp;{
&nbsp;    /* if new breath types are added, change AD_ACID to max type */
&nbsp;    int typ = (mattk-&gt;adtyp == AD_RBRE) ? rnd(AD_ACID) : mattk-&gt;adtyp;
&nbsp;
&nbsp;    if (lined_up(mtmp)) {
&nbsp;        if (mtmp-&gt;mcan) {
&nbsp;            if (!Deaf) {
&nbsp;                if (canseemon(mtmp))
&nbsp;                    pline("%s coughs.", Monnam(mtmp));
&nbsp;                else
&nbsp;                    You_hear("a cough.");
&nbsp;            }
&nbsp;            return 0;
&nbsp;        }
&nbsp;        if (!mtmp-&gt;mspec_used &amp;&amp; rn2(3)) {
&nbsp;            if ((typ &gt;= AD_MAGM) &amp;&amp; (typ &lt;= AD_ACID)) {
&nbsp;                if (canseemon(mtmp))
&nbsp;                    pline("%s breathes %s!", Monnam(mtmp),
&nbsp;                          breathwep[typ - 1]);
&nbsp;                buzz((int) (-20 - (typ - 1)), (int) mattk-&gt;damn, mtmp-&gt;mx,
&nbsp;                     mtmp-&gt;my, sgn(tbx), sgn(tby));
&nbsp;                nomul(0);
&nbsp;                /* breath runs out sometimes. Also, give monster some
&nbsp;                 * cunning; don't breath if the player fell asleep.
&nbsp;                 */
&nbsp;                if (!rn2(3))
&nbsp;                    mtmp-&gt;mspec_used = 10 + rn2(20);
&nbsp;                if (typ == AD_SLEE &amp;&amp; !Sleep_resistance)
&nbsp;                    mtmp-&gt;mspec_used += rnd(20);
&nbsp;            } else
&nbsp;                impossible("Breath weapon %d used", typ - 1);
&nbsp;        }
&nbsp;    }
&nbsp;    return 1;
&nbsp;}
&nbsp;
linedup
&nbsp;boolean
&nbsp;linedup(ax, ay, bx, by, boulderhandling)
&nbsp;register xchar ax, ay, bx, by;
&nbsp;int boulderhandling; /* 0=block, 1=ignore, 2=conditionally block */
&nbsp;{
&nbsp;    int dx, dy, boulderspots;
&nbsp;
&nbsp;    /* These two values are set for use after successful return. */
&nbsp;    tbx = ax - bx;
&nbsp;    tby = ay - by;
&nbsp;
&nbsp;    /* sometimes displacement makes a monster think that you're at its
&nbsp;       own location; prevent it from throwing and zapping in that case */
&nbsp;    if (!tbx &amp;&amp; !tby)
&nbsp;        return FALSE;
&nbsp;
&nbsp;    if ((!tbx || !tby || abs(tbx) == abs(tby)) /* straight line or diagonal */
&nbsp;        &amp;&amp; distmin(tbx, tby, 0, 0) &lt; BOLT_LIM) {
&nbsp;        if ((ax == u.ux &amp;&amp; ay == u.uy) ? (boolean) couldsee(bx, by)
&nbsp;                                       : clear_path(ax, ay, bx, by))
&nbsp;            return TRUE;
&nbsp;        /* don't have line of sight, but might still be lined up
&nbsp;           if that lack of sight is due solely to boulders */
&nbsp;        if (boulderhandling == 0)
&nbsp;            return FALSE;
&nbsp;        dx = sgn(ax - bx), dy = sgn(ay - by);
&nbsp;        boulderspots = 0;
&nbsp;        do {
&nbsp;            /* <bx,by> is guaranteed to eventually converge with <ax,ay> */
&nbsp;            bx += dx, by += dy;
&nbsp;            if (IS_ROCK(levl[bx][by].typ) || closed_door(bx, by))
&nbsp;                return FALSE;
&nbsp;            if (sobj_at(BOULDER, bx, by))
&nbsp;                ++boulderspots;
&nbsp;        } while (bx != ax || by != ay);
&nbsp;        /* reached target position without encountering obstacle */
&nbsp;        if (boulderhandling == 1 || rn2(2 + boulderspots) &lt; 2)
&nbsp;            return TRUE;
&nbsp;    }
&nbsp;    return FALSE;
&nbsp;}
&nbsp;
m_lined_up
&nbsp;STATIC_OVL boolean
&nbsp;m_lined_up(mtarg, mtmp)
&nbsp;struct monst *mtarg, *mtmp;
&nbsp;{
&nbsp;    return (linedup(mtarg-&gt;mx, mtarg-&gt;my, mtmp-&gt;mx, mtmp-&gt;my, 0));
&nbsp;}
&nbsp;
&nbsp;
lined_up
&nbsp;/* is mtmp in position to use ranged attack? */
&nbsp;boolean
&nbsp;lined_up(mtmp)
&nbsp;register struct monst *mtmp;
&nbsp;{
&nbsp;    boolean ignore_boulders;
&nbsp;
&nbsp;    /* hero concealment usually trumps monst awareness of being lined up */
&nbsp;    if (Upolyd &amp;&amp; rn2(25)
&nbsp;        &amp;&amp; (u.uundetected || (youmonst.m_ap_type != M_AP_NOTHING
&nbsp;                              &amp;&amp; youmonst.m_ap_type != M_AP_MONSTER)))
&nbsp;        return FALSE;
&nbsp;
&nbsp;    ignore_boulders = (throws_rocks(mtmp-&gt;data)
&nbsp;                       || m_carrying(mtmp, WAN_STRIKING));
&nbsp;    return linedup(mtmp-&gt;mux, mtmp-&gt;muy, mtmp-&gt;mx, mtmp-&gt;my,
&nbsp;                   ignore_boulders ? 1 : 2);
&nbsp;}
&nbsp;
m_carrying
&nbsp;/* check if a monster is carrying a particular item */
&nbsp;struct obj *
&nbsp;m_carrying(mtmp, type)
&nbsp;struct monst *mtmp;
&nbsp;int type;
&nbsp;{
&nbsp;    register struct obj *otmp;
&nbsp;
&nbsp;    for (otmp = mtmp-&gt;minvent; otmp; otmp = otmp-&gt;nobj)
&nbsp;        if (otmp-&gt;otyp == type)
&nbsp;            return otmp;
&nbsp;    return (struct obj *) 0;
&nbsp;}
&nbsp;
hit_bars
&nbsp;void
&nbsp;hit_bars(objp, objx, objy, barsx, barsy, your_fault, from_invent)
&nbsp;struct obj **objp;      /* *objp will be set to NULL if object breaks */
&nbsp;int objx, objy, barsx, barsy;
&nbsp;boolean your_fault, from_invent;
&nbsp;{
&nbsp;    struct obj *otmp = *objp;
&nbsp;    int obj_type = otmp-&gt;otyp;
&nbsp;    boolean unbreakable = (levl[barsx][barsy].wall_info &amp; W_NONDIGGABLE) != 0;
&nbsp;
&nbsp;    if (your_fault
&nbsp;        ? hero_breaks(otmp, objx, objy, from_invent)
&nbsp;        : breaks(otmp, objx, objy)) {
&nbsp;        *objp = 0; /* object is now gone */
&nbsp;        /* breakage makes its own noises */
&nbsp;        if (obj_type == POT_ACID) {
&nbsp;            if (cansee(barsx, barsy) &amp;&amp; !unbreakable)
&nbsp;                pline_The("iron bars are dissolved!");
&nbsp;            else
&nbsp;                You_hear(Hallucination ? "angry snakes!" : "a hissing noise.");
&nbsp;            if (!unbreakable)
&nbsp;                dissolve_bars(barsx, barsy);
&nbsp;        }
&nbsp;    }
&nbsp;    else if (obj_type == BOULDER || obj_type == HEAVY_IRON_BALL)
&nbsp;        pline("Whang!");
&nbsp;    else if (otmp-&gt;oclass == COIN_CLASS
&nbsp;             || objects[obj_type].oc_material == GOLD
&nbsp;             || objects[obj_type].oc_material == SILVER)
&nbsp;        pline("Clink!");
&nbsp;    else
&nbsp;        pline("Clonk!");
&nbsp;}
&nbsp;
hits_bars
&nbsp;/* TRUE iff thrown/kicked/rolled object doesn't pass through iron bars */
&nbsp;boolean
&nbsp;hits_bars(obj_p, x, y, barsx, barsy, always_hit, whodidit)
&nbsp;struct obj **obj_p; /* *obj_p will be set to NULL if object breaks */
&nbsp;int x, y, barsx, barsy;
&nbsp;int always_hit; /* caller can force a hit for items which would fit through */
&nbsp;int whodidit;   /* 1==hero, 0=other, -1==just check whether it'll pass thru */
&nbsp;{
&nbsp;    struct obj *otmp = *obj_p;
&nbsp;    int obj_type = otmp-&gt;otyp;
&nbsp;    boolean hits = always_hit;
&nbsp;
&nbsp;    if (!hits)
&nbsp;        switch (otmp-&gt;oclass) {
&nbsp;        case WEAPON_CLASS: {
&nbsp;            int oskill = objects[obj_type].oc_skill;
&nbsp;
&nbsp;            hits = (oskill != -P_BOW &amp;&amp; oskill != -P_CROSSBOW
&nbsp;                    &amp;&amp; oskill != -P_DART &amp;&amp; oskill != -P_SHURIKEN
&nbsp;                    &amp;&amp; oskill != P_SPEAR
&nbsp;                    &amp;&amp; oskill != P_KNIFE); /* but not dagger */
&nbsp;            break;
&nbsp;        }
&nbsp;        case ARMOR_CLASS:
&nbsp;            hits = (objects[obj_type].oc_armcat != ARM_GLOVES);
&nbsp;            break;
&nbsp;        case TOOL_CLASS:
&nbsp;            hits = (obj_type != SKELETON_KEY &amp;&amp; obj_type != LOCK_PICK
&nbsp;                    &amp;&amp; obj_type != CREDIT_CARD &amp;&amp; obj_type != TALLOW_CANDLE
&nbsp;                    &amp;&amp; obj_type != WAX_CANDLE &amp;&amp; obj_type != LENSES
&nbsp;                    &amp;&amp; obj_type != TIN_WHISTLE &amp;&amp; obj_type != MAGIC_WHISTLE);
&nbsp;            break;
&nbsp;        case ROCK_CLASS: /* includes boulder */
&nbsp;            if (obj_type != STATUE || mons[otmp-&gt;corpsenm].msize &gt; MZ_TINY)
&nbsp;                hits = TRUE;
&nbsp;            break;
&nbsp;        case FOOD_CLASS:
&nbsp;            if (obj_type == CORPSE &amp;&amp; mons[otmp-&gt;corpsenm].msize &gt; MZ_TINY)
&nbsp;                hits = TRUE;
&nbsp;            else
&nbsp;                hits = (obj_type == MEAT_STICK
&nbsp;                        || obj_type == HUGE_CHUNK_OF_MEAT);
&nbsp;            break;
&nbsp;        case SPBOOK_CLASS:
&nbsp;        case WAND_CLASS:
&nbsp;        case BALL_CLASS:
&nbsp;        case CHAIN_CLASS:
&nbsp;            hits = TRUE;
&nbsp;            break;
&nbsp;        default:
&nbsp;            break;
&nbsp;        }
&nbsp;
&nbsp;    if (hits &amp;&amp; whodidit != -1) {
&nbsp;        hit_bars(obj_p, x,y, barsx,barsy, whodidit, FALSE);
&nbsp;    }
&nbsp;
&nbsp;    return hits;
&nbsp;}
&nbsp;
&nbsp;/*mthrowu.c*/

</ax,ay></bx,by></bhitpos.x,.y>