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

Contents

1 Top of file
2 equipname
3 somegold
4 findgold
5 stealgold
6 stealarm
7 remove_worn_item
8 steal
9 mpickobj
10 stealamulet
11 maybe_absorb_item
12 mdrop_obj
13 mdrop_special_objs
14 relobj

Top of file
&nbsp;/* NetHack 3.6	steal.c	$NHDT-Date: 1496614914 2017/06/04 22:21:54 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.69 $ */
&nbsp;/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
&nbsp;/*-Copyright (c) Robert Patrick Rankin, 2012. */
&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_PTR int NDECL(stealarm);
&nbsp;
&nbsp;STATIC_DCL const char *FDECL(equipname, (struct obj *));
&nbsp;
equipname
&nbsp;STATIC_OVL const char *
&nbsp;equipname(otmp)
&nbsp;register struct obj *otmp;
&nbsp;{
&nbsp;    return ((otmp == uarmu)
&nbsp;                ? "shirt"
&nbsp;                : (otmp == uarmf)
&nbsp;                      ? "boots"
&nbsp;                      : (otmp == uarms)
&nbsp;                            ? "shield"
&nbsp;                            : (otmp == uarmg)
&nbsp;                                  ? "gloves"
&nbsp;                                  : (otmp == uarmc)
&nbsp;                                        ? cloak_simple_name(otmp)
&nbsp;                                        : (otmp == uarmh)
&nbsp;                                              ? helm_simple_name(otmp)
&nbsp;                                              : suit_simple_name(otmp));
&nbsp;}
&nbsp;
somegold
&nbsp;/* proportional subset of gold; return value actually fits in an int */
&nbsp;long
&nbsp;somegold(lmoney)
&nbsp;long lmoney;
&nbsp;{
&nbsp;#ifdef LINT /* long conv. ok */
&nbsp;    int igold = 0;
&nbsp;#else
&nbsp;    int igold = (lmoney &gt;= (long) LARGEST_INT) ? LARGEST_INT : (int) lmoney;
&nbsp;#endif
&nbsp;
&nbsp;    if (igold &lt; 50)
&nbsp;        ; /* all gold */
&nbsp;    else if (igold &lt; 100)
&nbsp;        igold = rn1(igold - 25 + 1, 25);
&nbsp;    else if (igold &lt; 500)
&nbsp;        igold = rn1(igold - 50 + 1, 50);
&nbsp;    else if (igold &lt; 1000)
&nbsp;        igold = rn1(igold - 100 + 1, 100);
&nbsp;    else if (igold &lt; 5000)
&nbsp;        igold = rn1(igold - 500 + 1, 500);
&nbsp;    else if (igold &lt; 10000)
&nbsp;        igold = rn1(igold - 1000 + 1, 1000);
&nbsp;    else
&nbsp;        igold = rn1(igold - 5000 + 1, 5000);
&nbsp;
&nbsp;    return (long) igold;
&nbsp;}
&nbsp;
findgold
&nbsp;/*
&nbsp; * Find the first (and hopefully only) gold object in a chain.
&nbsp; * Used when leprechaun (or you as leprechaun) looks for
&nbsp; * someone else's gold.  Returns a pointer so the gold may
&nbsp; * be seized without further searching.
&nbsp; * May search containers too.
&nbsp; * Deals in gold only, as leprechauns don't care for lesser coins.
&nbsp;*/
&nbsp;struct obj *
&nbsp;findgold(chain)
&nbsp;register struct obj *chain;
&nbsp;{
&nbsp;    while (chain &amp;&amp; chain-&gt;otyp != GOLD_PIECE)
&nbsp;        chain = chain-&gt;nobj;
&nbsp;    return chain;
&nbsp;}
&nbsp;
stealgold
&nbsp;/*
&nbsp; * Steal gold coins only.  Leprechauns don't care for lesser coins.
&nbsp;*/
&nbsp;void
&nbsp;stealgold(mtmp)
&nbsp;register struct monst *mtmp;
&nbsp;{
&nbsp;    register struct obj *fgold = g_at(u.ux, u.uy);
&nbsp;    register struct obj *ygold;
&nbsp;    register long tmp;
&nbsp;    struct monst *who;
&nbsp;    const char *whose, *what;
&nbsp;
&nbsp;    /* skip lesser coins on the floor */
&nbsp;    while (fgold &amp;&amp; fgold-&gt;otyp != GOLD_PIECE)
&nbsp;        fgold = fgold-&gt;nexthere;
&nbsp;
&nbsp;    /* Do you have real gold? */
&nbsp;    ygold = findgold(invent);
&nbsp;
&nbsp;    if (fgold &amp;&amp; (!ygold || fgold-&gt;quan &gt; ygold-&gt;quan || !rn2(5))) {
&nbsp;        obj_extract_self(fgold);
&nbsp;        add_to_minv(mtmp, fgold);
&nbsp;        newsym(u.ux, u.uy);
&nbsp;        if (u.usteed) {
&nbsp;            who = u.usteed;
&nbsp;            whose = s_suffix(y_monnam(who));
&nbsp;            what = makeplural(mbodypart(who, FOOT));
&nbsp;        } else {
&nbsp;            who = &amp;youmonst
&nbsp;            whose = "your";
&nbsp;            what = makeplural(body_part(FOOT));
&nbsp;        }
&nbsp;        /* [ avoid "between your rear regions" :-] */
&nbsp;        if (slithy(who-&gt;data))
&nbsp;            what = "coils";
&nbsp;        /* reduce "rear hooves/claws" to "hooves/claws" */
&nbsp;        if (!strncmp(what, "rear ", 5))
&nbsp;            what += 5;
&nbsp;        pline("%s quickly snatches some gold from %s %s %s!", Monnam(mtmp),
&nbsp;              (Levitation || Flying) ? "beneath" : "between", whose, what);
&nbsp;        if (!ygold || !rn2(5)) {
&nbsp;            if (!tele_restrict(mtmp))
&nbsp;                (void) rloc(mtmp, TRUE);
&nbsp;            monflee(mtmp, 0, FALSE, FALSE);
&nbsp;        }
&nbsp;    } else if (ygold) {
&nbsp;        const int gold_price = objects[GOLD_PIECE].oc_cost;
&nbsp;
&nbsp;        tmp = (somegold(money_cnt(invent)) + gold_price - 1) / gold_price;
&nbsp;        tmp = min(tmp, ygold-&gt;quan);
&nbsp;        if (tmp &lt; ygold-&gt;quan)
&nbsp;            ygold = splitobj(ygold, tmp);
&nbsp;        else
&nbsp;            setnotworn(ygold);
&nbsp;        freeinv(ygold);
&nbsp;        add_to_minv(mtmp, ygold);
&nbsp;        Your("purse feels lighter.");
&nbsp;        if (!tele_restrict(mtmp))
&nbsp;            (void) rloc(mtmp, TRUE);
&nbsp;        monflee(mtmp, 0, FALSE, FALSE);
&nbsp;        context.botl = 1;
&nbsp;    }
&nbsp;}
&nbsp;
stealarm
&nbsp;/* steal armor after you finish taking it off */
&nbsp;unsigned int stealoid; /* object to be stolen */
&nbsp;unsigned int stealmid; /* monster doing the stealing */
&nbsp;
&nbsp;STATIC_PTR int
&nbsp;stealarm(VOID_ARGS)
&nbsp;{
&nbsp;    register struct monst *mtmp;
&nbsp;    register struct obj *otmp;
&nbsp;
&nbsp;    for (otmp = invent; otmp; otmp = otmp-&gt;nobj) {
&nbsp;        if (otmp-&gt;o_id == stealoid) {
&nbsp;            for (mtmp = fmon; mtmp; mtmp = mtmp-&gt;nmon) {
&nbsp;                if (mtmp-&gt;m_id == stealmid) {
&nbsp;                    if (DEADMONSTER(mtmp))
&nbsp;                        impossible("stealarm(): dead monster stealing");
&nbsp;                    if (!dmgtype(mtmp-&gt;data, AD_SITM)) /* polymorphed */
&nbsp;                        goto botm;
&nbsp;                    if (otmp-&gt;unpaid)
&nbsp;                        subfrombill(otmp, shop_keeper(*u.ushops));
&nbsp;                    freeinv(otmp);
&nbsp;                    pline("%s steals %s!", Monnam(mtmp), doname(otmp));
&nbsp;                    (void) mpickobj(mtmp, otmp); /* may free otmp */
&nbsp;                    /* Implies seduction, "you gladly hand over ..."
&nbsp;                       so we don't set mavenge bit here. */
&nbsp;                    monflee(mtmp, 0, FALSE, FALSE);
&nbsp;                    if (!tele_restrict(mtmp))
&nbsp;                        (void) rloc(mtmp, TRUE);
&nbsp;                    break;
&nbsp;                }
&nbsp;            }
&nbsp;            break;
&nbsp;        }
&nbsp;    }
&nbsp;botm:
&nbsp;    stealoid = 0;
&nbsp;    return 0;
&nbsp;}
&nbsp;
remove_worn_item
&nbsp;/* An object you're wearing has been taken off by a monster (theft or
&nbsp;   seduction).  Also used if a worn item gets transformed (stone to flesh). */
&nbsp;void
&nbsp;remove_worn_item(obj, unchain_ball)
&nbsp;struct obj *obj;
&nbsp;boolean unchain_ball; /* whether to unpunish or just unwield */
&nbsp;{
&nbsp;    if (donning(obj))
&nbsp;        cancel_don();
&nbsp;    if (!obj-&gt;owornmask)
&nbsp;        return;
&nbsp;
&nbsp;    if (obj-&gt;owornmask &amp; W_ARMOR) {
&nbsp;        if (obj == uskin) {
&nbsp;            impossible("Removing embedded scales?");
&nbsp;            skinback(TRUE); /* uarm = uskin; uskin = 0; */
&nbsp;        }
&nbsp;        if (obj == uarm)
&nbsp;            (void) Armor_off();
&nbsp;        else if (obj == uarmc)
&nbsp;            (void) Cloak_off();
&nbsp;        else if (obj == uarmf)
&nbsp;            (void) Boots_off();
&nbsp;        else if (obj == uarmg)
&nbsp;            (void) Gloves_off();
&nbsp;        else if (obj == uarmh)
&nbsp;            (void) Helmet_off();
&nbsp;        else if (obj == uarms)
&nbsp;            (void) Shield_off();
&nbsp;        else if (obj == uarmu)
&nbsp;            (void) Shirt_off();
&nbsp;        /* catchall -- should never happen */
&nbsp;        else
&nbsp;            setworn((struct obj *) 0, obj-&gt;owornmask &amp; W_ARMOR);
&nbsp;    } else if (obj-&gt;owornmask &amp; W_AMUL) {
&nbsp;        Amulet_off();
&nbsp;    } else if (obj-&gt;owornmask &amp; W_RING) {
&nbsp;        Ring_gone(obj);
&nbsp;    } else if (obj-&gt;owornmask &amp; W_TOOL) {
&nbsp;        Blindf_off(obj);
&nbsp;    } else if (obj-&gt;owornmask &amp; W_WEAPON) {
&nbsp;        if (obj == uwep)
&nbsp;            uwepgone();
&nbsp;        if (obj == uswapwep)
&nbsp;            uswapwepgone();
&nbsp;        if (obj == uquiver)
&nbsp;            uqwepgone();
&nbsp;    }
&nbsp;
&nbsp;    if (obj-&gt;owornmask &amp; (W_BALL | W_CHAIN)) {
&nbsp;        if (unchain_ball)
&nbsp;            unpunish();
&nbsp;    } else if (obj-&gt;owornmask) {
&nbsp;        /* catchall */
&nbsp;        setnotworn(obj);
&nbsp;    }
&nbsp;}
&nbsp;
steal
&nbsp;/* Returns 1 when something was stolen (or at least, when N should flee now)
&nbsp; * Returns -1 if the monster died in the attempt
&nbsp; * Avoid stealing the object stealoid
&nbsp; * Nymphs and monkeys won't steal coins
&nbsp; */
&nbsp;int
&nbsp;steal(mtmp, objnambuf)
&nbsp;struct monst *mtmp;
&nbsp;char *objnambuf;
&nbsp;{
&nbsp;    struct obj *otmp;
&nbsp;    int tmp, could_petrify, armordelay, olddelay, named = 0, retrycnt = 0;
&nbsp;    boolean monkey_business, /* true iff an animal is doing the thievery */
&nbsp;        was_doffing;
&nbsp;
&nbsp;    if (objnambuf)
&nbsp;        *objnambuf = '\0';
&nbsp;    /* the following is true if successful on first of two attacks. */
&nbsp;    if (!monnear(mtmp, u.ux, u.uy))
&nbsp;        return 0;
&nbsp;
&nbsp;    /* food being eaten might already be used up but will not have
&nbsp;       been removed from inventory yet; we don't want to steal that,
&nbsp;       so this will cause it to be removed now */
&nbsp;    if (occupation)
&nbsp;        (void) maybe_finished_meal(FALSE);
&nbsp;
&nbsp;    if (!invent || (inv_cnt(FALSE) == 1 &amp;&amp; uskin)) {
&nbsp;    nothing_to_steal:
&nbsp;        /* Not even a thousand men in armor can strip a naked man. */
&nbsp;        if (Blind)
&nbsp;            pline("Somebody tries to rob you, but finds nothing to steal.");
&nbsp;        else
&nbsp;            pline("%s tries to rob you, but there is nothing to steal!",
&nbsp;                  Monnam(mtmp));
&nbsp;        return 1; /* let her flee */
&nbsp;    }
&nbsp;
&nbsp;    monkey_business = is_animal(mtmp-&gt;data);
&nbsp;    if (monkey_business || uarmg) {
&nbsp;        ; /* skip ring special cases */
&nbsp;    } else if (Adornment &amp; LEFT_RING) {
&nbsp;        otmp = uleft;
&nbsp;        goto gotobj;
&nbsp;    } else if (Adornment &amp; RIGHT_RING) {
&nbsp;        otmp = uright;
&nbsp;        goto gotobj;
&nbsp;    }
&nbsp;
&nbsp;retry:
&nbsp;    tmp = 0;
&nbsp;    for (otmp = invent; otmp; otmp = otmp-&gt;nobj)
&nbsp;        if ((!uarm || otmp != uarmc) &amp;&amp; otmp != uskin
&nbsp;            &amp;&amp; otmp-&gt;oclass != COIN_CLASS)
&nbsp;            tmp += (otmp-&gt;owornmask &amp; (W_ARMOR | W_ACCESSORY)) ? 5 : 1;
&nbsp;    if (!tmp)
&nbsp;        goto nothing_to_steal;
&nbsp;    tmp = rn2(tmp);
&nbsp;    for (otmp = invent; otmp; otmp = otmp-&gt;nobj)
&nbsp;        if ((!uarm || otmp != uarmc) &amp;&amp; otmp != uskin
&nbsp;            &amp;&amp; otmp-&gt;oclass != COIN_CLASS) {
&nbsp;            tmp -= (otmp-&gt;owornmask &amp; (W_ARMOR | W_ACCESSORY)) ? 5 : 1;
&nbsp;            if (tmp &lt; 0)
&nbsp;                break;
&nbsp;        }
&nbsp;    if (!otmp) {
&nbsp;        impossible("Steal fails!");
&nbsp;        return 0;
&nbsp;    }
&nbsp;    /* can't steal ring(s) while wearing gloves */
&nbsp;    if ((otmp == uleft || otmp == uright) &amp;&amp; uarmg)
&nbsp;        otmp = uarmg;
&nbsp;    /* can't steal gloves while wielding - so steal the wielded item. */
&nbsp;    if (otmp == uarmg &amp;&amp; uwep)
&nbsp;        otmp = uwep;
&nbsp;    /* can't steal armor while wearing cloak - so steal the cloak. */
&nbsp;    else if (otmp == uarm &amp;&amp; uarmc)
&nbsp;        otmp = uarmc;
&nbsp;    /* can't steal shirt while wearing cloak or suit */
&nbsp;    else if (otmp == uarmu &amp;&amp; uarmc)
&nbsp;        otmp = uarmc;
&nbsp;    else if (otmp == uarmu &amp;&amp; uarm)
&nbsp;        otmp = uarm;
&nbsp;
&nbsp;gotobj:
&nbsp;    if (otmp-&gt;o_id == stealoid)
&nbsp;        return 0;
&nbsp;
&nbsp;    if (otmp-&gt;otyp == BOULDER &amp;&amp; !throws_rocks(mtmp-&gt;data)) {
&nbsp;        if (!retrycnt++)
&nbsp;            goto retry;
&nbsp;        goto cant_take;
&nbsp;    }
&nbsp;    /* animals can't overcome curse stickiness nor unlock chains */
&nbsp;    if (monkey_business) {
&nbsp;        boolean ostuck;
&nbsp;        /* is the player prevented from voluntarily giving up this item?
&nbsp;           (ignores loadstones; the !can_carry() check will catch those) */
&nbsp;        if (otmp == uball)
&nbsp;            ostuck = TRUE; /* effectively worn; curse is implicit */
&nbsp;        else if (otmp == uquiver || (otmp == uswapwep &amp;&amp; !u.twoweap))
&nbsp;            ostuck = FALSE; /* not really worn; curse doesn't matter */
&nbsp;        else
&nbsp;            ostuck = ((otmp-&gt;cursed &amp;&amp; otmp-&gt;owornmask)
&nbsp;                      /* nymphs can steal rings from under
&nbsp;                         cursed weapon but animals can't */
&nbsp;                      || (otmp == uright &amp;&amp; welded(uwep))
&nbsp;                      || (otmp == uleft &amp;&amp; welded(uwep) &amp;&amp; bimanual(uwep)));
&nbsp;
&nbsp;        if (ostuck || can_carry(mtmp, otmp) == 0) {
&nbsp;            static const char *const how[] = { "steal", "snatch", "grab",
&nbsp;                                               "take" };
&nbsp;        cant_take:
&nbsp;            pline("%s tries to %s %s%s but gives up.", Monnam(mtmp),
&nbsp;                  how[rn2(SIZE(how))],
&nbsp;                  (otmp-&gt;owornmask &amp; W_ARMOR) ? "your " : "",
&nbsp;                  (otmp-&gt;owornmask &amp; W_ARMOR) ? equipname(otmp)
&nbsp;                                              : yname(otmp));
&nbsp;            /* the fewer items you have, the less likely the thief
&nbsp;               is going to stick around to try again (0) instead of
&nbsp;               running away (1) */
&nbsp;            return !rn2(inv_cnt(FALSE) / 5 + 2);
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    if (otmp-&gt;otyp == LEASH &amp;&amp; otmp-&gt;leashmon) {
&nbsp;        if (monkey_business &amp;&amp; otmp-&gt;cursed)
&nbsp;            goto cant_take;
&nbsp;        o_unleash(otmp);
&nbsp;    }
&nbsp;
&nbsp;    was_doffing = doffing(otmp);
&nbsp;    /* stop donning/doffing now so that afternmv won't be clobbered
&nbsp;       below; stop_occupation doesn't handle donning/doffing */
&nbsp;    olddelay = stop_donning(otmp);
&nbsp;    /* you're going to notice the theft... */
&nbsp;    stop_occupation();
&nbsp;
&nbsp;    if (otmp-&gt;owornmask &amp; (W_ARMOR | W_ACCESSORY)) {
&nbsp;        switch (otmp-&gt;oclass) {
&nbsp;        case TOOL_CLASS:
&nbsp;        case AMULET_CLASS:
&nbsp;        case RING_CLASS:
&nbsp;        case FOOD_CLASS: /* meat ring */
&nbsp;            remove_worn_item(otmp, TRUE);
&nbsp;            break;
&nbsp;        case ARMOR_CLASS:
&nbsp;            armordelay = objects[otmp-&gt;otyp].oc_delay;
&nbsp;            if (olddelay &gt; 0 &amp;&amp; olddelay &lt; armordelay)
&nbsp;                armordelay = olddelay;
&nbsp;            if (monkey_business) {
&nbsp;                /* animals usually don't have enough patience
&nbsp;                   to take off items which require extra time */
&nbsp;                if (armordelay &gt;= 1 &amp;&amp; !olddelay &amp;&amp; rn2(10))
&nbsp;                    goto cant_take;
&nbsp;                remove_worn_item(otmp, TRUE);
&nbsp;                break;
&nbsp;            } else {
&nbsp;                int curssv = otmp-&gt;cursed;
&nbsp;                int slowly;
&nbsp;                boolean seen = canspotmon(mtmp);
&nbsp;
&nbsp;                otmp-&gt;cursed = 0;
&nbsp;                /* can't charm you without first waking you */
&nbsp;                if (Unaware)
&nbsp;                    unmul((char *) 0);
&nbsp;                slowly = (armordelay &gt;= 1 || multi &lt; 0);
&nbsp;                if (flags.female)
&nbsp;                    pline("%s charms you.  You gladly %s your %s.",
&nbsp;                          !seen ? "She" : Monnam(mtmp),
&nbsp;                          curssv ? "let her take"
&nbsp;                                 : !slowly ? "hand over"
&nbsp;                                           : was_doffing ? "continue removing"
&nbsp;                                                         : "start removing",
&nbsp;                          equipname(otmp));
&nbsp;                else
&nbsp;                    pline("%s seduces you and %s off your %s.",
&nbsp;                          !seen ? "She" : Adjmonnam(mtmp, "beautiful"),
&nbsp;                          curssv
&nbsp;                              ? "helps you to take"
&nbsp;                              : !slowly ? "you take"
&nbsp;                                        : was_doffing ? "you continue taking"
&nbsp;                                                      : "you start taking",
&nbsp;                          equipname(otmp));
&nbsp;                named++;
&nbsp;                /* the following is to set multi for later on */
&nbsp;                nomul(-armordelay);
&nbsp;                multi_reason = "taking off clothes";
&nbsp;                nomovemsg = 0;
&nbsp;                remove_worn_item(otmp, TRUE);
&nbsp;                otmp-&gt;cursed = curssv;
&nbsp;                if (multi &lt; 0) {
&nbsp;                    /*
&nbsp;                    multi = 0;
&nbsp;                    afternmv = 0;
&nbsp;                    */
&nbsp;                    stealoid = otmp-&gt;o_id;
&nbsp;                    stealmid = mtmp-&gt;m_id;
&nbsp;                    afternmv = stealarm;
&nbsp;                    return 0;
&nbsp;                }
&nbsp;            }
&nbsp;            break;
&nbsp;        default:
&nbsp;            impossible("Tried to steal a strange worn thing. [%d]",
&nbsp;                       otmp-&gt;oclass);
&nbsp;        }
&nbsp;    } else if (otmp-&gt;owornmask)
&nbsp;        remove_worn_item(otmp, TRUE);
&nbsp;
&nbsp;    /* do this before removing it from inventory */
&nbsp;    if (objnambuf)
&nbsp;        Strcpy(objnambuf, yname(otmp));
&nbsp;    /* set mavenge bit so knights won't suffer an
&nbsp;     * alignment penalty during retaliation;
&nbsp;     */
&nbsp;    mtmp-&gt;mavenge = 1;
&nbsp;
&nbsp;    if (otmp-&gt;unpaid)
&nbsp;        subfrombill(otmp, shop_keeper(*u.ushops));
&nbsp;    freeinv(otmp);
&nbsp;    pline("%s stole %s.", named ? "She" : Monnam(mtmp), doname(otmp));
&nbsp;    could_petrify =
&nbsp;        (otmp-&gt;otyp == CORPSE &amp;&amp; touch_petrifies(&amp;mons[otmp-&gt;corpsenm]));
&nbsp;    (void) mpickobj(mtmp, otmp); /* may free otmp */
&nbsp;    if (could_petrify &amp;&amp; !(mtmp-&gt;misc_worn_check &amp; W_ARMG)) {
&nbsp;        minstapetrify(mtmp, TRUE);
&nbsp;        return -1;
&nbsp;    }
&nbsp;    return (multi &lt; 0) ? 0 : 1;
&nbsp;}
&nbsp;
mpickobj
&nbsp;/* Returns 1 if otmp is free'd, 0 otherwise. */
&nbsp;int
&nbsp;mpickobj(mtmp, otmp)
&nbsp;register struct monst *mtmp;
&nbsp;register struct obj *otmp;
&nbsp;{
&nbsp;    int freed_otmp;
&nbsp;    boolean snuff_otmp = FALSE;
&nbsp;
&nbsp;    /* if monster is acquiring a thrown or kicked object, the throwing
&nbsp;       or kicking code shouldn't continue to track and place it */
&nbsp;    if (otmp == thrownobj)
&nbsp;        thrownobj = 0;
&nbsp;    else if (otmp == kickedobj)
&nbsp;        kickedobj = 0;
&nbsp;    /* don't want hidden light source inside the monster; assumes that
&nbsp;       engulfers won't have external inventories; whirly monsters cause
&nbsp;       the light to be extinguished rather than letting it shine thru */
&nbsp;    if (obj_sheds_light(otmp) &amp;&amp; attacktype(mtmp-&gt;data, AT_ENGL)) {
&nbsp;        /* this is probably a burning object that you dropped or threw */
&nbsp;        if (u.uswallow &amp;&amp; mtmp == u.ustuck &amp;&amp; !Blind)
&nbsp;            pline("%s out.", Tobjnam(otmp, "go"));
&nbsp;        snuff_otmp = TRUE;
&nbsp;    }
&nbsp;    /* for hero owned object on shop floor, mtmp is taking possession
&nbsp;       and if it's eventually dropped in a shop, shk will claim it */
&nbsp;    if (!mtmp-&gt;mtame)
&nbsp;        otmp-&gt;no_charge = 0;
&nbsp;    /* Must do carrying effects on object prior to add_to_minv() */
&nbsp;    carry_obj_effects(otmp);
&nbsp;    /* add_to_minv() might free otmp [if merged with something else],
&nbsp;       so we have to call it after doing the object checks */
&nbsp;    freed_otmp = add_to_minv(mtmp, otmp);
&nbsp;    /* and we had to defer this until object is in mtmp's inventory */
&nbsp;    if (snuff_otmp)
&nbsp;        snuff_light_source(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;    return freed_otmp;
&nbsp;}
&nbsp;
stealamulet
&nbsp;/* called for AD_SAMU (the Wizard and quest nemeses) */
&nbsp;void
&nbsp;stealamulet(mtmp)
&nbsp;struct monst *mtmp;
&nbsp;{
&nbsp;    char buf[BUFSZ];
&nbsp;    struct obj *otmp = 0, *obj = 0;
&nbsp;    int real = 0, fake = 0, n;
&nbsp;
&nbsp;    /* target every quest artifact, not just current role's;
&nbsp;       if hero has more than one, choose randomly so that player
&nbsp;       can't use inventory ordering to influence the theft */
&nbsp;    for (n = 0, obj = invent; obj; obj = obj-&gt;nobj)
&nbsp;        if (any_quest_artifact(obj))
&nbsp;            ++n, otmp = obj;
&nbsp;    if (n &gt; 1) {
&nbsp;        n = rnd(n);
&nbsp;        for (otmp = invent; otmp; otmp = otmp-&gt;nobj)
&nbsp;            if (any_quest_artifact(otmp) &amp;&amp; !--n)
&nbsp;                break;
&nbsp;    }
&nbsp;
&nbsp;    if (!otmp) {
&nbsp;        /* if we didn't find any quest arifact, find another valuable item */
&nbsp;        if (u.uhave.amulet) {
&nbsp;            real = AMULET_OF_YENDOR;
&nbsp;            fake = FAKE_AMULET_OF_YENDOR;
&nbsp;        } else if (u.uhave.bell) {
&nbsp;            real = BELL_OF_OPENING;
&nbsp;            fake = BELL;
&nbsp;        } else if (u.uhave.book) {
&nbsp;            real = SPE_BOOK_OF_THE_DEAD;
&nbsp;        } else if (u.uhave.menorah) {
&nbsp;            real = CANDELABRUM_OF_INVOCATION;
&nbsp;        } else
&nbsp;            return; /* you have nothing of special interest */
&nbsp;
&nbsp;        /* If we get here, real and fake have been set up. */
&nbsp;        for (n = 0, obj = invent; obj; obj = obj-&gt;nobj)
&nbsp;            if (obj-&gt;otyp == real || (obj-&gt;otyp == fake &amp;&amp; !mtmp-&gt;iswiz))
&nbsp;                ++n, otmp = obj;
&nbsp;        if (n &gt; 1) {
&nbsp;            n = rnd(n);
&nbsp;            for (otmp = invent; otmp; otmp = otmp-&gt;nobj)
&nbsp;                if ((otmp-&gt;otyp == real
&nbsp;                     || (otmp-&gt;otyp == fake &amp;&amp; !mtmp-&gt;iswiz)) &amp;&amp; !--n)
&nbsp;                    break;
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    if (otmp) { /* we have something to snatch */
&nbsp;        /* take off outer gear if we're targetting [hypothetical]
&nbsp;           quest artifact suit, shirt, gloves, or rings */
&nbsp;        if ((otmp == uarm || otmp == uarmu) &amp;&amp; uarmc)
&nbsp;            remove_worn_item(uarmc, FALSE);
&nbsp;        if (otmp == uarmu &amp;&amp; uarm)
&nbsp;            remove_worn_item(uarm, FALSE);
&nbsp;        if ((otmp == uarmg || ((otmp == uright || otmp == uleft) &amp;&amp; uarmg))
&nbsp;            &amp;&amp; uwep) {
&nbsp;            /* gloves are about to be unworn; unwield weapon(s) first */
&nbsp;            if (u.twoweap)    /* remove_worn_item(uswapwep) indirectly */
&nbsp;                remove_worn_item(uswapwep, FALSE); /* clears u.twoweap */
&nbsp;            remove_worn_item(uwep, FALSE);
&nbsp;        }
&nbsp;        if ((otmp == uright || otmp == uleft) &amp;&amp; uarmg)
&nbsp;            /* calls Gloves_off() to handle wielded cockatrice corpse */
&nbsp;            remove_worn_item(uarmg, FALSE);
&nbsp;
&nbsp;        /* finally, steal the target item */
&nbsp;        if (otmp-&gt;owornmask)
&nbsp;            remove_worn_item(otmp, TRUE);
&nbsp;        if (otmp-&gt;unpaid)
&nbsp;            subfrombill(otmp, shop_keeper(*u.ushops));
&nbsp;        freeinv(otmp);
&nbsp;        Strcpy(buf, doname(otmp));
&nbsp;        (void) mpickobj(mtmp, otmp); /* could merge and free otmp but won't */
&nbsp;        pline("%s steals %s!", Monnam(mtmp), buf);
&nbsp;        if (can_teleport(mtmp-&gt;data) &amp;&amp; !tele_restrict(mtmp))
&nbsp;            (void) rloc(mtmp, TRUE);
&nbsp;    }
&nbsp;}
&nbsp;
maybe_absorb_item
&nbsp;/* when a mimic gets poked with something, it might take that thing
&nbsp;   (at present, only implemented for when the hero does the poking) */
&nbsp;void
&nbsp;maybe_absorb_item(mon, obj, ochance, achance)
&nbsp;struct monst *mon;
&nbsp;struct obj *obj;
&nbsp;int ochance, achance; /* percent chance for ordinary item, artifact */
&nbsp;{
&nbsp;    if (obj == uball || obj == uchain || obj-&gt;oclass == ROCK_CLASS
&nbsp;        || obj_resists(obj, 100 - ochance, 100 - achance)
&nbsp;        || !touch_artifact(obj, mon))
&nbsp;        return;
&nbsp;
&nbsp;    if (carried(obj)) {
&nbsp;        if (obj-&gt;owornmask)
&nbsp;            remove_worn_item(obj, TRUE);
&nbsp;        if (obj-&gt;unpaid)
&nbsp;            subfrombill(obj, shop_keeper(*u.ushops));
&nbsp;        if (cansee(mon-&gt;mx, mon-&gt;my)) {
&nbsp;            const char *MonName = Monnam(mon);
&nbsp;
&nbsp;            /* mon might be invisible; avoid "It pulls ... and absorbs it!" */
&nbsp;            if (!strcmp(MonName, "It"))
&nbsp;                MonName = "Something";
&nbsp;            pline("%s pulls %s away from you and absorbs %s!", MonName,
&nbsp;                  yname(obj), (obj-&gt;quan &gt; 1L) ? "them" : "it");
&nbsp;        } else {
&nbsp;            const char *hand_s = body_part(HAND);
&nbsp;
&nbsp;            if (bimanual(obj))
&nbsp;                hand_s = makeplural(hand_s);
&nbsp;            pline("%s %s pulled from your %s!", upstart(yname(obj)),
&nbsp;                  otense(obj, "are"), hand_s);
&nbsp;        }
&nbsp;        freeinv(obj);
&nbsp;    } else {
&nbsp;        /* not carried; presumably thrown or kicked */
&nbsp;        if (canspotmon(mon))
&nbsp;            pline("%s absorbs %s!", Monnam(mon), yname(obj));
&nbsp;    }
&nbsp;    /* add to mon's inventory */
&nbsp;    (void) mpickobj(mon, obj);
&nbsp;}
&nbsp;
mdrop_obj
&nbsp;/* drop one object taken from a (possibly dead) monster's inventory */
&nbsp;void
&nbsp;mdrop_obj(mon, obj, verbosely)
&nbsp;struct monst *mon;
&nbsp;struct obj *obj;
&nbsp;boolean verbosely;
&nbsp;{
&nbsp;    int omx = mon-&gt;mx, omy = mon-&gt;my;
&nbsp;    boolean update_mon = FALSE;
&nbsp;
&nbsp;    if (obj-&gt;owornmask) {
&nbsp;        /* perform worn item handling if the monster is still alive */
&nbsp;        if (mon-&gt;mhp &gt; 0) {
&nbsp;            mon-&gt;misc_worn_check &amp;= ~obj-&gt;owornmask;
&nbsp;            update_mon = TRUE;
&nbsp;
&nbsp;        /* don't charge for an owned saddle on dead steed (provided
&nbsp;           that the hero is within the same shop at the time) */
&nbsp;        } else if (mon-&gt;mtame &amp;&amp; (obj-&gt;owornmask &amp; W_SADDLE) != 0L
&nbsp;                   &amp;&amp; !obj-&gt;unpaid &amp;&amp; costly_spot(omx, omy)
&nbsp;                   /* being at costly_spot guarantees lev-&gt;roomno is not 0 */
&nbsp;                   &amp;&amp; index(in_rooms(u.ux, u.uy, SHOPBASE),
&nbsp;                            levl[omx][omy].roomno)) {
&nbsp;            obj-&gt;no_charge = 1;
&nbsp;        }
&nbsp;        /* this should be done even if the monster has died */
&nbsp;        if (obj-&gt;owornmask &amp; W_WEP)
&nbsp;            setmnotwielded(mon, obj);
&nbsp;        obj-&gt;owornmask = 0L;
&nbsp;    }
&nbsp;    /* obj_no_longer_held(obj); -- done by place_object */
&nbsp;    if (verbosely &amp;&amp; cansee(omx, omy))
&nbsp;        pline("%s drops %s.", Monnam(mon), distant_name(obj, doname));
&nbsp;    if (!flooreffects(obj, omx, omy, "fall")) {
&nbsp;        place_object(obj, omx, omy);
&nbsp;        stackobj(obj);
&nbsp;    }
&nbsp;    /* do this last, after placing obj on floor; removing steed's saddle
&nbsp;       throws rider, possibly inflicting fatal damage and producing bones */
&nbsp;    if (update_mon)
&nbsp;        update_mon_intrinsics(mon, obj, FALSE, TRUE);
&nbsp;}
&nbsp;
mdrop_special_objs
&nbsp;/* some monsters bypass the normal rules for moving between levels or
&nbsp;   even leaving the game entirely; when that happens, prevent them from
&nbsp;   taking the Amulet, invocation items, or quest artifact with them */
&nbsp;void
&nbsp;mdrop_special_objs(mon)
&nbsp;struct monst *mon;
&nbsp;{
&nbsp;    struct obj *obj, *otmp;
&nbsp;
&nbsp;    for (obj = mon-&gt;minvent; obj; obj = otmp) {
&nbsp;        otmp = obj-&gt;nobj;
&nbsp;        /* the Amulet, invocation tools, and Rider corpses resist even when
&nbsp;           artifacts and ordinary objects are given 0% resistance chance;
&nbsp;           current role's quest artifact is rescued too--quest artifacts
&nbsp;           for the other roles are not */
&nbsp;        if (obj_resists(obj, 0, 0) || is_quest_artifact(obj)) {
&nbsp;            obj_extract_self(obj);
&nbsp;            mdrop_obj(mon, obj, FALSE);
&nbsp;        }
&nbsp;    }
&nbsp;}
&nbsp;
relobj
&nbsp;/* release the objects the creature is carrying */
&nbsp;void
&nbsp;relobj(mtmp, show, is_pet)
&nbsp;struct monst *mtmp;
&nbsp;int show;
&nbsp;boolean is_pet; /* If true, pet should keep wielded/worn items */
&nbsp;{
&nbsp;    struct obj *otmp;
&nbsp;    int omx = mtmp-&gt;mx, omy = mtmp-&gt;my;
&nbsp;
&nbsp;    /* vault guard's gold goes away rather than be dropped... */
&nbsp;    if (mtmp-&gt;isgd &amp;&amp; (otmp = findgold(mtmp-&gt;minvent)) != 0) {
&nbsp;        if (canspotmon(mtmp))
&nbsp;            pline("%s gold %s.", s_suffix(Monnam(mtmp)),
&nbsp;                  canseemon(mtmp) ? "vanishes" : "seems to vanish");
&nbsp;        obj_extract_self(otmp);
&nbsp;        obfree(otmp, (struct obj *) 0);
&nbsp;    } /* isgd &amp;&amp; has gold */
&nbsp;
&nbsp;    while ((otmp = (is_pet ? droppables(mtmp) : mtmp-&gt;minvent)) != 0) {
&nbsp;        obj_extract_self(otmp);
&nbsp;        mdrop_obj(mtmp, otmp, is_pet &amp;&amp; flags.verbose);
&nbsp;    }
&nbsp;
&nbsp;    if (show &amp;&amp; cansee(omx, omy))
&nbsp;        newsym(omx, omy);
&nbsp;}
&nbsp;
&nbsp;/*steal.c*/