Source:NetHack 3.4.3/src/dog.c

From NetHackWiki
Jump to: navigation, search

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

Top of file[edit]

  1. /*	SCCS Id: @(#)dog.c	3.4	2002/09/08	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

  1. #include "hack.h"
  2. #include "edog.h"
  3.  
  4. #ifdef OVLB
  5.  
  6. STATIC_DCL int NDECL(pet_type);

initedog[edit]

  1. void
  2. initedog(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	mtmp->mtame = is_domestic(mtmp->data) ? 10 : 5;
  6. 	mtmp->mpeaceful = 1;
  7. 	mtmp->mavenge = 0;
  8. 	set_malign(mtmp); /* recalc alignment now that it's tamed */
  9. 	mtmp->mleashed = 0;
  10. 	mtmp->meating = 0;
  11. 	EDOG(mtmp)->droptime = 0;
  12. 	EDOG(mtmp)->dropdist = 10000;
  13. 	EDOG(mtmp)->apport = 10;
  14. 	EDOG(mtmp)->whistletime = 0;
  15. 	EDOG(mtmp)->hungrytime = 1000 + monstermoves;
  16. 	EDOG(mtmp)->ogoal.x = -1;	/* force error if used before set */
  17. 	EDOG(mtmp)->ogoal.y = -1;
  18. 	EDOG(mtmp)->abuse = 0;
  19. 	EDOG(mtmp)->revivals = 0;
  20. 	EDOG(mtmp)->mhpmax_penalty = 0;
  21. 	EDOG(mtmp)->killed_by_u = 0;
  22. }

pet_type[edit]

  1. STATIC_OVL int
  2. pet_type()
  3. {
  4. 	if (urole.petnum != NON_PM)
  5. 	    return (urole.petnum);
  6. 	else if (preferred_pet == 'c')
  7. 	    return (PM_KITTEN);
  8. 	else if (preferred_pet == 'd')
  9. 	    return (PM_LITTLE_DOG);
  10. 	else
  11. 	    return (rn2(2) ? PM_KITTEN : PM_LITTLE_DOG);
  12. }

make_familiar[edit]

  1. struct monst *
  2. make_familiar(otmp,x,y,quietly)
  3. register struct obj *otmp;
  4. xchar x, y;
  5. boolean quietly;
  6. {
  7. 	struct permonst *pm;
  8. 	struct monst *mtmp = 0;
  9. 	int chance, trycnt = 100;
  10.  
  11. 	do {
  12. 	    if (otmp) {	/* figurine; otherwise spell */
  13. 		int mndx = otmp->corpsenm;
  14. 		pm = &mons[mndx];
  15. 		/* activating a figurine provides one way to exceed the
  16. 		   maximum number of the target critter created--unless
  17. 		   it has a special limit (erinys, Nazgul) */
  18. 		if ((mvitals[mndx].mvflags & G_EXTINCT) &&
  19. 			mbirth_limit(mndx) != MAXMONNO) {
  20. 		    if (!quietly)
  21. 			/* have just been given "You <do something with>
  22. 			   the figurine and it transforms." message */
  23. 			pline("... into a pile of dust.");
  24. 		    break;	/* mtmp is null */
  25. 		}
  26. 	    } else if (!rn2(3)) {
  27. 		pm = &mons[pet_type()];
  28. 	    } else {
  29. 		pm = rndmonst();
  30. 		if (!pm) {
  31. 		  if (!quietly)
  32. 		    There("seems to be nothing available for a familiar.");
  33. 		  break;
  34. 		}
  35. 	    }
  36.  
  37. 	    mtmp = makemon(pm, x, y, MM_EDOG|MM_IGNOREWATER);
  38. 	    if (otmp && !mtmp) { /* monster was genocided or square occupied */
  39. 	 	if (!quietly)
  40. 		   pline_The("figurine writhes and then shatters into pieces!");
  41. 		break;
  42. 	    }
  43. 	} while (!mtmp && --trycnt > 0);
  44.  
  45. 	if (!mtmp) return (struct monst *)0;
  46.  
  47. 	if (is_pool(mtmp->mx, mtmp->my) && minliquid(mtmp))
  48. 		return (struct monst *)0;
  49.  
  50. 	initedog(mtmp);
  51. 	mtmp->msleeping = 0;
  52. 	if (otmp) { /* figurine; resulting monster might not become a pet */
  53. 	    chance = rn2(10);	/* 0==tame, 1==peaceful, 2==hostile */
  54. 	    if (chance > 2) chance = otmp->blessed ? 0 : !otmp->cursed ? 1 : 2;
  55. 	    /* 0,1,2:  b=80%,10,10; nc=10%,80,10; c=10%,10,80 */
  56. 	    if (chance > 0) {
  57. 		mtmp->mtame = 0;	/* not tame after all */
  58. 		if (chance == 2) { /* hostile (cursed figurine) */
  59. 		    if (!quietly)
  60. 		       You("get a bad feeling about this.");
  61. 		    mtmp->mpeaceful = 0;
  62. 		    set_malign(mtmp);
  63. 		}
  64. 	    }
  65. 	    /* if figurine has been named, give same name to the monster */
  66. 	    if (otmp->onamelth)
  67. 		mtmp = christen_monst(mtmp, ONAME(otmp));
  68. 	}
  69. 	set_malign(mtmp); /* more alignment changes */
  70. 	newsym(mtmp->mx, mtmp->my);
  71.  
  72. 	/* must wield weapon immediately since pets will otherwise drop it */
  73. 	if (mtmp->mtame && attacktype(mtmp->data, AT_WEAP)) {
  74. 		mtmp->weapon_check = NEED_HTH_WEAPON;
  75. 		(void) mon_wield_item(mtmp);
  76. 	}
  77. 	return mtmp;
  78. }

