2006-03-30 05:25:52 +04:00
|
|
|
/* $NetBSD: hack.dog.c,v 1.7 2006/03/30 01:25:52 jnemeth Exp $ */
|
1997-10-19 20:56:41 +04:00
|
|
|
|
1993-08-02 21:16:36 +04:00
|
|
|
/*
|
2003-04-02 22:36:33 +04:00
|
|
|
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
|
|
|
|
* Amsterdam
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* - Neither the name of the Stichting Centrum voor Wiskunde en
|
|
|
|
* Informatica, nor the names of its contributors may be used to endorse or
|
|
|
|
* promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
|
|
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
|
|
|
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1993-08-02 21:16:36 +04:00
|
|
|
*/
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-08-02 21:16:36 +04:00
|
|
|
#ifndef lint
|
2006-03-30 05:25:52 +04:00
|
|
|
__RCSID("$NetBSD: hack.dog.c,v 1.7 2006/03/30 01:25:52 jnemeth Exp $");
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* not lint */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include "hack.h"
|
|
|
|
#include "extern.h"
|
|
|
|
#include "hack.mfndpos.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "def.edog.h"
|
|
|
|
#include "def.mkroom.h"
|
|
|
|
|
2001-03-26 00:43:58 +04:00
|
|
|
const struct permonst li_dog =
|
1997-10-19 20:56:41 +04:00
|
|
|
{"little dog", 'd', 2, 18, 6, 1, 6, sizeof(struct edog)};
|
2001-03-26 00:43:58 +04:00
|
|
|
const struct permonst dog =
|
1997-10-19 20:56:41 +04:00
|
|
|
{"dog", 'd', 4, 16, 5, 1, 6, sizeof(struct edog)};
|
2001-03-26 00:43:58 +04:00
|
|
|
const struct permonst la_dog =
|
1997-10-19 20:56:41 +04:00
|
|
|
{"large dog", 'd', 6, 15, 4, 2, 4, sizeof(struct edog)};
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
makedog()
|
|
|
|
{
|
|
|
|
struct monst *mtmp = makemon(&li_dog, u.ux, u.uy);
|
|
|
|
if (!mtmp)
|
|
|
|
return; /* dogs were genocided */
|
1993-03-21 12:45:37 +03:00
|
|
|
initedog(mtmp);
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
initedog(mtmp)
|
|
|
|
struct monst *mtmp;
|
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
mtmp->mtame = mtmp->mpeaceful = 1;
|
|
|
|
EDOG(mtmp)->hungrytime = 1000 + moves;
|
|
|
|
EDOG(mtmp)->eattime = 0;
|
|
|
|
EDOG(mtmp)->droptime = 0;
|
|
|
|
EDOG(mtmp)->dropdist = 10000;
|
|
|
|
EDOG(mtmp)->apport = 10;
|
|
|
|
EDOG(mtmp)->whistletime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attach the monsters that went down (or up) together with @ */
|
1997-10-19 20:56:41 +04:00
|
|
|
struct monst *mydogs = 0;
|
|
|
|
struct monst *fallen_down = 0;/* monsters that fell through a trapdoor */
|
|
|
|
/* they will appear on the next level @ goes to, even if he goes up! */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
losedogs()
|
|
|
|
{
|
|
|
|
struct monst *mtmp;
|
|
|
|
while ((mtmp = mydogs) != NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
mydogs = mtmp->nmon;
|
|
|
|
mtmp->nmon = fmon;
|
|
|
|
fmon = mtmp;
|
|
|
|
mnexto(mtmp);
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
while ((mtmp = fallen_down) != NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
fallen_down = mtmp->nmon;
|
|
|
|
mtmp->nmon = fmon;
|
|
|
|
fmon = mtmp;
|
|
|
|
rloc(mtmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
keepdogs()
|
|
|
|
{
|
|
|
|
struct monst *mtmp;
|
|
|
|
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
|
|
|
|
if (dist(mtmp->mx, mtmp->my) < 3 && follower(mtmp)
|
|
|
|
&& !mtmp->msleep && !mtmp->mfroz) {
|
|
|
|
relmon(mtmp);
|
|
|
|
mtmp->nmon = mydogs;
|
|
|
|
mydogs = mtmp;
|
|
|
|
unpmon(mtmp);
|
|
|
|
keepdogs(); /* we destroyed the link, so use
|
|
|
|
* recursion */
|
|
|
|
return; /* (admittedly somewhat primitive) */
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
fall_down(mtmp)
|
|
|
|
struct monst *mtmp;
|
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
relmon(mtmp);
|
|
|
|
mtmp->nmon = fallen_down;
|
|
|
|
fallen_down = mtmp;
|
|
|
|
unpmon(mtmp);
|
|
|
|
mtmp->mtame = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return quality of food; the lower the better */
|
|
|
|
#define DOGFOOD 0
|
|
|
|
#define CADAVER 1
|
|
|
|
#define ACCFOOD 2
|
|
|
|
#define MANFOOD 3
|
|
|
|
#define APPORT 4
|
|
|
|
#define POISON 5
|
|
|
|
#define UNDEF 6
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
|
|
|
dogfood(obj)
|
|
|
|
struct obj *obj;
|
|
|
|
{
|
|
|
|
switch (obj->olet) {
|
1993-03-21 12:45:37 +03:00
|
|
|
case FOOD_SYM:
|
1997-10-19 20:56:41 +04:00
|
|
|
return (
|
|
|
|
(obj->otyp == TRIPE_RATION) ? DOGFOOD :
|
|
|
|
(obj->otyp < CARROT) ? ACCFOOD :
|
|
|
|
(obj->otyp < CORPSE) ? MANFOOD :
|
|
|
|
(poisonous(obj) || obj->age + 50 <= moves ||
|
|
|
|
obj->otyp == DEAD_COCKATRICE)
|
1993-03-21 12:45:37 +03:00
|
|
|
? POISON : CADAVER
|
1997-10-19 20:56:41 +04:00
|
|
|
);
|
1993-03-21 12:45:37 +03:00
|
|
|
default:
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!obj->cursed)
|
|
|
|
return (APPORT);
|
|
|
|
/* fall into next case */
|
1993-03-21 12:45:37 +03:00
|
|
|
case BALL_SYM:
|
|
|
|
case CHAIN_SYM:
|
|
|
|
case ROCK_SYM:
|
1997-10-19 20:56:41 +04:00
|
|
|
return (UNDEF);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return 0 (no move), 1 (move) or 2 (dead) */
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
2001-03-26 00:43:58 +04:00
|
|
|
dog_move(struct monst *mtmp, int after)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
int nx, ny, omx, omy, appr, nearer, j;
|
|
|
|
int udist, chi = 0, i, whappr;
|
|
|
|
struct monst *mtmp2;
|
2001-03-26 00:43:58 +04:00
|
|
|
const struct permonst *mdat = mtmp->data;
|
1997-10-19 20:56:41 +04:00
|
|
|
struct edog *edog = EDOG(mtmp);
|
|
|
|
struct obj *obj;
|
|
|
|
struct trap *trap;
|
|
|
|
xchar cnt, chcnt, nix, niy;
|
|
|
|
schar dogroom, uroom;
|
|
|
|
xchar gx = 0, gy = 0, gtyp, otyp; /* current goal */
|
|
|
|
coord poss[9];
|
|
|
|
int info[9];
|
1993-03-21 12:45:37 +03:00
|
|
|
#define GDIST(x,y) ((x-gx)*(x-gx) + (y-gy)*(y-gy))
|
|
|
|
#define DDIST(x,y) ((x-omx)*(x-omx) + (y-omy)*(y-omy))
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if (moves <= edog->eattime)
|
|
|
|
return (0); /* dog is still eating */
|
1993-03-21 12:45:37 +03:00
|
|
|
omx = mtmp->mx;
|
|
|
|
omy = mtmp->my;
|
|
|
|
whappr = (moves - EDOG(mtmp)->whistletime < 5);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (moves > edog->hungrytime + 500 && !mtmp->mconf) {
|
1993-03-21 12:45:37 +03:00
|
|
|
mtmp->mconf = 1;
|
|
|
|
mtmp->mhpmax /= 3;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (mtmp->mhp > mtmp->mhpmax)
|
1993-03-21 12:45:37 +03:00
|
|
|
mtmp->mhp = mtmp->mhpmax;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (cansee(omx, omy))
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("%s is confused from hunger.", Monnam(mtmp));
|
1997-10-19 20:56:41 +04:00
|
|
|
else
|
|
|
|
pline("You feel worried about %s.", monnam(mtmp));
|
|
|
|
} else if (moves > edog->hungrytime + 750 || mtmp->mhp < 1) {
|
|
|
|
if (cansee(omx, omy))
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("%s dies from hunger.", Monnam(mtmp));
|
|
|
|
else
|
1997-10-19 20:56:41 +04:00
|
|
|
pline("You have a sad feeling for a moment, then it passes.");
|
1993-03-21 12:45:37 +03:00
|
|
|
mondied(mtmp);
|
1997-10-19 20:56:41 +04:00
|
|
|
return (2);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
dogroom = inroom(omx, omy);
|
|
|
|
uroom = inroom(u.ux, u.uy);
|
|
|
|
udist = dist(omx, omy);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/* maybe we tamed him while being swallowed --jgm */
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!udist)
|
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/* if we are carrying sth then we drop it (perhaps near @) */
|
|
|
|
/* Note: if apport == 1 then our behaviour is independent of udist */
|
1997-10-19 20:56:41 +04:00
|
|
|
if (mtmp->minvent) {
|
|
|
|
if (!rn2(udist) || !rn2((int) edog->apport))
|
|
|
|
if (rn2(10) < edog->apport) {
|
|
|
|
relobj(mtmp, (int) mtmp->minvis);
|
|
|
|
if (edog->apport > 1)
|
|
|
|
edog->apport--;
|
|
|
|
edog->dropdist = udist; /* hpscdi!jon */
|
|
|
|
edog->droptime = moves;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
1997-10-19 20:56:41 +04:00
|
|
|
if ((obj = o_at(omx, omy)) != NULL)
|
|
|
|
if (!strchr("0_", obj->olet)) {
|
|
|
|
if ((otyp = dogfood(obj)) <= CADAVER) {
|
|
|
|
nix = omx;
|
|
|
|
niy = omy;
|
|
|
|
goto eatobj;
|
|
|
|
}
|
|
|
|
if (obj->owt < 10 * mtmp->data->mlevel)
|
|
|
|
if (rn2(20) < edog->apport + 3)
|
|
|
|
if (rn2(udist) || !rn2((int) edog->apport)) {
|
|
|
|
freeobj(obj);
|
|
|
|
unpobj(obj);
|
|
|
|
/*
|
|
|
|
* if(levl[omx][omy].s
|
|
|
|
* crsym ==
|
|
|
|
* obj->olet)
|
|
|
|
* newsym(omx,omy);
|
|
|
|
*/
|
|
|
|
mpickobj(mtmp, obj);
|
|
|
|
}
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* first we look for food */
|
1997-10-19 20:56:41 +04:00
|
|
|
gtyp = UNDEF; /* no goal as yet */
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef LINT
|
1997-10-19 20:56:41 +04:00
|
|
|
gx = gy = 0; /* suppress 'used before set' message */
|
|
|
|
#endif /* LINT */
|
|
|
|
for (obj = fobj; obj; obj = obj->nobj) {
|
1993-03-21 12:45:37 +03:00
|
|
|
otyp = dogfood(obj);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (otyp > gtyp || otyp == UNDEF)
|
|
|
|
continue;
|
|
|
|
if (inroom(obj->ox, obj->oy) != dogroom)
|
|
|
|
continue;
|
|
|
|
if (otyp < MANFOOD &&
|
|
|
|
(dogroom >= 0 || DDIST(obj->ox, obj->oy) < 10)) {
|
|
|
|
if (otyp < gtyp || (otyp == gtyp &&
|
|
|
|
DDIST(obj->ox, obj->oy) < DDIST(gx, gy))) {
|
1993-03-21 12:45:37 +03:00
|
|
|
gx = obj->ox;
|
|
|
|
gy = obj->oy;
|
|
|
|
gtyp = otyp;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
} else if (gtyp == UNDEF && dogroom >= 0 &&
|
|
|
|
uroom == dogroom &&
|
|
|
|
!mtmp->minvent && edog->apport > rn2(8)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
gx = obj->ox;
|
|
|
|
gy = obj->oy;
|
|
|
|
gtyp = APPORT;
|
|
|
|
}
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (gtyp == UNDEF ||
|
|
|
|
(gtyp != DOGFOOD && gtyp != APPORT && moves < edog->hungrytime)) {
|
|
|
|
if (dogroom < 0 || dogroom == uroom) {
|
1993-03-21 12:45:37 +03:00
|
|
|
gx = u.ux;
|
|
|
|
gy = u.uy;
|
|
|
|
#ifndef QUEST
|
|
|
|
} else {
|
1997-10-19 20:56:41 +04:00
|
|
|
int tmp = rooms[dogroom].fdoor;
|
|
|
|
cnt = rooms[dogroom].doorct;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
gx = gy = FAR; /* random, far away */
|
1997-10-19 20:56:41 +04:00
|
|
|
while (cnt--) {
|
|
|
|
if (dist(gx, gy) >
|
|
|
|
dist(doors[tmp].x, doors[tmp].y)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
gx = doors[tmp].x;
|
|
|
|
gy = doors[tmp].y;
|
|
|
|
}
|
|
|
|
tmp++;
|
|
|
|
}
|
|
|
|
/* here gx == FAR e.g. when dog is in a vault */
|
1997-10-19 20:56:41 +04:00
|
|
|
if (gx == FAR || (gx == omx && gy == omy)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
gx = u.ux;
|
|
|
|
gy = u.uy;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* QUEST */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
appr = (udist >= 9) ? 1 : (mtmp->mflee) ? -1 : 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (after && udist <= 4 && gx == u.ux && gy == u.uy)
|
|
|
|
return (0);
|
|
|
|
if (udist > 1) {
|
|
|
|
if (!IS_ROOM(levl[u.ux][u.uy].typ) || !rn2(4) ||
|
|
|
|
whappr ||
|
|
|
|
(mtmp->minvent && rn2((int) edog->apport)))
|
1993-03-21 12:45:37 +03:00
|
|
|
appr = 1;
|
|
|
|
}
|
|
|
|
/* if you have dog food he'll follow you more closely */
|
1997-10-19 20:56:41 +04:00
|
|
|
if (appr == 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
obj = invent;
|
1997-10-19 20:56:41 +04:00
|
|
|
while (obj) {
|
|
|
|
if (obj->otyp == TRIPE_RATION) {
|
1993-03-21 12:45:37 +03:00
|
|
|
appr = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
obj = obj->nobj;
|
|
|
|
}
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
} else
|
|
|
|
appr = 1; /* gtyp != UNDEF */
|
|
|
|
if (mtmp->mconf)
|
|
|
|
appr = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if (gx == u.ux && gy == u.uy && (dogroom != uroom || dogroom < 0)) {
|
|
|
|
coord *cp;
|
|
|
|
cp = gettrack(omx, omy);
|
|
|
|
if (cp) {
|
1993-03-21 12:45:37 +03:00
|
|
|
gx = cp->x;
|
|
|
|
gy = cp->y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nix = omx;
|
|
|
|
niy = omy;
|
1997-10-19 20:56:41 +04:00
|
|
|
cnt = mfndpos(mtmp, poss, info, ALLOW_M | ALLOW_TRAPS);
|
1993-03-21 12:45:37 +03:00
|
|
|
chcnt = 0;
|
|
|
|
chi = -1;
|
1997-10-19 20:56:41 +04:00
|
|
|
for (i = 0; i < cnt; i++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
nx = poss[i].x;
|
|
|
|
ny = poss[i].y;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (info[i] & ALLOW_M) {
|
|
|
|
mtmp2 = m_at(nx, ny);
|
2006-03-30 05:25:52 +04:00
|
|
|
if (mtmp2 = NULL)
|
|
|
|
panic("error in dog_move");
|
1997-10-19 20:56:41 +04:00
|
|
|
if (mtmp2->data->mlevel >= mdat->mlevel + 2 ||
|
|
|
|
mtmp2->data->mlet == 'c')
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (after)
|
|
|
|
return (0); /* hit only once each move */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if (hitmm(mtmp, mtmp2) == 1 && rn2(4) &&
|
|
|
|
mtmp2->mlstmv != moves &&
|
|
|
|
hitmm(mtmp2, mtmp) == 2)
|
|
|
|
return (2);
|
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
/* dog avoids traps */
|
|
|
|
/* but perhaps we have to pass a trap in order to follow @ */
|
1997-10-19 20:56:41 +04:00
|
|
|
if ((info[i] & ALLOW_TRAPS) && (trap = t_at(nx, ny))) {
|
|
|
|
if (!trap->tseen && rn2(40))
|
|
|
|
continue;
|
|
|
|
if (rn2(10))
|
|
|
|
continue;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
/* dog eschewes cursed objects */
|
|
|
|
/* but likes dog food */
|
|
|
|
obj = fobj;
|
1997-10-19 20:56:41 +04:00
|
|
|
while (obj) {
|
|
|
|
if (obj->ox != nx || obj->oy != ny)
|
|
|
|
goto nextobj;
|
|
|
|
if (obj->cursed)
|
|
|
|
goto nxti;
|
|
|
|
if (obj->olet == FOOD_SYM &&
|
|
|
|
(otyp = dogfood(obj)) < MANFOOD &&
|
|
|
|
(otyp < ACCFOOD || edog->hungrytime <= moves)) {
|
|
|
|
/*
|
|
|
|
* Note: our dog likes the food so much that
|
|
|
|
* he might eat it even when it conceals a
|
|
|
|
* cursed object
|
|
|
|
*/
|
|
|
|
nix = nx;
|
|
|
|
niy = ny;
|
|
|
|
chi = i;
|
|
|
|
eatobj:
|
|
|
|
edog->eattime =
|
|
|
|
moves + obj->quan * objects[obj->otyp].oc_delay;
|
|
|
|
if (edog->hungrytime < moves)
|
|
|
|
edog->hungrytime = moves;
|
|
|
|
edog->hungrytime +=
|
|
|
|
5 * obj->quan * objects[obj->otyp].nutrition;
|
|
|
|
mtmp->mconf = 0;
|
|
|
|
if (cansee(nix, niy))
|
|
|
|
pline("%s ate %s.", Monnam(mtmp), doname(obj));
|
|
|
|
/* perhaps this was a reward */
|
|
|
|
if (otyp != CADAVER)
|
|
|
|
edog->apport += 200 / (edog->dropdist + moves - edog->droptime);
|
|
|
|
delobj(obj);
|
|
|
|
goto newdogpos;
|
|
|
|
}
|
|
|
|
nextobj:
|
|
|
|
obj = obj->nobj;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
for (j = 0; j < MTSZ && j < cnt - 1; j++)
|
|
|
|
if (nx == mtmp->mtrack[j].x && ny == mtmp->mtrack[j].y)
|
|
|
|
if (rn2(4 * (cnt - j)))
|
|
|
|
goto nxti;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
/*
|
|
|
|
* Some stupid C compilers cannot compute the whole
|
|
|
|
* expression at once.
|
|
|
|
*/
|
|
|
|
nearer = GDIST(nx, ny);
|
|
|
|
nearer -= GDIST(nix, niy);
|
1993-03-21 12:45:37 +03:00
|
|
|
nearer *= appr;
|
1997-10-19 20:56:41 +04:00
|
|
|
if ((nearer == 0 && !rn2(++chcnt)) || nearer < 0 ||
|
|
|
|
(nearer > 0 && !whappr &&
|
|
|
|
((omx == nix && omy == niy && !rn2(3))
|
|
|
|
|| !rn2(12))
|
|
|
|
)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
nix = nx;
|
|
|
|
niy = ny;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (nearer < 0)
|
|
|
|
chcnt = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
chi = i;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
nxti: ;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
newdogpos:
|
1997-10-19 20:56:41 +04:00
|
|
|
if (nix != omx || niy != omy) {
|
|
|
|
if (info[chi] & ALLOW_U) {
|
|
|
|
(void) hitu(mtmp, d(mdat->damn, mdat->damd) + 1);
|
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
mtmp->mx = nix;
|
|
|
|
mtmp->my = niy;
|
1997-10-19 20:56:41 +04:00
|
|
|
for (j = MTSZ - 1; j > 0; j--)
|
|
|
|
mtmp->mtrack[j] = mtmp->mtrack[j - 1];
|
1993-03-21 12:45:37 +03:00
|
|
|
mtmp->mtrack[0].x = omx;
|
|
|
|
mtmp->mtrack[0].y = omy;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (mintrap(mtmp) == 2) /* he died */
|
|
|
|
return (2);
|
1993-03-21 12:45:37 +03:00
|
|
|
pmon(mtmp);
|
1997-10-19 20:56:41 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* return roomnumber or -1 */
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
|
|
|
inroom(x, y)
|
|
|
|
xchar x, y;
|
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef QUEST
|
1997-10-19 20:56:41 +04:00
|
|
|
struct mkroom *croom = &rooms[0];
|
|
|
|
while (croom->hx >= 0) {
|
|
|
|
if (croom->hx >= x - 1 && croom->lx <= x + 1 &&
|
|
|
|
croom->hy >= y - 1 && croom->ly <= y + 1)
|
|
|
|
return (croom - rooms);
|
1993-03-21 12:45:37 +03:00
|
|
|
croom++;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* QUEST */
|
|
|
|
return (-1); /* not in room or on door */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
tamedog(mtmp, obj)
|
1997-10-19 20:56:41 +04:00
|
|
|
struct monst *mtmp;
|
|
|
|
struct obj *obj;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
struct monst *mtmp2;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if (flags.moonphase == FULL_MOON && night() && rn2(6))
|
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/* If we cannot tame him, at least he's no longer afraid. */
|
|
|
|
mtmp->mflee = 0;
|
|
|
|
mtmp->mfleetim = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (mtmp->mtame || mtmp->mfroz ||
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef NOWORM
|
1997-10-19 20:56:41 +04:00
|
|
|
mtmp->wormno ||
|
|
|
|
#endif /* NOWORM */
|
|
|
|
mtmp->isshk || mtmp->isgd || strchr(" &@12", mtmp->data->mlet))
|
|
|
|
return (0); /* no tame long worms? */
|
|
|
|
if (obj) {
|
|
|
|
if (dogfood(obj) >= MANFOOD)
|
|
|
|
return (0);
|
|
|
|
if (cansee(mtmp->mx, mtmp->my)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("%s devours the %s.", Monnam(mtmp),
|
1997-10-19 20:56:41 +04:00
|
|
|
objects[obj->otyp].oc_name);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
obfree(obj, (struct obj *) 0);
|
|
|
|
}
|
|
|
|
mtmp2 = newmonst(sizeof(struct edog) + mtmp->mnamelth);
|
|
|
|
*mtmp2 = *mtmp;
|
|
|
|
mtmp2->mxlth = sizeof(struct edog);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (mtmp->mnamelth)
|
|
|
|
(void) strcpy(NAME(mtmp2), NAME(mtmp));
|
1993-03-21 12:45:37 +03:00
|
|
|
initedog(mtmp2);
|
1997-10-19 20:56:41 +04:00
|
|
|
replmon(mtmp, mtmp2);
|
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|