]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.dog.c
1 /* $NetBSD: hack.dog.c,v 1.4 1997/10/19 16:57:50 christos Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.dog.c,v 1.4 1997/10/19 16:57:50 christos Exp $");
14 #include "hack.mfndpos.h"
16 #include "def.mkroom.h"
18 struct permonst li_dog
=
19 {"little dog", 'd', 2, 18, 6, 1, 6, sizeof(struct edog
)};
21 {"dog", 'd', 4, 16, 5, 1, 6, sizeof(struct edog
)};
22 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(mtmp
, after
)
137 int nx
, ny
, omx
, omy
, appr
, nearer
, j
;
138 int udist
, chi
= 0, i
, whappr
;
140 struct permonst
*mdat
= mtmp
->data
;
141 struct edog
*edog
= EDOG(mtmp
);
144 xchar cnt
, chcnt
, nix
, niy
;
145 schar dogroom
, uroom
;
146 xchar gx
= 0, gy
= 0, gtyp
, otyp
; /* current goal */
149 #define GDIST(x,y) ((x-gx)*(x-gx) + (y-gy)*(y-gy))
150 #define DDIST(x,y) ((x-omx)*(x-omx) + (y-omy)*(y-omy))
152 if (moves
<= edog
->eattime
)
153 return (0); /* dog is still eating */
156 whappr
= (moves
- EDOG(mtmp
)->whistletime
< 5);
157 if (moves
> edog
->hungrytime
+ 500 && !mtmp
->mconf
) {
160 if (mtmp
->mhp
> mtmp
->mhpmax
)
161 mtmp
->mhp
= mtmp
->mhpmax
;
162 if (cansee(omx
, omy
))
163 pline("%s is confused from hunger.", Monnam(mtmp
));
165 pline("You feel worried about %s.", monnam(mtmp
));
166 } else if (moves
> edog
->hungrytime
+ 750 || mtmp
->mhp
< 1) {
167 if (cansee(omx
, omy
))
168 pline("%s dies from hunger.", Monnam(mtmp
));
170 pline("You have a sad feeling for a moment, then it passes.");
174 dogroom
= inroom(omx
, omy
);
175 uroom
= inroom(u
.ux
, u
.uy
);
176 udist
= dist(omx
, omy
);
178 /* maybe we tamed him while being swallowed --jgm */
182 /* if we are carrying sth then we drop it (perhaps near @) */
183 /* Note: if apport == 1 then our behaviour is independent of udist */
185 if (!rn2(udist
) || !rn2((int) edog
->apport
))
186 if (rn2(10) < edog
->apport
) {
187 relobj(mtmp
, (int) mtmp
->minvis
);
188 if (edog
->apport
> 1)
190 edog
->dropdist
= udist
; /* hpscdi!jon */
191 edog
->droptime
= moves
;
194 if ((obj
= o_at(omx
, omy
)) != NULL
)
195 if (!strchr("0_", obj
->olet
)) {
196 if ((otyp
= dogfood(obj
)) <= CADAVER
) {
201 if (obj
->owt
< 10 * mtmp
->data
->mlevel
)
202 if (rn2(20) < edog
->apport
+ 3)
203 if (rn2(udist
) || !rn2((int) edog
->apport
)) {
207 * if(levl[omx][omy].s
217 /* first we look for food */
218 gtyp
= UNDEF
; /* no goal as yet */
220 gx
= gy
= 0; /* suppress 'used before set' message */
222 for (obj
= fobj
; obj
; obj
= obj
->nobj
) {
224 if (otyp
> gtyp
|| otyp
== UNDEF
)
226 if (inroom(obj
->ox
, obj
->oy
) != dogroom
)
228 if (otyp
< MANFOOD
&&
229 (dogroom
>= 0 || DDIST(obj
->ox
, obj
->oy
) < 10)) {
230 if (otyp
< gtyp
|| (otyp
== gtyp
&&
231 DDIST(obj
->ox
, obj
->oy
) < DDIST(gx
, gy
))) {
236 } else if (gtyp
== UNDEF
&& dogroom
>= 0 &&
238 !mtmp
->minvent
&& edog
->apport
> rn2(8)) {
245 (gtyp
!= DOGFOOD
&& gtyp
!= APPORT
&& moves
< edog
->hungrytime
)) {
246 if (dogroom
< 0 || dogroom
== uroom
) {
251 int tmp
= rooms
[dogroom
].fdoor
;
252 cnt
= rooms
[dogroom
].doorct
;
254 gx
= gy
= FAR
; /* random, far away */
257 dist(doors
[tmp
].x
, doors
[tmp
].y
)) {
263 /* here gx == FAR e.g. when dog is in a vault */
264 if (gx
== FAR
|| (gx
== omx
&& gy
== omy
)) {
270 appr
= (udist
>= 9) ? 1 : (mtmp
->mflee
) ? -1 : 0;
271 if (after
&& udist
<= 4 && gx
== u
.ux
&& gy
== u
.uy
)
274 if (!IS_ROOM(levl
[u
.ux
][u
.uy
].typ
) || !rn2(4) ||
276 (mtmp
->minvent
&& rn2((int) edog
->apport
)))
279 /* if you have dog food he'll follow you more closely */
283 if (obj
->otyp
== TRIPE_RATION
) {
291 appr
= 1; /* gtyp != UNDEF */
295 if (gx
== u
.ux
&& gy
== u
.uy
&& (dogroom
!= uroom
|| dogroom
< 0)) {
297 cp
= gettrack(omx
, omy
);
305 cnt
= mfndpos(mtmp
, poss
, info
, ALLOW_M
| ALLOW_TRAPS
);
308 for (i
= 0; i
< cnt
; i
++) {
311 if (info
[i
] & ALLOW_M
) {
312 mtmp2
= m_at(nx
, ny
);
313 if (mtmp2
->data
->mlevel
>= mdat
->mlevel
+ 2 ||
314 mtmp2
->data
->mlet
== 'c')
317 return (0); /* hit only once each move */
319 if (hitmm(mtmp
, mtmp2
) == 1 && rn2(4) &&
320 mtmp2
->mlstmv
!= moves
&&
321 hitmm(mtmp2
, mtmp
) == 2)
325 /* dog avoids traps */
326 /* but perhaps we have to pass a trap in order to follow @ */
327 if ((info
[i
] & ALLOW_TRAPS
) && (trap
= t_at(nx
, ny
))) {
328 if (!trap
->tseen
&& rn2(40))
333 /* dog eschewes cursed objects */
334 /* but likes dog food */
337 if (obj
->ox
!= nx
|| obj
->oy
!= ny
)
341 if (obj
->olet
== FOOD_SYM
&&
342 (otyp
= dogfood(obj
)) < MANFOOD
&&
343 (otyp
< ACCFOOD
|| edog
->hungrytime
<= moves
)) {
345 * Note: our dog likes the food so much that
346 * he might eat it even when it conceals a
354 moves
+ obj
->quan
* objects
[obj
->otyp
].oc_delay
;
355 if (edog
->hungrytime
< moves
)
356 edog
->hungrytime
= moves
;
358 5 * obj
->quan
* objects
[obj
->otyp
].nutrition
;
360 if (cansee(nix
, niy
))
361 pline("%s ate %s.", Monnam(mtmp
), doname(obj
));
362 /* perhaps this was a reward */
364 edog
->apport
+= 200 / (edog
->dropdist
+ moves
- edog
->droptime
);
372 for (j
= 0; j
< MTSZ
&& j
< cnt
- 1; j
++)
373 if (nx
== mtmp
->mtrack
[j
].x
&& ny
== mtmp
->mtrack
[j
].y
)
374 if (rn2(4 * (cnt
- j
)))
378 * Some stupid C compilers cannot compute the whole
379 * expression at once.
381 nearer
= GDIST(nx
, ny
);
382 nearer
-= GDIST(nix
, niy
);
384 if ((nearer
== 0 && !rn2(++chcnt
)) || nearer
< 0 ||
385 (nearer
> 0 && !whappr
&&
386 ((omx
== nix
&& omy
== niy
&& !rn2(3))
398 if (nix
!= omx
|| niy
!= omy
) {
399 if (info
[chi
] & ALLOW_U
) {
400 (void) hitu(mtmp
, d(mdat
->damn
, mdat
->damd
) + 1);
405 for (j
= MTSZ
- 1; j
> 0; j
--)
406 mtmp
->mtrack
[j
] = mtmp
->mtrack
[j
- 1];
407 mtmp
->mtrack
[0].x
= omx
;
408 mtmp
->mtrack
[0].y
= omy
;
410 if (mintrap(mtmp
) == 2) /* he died */
416 /* return roomnumber or -1 */
422 struct mkroom
*croom
= &rooms
[0];
423 while (croom
->hx
>= 0) {
424 if (croom
->hx
>= x
- 1 && croom
->lx
<= x
+ 1 &&
425 croom
->hy
>= y
- 1 && croom
->ly
<= y
+ 1)
426 return (croom
- rooms
);
430 return (-1); /* not in room or on door */
440 if (flags
.moonphase
== FULL_MOON
&& night() && rn2(6))
443 /* If we cannot tame him, at least he's no longer afraid. */
446 if (mtmp
->mtame
|| mtmp
->mfroz
||
450 mtmp
->isshk
|| mtmp
->isgd
|| strchr(" &@12", mtmp
->data
->mlet
))
451 return (0); /* no tame long worms? */
453 if (dogfood(obj
) >= MANFOOD
)
455 if (cansee(mtmp
->mx
, mtmp
->my
)) {
456 pline("%s devours the %s.", Monnam(mtmp
),
457 objects
[obj
->otyp
].oc_name
);
459 obfree(obj
, (struct obj
*) 0);
461 mtmp2
= newmonst(sizeof(struct edog
) + mtmp
->mnamelth
);
463 mtmp2
->mxlth
= sizeof(struct edog
);
465 (void) strcpy(NAME(mtmp2
), NAME(mtmp
));
467 replmon(mtmp
, mtmp2
);