makedog[edit]

  1. struct monst *
  2. makedog()
  3. {
  4. 	register struct monst *mtmp;
  5. #ifdef STEED
  6. 	register struct obj *otmp;
  7. #endif
  8. 	const char *petname;
  9. 	int   pettype;
  10. 	static int petname_used = 0;
  11.  
  12. 	if (preferred_pet == 'n') return((struct monst *) 0);
  13.  
  14. 	pettype = pet_type();
  15. 	if (pettype == PM_LITTLE_DOG)
  16. 		petname = dogname;
  17. 	else if (pettype == PM_PONY)
  18. 		petname = horsename;
  19. 	else
  20. 		petname = catname;
  21.  
  22. 	/* default pet names */
  23. 	if (!*petname && pettype == PM_LITTLE_DOG) {
  24. 	    /* All of these names were for dogs. */
  25. 	    if(Role_if(PM_CAVEMAN)) petname = "Slasher";   /* The Warrior */
  26. 	    if(Role_if(PM_SAMURAI)) petname = "Hachi";     /* Shibuya Station */
  27. 	    if(Role_if(PM_BARBARIAN)) petname = "Idefix";  /* Obelix */
  28. 	    if(Role_if(PM_RANGER)) petname = "Sirius";     /* Orion's dog */
  29. 	}
  30.  
  31. 	mtmp = makemon(&mons[pettype], u.ux, u.uy, MM_EDOG);
  32.  
  33. 	if(!mtmp) return((struct monst *) 0); /* pets were genocided */
  34.  
  35. #ifdef STEED
  36. 	/* Horses already wear a saddle */
  37. 	if (pettype == PM_PONY && !!(otmp = mksobj(SADDLE, TRUE, FALSE))) {
  38. 	    if (mpickobj(mtmp, otmp))
  39. 		panic("merged saddle?");
  40. 	    mtmp->misc_worn_check |= W_SADDLE;
  41. 	    otmp->dknown = otmp->bknown = otmp->rknown = 1;
  42. 	    otmp->owornmask = W_SADDLE;
  43. 	    otmp->leashmon = mtmp->m_id;
  44. 	    update_mon_intrinsics(mtmp, otmp, TRUE, TRUE);
  45. 	}
  46. #endif
  47.  
  48. 	if (!petname_used++ && *petname)
  49. 		mtmp = christen_monst(mtmp, petname);
  50.  
  51. 	initedog(mtmp);
  52. 	return(mtmp);
  53. }

update_mlstmv[edit]

  1. /* record `last move time' for all monsters prior to level save so that
  2. mon_arrive() can catch up for lost time when they're restored later */
  3. void
  4. update_mlstmv()
  5. {
  6. 	struct monst *mon;
  7.  
  8. 	/* monst->mlstmv used to be updated every time `monst' actually moved,
  9. 	   but that is no longer the case so we just do a blanket assignment */
  10. 	for (mon = fmon; mon; mon = mon->nmon)
  11. 	    if (!DEADMONSTER(mon)) mon->mlstmv = monstermoves;
  12. }

losedogs[edit]

  1. void
  2. losedogs()
  3. {
  4. 	register struct monst *mtmp, *mtmp0 = 0, *mtmp2;
  5.  
  6. 	while ((mtmp = mydogs) != 0) {
  7. 		mydogs = mtmp->nmon;
  8. 		mon_arrive(mtmp, TRUE);
  9. 	}
  10.  
  11. 	for(mtmp = migrating_mons; mtmp; mtmp = mtmp2) {
  12. 		mtmp2 = mtmp->nmon;
  13. 		if (mtmp->mux == u.uz.dnum && mtmp->muy == u.uz.dlevel) {
  14. 		    if(mtmp == migrating_mons)
  15. 			migrating_mons = mtmp->nmon;
  16. 		    else
  17. 			mtmp0->nmon = mtmp->nmon;
  18. 		    mon_arrive(mtmp, FALSE);
  19. 		} else
  20. 		    mtmp0 = mtmp;
  21. 	}
  22. }

