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

Contents

1 Top of file
2 newedog
3 free_edog
4 initedog
5 pet_type
6 make_familiar
7 makedog
8 update_mlstmv
9 losedogs
10 mon_arrive
11 mon_catchup_elapsed_time
12 keepdogs
13 migrate_to_level
14 dogfood
15 tamedog
16 wary_dog
17 abuse_dog

Top of file
&nbsp;/* NetHack 3.6	dog.c	$NHDT-Date: 1502753406 2017/08/14 23:30:06 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.60 $ */
&nbsp;/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
&nbsp;/*-Copyright (c) Robert Patrick Rankin, 2011. */
&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 NDECL(pet_type);
&nbsp;
newedog
&nbsp;void
&nbsp;newedog(mtmp)
&nbsp;struct monst *mtmp;
&nbsp;{
&nbsp;    if (!mtmp-&gt;mextra)
&nbsp;        mtmp-&gt;mextra = newmextra();
&nbsp;    if (!EDOG(mtmp)) {
&nbsp;        EDOG(mtmp) = (struct edog *) alloc(sizeof(struct edog));
&nbsp;        (void) memset((genericptr_t) EDOG(mtmp), 0, sizeof(struct edog));
&nbsp;    }
&nbsp;}
&nbsp;
free_edog
&nbsp;void
&nbsp;free_edog(mtmp)
&nbsp;struct monst *mtmp;
&nbsp;{
&nbsp;    if (mtmp-&gt;mextra &amp;&amp; EDOG(mtmp)) {
&nbsp;        free((genericptr_t) EDOG(mtmp));
&nbsp;        EDOG(mtmp) = (struct edog *) 0;
&nbsp;    }
&nbsp;    mtmp-&gt;mtame = 0;
&nbsp;}
&nbsp;
initedog
&nbsp;void
&nbsp;initedog(mtmp)
&nbsp;register struct monst *mtmp;
&nbsp;{
&nbsp;    mtmp-&gt;mtame = is_domestic(mtmp-&gt;data) ? 10 : 5;
&nbsp;    mtmp-&gt;mpeaceful = 1;
&nbsp;    mtmp-&gt;mavenge = 0;
&nbsp;    set_malign(mtmp); /* recalc alignment now that it's tamed */
&nbsp;    mtmp-&gt;mleashed = 0;
&nbsp;    mtmp-&gt;meating = 0;
&nbsp;    EDOG(mtmp)-&gt;droptime = 0;
&nbsp;    EDOG(mtmp)-&gt;dropdist = 10000;
&nbsp;    EDOG(mtmp)-&gt;apport = ACURR(A_CHA);
&nbsp;    EDOG(mtmp)-&gt;whistletime = 0;
&nbsp;    EDOG(mtmp)-&gt;hungrytime = 1000 + monstermoves;
&nbsp;    EDOG(mtmp)-&gt;ogoal.x = -1; /* force error if used before set */
&nbsp;    EDOG(mtmp)-&gt;ogoal.y = -1;
&nbsp;    EDOG(mtmp)-&gt;abuse = 0;
&nbsp;    EDOG(mtmp)-&gt;revivals = 0;
&nbsp;    EDOG(mtmp)-&gt;mhpmax_penalty = 0;
&nbsp;    EDOG(mtmp)-&gt;killed_by_u = 0;
&nbsp;}
&nbsp;
pet_type
&nbsp;STATIC_OVL int
&nbsp;pet_type()
&nbsp;{
&nbsp;    if (urole.petnum != NON_PM)
&nbsp;        return  urole.petnum;
&nbsp;    else if (preferred_pet == 'c')
&nbsp;        return  PM_KITTEN;
&nbsp;    else if (preferred_pet == 'd')
&nbsp;        return  PM_LITTLE_DOG;
&nbsp;    else
&nbsp;        return  rn2(2) ? PM_KITTEN : PM_LITTLE_DOG;
&nbsp;}
&nbsp;
make_familiar
&nbsp;struct monst *
&nbsp;make_familiar(otmp, x, y, quietly)
&nbsp;register struct obj *otmp;
&nbsp;xchar x, y;
&nbsp;boolean quietly;
&nbsp;{
&nbsp;    struct permonst *pm;
&nbsp;    struct monst *mtmp = 0;
&nbsp;    int chance, trycnt = 100;
&nbsp;
&nbsp;    do {
&nbsp;        if (otmp) { /* figurine; otherwise spell */
&nbsp;            int mndx = otmp-&gt;corpsenm;
&nbsp;            pm = &amp;mons[mndx];
&nbsp;            /* activating a figurine provides one way to exceed the
&nbsp;               maximum number of the target critter created--unless
&nbsp;               it has a special limit (erinys, Nazgul) */
&nbsp;            if ((mvitals[mndx].mvflags &amp; G_EXTINCT)
&nbsp;                &amp;&amp; mbirth_limit(mndx) != MAXMONNO) {
&nbsp;                if (!quietly)
&nbsp;                    /* have just been given "You 

<do something="" with="">
&nbsp;                       the figurine and it transforms." message */
&nbsp;                    pline("... into a pile of dust.");
&nbsp;                break; /* mtmp is null */
&nbsp;            }
&nbsp;        } else if (!rn2(3)) {
&nbsp;            pm = &amp;mons[pet_type()];
&nbsp;        } else {
&nbsp;            pm = rndmonst();
&nbsp;            if (!pm) {
&nbsp;                if (!quietly)
&nbsp;                    There("seems to be nothing available for a familiar.");
&nbsp;                break;
&nbsp;            }
&nbsp;        }
&nbsp;
&nbsp;        mtmp = makemon(pm, x, y, MM_EDOG | MM_IGNOREWATER | NO_MINVENT);
&nbsp;        if (otmp &amp;&amp; !mtmp) { /* monster was genocided or square occupied */
&nbsp;            if (!quietly)
&nbsp;                pline_The("figurine writhes and then shatters into pieces!");
&nbsp;            break;
&nbsp;        }
&nbsp;    } while (!mtmp &amp;&amp; --trycnt &gt; 0);
&nbsp;
&nbsp;    if (!mtmp)
&nbsp;        return (struct monst *) 0;
&nbsp;
&nbsp;    if (is_pool(mtmp-&gt;mx, mtmp-&gt;my) &amp;&amp; minliquid(mtmp))
&nbsp;        return (struct monst *) 0;
&nbsp;
&nbsp;    initedog(mtmp);
&nbsp;    mtmp-&gt;msleeping = 0;
&nbsp;    if (otmp) { /* figurine; resulting monster might not become a pet */
&nbsp;        chance = rn2(10); /* 0==tame, 1==peaceful, 2==hostile */
&nbsp;        if (chance &gt; 2)
&nbsp;            chance = otmp-&gt;blessed ? 0 : !otmp-&gt;cursed ? 1 : 2;
&nbsp;        /* 0,1,2:  b=80%,10,10; nc=10%,80,10; c=10%,10,80 */
&nbsp;        if (chance &gt; 0) {
&nbsp;            mtmp-&gt;mtame = 0;   /* not tame after all */
&nbsp;            if (chance == 2) { /* hostile (cursed figurine) */
&nbsp;                if (!quietly)
&nbsp;                    You("get a bad feeling about this.");
&nbsp;                mtmp-&gt;mpeaceful = 0;
&nbsp;                set_malign(mtmp);
&nbsp;            }
&nbsp;        }
&nbsp;        /* if figurine has been named, give same name to the monster */
&nbsp;        if (has_oname(otmp))
&nbsp;            mtmp = christen_monst(mtmp, ONAME(otmp));
&nbsp;    }
&nbsp;    set_malign(mtmp); /* more alignment changes */
&nbsp;    newsym(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;
&nbsp;    /* must wield weapon immediately since pets will otherwise drop it */
&nbsp;    if (mtmp-&gt;mtame &amp;&amp; attacktype(mtmp-&gt;data, AT_WEAP)) {
&nbsp;        mtmp-&gt;weapon_check = NEED_HTH_WEAPON;
&nbsp;        (void) mon_wield_item(mtmp);
&nbsp;    }
&nbsp;    return mtmp;
&nbsp;}
&nbsp;
makedog
&nbsp;struct monst *
&nbsp;makedog()
&nbsp;{
&nbsp;    register struct monst *mtmp;
&nbsp;    register struct obj *otmp;
&nbsp;    const char *petname;
&nbsp;    int pettype;
&nbsp;    static int petname_used = 0;
&nbsp;
&nbsp;    if (preferred_pet == 'n')
&nbsp;        return ((struct monst *) 0);
&nbsp;
&nbsp;    pettype = pet_type();
&nbsp;    if (pettype == PM_LITTLE_DOG)
&nbsp;        petname = dogname;
&nbsp;    else if (pettype == PM_PONY)
&nbsp;        petname = horsename;
&nbsp;    else
&nbsp;        petname = catname;
&nbsp;
&nbsp;    /* default pet names */
&nbsp;    if (!*petname &amp;&amp; pettype == PM_LITTLE_DOG) {
&nbsp;        /* All of these names were for dogs. */
&nbsp;        if (Role_if(PM_CAVEMAN))
&nbsp;            petname = "Slasher"; /* The Warrior */
&nbsp;        if (Role_if(PM_SAMURAI))
&nbsp;            petname = "Hachi"; /* Shibuya Station */
&nbsp;        if (Role_if(PM_BARBARIAN))
&nbsp;            petname = "Idefix"; /* Obelix */
&nbsp;        if (Role_if(PM_RANGER))
&nbsp;            petname = "Sirius"; /* Orion's dog */
&nbsp;    }
&nbsp;
&nbsp;    mtmp = makemon(&amp;mons[pettype], u.ux, u.uy, MM_EDOG);
&nbsp;
&nbsp;    if (!mtmp)
&nbsp;        return ((struct monst *) 0); /* pets were genocided */
&nbsp;
&nbsp;    context.startingpet_mid = mtmp-&gt;m_id;
&nbsp;    /* Horses already wear a saddle */
&nbsp;    if (pettype == PM_PONY &amp;&amp; !!(otmp = mksobj(SADDLE, TRUE, FALSE))) {
&nbsp;        otmp-&gt;dknown = otmp-&gt;bknown = otmp-&gt;rknown = 1;
&nbsp;        put_saddle_on_mon(otmp, mtmp);
&nbsp;    }
&nbsp;
&nbsp;    if (!petname_used++ &amp;&amp; *petname)
&nbsp;        mtmp = christen_monst(mtmp, petname);
&nbsp;
&nbsp;    initedog(mtmp);
&nbsp;    return  mtmp;
&nbsp;}
&nbsp;
update_mlstmv
&nbsp;/* record `last move time' for all monsters prior to level save so that
&nbsp;   mon_arrive() can catch up for lost time when they're restored later */
&nbsp;void
&nbsp;update_mlstmv()
&nbsp;{
&nbsp;    struct monst *mon;
&nbsp;
&nbsp;    /* monst-&gt;mlstmv used to be updated every time `monst' actually moved,
&nbsp;       but that is no longer the case so we just do a blanket assignment */
&nbsp;    for (mon = fmon; mon; mon = mon-&gt;nmon) {
&nbsp;        if (DEADMONSTER(mon))
&nbsp;            continue;
&nbsp;        mon-&gt;mlstmv = monstermoves;
&nbsp;    }
&nbsp;}
&nbsp;
losedogs
&nbsp;void
&nbsp;losedogs()
&nbsp;{
&nbsp;    register struct monst *mtmp, *mtmp0 = 0, *mtmp2;
&nbsp;    int dismissKops = 0;
&nbsp;
&nbsp;    /*
&nbsp;     * First, scan migrating_mons for shopkeepers who want to dismiss Kops,
&nbsp;     * and scan mydogs for shopkeepers who want to retain kops.
&nbsp;     * Second, dismiss kops if warranted, making more room for arrival.
&nbsp;     * Third, place monsters accompanying the hero.
&nbsp;     * Last, place migrating monsters coming to this level.
&nbsp;     *
&nbsp;     * Hero might eventually be displaced (due to the third step, but
&nbsp;     * occurring later), which is the main reason to do the second step
&nbsp;     * sooner (in turn necessitating the first step, rather than combining
&nbsp;     * the list scans with monster placement).
&nbsp;     */
&nbsp;
&nbsp;    /* check for returning shk(s) */
&nbsp;    for (mtmp = migrating_mons; mtmp; mtmp = mtmp-&gt;nmon) {
&nbsp;        if (mtmp-&gt;mux != u.uz.dnum || mtmp-&gt;muy != u.uz.dlevel)
&nbsp;            continue;
&nbsp;        if (mtmp-&gt;isshk) {
&nbsp;            if (ESHK(mtmp)-&gt;dismiss_kops) {
&nbsp;                if (dismissKops == 0)
&nbsp;                    dismissKops = 1;
&nbsp;                ESHK(mtmp)-&gt;dismiss_kops = FALSE; /* reset */
&nbsp;            } else if (!mtmp-&gt;mpeaceful) {
&nbsp;                /* an unpacified shk is returning; don't dismiss kops
&nbsp;                   even if another pacified one is willing to do so */
&nbsp;                dismissKops = -1;
&nbsp;                /* [keep looping; later monsters might need ESHK reset] */
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;    /* make the same check for mydogs */
&nbsp;    for (mtmp = mydogs; mtmp &amp;&amp; dismissKops &gt;= 0; mtmp = mtmp-&gt;nmon) {
&nbsp;        if (mtmp-&gt;isshk) {
&nbsp;            /* hostile shk might accompany hero [ESHK(mtmp)-&gt;dismiss_kops
&nbsp;               can't be set here; it's only used for migrating_mons] */
&nbsp;            if (!mtmp-&gt;mpeaceful)
&nbsp;                dismissKops = -1;
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* when a hostile shopkeeper chases hero to another level
&nbsp;       and then gets paid off there, get rid of summoned kops
&nbsp;       here now that he has returned to his shop level */
&nbsp;    if (dismissKops &gt; 0)
&nbsp;        make_happy_shoppers(TRUE);
&nbsp;
&nbsp;    /* place pets and/or any other monsters who accompany hero */
&nbsp;    while ((mtmp = mydogs) != 0) {
&nbsp;        mydogs = mtmp-&gt;nmon;
&nbsp;        mon_arrive(mtmp, TRUE);
&nbsp;    }
&nbsp;
&nbsp;    /* time for migrating monsters to arrive */
&nbsp;    for (mtmp = migrating_mons; mtmp; mtmp = mtmp2) {
&nbsp;        mtmp2 = mtmp-&gt;nmon;
&nbsp;        if (mtmp-&gt;mux == u.uz.dnum &amp;&amp; mtmp-&gt;muy == u.uz.dlevel) {
&nbsp;            if (mtmp == migrating_mons)
&nbsp;                migrating_mons = mtmp-&gt;nmon;
&nbsp;            else
&nbsp;                mtmp0-&gt;nmon = mtmp-&gt;nmon;
&nbsp;            mon_arrive(mtmp, FALSE);
&nbsp;        } else
&nbsp;            mtmp0 = mtmp;
&nbsp;    }
&nbsp;}
&nbsp;
mon_arrive
&nbsp;/* called from resurrect() in addition to losedogs() */
&nbsp;void
&nbsp;mon_arrive(mtmp, with_you)
&nbsp;struct monst *mtmp;
&nbsp;boolean with_you;
&nbsp;{
&nbsp;    struct trap *t;
&nbsp;    xchar xlocale, ylocale, xyloc, xyflags, wander;
&nbsp;    int num_segs;
&nbsp;
&nbsp;    mtmp-&gt;nmon = fmon;
&nbsp;    fmon = mtmp;
&nbsp;    if (mtmp-&gt;isshk)
&nbsp;        set_residency(mtmp, FALSE);
&nbsp;
&nbsp;    num_segs = mtmp-&gt;wormno;
&nbsp;    /* baby long worms have no tail so don't use is_longworm() */
&nbsp;    if (mtmp-&gt;data == &amp;mons[PM_LONG_WORM]) {
&nbsp;        mtmp-&gt;wormno = get_wormno();
&nbsp;        if (mtmp-&gt;wormno)
&nbsp;            initworm(mtmp, num_segs);
&nbsp;    } else
&nbsp;        mtmp-&gt;wormno = 0;
&nbsp;
&nbsp;    /* some monsters might need to do something special upon arrival
&nbsp;       _after_ the current level has been fully set up; see dochug() */
&nbsp;    mtmp-&gt;mstrategy |= STRAT_ARRIVE;
&nbsp;
&nbsp;    /* make sure mnexto(rloc_to(set_apparxy())) doesn't use stale data */
&nbsp;    mtmp-&gt;mux = u.ux, mtmp-&gt;muy = u.uy;
&nbsp;    xyloc = mtmp-&gt;mtrack[0].x;
&nbsp;    xyflags = mtmp-&gt;mtrack[0].y;
&nbsp;    xlocale = mtmp-&gt;mtrack[1].x;
&nbsp;    ylocale = mtmp-&gt;mtrack[1].y;
&nbsp;    memset(mtmp-&gt;mtrack, 0, sizeof(mtmp-&gt;mtrack));
&nbsp;
&nbsp;    if (mtmp == u.usteed)
&nbsp;        return; /* don't place steed on the map */
&nbsp;    if (with_you) {
&nbsp;        /* When a monster accompanies you, sometimes it will arrive
&nbsp;           at your intended destination and you'll end up next to
&nbsp;           that spot.  This code doesn't control the final outcome;
&nbsp;           goto_level(do.c) decides who ends up at your target spot
&nbsp;           when there is a monster there too. */
&nbsp;        if (!MON_AT(u.ux, u.uy)
&nbsp;            &amp;&amp; !rn2(mtmp-&gt;mtame ? 10 : mtmp-&gt;mpeaceful ? 5 : 2))
&nbsp;            rloc_to(mtmp, u.ux, u.uy);
&nbsp;        else
&nbsp;            mnexto(mtmp);
&nbsp;        return;
&nbsp;    }
&nbsp;    /*
&nbsp;     * The monster arrived on this level independently of the player.
&nbsp;     * Its coordinate fields were overloaded for use as flags that
&nbsp;     * specify its final destination.
&nbsp;     */
&nbsp;
&nbsp;    if (mtmp-&gt;mlstmv &lt; monstermoves - 1L) {
&nbsp;        /* heal monster for time spent in limbo */
&nbsp;        long nmv = monstermoves - 1L - mtmp-&gt;mlstmv;
&nbsp;
&nbsp;        mon_catchup_elapsed_time(mtmp, nmv);
&nbsp;        mtmp-&gt;mlstmv = monstermoves - 1L;
&nbsp;
&nbsp;        /* let monster move a bit on new level (see placement code below) */
&nbsp;        wander = (xchar) min(nmv, 8);
&nbsp;    } else
&nbsp;        wander = 0;
&nbsp;
&nbsp;    switch (xyloc) {
&nbsp;    case MIGR_APPROX_XY: /* {x,y}locale set above */
&nbsp;        break;
&nbsp;    case MIGR_EXACT_XY:
&nbsp;        wander = 0;
&nbsp;        break;
&nbsp;    case MIGR_WITH_HERO:
&nbsp;        xlocale = u.ux, ylocale = u.uy;
&nbsp;        break;
&nbsp;    case MIGR_STAIRS_UP:
&nbsp;        xlocale = xupstair, ylocale = yupstair;
&nbsp;        break;
&nbsp;    case MIGR_STAIRS_DOWN:
&nbsp;        xlocale = xdnstair, ylocale = ydnstair;
&nbsp;        break;
&nbsp;    case MIGR_LADDER_UP:
&nbsp;        xlocale = xupladder, ylocale = yupladder;
&nbsp;        break;
&nbsp;    case MIGR_LADDER_DOWN:
&nbsp;        xlocale = xdnladder, ylocale = ydnladder;
&nbsp;        break;
&nbsp;    case MIGR_SSTAIRS:
&nbsp;        xlocale = sstairs.sx, ylocale = sstairs.sy;
&nbsp;        break;
&nbsp;    case MIGR_PORTAL:
&nbsp;        if (In_endgame(&amp;u.uz)) {
&nbsp;            /* there is no arrival portal for endgame levels */
&nbsp;            /* BUG[?]: for simplicity, this code relies on the fact
&nbsp;               that we know that the current endgame levels always
&nbsp;               build upwards and never have any exclusion subregion
&nbsp;               inside their TELEPORT_REGION settings. */
&nbsp;            xlocale = rn1(updest.hx - updest.lx + 1, updest.lx);
&nbsp;            ylocale = rn1(updest.hy - updest.ly + 1, updest.ly);
&nbsp;            break;
&nbsp;        }
&nbsp;        /* find the arrival portal */
&nbsp;        for (t = ftrap; t; t = t-&gt;ntrap)
&nbsp;            if (t-&gt;ttyp == MAGIC_PORTAL)
&nbsp;                break;
&nbsp;        if (t) {
&nbsp;            xlocale = t-&gt;tx, ylocale = t-&gt;ty;
&nbsp;            break;
&nbsp;        } else {
&nbsp;            impossible("mon_arrive: no corresponding portal?");
&nbsp;        } /*FALLTHRU*/
&nbsp;    default:
&nbsp;    case MIGR_RANDOM:
&nbsp;        xlocale = ylocale = 0;
&nbsp;        break;
&nbsp;    }
&nbsp;
&nbsp;    if (xlocale &amp;&amp; wander) {
&nbsp;        /* monster moved a bit; pick a nearby location */
&nbsp;        /* mnearto() deals w/stone, et al */
&nbsp;        char *r = in_rooms(xlocale, ylocale, 0);
&nbsp;        if (r &amp;&amp; *r) {
&nbsp;            coord c;
&nbsp;            /* somexy() handles irregular rooms */
&nbsp;            if (somexy(&amp;rooms[*r - ROOMOFFSET], &amp;c))
&nbsp;                xlocale = c.x, ylocale = c.y;
&nbsp;            else
&nbsp;                xlocale = ylocale = 0;
&nbsp;        } else { /* not in a room */
&nbsp;            int i, j;
&nbsp;            i = max(1, xlocale - wander);
&nbsp;            j = min(COLNO - 1, xlocale + wander);
&nbsp;            xlocale = rn1(j - i, i);
&nbsp;            i = max(0, ylocale - wander);
&nbsp;            j = min(ROWNO - 1, ylocale + wander);
&nbsp;            ylocale = rn1(j - i, i);
&nbsp;        }
&nbsp;    } /* moved a bit */
&nbsp;
&nbsp;    mtmp-&gt;mx = 0; /*(already is 0)*/
&nbsp;    mtmp-&gt;my = xyflags;
&nbsp;    if (xlocale) {
&nbsp;        if (!mnearto(mtmp, xlocale, ylocale, FALSE))
&nbsp;            goto fail_mon_placement;
&nbsp;    } else {
&nbsp;        if (!rloc(mtmp, TRUE)) {
&nbsp;            /*
&nbsp;             * Failed to place migrating monster,
&nbsp;             * probably because the level is full.
&nbsp;             * Dump the monster's cargo and leave the monster dead.
&nbsp;             */
&nbsp;            struct obj *obj;
&nbsp;fail_mon_placement:
&nbsp;            while ((obj = mtmp-&gt;minvent) != 0) {
&nbsp;                obj_extract_self(obj);
&nbsp;                obj_no_longer_held(obj);
&nbsp;                if (obj-&gt;owornmask &amp; W_WEP)
&nbsp;                    setmnotwielded(mtmp, obj);
&nbsp;                obj-&gt;owornmask = 0L;
&nbsp;                if (xlocale &amp;&amp; ylocale)
&nbsp;                    place_object(obj, xlocale, ylocale);
&nbsp;                else if (rloco(obj)) {
&nbsp;                    if (!get_obj_location(obj, &amp;xlocale, &amp;ylocale, 0))
&nbsp;                        impossible("Can't find relocated object.");
&nbsp;                }
&nbsp;            }
&nbsp;            (void) mkcorpstat(CORPSE, (struct monst *) 0, mtmp-&gt;data, xlocale,
&nbsp;                              ylocale, CORPSTAT_NONE);
&nbsp;            mongone(mtmp);
&nbsp;        }
&nbsp;    }
&nbsp;}
&nbsp;
mon_catchup_elapsed_time
&nbsp;/* heal monster for time spent elsewhere */
&nbsp;void
&nbsp;mon_catchup_elapsed_time(mtmp, nmv)
&nbsp;struct monst *mtmp;
&nbsp;long nmv; /* number of moves */
&nbsp;{
&nbsp;    int imv = 0; /* avoid zillions of casts and lint warnings */
&nbsp;
&nbsp;#if defined(DEBUG) || defined(BETA)
&nbsp;    if (nmv &lt; 0L) { /* crash likely... */
&nbsp;        panic("catchup from future time?");
&nbsp;        /*NOTREACHED*/
&nbsp;        return;
&nbsp;    } else if (nmv == 0L) { /* safe, but should'nt happen */
&nbsp;        impossible("catchup from now?");
&nbsp;    } else
&nbsp;#endif
&nbsp;        if (nmv &gt;= LARGEST_INT) /* paranoia */
&nbsp;        imv = LARGEST_INT - 1;
&nbsp;    else
&nbsp;        imv = (int) nmv;
&nbsp;
&nbsp;    /* might stop being afraid, blind or frozen */
&nbsp;    /* set to 1 and allow final decrement in movemon() */
&nbsp;    if (mtmp-&gt;mblinded) {
&nbsp;        if (imv &gt;= (int) mtmp-&gt;mblinded)
&nbsp;            mtmp-&gt;mblinded = 1;
&nbsp;        else
&nbsp;            mtmp-&gt;mblinded -= imv;
&nbsp;    }
&nbsp;    if (mtmp-&gt;mfrozen) {
&nbsp;        if (imv &gt;= (int) mtmp-&gt;mfrozen)
&nbsp;            mtmp-&gt;mfrozen = 1;
&nbsp;        else
&nbsp;            mtmp-&gt;mfrozen -= imv;
&nbsp;    }
&nbsp;    if (mtmp-&gt;mfleetim) {
&nbsp;        if (imv &gt;= (int) mtmp-&gt;mfleetim)
&nbsp;            mtmp-&gt;mfleetim = 1;
&nbsp;        else
&nbsp;            mtmp-&gt;mfleetim -= imv;
&nbsp;    }
&nbsp;
&nbsp;    /* might recover from temporary trouble */
&nbsp;    if (mtmp-&gt;mtrapped &amp;&amp; rn2(imv + 1) &gt; 40 / 2)
&nbsp;        mtmp-&gt;mtrapped = 0;
&nbsp;    if (mtmp-&gt;mconf &amp;&amp; rn2(imv + 1) &gt; 50 / 2)
&nbsp;        mtmp-&gt;mconf = 0;
&nbsp;    if (mtmp-&gt;mstun &amp;&amp; rn2(imv + 1) &gt; 10 / 2)
&nbsp;        mtmp-&gt;mstun = 0;
&nbsp;
&nbsp;    /* might finish eating or be able to use special ability again */
&nbsp;    if (imv &gt; mtmp-&gt;meating)
&nbsp;        finish_meating(mtmp);
&nbsp;    else
&nbsp;        mtmp-&gt;meating -= imv;
&nbsp;    if (imv &gt; mtmp-&gt;mspec_used)
&nbsp;        mtmp-&gt;mspec_used = 0;
&nbsp;    else
&nbsp;        mtmp-&gt;mspec_used -= imv;
&nbsp;
&nbsp;    /* reduce tameness for every 150 moves you are separated */
&nbsp;    if (mtmp-&gt;mtame) {
&nbsp;        int wilder = (imv + 75) / 150;
&nbsp;        if (mtmp-&gt;mtame &gt; wilder)
&nbsp;            mtmp-&gt;mtame -= wilder; /* less tame */
&nbsp;        else if (mtmp-&gt;mtame &gt; rn2(wilder))
&nbsp;            mtmp-&gt;mtame = 0; /* untame */
&nbsp;        else
&nbsp;            mtmp-&gt;mtame = mtmp-&gt;mpeaceful = 0; /* hostile! */
&nbsp;    }
&nbsp;    /* check to see if it would have died as a pet; if so, go wild instead
&nbsp;     * of dying the next time we call dog_move()
&nbsp;     */
&nbsp;    if (mtmp-&gt;mtame &amp;&amp; !mtmp-&gt;isminion
&nbsp;        &amp;&amp; (carnivorous(mtmp-&gt;data) || herbivorous(mtmp-&gt;data))) {
&nbsp;        struct edog *edog = EDOG(mtmp);
&nbsp;
&nbsp;        if ((monstermoves &gt; edog-&gt;hungrytime + 500 &amp;&amp; mtmp-&gt;mhp &lt; 3)
&nbsp;            || (monstermoves &gt; edog-&gt;hungrytime + 750))
&nbsp;            mtmp-&gt;mtame = mtmp-&gt;mpeaceful = 0;
&nbsp;    }
&nbsp;
&nbsp;    if (!mtmp-&gt;mtame &amp;&amp; mtmp-&gt;mleashed) {
&nbsp;        /* leashed monsters should always be with hero, consequently
&nbsp;           never losing any time to be accounted for later */
&nbsp;        impossible("catching up for leashed monster?");
&nbsp;        m_unleash(mtmp, FALSE);
&nbsp;    }
&nbsp;
&nbsp;    /* recover lost hit points */
&nbsp;    if (!regenerates(mtmp-&gt;data))
&nbsp;        imv /= 20;
&nbsp;    if (mtmp-&gt;mhp + imv &gt;= mtmp-&gt;mhpmax)
&nbsp;        mtmp-&gt;mhp = mtmp-&gt;mhpmax;
&nbsp;    else
&nbsp;        mtmp-&gt;mhp += imv;
&nbsp;}
&nbsp;
keepdogs
&nbsp;/* called when you move to another level */
&nbsp;void
&nbsp;keepdogs(pets_only)
&nbsp;boolean pets_only; /* true for ascension or final escape */
&nbsp;{
&nbsp;    register struct monst *mtmp, *mtmp2;
&nbsp;    register struct obj *obj;
&nbsp;    int num_segs;
&nbsp;    boolean stay_behind;
&nbsp;
&nbsp;    for (mtmp = fmon; mtmp; mtmp = mtmp2) {
&nbsp;        mtmp2 = mtmp-&gt;nmon;
&nbsp;        if (DEADMONSTER(mtmp))
&nbsp;            continue;
&nbsp;        if (pets_only) {
&nbsp;            if (!mtmp-&gt;mtame)
&nbsp;                continue; /* reject non-pets */
&nbsp;            /* don't block pets from accompanying hero's dungeon
&nbsp;               escape or ascension simply due to mundane trifles;
&nbsp;               unlike level change for steed, don't bother trying
&nbsp;               to achieve a normal trap escape first */
&nbsp;            mtmp-&gt;mtrapped = 0;
&nbsp;            mtmp-&gt;meating = 0;
&nbsp;            mtmp-&gt;msleeping = 0;
&nbsp;            mtmp-&gt;mfrozen = 0;
&nbsp;            mtmp-&gt;mcanmove = 1;
&nbsp;        }
&nbsp;        if (((monnear(mtmp, u.ux, u.uy) &amp;&amp; levl_follower(mtmp))
&nbsp;             /* the wiz will level t-port from anywhere to chase
&nbsp;                the amulet; if you don't have it, will chase you
&nbsp;                only if in range. -3. */
&nbsp;             || (u.uhave.amulet &amp;&amp; mtmp-&gt;iswiz))
&nbsp;            &amp;&amp; ((!mtmp-&gt;msleeping &amp;&amp; mtmp-&gt;mcanmove)
&nbsp;                /* eg if level teleport or new trap, steed has no control
&nbsp;                   to avoid following */
&nbsp;                || (mtmp == u.usteed))
&nbsp;            /* monster won't follow if it hasn't noticed you yet */
&nbsp;            &amp;&amp; !(mtmp-&gt;mstrategy &amp; STRAT_WAITFORU)) {
&nbsp;            stay_behind = FALSE;
&nbsp;            if (mtmp-&gt;mtrapped)
&nbsp;                (void) mintrap(mtmp); /* try to escape */
&nbsp;            if (mtmp == u.usteed) {
&nbsp;                /* make sure steed is eligible to accompany hero */
&nbsp;                mtmp-&gt;mtrapped = 0;       /* escape trap */
&nbsp;                mtmp-&gt;meating = 0;        /* terminate eating */
&nbsp;                mdrop_special_objs(mtmp); /* drop Amulet */
&nbsp;            } else if (mtmp-&gt;meating || mtmp-&gt;mtrapped) {
&nbsp;                if (canseemon(mtmp))
&nbsp;                    pline("%s is still %s.", Monnam(mtmp),
&nbsp;                          mtmp-&gt;meating ? "eating" : "trapped");
&nbsp;                stay_behind = TRUE;
&nbsp;            } else if (mon_has_amulet(mtmp)) {
&nbsp;                if (canseemon(mtmp))
&nbsp;                    pline("%s seems very disoriented for a moment.",
&nbsp;                          Monnam(mtmp));
&nbsp;                stay_behind = TRUE;
&nbsp;            }
&nbsp;            if (stay_behind) {
&nbsp;                if (mtmp-&gt;mleashed) {
&nbsp;                    pline("%s leash suddenly comes loose.",
&nbsp;                          humanoid(mtmp-&gt;data)
&nbsp;                              ? (mtmp-&gt;female ? "Her" : "His")
&nbsp;                              : "Its");
&nbsp;                    m_unleash(mtmp, FALSE);
&nbsp;                }
&nbsp;                if (mtmp == u.usteed) {
&nbsp;                    /* can't happen unless someone makes a change
&nbsp;                       which scrambles the stay_behind logic above */
&nbsp;                    impossible("steed left behind?");
&nbsp;                    dismount_steed(DISMOUNT_GENERIC);
&nbsp;                }
&nbsp;                continue;
&nbsp;            }
&nbsp;            if (mtmp-&gt;isshk)
&nbsp;                set_residency(mtmp, TRUE);
&nbsp;
&nbsp;            if (mtmp-&gt;wormno) {
&nbsp;                register int cnt;
&nbsp;                /* NOTE: worm is truncated to # segs = max wormno size */
&nbsp;                cnt = count_wsegs(mtmp);
&nbsp;                num_segs = min(cnt, MAX_NUM_WORMS - 1);
&nbsp;                wormgone(mtmp);
&nbsp;            } else
&nbsp;                num_segs = 0;
&nbsp;
&nbsp;            /* set minvent's obj-&gt;no_charge to 0 */
&nbsp;            for (obj = mtmp-&gt;minvent; obj; obj = obj-&gt;nobj) {
&nbsp;                if (Has_contents(obj))
&nbsp;                    picked_container(obj); /* does the right thing */
&nbsp;                obj-&gt;no_charge = 0;
&nbsp;            }
&nbsp;
&nbsp;            relmon(mtmp, &amp;mydogs);   /* move it from map to mydogs */
&nbsp;            mtmp-&gt;mx = mtmp-&gt;my = 0; /* avoid mnexto()/MON_AT() problem */
&nbsp;            mtmp-&gt;wormno = num_segs;
&nbsp;            mtmp-&gt;mlstmv = monstermoves;
&nbsp;        } else if (mtmp-&gt;iswiz) {
&nbsp;            /* we want to be able to find him when his next resurrection
&nbsp;               chance comes up, but have him resume his present location
&nbsp;               if player returns to this level before that time */
&nbsp;            migrate_to_level(mtmp, ledger_no(&amp;u.uz), MIGR_EXACT_XY,
&nbsp;                             (coord *) 0);
&nbsp;        } else if (mtmp-&gt;mleashed) {
&nbsp;            /* this can happen if your quest leader ejects you from the
&nbsp;               "home" level while a leashed pet isn't next to you */
&nbsp;            pline("%s leash goes slack.", s_suffix(Monnam(mtmp)));
&nbsp;            m_unleash(mtmp, FALSE);
&nbsp;        }
&nbsp;    }
&nbsp;}
&nbsp;
migrate_to_level
&nbsp;void
&nbsp;migrate_to_level(mtmp, tolev, xyloc, cc)
&nbsp;register struct monst *mtmp;
&nbsp;xchar tolev; /* destination level */
&nbsp;xchar xyloc; /* MIGR_xxx destination xy location: */
&nbsp;coord *cc;   /* optional destination coordinates */
&nbsp;{
&nbsp;    register struct obj *obj;
&nbsp;    d_level new_lev;
&nbsp;    xchar xyflags;
&nbsp;    int num_segs = 0; /* count of worm segments */
&nbsp;
&nbsp;    if (mtmp-&gt;isshk)
&nbsp;        set_residency(mtmp, TRUE);
&nbsp;
&nbsp;    if (mtmp-&gt;wormno) {
&nbsp;        register int cnt;
&nbsp;        /* **** NOTE: worm is truncated to # segs = max wormno size **** */
&nbsp;        cnt = count_wsegs(mtmp);
&nbsp;        num_segs = min(cnt, MAX_NUM_WORMS - 1);
&nbsp;        wormgone(mtmp);
&nbsp;    }
&nbsp;
&nbsp;    /* set minvent's obj-&gt;no_charge to 0 */
&nbsp;    for (obj = mtmp-&gt;minvent; obj; obj = obj-&gt;nobj) {
&nbsp;        if (Has_contents(obj))
&nbsp;            picked_container(obj); /* does the right thing */
&nbsp;        obj-&gt;no_charge = 0;
&nbsp;    }
&nbsp;
&nbsp;    if (mtmp-&gt;mleashed) {
&nbsp;        mtmp-&gt;mtame--;
&nbsp;        m_unleash(mtmp, TRUE);
&nbsp;    }
&nbsp;    relmon(mtmp, &amp;migrating_mons); /* move it from map to migrating_mons */
&nbsp;
&nbsp;    new_lev.dnum = ledger_to_dnum((xchar) tolev);
&nbsp;    new_lev.dlevel = ledger_to_dlev((xchar) tolev);
&nbsp;    /* overload mtmp-&gt;[mx,my], mtmp-&gt;[mux,muy], and mtmp-&gt;mtrack[] as */
&nbsp;    /* destination codes (setup flag bits before altering mx or my) */
&nbsp;    xyflags = (depth(&amp;new_lev) &lt; depth(&amp;u.uz)); /* 1 =&gt; up */
&nbsp;    if (In_W_tower(mtmp-&gt;mx, mtmp-&gt;my, &amp;u.uz))
&nbsp;        xyflags |= 2;
&nbsp;    mtmp-&gt;wormno = num_segs;
&nbsp;    mtmp-&gt;mlstmv = monstermoves;
&nbsp;    mtmp-&gt;mtrack[1].x = cc ? cc-&gt;x : mtmp-&gt;mx;
&nbsp;    mtmp-&gt;mtrack[1].y = cc ? cc-&gt;y : mtmp-&gt;my;
&nbsp;    mtmp-&gt;mtrack[0].x = xyloc;
&nbsp;    mtmp-&gt;mtrack[0].y = xyflags;
&nbsp;    mtmp-&gt;mux = new_lev.dnum;
&nbsp;    mtmp-&gt;muy = new_lev.dlevel;
&nbsp;    mtmp-&gt;mx = mtmp-&gt;my = 0; /* this implies migration */
&nbsp;    if (mtmp == context.polearm.hitmon)
&nbsp;        context.polearm.hitmon = NULL;
&nbsp;}
&nbsp;
dogfood
&nbsp;/* return quality of food; the lower the better */
&nbsp;/* fungi will eat even tainted food */
&nbsp;int
&nbsp;dogfood(mon, obj)
&nbsp;struct monst *mon;
&nbsp;register struct obj *obj;
&nbsp;{
&nbsp;    struct permonst *mptr = mon-&gt;data, *fptr = 0;
&nbsp;    boolean carni = carnivorous(mptr), herbi = herbivorous(mptr),
&nbsp;            starving, mblind;
&nbsp;
&nbsp;    if (is_quest_artifact(obj) || obj_resists(obj, 0, 95))
&nbsp;        return obj-&gt;cursed ? TABU : APPORT;
&nbsp;
&nbsp;    switch (obj-&gt;oclass) {
&nbsp;    case FOOD_CLASS:
&nbsp;        if (obj-&gt;otyp == CORPSE || obj-&gt;otyp == TIN || obj-&gt;otyp == EGG)
&nbsp;            fptr = &amp;mons[obj-&gt;corpsenm];
&nbsp;
&nbsp;        if (obj-&gt;otyp == CORPSE &amp;&amp; is_rider(fptr))
&nbsp;            return TABU;
&nbsp;        if ((obj-&gt;otyp == CORPSE || obj-&gt;otyp == EGG) &amp;&amp; touch_petrifies(fptr)
&nbsp;            &amp;&amp; !resists_ston(mon))
&nbsp;            return POISON;
&nbsp;        if (!carni &amp;&amp; !herbi)
&nbsp;            return obj-&gt;cursed ? UNDEF : APPORT;
&nbsp;
&nbsp;        /* a starving pet will eat almost anything */
&nbsp;        starving = (mon-&gt;mtame &amp;&amp; !mon-&gt;isminion
&nbsp;                    &amp;&amp; EDOG(mon)-&gt;mhpmax_penalty);
&nbsp;        /* even carnivores will eat carrots if they're temporarily blind */
&nbsp;        mblind = (!mon-&gt;mcansee &amp;&amp; haseyes(mon-&gt;data));
&nbsp;
&nbsp;        /* ghouls prefer old corpses and unhatchable eggs, yum!
&nbsp;           they'll eat fresh non-veggy corpses and hatchable eggs
&nbsp;           when starving; they never eat stone-to-flesh'd meat */
&nbsp;        if (mptr == &amp;mons[PM_GHOUL]) {
&nbsp;            if (obj-&gt;otyp == CORPSE)
&nbsp;                return (peek_at_iced_corpse_age(obj) + 50L &lt;= monstermoves
&nbsp;                        &amp;&amp; fptr != &amp;mons[PM_LIZARD]
&nbsp;                        &amp;&amp; fptr != &amp;mons[PM_LICHEN])
&nbsp;                           ? DOGFOOD
&nbsp;                           : (starving &amp;&amp; !vegan(fptr))
&nbsp;                              ? ACCFOOD
&nbsp;                              : POISON;
&nbsp;            if (obj-&gt;otyp == EGG)
&nbsp;                return stale_egg(obj) ? CADAVER : starving ? ACCFOOD : POISON;
&nbsp;            return TABU;
&nbsp;        }
&nbsp;
&nbsp;        switch (obj-&gt;otyp) {
&nbsp;        case TRIPE_RATION:
&nbsp;        case MEATBALL:
&nbsp;        case MEAT_RING:
&nbsp;        case MEAT_STICK:
&nbsp;        case HUGE_CHUNK_OF_MEAT:
&nbsp;            return carni ? DOGFOOD : MANFOOD;
&nbsp;        case EGG:
&nbsp;            return carni ? CADAVER : MANFOOD;
&nbsp;        case CORPSE:
&nbsp;            if ((peek_at_iced_corpse_age(obj) + 50L &lt;= monstermoves
&nbsp;                 &amp;&amp; obj-&gt;corpsenm != PM_LIZARD &amp;&amp; obj-&gt;corpsenm != PM_LICHEN
&nbsp;                 &amp;&amp; mptr-&gt;mlet != S_FUNGUS)
&nbsp;                || (acidic(fptr) &amp;&amp; !resists_acid(mon))
&nbsp;                || (poisonous(fptr) &amp;&amp; !resists_poison(mon)))
&nbsp;                return POISON;
&nbsp;            /* turning into slime is preferable to starvation */
&nbsp;            else if (fptr == &amp;mons[PM_GREEN_SLIME] &amp;&amp; !slimeproof(mon-&gt;data))
&nbsp;                return starving ? ACCFOOD : POISON;
&nbsp;            else if (vegan(fptr))
&nbsp;                return herbi ? CADAVER : MANFOOD;
&nbsp;            /* most humanoids will avoid cannibalism unless starving;
&nbsp;               arbitrary: elves won't eat other elves even then */
&nbsp;            else if (humanoid(mptr) &amp;&amp; same_race(mptr, fptr)
&nbsp;                     &amp;&amp; (!is_undead(mptr) &amp;&amp; fptr-&gt;mlet != S_KOBOLD
&nbsp;                         &amp;&amp; fptr-&gt;mlet != S_ORC &amp;&amp; fptr-&gt;mlet != S_OGRE))
&nbsp;                return (starving &amp;&amp; carni &amp;&amp; !is_elf(mptr)) ? ACCFOOD : TABU;
&nbsp;            else
&nbsp;                return carni ? CADAVER : MANFOOD;
&nbsp;        case CLOVE_OF_GARLIC:
&nbsp;            return (is_undead(mptr) || is_vampshifter(mon))
&nbsp;                      ? TABU
&nbsp;                      : (herbi || starving)
&nbsp;                         ? ACCFOOD
&nbsp;                         : MANFOOD;
&nbsp;        case TIN:
&nbsp;            return metallivorous(mptr) ? ACCFOOD : MANFOOD;
&nbsp;        case APPLE:
&nbsp;            return herbi ? DOGFOOD : starving ? ACCFOOD : MANFOOD;
&nbsp;        case CARROT:
&nbsp;            return (herbi || mblind) ? DOGFOOD : starving ? ACCFOOD : MANFOOD;
&nbsp;        case BANANA:
&nbsp;            return (mptr-&gt;mlet == S_YETI &amp;&amp; herbi)
&nbsp;                      ? DOGFOOD /* for monkey and ape (tameable), sasquatch */
&nbsp;                      : (herbi || starving)
&nbsp;                         ? ACCFOOD
&nbsp;                         : MANFOOD;
&nbsp;        default:
&nbsp;            if (starving)
&nbsp;                return ACCFOOD;
&nbsp;            return (obj-&gt;otyp &gt; SLIME_MOLD) ? (carni ? ACCFOOD : MANFOOD)
&nbsp;                                            : (herbi ? ACCFOOD : MANFOOD);
&nbsp;        }
&nbsp;    default:
&nbsp;        if (obj-&gt;otyp == AMULET_OF_STRANGULATION
&nbsp;            || obj-&gt;otyp == RIN_SLOW_DIGESTION)
&nbsp;            return TABU;
&nbsp;        if (mon_hates_silver(mon) &amp;&amp; objects[obj-&gt;otyp].oc_material == SILVER)
&nbsp;            return TABU;
&nbsp;        if (mptr == &amp;mons[PM_GELATINOUS_CUBE] &amp;&amp; is_organic(obj))
&nbsp;            return ACCFOOD;
&nbsp;        if (metallivorous(mptr) &amp;&amp; is_metallic(obj)
&nbsp;            &amp;&amp; (is_rustprone(obj) || mptr != &amp;mons[PM_RUST_MONSTER])) {
&nbsp;            /* Non-rustproofed ferrous based metals are preferred. */
&nbsp;            return (is_rustprone(obj) &amp;&amp; !obj-&gt;oerodeproof) ? DOGFOOD
&nbsp;                                                            : ACCFOOD;
&nbsp;        }
&nbsp;        if (!obj-&gt;cursed
&nbsp;            &amp;&amp; obj-&gt;oclass != BALL_CLASS
&nbsp;            &amp;&amp; obj-&gt;oclass != CHAIN_CLASS)
&nbsp;            return APPORT;
&nbsp;        /*FALLTHRU*/
&nbsp;    case ROCK_CLASS:
&nbsp;        return UNDEF;
&nbsp;    }
&nbsp;}
&nbsp;
tamedog
&nbsp;/*
&nbsp; * With the separate mextra structure added in 3.6.x this always
&nbsp; * operates on the original mtmp. It now returns TRUE if the taming
&nbsp; * succeeded.
&nbsp; */
&nbsp;boolean
&nbsp;tamedog(mtmp, obj)
&nbsp;register struct monst *mtmp;
&nbsp;register struct obj *obj;
&nbsp;{
&nbsp;    /* The Wiz, Medusa and the quest nemeses aren't even made peaceful. */
&nbsp;    if (mtmp-&gt;iswiz || mtmp-&gt;data == &amp;mons[PM_MEDUSA]
&nbsp;        || (mtmp-&gt;data-&gt;mflags3 &amp; M3_WANTSARTI))
&nbsp;        return FALSE;
&nbsp;
&nbsp;    /* worst case, at least it'll be peaceful. */
&nbsp;    mtmp-&gt;mpeaceful = 1;
&nbsp;    set_malign(mtmp);
&nbsp;    if (flags.moonphase == FULL_MOON &amp;&amp; night() &amp;&amp; rn2(6) &amp;&amp; obj
&nbsp;        &amp;&amp; mtmp-&gt;data-&gt;mlet == S_DOG)
&nbsp;        return FALSE;
&nbsp;
&nbsp;    /* If we cannot tame it, at least it's no longer afraid. */
&nbsp;    mtmp-&gt;mflee = 0;
&nbsp;    mtmp-&gt;mfleetim = 0;
&nbsp;
&nbsp;    /* make grabber let go now, whether it becomes tame or not */
&nbsp;    if (mtmp == u.ustuck) {
&nbsp;        if (u.uswallow)
&nbsp;            expels(mtmp, mtmp-&gt;data, TRUE);
&nbsp;        else if (!(Upolyd &amp;&amp; sticks(youmonst.data)))
&nbsp;            unstuck(mtmp);
&nbsp;    }
&nbsp;
&nbsp;    /* feeding it treats makes it tamer */
&nbsp;    if (mtmp-&gt;mtame &amp;&amp; obj) {
&nbsp;        int tasty;
&nbsp;
&nbsp;        if (mtmp-&gt;mcanmove &amp;&amp; !mtmp-&gt;mconf &amp;&amp; !mtmp-&gt;meating
&nbsp;            &amp;&amp; ((tasty = dogfood(mtmp, obj)) == DOGFOOD
&nbsp;                || (tasty &lt;= ACCFOOD
&nbsp;                    &amp;&amp; EDOG(mtmp)-&gt;hungrytime &lt;= monstermoves))) {
&nbsp;            /* pet will "catch" and eat this thrown food */
&nbsp;            if (canseemon(mtmp)) {
&nbsp;                boolean big_corpse =
&nbsp;                    (obj-&gt;otyp == CORPSE &amp;&amp; obj-&gt;corpsenm &gt;= LOW_PM
&nbsp;                     &amp;&amp; mons[obj-&gt;corpsenm].msize &gt; mtmp-&gt;data-&gt;msize);
&nbsp;                pline("%s catches %s%s", Monnam(mtmp), the(xname(obj)),
&nbsp;                      !big_corpse ? "." : ", or vice versa!");
&nbsp;            } else if (cansee(mtmp-&gt;mx, mtmp-&gt;my))
&nbsp;                pline("%s.", Tobjnam(obj, "stop"));
&nbsp;            /* dog_eat expects a floor object */
&nbsp;            place_object(obj, mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;            (void) dog_eat(mtmp, obj, mtmp-&gt;mx, mtmp-&gt;my, FALSE);
&nbsp;            /* eating might have killed it, but that doesn't matter here;
&nbsp;               a non-null result suppresses "miss" message for thrown
&nbsp;               food and also implies that the object has been deleted */
&nbsp;            return TRUE;
&nbsp;        } else
&nbsp;            return FALSE;
&nbsp;    }
&nbsp;
&nbsp;    if (mtmp-&gt;mtame || !mtmp-&gt;mcanmove
&nbsp;        /* monsters with conflicting structures cannot be tamed */
&nbsp;        || mtmp-&gt;isshk || mtmp-&gt;isgd || mtmp-&gt;ispriest || mtmp-&gt;isminion
&nbsp;        || is_covetous(mtmp-&gt;data) || is_human(mtmp-&gt;data)
&nbsp;        || (is_demon(mtmp-&gt;data) &amp;&amp; !is_demon(youmonst.data))
&nbsp;        || (obj &amp;&amp; dogfood(mtmp, obj) &gt;= MANFOOD))
&nbsp;        return FALSE;
&nbsp;
&nbsp;    if (mtmp-&gt;m_id == quest_status.leader_m_id)
&nbsp;        return FALSE;
&nbsp;
&nbsp;    /* add the pet extension */
&nbsp;    newedog(mtmp);
&nbsp;    initedog(mtmp);
&nbsp;
&nbsp;    if (obj) { /* thrown food */
&nbsp;        /* defer eating until the edog extension has been set up */
&nbsp;        place_object(obj, mtmp-&gt;mx, mtmp-&gt;my); /* put on floor */
&nbsp;        /* devour the food (might grow into larger, genocided monster) */
&nbsp;        if (dog_eat(mtmp, obj, mtmp-&gt;mx, mtmp-&gt;my, TRUE) == 2)
&nbsp;            return TRUE; /* oops, it died... */
&nbsp;        /* `obj' is now obsolete */
&nbsp;    }
&nbsp;
&nbsp;    newsym(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;    if (attacktype(mtmp-&gt;data, AT_WEAP)) {
&nbsp;        mtmp-&gt;weapon_check = NEED_HTH_WEAPON;
&nbsp;        (void) mon_wield_item(mtmp);
&nbsp;    }
&nbsp;    return TRUE;
&nbsp;}
&nbsp;
wary_dog
&nbsp;/*
&nbsp; * Called during pet revival or pet life-saving.
&nbsp; * If you killed the pet, it revives wild.
&nbsp; * If you abused the pet a lot while alive, it revives wild.
&nbsp; * If you abused the pet at all while alive, it revives untame.
&nbsp; * If the pet wasn't abused and was very tame, it might revive tame.
&nbsp; */
&nbsp;void
&nbsp;wary_dog(mtmp, was_dead)
&nbsp;struct monst *mtmp;
&nbsp;boolean was_dead;
&nbsp;{
&nbsp;    struct edog *edog;
&nbsp;    boolean quietly = was_dead;
&nbsp;
&nbsp;    finish_meating(mtmp);
&nbsp;
&nbsp;    if (!mtmp-&gt;mtame)
&nbsp;        return;
&nbsp;    edog = !mtmp-&gt;isminion ? EDOG(mtmp) : 0;
&nbsp;
&nbsp;    /* if monster was starving when it died, undo that now */
&nbsp;    if (edog &amp;&amp; edog-&gt;mhpmax_penalty) {
&nbsp;        mtmp-&gt;mhpmax += edog-&gt;mhpmax_penalty;
&nbsp;        mtmp-&gt;mhp += edog-&gt;mhpmax_penalty; /* heal it */
&nbsp;        edog-&gt;mhpmax_penalty = 0;
&nbsp;    }
&nbsp;
&nbsp;    if (edog &amp;&amp; (edog-&gt;killed_by_u == 1 || edog-&gt;abuse &gt; 2)) {
&nbsp;        mtmp-&gt;mpeaceful = mtmp-&gt;mtame = 0;
&nbsp;        if (edog-&gt;abuse &gt;= 0 &amp;&amp; edog-&gt;abuse &lt; 10)
&nbsp;            if (!rn2(edog-&gt;abuse + 1))
&nbsp;                mtmp-&gt;mpeaceful = 1;
&nbsp;        if (!quietly &amp;&amp; cansee(mtmp-&gt;mx, mtmp-&gt;my)) {
&nbsp;            if (haseyes(youmonst.data)) {
&nbsp;                if (haseyes(mtmp-&gt;data))
&nbsp;                    pline("%s %s to look you in the %s.", Monnam(mtmp),
&nbsp;                          mtmp-&gt;mpeaceful ? "seems unable" : "refuses",
&nbsp;                          body_part(EYE));
&nbsp;                else
&nbsp;                    pline("%s avoids your gaze.", Monnam(mtmp));
&nbsp;            }
&nbsp;        }
&nbsp;    } else {
&nbsp;        /* chance it goes wild anyway - Pet Sematary */
&nbsp;        mtmp-&gt;mtame = rn2(mtmp-&gt;mtame + 1);
&nbsp;        if (!mtmp-&gt;mtame)
&nbsp;            mtmp-&gt;mpeaceful = rn2(2);
&nbsp;    }
&nbsp;
&nbsp;    if (!mtmp-&gt;mtame) {
&nbsp;        if (!quietly &amp;&amp; canspotmon(mtmp))
&nbsp;            pline("%s %s.", Monnam(mtmp),
&nbsp;                  mtmp-&gt;mpeaceful ? "is no longer tame" : "has become feral");
&nbsp;        newsym(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;        /* a life-saved monster might be leashed;
&nbsp;           don't leave it that way if it's no longer tame */
&nbsp;        if (mtmp-&gt;mleashed)
&nbsp;            m_unleash(mtmp, TRUE);
&nbsp;        if (mtmp == u.usteed)
&nbsp;            dismount_steed(DISMOUNT_THROWN);
&nbsp;    } else if (edog) {
&nbsp;        /* it's still a pet; start a clean pet-slate now */
&nbsp;        edog-&gt;revivals++;
&nbsp;        edog-&gt;killed_by_u = 0;
&nbsp;        edog-&gt;abuse = 0;
&nbsp;        edog-&gt;ogoal.x = edog-&gt;ogoal.y = -1;
&nbsp;        if (was_dead || edog-&gt;hungrytime &lt; monstermoves + 500L)
&nbsp;            edog-&gt;hungrytime = monstermoves + 500L;
&nbsp;        if (was_dead) {
&nbsp;            edog-&gt;droptime = 0L;
&nbsp;            edog-&gt;dropdist = 10000;
&nbsp;            edog-&gt;whistletime = 0L;
&nbsp;            edog-&gt;apport = 5;
&nbsp;        } /* else lifesaved, so retain current values */
&nbsp;    }
&nbsp;}
&nbsp;
abuse_dog
&nbsp;void
&nbsp;abuse_dog(mtmp)
&nbsp;struct monst *mtmp;
&nbsp;{
&nbsp;    if (!mtmp-&gt;mtame)
&nbsp;        return;
&nbsp;
&nbsp;    if (Aggravate_monster || Conflict)
&nbsp;        mtmp-&gt;mtame /= 2;
&nbsp;    else
&nbsp;        mtmp-&gt;mtame--;
&nbsp;
&nbsp;    if (mtmp-&gt;mtame &amp;&amp; !mtmp-&gt;isminion)
&nbsp;        EDOG(mtmp)-&gt;abuse++;
&nbsp;
&nbsp;    if (!mtmp-&gt;mtame &amp;&amp; mtmp-&gt;mleashed)
&nbsp;        m_unleash(mtmp, TRUE);
&nbsp;
&nbsp;    /* don't make a sound if pet is in the middle of leaving the level */
&nbsp;    /* newsym isn't necessary in this case either */
&nbsp;    if (mtmp-&gt;mx != 0) {
&nbsp;        if (mtmp-&gt;mtame &amp;&amp; rn2(mtmp-&gt;mtame))
&nbsp;            yelp(mtmp);
&nbsp;        else
&nbsp;            growl(mtmp); /* give them a moment's worry */
&nbsp;
&nbsp;        if (!mtmp-&gt;mtame)
&nbsp;            newsym(mtmp-&gt;mx, mtmp-&gt;my);
&nbsp;    }
&nbsp;}
&nbsp;
&nbsp;/*dog.c*/

</do>