]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.dog.c
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.dog.c - version 1.0.3 */
5 #include "hack.mfndpos.h"
6 extern struct monst
*makemon();
8 #include "def.mkroom.h"
10 struct permonst li_dog
=
11 { "little dog", 'd',2,18,6,1,6,sizeof(struct edog
) };
13 { "dog", 'd',4,16,5,1,6,sizeof(struct edog
) };
14 struct permonst la_dog
=
15 { "large dog", 'd',6,15,4,2,4,sizeof(struct edog
) };
19 register struct monst
*mtmp
= makemon(&li_dog
,u
.ux
,u
.uy
);
20 if(!mtmp
) return; /* dogs were genocided */
24 initedog(mtmp
) register struct monst
*mtmp
; {
25 mtmp
->mtame
= mtmp
->mpeaceful
= 1;
26 EDOG(mtmp
)->hungrytime
= 1000 + moves
;
27 EDOG(mtmp
)->eattime
= 0;
28 EDOG(mtmp
)->droptime
= 0;
29 EDOG(mtmp
)->dropdist
= 10000;
30 EDOG(mtmp
)->apport
= 10;
31 EDOG(mtmp
)->whistletime
= 0;
34 /* attach the monsters that went down (or up) together with @ */
35 struct monst
*mydogs
= 0;
36 struct monst
*fallen_down
= 0; /* monsters that fell through a trapdoor */
37 /* they will appear on the next level @ goes to, even if he goes up! */
40 register struct monst
*mtmp
;
47 while(mtmp
= fallen_down
){
48 fallen_down
= mtmp
->nmon
;
56 register struct monst
*mtmp
;
57 for(mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
58 if(dist(mtmp
->mx
,mtmp
->my
) < 3 && follower(mtmp
)
59 && !mtmp
->msleep
&& !mtmp
->mfroz
) {
64 keepdogs(); /* we destroyed the link, so use recursion */
65 return; /* (admittedly somewhat primitive) */
69 fall_down(mtmp
) register struct monst
*mtmp
; {
71 mtmp
->nmon
= fallen_down
;
77 /* return quality of food; the lower the better */
85 dogfood(obj
) register struct obj
*obj
; {
89 (obj
->otyp
== TRIPE_RATION
) ? DOGFOOD
:
90 (obj
->otyp
< CARROT
) ? ACCFOOD
:
91 (obj
->otyp
< CORPSE
) ? MANFOOD
:
92 (poisonous(obj
) || obj
->age
+ 50 <= moves
||
93 obj
->otyp
== DEAD_COCKATRICE
)
97 if(!obj
->cursed
) return(APPORT
);
98 /* fall into next case */
106 /* return 0 (no move), 1 (move) or 2 (dead) */
107 dog_move(mtmp
, after
) register struct monst
*mtmp
; {
108 register int nx
,ny
,omx
,omy
,appr
,nearer
,j
;
109 int udist
,chi
,i
,whappr
;
110 register struct monst
*mtmp2
;
111 register struct permonst
*mdat
= mtmp
->data
;
112 register struct edog
*edog
= EDOG(mtmp
);
115 xchar cnt
,chcnt
,nix
,niy
;
117 xchar gx
,gy
,gtyp
,otyp
; /* current goal */
120 #define GDIST(x,y) ((x-gx)*(x-gx) + (y-gy)*(y-gy))
121 #define DDIST(x,y) ((x-omx)*(x-omx) + (y-omy)*(y-omy))
123 if(moves
<= edog
->eattime
) return(0); /* dog is still eating */
126 whappr
= (moves
- EDOG(mtmp
)->whistletime
< 5);
127 if(moves
> edog
->hungrytime
+ 500 && !mtmp
->mconf
){
130 if(mtmp
->mhp
> mtmp
->mhpmax
)
131 mtmp
->mhp
= mtmp
->mhpmax
;
133 pline("%s is confused from hunger.", Monnam(mtmp
));
134 else pline("You feel worried about %s.", monnam(mtmp
));
136 if(moves
> edog
->hungrytime
+ 750 || mtmp
->mhp
< 1){
138 pline("%s dies from hunger.", Monnam(mtmp
));
140 pline("You have a sad feeling for a moment, then it passes.");
144 dogroom
= inroom(omx
,omy
);
145 uroom
= inroom(u
.ux
,u
.uy
);
146 udist
= dist(omx
,omy
);
148 /* maybe we tamed him while being swallowed --jgm */
149 if(!udist
) return(0);
151 /* if we are carrying sth then we drop it (perhaps near @) */
152 /* Note: if apport == 1 then our behaviour is independent of udist */
154 if(!rn2(udist
) || !rn2((int) edog
->apport
))
155 if(rn2(10) < edog
->apport
){
156 relobj(mtmp
, (int) mtmp
->minvis
);
157 if(edog
->apport
> 1) edog
->apport
--;
158 edog
->dropdist
= udist
; /* hpscdi!jon */
159 edog
->droptime
= moves
;
162 if(obj
= o_at(omx
,omy
)) if(!index("0_", obj
->olet
)){
163 if((otyp
= dogfood(obj
)) <= CADAVER
){
168 if(obj
->owt
< 10*mtmp
->data
->mlevel
)
169 if(rn2(20) < edog
->apport
+3)
170 if(rn2(udist
) || !rn2((int) edog
->apport
)){
173 /* if(levl[omx][omy].scrsym == obj->olet)
180 /* first we look for food */
181 gtyp
= UNDEF
; /* no goal as yet */
183 gx
= gy
= 0; /* suppress 'used before set' message */
185 for(obj
= fobj
; obj
; obj
= obj
->nobj
) {
187 if(otyp
> gtyp
|| otyp
== UNDEF
) continue;
188 if(inroom(obj
->ox
,obj
->oy
) != dogroom
) continue;
190 (dogroom
>= 0 || DDIST(obj
->ox
,obj
->oy
) < 10)) {
191 if(otyp
< gtyp
|| (otyp
== gtyp
&&
192 DDIST(obj
->ox
,obj
->oy
) < DDIST(gx
,gy
))){
198 if(gtyp
== UNDEF
&& dogroom
>= 0 &&
200 !mtmp
->minvent
&& edog
->apport
> rn2(8)){
207 (gtyp
!= DOGFOOD
&& gtyp
!= APPORT
&& moves
< edog
->hungrytime
)){
208 if(dogroom
< 0 || dogroom
== uroom
){
213 int tmp
= rooms
[dogroom
].fdoor
;
214 cnt
= rooms
[dogroom
].doorct
;
216 gx
= gy
= FAR
; /* random, far away */
219 dist(doors
[tmp
].x
, doors
[tmp
].y
)){
225 /* here gx == FAR e.g. when dog is in a vault */
226 if(gx
== FAR
|| (gx
== omx
&& gy
== omy
)){
232 appr
= (udist
>= 9) ? 1 : (mtmp
->mflee
) ? -1 : 0;
233 if(after
&& udist
<= 4 && gx
== u
.ux
&& gy
== u
.uy
)
236 if(!IS_ROOM(levl
[u
.ux
][u
.uy
].typ
) || !rn2(4) ||
238 (mtmp
->minvent
&& rn2((int) edog
->apport
)))
241 /* if you have dog food he'll follow you more closely */
245 if(obj
->otyp
== TRIPE_RATION
){
252 } else appr
= 1; /* gtyp != UNDEF */
253 if(mtmp
->mconf
) appr
= 0;
255 if(gx
== u
.ux
&& gy
== u
.uy
&& (dogroom
!= uroom
|| dogroom
< 0)){
256 extern coord
*gettrack();
258 cp
= gettrack(omx
,omy
);
267 cnt
= mfndpos(mtmp
,poss
,info
,ALLOW_M
| ALLOW_TRAPS
);
270 for(i
=0; i
<cnt
; i
++){
273 if(info
[i
] & ALLOW_M
){
275 if(mtmp2
->data
->mlevel
>= mdat
->mlevel
+2 ||
276 mtmp2
->data
->mlet
== 'c')
278 if(after
) return(0); /* hit only once each move */
280 if(hitmm(mtmp
, mtmp2
) == 1 && rn2(4) &&
281 mtmp2
->mlstmv
!= moves
&&
282 hitmm(mtmp2
,mtmp
) == 2) return(2);
286 /* dog avoids traps */
287 /* but perhaps we have to pass a trap in order to follow @ */
288 if((info
[i
] & ALLOW_TRAPS
) && (trap
= t_at(nx
,ny
))){
289 if(!trap
->tseen
&& rn2(40)) continue;
290 if(rn2(10)) continue;
293 /* dog eschewes cursed objects */
294 /* but likes dog food */
297 if(obj
->ox
!= nx
|| obj
->oy
!= ny
)
299 if(obj
->cursed
) goto nxti
;
300 if(obj
->olet
== FOOD_SYM
&&
301 (otyp
= dogfood(obj
)) < MANFOOD
&&
302 (otyp
< ACCFOOD
|| edog
->hungrytime
<= moves
)){
303 /* Note: our dog likes the food so much that he
304 might eat it even when it conceals a cursed object */
310 moves
+ obj
->quan
* objects
[obj
->otyp
].oc_delay
;
311 if(edog
->hungrytime
< moves
)
312 edog
->hungrytime
= moves
;
314 5*obj
->quan
* objects
[obj
->otyp
].nutrition
;
317 pline("%s ate %s.", Monnam(mtmp
), doname(obj
));
318 /* perhaps this was a reward */
320 edog
->apport
+= 200/(edog
->dropdist
+moves
-edog
->droptime
);
328 for(j
=0; j
<MTSZ
&& j
<cnt
-1; j
++)
329 if(nx
== mtmp
->mtrack
[j
].x
&& ny
== mtmp
->mtrack
[j
].y
)
330 if(rn2(4*(cnt
-j
))) goto nxti
;
332 /* Some stupid C compilers cannot compute the whole expression at once. */
333 nearer
= GDIST(nx
,ny
);
334 nearer
-= GDIST(nix
,niy
);
336 if((nearer
== 0 && !rn2(++chcnt
)) || nearer
<0 ||
337 (nearer
> 0 && !whappr
&&
338 ((omx
== nix
&& omy
== niy
&& !rn2(3))
343 if(nearer
< 0) chcnt
= 0;
349 if(nix
!= omx
|| niy
!= omy
){
350 if(info
[chi
] & ALLOW_U
){
351 (void) hitu(mtmp
, d(mdat
->damn
, mdat
->damd
)+1);
356 for(j
=MTSZ
-1; j
>0; j
--) mtmp
->mtrack
[j
] = mtmp
->mtrack
[j
-1];
357 mtmp
->mtrack
[0].x
= omx
;
358 mtmp
->mtrack
[0].y
= omy
;
360 if(mintrap(mtmp
) == 2) /* he died */
366 /* return roomnumber or -1 */
367 inroom(x
,y
) xchar x
,y
; {
369 register struct mkroom
*croom
= &rooms
[0];
370 while(croom
->hx
>= 0){
371 if(croom
->hx
>= x
-1 && croom
->lx
<= x
+1 &&
372 croom
->hy
>= y
-1 && croom
->ly
<= y
+1)
373 return(croom
- rooms
);
377 return(-1); /* not in room or on door */
381 register struct monst
*mtmp
;
382 register struct obj
*obj
;
384 register struct monst
*mtmp2
;
386 if(flags
.moonphase
== FULL_MOON
&& night() && rn2(6))
389 /* If we cannot tame him, at least he's no longer afraid. */
392 if(mtmp
->mtame
|| mtmp
->mfroz
||
396 mtmp
->isshk
|| mtmp
->isgd
|| index(" &@12", mtmp
->data
->mlet
))
397 return(0); /* no tame long worms? */
399 if(dogfood(obj
) >= MANFOOD
) return(0);
400 if(cansee(mtmp
->mx
,mtmp
->my
)){
401 pline("%s devours the %s.", Monnam(mtmp
),
402 objects
[obj
->otyp
].oc_name
);
404 obfree(obj
, (struct obj
*) 0);
406 mtmp2
= newmonst(sizeof(struct edog
) + mtmp
->mnamelth
);
408 mtmp2
->mxlth
= sizeof(struct edog
);
409 if(mtmp
->mnamelth
) (void) strcpy(NAME(mtmp2
), NAME(mtmp
));