mon_arrive[edit]

  1. /* called from resurrect() in addition to losedogs() */
  2. void
  3. mon_arrive(mtmp, with_you)
  4. struct monst *mtmp;
  5. boolean with_you;
  6. {
  7. 	struct trap *t;
  8. 	xchar xlocale, ylocale, xyloc, xyflags, wander;
  9. 	int num_segs;
  10.  
  11. 	mtmp->nmon = fmon;
  12. 	fmon = mtmp;
  13. 	if (mtmp->isshk)
  14. 	    set_residency(mtmp, FALSE);
  15.  
  16. 	num_segs = mtmp->wormno;
  17. 	/* baby long worms have no tail so don't use is_longworm() */
  18. 	if ((mtmp->data == &mons[PM_LONG_WORM]) &&
  19. #ifdef DCC30_BUG
  20. 	    (mtmp->wormno = get_wormno(), mtmp->wormno != 0))
  21. #else
  22. 	    (mtmp->wormno = get_wormno()) != 0)
  23. #endif
  24. 	{
  25. 	    initworm(mtmp, num_segs);
  26. 	    /* tail segs are not yet initialized or displayed */
  27. 	} else mtmp->wormno = 0;
  28.  
  29. 	/* some monsters might need to do something special upon arrival
  30. 	   _after_ the current level has been fully set up; see dochug() */
  31. 	mtmp->mstrategy |= STRAT_ARRIVE;
  32.  
  33. 	/* make sure mnexto(rloc_to(set_apparxy())) doesn't use stale data */
  34. 	mtmp->mux = u.ux,  mtmp->muy = u.uy;
  35. 	xyloc	= mtmp->mtrack[0].x;
  36. 	xyflags = mtmp->mtrack[0].y;
  37. 	xlocale = mtmp->mtrack[1].x;
  38. 	ylocale = mtmp->mtrack[1].y;
  39. 	mtmp->mtrack[0].x = mtmp->mtrack[0].y = 0;
  40. 	mtmp->mtrack[1].x = mtmp->mtrack[1].y = 0;
  41.  
  42. #ifdef STEED
  43. 	if (mtmp == u.usteed)
  44. 	    return;	/* don't place steed on the map */
  45. #endif
  46. 	if (with_you) {
  47. 	    /* When a monster accompanies you, sometimes it will arrive
  48. 	       at your intended destination and you'll end up next to
  49. 	       that spot.  This code doesn't control the final outcome;
  50. 	       goto_level(do.c) decides who ends up at your target spot
  51. 	       when there is a monster there too. */
  52. 	    if (!MON_AT(u.ux, u.uy) &&
  53. 		    !rn2(mtmp->mtame ? 10 : mtmp->mpeaceful ? 5 : 2))
  54. 		rloc_to(mtmp, u.ux, u.uy);
  55. 	    else
  56. 		mnexto(mtmp);
  57. 	    return;
  58. 	}
  59. 	/*
  60. 	 * The monster arrived on this level independently of the player.
  61. 	 * Its coordinate fields were overloaded for use as flags that
  62. 	 * specify its final destination.
  63. 	 */
  64.  
  65. 	if (mtmp->mlstmv < monstermoves - 1L) {
  66. 	    /* heal monster for time spent in limbo */
  67. 	    long nmv = monstermoves - 1L - mtmp->mlstmv;
  68.  
  69. 	    mon_catchup_elapsed_time(mtmp, nmv);
  70. 	    mtmp->mlstmv = monstermoves - 1L;
  71.  
  72. 	    /* let monster move a bit on new level (see placement code below) */
  73. 	    wander = (xchar) min(nmv, 8);
  74. 	} else
  75. 	    wander = 0;
  76.  
  77. 	switch (xyloc) {
  78. 	 case MIGR_APPROX_XY:	/* {x,y}locale set above */
  79. 		break;
  80. 	 case MIGR_EXACT_XY:	wander = 0;
  81. 		break;
  82. 	 case MIGR_NEAR_PLAYER:	xlocale = u.ux,  ylocale = u.uy;
  83. 		break;
  84. 	 case MIGR_STAIRS_UP:	xlocale = xupstair,  ylocale = yupstair;
  85. 		break;
  86. 	 case MIGR_STAIRS_DOWN:	xlocale = xdnstair,  ylocale = ydnstair;
  87. 		break;
  88. 	 case MIGR_LADDER_UP:	xlocale = xupladder,  ylocale = yupladder;
  89. 		break;
  90. 	 case MIGR_LADDER_DOWN:	xlocale = xdnladder,  ylocale = ydnladder;
  91. 		break;
  92. 	 case MIGR_SSTAIRS:	xlocale = sstairs.sx,  ylocale = sstairs.sy;
  93. 		break;
  94. 	 case MIGR_PORTAL:
  95. 		if (In_endgame(&u.uz)) {
  96. 		    /* there is no arrival portal for endgame levels */
  97. 		    /* BUG[?]: for simplicity, this code relies on the fact
  98. 		       that we know that the current endgame levels always
  99. 		       build upwards and never have any exclusion subregion
  100. 		       inside their TELEPORT_REGION settings. */
  101. 		    xlocale = rn1(updest.hx - updest.lx + 1, updest.lx);
  102. 		    ylocale = rn1(updest.hy - updest.ly + 1, updest.ly);
  103. 		    break;
  104. 		}
  105. 		/* find the arrival portal */
  106. 		for (t = ftrap; t; t = t->ntrap)
  107. 		    if (t->ttyp == MAGIC_PORTAL) break;
  108. 		if (t) {
  109. 		    xlocale = t->tx,  ylocale = t->ty;
  110. 		    break;
  111. 		} else {
  112. 		    impossible("mon_arrive: no corresponding portal?");
  113. 		} /*FALLTHRU*/
  114. 	 default:
  115. 	 case MIGR_RANDOM:	xlocale = ylocale = 0;
  116. 		    break;
  117. 	    }
  118.  
  119. 	if (xlocale && wander) {
  120. 	    /* monster moved a bit; pick a nearby location */
  121. 	    /* mnearto() deals w/stone, et al */
  122. 	    char *r = in_rooms(xlocale, ylocale, 0);
  123. 	    if (r && *r) {
  124. 		coord c;
  125. 		/* somexy() handles irregular rooms */
  126. 		if (somexy(&rooms[*r - ROOMOFFSET], &c))
  127. 		    xlocale = c.x,  ylocale = c.y;
  128. 		else
  129. 		    xlocale = ylocale = 0;
  130. 	    } else {		/* not in a room */
  131. 		int i, j;
  132. 		i = max(1, xlocale - wander);
  133. 		j = min(COLNO-1, xlocale + wander);
  134. 		xlocale = rn1(j - i, i);
  135. 		i = max(0, ylocale - wander);
  136. 		j = min(ROWNO-1, ylocale + wander);
  137. 		ylocale = rn1(j - i, i);
  138. 	    }
  139. 	}	/* moved a bit */
  140.  
  141. 	mtmp->mx = 0;	/*(already is 0)*/
  142. 	mtmp->my = xyflags;
  143. 	if (xlocale)
  144. 	    (void) mnearto(mtmp, xlocale, ylocale, FALSE);
  145. 	else {
  146. 	    if (!rloc(mtmp,TRUE)) {
  147. 		/*
  148. 		 * Failed to place migrating monster,
  149. 		 * probably because the level is full.
  150. 		 * Dump the monster's cargo and leave the monster dead.
  151. 		 */
  152. 	    	struct obj *obj, *corpse;
  153. 		while ((obj = mtmp->minvent) != 0) {
  154. 		    obj_extract_self(obj);
  155. 		    obj_no_longer_held(obj);
  156. 		    if (obj->owornmask & W_WEP)
  157. 			setmnotwielded(mtmp,obj);
  158. 		    obj->owornmask = 0L;
  159. 		    if (xlocale && ylocale)
  160. 			    place_object(obj, xlocale, ylocale);
  161. 		    else {
  162. 		    	rloco(obj);
  163. 			get_obj_location(obj, &xlocale, &ylocale, 0);
  164. 		    }
  165. 		}
  166. 		corpse = mkcorpstat(CORPSE, (struct monst *)0, mtmp->data,
  167. 				xlocale, ylocale, FALSE);
  168. #ifndef GOLDOBJ
  169. 		if (mtmp->mgold) {
  170. 		    if (xlocale == 0 && ylocale == 0 && corpse) {
  171. 			(void) get_obj_location(corpse, &xlocale, &ylocale, 0);
  172. 			(void) mkgold(mtmp->mgold, xlocale, ylocale);
  173. 		    }
  174. 		    mtmp->mgold = 0L;
  175. 		}
  176. #endif
  177. 		mongone(mtmp);
  178. 	    }
  179. 	}
  180. }

