]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.dog.c
1 /* $NetBSD: hack.dog.c,v 1.5 2001/03/25 20:43:59 jsm Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.dog.c,v 1.5 2001/03/25 20:43:59 jsm Exp $");
14 #include "hack.mfndpos.h"
16 #include "def.mkroom.h"
18 const struct permonst li_dog
=
19 {"little dog", 'd', 2, 18, 6, 1, 6, sizeof(struct edog
)};
20 const struct permonst dog
=
21 {"dog", 'd', 4, 16, 5, 1, 6, sizeof(struct edog
)};
22 const struct permonst la_dog
=
23 {"large dog", 'd', 6, 15, 4, 2, 4, sizeof(struct edog
)};
29 struct monst
*mtmp
= makemon(&li_dog
, u
.ux
, u
.uy
);
31 return; /* dogs were genocided */
39 mtmp
->mtame
= mtmp
->mpeaceful
= 1;
40 EDOG(mtmp
)->hungrytime
= 1000 + moves
;
41 EDOG(mtmp
)->eattime
= 0;
42 EDOG(mtmp
)->droptime
= 0;
43 EDOG(mtmp
)->dropdist
= 10000;
44 EDOG(mtmp
)->apport
= 10;
45 EDOG(mtmp
)->whistletime
= 0;
48 /* attach the monsters that went down (or up) together with @ */
49 struct monst
*mydogs
= 0;
50 struct monst
*fallen_down
= 0;/* monsters that fell through a trapdoor */
51 /* they will appear on the next level @ goes to, even if he goes up! */
57 while ((mtmp
= mydogs
) != NULL
) {
63 while ((mtmp
= fallen_down
) != NULL
) {
64 fallen_down
= mtmp
->nmon
;
75 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
76 if (dist(mtmp
->mx
, mtmp
->my
) < 3 && follower(mtmp
)
77 && !mtmp
->msleep
&& !mtmp
->mfroz
) {
82 keepdogs(); /* we destroyed the link, so use
84 return; /* (admittedly somewhat primitive) */
93 mtmp
->nmon
= fallen_down
;
99 /* return quality of food; the lower the better */
114 (obj
->otyp
== TRIPE_RATION
) ? DOGFOOD
:
115 (obj
->otyp
< CARROT
) ? ACCFOOD
:
116 (obj
->otyp
< CORPSE
) ? MANFOOD
:
117 (poisonous(obj
) || obj
->age
+ 50 <= moves
||
118 obj
->otyp
== DEAD_COCKATRICE
)
124 /* fall into next case */
132 /* return 0 (no move), 1 (move) or 2 (dead) */
134 dog_move(struct monst
*mtmp
, int after
)
136 int nx
, ny
, omx
, omy
, appr
, nearer
, j
;
137 int udist
, chi
= 0, i
, whappr
;
139 const struct permonst
*mdat
= mtmp
->data
;
140 struct edog
*edog
= EDOG(mtmp
);
143 xchar cnt
, chcnt
, nix
, niy
;
144 schar dogroom
, uroom
;
145 xchar gx
= 0, gy
= 0, gtyp
, otyp
; /* current goal */
148 #define GDIST(x,y) ((x-gx)*(x-gx) + (y-gy)*(y-gy))
149 #define DDIST(x,y) ((x-omx)*(x-omx) + (y-omy)*(y-omy))
151 if (moves
<= edog
->eattime
)
152 return (0); /* dog is still eating */
155 whappr
= (moves
- EDOG(mtmp
)->whistletime
< 5);
156 if (moves
> edog
->hungrytime
+ 500 && !mtmp
->mconf
) {
159 if (mtmp
->mhp
> mtmp
->mhpmax
)
160 mtmp
->mhp
= mtmp
->mhpmax
;
161 if (cansee(omx
, omy
))
162 pline("%s is confused from hunger.", Monnam(mtmp
));
164 pline("You feel worried about %s.", monnam(mtmp
));
165 } else if (moves
> edog
->hungrytime
+ 750 || mtmp
->mhp
< 1) {
166 if (cansee(omx
, omy
))
167 pline("%s dies from hunger.", Monnam(mtmp
));
169 pline("You have a sad feeling for a moment, then it passes.");
173 dogroom
= inroom(omx
, omy
);
174 uroom
= inroom(u
.ux
, u
.uy
);
175 udist
= dist(omx
, omy
);
177 /* maybe we tamed him while being swallowed --jgm */
181 /* if we are carrying sth then we drop it (perhaps near @) */
182 /* Note: if apport == 1 then our behaviour is independent of udist */
184 if (!rn2(udist
) || !rn2((int) edog
->apport
))
185 if (rn2(10) < edog
->apport
) {
186 relobj(mtmp
, (int) mtmp
->minvis
);
187 if (edog
->apport
> 1)
189 edog
->dropdist
= udist
; /* hpscdi!jon */
190 edog
->droptime
= moves
;
193 if ((obj
= o_at(omx
, omy
)) != NULL
)
194 if (!strchr("0_", obj
->olet
)) {
195 if ((otyp
= dogfood(obj
)) <= CADAVER
) {
200 if (obj
->owt
< 10 * mtmp
->data
->mlevel
)
201 if (rn2(20) < edog
->apport
+ 3)
202 if (rn2(udist
) || !rn2((int) edog
->apport
)) {
206 * if(levl[omx][omy].s
216 /* first we look for food */
217 gtyp
= UNDEF
; /* no goal as yet */
219 gx
= gy
= 0; /* suppress 'used before set' message */
221 for (obj
= fobj
; obj
; obj
= obj
->nobj
) {
223 if (otyp
> gtyp
|| otyp
== UNDEF
)
225 if (inroom(obj
->ox
, obj
->oy
) != dogroom
)
227 if (otyp
< MANFOOD
&&
228 (dogroom
>= 0 || DDIST(obj
->ox
, obj
->oy
) < 10)) {
229 if (otyp
< gtyp
|| (otyp
== gtyp
&&
230 DDIST(obj
->ox
, obj
->oy
) < DDIST(gx
, gy
))) {
235 } else if (gtyp
== UNDEF
&& dogroom
>= 0 &&
237 !mtmp
->minvent
&& edog
->apport
> rn2(8)) {
244 (gtyp
!= DOGFOOD
&& gtyp
!= APPORT
&& moves
< edog
->hungrytime
)) {
245 if (dogroom
< 0 || dogroom
== uroom
) {
250 int tmp
= rooms
[dogroom
].fdoor
;
251 cnt
= rooms
[dogroom
].doorct
;
253 gx
= gy
= FAR
; /* random, far away */
256 dist(doors
[tmp
].x
, doors
[tmp
].y
)) {
262 /* here gx == FAR e.g. when dog is in a vault */
263 if (gx
== FAR
|| (gx
== omx
&& gy
== omy
)) {
269 appr
= (udist
>= 9) ? 1 : (mtmp
->mflee
) ? -1 : 0;
270 if (after
&& udist
<= 4 && gx
== u
.ux
&& gy
== u
.uy
)
273 if (!IS_ROOM(levl
[u
.ux
][u
.uy
].typ
) || !rn2(4) ||
275 (mtmp
->minvent
&& rn2((int) edog
->apport
)))
278 /* if you have dog food he'll follow you more closely */
282 if (obj
->otyp
== TRIPE_RATION
) {
290 appr
= 1; /* gtyp != UNDEF */
294 if (gx
== u
.ux
&& gy
== u
.uy
&& (dogroom
!= uroom
|| dogroom
< 0)) {
296 cp
= gettrack(omx
, omy
);
304 cnt
= mfndpos(mtmp
, poss
, info
, ALLOW_M
| ALLOW_TRAPS
);
307 for (i
= 0; i
< cnt
; i
++) {
310 if (info
[i
] & ALLOW_M
) {
311 mtmp2
= m_at(nx
, ny
);
312 if (mtmp2
->data
->mlevel
>= mdat
->mlevel
+ 2 ||
313 mtmp2
->data
->mlet
== 'c')
316 return (0); /* hit only once each move */
318 if (hitmm(mtmp
, mtmp2
) == 1 && rn2(4) &&
319 mtmp2
->mlstmv
!= moves
&&
320 hitmm(mtmp2
, mtmp
) == 2)
324 /* dog avoids traps */
325 /* but perhaps we have to pass a trap in order to follow @ */
326 if ((info
[i
] & ALLOW_TRAPS
) && (trap
= t_at(nx
, ny
))) {
327 if (!trap
->tseen
&& rn2(40))
332 /* dog eschewes cursed objects */
333 /* but likes dog food */
336 if (obj
->ox
!= nx
|| obj
->oy
!= ny
)
340 if (obj
->olet
== FOOD_SYM
&&
341 (otyp
= dogfood(obj
)) < MANFOOD
&&
342 (otyp
< ACCFOOD
|| edog
->hungrytime
<= moves
)) {
344 * Note: our dog likes the food so much that
345 * he might eat it even when it conceals a
353 moves
+ obj
->quan
* objects
[obj
->otyp
].oc_delay
;
354 if (edog
->hungrytime
< moves
)
355 edog
->hungrytime
= moves
;
357 5 * obj
->quan
* objects
[obj
->otyp
].nutrition
;
359 if (cansee(nix
, niy
))
360 pline("%s ate %s.", Monnam(mtmp
), doname(obj
));
361 /* perhaps this was a reward */
363 edog
->apport
+= 200 / (edog
->dropdist
+ moves
- edog
->droptime
);
371 for (j
= 0; j
< MTSZ
&& j
< cnt
- 1; j
++)
372 if (nx
== mtmp
->mtrack
[j
].x
&& ny
== mtmp
->mtrack
[j
].y
)
373 if (rn2(4 * (cnt
- j
)))
377 * Some stupid C compilers cannot compute the whole
378 * expression at once.
380 nearer
= GDIST(nx
, ny
);
381 nearer
-= GDIST(nix
, niy
);
383 if ((nearer
== 0 && !rn2(++chcnt
)) || nearer
< 0 ||
384 (nearer
> 0 && !whappr
&&
385 ((omx
== nix
&& omy
== niy
&& !rn2(3))
397 if (nix
!= omx
|| niy
!= omy
) {
398 if (info
[chi
] & ALLOW_U
) {
399 (void) hitu(mtmp
, d(mdat
->damn
, mdat
->damd
) + 1);
404 for (j
= MTSZ
- 1; j
> 0; j
--)
405 mtmp
->mtrack
[j
] = mtmp
->mtrack
[j
- 1];
406 mtmp
->mtrack
[0].x
= omx
;
407 mtmp
->mtrack
[0].y
= omy
;
409 if (mintrap(mtmp
) == 2) /* he died */
415 /* return roomnumber or -1 */
421 struct mkroom
*croom
= &rooms
[0];
422 while (croom
->hx
>= 0) {
423 if (croom
->hx
>= x
- 1 && croom
->lx
<= x
+ 1 &&
424 croom
->hy
>= y
- 1 && croom
->ly
<= y
+ 1)
425 return (croom
- rooms
);
429 return (-1); /* not in room or on door */
439 if (flags
.moonphase
== FULL_MOON
&& night() && rn2(6))
442 /* If we cannot tame him, at least he's no longer afraid. */
445 if (mtmp
->mtame
|| mtmp
->mfroz
||
449 mtmp
->isshk
|| mtmp
->isgd
|| strchr(" &@12", mtmp
->data
->mlet
))
450 return (0); /* no tame long worms? */
452 if (dogfood(obj
) >= MANFOOD
)
454 if (cansee(mtmp
->mx
, mtmp
->my
)) {
455 pline("%s devours the %s.", Monnam(mtmp
),
456 objects
[obj
->otyp
].oc_name
);
458 obfree(obj
, (struct obj
*) 0);
460 mtmp2
= newmonst(sizeof(struct edog
) + mtmp
->mnamelth
);
462 mtmp2
->mxlth
= sizeof(struct edog
);
464 (void) strcpy(NAME(mtmp2
), NAME(mtmp
));
466 replmon(mtmp
, mtmp2
);