Wikia

Wikihack

Source:NetHack 3.4.0/dog.c

2,032pages on
this wiki
Talk0

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

Around Wikia's network

Random Wiki