mon_catchup_elapsed_time[edit]

  1. /* heal monster for time spent elsewhere */
  2. void
  3. mon_catchup_elapsed_time(mtmp, nmv)
  4. struct monst *mtmp;
  5. long nmv;		/* number of moves */
  6. {
  7. 	int imv = 0;	/* avoid zillions of casts and lint warnings */
  8.  
  9. #if defined(DEBUG) || defined(BETA)
  10. 	if (nmv < 0L) {			/* crash likely... */
  11. 	    panic("catchup from future time?");
  12. 	    /*NOTREACHED*/
  13. 	    return;
  14. 	} else if (nmv == 0L) {		/* safe, but should'nt happen */
  15. 	    impossible("catchup from now?");
  16. 	} else
  17. #endif
  18. 	if (nmv >= LARGEST_INT)		/* paranoia */
  19. 	    imv = LARGEST_INT - 1;
  20. 	else
  21. 	    imv = (int)nmv;
  22.  
  23. 	/* might stop being afraid, blind or frozen */
  24. 	/* set to 1 and allow final decrement in movemon() */
  25. 	if (mtmp->mblinded) {
  26. 	    if (imv >= (int) mtmp->mblinded) mtmp->mblinded = 1;
  27. 	    else mtmp->mblinded -= imv;
  28. 	}
  29. 	if (mtmp->mfrozen) {
  30. 	    if (imv >= (int) mtmp->mfrozen) mtmp->mfrozen = 1;
  31. 	    else mtmp->mfrozen -= imv;
  32. 	}
  33. 	if (mtmp->mfleetim) {
  34. 	    if (imv >= (int) mtmp->mfleetim) mtmp->mfleetim = 1;
  35. 	    else mtmp->mfleetim -= imv;
  36. 	}
  37.  
  38. 	/* might recover from temporary trouble */
  39. 	if (mtmp->mtrapped && rn2(imv + 1) > 40/2) mtmp->mtrapped = 0;
  40. 	if (mtmp->mconf    && rn2(imv + 1) > 50/2) mtmp->mconf = 0;
  41. 	if (mtmp->mstun    && rn2(imv + 1) > 10/2) mtmp->mstun = 0;
  42.  
  43. 	/* might finish eating or be able to use special ability again */
  44. 	if (imv > mtmp->meating) mtmp->meating = 0;
  45. 	else mtmp->meating -= imv;
  46. 	if (imv > mtmp->mspec_used) mtmp->mspec_used = 0;
  47. 	else mtmp->mspec_used -= imv;
  48.  
  49. 	/* reduce tameness for every 150 moves you are separated */
  50. 	if (mtmp->mtame) {
  51. 	    int wilder = (imv + 75) / 150;
  52. 	    if (mtmp->mtame > wilder) mtmp->mtame -= wilder;	/* less tame */
  53. 	    else if (mtmp->mtame > rn2(wilder)) mtmp->mtame = 0;  /* untame */
  54. 	    else mtmp->mtame = mtmp->mpeaceful = 0;		/* hostile! */
  55. 	}
  56. 	/* check to see if it would have died as a pet; if so, go wild instead
  57. 	 * of dying the next time we call dog_move()
  58. 	 */
  59. 	if (mtmp->mtame && !mtmp->isminion &&
  60. 			(carnivorous(mtmp->data) || herbivorous(mtmp->data))) {
  61. 	    struct edog *edog = EDOG(mtmp);
  62.  
  63. 	    if ((monstermoves > edog->hungrytime + 500 && mtmp->mhp < 3) ||
  64. 		    (monstermoves > edog->hungrytime + 750))
  65. 		mtmp->mtame = mtmp->mpeaceful = 0;
  66. 	}
  67.  
  68. 	if (!mtmp->mtame && mtmp->mleashed) {
  69. 	    /* leashed monsters should always be with hero, consequently
  70. 	       never losing any time to be accounted for later */
  71. 	    impossible("catching up for leashed monster?");
  72. 	    m_unleash(mtmp, FALSE);
  73. 	}
  74.  
  75. 	/* recover lost hit points */
  76. 	if (!regenerates(mtmp->data)) imv /= 20;
  77. 	if (mtmp->mhp + imv >= mtmp->mhpmax)
  78. 	    mtmp->mhp = mtmp->mhpmax;
  79. 	else mtmp->mhp += imv;
  80. }
  81.  
  82. #endif /* OVLB */

