Wikia

Wikihack

Source:NetHack 3.3.0/dog.c

2,032pages on
this wiki
Talk0

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

Warning! This is the source code from an old release. For the latest release, see Source code

The NetHack General Public License applies to screenshots, source code and other content from NetHack.
1.    /*	SCCS Id: @(#)dog.c	3.3	1999/10/20	*/
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* NetHack may be freely redistributed.  See license for details. */
4.    
5.    #include "hack.h"
6.    #include "edog.h"
7.    
8.    #ifdef OVLB
9.    
10.   STATIC_DCL int NDECL(pet_type);
11.   
12.   void
13.   initedog(mtmp)
14.   register struct monst *mtmp;
15.   {
16.   	mtmp->mtame = is_domestic(mtmp->data) ? 10 : 5;
17.   	mtmp->mpeaceful = 1;
18.   	set_malign(mtmp); /* recalc alignment now that it's tamed */
19.   	mtmp->mleashed = 0;
20.   	mtmp->meating = 0;
21.   	EDOG(mtmp)->droptime = 0;
22.   	EDOG(mtmp)->dropdist = 10000;
23.   	EDOG(mtmp)->apport = 10;
24.   	EDOG(mtmp)->whistletime = 0;
25.   	EDOG(mtmp)->hungrytime = 1000 + monstermoves;
26.   	EDOG(mtmp)->ogoal.x = -1;	/* force error if used before set */
27.   	EDOG(mtmp)->ogoal.y = -1;
28.   	EDOG(mtmp)->abuse = 0;
29.   	EDOG(mtmp)->revivals = 0;
30.   	EDOG(mtmp)->killed_by_u = 0;
31.   }
32.   
33.   STATIC_OVL int
34.   pet_type()
35.   {
36.   	if (urole.petnum != NON_PM)
37.   	    return (urole.petnum);
38.   	else if (preferred_pet == 'c')
39.   	    return (PM_KITTEN);
40.   	else if (preferred_pet == 'd')
41.   	    return (PM_LITTLE_DOG);
42.   	else
43.   	    return (rn2(2) ? PM_KITTEN : PM_LITTLE_DOG);
44.   }
45.   
46.   struct monst *
47.   make_familiar(otmp,x,y,quietly)
48.   register struct obj *otmp;
49.   xchar x, y;
50.   boolean quietly;
51.   {
52.   	struct permonst *pm;
53.   	struct monst *mtmp = 0;
54.   	int chance, trycnt = 100;
55.   
56.   	do {
57.   	    if (otmp) {
58.   		pm = &mons[otmp->corpsenm]; /* Figurine; otherwise spell */
59.   	    } else if (!rn2(3)) {
60.   		pm = &mons[pet_type()];
61.   	    } else {
62.   		pm = rndmonst();
63.   		if (!pm) {
64.   		  if (!quietly)
65.   		    pline("There seems to be nothing available for a familiar.");
66.   		  break;
67.   		}
68.   	    }
69.   
70.   	    mtmp = makemon(pm, x, y, MM_EDOG);
71.   	    if (otmp && !mtmp) { /* monster was genocided or square occupied */
72.   	 	if (!quietly)
73.   		   pline_The("figurine writhes and then shatters into pieces!");
74.   		break;
75.   	    }
76.   	} while (!mtmp && --trycnt > 0);
77.   
78.   	if (!mtmp) return (struct monst *)0;
79.   
80.   	initedog(mtmp);
81.   	mtmp->msleeping = 0;
82.   	if (otmp) { /* figurine; resulting monster might not become a pet */
83.   	    chance = rn2(10);	/* 0==tame, 1==peaceful, 2==hostile */
84.   	    if (chance > 2) chance = otmp->blessed ? 0 : !otmp->cursed ? 1 : 2;
85.   	    /* 0,1,2:  b=80%,10,10; nc=10%,80,10; c=10%,10,80 */
86.   	    if (chance > 0) {
87.   		mtmp->mtame = 0;	/* not tame after all */
88.   		if (chance == 2) { /* hostile (cursed figurine) */
89.   		    if (!quietly)
90.   		       You("get a bad feeling about this.");
91.   		    mtmp->mpeaceful = 0;
92.   		}
93.   	    }
94.   	    /* if figurine has been named, give same name to the monster */
95.   	    if (otmp->onamelth)
96.   		mtmp = christen_monst(mtmp, ONAME(otmp));
97.   	}
98.   	set_malign(mtmp); /* more alignment changes */
99.   	newsym(mtmp->mx, mtmp->my);
100.  
101.  	/* must wield weapon immediately since pets will otherwise drop it */
102.  	if (mtmp->mtame && attacktype(mtmp->data, AT_WEAP)) {
103.  		mtmp->weapon_check = NEED_HTH_WEAPON;
104.  		(void) mon_wield_item(mtmp);
105.  	}
106.  	return mtmp;
107.  }
108.  
109.  struct monst *
110.  makedog()
111.  {
112.  	register struct monst *mtmp;
113.  #ifdef STEED
114.  	register struct obj *otmp;
115.  #endif
116.  	const char *petname;
117.  	int   pettype;
118.  	static int petname_used = 0;
119.  
120.  	pettype = pet_type();
121.  	if (pettype == PM_LITTLE_DOG)
122.  		petname = dogname;
123.  	else if (pettype == PM_PONY)
124.  		petname = horsename;
125.  	else
126.  		petname = catname;
127.  
128.  	/* default pet names */
129.  	if (!*petname) {
130.  	    if(Role_if(PM_CAVEMAN)) petname = "Slasher";   /* The Warrior */
131.  	    if(Role_if(PM_SAMURAI)) petname = "Hachi";     /* Shibuya Station */
132.  	    if(Role_if(PM_BARBARIAN)) petname = "Idefix";  /* Obelix */
133.  	    if(Role_if(PM_RANGER)) petname = "Sirius";     /* Orion's dog */
134.  	}
135.  
136.  	mtmp = makemon(&mons[pettype], u.ux, u.uy, MM_EDOG);
137.  
138.  	if(!mtmp) return((struct monst *) 0); /* pets were genocided */
139.  
140.  #ifdef STEED
141.  	/* Horses already wear a saddle */
142.  	if (pettype == PM_PONY && !!(otmp = mksobj(SADDLE, TRUE, FALSE))) {
143.  	    mpickobj(mtmp, otmp);
144.  	    mtmp->misc_worn_check |= W_SADDLE;
145.  	    otmp->owornmask = W_SADDLE;
146.  	    otmp->leashmon = mtmp->m_id;
147.  	    update_mon_intrinsics(mtmp, otmp, TRUE);
148.  	}
149.  #endif
150.  
151.  	if (!petname_used++ && *petname)
152.  		mtmp = christen_monst(mtmp, petname);
153.  
154.  	initedog(mtmp);
155.  	return(mtmp);
156.  }
157.  
158.  /* record `last move time' for all monsters prior to level save so that
159.     mon_arrive() can catch up for lost time when they're restored later */
160.  void
161.  update_mlstmv()
162.  {
163.  	struct monst *mon;
164.  
165.  	/* monst->mlstmv used to be updated every time `monst' actually moved,
166.  	   but that is no longer the case so we just do a blanket assignment */
167.  	for (mon = fmon; mon; mon = mon->nmon)
168.  	    mon->mlstmv = monstermoves;
169.  }
170.  
171.  void
172.  losedogs()
173.  {
174.  	register struct monst *mtmp, *mtmp0 = 0, *mtmp2;
175.  
176.  	while ((mtmp = mydogs) != 0) {
177.  		mydogs = mtmp->nmon;
178.  		mon_arrive(mtmp, TRUE);
179.  	}
180.  
181.  	for(mtmp = migrating_mons; mtmp; mtmp = mtmp2) {
182.  		mtmp2 = mtmp->nmon;
183.  		if (mtmp->mux == u.uz.dnum && mtmp->muy == u.uz.dlevel) {
184.  		    if(mtmp == migrating_mons)
185.  			migrating_mons = mtmp->nmon;
186.  		    else
187.  			mtmp0->nmon = mtmp->nmon;
188.  		    mon_arrive(mtmp, FALSE);
189.  		} else
190.  		    mtmp0 = mtmp;
191.  	}
192.  }
193.  
194.  /* called from resurrect() in addition to losedogs() */
195.  void
196.  mon_arrive(mtmp, with_you)
197.  struct monst *mtmp;
198.  boolean with_you;
199.  {
200.  	struct trap *t;
201.  	xchar xlocale, ylocale, xyloc, xyflags, wander;
202.  	int num_segs;
203.  
204.  	mtmp->nmon = fmon;
205.  	fmon = mtmp;
206.  	if (mtmp->isshk)
207.  	    set_residency(mtmp, FALSE);
208.  
209.  	num_segs = mtmp->wormno;
210.  	/* baby long worms have no tail so don't use is_longworm() */
211.  	if ((mtmp->data == &mons[PM_LONG_WORM]) &&
212.  #ifdef DCC30_BUG
213.  	    (mtmp->wormno = get_wormno(), mtmp->wormno != 0))
214.  #else
215.  	    (mtmp->wormno = get_wormno()) != 0)
216.  #endif
217.  	{
218.  	    initworm(mtmp, num_segs);
219.  	    /* tail segs are not yet initialized or displayed */
220.  	} else mtmp->wormno = 0;
221.  
222.  	/* some monsters might need to do something special upon arrival
223.  	   _after_ the current level has been fully set up; see dochug() */
224.  	mtmp->mstrategy |= STRAT_ARRIVE;
225.  
226.  	/* make sure mnexto(rloc_to(set_apparxy())) doesn't use stale data */
227.  	mtmp->mux = u.ux,  mtmp->muy = u.uy;
228.  	xyloc	= mtmp->mtrack[0].x;
229.  	xyflags = mtmp->mtrack[0].y;
230.  	xlocale = mtmp->mtrack[1].x;
231.  	ylocale = mtmp->mtrack[1].y;
232.  	mtmp->mtrack[0].x = mtmp->mtrack[0].y = 0;
233.  	mtmp->mtrack[1].x = mtmp->mtrack[1].y = 0;
234.  
235.  #ifdef STEED
236.  	if (mtmp == u.usteed)
237.  	    return;	/* don't place steed on the map */
238.  #endif
239.  	if (with_you) {
240.  	    /* When a monster accompanies you, sometimes it will arrive
241.  	       at your intended destination and you'll end up next to
242.  	       that spot.  This code doesn't control the final outcome;
243.  	       goto_level(do.c) decides who ends up at your target spot
244.  	       when there is a monster there too. */
245.  	    if (!MON_AT(u.ux, u.uy) &&
246.  		    !rn2(mtmp->mtame ? 10 : mtmp->mpeaceful ? 5 : 2))
247.  		rloc_to(mtmp, u.ux, u.uy);
248.  	    else
249.  		mnexto(mtmp);
250.  	    return;
251.  	}
252.  	/*
253.  	 * The monster arrived on this level independently of the player.
254.  	 * Its coordinate fields were overloaded for use as flags that
255.  	 * specify its final destination.
256.  	 */
257.  
258.  	if (mtmp->mlstmv < monstermoves - 1L) {
259.  	    /* heal monster for time spent in limbo */
260.  	    long nmv = monstermoves - 1L - mtmp->mlstmv;
261.  
262.  	    mon_catchup_elapsed_time(mtmp, nmv);
263.  	    mtmp->mlstmv = monstermoves - 1L;
264.  
265.  	    /* let monster move a bit on new level (see placement code below) */
266.  	    wander = (xchar) min(nmv, 8);
267.  	} else
268.  	    wander = 0;
269.  
270.  	switch (xyloc) {
271.  	 case MIGR_APPROX_XY:	/* {x,y}locale set above */
272.  		break;
273.  	 case MIGR_EXACT_XY:	wander = 0;
274.  		break;
275.  	 case MIGR_NEAR_PLAYER:	xlocale = u.ux,  ylocale = u.uy;
276.  		break;
277.  	 case MIGR_STAIRS_UP:	xlocale = xupstair,  ylocale = yupstair;
278.  		break;
279.  	 case MIGR_STAIRS_DOWN:	xlocale = xdnstair,  ylocale = ydnstair;
280.  		break;
281.  	 case MIGR_LADDER_UP:	xlocale = xupladder,  ylocale = yupladder;
282.  		break;
283.  	 case MIGR_LADDER_DOWN:	xlocale = xdnladder,  ylocale = ydnladder;
284.  		break;
285.  	 case MIGR_SSTAIRS:	xlocale = sstairs.sx,  ylocale = sstairs.sy;
286.  		break;
287.  	 case MIGR_PORTAL:
288.  		if (In_endgame(&u.uz)) {
289.  		    /* there is no arrival portal for endgame levels */
290.  		    /* BUG[?]: for simplicity, this code relies on the fact
291.  		       that we know that the current endgame levels always
292.  		       build upwards and never have any exclusion subregion
293.  		       inside their TELEPORT_REGION settings. */
294.  		    xlocale = rn1(updest.hx - updest.lx + 1, updest.lx);
295.  		    ylocale = rn1(updest.hy - updest.ly + 1, updest.ly);
296.  		    break;
297.  		}
298.  		/* find the arrival portal */
299.  		for (t = ftrap; t; t = t->ntrap)
300.  		    if (t->ttyp == MAGIC_PORTAL) break;
301.  		if (t) {
302.  		    xlocale = t->tx,  ylocale = t->ty;
303.  		    break;
304.  		} else {
305.  		    impossible("mon_arrive: no corresponding portal?");
306.  		} /*FALLTHRU*/
307.  	 default:
308.  	 case MIGR_RANDOM:	xlocale = ylocale = 0;
309.  		    break;
310.  	    }
311.  
312.  	if (xlocale && wander) {
313.  	    /* monster moved a bit; pick a nearby location */
314.  	    /* mnearto() deals w/stone, et al */
315.  	    char *r = in_rooms(xlocale, ylocale, 0);
316.  	    if (r && *r) {
317.  		coord c;
318.  		/* somexy() handles irregular rooms */
319.  		if (somexy(&rooms[*r - ROOMOFFSET], &c))
320.  		    xlocale = c.x,  ylocale = c.y;
321.  		else
322.  		    xlocale = ylocale = 0;
323.  	    } else {		/* not in a room */
324.  		int i, j;
325.  		i = max(1, xlocale - wander);
326.  		j = min(COLNO-1, xlocale + wander);
327.  		xlocale = rn1(j - i, i);
328.  		i = max(0, ylocale - wander);
329.  		j = min(ROWNO-1, ylocale + wander);
330.  		ylocale = rn1(j - i, i);
331.  	    }
332.  	}	/* moved a bit */
333.  
334.  	mtmp->mx = 0;	/*(already is 0)*/
335.  	mtmp->my = xyflags;
336.  	if (xlocale)
337.  	    (void) mnearto(mtmp, xlocale, ylocale, FALSE);
338.  	else
339.  	    rloc(mtmp);
340.  }
341.  
342.  /* heal monster for time spent elsewhere */
343.  void
344.  mon_catchup_elapsed_time(mtmp, nmv)
345.  struct monst *mtmp;
346.  long nmv;		/* number of moves */
347.  {
348.  	int imv = 0;	/* avoid zillions of casts and lint warnings */
349.  
350.  #if defined(DEBUG) || defined(BETA)
351.  	if (nmv < 0L) {			/* crash likely... */
352.  	    panic("catchup from future time?");
353.  	    /*NOTREACHED*/
354.  	    return;
355.  	} else if (nmv == 0L) {		/* safe, but should'nt happen */
356.  	    impossible("catchup from now?");
357.  	} else
358.  #endif
359.  	if (nmv >= LARGEST_INT)		/* paranoia */
360.  	    imv = LARGEST_INT - 1;
361.  	else
362.  	    imv = (int)nmv;
363.  
364.  	/* might stop being afraid, blind or frozen */
365.  	/* set to 1 and allow final decrement in movemon() */
366.  	if (mtmp->mblinded) {
367.  	    if (imv >= (int) mtmp->mblinded) mtmp->mblinded = 1;
368.  	    else mtmp->mblinded -= imv;
369.  	}
370.  	if (mtmp->mfrozen) {
371.  	    if (imv >= (int) mtmp->mfrozen) mtmp->mfrozen = 1;
372.  	    else mtmp->mfrozen -= imv;
373.  	}
374.  	if (mtmp->mfleetim) {
375.  	    if (imv >= (int) mtmp->mfleetim) mtmp->mfleetim = 1;
376.  	    else mtmp->mfleetim -= imv;
377.  	}
378.  
379.  	/* might recover from temporary trouble */
380.  	if (mtmp->mtrapped && rn2(imv + 1) > 40/2) mtmp->mtrapped = 0;
381.  	if (mtmp->mconf    && rn2(imv + 1) > 50/2) mtmp->mconf = 0;
382.  	if (mtmp->mstun    && rn2(imv + 1) > 10/2) mtmp->mstun = 0;
383.  
384.  	/* might finish eating or be able to use special ability again */
385.  	if (imv > mtmp->meating) mtmp->meating = 0;
386.  	else mtmp->meating -= imv;
387.  	if (imv > mtmp->mspec_used) mtmp->mspec_used = 0;
388.  	else mtmp->mspec_used -= imv;
389.  
390.  	/* reduce tameness for every 150 moves you are separated */
391.  	if (mtmp->mtame) {
392.  	    int wilder = (imv + 75) / 150;
393.  	    if (mtmp->mtame > wilder) mtmp->mtame -= wilder;	/* less tame */
394.  	    else if (mtmp->mtame > rn2(wilder)) mtmp->mtame = 0;  /* untame */
395.  	    else mtmp->mtame = mtmp->mpeaceful = 0;		/* hostile! */
396.  	}
397.  	/* check to see if it would have died as a pet; if so, go wild instead
398.  	 * of dying the next time we call dog_move()
399.  	 */
400.  	if (mtmp->mtame && !mtmp->isminion &&
401.  			(carnivorous(mtmp->data) || herbivorous(mtmp->data))) {
402.  	    struct edog *edog = EDOG(mtmp);
403.  
404.  	    if ((monstermoves > edog->hungrytime + 500 && mtmp->mhp < 3) ||
405.  		    (monstermoves > edog->hungrytime + 750))
406.  		mtmp->mtame = mtmp->mpeaceful = 0;
407.  	}
408.  
409.  	/* recover lost hit points */
410.  	if (!regenerates(mtmp->data)) imv /= 20;
411.  	if (mtmp->mhp + imv >= mtmp->mhpmax)
412.  	    mtmp->mhp = mtmp->mhpmax;
413.  	else mtmp->mhp += imv;
414.  }
415.  
416.  #endif /* OVLB */
417.  #ifdef OVL2
418.  
419.  /* called when you move to another level */
420.  void
421.  keepdogs(pets_only)
422.  boolean pets_only;	/* true for ascension or final escape */
423.  {
424.  	register struct monst *mtmp, *mtmp2;
425.  	register struct obj *obj;
426.  	int num_segs;
427.  	boolean stay_behind;
428.  
429.  	for (mtmp = fmon; mtmp; mtmp = mtmp2) {
430.  	    mtmp2 = mtmp->nmon;
431.  	    if (pets_only && !mtmp->mtame) continue;
432.  	    if (((monnear(mtmp, u.ux, u.uy) && levl_follower(mtmp)) ||
433.  #ifdef STEED
434.  			(mtmp == u.usteed) ||
435.  #endif
436.  		/* the wiz will level t-port from anywhere to chase
437.  		   the amulet; if you don't have it, will chase you
438.  		   only if in range. -3. */
439.  			(u.uhave.amulet && mtmp->iswiz))
440.  			&& !mtmp->msleeping && mtmp->mcanmove) {
441.  		stay_behind = FALSE;
442.  		if (mtmp->mtame && mtmp->meating) {
443.  			if (canseemon(mtmp))
444.  			    pline("%s is still eating.", Monnam(mtmp));
445.  			stay_behind = TRUE;
446.  		} else if (mon_has_amulet(mtmp)) {
447.  			if (canseemon(mtmp))
448.  			    pline("%s seems very disoriented for a moment.",
449.  				Monnam(mtmp));
450.  			stay_behind = TRUE;
451.  		}
452.  		if (stay_behind
453.  #ifdef STEED
454.  				&& mtmp != u.usteed
455.  #endif
456.  				) {
457.  			if (mtmp->mleashed) {
458.  				pline("%s leash suddenly comes loose.",
459.  					humanoid(mtmp->data)
460.  					    ? (mtmp->female ? "Her" : "His")
461.  					    : "Its");
462.  				m_unleash(mtmp);
463.  			}
464.  			continue;
465.  		}
466.  		if (mtmp->isshk)
467.  			set_residency(mtmp, TRUE);
468.  
469.  		if (mtmp->wormno) {
470.  		    register int cnt;
471.  		    /* NOTE: worm is truncated to # segs = max wormno size */
472.  		    cnt = count_wsegs(mtmp);
473.  		    num_segs = min(cnt, MAX_NUM_WORMS - 1);
474.  		    wormgone(mtmp);
475.  		} else num_segs = 0;
476.  
477.  		/* set minvent's obj->no_charge to 0 */
478.  		for(obj = mtmp->minvent; obj; obj = obj->nobj) {
479.  		    if (Has_contents(obj))
480.  			picked_container(obj);	/* does the right thing */
481.  		    obj->no_charge = 0;
482.  		}
483.  
484.  		relmon(mtmp);
485.  		newsym(mtmp->mx,mtmp->my);
486.  		mtmp->mx = mtmp->my = 0; /* avoid mnexto()/MON_AT() problem */
487.  		mtmp->wormno = num_segs;
488.  		mtmp->mlstmv = monstermoves;
489.  		mtmp->nmon = mydogs;
490.  		mydogs = mtmp;
491.  	    } else if (mtmp->iswiz) {
492.  		/* we want to be able to find him when his next resurrection
493.  		   chance comes up, but have him resume his present location
494.  		   if player returns to this level before that time */
495.  		migrate_to_level(mtmp, ledger_no(&u.uz),
496.  				 MIGR_EXACT_XY, (coord *)0);
497.  	    } else if (mtmp->mleashed) {
498.  		/* this can happen if your quest leader ejects you from the
499.  		   "home" level while a leashed pet isn't next to you */
500.  		pline("%s leash goes slack.", s_suffix(Monnam(mtmp)));
501.  		m_unleash(mtmp);
502.  	    }
503.  	}
504.  }
505.  
506.  #endif /* OVL2 */
507.  #ifdef OVLB
508.  
509.  void
510.  migrate_to_level(mtmp, tolev, xyloc, cc)
511.  	register struct monst *mtmp;
512.  	xchar tolev;	/* destination level */
513.  	xchar xyloc;	/* MIGR_xxx destination xy location: */
514.  	coord *cc;	/* optional destination coordinates */
515.  {
516.  	register struct obj *obj;
517.  	d_level new_lev;
518.  	xchar xyflags;
519.  	int num_segs = 0;	/* count of worm segments */
520.  
521.  	if (mtmp->isshk)
522.  	    set_residency(mtmp, TRUE);
523.  
524.  	if (mtmp->wormno) {
525.  	    register int cnt;
526.  	  /* **** NOTE: worm is truncated to # segs = max wormno size **** */
527.  	    cnt = count_wsegs(mtmp);
528.  	    num_segs = min(cnt, MAX_NUM_WORMS - 1);
529.  	    wormgone(mtmp);
530.  	}
531.  
532.  	/* set minvent's obj->no_charge to 0 */
533.  	for(obj = mtmp->minvent; obj; obj = obj->nobj) {
534.  	    if (Has_contents(obj))
535.  		picked_container(obj);	/* does the right thing */
536.  	    obj->no_charge = 0;
537.  	}
538.  
539.  	relmon(mtmp);
540.  	mtmp->nmon = migrating_mons;
541.  	migrating_mons = mtmp;
542.  	if (mtmp->mleashed)  {
543.  		m_unleash(mtmp);
544.  		mtmp->mtame--;
545.  		pline_The("leash comes off!");
546.  	}
547.  	newsym(mtmp->mx,mtmp->my);
548.  
549.  	new_lev.dnum = ledger_to_dnum((xchar)tolev);
550.  	new_lev.dlevel = ledger_to_dlev((xchar)tolev);
551.  	/* overload mtmp->[mx,my], mtmp->[mux,muy], and mtmp->mtrack[] as */
552.  	/* destination codes (setup flag bits before altering mx or my) */
553.  	xyflags = (depth(&new_lev) < depth(&u.uz));	/* 1 => up */
554.  	if (In_W_tower(mtmp->mx, mtmp->my, &u.uz)) xyflags |= 2;
555.  	mtmp->wormno = num_segs;
556.  	mtmp->mlstmv = monstermoves;
557.  	mtmp->mtrack[1].x = cc ? cc->x : mtmp->mx;
558.  	mtmp->mtrack[1].y = cc ? cc->y : mtmp->my;
559.  	mtmp->mtrack[0].x = xyloc;
560.  	mtmp->mtrack[0].y = xyflags;
561.  	mtmp->mux = new_lev.dnum;
562.  	mtmp->muy = new_lev.dlevel;
563.  	mtmp->mx = mtmp->my = 0;	/* this implies migration */
564.  }
565.  
566.  #endif /* OVLB */
567.  #ifdef OVL1
568.  
569.  /* return quality of food; the lower the better */
570.  /* fungi will eat even tainted food */
571.  int
572.  dogfood(mon,obj)
573.  struct monst *mon;
574.  register struct obj *obj;
575.  {
576.  	boolean carni = carnivorous(mon->data);
577.  	boolean herbi = herbivorous(mon->data);
578.  	struct permonst *fptr = &mons[obj->corpsenm];
579.  
580.  	if (is_quest_artifact(obj) || obj_resists(obj, 0, 95))
581.  	    return (obj->cursed ? TABU : APPORT);
582.  
583.  	switch(obj->oclass) {
584.  	case FOOD_CLASS:
585.  	    if (obj->otyp == CORPSE &&
586.  		((touch_petrifies(&mons[obj->corpsenm]) && !resists_ston(mon))
587.  		 || is_rider(fptr)))
588.  		    return TABU;
589.  
590.  	    /* Ghouls only eat old corpses... yum! */
591.  	    if (mon->data == &mons[PM_GHOUL])
592.  	    	return (obj->otyp == CORPSE && obj->age+50 <= monstermoves) ?
593.  	       			DOGFOOD : TABU;
594.  
595.  	    if (!carni && !herbi)
596.  		    return (obj->cursed ? UNDEF : APPORT);
597.  
598.  	    switch (obj->otyp) {
599.  		case TRIPE_RATION:
600.  		case MEATBALL:
601.  		case MEAT_RING:
602.  		case MEAT_STICK:
603.  		    return (carni ? DOGFOOD : MANFOOD);
604.  		case EGG:
605.  		    if (touch_petrifies(&mons[obj->corpsenm]) && !resists_ston(mon))
606.  			return POISON;
607.  		    return (carni ? CADAVER : MANFOOD);
608.  		case CORPSE:
609.  		   if ((peek_at_iced_corpse_age(obj)+50 <= monstermoves
610.  					    && obj->corpsenm != PM_LIZARD
611.  					    && obj->corpsenm != PM_LICHEN
612.  					    && mon->data->mlet != S_FUNGUS) ||
613.  			(acidic(&mons[obj->corpsenm]) && !resists_acid(mon)) ||
614.  			(poisonous(&mons[obj->corpsenm]) &&
615.  						!resists_poison(mon)))
616.  			return POISON;
617.  		    else if (fptr->mlet == S_FUNGUS)
618.  			return (herbi ? CADAVER : MANFOOD);
619.  		    else if (is_meaty(fptr))
620.  		        return (carni ? CADAVER : MANFOOD);
621.  		    else return (carni ? ACCFOOD : MANFOOD);
622.  		case CLOVE_OF_GARLIC:
623.  		    return (is_undead(mon->data) ? TABU :
624.  			    (herbi ? ACCFOOD : MANFOOD));
625.  		case TIN:
626.  		    return (metallivorous(mon->data) ? ACCFOOD : MANFOOD);
627.  		case APPLE:
628.  		case CARROT:
629.  		    return (herbi ? DOGFOOD : MANFOOD);
630.  		case BANANA:
631.  		    return ((mon->data->mlet == S_YETI) ? DOGFOOD :
632.  			    (herbi ? ACCFOOD : MANFOOD));
633.  		default:
634.  		    return (obj->otyp > SLIME_MOLD ?
635.  			    (carni ? ACCFOOD : MANFOOD) :
636.  			    (herbi ? ACCFOOD : MANFOOD));
637.  	    }
638.  	default:
639.  	    if (obj->otyp == AMULET_OF_STRANGULATION ||
640.  	    		obj->otyp == RIN_SLOW_DIGESTION)
641.  	    	return (TABU);
642.  	    if (hates_silver(mon->data) &&
643.  		objects[obj->otyp].oc_material == SILVER)
644.  		return(TABU);
645.  	    if (mon->data == &mons[PM_GELATINOUS_CUBE] && is_organic(obj))
646.  		return(ACCFOOD);
647.  	    if (metallivorous(mon->data) && is_metallic(obj))
648.  		/* Non-rustproofed ferrous based metals are preferred. */
649.  		return(objects[obj->otyp].oc_material == IRON &&
650.  		       !obj->oerodeproof ? DOGFOOD : ACCFOOD);
651.  	    if(!obj->cursed && obj->oclass != BALL_CLASS &&
652.  						obj->oclass != CHAIN_CLASS)
653.  		return(APPORT);
654.  	    /* fall into next case */
655.  	case ROCK_CLASS:
656.  	    return(UNDEF);
657.  	}
658.  }
659.  
660.  #endif /* OVL1 */
661.  #ifdef OVLB
662.  
663.  struct monst *
664.  tamedog(mtmp, obj)
665.  register struct monst *mtmp;
666.  register struct obj *obj;
667.  {
668.  	register struct monst *mtmp2;
669.  
670.  	/* The Wiz, Medusa and the quest nemeses aren't even made peaceful. */
671.  	if (mtmp->iswiz || mtmp->data == &mons[PM_MEDUSA]
672.  				|| (mtmp->data->mflags3 & M3_WANTSARTI))
673.  		return((struct monst *)0);
674.  
675.  	/* worst case, at least it'll be peaceful. */
676.  	mtmp->mpeaceful = 1;
677.  	set_malign(mtmp);
678.  	if(flags.moonphase == FULL_MOON && night() && rn2(6) && obj
679.  						&& mtmp->data->mlet == S_DOG)
680.  		return((struct monst *)0);
681.  
682.  	/* If we cannot tame it, at least it's no longer afraid. */
683.  	mtmp->mflee = 0;
684.  	mtmp->mfleetim = 0;
685.  
686.  	/* make grabber let go now, whether it becomes tame or not */
687.  	if (mtmp == u.ustuck) {
688.  	    if (u.uswallow)
689.  		expels(mtmp, mtmp->data, TRUE);
690.  	    else if (!(Upolyd && sticks(youmonst.data)))
691.  		unstuck(mtmp);
692.  	}
693.  
694.  	/* feeding it treats makes it tamer */
695.  	if (mtmp->mtame && obj) {
696.  	    int tasty;
697.  
698.  	    if (mtmp->mcanmove && !mtmp->mconf && !mtmp->meating &&
699.  		((tasty = dogfood(mtmp, obj)) == DOGFOOD ||
700.  		 (tasty <= ACCFOOD && EDOG(mtmp)->hungrytime <= monstermoves))) {
701.  		/* pet will "catch" and eat this thrown food */
702.  		if (canseemon(mtmp)) {
703.  		    boolean big_corpse = (obj->otyp == CORPSE &&
704.  					  obj->corpsenm >= LOW_PM &&
705.  				mons[obj->corpsenm].msize > mtmp->data->msize);
706.  		    pline("%s catches %s%s",
707.  			  Monnam(mtmp), the(xname(obj)),
708.  			  !big_corpse ? "." : ", or vice versa!");
709.  		} else if (cansee(mtmp->mx,mtmp->my))
710.  		    pline("%s stops.", The(xname(obj)));
711.  		/* dog_eat expects a floor object */
712.  		place_object(obj, mtmp->mx, mtmp->my);
713.  		(void) dog_eat(mtmp, obj, mtmp->mx, mtmp->my, FALSE);
714.  		/* eating might have killed it, but that doesn't matter here;
715.  		   a non-null result suppresses "miss" message for thrown
716.  		   food and also implies that the object has been deleted */
717.  		return mtmp;
718.  	    } else
719.  		return (struct monst *)0;
720.  	}
721.  
722.  	if (mtmp->mtame || !mtmp->mcanmove ||
723.  	    /* monsters with conflicting structures cannot be tamed */
724.  	    mtmp->isshk || mtmp->isgd || mtmp->ispriest || mtmp->isminion ||
725.  	    is_covetous(mtmp->data) || is_human(mtmp->data) ||
726.  	    (is_demon(mtmp->data) && !is_demon(youmonst.data)) ||
727.  	    (obj && dogfood(mtmp, obj) >= MANFOOD)) return (struct monst *)0;
728.  
729.  	/* make a new monster which has the pet extension */
730.  	mtmp2 = newmonst(sizeof(struct edog) + mtmp->mnamelth);
731.  	*mtmp2 = *mtmp;
732.  	mtmp2->mxlth = sizeof(struct edog);
733.  	if (mtmp->mnamelth) Strcpy(NAME(mtmp2), NAME(mtmp));
734.  	initedog(mtmp2);
735.  	replmon(mtmp, mtmp2);
736.  	/* `mtmp' is now obsolete */
737.  
738.  	if (obj) {		/* thrown food */
739.  	    /* defer eating until the edog extension has been set up */
740.  	    place_object(obj, mtmp2->mx, mtmp2->my);	/* put on floor */
741.  	    /* devour the food (might grow into larger, genocided monster) */
742.  	    if (dog_eat(mtmp2, obj, mtmp2->mx, mtmp2->my, TRUE) == 2)
743.  		return mtmp2;		/* oops, it died... */
744.  	    /* `obj' is now obsolete */
745.  	}
746.  
747.  	newsym(mtmp2->mx, mtmp2->my);
748.  	if (attacktype(mtmp2->data, AT_WEAP)) {
749.  		mtmp2->weapon_check = NEED_HTH_WEAPON;
750.  		(void) mon_wield_item(mtmp2);
751.  	}
752.  	return(mtmp2);
753.  }
754.  
755.  /*
756.   * Called during pet revival or pet life-saving.
757.   * If you killed the pet, it revives wild.
758.   * If you abused the pet a lot while alive, it revives wild.
759.   * If you abused the pet at all while alive, it revives untame.
760.   * If the pet wasn't abused and was very tame, it might revive tame.
761.   */
762.  void
763.  wary_dog(mtmp, quietly)
764.  struct monst *mtmp;
765.  boolean quietly;
766.  {
767.      if (!mtmp->mtame) return;
768.      mtmp->mpeaceful = 0;
769.      if ((EDOG(mtmp)->killed_by_u == 1) || (EDOG(mtmp)->abuse > 2)) {
770.  	mtmp->mtame = 0;
771.  	if (EDOG(mtmp)->abuse >= 0 && EDOG(mtmp)->abuse < 10)
772.  		if (!rn2(EDOG(mtmp)->abuse + 1)) mtmp->mpeaceful = 1;
773.  	if(!quietly && cansee(mtmp->mx, mtmp->my)) {
774.  	    if (haseyes(youmonst.data)) {
775.  		if (haseyes(mtmp->data))
776.  			pline("%s %s to look you in the %s.",
777.  				Monnam(mtmp),
778.  				mtmp->mpeaceful ? "seems unable" :
779.  					    "refuses",
780.  				body_part(EYE));
781.  		else 
782.  			pline("%s avoids your gaze.",
783.  				Monnam(mtmp));
784.  	    }
785.  	}
786.      } else {
787.      	/* chance it goes wild anyway - Pet Semetary */
788.      	if (!rn2(mtmp->mtame)) {
789.      		mtmp->mtame = 0;
790.      	}
791.      }
792.      /* if its still a pet, start a clean pet-slate now */
793.      if (mtmp->mtame) {
794.  	EDOG(mtmp)->revivals++;
795.      	EDOG(mtmp)->killed_by_u = 0;
796.      	EDOG(mtmp)->abuse = 0;
797.      }
798.  }
799.  
800.  void
801.  abuse_dog(mtmp)
802.  struct monst *mtmp;
803.  {
804.  	if (!mtmp->mtame) return;
805.  
806.  	if (Aggravate_monster || Conflict) mtmp->mtame /=2;
807.  	else mtmp->mtame--;
808.  
809.  	if (mtmp->mtame) 
810.  		EDOG(mtmp)->abuse++;
811.  
812.  	if (mtmp->mtame && rn2(mtmp->mtame)) yelp(mtmp);
813.  	else growl(mtmp);	/* give them a moment's worry */
814.  	
815.  	if (!mtmp->mtame) newsym(mtmp->mx, mtmp->my);
816.  }
817.  
818.  #endif /* OVLB */
819.  
820.  /*dog.c*/

Around Wikia's network

Random Wiki