keepdogs[edit]

  1. #ifdef OVL2
  2.  
  3. /* called when you move to another level */
  4. void
  5. keepdogs(pets_only)
  6. boolean pets_only;	/* true for ascension or final escape */
  7. {
  8. 	register struct monst *mtmp, *mtmp2;
  9. 	register struct obj *obj;
  10. 	int num_segs;
  11. 	boolean stay_behind;
  12.  
  13. 	for (mtmp = fmon; mtmp; mtmp = mtmp2) {
  14. 	    mtmp2 = mtmp->nmon;
  15. 	    if (DEADMONSTER(mtmp)) continue;
  16. 	    if (pets_only && !mtmp->mtame) continue;
  17. 	    if (((monnear(mtmp, u.ux, u.uy) && levl_follower(mtmp)) ||
  18. #ifdef STEED
  19. 			(mtmp == u.usteed) ||
  20. #endif
  21. 		/* the wiz will level t-port from anywhere to chase
  22. 		   the amulet; if you don't have it, will chase you
  23. 		   only if in range. -3. */
  24. 			(u.uhave.amulet && mtmp->iswiz))
  25. 		&& ((!mtmp->msleeping && mtmp->mcanmove)
  26. #ifdef STEED
  27. 		    /* eg if level teleport or new trap, steed has no control
  28. 		       to avoid following */
  29. 		    || (mtmp == u.usteed)
  30. #endif
  31. 		    )
  32. 		/* monster won't follow if it hasn't noticed you yet */
  33. 		&& !(mtmp->mstrategy & STRAT_WAITFORU)) {
  34. 		stay_behind = FALSE;
  35. 		if (mtmp->mtame && mtmp->meating) {
  36. 			if (canseemon(mtmp))
  37. 			    pline("%s is still eating.", Monnam(mtmp));
  38. 			stay_behind = TRUE;
  39. 		} else if (mon_has_amulet(mtmp)) {
  40. 			if (canseemon(mtmp))
  41. 			    pline("%s seems very disoriented for a moment.",
  42. 				Monnam(mtmp));
  43. 			stay_behind = TRUE;
  44. 		} else if (mtmp->mtame && mtmp->mtrapped) {
  45. 			if (canseemon(mtmp))
  46. 			    pline("%s is still trapped.", Monnam(mtmp));
  47. 			stay_behind = TRUE;
  48. 		}
  49. #ifdef STEED
  50. 		if (mtmp == u.usteed) stay_behind = FALSE;
  51. #endif
  52. 		if (stay_behind) {
  53. 			if (mtmp->mleashed) {
  54. 				pline("%s leash suddenly comes loose.",
  55. 					humanoid(mtmp->data)
  56. 					    ? (mtmp->female ? "Her" : "His")
  57. 					    : "Its");
  58. 				m_unleash(mtmp, FALSE);
  59. 			}
  60. 			continue;
  61. 		}
  62. 		if (mtmp->isshk)
  63. 			set_residency(mtmp, TRUE);
  64.  
  65. 		if (mtmp->wormno) {
  66. 		    register int cnt;
  67. 		    /* NOTE: worm is truncated to # segs = max wormno size */
  68. 		    cnt = count_wsegs(mtmp);
  69. 		    num_segs = min(cnt, MAX_NUM_WORMS - 1);
  70. 		    wormgone(mtmp);
  71. 		} else num_segs = 0;
  72.  
  73. 		/* set minvent's obj->no_charge to 0 */
  74. 		for(obj = mtmp->minvent; obj; obj = obj->nobj) {
  75. 		    if (Has_contents(obj))
  76. 			picked_container(obj);	/* does the right thing */
  77. 		    obj->no_charge = 0;
  78. 		}
  79.  
  80. 		relmon(mtmp);
  81. 		newsym(mtmp->mx,mtmp->my);
  82. 		mtmp->mx = mtmp->my = 0; /* avoid mnexto()/MON_AT() problem */
  83. 		mtmp->wormno = num_segs;
  84. 		mtmp->mlstmv = monstermoves;
  85. 		mtmp->nmon = mydogs;
  86. 		mydogs = mtmp;
  87. 	    } else if (mtmp->iswiz) {
  88. 		/* we want to be able to find him when his next resurrection
  89. 		   chance comes up, but have him resume his present location
  90. 		   if player returns to this level before that time */
  91. 		migrate_to_level(mtmp, ledger_no(&u.uz),
  92. 				 MIGR_EXACT_XY, (coord *)0);
  93. 	    } else if (mtmp->mleashed) {
  94. 		/* this can happen if your quest leader ejects you from the
  95. 		   "home" level while a leashed pet isn't next to you */
  96. 		pline("%s leash goes slack.", s_suffix(Monnam(mtmp)));
  97. 		m_unleash(mtmp, FALSE);
  98. 	    }
  99. 	}
  100. }
  101.  
  102. #endif /* OVL2 */

migrate_to_level[edit]

  1. #ifdef OVLB
  2.  
  3. void
  4. migrate_to_level(mtmp, tolev, xyloc, cc)
  5. 	register struct monst *mtmp;
  6. 	xchar tolev;	/* destination level */
  7. 	xchar xyloc;	/* MIGR_xxx destination xy location: */
  8. 	coord *cc;	/* optional destination coordinates */
  9. {
  10. 	register struct obj *obj;
  11. 	d_level new_lev;
  12. 	xchar xyflags;
  13. 	int num_segs = 0;	/* count of worm segments */
  14.  
  15. 	if (mtmp->isshk)
  16. 	    set_residency(mtmp, TRUE);
  17.  
  18. 	if (mtmp->wormno) {
  19. 	    register int cnt;
  20. 	  /* **** NOTE: worm is truncated to # segs = max wormno size **** */
  21. 	    cnt = count_wsegs(mtmp);
  22. 	    num_segs = min(cnt, MAX_NUM_WORMS - 1);
  23. 	    wormgone(mtmp);
  24. 	}
  25.  
  26. 	/* set minvent's obj->no_charge to 0 */
  27. 	for(obj = mtmp->minvent; obj; obj = obj->nobj) {
  28. 	    if (Has_contents(obj))
  29. 		picked_container(obj);	/* does the right thing */
  30. 	    obj->no_charge = 0;
  31. 	}
  32.  
  33. 	if (mtmp->mleashed) {
  34. 		mtmp->mtame--;
  35. 		m_unleash(mtmp, TRUE);
  36. 	}
  37. 	relmon(mtmp);
  38. 	mtmp->nmon = migrating_mons;
  39. 	migrating_mons = mtmp;
  40. 	newsym(mtmp->mx,mtmp->my);
  41.  
  42. 	new_lev.dnum = ledger_to_dnum((xchar)tolev);
  43. 	new_lev.dlevel = ledger_to_dlev((xchar)tolev);
  44. 	/* overload mtmp->[mx,my], mtmp->[mux,muy], and mtmp->mtrack[] as */
  45. 	/* destination codes (setup flag bits before altering mx or my) */
  46. 	xyflags = (depth(&new_lev) < depth(&u.uz));	/* 1 => up */
  47. 	if (In_W_tower(mtmp->mx, mtmp->my, &u.uz)) xyflags |= 2;
  48. 	mtmp->wormno = num_segs;
  49. 	mtmp->mlstmv = monstermoves;
  50. 	mtmp->mtrack[1].x = cc ? cc->x : mtmp->mx;
  51. 	mtmp->mtrack[1].y = cc ? cc->y : mtmp->my;
  52. 	mtmp->mtrack[0].x = xyloc;
  53. 	mtmp->mtrack[0].y = xyflags;
  54. 	mtmp->mux = new_lev.dnum;
  55. 	mtmp->muy = new_lev.dlevel;
  56. 	mtmp->mx = mtmp->my = 0;	/* this implies migration */
  57. }
  58.  
  59. #endif /* OVLB */

dogfood[edit]

  1. #ifdef OVL1
  2.  
  3. /* return quality of food; the lower the better */
  4. /* fungi will eat even tainted food */
  5. int
  6. dogfood(mon,obj)
  7. struct monst *mon;
  8. register struct obj *obj;
  9. {
  10. 	boolean carni = carnivorous(mon->data);
  11. 	boolean herbi = herbivorous(mon->data);
  12. 	struct permonst *fptr = &mons[obj->corpsenm];
  13. 	boolean starving;
  14.  
  15. 	if (is_quest_artifact(obj) || obj_resists(obj, 0, 95))
  16. 	    return (obj->cursed ? TABU : APPORT);
  17.  
  18. 	switch(obj->oclass) {
  19. 	case FOOD_CLASS:
  20. 	    if (obj->otyp == CORPSE &&
  21. 		((touch_petrifies(&mons[obj->corpsenm]) && !resists_ston(mon))
  22. 		 || is_rider(fptr)))
  23. 		    return TABU;
  24.  
  25. 	    /* Ghouls only eat old corpses... yum! */
  26. 	    if (mon->data == &mons[PM_GHOUL])
  27. 		return (obj->otyp == CORPSE &&
  28. 			peek_at_iced_corpse_age(obj) + 50L <= monstermoves) ?
  29. 				DOGFOOD : TABU;
  30.  
  31. 	    if (!carni && !herbi)
  32. 		    return (obj->cursed ? UNDEF : APPORT);
  33.  
  34. 	    /* a starving pet will eat almost anything */
  35. 	    starving = (mon->mtame && !mon->isminion &&
  36. 			EDOG(mon)->mhpmax_penalty);
  37.  
  38. 	    switch (obj->otyp) {
  39. 		case TRIPE_RATION:
  40. 		case MEATBALL:
  41. 		case MEAT_RING:
  42. 		case MEAT_STICK:
  43. 		case HUGE_CHUNK_OF_MEAT:
  44. 		    return (carni ? DOGFOOD : MANFOOD);
  45. 		case EGG:
  46. 		    if (touch_petrifies(&mons[obj->corpsenm]) && !resists_ston(mon))
  47. 			return POISON;
  48. 		    return (carni ? CADAVER : MANFOOD);
  49. 		case CORPSE:
  50. 		   if ((peek_at_iced_corpse_age(obj) + 50L <= monstermoves
  51. 					    && obj->corpsenm != PM_LIZARD
  52. 					    && obj->corpsenm != PM_LICHEN
  53. 					    && mon->data->mlet != S_FUNGUS) ||
  54. 			(acidic(&mons[obj->corpsenm]) && !resists_acid(mon)) ||
  55. 			(poisonous(&mons[obj->corpsenm]) &&
  56. 						!resists_poison(mon)))
  57. 			return POISON;
  58. 		    else if (vegan(fptr))
  59. 			return (herbi ? CADAVER : MANFOOD);
  60. 		    else return (carni ? CADAVER : MANFOOD);
  61. 		case CLOVE_OF_GARLIC:
  62. 		    return (is_undead(mon->data) ? TABU :
  63. 			    ((herbi || starving) ? ACCFOOD : MANFOOD));
  64. 		case TIN:
  65. 		    return (metallivorous(mon->data) ? ACCFOOD : MANFOOD);
  66. 		case APPLE:
  67. 		case CARROT:
  68. 		    return (herbi ? DOGFOOD : starving ? ACCFOOD : MANFOOD);
  69. 		case BANANA:
  70. 		    return ((mon->data->mlet == S_YETI) ? DOGFOOD :
  71. 			    ((herbi || starving) ? ACCFOOD : MANFOOD));
  72. 		default:
  73. 		    if (starving) return ACCFOOD;
  74. 		    return (obj->otyp > SLIME_MOLD ?
  75. 			    (carni ? ACCFOOD : MANFOOD) :
  76. 			    (herbi ? ACCFOOD : MANFOOD));
  77. 	    }
  78. 	default:
  79. 	    if (obj->otyp == AMULET_OF_STRANGULATION ||
  80. 			obj->otyp == RIN_SLOW_DIGESTION)
  81. 		return TABU;
  82. 	    if (hates_silver(mon->data) &&
  83. 		objects[obj->otyp].oc_material == SILVER)
  84. 		return(TABU);
  85. 	    if (mon->data == &mons[PM_GELATINOUS_CUBE] && is_organic(obj))
  86. 		return(ACCFOOD);
  87. 	    if (metallivorous(mon->data) && is_metallic(obj) && (is_rustprone(obj) || mon->data != &mons[PM_RUST_MONSTER])) {
  88. 		/* Non-rustproofed ferrous based metals are preferred. */
  89. 		return((is_rustprone(obj) && !obj->oerodeproof) ? DOGFOOD :
  90. 			ACCFOOD);
  91. 	    }
  92. 	    if(!obj->cursed && obj->oclass != BALL_CLASS &&
  93. 						obj->oclass != CHAIN_CLASS)
  94. 		return(APPORT);
  95. 	    /* fall into next case */
  96. 	case ROCK_CLASS:
  97. 	    return(UNDEF);
  98. 	}
  99. }
  100.  
  101. #endif /* OVL1 */

tamedog[edit]

  1. #ifdef OVLB
  2.  
  3. struct monst *
  4. tamedog(mtmp, obj)
  5. register struct monst *mtmp;
  6. register struct obj *obj;
  7. {
  8. 	register struct monst *mtmp2;
  9.  
  10. 	/* The Wiz, Medusa and the quest nemeses aren't even made peaceful. */
  11. 	if (mtmp->iswiz || mtmp->data == &mons[PM_MEDUSA]
  12. 				|| (mtmp->data->mflags3 & M3_WANTSARTI))
  13. 		return((struct monst *)0);
  14.  
  15. 	/* worst case, at least it'll be peaceful. */
  16. 	mtmp->mpeaceful = 1;
  17. 	set_malign(mtmp);
  18. 	if(flags.moonphase == FULL_MOON && night() && rn2(6) && obj
  19. 						&& mtmp->data->mlet == S_DOG)
  20. 		return((struct monst *)0);
  21.  
  22. 	/* If we cannot tame it, at least it's no longer afraid. */
  23. 	mtmp->mflee = 0;
  24. 	mtmp->mfleetim = 0;
  25.  
  26. 	/* make grabber let go now, whether it becomes tame or not */
  27. 	if (mtmp == u.ustuck) {
  28. 	    if (u.uswallow)
  29. 		expels(mtmp, mtmp->data, TRUE);
  30. 	    else if (!(Upolyd && sticks(youmonst.data)))
  31. 		unstuck(mtmp);
  32. 	}
  33.  
  34. 	/* feeding it treats makes it tamer */
  35. 	if (mtmp->mtame && obj) {
  36. 	    int tasty;
  37.  
  38. 	    if (mtmp->mcanmove && !mtmp->mconf && !mtmp->meating &&
  39. 		((tasty = dogfood(mtmp, obj)) == DOGFOOD ||
  40. 		 (tasty <= ACCFOOD && EDOG(mtmp)->hungrytime <= monstermoves))) {
  41. 		/* pet will "catch" and eat this thrown food */
  42. 		if (canseemon(mtmp)) {
  43. 		    boolean big_corpse = (obj->otyp == CORPSE &&
  44. 					  obj->corpsenm >= LOW_PM &&
  45. 				mons[obj->corpsenm].msize > mtmp->data->msize);
  46. 		    pline("%s catches %s%s",
  47. 			  Monnam(mtmp), the(xname(obj)),
  48. 			  !big_corpse ? "." : ", or vice versa!");
  49. 		} else if (cansee(mtmp->mx,mtmp->my))
  50. 		    pline("%s.", Tobjnam(obj, "stop"));
  51. 		/* dog_eat expects a floor object */
  52. 		place_object(obj, mtmp->mx, mtmp->my);
  53. 		(void) dog_eat(mtmp, obj, mtmp->mx, mtmp->my, FALSE);
  54. 		/* eating might have killed it, but that doesn't matter here;
  55. 		   a non-null result suppresses "miss" message for thrown
  56. 		   food and also implies that the object has been deleted */
  57. 		return mtmp;
  58. 	    } else
  59. 		return (struct monst *)0;
  60. 	}
  61.  
  62. 	if (mtmp->mtame || !mtmp->mcanmove ||
  63. 	    /* monsters with conflicting structures cannot be tamed */
  64. 	    mtmp->isshk || mtmp->isgd || mtmp->ispriest || mtmp->isminion ||
  65. 	    is_covetous(mtmp->data) || is_human(mtmp->data) ||
  66. 	    (is_demon(mtmp->data) && !is_demon(youmonst.data)) ||
  67. 	    (obj && dogfood(mtmp, obj) >= MANFOOD)) return (struct monst *)0;
  68.  
  69. 	if (mtmp->m_id == quest_status.leader_m_id)
  70. 	    return((struct monst *)0);
  71.  
  72. 	/* make a new monster which has the pet extension */
  73. 	mtmp2 = newmonst(sizeof(struct edog) + mtmp->mnamelth);
  74. 	*mtmp2 = *mtmp;
  75. 	mtmp2->mxlth = sizeof(struct edog);
  76. 	if (mtmp->mnamelth) Strcpy(NAME(mtmp2), NAME(mtmp));
  77. 	initedog(mtmp2);
  78. 	replmon(mtmp, mtmp2);
  79. 	/* `mtmp' is now obsolete */
  80.  
  81. 	if (obj) {		/* thrown food */
  82. 	    /* defer eating until the edog extension has been set up */
  83. 	    place_object(obj, mtmp2->mx, mtmp2->my);	/* put on floor */
  84. 	    /* devour the food (might grow into larger, genocided monster) */
  85. 	    if (dog_eat(mtmp2, obj, mtmp2->mx, mtmp2->my, TRUE) == 2)
  86. 		return mtmp2;		/* oops, it died... */
  87. 	    /* `obj' is now obsolete */
  88. 	}
  89.  
  90. 	newsym(mtmp2->mx, mtmp2->my);
  91. 	if (attacktype(mtmp2->data, AT_WEAP)) {
  92. 		mtmp2->weapon_check = NEED_HTH_WEAPON;
  93. 		(void) mon_wield_item(mtmp2);
  94. 	}
  95. 	return(mtmp2);
  96. }

wary_dog[edit]

  1. /*
  2. * Called during pet revival or pet life-saving.
  3. * If you killed the pet, it revives wild.
  4. * If you abused the pet a lot while alive, it revives wild.
  5. * If you abused the pet at all while alive, it revives untame.
  6. * If the pet wasn't abused and was very tame, it might revive tame.
  7. */
  8. void
  9. wary_dog(mtmp, was_dead)
  10. struct monst *mtmp;
  11. boolean was_dead;
  12. {
  13. struct edog *edog;
  14. boolean quietly = was_dead;
  15.  
  16. mtmp->meating = 0;
  17. if (!mtmp->mtame) return;
  18. edog = !mtmp->isminion ? EDOG(mtmp) : 0;
  19.  
  20. /* if monster was starving when it died, undo that now */
  21. if (edog && edog->mhpmax_penalty) {
  22. 	mtmp->mhpmax += edog->mhpmax_penalty;
  23. 	mtmp->mhp += edog->mhpmax_penalty;	/* heal it */
  24. 	edog->mhpmax_penalty = 0;
  25. }
  26.  
  27. if (edog && (edog->killed_by_u == 1 || edog->abuse > 2)) {
  28. 	mtmp->mpeaceful = mtmp->mtame = 0;
  29. 	if (edog->abuse >= 0 && edog->abuse < 10)
  30. 	    if (!rn2(edog->abuse + 1)) mtmp->mpeaceful = 1;
  31. 	if(!quietly && cansee(mtmp->mx, mtmp->my)) {
  32. 	    if (haseyes(youmonst.data)) {
  33. 		if (haseyes(mtmp->data))
  34. 			pline("%s %s to look you in the %s.",
  35. 				Monnam(mtmp),
  36. 				mtmp->mpeaceful ? "seems unable" :
  37. 					    "refuses",
  38. 				body_part(EYE));
  39. 		else 
  40. 			pline("%s avoids your gaze.",
  41. 				Monnam(mtmp));
  42. 	    }
  43. 	}
  44. } else {
  45. 	/* chance it goes wild anyway - Pet Semetary */
  46. 	if (!rn2(mtmp->mtame)) {
  47. 	    mtmp->mpeaceful = mtmp->mtame = 0;
  48. 	}
  49. }
  50. if (!mtmp->mtame) {
  51. 	newsym(mtmp->mx, mtmp->my);
  52. 	/* a life-saved monster might be leashed;
  53. 	   don't leave it that way if it's no longer tame */
  54. 	if (mtmp->mleashed) m_unleash(mtmp, TRUE);
  55. }
  56.  
  57. /* if its still a pet, start a clean pet-slate now */
  58. if (edog && mtmp->mtame) {
  59. 	edog->revivals++;
  60. 	edog->killed_by_u = 0;
  61. 	edog->abuse = 0;
  62. 	edog->ogoal.x = edog->ogoal.y = -1;
  63. 	if (was_dead || edog->hungrytime < monstermoves + 500L)
  64. 	    edog->hungrytime = monstermoves + 500L;
  65. 	if (was_dead) {
  66. 	    edog->droptime = 0L;
  67. 	    edog->dropdist = 10000;
  68. 	    edog->whistletime = 0L;
  69. 	    edog->apport = 5;
  70. 	} /* else lifesaved, so retain current values */
  71. }
  72. }

abuse_dog[edit]

  1. void
  2. abuse_dog(mtmp)
  3. struct monst *mtmp;
  4. {
  5. 	if (!mtmp->mtame) return;
  6.  
  7. 	if (Aggravate_monster || Conflict) mtmp->mtame /=2;
  8. 	else mtmp->mtame--;
  9.  
  10. 	if (mtmp->mtame && !mtmp->isminion)
  11. 	    EDOG(mtmp)->abuse++;
  12.  
  13. 	if (!mtmp->mtame && mtmp->mleashed)
  14. 	    m_unleash(mtmp, TRUE);
  15.  
  16. 	/* don't make a sound if pet is in the middle of leaving the level */
  17. 	/* newsym isn't necessary in this case either */
  18. 	if (mtmp->mx != 0) {
  19. 	    if (mtmp->mtame && rn2(mtmp->mtame)) yelp(mtmp);
  20. 	    else growl(mtmp);	/* give them a moment's worry */
  21.  
  22. 	    if (!mtmp->mtame) newsym(mtmp->mx, mtmp->my);
  23. 	}
  24. }
  25.  
  26. #endif /* OVLB */
  27.  
  28. /*dog.c*/