Source:NetHack 3.4.3/src/mon.c

From NetHackWiki
(Redirected from Source:Ref/can be hatched)
Jump to: navigation, search

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

Top of file[edit]

  1. /*	SCCS Id: @(#)mon.c	3.4	2003/12/04	*/
  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. /* If you're using precompiled headers, you don't want this either */
  2. #ifdef MICROPORT_BUG
  3. #define MKROOM_H
  4. #endif
  5.  
  6. #include "hack.h"
  7. #include "mfndpos.h"
  8. #include "edog.h"
  9. #include <ctype.h>
  10.  
  11. STATIC_DCL boolean FDECL(restrap,(struct monst *));
  12. STATIC_DCL long FDECL(mm_aggression, (struct monst *,struct monst *));
  13. #ifdef OVL2
  14. STATIC_DCL int NDECL(pick_animal);
  15. STATIC_DCL int FDECL(select_newcham_form, (struct monst *));
  16. STATIC_DCL void FDECL(kill_eggs, (struct obj *));
  17. #endif
  18.  
  19. #ifdef REINCARNATION
  20. #define LEVEL_SPECIFIC_NOCORPSE(mdat) \
  21. 	 (Is_rogue_level(&u.uz) || \
  22. 	   (level.flags.graveyard && is_undead(mdat) && rn2(3)))
  23. #else
  24. #define LEVEL_SPECIFIC_NOCORPSE(mdat) \
  25. 	   (level.flags.graveyard && is_undead(mdat) && rn2(3))
  26. #endif
  27.  
  28.  
  29. #if 0
  30. /* part of the original warning code which was replaced in 3.3.1 */
  31. #ifdef OVL1
  32. #define warnDelay 10
  33. long lastwarntime;
  34. int lastwarnlev;
  35.  
  36. const char *warnings[] = {
  37. 	"white", "pink", "red", "ruby", "purple", "black"
  38. };
  39.  
  40. STATIC_DCL void NDECL(warn_effects);
  41. #endif /* OVL1 */
  42. #endif /* 0 */
  43.  
  44. #ifndef OVLB
  45. STATIC_VAR short cham_to_pm[];
  46. #else
  47. STATIC_DCL struct obj *FDECL(make_corpse,(struct monst *));
  48. STATIC_DCL void FDECL(m_detach, (struct monst *, struct permonst *));
  49. STATIC_DCL void FDECL(lifesaved_monster, (struct monst *));

undead_to_corpse[edit]

  1. /* convert the monster index of an undead to its living counterpart */
  2. int
  3. undead_to_corpse(mndx)
  4. int mndx;
  5. {
  6. 	switch (mndx) {
  7. 	case PM_KOBOLD_ZOMBIE:
  8. 	case PM_KOBOLD_MUMMY:	mndx = PM_KOBOLD;  break;
  9. 	case PM_DWARF_ZOMBIE:
  10. 	case PM_DWARF_MUMMY:	mndx = PM_DWARF;  break;
  11. 	case PM_GNOME_ZOMBIE:
  12. 	case PM_GNOME_MUMMY:	mndx = PM_GNOME;  break;
  13. 	case PM_ORC_ZOMBIE:
  14. 	case PM_ORC_MUMMY:	mndx = PM_ORC;  break;
  15. 	case PM_ELF_ZOMBIE:
  16. 	case PM_ELF_MUMMY:	mndx = PM_ELF;  break;
  17. 	case PM_VAMPIRE:
  18. 	case PM_VAMPIRE_LORD:
  19. #if 0	/* DEFERRED */
  20. 	case PM_VAMPIRE_MAGE:
  21. #endif
  22. 	case PM_HUMAN_ZOMBIE:
  23. 	case PM_HUMAN_MUMMY:	mndx = PM_HUMAN;  break;
  24. 	case PM_GIANT_ZOMBIE:
  25. 	case PM_GIANT_MUMMY:	mndx = PM_GIANT;  break;
  26. 	case PM_ETTIN_ZOMBIE:
  27. 	case PM_ETTIN_MUMMY:	mndx = PM_ETTIN;  break;
  28. 	default:  break;
  29. 	}
  30. 	return mndx;
  31. }

genus[edit]

  1. /* Convert the monster index of some monsters (such as quest guardians)
  2. * to their generic species type.
  3. *
  4. * Return associated character class monster, rather than species
  5. * if mode is 1.
  6. */
  7. int
  8. genus(mndx, mode)
  9. int mndx, mode;
  10. {
  11. 	switch (mndx) {
  12. /* Quest guardians */
  13. 	case PM_STUDENT:     mndx = mode ? PM_ARCHEOLOGIST  : PM_HUMAN; break;
  14. 	case PM_CHIEFTAIN:   mndx = mode ? PM_BARBARIAN : PM_HUMAN; break;
  15. 	case PM_NEANDERTHAL: mndx = mode ? PM_CAVEMAN   : PM_HUMAN; break;
  16. 	case PM_ATTENDANT:   mndx = mode ? PM_HEALER    : PM_HUMAN; break;
  17. 	case PM_PAGE:        mndx = mode ? PM_KNIGHT    : PM_HUMAN; break;
  18. 	case PM_ABBOT:       mndx = mode ? PM_MONK      : PM_HUMAN; break;
  19. 	case PM_ACOLYTE:     mndx = mode ? PM_PRIEST    : PM_HUMAN; break;
  20. 	case PM_HUNTER:      mndx = mode ? PM_RANGER    : PM_HUMAN; break;
  21. 	case PM_THUG:        mndx = mode ? PM_ROGUE     : PM_HUMAN; break;
  22. 	case PM_ROSHI:       mndx = mode ? PM_SAMURAI   : PM_HUMAN; break;
  23. #ifdef TOURIST
  24. 	case PM_GUIDE:       mndx = mode ? PM_TOURIST   : PM_HUMAN; break;
  25. #endif
  26. 	case PM_APPRENTICE:  mndx = mode ? PM_WIZARD    : PM_HUMAN; break;
  27. 	case PM_WARRIOR:     mndx = mode ? PM_VALKYRIE  : PM_HUMAN; break;
  28. 	default:
  29. 		if (mndx >= LOW_PM && mndx < NUMMONS) {
  30. 			struct permonst *ptr = &mons[mndx];
  31. 			if (is_human(ptr))      mndx = PM_HUMAN;
  32. 			else if (is_elf(ptr))   mndx = PM_ELF;
  33. 			else if (is_dwarf(ptr)) mndx = PM_DWARF;
  34. 			else if (is_gnome(ptr)) mndx = PM_GNOME;
  35. 			else if (is_orc(ptr))   mndx = PM_ORC;
  36. 		}
  37. 		break;
  38. 	}
  39. 	return mndx;
  40. }

pm_to_cham[edit]

  1. /* convert monster index to chameleon index */
  2. int
  3. pm_to_cham(mndx)
  4. int mndx;
  5. {
  6. 	int mcham;
  7.  
  8. 	switch (mndx) {
  9. 	case PM_CHAMELEON:	mcham = CHAM_CHAMELEON; break;
  10. 	case PM_DOPPELGANGER:	mcham = CHAM_DOPPELGANGER; break;
  11. 	case PM_SANDESTIN:	mcham = CHAM_SANDESTIN; break;
  12. 	default: mcham = CHAM_ORDINARY; break;
  13. 	}
  14. 	return mcham;
  15. }
  16.  
  17. /* convert chameleon index to monster index */
  18. STATIC_VAR short cham_to_pm[] = {
  19. 		NON_PM,		/* placeholder for CHAM_ORDINARY */
  20. 		PM_CHAMELEON,
  21. 		PM_DOPPELGANGER,
  22. 		PM_SANDESTIN,
  23. };
  24.  
  25. /* for deciding whether corpse or statue will carry along full monster data */
  26. #define KEEPTRAITS(mon)	((mon)->isshk || (mon)->mtame ||		\
  27. 			 ((mon)->data->geno & G_UNIQ) ||		\
  28. 			 is_reviver((mon)->data) ||			\
  29. 			 /* normally leader the will be unique, */	\
  30. 			 /* but he might have been polymorphed  */	\
  31. 			 (mon)->m_id == quest_status.leader_m_id ||	\
  32. 			 /* special cancellation handling for these */	\
  33. 			 (dmgtype((mon)->data, AD_SEDU) ||		\
  34. 			  dmgtype((mon)->data, AD_SSEX)))

make_corpse[edit]

  1. /* Creates a monster corpse, a "special" corpse, or nothing if it doesn't
  2. * leave corpses.  Monsters which leave "special" corpses should have
  3. * G_NOCORPSE set in order to prevent wishing for one, finding tins of one,
  4. * etc....
  5. */
  6. STATIC_OVL struct obj *
  7. make_corpse(mtmp)
  8. register struct monst *mtmp;
  9. {
  10. 	register struct permonst *mdat = mtmp->data;
  11. 	int num;
  12. 	struct obj *obj = (struct obj *)0;
  13. 	int x = mtmp->mx, y = mtmp->my;
  14. 	int mndx = monsndx(mdat);
  15.  
  16. 	switch(mndx) {
  17. 	    case PM_GRAY_DRAGON:
  18. 	    case PM_SILVER_DRAGON:
  19. #if 0	/* DEFERRED */
  20. 	    case PM_SHIMMERING_DRAGON:
  21. #endif
  22. 	    case PM_RED_DRAGON:
  23. 	    case PM_ORANGE_DRAGON:
  24. 	    case PM_WHITE_DRAGON:
  25. 	    case PM_BLACK_DRAGON:
  26. 	    case PM_BLUE_DRAGON:
  27. 	    case PM_GREEN_DRAGON:
  28. 	    case PM_YELLOW_DRAGON:
  29. 		/* Make dragon scales.  This assumes that the order of the */
  30. 		/* dragons is the same as the order of the scales.	   */
  31. 		if (!rn2(mtmp->mrevived ? 20 : 3)) {
  32. 		    num = GRAY_DRAGON_SCALES + monsndx(mdat) - PM_GRAY_DRAGON;
  33. 		    obj = mksobj_at(num, x, y, FALSE, FALSE);
  34. 		    obj->spe = 0;
  35. 		    obj->cursed = obj->blessed = FALSE;
  36. 		}
  37. 		goto default_1;
  38.  
  39. 	    case PM_WHITE_UNICORN:
  40. 	    case PM_GRAY_UNICORN:
  41. 	    case PM_BLACK_UNICORN:
  42. 		if (mtmp->mrevived && rn2(20)) {
  43. 			if (canseemon(mtmp))
  44. 			   pline("%s recently regrown horn crumbles to dust.",
  45. 				s_suffix(Monnam(mtmp)));
  46. 		} else
  47. 			(void) mksobj_at(UNICORN_HORN, x, y, TRUE, FALSE);
  48. 		goto default_1;
  49. 	    case PM_LONG_WORM:
  50. 		(void) mksobj_at(WORM_TOOTH, x, y, TRUE, FALSE);
  51. 		goto default_1;
  52. 	    case PM_VAMPIRE:
  53. 	    case PM_VAMPIRE_LORD:
  54. 		/* include mtmp in the mkcorpstat() call */
  55. 		num = undead_to_corpse(mndx);
  56. 		obj = mkcorpstat(CORPSE, mtmp, &mons[num], x, y, TRUE);
  57. 		obj->age -= 100;		/* this is an *OLD* corpse */
  58. 		break;
  59. 	    case PM_KOBOLD_MUMMY:
  60. 	    case PM_DWARF_MUMMY:
  61. 	    case PM_GNOME_MUMMY:
  62. 	    case PM_ORC_MUMMY:
  63. 	    case PM_ELF_MUMMY:
  64. 	    case PM_HUMAN_MUMMY:
  65. 	    case PM_GIANT_MUMMY:
  66. 	    case PM_ETTIN_MUMMY:
  67. 	    case PM_KOBOLD_ZOMBIE:
  68. 	    case PM_DWARF_ZOMBIE:
  69. 	    case PM_GNOME_ZOMBIE:
  70. 	    case PM_ORC_ZOMBIE:
  71. 	    case PM_ELF_ZOMBIE:
  72. 	    case PM_HUMAN_ZOMBIE:
  73. 	    case PM_GIANT_ZOMBIE:
  74. 	    case PM_ETTIN_ZOMBIE:
  75. 		num = undead_to_corpse(mndx);
  76. 		obj = mkcorpstat(CORPSE, mtmp, &mons[num], x, y, TRUE);
  77. 		obj->age -= 100;		/* this is an *OLD* corpse */
  78. 		break;
  79. 	    case PM_IRON_GOLEM:
  80. 		num = d(2,6);
  81. 		while (num--)
  82. 			obj = mksobj_at(IRON_CHAIN, x, y, TRUE, FALSE);
  83. 		mtmp->mnamelth = 0;
  84. 		break;
  85. 	    case PM_GLASS_GOLEM:
  86. 		num = d(2,4);   /* very low chance of creating all glass gems */
  87. 		while (num--)
  88. 			obj = mksobj_at((LAST_GEM + rnd(9)), x, y, TRUE, FALSE);
  89. 		mtmp->mnamelth = 0;
  90. 		break;
  91. 	    case PM_CLAY_GOLEM:
  92. 		obj = mksobj_at(ROCK, x, y, FALSE, FALSE);
  93. 		obj->quan = (long)(rn2(20) + 50);
  94. 		obj->owt = weight(obj);
  95. 		mtmp->mnamelth = 0;
  96. 		break;
  97. 	    case PM_STONE_GOLEM:
  98. 		obj = mkcorpstat(STATUE, (struct monst *)0,
  99. 			mdat, x, y, FALSE);
  100. 		break;
  101. 	    case PM_WOOD_GOLEM:
  102. 		num = d(2,4);
  103. 		while(num--) {
  104. 			obj = mksobj_at(QUARTERSTAFF, x, y, TRUE, FALSE);
  105. 		}
  106. 		mtmp->mnamelth = 0;
  107. 		break;
  108. 	    case PM_LEATHER_GOLEM:
  109. 		num = d(2,4);
  110. 		while(num--)
  111. 			obj = mksobj_at(LEATHER_ARMOR, x, y, TRUE, FALSE);
  112. 		mtmp->mnamelth = 0;
  113. 		break;
  114. 	    case PM_GOLD_GOLEM:
  115. 		/* Good luck gives more coins */
  116. 		obj = mkgold((long)(200 - rnl(101)), x, y);
  117. 		mtmp->mnamelth = 0;
  118. 		break;
  119. 	    case PM_PAPER_GOLEM:
  120. 		num = rnd(4);
  121. 		while (num--)
  122. 			obj = mksobj_at(SCR_BLANK_PAPER, x, y, TRUE, FALSE);
  123. 		mtmp->mnamelth = 0;
  124. 		break;
  125. 	    default_1:
  126. 	    default:
  127. 		if (mvitals[mndx].mvflags & G_NOCORPSE)
  128. 		    return (struct obj *)0;
  129. 		else	/* preserve the unique traits of some creatures */
  130. 		    obj = mkcorpstat(CORPSE, KEEPTRAITS(mtmp) ? mtmp : 0,
  131. 				     mdat, x, y, TRUE);
  132. 		break;
  133. 	}
  134. 	/* All special cases should precede the G_NOCORPSE check */
  135.  
  136. 	/* if polymorph or undead turning has killed this monster,
  137. 	   prevent the same attack beam from hitting its corpse */
  138. 	if (flags.bypasses) bypass_obj(obj);
  139.  
  140. 	if (mtmp->mnamelth)
  141. 	    obj = oname(obj, NAME(mtmp));
  142.  
  143. 	/* Avoid "It was hidden under a green mold corpse!" 
  144. 	 *  during Blind combat. An unseen monster referred to as "it"
  145. 	 *  could be killed and leave a corpse.  If a hider then hid
  146. 	 *  underneath it, you could be told the corpse type of a
  147. 	 *  monster that you never knew was there without this.
  148. 	 *  The code in hitmu() substitutes the word "something"
  149. 	 *  if the corpses obj->dknown is 0.
  150. 	 */
  151. 	if (Blind && !sensemon(mtmp)) obj->dknown = 0;
  152.  
  153. #ifdef INVISIBLE_OBJECTS
  154. 	/* Invisible monster ==> invisible corpse */
  155. 	obj->oinvis = mtmp->minvis;
  156. #endif
  157.  
  158. 	stackobj(obj);
  159. 	newsym(x, y);
  160. 	return obj;
  161. }
  162.  
  163. #endif /* OVLB */
  164. #ifdef OVL1
  165.  
  166. #if 0

warn_effects[edit]

  1. /* part of the original warning code which was replaced in 3.3.1 */
  2. STATIC_OVL void
  3. warn_effects()
  4. {
  5. if (warnlevel == 100) {
  6. 	if(!Blind && uwep &&
  7. 	    (warnlevel > lastwarnlev || moves > lastwarntime + warnDelay)) {
  8. 	    Your("%s %s!", aobjnam(uwep, "glow"),
  9. 		hcolor(NH_LIGHT_BLUE));
  10. 	    lastwarnlev = warnlevel;
  11. 	    lastwarntime = moves;
  12. 	}
  13. 	warnlevel = 0;
  14. 	return;
  15. }
  16.  
  17. if (warnlevel >= SIZE(warnings))
  18. 	warnlevel = SIZE(warnings)-1;
  19. if (!Blind &&
  20. 	    (warnlevel > lastwarnlev || moves > lastwarntime + warnDelay)) {
  21. 	const char *which, *what, *how;
  22. 	long rings = (EWarning & (LEFT_RING|RIGHT_RING));
  23.  
  24. 	if (rings) {
  25. 	    what = Hallucination ? "mood ring" : "ring";
  26. 	    how = "glows";	/* singular verb */
  27. 	    if (rings == LEFT_RING) {
  28. 		which = "left ";
  29. 	    } else if (rings == RIGHT_RING) {
  30. 		which = "right ";
  31. 	    } else {		/* both */
  32. 		which = "";
  33. 		what = (const char *) makeplural(what);
  34. 		how = "glow";	/* plural verb */
  35. 	    }
  36. 	    Your("%s%s %s %s!", which, what, how, hcolor(warnings[warnlevel]));
  37. 	} else {
  38. 	    if (Hallucination)
  39. 		Your("spider-sense is tingling...");
  40. 	    else
  41. 		You_feel("apprehensive as you sense a %s flash.",
  42. 		    warnings[warnlevel]);
  43. 	}
  44.  
  45. 	lastwarntime = moves;
  46. 	lastwarnlev = warnlevel;
  47. }
  48. }
  49. #endif /* 0 */

minliquid[edit]

  1. /* check mtmp and water/lava for compatibility, 0 (survived), 1 (died) */
  2. int
  3. minliquid(mtmp)
  4. register struct monst *mtmp;
  5. {
  6. boolean inpool, inlava, infountain;
  7.  
  8. inpool = is_pool(mtmp->mx,mtmp->my) &&
  9. 	     !is_flyer(mtmp->data) && !is_floater(mtmp->data);
  10. inlava = is_lava(mtmp->mx,mtmp->my) &&
  11. 	     !is_flyer(mtmp->data) && !is_floater(mtmp->data);
  12. infountain = IS_FOUNTAIN(levl[mtmp->mx][mtmp->my].typ);
  13.  
  14. #ifdef STEED
  15. 	/* Flying and levitation keeps our steed out of the liquid */
  16. 	/* (but not water-walking or swimming) */
  17. 	if (mtmp == u.usteed && (Flying || Levitation))
  18. 		return (0);
  19. #endif
  20.  
  21. /* Gremlin multiplying won't go on forever since the hit points
  22. * keep going down, and when it gets to 1 hit point the clone
  23. * function will fail.
  24. */
  25. if (mtmp->data == &mons[PM_GREMLIN] && (inpool || infountain) && rn2(3)) {
  26. 	if (split_mon(mtmp, (struct monst *)0))
  27. 	    dryup(mtmp->mx, mtmp->my, FALSE);
  28. 	if (inpool) water_damage(mtmp->minvent, FALSE, FALSE);
  29. 	return (0);
  30. } else if (mtmp->data == &mons[PM_IRON_GOLEM] && inpool && !rn2(5)) {
  31. 	int dam = d(2,6);
  32. 	if (cansee(mtmp->mx,mtmp->my))
  33. 	    pline("%s rusts.", Monnam(mtmp));
  34. 	mtmp->mhp -= dam;
  35. 	if (mtmp->mhpmax > dam) mtmp->mhpmax -= dam;
  36. 	if (mtmp->mhp < 1) {
  37. 	    mondead(mtmp);
  38. 	    if (mtmp->mhp < 1) return (1);
  39. 	}
  40. 	water_damage(mtmp->minvent, FALSE, FALSE);
  41. 	return (0);
  42. }
  43.  
  44. if (inlava) {
  45. 	/*
  46. 	 * Lava effects much as water effects. Lava likers are able to
  47. 	 * protect their stuff. Fire resistant monsters can only protect
  48. 	 * themselves  --ALI
  49. 	 */
  50. 	if (!is_clinger(mtmp->data) && !likes_lava(mtmp->data)) {
  51. 	    if (!resists_fire(mtmp)) {
  52. 		if (cansee(mtmp->mx,mtmp->my))
  53. 		    pline("%s %s.", Monnam(mtmp),
  54. 			  mtmp->data == &mons[PM_WATER_ELEMENTAL] ?
  55. 			  "boils away" : "burns to a crisp");
  56. 		mondead(mtmp);
  57. 	    }
  58. 	    else {
  59. 		if (--mtmp->mhp < 1) {
  60. 		    if (cansee(mtmp->mx,mtmp->my))
  61. 			pline("%s surrenders to the fire.", Monnam(mtmp));
  62. 		    mondead(mtmp);
  63. 		}
  64. 		else if (cansee(mtmp->mx,mtmp->my))
  65. 		    pline("%s burns slightly.", Monnam(mtmp));
  66. 	    }
  67. 	    if (mtmp->mhp > 0) {
  68. 		(void) fire_damage(mtmp->minvent, FALSE, FALSE,
  69. 						mtmp->mx, mtmp->my);
  70. 		(void) rloc(mtmp, FALSE);
  71. 		return 0;
  72. 	    }
  73. 	    return (1);
  74. 	}
  75. } else if (inpool) {
  76. 	/* Most monsters drown in pools.  flooreffects() will take care of
  77. 	 * water damage to dead monsters' inventory, but survivors need to
  78. 	 * be handled here.  Swimmers are able to protect their stuff...
  79. 	 */
  80. 	if (!is_clinger(mtmp->data)
  81. 	    && !is_swimmer(mtmp->data) && !amphibious(mtmp->data)) {
  82. 	    if (cansee(mtmp->mx,mtmp->my)) {
  83. 		    pline("%s drowns.", Monnam(mtmp));
  84. 	    }
  85. 	    if (u.ustuck && u.uswallow && u.ustuck == mtmp) {
  86. 	    /* This can happen after a purple worm plucks you off a
  87. 		flying steed while you are over water. */
  88. 		pline("%s sinks as water rushes in and flushes you out.",
  89. 			Monnam(mtmp));
  90. 	    }
  91. 	    mondead(mtmp);
  92. 	    if (mtmp->mhp > 0) {
  93. 		(void) rloc(mtmp, FALSE);
  94. 		water_damage(mtmp->minvent, FALSE, FALSE);
  95. 		return 0;
  96. 	    }
  97. 	    return (1);
  98. 	}
  99. } else {
  100. 	/* but eels have a difficult time outside */
  101. 	if (mtmp->data->mlet == S_EEL && !Is_waterlevel(&u.uz)) {
  102. 	    if(mtmp->mhp > 1) mtmp->mhp--;
  103. 	    monflee(mtmp, 2, FALSE, FALSE);
  104. 	}
  105. }
  106. return (0);
  107. }

mcalcmove[edit]

  1. int
  2. mcalcmove(mon)
  3. struct monst *mon;
  4. {
  5. int mmove = mon->data->mmove;
  6.  
  7. /* Note: MSLOW's `+ 1' prevents slowed speed 1 getting reduced to 0;
  8. *	     MFAST's `+ 2' prevents hasted speed 1 from becoming a no-op;
  9. *	     both adjustments have negligible effect on higher speeds.
  10. */
  11. if (mon->mspeed == MSLOW)
  12. 	mmove = (2 * mmove + 1) / 3;
  13. else if (mon->mspeed == MFAST)
  14. 	mmove = (4 * mmove + 2) / 3;
  15.  
  16. #ifdef STEED
  17. if (mon == u.usteed) {
  18. 	if (u.ugallop && flags.mv) {
  19. 	    /* average movement is 1.50 times normal */
  20. 	    mmove = ((rn2(2) ? 4 : 5) * mmove) / 3;
  21. 	}
  22. }
  23. #endif
  24.  
  25. return mmove;
  26. }

mcalcdistress[edit]

  1. /* actions that happen once per ``turn'', regardless of each
  2. individual monster's metabolism; some of these might need to
  3. be reclassified to occur more in proportion with movement rate */
  4. void
  5. mcalcdistress()
  6. {
  7. struct monst *mtmp;
  8.  
  9. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  10. 	if (DEADMONSTER(mtmp)) continue;
  11.  
  12. 	/* must check non-moving monsters once/turn in case
  13. 	 * they managed to end up in liquid */
  14. 	if (mtmp->data->mmove == 0) {
  15. 	    if (vision_full_recalc) vision_recalc(0);
  16. 	    if (minliquid(mtmp)) continue;
  17. 	}
  18.  
  19. 	/* regenerate hit points */
  20. 	mon_regen(mtmp, FALSE);
  21.  
  22. 	/* possibly polymorph shapechangers and lycanthropes */
  23. 	if (mtmp->cham && !rn2(6))
  24. 	    (void) newcham(mtmp, (struct permonst *)0, FALSE, FALSE);
  25. 	were_change(mtmp);
  26.  
  27. 	/* gradually time out temporary problems */
  28. 	if (mtmp->mblinded && !--mtmp->mblinded)
  29. 	    mtmp->mcansee = 1;
  30. 	if (mtmp->mfrozen && !--mtmp->mfrozen)
  31. 	    mtmp->mcanmove = 1;
  32. 	if (mtmp->mfleetim && !--mtmp->mfleetim)
  33. 	    mtmp->mflee = 0;
  34.  
  35. 	/* FIXME: mtmp->mlstmv ought to be updated here */
  36. }
  37. }

movemon[edit]

  1. int
  2. movemon()
  3. {
  4. register struct monst *mtmp, *nmtmp;
  5. register boolean somebody_can_move = FALSE;
  6. #if 0
  7. /* part of the original warning code which was replaced in 3.3.1 */
  8. warnlevel = 0;
  9. #endif
  10.  
  11. /*
  12. Some of you may remember the former assertion here that
  13. because of deaths and other actions, a simple one-pass
  14. algorithm wasn't possible for movemon.  Deaths are no longer
  15. removed to the separate list fdmon; they are simply left in
  16. the chain with hit points <= 0, to be cleaned up at the end
  17. of the pass.
  18.  
  19. The only other actions which cause monsters to be removed from
  20. the chain are level migrations and losedogs().  I believe losedogs()
  21. is a cleanup routine not associated with monster movements, and
  22. monsters can only affect level migrations on themselves, not others
  23. (hence the fetching of nmon before moving the monster).  Currently,
  24. monsters can jump into traps, read cursed scrolls of teleportation,
  25. and drink cursed potions of raise level to change levels.  These are
  26. all reflexive at this point.  Should one monster be able to level
  27. teleport another, this scheme would have problems.
  28. */
  29.  
  30. for(mtmp = fmon; mtmp; mtmp = nmtmp) {
  31. 	nmtmp = mtmp->nmon;
  32.  
  33. 	/* Find a monster that we have not treated yet.	 */
  34. 	if(DEADMONSTER(mtmp))
  35. 	    continue;
  36. 	if(mtmp->movement < NORMAL_SPEED)
  37. 	    continue;
  38.  
  39. 	mtmp->movement -= NORMAL_SPEED;
  40. 	if (mtmp->movement >= NORMAL_SPEED)
  41. 	    somebody_can_move = TRUE;
  42.  
  43. 	if (vision_full_recalc) vision_recalc(0);	/* vision! */
  44.  
  45. 	if (minliquid(mtmp)) continue;
  46.  
  47. 	if (is_hider(mtmp->data)) {
  48. 	    /* unwatched mimics and piercers may hide again  [MRS] */
  49. 	    if(restrap(mtmp))   continue;
  50. 	    if(mtmp->m_ap_type == M_AP_FURNITURE ||
  51. 				mtmp->m_ap_type == M_AP_OBJECT)
  52. 		    continue;
  53. 	    if(mtmp->mundetected) continue;
  54. 	}
  55.  
  56. 	/* continue if the monster died fighting */
  57. 	if (Conflict && !mtmp->iswiz && mtmp->mcansee) {
  58. 	    /* Note:
  59. 	     *  Conflict does not take effect in the first round.
  60. 	     *  Therefore, A monster when stepping into the area will
  61. 	     *  get to swing at you.
  62. 	     *
  63. 	     *  The call to fightm() must be _last_.  The monster might
  64. 	     *  have died if it returns 1.
  65. 	     */
  66. 	    if (couldsee(mtmp->mx,mtmp->my) &&
  67. 		(distu(mtmp->mx,mtmp->my) <= BOLT_LIM*BOLT_LIM) &&
  68. 							fightm(mtmp))
  69. 		continue;	/* mon might have died */
  70. 	}
  71. 	if(dochugw(mtmp))		/* otherwise just move the monster */
  72. 	    continue;
  73. }
  74. #if 0
  75. /* part of the original warning code which was replaced in 3.3.1 */
  76. if(warnlevel > 0)
  77. 	warn_effects();
  78. #endif
  79.  
  80. if (any_light_source())
  81. 	vision_full_recalc = 1;	/* in case a mon moved with a light source */
  82. dmonsfree();	/* remove all dead monsters */
  83.  
  84. /* a monster may have levteleported player -dlc */
  85. if (u.utotype) {
  86. 	deferred_goto();
  87. 	/* changed levels, so these monsters are dormant */
  88. 	somebody_can_move = FALSE;
  89. }
  90.  
  91. return somebody_can_move;
  92. }
  93.  
  94. #endif /* OVL1 */
  95. #ifdef OVLB
  96.  
  97. #define mstoning(obj)	(ofood(obj) && \
  98. 					(touch_petrifies(&mons[(obj)->corpsenm]) || \
  99. 					(obj)->corpsenm == PM_MEDUSA))

meatmetal[edit]

  1. /*
  2. * Maybe eat a metallic object (not just gold).
  3. * Return value: 0 => nothing happened, 1 => monster ate something,
  4. * 2 => monster died (it must have grown into a genocided form, but
  5. * that can't happen at present because nothing which eats objects
  6. * has young and old forms).
  7. */
  8. int
  9. meatmetal(mtmp)
  10. 	register struct monst *mtmp;
  11. {
  12. 	register struct obj *otmp;
  13. 	struct permonst *ptr;
  14. 	int poly, grow, heal, mstone;
  15.  
  16. 	/* If a pet, eating is handled separately, in dog.c */
  17. 	if (mtmp->mtame) return 0;
  18.  
  19. 	/* Eats topmost metal object if it is there */
  20. 	for (otmp = level.objects[mtmp->mx][mtmp->my];
  21. 						otmp; otmp = otmp->nexthere) {
  22. 	    if (mtmp->data == &mons[PM_RUST_MONSTER] && !is_rustprone(otmp))
  23. 		continue;
  24. 	    if (is_metallic(otmp) && !obj_resists(otmp, 5, 95) &&
  25. 		touch_artifact(otmp,mtmp)) {
  26. 		if (mtmp->data == &mons[PM_RUST_MONSTER] && otmp->oerodeproof) {
  27. 		    if (canseemon(mtmp) && flags.verbose) {
  28. 			pline("%s eats %s!",
  29. 				Monnam(mtmp),
  30. 				distant_name(otmp,doname));
  31. 		    }
  32. 		    /* The object's rustproofing is gone now */
  33. 		    otmp->oerodeproof = 0;
  34. 		    mtmp->mstun = 1;
  35. 		    if (canseemon(mtmp) && flags.verbose) {
  36. 			pline("%s spits %s out in disgust!",
  37. 			      Monnam(mtmp), distant_name(otmp,doname));
  38. 		    }
  39. 		/* KMH -- Don't eat indigestible/choking objects */
  40. 		} else if (otmp->otyp != AMULET_OF_STRANGULATION &&
  41. 				otmp->otyp != RIN_SLOW_DIGESTION) {
  42. 		    if (cansee(mtmp->mx,mtmp->my) && flags.verbose)
  43. 			pline("%s eats %s!", Monnam(mtmp),
  44. 				distant_name(otmp,doname));
  45. 		    else if (flags.soundok && flags.verbose)
  46. 			You_hear("a crunching sound.");
  47. 		    mtmp->meating = otmp->owt/2 + 1;
  48. 		    /* Heal up to the object's weight in hp */
  49. 		    if (mtmp->mhp < mtmp->mhpmax) {
  50. 			mtmp->mhp += objects[otmp->otyp].oc_weight;
  51. 			if (mtmp->mhp > mtmp->mhpmax) mtmp->mhp = mtmp->mhpmax;
  52. 		    }
  53. 		    if(otmp == uball) {
  54. 			unpunish();
  55. 			delobj(otmp);
  56. 		    } else if (otmp == uchain) {
  57. 			unpunish();	/* frees uchain */
  58. 		    } else {
  59. 			poly = polyfodder(otmp);
  60. 			grow = mlevelgain(otmp);
  61. 			heal = mhealup(otmp);
  62. 			mstone = mstoning(otmp);
  63. 			delobj(otmp);
  64. 			ptr = mtmp->data;
  65. 			if (poly) {
  66. 			    if (newcham(mtmp, (struct permonst *)0,
  67. 					FALSE, FALSE))
  68. 				ptr = mtmp->data;
  69. 			} else if (grow) {
  70. 			    ptr = grow_up(mtmp, (struct monst *)0);
  71. 			} else if (mstone) {
  72. 			    if (poly_when_stoned(ptr)) {
  73. 				mon_to_stone(mtmp);
  74. 				ptr = mtmp->data;
  75. 			    } else if (!resists_ston(mtmp)) {
  76. 				if (canseemon(mtmp))
  77. 				    pline("%s turns to stone!", Monnam(mtmp));
  78. 				monstone(mtmp);
  79. 				ptr = (struct permonst *)0;
  80. 			    }
  81. 			} else if (heal) {
  82. 			    mtmp->mhp = mtmp->mhpmax;
  83. 			}
  84. 			if (!ptr) return 2;		 /* it died */
  85. 		    }
  86. 		    /* Left behind a pile? */
  87. 		    if (rnd(25) < 3)
  88. 			(void)mksobj_at(ROCK, mtmp->mx, mtmp->my, TRUE, FALSE);
  89. 		    newsym(mtmp->mx, mtmp->my);
  90. 		    return 1;
  91. 		}
  92. 	    }
  93. 	}
  94. 	return 0;
  95. }

meatobj[edit]

  1. int
  2. meatobj(mtmp)		/* for gelatinous cubes */
  3. 	register struct monst *mtmp;
  4. {
  5. 	register struct obj *otmp, *otmp2;
  6. 	struct permonst *ptr;
  7. 	int poly, grow, heal, count = 0, ecount = 0;
  8. 	char buf[BUFSZ];
  9.  
  10. 	buf[0] = '\0';
  11. 	/* If a pet, eating is handled separately, in dog.c */
  12. 	if (mtmp->mtame) return 0;
  13.  
  14. 	/* Eats organic objects, including cloth and wood, if there */
  15. 	/* Engulfs others, except huge rocks and metal attached to player */
  16. 	for (otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) {
  17. 	    otmp2 = otmp->nexthere;
  18. 	    if (is_organic(otmp) && !obj_resists(otmp, 5, 95) &&
  19. 		    touch_artifact(otmp,mtmp)) {
  20. 		if (otmp->otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm]) &&
  21. 			!resists_ston(mtmp))
  22. 		    continue;
  23. 		if (otmp->otyp == AMULET_OF_STRANGULATION ||
  24. 				otmp->otyp == RIN_SLOW_DIGESTION)
  25. 		    continue;
  26. 		++count;
  27. 		if (cansee(mtmp->mx,mtmp->my) && flags.verbose)
  28. 		    pline("%s eats %s!", Monnam(mtmp),
  29. 			    distant_name(otmp, doname));
  30. 		else if (flags.soundok && flags.verbose)
  31. 		    You_hear("a slurping sound.");
  32. 		/* Heal up to the object's weight in hp */
  33. 		if (mtmp->mhp < mtmp->mhpmax) {
  34. 		    mtmp->mhp += objects[otmp->otyp].oc_weight;
  35. 		    if (mtmp->mhp > mtmp->mhpmax) mtmp->mhp = mtmp->mhpmax;
  36. 		}
  37. 		if (Has_contents(otmp)) {
  38. 		    register struct obj *otmp3;
  39. 		    /* contents of eaten containers become engulfed; this
  40. 		       is arbitrary, but otherwise g.cubes are too powerful */
  41. 		    while ((otmp3 = otmp->cobj) != 0) {
  42. 			obj_extract_self(otmp3);
  43. 			if (otmp->otyp == ICE_BOX && otmp3->otyp == CORPSE) {
  44. 			    otmp3->age = monstermoves - otmp3->age;
  45. 			    start_corpse_timeout(otmp3);
  46. 			}
  47. 			(void) mpickobj(mtmp, otmp3);
  48. 		    }
  49. 		}
  50. 		poly = polyfodder(otmp);
  51. 		grow = mlevelgain(otmp);
  52. 		heal = mhealup(otmp);
  53. 		delobj(otmp);		/* munch */
  54. 		ptr = mtmp->data;
  55. 		if (poly) {
  56. 		    if (newcham(mtmp, (struct permonst *)0, FALSE, FALSE))
  57. 			ptr = mtmp->data;
  58. 		} else if (grow) {
  59. 		    ptr = grow_up(mtmp, (struct monst *)0);
  60. 		} else if (heal) {
  61. 		    mtmp->mhp = mtmp->mhpmax;
  62. 		}
  63. 		/* in case it polymorphed or died */
  64. 		if (ptr != &mons[PM_GELATINOUS_CUBE])
  65. 		    return !ptr ? 2 : 1;
  66. 	    } else if (otmp->oclass != ROCK_CLASS &&
  67. 				    otmp != uball && otmp != uchain) {
  68. 		++ecount;
  69. 		if (ecount == 1) {
  70. 			Sprintf(buf, "%s engulfs %s.", Monnam(mtmp),
  71. 			    distant_name(otmp,doname));
  72. 		} else if (ecount == 2)
  73. 			Sprintf(buf, "%s engulfs several objects.", Monnam(mtmp));
  74. 		obj_extract_self(otmp);
  75. 		(void) mpickobj(mtmp, otmp);	/* slurp */
  76. 	    }
  77. 	    /* Engulf & devour is instant, so don't set meating */
  78. 	    if (mtmp->minvis) newsym(mtmp->mx, mtmp->my);
  79. 	}
  80. 	if (ecount > 0) {
  81. 	    if (cansee(mtmp->mx, mtmp->my) && flags.verbose && buf[0])
  82. 		pline("%s", buf);
  83. 	    else if (flags.soundok && flags.verbose)
  84. 	    	You_hear("%s slurping sound%s.",
  85. 			ecount == 1 ? "a" : "several",
  86. 			ecount == 1 ? "" : "s");
  87. 	}
  88. 	return ((count > 0) || (ecount > 0)) ? 1 : 0;
  89. }

mpickgold[edit]

  1. void
  2. mpickgold(mtmp)
  3. 	register struct monst *mtmp;
  4. {
  5. register struct obj *gold;
  6. int mat_idx;
  7.  
  8. if ((gold = g_at(mtmp->mx, mtmp->my)) != 0) {
  9. 	mat_idx = objects[gold->otyp].oc_material;
  10. #ifndef GOLDOBJ
  11. 	mtmp->mgold += gold->quan;
  12. 	delobj(gold);
  13. #else
  14. obj_extract_self(gold);
  15. add_to_minv(mtmp, gold);
  16. #endif
  17. 	if (cansee(mtmp->mx, mtmp->my) ) {
  18. 	    if (flags.verbose && !mtmp->isgd)
  19. 		pline("%s picks up some %s.", Monnam(mtmp),
  20. 			mat_idx == GOLD ? "gold" : "money");
  21. 	    newsym(mtmp->mx, mtmp->my);
  22. 	}
  23. }
  24. }
  25. #endif /* OVLB */
  26. #ifdef OVL2

mpickstuff[edit]

  1. boolean
  2. mpickstuff(mtmp, str)
  3. 	register struct monst *mtmp;
  4. 	register const char *str;
  5. {
  6. 	register struct obj *otmp, *otmp2;
  7.  
  8. /*	prevent shopkeepers from leaving the door of their shop */
  9. 	if(mtmp->isshk && inhishop(mtmp)) return FALSE;
  10.  
  11. 	for(otmp = level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) {
  12. 	    otmp2 = otmp->nexthere;
  13. /*	Nymphs take everything.  Most monsters don't pick up corpses. */
  14. 	    if (!str ? searches_for_item(mtmp,otmp) :
  15. 		  !!(index(str, otmp->oclass))) {
  16. 		if (otmp->otyp == CORPSE && mtmp->data->mlet != S_NYMPH &&
  17. 			/* let a handful of corpse types thru to can_carry() */
  18. 			!touch_petrifies(&mons[otmp->corpsenm]) &&
  19. 			otmp->corpsenm != PM_LIZARD &&
  20. 			!acidic(&mons[otmp->corpsenm])) continue;
  21. 		if (!touch_artifact(otmp,mtmp)) continue;
  22. 		if (!can_carry(mtmp,otmp)) continue;
  23. 		if (is_pool(mtmp->mx,mtmp->my)) continue;
  24. #ifdef INVISIBLE_OBJECTS
  25. 		if (otmp->oinvis && !perceives(mtmp->data)) continue;
  26. #endif
  27. 		if (cansee(mtmp->mx,mtmp->my) && flags.verbose)
  28. 			pline("%s picks up %s.", Monnam(mtmp),
  29. 			      (distu(mtmp->mx, mtmp->my) <= 5) ?
  30. 				doname(otmp) : distant_name(otmp, doname));
  31. 		obj_extract_self(otmp);
  32. 		/* unblock point after extract, before pickup */
  33. 		if (otmp->otyp == BOULDER)
  34. 		    unblock_point(otmp->ox,otmp->oy);	/* vision */
  35. 		(void) mpickobj(mtmp, otmp);	/* may merge and free otmp */
  36. 		m_dowear(mtmp, FALSE);
  37. 		newsym(mtmp->mx, mtmp->my);
  38. 		return TRUE;			/* pick only one object */
  39. 	    }
  40. 	}
  41. 	return FALSE;
  42. }
  43.  
  44. #endif /* OVL2 */
  45. #ifdef OVL0

curr_mon_load[edit]

  1. int
  2. curr_mon_load(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	register int curload = 0;
  6. 	register struct obj *obj;
  7.  
  8. 	for(obj = mtmp->minvent; obj; obj = obj->nobj) {
  9. 		if(obj->otyp != BOULDER || !throws_rocks(mtmp->data))
  10. 			curload += obj->owt;
  11. 	}
  12.  
  13. 	return curload;
  14. }

max_mon_load[edit]

  1. int
  2. max_mon_load(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	register long maxload;
  6.  
  7. 	/* Base monster carrying capacity is equal to human maximum
  8. 	 * carrying capacity, or half human maximum if not strong.
  9. 	 * (for a polymorphed player, the value used would be the
  10. 	 * non-polymorphed carrying capacity instead of max/half max).
  11. 	 * This is then modified by the ratio between the monster weights
  12. 	 * and human weights.  Corpseless monsters are given a capacity
  13. 	 * proportional to their size instead of weight.
  14. 	 */
  15. 	if (!mtmp->data->cwt)
  16. 		maxload = (MAX_CARR_CAP * (long)mtmp->data->msize) / MZ_HUMAN;
  17. 	else if (!strongmonst(mtmp->data)
  18. 		|| (strongmonst(mtmp->data) && (mtmp->data->cwt > WT_HUMAN)))
  19. 		maxload = (MAX_CARR_CAP * (long)mtmp->data->cwt) / WT_HUMAN;
  20. 	else	maxload = MAX_CARR_CAP; /*strong monsters w/cwt <= WT_HUMAN*/
  21.  
  22. 	if (!strongmonst(mtmp->data)) maxload /= 2;
  23.  
  24. 	if (maxload < 1) maxload = 1;
  25.  
  26. 	return (int) maxload;
  27. }

can_carry[edit]

  1. /* for restricting monsters' object-pickup */
  2. boolean
  3. can_carry(mtmp,otmp)
  4. struct monst *mtmp;
  5. struct obj *otmp;
  6. {
  7. 	int otyp = otmp->otyp, newload = otmp->owt;
  8. 	struct permonst *mdat = mtmp->data;
  9.  
  10. 	if (notake(mdat)) return FALSE;		/* can't carry anything */
  11.  
  12. 	if (otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm]) &&
  13. 		!(mtmp->misc_worn_check & W_ARMG) && !resists_ston(mtmp))
  14. 	    return FALSE;
  15. 	if (otyp == CORPSE && is_rider(&mons[otmp->corpsenm]))
  16. 	    return FALSE;
  17. 	if (objects[otyp].oc_material == SILVER && hates_silver(mdat) &&
  18. 		(otyp != BELL_OF_OPENING || !is_covetous(mdat)))
  19. 	    return FALSE;
  20.  
  21. #ifdef STEED
  22. 	/* Steeds don't pick up stuff (to avoid shop abuse) */
  23. 	if (mtmp == u.usteed) return (FALSE);
  24. #endif
  25. 	if (mtmp->isshk) return(TRUE); /* no limit */
  26. 	if (mtmp->mpeaceful && !mtmp->mtame) return(FALSE);
  27. 	/* otherwise players might find themselves obligated to violate
  28. 	 * their alignment if the monster takes something they need
  29. 	 */
  30.  
  31. 	/* special--boulder throwers carry unlimited amounts of boulders */
  32. 	if (throws_rocks(mdat) && otyp == BOULDER)
  33. 		return(TRUE);
  34.  
  35. 	/* nymphs deal in stolen merchandise, but not boulders or statues */
  36. 	if (mdat->mlet == S_NYMPH)
  37. 		return (boolean)(otmp->oclass != ROCK_CLASS);
  38.  
  39. 	if (curr_mon_load(mtmp) + newload > max_mon_load(mtmp)) return FALSE;
  40.  
  41. 	return(TRUE);
  42. }

mfndpos[edit]

  1. /* return number of acceptable neighbour positions */
  2. int
  3. mfndpos(mon, poss, info, flag)
  4. 	register struct monst *mon;
  5. 	coord *poss;	/* coord poss[9] */
  6. 	long *info;	/* long info[9] */
  7. 	long flag;
  8. {
  9. 	struct permonst *mdat = mon->data;
  10. 	register xchar x,y,nx,ny;
  11. 	register int cnt = 0;
  12. 	register uchar ntyp;
  13. 	uchar nowtyp;
  14. 	boolean wantpool,poolok,lavaok,nodiag;
  15. 	boolean rockok = FALSE, treeok = FALSE, thrudoor;
  16. 	int maxx, maxy;
  17.  
  18. 	x = mon->mx;
  19. 	y = mon->my;
  20. 	nowtyp = levl[x][y].typ;
  21.  
  22. 	nodiag = (mdat == &mons[PM_GRID_BUG]);
  23. 	wantpool = mdat->mlet == S_EEL;
  24. 	poolok = is_flyer(mdat) || is_clinger(mdat) ||
  25. 		 (is_swimmer(mdat) && !wantpool);
  26. 	lavaok = is_flyer(mdat) || is_clinger(mdat) || likes_lava(mdat);
  27. 	thrudoor = ((flag & (ALLOW_WALL|BUSTDOOR)) != 0L);
  28. 	if (flag & ALLOW_DIG) {
  29. 	    struct obj *mw_tmp;
  30.  
  31. 	    /* need to be specific about what can currently be dug */
  32. 	    if (!needspick(mdat)) {
  33. 		rockok = treeok = TRUE;
  34. 	    } else if ((mw_tmp = MON_WEP(mon)) && mw_tmp->cursed &&
  35. 		       mon->weapon_check == NO_WEAPON_WANTED) {
  36. 		rockok = is_pick(mw_tmp);
  37. 		treeok = is_axe(mw_tmp);
  38. 	    } else {
  39. 		rockok = (m_carrying(mon, PICK_AXE) ||
  40. 			  (m_carrying(mon, DWARVISH_MATTOCK) &&
  41. 			   !which_armor(mon, W_ARMS)));
  42. 		treeok = (m_carrying(mon, AXE) ||
  43. 			  (m_carrying(mon, BATTLE_AXE) &&
  44. 			   !which_armor(mon, W_ARMS)));
  45. 	    }
  46. 	    thrudoor |= rockok || treeok;
  47. 	}
  48.  
  49. nexttry:	/* eels prefer the water, but if there is no water nearby,
  50. 		   they will crawl over land */
  51. 	if(mon->mconf) {
  52. 		flag |= ALLOW_ALL;
  53. 		flag &= ~NOTONL;
  54. 	}
  55. 	if(!mon->mcansee)
  56. 		flag |= ALLOW_SSM;
  57. 	maxx = min(x+1,COLNO-1);
  58. 	maxy = min(y+1,ROWNO-1);
  59. 	for(nx = max(1,x-1); nx <= maxx; nx++)
  60. 	  for(ny = max(0,y-1); ny <= maxy; ny++) {
  61. 	    if(nx == x && ny == y) continue;
  62. 	    if(IS_ROCK(ntyp = levl[nx][ny].typ) &&
  63. 	       !((flag & ALLOW_WALL) && may_passwall(nx,ny)) &&
  64. 	       !((IS_TREE(ntyp) ? treeok : rockok) && may_dig(nx,ny))) continue;
  65. 	    /* KMH -- Added iron bars */
  66. 	    if (ntyp == IRONBARS && !(flag & ALLOW_BARS)) continue;
  67. 	    if(IS_DOOR(ntyp) && !amorphous(mdat) &&
  68. 	       ((levl[nx][ny].doormask & D_CLOSED && !(flag & OPENDOOR)) ||
  69. 		(levl[nx][ny].doormask & D_LOCKED && !(flag & UNLOCKDOOR))) &&
  70. 	       !thrudoor) continue;
  71. 	    if(nx != x && ny != y && (nodiag ||
  72. #ifdef REINCARNATION
  73. 	       ((IS_DOOR(nowtyp) &&
  74. 		 ((levl[x][y].doormask & ~D_BROKEN) || Is_rogue_level(&u.uz))) ||
  75. 		(IS_DOOR(ntyp) &&
  76. 		 ((levl[nx][ny].doormask & ~D_BROKEN) || Is_rogue_level(&u.uz))))
  77. #else
  78. 	       ((IS_DOOR(nowtyp) && (levl[x][y].doormask & ~D_BROKEN)) ||
  79. 		(IS_DOOR(ntyp) && (levl[nx][ny].doormask & ~D_BROKEN)))
  80. #endif
  81. 	       ))
  82. 		continue;
  83. 	    if((is_pool(nx,ny) == wantpool || poolok) &&
  84. 	       (lavaok || !is_lava(nx,ny))) {
  85. 		int dispx, dispy;
  86. 		boolean monseeu = (mon->mcansee && (!Invis || perceives(mdat)));
  87. 		boolean checkobj = OBJ_AT(nx,ny);
  88.  
  89. 		/* Displacement also displaces the Elbereth/scare monster,
  90. 		 * as long as you are visible.
  91. 		 */
  92. 		if(Displaced && monseeu && (mon->mux==nx) && (mon->muy==ny)) {
  93. 		    dispx = u.ux;
  94. 		    dispy = u.uy;
  95. 		} else {
  96. 		    dispx = nx;
  97. 		    dispy = ny;
  98. 		}
  99.  
  100. 		info[cnt] = 0;
  101. 		if ((checkobj || Displaced) && onscary(dispx, dispy, mon)) {
  102. 		    if(!(flag & ALLOW_SSM)) continue;
  103. 		    info[cnt] |= ALLOW_SSM;
  104. 		}
  105. 		if((nx == u.ux && ny == u.uy) ||
  106. 		   (nx == mon->mux && ny == mon->muy)) {
  107. 			if (nx == u.ux && ny == u.uy) {
  108. 				/* If it's right next to you, it found you,
  109. 				 * displaced or no.  We must set mux and muy
  110. 				 * right now, so when we return we can tell
  111. 				 * that the ALLOW_U means to attack _you_ and
  112. 				 * not the image.
  113. 				 */
  114. 				mon->mux = u.ux;
  115. 				mon->muy = u.uy;
  116. 			}
  117. 			if(!(flag & ALLOW_U)) continue;
  118. 			info[cnt] |= ALLOW_U;
  119. 		} else {
  120. 			if(MON_AT(nx, ny)) {
  121. 				struct monst *mtmp2 = m_at(nx, ny);
  122. 				long mmflag = flag | mm_aggression(mon, mtmp2);
  123.  
  124. 				if (!(mmflag & ALLOW_M)) continue;
  125. 				info[cnt] |= ALLOW_M;
  126. 				if (mtmp2->mtame) {
  127. 					if (!(mmflag & ALLOW_TM)) continue;
  128. 					info[cnt] |= ALLOW_TM;
  129. 				}
  130. 			}
  131. 			/* Note: ALLOW_SANCT only prevents movement, not */
  132. 			/* attack, into a temple. */
  133. 			if(level.flags.has_temple &&
  134. 			   *in_rooms(nx, ny, TEMPLE) &&
  135. 			   !*in_rooms(x, y, TEMPLE) &&
  136. 			   in_your_sanctuary((struct monst *)0, nx, ny)) {
  137. 				if(!(flag & ALLOW_SANCT)) continue;
  138. 				info[cnt] |= ALLOW_SANCT;
  139. 			}
  140. 		}
  141. 		if(checkobj && sobj_at(CLOVE_OF_GARLIC, nx, ny)) {
  142. 			if(flag & NOGARLIC) continue;
  143. 			info[cnt] |= NOGARLIC;
  144. 		}
  145. 		if(checkobj && sobj_at(BOULDER, nx, ny)) {
  146. 			if(!(flag & ALLOW_ROCK)) continue;
  147. 			info[cnt] |= ALLOW_ROCK;
  148. 		}
  149. 		if (monseeu && onlineu(nx,ny)) {
  150. 			if(flag & NOTONL) continue;
  151. 			info[cnt] |= NOTONL;
  152. 		}
  153. 		if (nx != x && ny != y && bad_rock(mdat, x, ny)
  154. 			    && bad_rock(mdat, nx, y)
  155. 			    && (bigmonst(mdat) || (curr_mon_load(mon) > 600)))
  156. 			continue;
  157. 		/* The monster avoids a particular type of trap if it's familiar
  158. 		 * with the trap type.  Pets get ALLOW_TRAPS and checking is
  159. 		 * done in dogmove.c.  In either case, "harmless" traps are
  160. 		 * neither avoided nor marked in info[].
  161. 		 */
  162. 		{ register struct trap *ttmp = t_at(nx, ny);
  163. 		    if(ttmp) {
  164. 			if(ttmp->ttyp >= TRAPNUM || ttmp->ttyp == 0)  {
  165. impossible("A monster looked at a very strange trap of type %d.", ttmp->ttyp);
  166. 			    continue;
  167. 			}
  168. 			if ((ttmp->ttyp != RUST_TRAP
  169. 					|| mdat == &mons[PM_IRON_GOLEM])
  170. 				&& ttmp->ttyp != STATUE_TRAP
  171. 				&& ((ttmp->ttyp != PIT
  172. 				    && ttmp->ttyp != SPIKED_PIT
  173. 				    && ttmp->ttyp != TRAPDOOR
  174. 				    && ttmp->ttyp != HOLE)
  175. 				      || (!is_flyer(mdat)
  176. 				    && !is_floater(mdat)
  177. 				    && !is_clinger(mdat))
  178. 				      || In_sokoban(&u.uz))
  179. 				&& (ttmp->ttyp != SLP_GAS_TRAP ||
  180. 				    !resists_sleep(mon))
  181. 				&& (ttmp->ttyp != BEAR_TRAP ||
  182. 				    (mdat->msize > MZ_SMALL &&
  183. 				     !amorphous(mdat) && !is_flyer(mdat)))
  184. 				&& (ttmp->ttyp != FIRE_TRAP ||
  185. 				    !resists_fire(mon))
  186. 				&& (ttmp->ttyp != SQKY_BOARD || !is_flyer(mdat))
  187. 				&& (ttmp->ttyp != WEB || (!amorphous(mdat) &&
  188. 				    !webmaker(mdat)))
  189. 			) {
  190. 			    if (!(flag & ALLOW_TRAPS)) {
  191. 				if (mon->mtrapseen & (1L << (ttmp->ttyp - 1)))
  192. 				    continue;
  193. 			    }
  194. 			    info[cnt] |= ALLOW_TRAPS;
  195. 			}
  196. 		    }
  197. 		}
  198. 		poss[cnt].x = nx;
  199. 		poss[cnt].y = ny;
  200. 		cnt++;
  201. 	    }
  202. 	}
  203. 	if(!cnt && wantpool && !is_pool(x,y)) {
  204. 		wantpool = FALSE;
  205. 		goto nexttry;
  206. 	}
  207. 	return(cnt);
  208. }
  209.  
  210. #endif /* OVL0 */
  211. #ifdef OVL1

mm_aggression[edit]

  1. /* Monster against monster special attacks; for the specified monster
  2. combinations, this allows one monster to attack another adjacent one
  3. in the absence of Conflict.  There is no provision for targetting
  4. other monsters; just hand to hand fighting when they happen to be
  5. next to each other. */
  6. STATIC_OVL long
  7. mm_aggression(magr, mdef)
  8. struct monst *magr,	/* monster that is currently deciding where to move */
  9. 	     *mdef;	/* another monster which is next to it */
  10. {
  11. 	/* supposedly purple worms are attracted to shrieking because they
  12. 	   like to eat shriekers, so attack the latter when feasible */
  13. 	if (magr->data == &mons[PM_PURPLE_WORM] &&
  14. 		mdef->data == &mons[PM_SHRIEKER])
  15. 	    return ALLOW_M|ALLOW_TM;
  16. 	/* Various other combinations such as dog vs cat, cat vs rat, and
  17. 	   elf vs orc have been suggested.  For the time being we don't
  18. 	   support those. */
  19. 	return 0L;
  20. }

monnear[edit]

  1. boolean
  2. monnear(mon, x, y)
  3. register struct monst *mon;
  4. register int x,y;
  5. /* Is the square close enough for the monster to move or attack into? */
  6. {
  7. 	register int distance = dist2(mon->mx, mon->my, x, y);
  8. 	if (distance==2 && mon->data==&mons[PM_GRID_BUG]) return 0;
  9. 	return((boolean)(distance < 3));
  10. }

dmonsfree[edit]

  1. /* really free dead monsters */
  2. void
  3. dmonsfree()
  4. {
  5. struct monst **mtmp;
  6. int count = 0;
  7.  
  8. for (mtmp = &fmon; *mtmp;) {
  9. 	if ((*mtmp)->mhp <= 0) {
  10. 	    struct monst *freetmp = *mtmp;
  11. 	    *mtmp = (*mtmp)->nmon;
  12. 	    dealloc_monst(freetmp);
  13. 	    count++;
  14. 	} else
  15. 	    mtmp = &(*mtmp)->nmon;
  16. }
  17.  
  18. if (count != iflags.purge_monsters)
  19. 	impossible("dmonsfree: %d removed doesn't match %d pending",
  20. 		   count, iflags.purge_monsters);
  21. iflags.purge_monsters = 0;
  22. }
  23.  
  24. #endif /* OVL1 */
  25. #ifdef OVLB

replmon[edit]

  1. /* called when monster is moved to larger structure */
  2. void
  3. replmon(mtmp, mtmp2)
  4. register struct monst *mtmp, *mtmp2;
  5. {
  6. struct obj *otmp;
  7.  
  8. /* transfer the monster's inventory */
  9. for (otmp = mtmp2->minvent; otmp; otmp = otmp->nobj) {
  10. #ifdef DEBUG
  11. 	if (otmp->where != OBJ_MINVENT || otmp->ocarry != mtmp)
  12. 	    panic("replmon: minvent inconsistency");
  13. #endif
  14. 	otmp->ocarry = mtmp2;
  15. }
  16. mtmp->minvent = 0;
  17.  
  18. /* remove the old monster from the map and from `fmon' list */
  19. relmon(mtmp);
  20.  
  21. /* finish adding its replacement */
  22. #ifdef STEED
  23. if (mtmp == u.usteed) ; else	/* don't place steed onto the map */
  24. #endif
  25. place_monster(mtmp2, mtmp2->mx, mtmp2->my);
  26. if (mtmp2->wormno)	    /* update level.monsters[wseg->wx][wseg->wy] */
  27. 	place_wsegs(mtmp2); /* locations to mtmp2 not mtmp. */
  28. if (emits_light(mtmp2->data)) {
  29. 	/* since this is so rare, we don't have any `mon_move_light_source' */
  30. 	new_light_source(mtmp2->mx, mtmp2->my,
  31. 			 emits_light(mtmp2->data),
  32. 			 LS_MONSTER, (genericptr_t)mtmp2);
  33. 	/* here we rely on the fact that `mtmp' hasn't actually been deleted */
  34. 	del_light_source(LS_MONSTER, (genericptr_t)mtmp);
  35. }
  36. mtmp2->nmon = fmon;
  37. fmon = mtmp2;
  38. if (u.ustuck == mtmp) u.ustuck = mtmp2;
  39. #ifdef STEED
  40. if (u.usteed == mtmp) u.usteed = mtmp2;
  41. #endif
  42. if (mtmp2->isshk) replshk(mtmp,mtmp2);
  43.  
  44. /* discard the old monster */
  45. dealloc_monst(mtmp);
  46. }

relmon[edit]

  1. /* release mon from display and monster list */
  2. void
  3. relmon(mon)
  4. register struct monst *mon;
  5. {
  6. 	register struct monst *mtmp;
  7.  
  8. 	if (fmon == (struct monst *)0)  panic ("relmon: no fmon available.");
  9.  
  10. 	remove_monster(mon->mx, mon->my);
  11.  
  12. 	if(mon == fmon) fmon = fmon->nmon;
  13. 	else {
  14. 		for(mtmp = fmon; mtmp && mtmp->nmon != mon; mtmp = mtmp->nmon) ;
  15. 		if(mtmp)    mtmp->nmon = mon->nmon;
  16. 		else	    panic("relmon: mon not in list.");
  17. 	}
  18. }

m_detach[edit]

  1. /* remove effects of mtmp from other data structures */
  2. STATIC_OVL void
  3. m_detach(mtmp, mptr)
  4. struct monst *mtmp;
  5. struct permonst *mptr;	/* reflects mtmp->data _prior_ to mtmp's death */
  6. {
  7. 	if (mtmp->mleashed) m_unleash(mtmp, FALSE);
  8. 	    /* to prevent an infinite relobj-flooreffects-hmon-killed loop */
  9. 	mtmp->mtrapped = 0;
  10. 	mtmp->mhp = 0; /* simplify some tests: force mhp to 0 */
  11. 	relobj(mtmp, 0, FALSE);
  12. 	remove_monster(mtmp->mx, mtmp->my);
  13. 	if (emits_light(mptr))
  14. 	    del_light_source(LS_MONSTER, (genericptr_t)mtmp);
  15. 	newsym(mtmp->mx,mtmp->my);
  16. 	unstuck(mtmp);
  17. 	fill_pit(mtmp->mx, mtmp->my);
  18.  
  19. 	if(mtmp->isshk) shkgone(mtmp);
  20. 	if(mtmp->wormno) wormgone(mtmp);
  21. 	iflags.purge_monsters++;
  22. }

mlifesaver[edit]

  1. /* find the worn amulet of life saving which will save a monster */
  2. struct obj *
  3. mlifesaver(mon)
  4. struct monst *mon;
  5. {
  6. 	if (!nonliving(mon->data)) {
  7. 	    struct obj *otmp = which_armor(mon, W_AMUL);
  8.  
  9. 	    if (otmp && otmp->otyp == AMULET_OF_LIFE_SAVING)
  10. 		return otmp;
  11. 	}
  12. 	return (struct obj *)0;
  13. }

lifesaved_monster[edit]

  1. STATIC_OVL void
  2. lifesaved_monster(mtmp)
  3. struct monst *mtmp;
  4. {
  5. 	struct obj *lifesave = mlifesaver(mtmp);
  6.  
  7. 	if (lifesave) {
  8. 		/* not canseemon; amulets are on the head, so you don't want */
  9. 		/* to show this for a long worm with only a tail visible. */
  10. 		/* Nor do you check invisibility, because glowing and disinte- */
  11. 		/* grating amulets are always visible. */
  12. 		if (cansee(mtmp->mx, mtmp->my)) {
  13. 			pline("But wait...");
  14. 			pline("%s medallion begins to glow!",
  15. 				s_suffix(Monnam(mtmp)));
  16. 			makeknown(AMULET_OF_LIFE_SAVING);
  17. 			if (attacktype(mtmp->data, AT_EXPL)
  18. 			    || attacktype(mtmp->data, AT_BOOM))
  19. 				pline("%s reconstitutes!", Monnam(mtmp));
  20. 			else
  21. 				pline("%s looks much better!", Monnam(mtmp));
  22. 			pline_The("medallion crumbles to dust!");
  23. 		}
  24. 		m_useup(mtmp, lifesave);
  25. 		mtmp->mcanmove = 1;
  26. 		mtmp->mfrozen = 0;
  27. 		if (mtmp->mtame && !mtmp->isminion) {
  28. 			wary_dog(mtmp, FALSE);
  29. 		}
  30. 		if (mtmp->mhpmax <= 0) mtmp->mhpmax = 10;
  31. 		mtmp->mhp = mtmp->mhpmax;
  32. 		if (mvitals[monsndx(mtmp->data)].mvflags & G_GENOD) {
  33. 			if (cansee(mtmp->mx, mtmp->my))
  34. 			    pline("Unfortunately %s is still genocided...",
  35. 				mon_nam(mtmp));
  36. 		} else
  37. 			return;
  38. 	}
  39. 	mtmp->mhp = 0;
  40. }

mondead[edit]

  1. void
  2. mondead(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	struct permonst *mptr;
  6. 	int tmp;
  7.  
  8. 	if(mtmp->isgd) {
  9. 		/* if we're going to abort the death, it *must* be before
  10. 		 * the m_detach or there will be relmon problems later */
  11. 		if(!grddead(mtmp)) return;
  12. 	}
  13. 	lifesaved_monster(mtmp);
  14. 	if (mtmp->mhp > 0) return;
  15.  
  16. #ifdef STEED
  17. 	/* Player is thrown from his steed when it dies */
  18. 	if (mtmp == u.usteed)
  19. 		dismount_steed(DISMOUNT_GENERIC);
  20. #endif
  21.  
  22. 	mptr = mtmp->data;		/* save this for m_detach() */
  23. 	/* restore chameleon, lycanthropes to true form at death */
  24. 	if (mtmp->cham)
  25. 	    set_mon_data(mtmp, &mons[cham_to_pm[mtmp->cham]], -1);
  26. 	else if (mtmp->data == &mons[PM_WEREJACKAL])
  27. 	    set_mon_data(mtmp, &mons[PM_HUMAN_WEREJACKAL], -1);
  28. 	else if (mtmp->data == &mons[PM_WEREWOLF])
  29. 	    set_mon_data(mtmp, &mons[PM_HUMAN_WEREWOLF], -1);
  30. 	else if (mtmp->data == &mons[PM_WERERAT])
  31. 	    set_mon_data(mtmp, &mons[PM_HUMAN_WERERAT], -1);
  32.  
  33. 	/* if MAXMONNO monsters of a given type have died, and it
  34. 	 * can be done, extinguish that monster.
  35. 	 *
  36. 	 * mvitals[].died does double duty as total number of dead monsters
  37. 	 * and as experience factor for the player killing more monsters.
  38. 	 * this means that a dragon dying by other means reduces the
  39. 	 * experience the player gets for killing a dragon directly; this
  40. 	 * is probably not too bad, since the player likely finagled the
  41. 	 * first dead dragon via ring of conflict or pets, and extinguishing
  42. 	 * based on only player kills probably opens more avenues of abuse
  43. 	 * for rings of conflict and such.
  44. 	 */
  45. 	tmp = monsndx(mtmp->data);
  46. 	if (mvitals[tmp].died < 255) mvitals[tmp].died++;
  47.  
  48. 	/* if it's a (possibly polymorphed) quest leader, mark him as dead */
  49. 	if (mtmp->m_id == quest_status.leader_m_id)
  50. 	    quest_status.leader_is_dead = TRUE;
  51. #ifdef MAIL
  52. 	/* if the mail daemon dies, no more mail delivery.  -3. */
  53. 	if (tmp == PM_MAIL_DAEMON) mvitals[tmp].mvflags |= G_GENOD;
  54. #endif
  55.  
  56. #ifdef KOPS
  57. 	if (mtmp->data->mlet == S_KOP) {
  58. 	    /* Dead Kops may come back. */
  59. 	    switch(rnd(5)) {
  60. 		case 1:	     /* returns near the stairs */
  61. 			(void) makemon(mtmp->data,xdnstair,ydnstair,NO_MM_FLAGS);
  62. 			break;
  63. 		case 2:	     /* randomly */
  64. 			(void) makemon(mtmp->data,0,0,NO_MM_FLAGS);
  65. 			break;
  66. 		default:
  67. 			break;
  68. 	    }
  69. 	}
  70. #endif
  71. 	if(mtmp->iswiz) wizdead();
  72. 	if(mtmp->data->msound == MS_NEMESIS) nemdead();
  73. 	if(glyph_is_invisible(levl[mtmp->mx][mtmp->my].glyph))
  74. 	    unmap_object(mtmp->mx, mtmp->my);
  75. 	m_detach(mtmp, mptr);
  76. }

corpse_chance[edit]

  1. /* TRUE if corpse might be dropped, magr may die if mon was swallowed */
  2. boolean
  3. corpse_chance(mon, magr, was_swallowed)
  4. struct monst *mon;
  5. struct monst *magr;			/* killer, if swallowed */
  6. boolean was_swallowed;			/* digestion */
  7. {
  8. 	struct permonst *mdat = mon->data;
  9. 	int i, tmp;
  10.  
  11. 	if (mdat == &mons[PM_VLAD_THE_IMPALER] || mdat->mlet == S_LICH) {
  12. 	    if (cansee(mon->mx, mon->my) && !was_swallowed)
  13. 		pline("%s body crumbles into dust.", s_suffix(Monnam(mon)));
  14. 	    return FALSE;
  15. 	}
  16.  
  17. 	/* Gas spores always explode upon death */
  18. 	for(i = 0; i < NATTK; i++) {
  19. 	    if (mdat->mattk[i].aatyp == AT_BOOM) {
  20. 	    	if (mdat->mattk[i].damn)
  21. 	    	    tmp = d((int)mdat->mattk[i].damn,
  22. 	    	    		(int)mdat->mattk[i].damd);
  23. 	    	else if(mdat->mattk[i].damd)
  24. 	    	    tmp = d((int)mdat->mlevel+1, (int)mdat->mattk[i].damd);
  25. 	    	else tmp = 0;
  26. 		if (was_swallowed && magr) {
  27. 		    if (magr == &youmonst) {
  28. 			There("is an explosion in your %s!",
  29. 			      body_part(STOMACH));
  30. 			Sprintf(killer_buf, "%s explosion",
  31. 				s_suffix(mdat->mname));
  32. 			if (Half_physical_damage) tmp = (tmp+1) / 2;
  33. 			losehp(tmp, killer_buf, KILLED_BY_AN);
  34. 		    } else {
  35. 			if (flags.soundok) You_hear("an explosion.");
  36. 			magr->mhp -= tmp;
  37. 			if (magr->mhp < 1) mondied(magr);
  38. 			if (magr->mhp < 1) { /* maybe lifesaved */
  39. 			    if (canspotmon(magr))
  40. 				pline("%s rips open!", Monnam(magr));
  41. 			} else if (canseemon(magr))
  42. 			    pline("%s seems to have indigestion.",
  43. 				  Monnam(magr));
  44. 		    }
  45.  
  46. 		    return FALSE;
  47. 		}
  48.  
  49. 	    	Sprintf(killer_buf, "%s explosion", s_suffix(mdat->mname));
  50. 	    	killer = killer_buf;
  51. 	    	killer_format = KILLED_BY_AN;
  52. 	    	explode(mon->mx, mon->my, -1, tmp, MON_EXPLODE, EXPL_NOXIOUS); 
  53. 	    	return (FALSE);
  54. 	    }
  55. 	}
  56.  
  57. 	/* must duplicate this below check in xkilled() since it results in
  58. 	 * creating no objects as well as no corpse
  59. 	 */
  60. 	if (LEVEL_SPECIFIC_NOCORPSE(mdat))
  61. 		return FALSE;
  62.  
  63. 	if (bigmonst(mdat) || mdat == &mons[PM_LIZARD]
  64. 		   || is_golem(mdat)
  65. 		   || is_mplayer(mdat)
  66. 		   || is_rider(mdat))
  67. 		return TRUE;
  68. 	return (boolean) (!rn2((int)
  69. 		(2 + ((int)(mdat->geno & G_FREQ)<2) + verysmall(mdat))));
  70. }

mondied[edit]

  1. /* drop (perhaps) a cadaver and remove monster */
  2. void
  3. mondied(mdef)
  4. register struct monst *mdef;
  5. {
  6. 	mondead(mdef);
  7. 	if (mdef->mhp > 0) return;	/* lifesaved */
  8.  
  9. 	if (corpse_chance(mdef, (struct monst *)0, FALSE) &&
  10. 	    (accessible(mdef->mx, mdef->my) || is_pool(mdef->mx, mdef->my)))
  11. 		(void) make_corpse(mdef);
  12. }

mongone[edit]

  1. /* monster disappears, not dies */
  2. void
  3. mongone(mdef)
  4. register struct monst *mdef;
  5. {
  6. 	mdef->mhp = 0;	/* can skip some inventory bookkeeping */
  7. #ifdef STEED
  8. 	/* Player is thrown from his steed when it disappears */
  9. 	if (mdef == u.usteed)
  10. 		dismount_steed(DISMOUNT_GENERIC);
  11. #endif
  12.  
  13. 	/* drop special items like the Amulet so that a dismissed Kop or nurse
  14. 	   can't remove them from the game */
  15. 	mdrop_special_objs(mdef);
  16. 	/* release rest of monster's inventory--it is removed from game */
  17. 	discard_minvent(mdef);
  18. #ifndef GOLDOBJ
  19. 	mdef->mgold = 0L;
  20. #endif
  21. 	m_detach(mdef, mdef->data);
  22. }

monstone[edit]

  1. /* drop a statue or rock and remove monster */
  2. void
  3. monstone(mdef)
  4. register struct monst *mdef;
  5. {
  6. 	struct obj *otmp, *obj, *oldminvent;
  7. 	xchar x = mdef->mx, y = mdef->my;
  8. 	boolean wasinside = FALSE;
  9.  
  10. 	/* we have to make the statue before calling mondead, to be able to
  11. 	 * put inventory in it, and we have to check for lifesaving before
  12. 	 * making the statue....
  13. 	 */
  14. 	lifesaved_monster(mdef);
  15. 	if (mdef->mhp > 0) return;
  16.  
  17. 	mdef->mtrapped = 0;	/* (see m_detach) */
  18.  
  19. 	if ((int)mdef->data->msize > MZ_TINY ||
  20. 		    !rn2(2 + ((int) (mdef->data->geno & G_FREQ) > 2))) {
  21. 		oldminvent = 0;
  22. 		/* some objects may end up outside the statue */
  23. 		while ((obj = mdef->minvent) != 0) {
  24. 		    obj_extract_self(obj);
  25. 		    if (obj->owornmask)
  26. 			update_mon_intrinsics(mdef, obj, FALSE, TRUE);
  27. 		    obj_no_longer_held(obj);
  28. 		    if (obj->owornmask & W_WEP)
  29. 			setmnotwielded(mdef,obj);
  30. 		    obj->owornmask = 0L;
  31. 		    if (obj->otyp == BOULDER ||
  32. #if 0				/* monsters don't carry statues */
  33. (obj->otyp == STATUE && mons[obj->corpsenm].msize >= mdef->data->msize) ||
  34. #endif
  35. 				obj_resists(obj, 0, 0)) {
  36. 			if (flooreffects(obj, x, y, "fall")) continue;
  37. 			place_object(obj, x, y);
  38. 		    } else {
  39. 			if (obj->lamplit) end_burn(obj, TRUE);
  40. 			obj->nobj = oldminvent;
  41. 			oldminvent = obj;
  42. 		    }
  43. 		}
  44. 		/* defer statue creation until after inventory removal
  45. 		   so that saved monster traits won't retain any stale
  46. 		   item-conferred attributes */
  47. 		otmp = mkcorpstat(STATUE, KEEPTRAITS(mdef) ? mdef : 0,
  48. 				  mdef->data, x, y, FALSE);
  49. 		if (mdef->mnamelth) otmp = oname(otmp, NAME(mdef));
  50. 		while ((obj = oldminvent) != 0) {
  51. 		    oldminvent = obj->nobj;
  52. 		    (void) add_to_container(otmp, obj);
  53. 		}
  54. #ifndef GOLDOBJ
  55. 		if (mdef->mgold) {
  56. 			struct obj *au;
  57. 			au = mksobj(GOLD_PIECE, FALSE, FALSE);
  58. 			au->quan = mdef->mgold;
  59. 			au->owt = weight(au);
  60. 			(void) add_to_container(otmp, au);
  61. 			mdef->mgold = 0;
  62. 		}
  63. #endif
  64. 		/* Archeologists should not break unique statues */
  65. 		if (mdef->data->geno & G_UNIQ)
  66. 			otmp->spe = 1;
  67. 		otmp->owt = weight(otmp);
  68. 	} else
  69. 		otmp = mksobj_at(ROCK, x, y, TRUE, FALSE);
  70.  
  71. 	stackobj(otmp);
  72. 	/* mondead() already does this, but we must do it before the newsym */
  73. 	if(glyph_is_invisible(levl[x][y].glyph))
  74. 	    unmap_object(x, y);
  75. 	if (cansee(x, y)) newsym(x,y);
  76. 	/* We don't currently trap the hero in the statue in this case but we could */
  77. 	if (u.uswallow && u.ustuck == mdef) wasinside = TRUE;
  78. 	mondead(mdef);
  79. 	if (wasinside) {
  80. 		if (is_animal(mdef->data))
  81. 			You("%s through an opening in the new %s.",
  82. 				locomotion(youmonst.data, "jump"),
  83. 				xname(otmp));
  84. 	}
  85. }

monkilled[edit]

  1. /* another monster has killed the monster mdef */
  2. void
  3. monkilled(mdef, fltxt, how)
  4. register struct monst *mdef;
  5. const char *fltxt;
  6. int how;
  7. {
  8. 	boolean be_sad = FALSE;		/* true if unseen pet is killed */
  9.  
  10. 	if ((mdef->wormno ? worm_known(mdef) : cansee(mdef->mx, mdef->my))
  11. 		&& fltxt)
  12. 	    pline("%s is %s%s%s!", Monnam(mdef),
  13. 			nonliving(mdef->data) ? "destroyed" : "killed",
  14. 		    *fltxt ? " by the " : "",
  15. 		    fltxt
  16. 		 );
  17. 	else
  18. 	    be_sad = (mdef->mtame != 0);
  19.  
  20. 	/* no corpses if digested or disintegrated */
  21. 	if(how == AD_DGST || how == -AD_RBRE)
  22. 	    mondead(mdef);
  23. 	else
  24. 	    mondied(mdef);
  25.  
  26. 	if (be_sad && mdef->mhp <= 0)
  27. 	    You("have a sad feeling for a moment, then it passes.");
  28. }

unstuck[edit]

  1. void
  2. unstuck(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	if(u.ustuck == mtmp) {
  6. 		if(u.uswallow){
  7. 			u.ux = mtmp->mx;
  8. 			u.uy = mtmp->my;
  9. 			u.uswallow = 0;
  10. 			u.uswldtim = 0;
  11. 			if (Punished) placebc();
  12. 			vision_full_recalc = 1;
  13. 			docrt();
  14. 		}
  15. 		u.ustuck = 0;
  16. 	}
  17. }

killed[edit]

  1. void
  2. killed(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	xkilled(mtmp, 1);
  6. }

xkilled[edit]

  1. /* the player has killed the monster mtmp */
  2. void
  3. xkilled(mtmp, dest)
  4. 	register struct monst *mtmp;
  5. /*
  6. * Dest=1, normal; dest=0, don't print message; dest=2, don't drop corpse
  7. * either; dest=3, message but no corpse
  8. */
  9. 	int	dest;
  10. {
  11. 	register int tmp, x = mtmp->mx, y = mtmp->my;
  12. 	register struct permonst *mdat;
  13. 	int mndx;
  14. 	register struct obj *otmp;
  15. 	register struct trap *t;
  16. 	boolean redisp = FALSE;
  17. 	boolean wasinside = u.uswallow && (u.ustuck == mtmp);
  18.  
  19.  
  20. 	/* KMH, conduct */
  21. 	u.uconduct.killer++;
  22.  
  23. 	if (dest & 1) {
  24. 	    const char *verb = nonliving(mtmp->data) ? "destroy" : "kill";
  25.  
  26. 	    if (!wasinside && !canspotmon(mtmp))
  27. 		You("%s it!", verb);
  28. 	    else {
  29. 		You("%s %s!", verb,
  30. 		    !mtmp->mtame ? mon_nam(mtmp) :
  31. 			x_monnam(mtmp,
  32. 				 mtmp->mnamelth ? ARTICLE_NONE : ARTICLE_THE,
  33. 				 "poor",
  34. 				 mtmp->mnamelth ? SUPPRESS_SADDLE : 0,
  35. 				 FALSE));
  36. 	    }
  37. 	}
  38.  
  39. 	if (mtmp->mtrapped && (t = t_at(x, y)) != 0 &&
  40. 		(t->ttyp == PIT || t->ttyp == SPIKED_PIT) &&
  41. 		sobj_at(BOULDER, x, y))
  42. 	    dest |= 2;     /*
  43. 			    * Prevent corpses/treasure being created "on top"
  44. 			    * of the boulder that is about to fall in. This is
  45. 			    * out of order, but cannot be helped unless this
  46. 			    * whole routine is rearranged.
  47. 			    */
  48.  
  49. 	/* your pet knows who just killed it...watch out */
  50. 	if (mtmp->mtame && !mtmp->isminion) EDOG(mtmp)->killed_by_u = 1;
  51.  
  52. 	/* dispose of monster and make cadaver */
  53. 	if(stoned) monstone(mtmp);
  54. 	else mondead(mtmp);
  55.  
  56. 	if (mtmp->mhp > 0) { /* monster lifesaved */
  57. 		/* Cannot put the non-visible lifesaving message in
  58. 		 * lifesaved_monster() since the message appears only when you
  59. 		 * kill it (as opposed to visible lifesaving which always
  60. 		 * appears).
  61. 		 */
  62. 		stoned = FALSE;
  63. 		if (!cansee(x,y)) pline("Maybe not...");
  64. 		return;
  65. 	}
  66.  
  67. 	mdat = mtmp->data; /* note: mondead can change mtmp->data */
  68. 	mndx = monsndx(mdat);
  69.  
  70. 	if (stoned) {
  71. 		stoned = FALSE;
  72. 		goto cleanup;
  73. 	}
  74.  
  75. 	if((dest & 2) || LEVEL_SPECIFIC_NOCORPSE(mdat))
  76. 		goto cleanup;
  77.  
  78. #ifdef MAIL
  79. 	if(mdat == &mons[PM_MAIL_DAEMON]) {
  80. 		stackobj(mksobj_at(SCR_MAIL, x, y, FALSE, FALSE));
  81. 		redisp = TRUE;
  82. 	}
  83. #endif
  84. 	if((!accessible(x, y) && !is_pool(x, y)) ||
  85. 	   (x == u.ux && y == u.uy)) {
  86. 	    /* might be mimic in wall or corpse in lava or on player's spot */
  87. 	    redisp = TRUE;
  88. 	    if(wasinside) spoteffects(TRUE);
  89. 	} else if(x != u.ux || y != u.uy) {
  90. 		/* might be here after swallowed */
  91. 		if (!rn2(6) && !(mvitals[mndx].mvflags & G_NOCORPSE)
  92. #ifdef KOPS
  93. 					&& mdat->mlet != S_KOP
  94. #endif
  95. 							) {
  96. 			int typ;
  97.  
  98. 			otmp = mkobj_at(RANDOM_CLASS, x, y, TRUE);
  99. 			/* Don't create large objects from small monsters */
  100. 			typ = otmp->otyp;
  101. 			if (mdat->msize < MZ_HUMAN && typ != FOOD_RATION
  102. 			    && typ != LEASH
  103. 			    && typ != FIGURINE
  104. 			    && (otmp->owt > 3 ||
  105. 				objects[typ].oc_big /*oc_bimanual/oc_bulky*/ ||
  106. 				is_spear(otmp) || is_pole(otmp) ||
  107. 				typ == MORNING_STAR)) {
  108. 			    delobj(otmp);
  109. 			} else redisp = TRUE;
  110. 		}
  111. 		/* Whether or not it always makes a corpse is, in theory,
  112. 		 * different from whether or not the corpse is "special";
  113. 		 * if we want both, we have to specify it explicitly.
  114. 		 */
  115. 		if (corpse_chance(mtmp, (struct monst *)0, FALSE))
  116. 			(void) make_corpse(mtmp);
  117. 	}
  118. 	if(redisp) newsym(x,y);
  119. cleanup:
  120. 	/* punish bad behaviour */
  121. 	if(is_human(mdat) && (!always_hostile(mdat) && mtmp->malign <= 0) &&
  122. 	   (mndx < PM_ARCHEOLOGIST || mndx > PM_WIZARD) &&
  123. 	   u.ualign.type != A_CHAOTIC) {
  124. 		HTelepat &= ~INTRINSIC;
  125. 		change_luck(-2);
  126. 		You("murderer!");
  127. 		if (Blind && !Blind_telepat)
  128. 		    see_monsters(); /* Can't sense monsters any more. */
  129. 	}
  130. 	if((mtmp->mpeaceful && !rn2(2)) || mtmp->mtame)	change_luck(-1);
  131. 	if (is_unicorn(mdat) &&
  132. 				sgn(u.ualign.type) == sgn(mdat->maligntyp)) {
  133. 		change_luck(-5);
  134. 		You_feel("guilty...");
  135. 	}
  136.  
  137. 	/* give experience points */
  138. 	tmp = experience(mtmp, (int)mvitals[mndx].died + 1);
  139. 	more_experienced(tmp, 0);
  140. 	newexplevel();		/* will decide if you go up */
  141.  
  142. 	/* adjust alignment points */
  143. 	if (mtmp->m_id == quest_status.leader_m_id) {		/* REAL BAD! */
  144. 	    adjalign(-(u.ualign.record+(int)ALIGNLIM/2));
  145. 	    pline("That was %sa bad idea...",
  146. 	    		u.uevent.qcompleted ? "probably " : "");
  147. 	} else if (mdat->msound == MS_NEMESIS)	/* Real good! */
  148. 	    adjalign((int)(ALIGNLIM/4));
  149. 	else if (mdat->msound == MS_GUARDIAN) {	/* Bad */
  150. 	    adjalign(-(int)(ALIGNLIM/8));
  151. 	    if (!Hallucination) pline("That was probably a bad idea...");
  152. 	    else pline("Whoopsie-daisy!");
  153. 	}else if (mtmp->ispriest) {
  154. 		adjalign((p_coaligned(mtmp)) ? -2 : 2);
  155. 		/* cancel divine protection for killing your priest */
  156. 		if (p_coaligned(mtmp)) u.ublessed = 0;
  157. 		if (mdat->maligntyp == A_NONE)
  158. 			adjalign((int)(ALIGNLIM / 4));		/* BIG bonus */
  159. 	} else if (mtmp->mtame) {
  160. 		adjalign(-15);	/* bad!! */
  161. 		/* your god is mighty displeased... */
  162. 		if (!Hallucination) You_hear("the rumble of distant thunder...");
  163. 		else You_hear("the studio audience applaud!");
  164. 	} else if (mtmp->mpeaceful)
  165. 		adjalign(-5);
  166.  
  167. 	/* malign was already adjusted for u.ualign.type and randomization */
  168. 	adjalign(mtmp->malign);
  169. }

mon_to_stone[edit]

  1. /* changes the monster into a stone monster of the same type */
  2. /* this should only be called when poly_when_stoned() is true */
  3. void
  4. mon_to_stone(mtmp)
  5. register struct monst *mtmp;
  6. {
  7. if(mtmp->data->mlet == S_GOLEM) {
  8. 	/* it's a golem, and not a stone golem */
  9. 	if(canseemon(mtmp))
  10. 	    pline("%s solidifies...", Monnam(mtmp));
  11. 	if (newcham(mtmp, &mons[PM_STONE_GOLEM], FALSE, FALSE)) {
  12. 	    if(canseemon(mtmp))
  13. 		pline("Now it's %s.", an(mtmp->data->mname));
  14. 	} else {
  15. 	    if(canseemon(mtmp))
  16. 		pline("... and returns to normal.");
  17. 	}
  18. } else
  19. 	impossible("Can't polystone %s!", a_monnam(mtmp));
  20. }

mnexto[edit]

  1. void
  2. mnexto(mtmp)	/* Make monster mtmp next to you (if possible) */
  3. 	struct monst *mtmp;
  4. {
  5. 	coord mm;
  6.  
  7. #ifdef STEED
  8. 	if (mtmp == u.usteed) {
  9. 		/* Keep your steed in sync with you instead */
  10. 		mtmp->mx = u.ux;
  11. 		mtmp->my = u.uy;
  12. 		return;
  13. 	}
  14. #endif
  15.  
  16. 	if(!enexto(&mm, u.ux, u.uy, mtmp->data)) return;
  17. 	rloc_to(mtmp, mm.x, mm.y);
  18. 	return;
  19. }

mnearto[edit]

  1. /* mnearto()
  2. * Put monster near (or at) location if possible.
  3. * Returns:
  4. *	1 - if a monster was moved from x, y to put mtmp at x, y.
  5. *	0 - in most cases.
  6. */
  7. boolean
  8. mnearto(mtmp,x,y,move_other)
  9. register struct monst *mtmp;
  10. xchar x, y;
  11. boolean move_other;	/* make sure mtmp gets to x, y! so move m_at(x, y) */
  12. {
  13. 	struct monst *othermon = (struct monst *)0;
  14. 	xchar newx, newy;
  15. 	coord mm;
  16.  
  17. 	if ((mtmp->mx == x) && (mtmp->my == y)) return(FALSE);
  18.  
  19. 	if (move_other && (othermon = m_at(x, y))) {
  20. 		if (othermon->wormno)
  21. 			remove_worm(othermon);
  22. 		else
  23. 			remove_monster(x, y);
  24. 	}
  25.  
  26. 	newx = x;
  27. 	newy = y;
  28.  
  29. 	if (!goodpos(newx, newy, mtmp, 0)) {
  30. 		/* actually we have real problems if enexto ever fails.
  31. 		 * migrating_mons that need to be placed will cause
  32. 		 * no end of trouble.
  33. 		 */
  34. 		if (!enexto(&mm, newx, newy, mtmp->data)) return(FALSE);
  35. 		newx = mm.x; newy = mm.y;
  36. 	}
  37.  
  38. 	rloc_to(mtmp, newx, newy);
  39.  
  40. 	if (move_other && othermon) {
  41. 	    othermon->mx = othermon->my = 0;
  42. 	    (void) mnearto(othermon, x, y, FALSE);
  43. 	    if ((othermon->mx != x) || (othermon->my != y))
  44. 		return(TRUE);
  45. 	}
  46.  
  47. 	return(FALSE);
  48. }
  49.  
  50.  
  51. static const char *poiseff[] = {
  52.  
  53. 	" feel weaker", "r brain is on fire",
  54. 	"r judgement is impaired", "r muscles won't obey you",
  55. 	" feel very sick", " break out in hives"
  56. };

poisontell[edit]

  1. void
  2. poisontell(typ)
  3.  
  4. 	int	typ;
  5. {
  6. 	pline("You%s.", poiseff[typ]);
  7. }

poisoned[edit]

  1. void
  2. poisoned(string, typ, pname, fatal)
  3. const char *string, *pname;
  4. int  typ, fatal;
  5. {
  6. 	int i, plural, kprefix = KILLED_BY_AN;
  7. 	boolean thrown_weapon = (fatal < 0);
  8.  
  9. 	if (thrown_weapon) fatal = -fatal;
  10. 	if(strcmp(string, "blast") && !thrown_weapon) {
  11. 	    /* 'blast' has already given a 'poison gas' message */
  12. 	    /* so have "poison arrow", "poison dart", etc... */
  13. 	    plural = (string[strlen(string) - 1] == 's')? 1 : 0;
  14. 	    /* avoid "The" Orcus's sting was poisoned... */
  15. 	    pline("%s%s %s poisoned!", isupper(*string) ? "" : "The ",
  16. 			string, plural ? "were" : "was");
  17. 	}
  18.  
  19. 	if(Poison_resistance) {
  20. 		if(!strcmp(string, "blast")) shieldeff(u.ux, u.uy);
  21. 		pline_The("poison doesn't seem to affect you.");
  22. 		return;
  23. 	}
  24. 	/* suppress killer prefix if it already has one */
  25. 	if ((i = name_to_mon(pname)) >= LOW_PM && mons[i].geno & G_UNIQ) {
  26. 	    kprefix = KILLED_BY;
  27. 	    if (!type_is_pname(&mons[i])) pname = the(pname);
  28. 	} else if (!strncmpi(pname, "the ", 4) ||
  29. 	    !strncmpi(pname, "an ", 3) ||
  30. 	    !strncmpi(pname, "a ", 2)) {
  31. 	    /*[ does this need a plural check too? ]*/
  32. 	    kprefix = KILLED_BY;
  33. 	}
  34. 	i = rn2(fatal + 20*thrown_weapon);
  35. 	if(i == 0 && typ != A_CHA) {
  36. 		u.uhp = -1;
  37. 		pline_The("poison was deadly...");
  38. 	} else if(i <= 5) {
  39. 		/* Check that a stat change was made */
  40. 		if (adjattrib(typ, thrown_weapon ? -1 : -rn1(3,3), 1))
  41. 		    pline("You%s!", poiseff[typ]);
  42. 	} else {
  43. 		i = thrown_weapon ? rnd(6) : rn1(10,6);
  44. 		if(Half_physical_damage) i = (i+1) / 2;
  45. 		losehp(i, pname, kprefix);
  46. 	}
  47. 	if(u.uhp < 1) {
  48. 		killer_format = kprefix;
  49. 		killer = pname;
  50. 		/* "Poisoned by a poisoned ___" is redundant */
  51. 		done(strstri(pname, "poison") ? DIED : POISONING);
  52. 	}
  53. 	(void) encumber_msg();
  54. }

m_respond[edit]

  1. /* monster responds to player action; not the same as a passive attack */
  2. /* assumes reason for response has been tested, and response _must_ be made */
  3. void
  4. m_respond(mtmp)
  5. register struct monst *mtmp;
  6. {
  7. if(mtmp->data->msound == MS_SHRIEK) {
  8. 	if(flags.soundok) {
  9. 	    pline("%s shrieks.", Monnam(mtmp));
  10. 	    stop_occupation();
  11. 	}
  12. 	if (!rn2(10)) {
  13. 	    if (!rn2(13))
  14. 		(void) makemon(&mons[PM_PURPLE_WORM], 0, 0, NO_MM_FLAGS);
  15. 	    else
  16. 		(void) makemon((struct permonst *)0, 0, 0, NO_MM_FLAGS);
  17.  
  18. 	}
  19. 	aggravate();
  20. }
  21. if(mtmp->data == &mons[PM_MEDUSA]) {
  22. 	register int i;
  23. 	for(i = 0; i < NATTK; i++)
  24. 	     if(mtmp->data->mattk[i].aatyp == AT_GAZE) {
  25. 		 (void) gazemu(mtmp, &mtmp->data->mattk[i]);
  26. 		 break;
  27. 	     }
  28. }
  29. }
  30.  
  31. #endif /* OVLB */
  32. #ifdef OVL2

setmangry[edit]

  1. void
  2. setmangry(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	mtmp->mstrategy &= ~STRAT_WAITMASK;
  6. 	if(!mtmp->mpeaceful) return;
  7. 	if(mtmp->mtame) return;
  8. 	mtmp->mpeaceful = 0;
  9. 	if(mtmp->ispriest) {
  10. 		if(p_coaligned(mtmp)) adjalign(-5); /* very bad */
  11. 		else adjalign(2);
  12. 	} else
  13. 		adjalign(-1);		/* attacking peaceful monsters is bad */
  14. 	if (couldsee(mtmp->mx, mtmp->my)) {
  15. 		if (humanoid(mtmp->data) || mtmp->isshk || mtmp->isgd)
  16. 		    pline("%s gets angry!", Monnam(mtmp));
  17. 		else if (flags.verbose && flags.soundok) growl(mtmp);
  18. 	}
  19.  
  20. 	/* attacking your own quest leader will anger his or her guardians */
  21. 	if (!flags.mon_moving &&	/* should always be the case here */
  22. 		mtmp->data == &mons[quest_info(MS_LEADER)]) {
  23. 	    struct monst *mon;
  24. 	    struct permonst *q_guardian = &mons[quest_info(MS_GUARDIAN)];
  25. 	    int got_mad = 0;
  26.  
  27. 	    /* guardians will sense this attack even if they can't see it */
  28. 	    for (mon = fmon; mon; mon = mon->nmon)
  29. 		if (!DEADMONSTER(mon) && mon->data == q_guardian && mon->mpeaceful) {
  30. 		    mon->mpeaceful = 0;
  31. 		    if (canseemon(mon)) ++got_mad;
  32. 		}
  33. 	    if (got_mad && !Hallucination)
  34. 		pline_The("%s appear%s to be angry too...",
  35. 		      got_mad == 1 ? q_guardian->mname :
  36. 				    makeplural(q_guardian->mname),
  37. 		      got_mad == 1 ? "s" : "");
  38. 	}
  39. }

wakeup[edit]

  1. void
  2. wakeup(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	mtmp->msleeping = 0;
  6. 	mtmp->meating = 0;	/* assume there's no salvagable food left */
  7. 	setmangry(mtmp);
  8. 	if(mtmp->m_ap_type) seemimic(mtmp);
  9. 	else if (flags.forcefight && !flags.mon_moving && mtmp->mundetected) {
  10. 	    mtmp->mundetected = 0;
  11. 	    newsym(mtmp->mx, mtmp->my);
  12. 	}
  13. }

wake_nearby[edit]

  1. /* Wake up nearby monsters. */
  2. void
  3. wake_nearby()
  4. {
  5. 	register struct monst *mtmp;
  6.  
  7. 	for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  8. 	    if (!DEADMONSTER(mtmp) && distu(mtmp->mx,mtmp->my) < u.ulevel*20) {
  9. 		mtmp->msleeping = 0;
  10. 		if (mtmp->mtame && !mtmp->isminion)
  11. 		    EDOG(mtmp)->whistletime = moves;
  12. 	    }
  13. 	}
  14. }

wake_nearto[edit]

  1. /* Wake up monsters near some particular location. */
  2. void
  3. wake_nearto(x, y, distance)
  4. register int x, y, distance;
  5. {
  6. 	register struct monst *mtmp;
  7.  
  8. 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  9. 	    if (!DEADMONSTER(mtmp) && mtmp->msleeping && (distance == 0 ||
  10. 				 dist2(mtmp->mx, mtmp->my, x, y) < distance))
  11. 		mtmp->msleeping = 0;
  12. 	}
  13. }

seemimic[edit]

  1. /* NOTE: we must check for mimicry before calling this routine */
  2. void
  3. seemimic(mtmp)
  4. register struct monst *mtmp;
  5. {
  6. 	unsigned old_app = mtmp->mappearance;
  7. 	uchar old_ap_type = mtmp->m_ap_type;
  8.  
  9. 	mtmp->m_ap_type = M_AP_NOTHING;
  10. 	mtmp->mappearance = 0;
  11.  
  12. 	/*
  13. 	 *  Discovered mimics don't block light.
  14. 	 */
  15. 	if (((old_ap_type == M_AP_FURNITURE &&
  16. 	      (old_app == S_hcdoor || old_app == S_vcdoor)) ||
  17. 	     (old_ap_type == M_AP_OBJECT && old_app == BOULDER)) &&
  18. 	    !does_block(mtmp->mx, mtmp->my, &levl[mtmp->mx][mtmp->my]))
  19. 	    unblock_point(mtmp->mx, mtmp->my);
  20.  
  21. 	newsym(mtmp->mx,mtmp->my);
  22. }

rescham[edit]

  1. /* force all chameleons to become normal */
  2. void
  3. rescham()
  4. {
  5. 	register struct monst *mtmp;
  6. 	int mcham;
  7.  
  8. 	for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  9. 		if (DEADMONSTER(mtmp)) continue;
  10. 		mcham = (int) mtmp->cham;
  11. 		if (mcham) {
  12. 			mtmp->cham = CHAM_ORDINARY;
  13. 			(void) newcham(mtmp, &mons[cham_to_pm[mcham]],
  14. 				       FALSE, FALSE);
  15. 		}
  16. 		if(is_were(mtmp->data) && mtmp->data->mlet != S_HUMAN)
  17. 			new_were(mtmp);
  18. 		if(mtmp->m_ap_type && cansee(mtmp->mx, mtmp->my)) {
  19. 			seemimic(mtmp);
  20. 			/* we pretend that the mimic doesn't */
  21. 			/* know that it has been unmasked.   */
  22. 			mtmp->msleeping = 1;
  23. 		}
  24. 	}
  25. }

restartcham[edit]

  1. /* Let the chameleons change again -dgk */
  2. void
  3. restartcham()
  4. {
  5. 	register struct monst *mtmp;
  6.  
  7. 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  8. 		if (DEADMONSTER(mtmp)) continue;
  9. 		mtmp->cham = pm_to_cham(monsndx(mtmp->data));
  10. 		if (mtmp->data->mlet == S_MIMIC && mtmp->msleeping &&
  11. 				cansee(mtmp->mx, mtmp->my)) {
  12. 			set_mimic_sym(mtmp);
  13. 			newsym(mtmp->mx,mtmp->my);
  14. 		}
  15. 	}
  16. }

restore_cham[edit]

  1. /* called when restoring a monster from a saved level; protection
  2. against shape-changing might be different now than it was at the
  3. time the level was saved. */
  4. void
  5. restore_cham(mon)
  6. struct monst *mon;
  7. {
  8. 	int mcham;
  9.  
  10. 	if (Protection_from_shape_changers) {
  11. 	    mcham = (int) mon->cham;
  12. 	    if (mcham) {
  13. 		mon->cham = CHAM_ORDINARY;
  14. 		(void) newcham(mon, &mons[cham_to_pm[mcham]], FALSE, FALSE);
  15. 	    } else if (is_were(mon->data) && !is_human(mon->data)) {
  16. 		new_were(mon);
  17. 	    }
  18. 	} else if (mon->cham == CHAM_ORDINARY) {
  19. 	    mon->cham = pm_to_cham(monsndx(mon->data));
  20. 	}
  21. }

restrap[edit]

  1. /* unwatched hiders may hide again; if so, a 1 is returned.  */
  2. STATIC_OVL boolean
  3. restrap(mtmp)
  4. register struct monst *mtmp;
  5. {
  6. 	if(mtmp->cham || mtmp->mcan || mtmp->m_ap_type ||
  7. 	   cansee(mtmp->mx, mtmp->my) || rn2(3) || (mtmp == u.ustuck) ||
  8. 	   (sensemon(mtmp) && distu(mtmp->mx, mtmp->my) <= 2))
  9. 		return(FALSE);
  10.  
  11. 	if(mtmp->data->mlet == S_MIMIC) {
  12. 		set_mimic_sym(mtmp);
  13. 		return(TRUE);
  14. 	} else
  15. 	    if(levl[mtmp->mx][mtmp->my].typ == ROOM)  {
  16. 		mtmp->mundetected = 1;
  17. 		return(TRUE);
  18. 	    }
  19.  
  20. 	return(FALSE);
  21. }
  22.  
  23. short *animal_list = 0;		/* list of PM values for animal monsters */
  24. int animal_list_count;

mon_animal_list[edit]

  1. void
  2. mon_animal_list(construct)
  3. boolean construct;
  4. {
  5. 	if (construct) {
  6. 	    short animal_temp[SPECIAL_PM];
  7. 	    int i, n;
  8.  
  9. 	 /* if (animal_list) impossible("animal_list already exists"); */
  10.  
  11. 	    for (n = 0, i = LOW_PM; i < SPECIAL_PM; i++)
  12. 		if (is_animal(&mons[i])) animal_temp[n++] = i;
  13. 	 /* if (n == 0) animal_temp[n++] = NON_PM; */
  14.  
  15. 	    animal_list = (short *)alloc(n * sizeof *animal_list);
  16. 	    (void) memcpy((genericptr_t)animal_list,
  17. 			  (genericptr_t)animal_temp,
  18. 			  n * sizeof *animal_list);
  19. 	    animal_list_count = n;
  20. 	} else {	/* release */
  21. 	    if (animal_list) free((genericptr_t)animal_list), animal_list = 0;
  22. 	    animal_list_count = 0;
  23. 	}
  24. }

pick_animal[edit]

  1. STATIC_OVL int
  2. pick_animal()
  3. {
  4. 	if (!animal_list) mon_animal_list(TRUE);
  5.  
  6. 	return animal_list[rn2(animal_list_count)];
  7. }

select_newcham_form[edit]

  1. STATIC_OVL int
  2. select_newcham_form(mon)
  3. struct monst *mon;
  4. {
  5. 	int mndx = NON_PM;
  6.  
  7. 	switch (mon->cham) {
  8. 	    case CHAM_SANDESTIN:
  9. 		if (rn2(7)) mndx = pick_nasty();
  10. 		break;
  11. 	    case CHAM_DOPPELGANGER:
  12. 		if (!rn2(7)) mndx = pick_nasty();
  13. 		else if (rn2(3)) mndx = rn1(PM_WIZARD - PM_ARCHEOLOGIST + 1,
  14. 					    PM_ARCHEOLOGIST);
  15. 		break;
  16. 	    case CHAM_CHAMELEON:
  17. 		if (!rn2(3)) mndx = pick_animal();
  18. 		break;
  19. 	    case CHAM_ORDINARY:
  20. 	      {
  21. 		struct obj *m_armr = which_armor(mon, W_ARM);
  22.  
  23. 		if (m_armr && Is_dragon_scales(m_armr))
  24. 		    mndx = Dragon_scales_to_pm(m_armr) - mons;
  25. 		else if (m_armr && Is_dragon_mail(m_armr))
  26. 		    mndx = Dragon_mail_to_pm(m_armr) - mons;
  27. 	      }
  28. 		break;
  29. 	}
  30. #ifdef WIZARD
  31. 	/* For debugging only: allow control of polymorphed monster; not saved */
  32. 	if (wizard && iflags.mon_polycontrol) {
  33. 		char pprompt[BUFSZ], buf[BUFSZ];
  34. 		int tries = 0;
  35. 		do {
  36. 			Sprintf(pprompt,
  37. 				"Change %s into what kind of monster? [type the name]",
  38. 				mon_nam(mon));
  39. 			getlin(pprompt,buf);
  40. 			mndx = name_to_mon(buf);
  41. 			if (mndx < LOW_PM)
  42. 				You("cannot polymorph %s into that.", mon_nam(mon));
  43. 			else break;
  44. 		} while(++tries < 5);
  45. 		if (tries==5) pline(thats_enough_tries);
  46. 	}
  47. #endif /*WIZARD*/
  48. 	if (mndx == NON_PM) mndx = rn1(SPECIAL_PM - LOW_PM, LOW_PM);
  49. 	return mndx;
  50. }

newcham[edit]

  1. /* make a chameleon look like a new monster; returns 1 if it actually changed */
  2. int
  3. newcham(mtmp, mdat, polyspot, msg)
  4. struct monst *mtmp;
  5. struct permonst *mdat;
  6. boolean polyspot;	/* change is the result of wand or spell of polymorph */
  7. boolean msg;		/* "The oldmon turns into a newmon!" */
  8. {
  9. 	int mhp, hpn, hpd;
  10. 	int mndx, tryct;
  11. 	struct permonst *olddata = mtmp->data;
  12. 	char oldname[BUFSZ];
  13.  
  14. 	if (msg) {
  15. 	    /* like Monnam() but never mention saddle */
  16. 	    Strcpy(oldname, x_monnam(mtmp, ARTICLE_THE, (char *)0,
  17. 				     SUPPRESS_SADDLE, FALSE));
  18. 	    oldname[0] = highc(oldname[0]);
  19. 	}
  20.  
  21. 	/* mdat = 0 -> caller wants a random monster shape */
  22. 	tryct = 0;
  23. 	if (mdat == 0) {
  24. 	    while (++tryct <= 100) {
  25. 		mndx = select_newcham_form(mtmp);
  26. 		mdat = &mons[mndx];
  27. 		if ((mvitals[mndx].mvflags & G_GENOD) != 0 ||
  28. 			is_placeholder(mdat)) continue;
  29. 		/* polyok rules out all M2_PNAME and M2_WERE's;
  30. 		   select_newcham_form might deliberately pick a player
  31. 		   character type, so we can't arbitrarily rule out all
  32. 		   human forms any more */
  33. 		if (is_mplayer(mdat) || (!is_human(mdat) && polyok(mdat)))
  34. 		    break;
  35. 	    }
  36. 	    if (tryct > 100) return 0;	/* Should never happen */
  37. 	} else if (mvitals[monsndx(mdat)].mvflags & G_GENOD)
  38. 	    return(0);	/* passed in mdat is genocided */
  39.  
  40. 	if(is_male(mdat)) {
  41. 		if(mtmp->female) mtmp->female = FALSE;
  42. 	} else if (is_female(mdat)) {
  43. 		if(!mtmp->female) mtmp->female = TRUE;
  44. 	} else if (!is_neuter(mdat)) {
  45. 		if(!rn2(10)) mtmp->female = !mtmp->female;
  46. 	}
  47.  
  48. 	if (In_endgame(&u.uz) && is_mplayer(olddata)) {
  49. 		/* mplayers start out as "Foo the Bar", but some of the
  50. 		 * titles are inappropriate when polymorphed, particularly
  51. 		 * into the opposite sex.  players don't use ranks when
  52. 		 * polymorphed, so dropping the rank for mplayers seems
  53. 		 * reasonable.
  54. 		 */
  55. 		char *p = index(NAME(mtmp), ' ');
  56. 		if (p) {
  57. 			*p = '\0';
  58. 			mtmp->mnamelth = p - NAME(mtmp) + 1;
  59. 		}
  60. 	}
  61.  
  62. 	if(mdat == mtmp->data) return(0);	/* still the same monster */
  63.  
  64. 	if(mtmp->wormno) {			/* throw tail away */
  65. 		wormgone(mtmp);
  66. 		place_monster(mtmp, mtmp->mx, mtmp->my);
  67. 	}
  68.  
  69. 	hpn = mtmp->mhp;
  70. 	hpd = (mtmp->m_lev < 50) ? ((int)mtmp->m_lev)*8 : mdat->mlevel;
  71. 	if(!hpd) hpd = 4;
  72.  
  73. 	mtmp->m_lev = adj_lev(mdat);		/* new monster level */
  74.  
  75. 	mhp = (mtmp->m_lev < 50) ? ((int)mtmp->m_lev)*8 : mdat->mlevel;
  76. 	if(!mhp) mhp = 4;
  77.  
  78. 	/* new hp: same fraction of max as before */
  79. #ifndef LINT
  80. 	mtmp->mhp = (int)(((long)hpn*(long)mhp)/(long)hpd);
  81. #endif
  82. 	if(mtmp->mhp < 0) mtmp->mhp = hpn;	/* overflow */
  83. /* Unlikely but not impossible; a 1HD creature with 1HP that changes into a
  84. 0HD creature will require this statement */
  85. 	if (!mtmp->mhp) mtmp->mhp = 1;
  86.  
  87. /* and the same for maximum hit points */
  88. 	hpn = mtmp->mhpmax;
  89. #ifndef LINT
  90. 	mtmp->mhpmax = (int)(((long)hpn*(long)mhp)/(long)hpd);
  91. #endif
  92. 	if(mtmp->mhpmax < 0) mtmp->mhpmax = hpn;	/* overflow */
  93. 	if (!mtmp->mhpmax) mtmp->mhpmax = 1;
  94.  
  95. 	/* take on the new form... */
  96. 	set_mon_data(mtmp, mdat, 0);
  97.  
  98. 	if (emits_light(olddata) != emits_light(mtmp->data)) {
  99. 	    /* used to give light, now doesn't, or vice versa,
  100. 	       or light's range has changed */
  101. 	    if (emits_light(olddata))
  102. 		del_light_source(LS_MONSTER, (genericptr_t)mtmp);
  103. 	    if (emits_light(mtmp->data))
  104. 		new_light_source(mtmp->mx, mtmp->my, emits_light(mtmp->data),
  105. 				 LS_MONSTER, (genericptr_t)mtmp);
  106. 	}
  107. 	if (!mtmp->perminvis || pm_invisible(olddata))
  108. 	    mtmp->perminvis = pm_invisible(mdat);
  109. 	mtmp->minvis = mtmp->invis_blkd ? 0 : mtmp->perminvis;
  110. 	if (!(hides_under(mdat) && OBJ_AT(mtmp->mx, mtmp->my)) &&
  111. 			!(mdat->mlet == S_EEL && is_pool(mtmp->mx, mtmp->my)))
  112. 		mtmp->mundetected = 0;
  113. 	if (u.ustuck == mtmp) {
  114. 		if(u.uswallow) {
  115. 			if(!attacktype(mdat,AT_ENGL)) {
  116. 				/* Does mdat care? */
  117. 				if (!noncorporeal(mdat) && !amorphous(mdat) &&
  118. 				    !is_whirly(mdat) &&
  119. 				    (mdat != &mons[PM_YELLOW_LIGHT])) {
  120. 					You("break out of %s%s!", mon_nam(mtmp),
  121. 					    (is_animal(mdat)?
  122. 					    "'s stomach" : ""));
  123. 					mtmp->mhp = 1;  /* almost dead */
  124. 				}
  125. 				expels(mtmp, olddata, FALSE);
  126. 			} else {
  127. 				/* update swallow glyphs for new monster */
  128. 				swallowed(0);
  129. 			}
  130. 		} else if (!sticks(mdat) && !sticks(youmonst.data))
  131. 			unstuck(mtmp);
  132. 	}
  133.  
  134. #ifndef DCC30_BUG
  135. 	if (mdat == &mons[PM_LONG_WORM] && (mtmp->wormno = get_wormno()) != 0) {
  136. #else
  137. 	/* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the
  138. 	 * same expression.
  139. 	 */
  140. 	if (mdat == &mons[PM_LONG_WORM] &&
  141. 		(mtmp->wormno = get_wormno(), mtmp->wormno != 0)) {
  142. #endif
  143. 	    /* we can now create worms with tails - 11/91 */
  144. 	    initworm(mtmp, rn2(5));
  145. 	    if (count_wsegs(mtmp))
  146. 		place_worm_tail_randomly(mtmp, mtmp->mx, mtmp->my);
  147. 	}
  148.  
  149. 	newsym(mtmp->mx,mtmp->my);
  150.  
  151. 	if (msg) {
  152. 	    uchar save_mnamelth = mtmp->mnamelth;
  153. 	    mtmp->mnamelth = 0;
  154. 	    pline("%s turns into %s!", oldname,
  155. 		  mdat == &mons[PM_GREEN_SLIME] ? "slime" :
  156. 		  x_monnam(mtmp, ARTICLE_A, (char*)0, SUPPRESS_SADDLE, FALSE));
  157. 	    mtmp->mnamelth = save_mnamelth;
  158. 	}
  159.  
  160. 	possibly_unwield(mtmp, polyspot);	/* might lose use of weapon */
  161. 	mon_break_armor(mtmp, polyspot);
  162. 	if (!(mtmp->misc_worn_check & W_ARMG))
  163. 	    mselftouch(mtmp, "No longer petrify-resistant, ",
  164. 			!flags.mon_moving);
  165. 	m_dowear(mtmp, FALSE);
  166.  
  167. 	/* This ought to re-test can_carry() on each item in the inventory
  168. 	 * rather than just checking ex-giants & boulders, but that'd be
  169. 	 * pretty expensive to perform.  If implemented, then perhaps
  170. 	 * minvent should be sorted in order to drop heaviest items first.
  171. 	 */
  172. 	/* former giants can't continue carrying boulders */
  173. 	if (mtmp->minvent && !throws_rocks(mdat)) {
  174. 	    register struct obj *otmp, *otmp2;
  175.  
  176. 	    for (otmp = mtmp->minvent; otmp; otmp = otmp2) {
  177. 		otmp2 = otmp->nobj;
  178. 		if (otmp->otyp == BOULDER) {
  179. 		    /* this keeps otmp from being polymorphed in the
  180. 		       same zap that the monster that held it is polymorphed */
  181. 		    if (polyspot) bypass_obj(otmp);
  182. 		    obj_extract_self(otmp);
  183. 		    /* probably ought to give some "drop" message here */
  184. 		    if (flooreffects(otmp, mtmp->mx, mtmp->my, "")) continue;
  185. 		    place_object(otmp, mtmp->mx, mtmp->my);
  186. 		}
  187. 	    }
  188. 	}
  189.  
  190. 	return(1);
  191. }
  192.  
  193. /* sometimes an egg will be special */
  194. #define BREEDER_EGG (!rn2(77))

can_be_hatched[edit]

  1. /*
  2. * Determine if the given monster number can be hatched from an egg.
  3. * Return the monster number to use as the egg's corpsenm.  Return
  4. * NON_PM if the given monster can't be hatched.
  5. */
  6. int
  7. can_be_hatched(mnum)
  8. int mnum;
  9. {
  10. /* ranger quest nemesis has the oviparous bit set, making it
  11. be possible to wish for eggs of that unique monster; turn
  12. such into ordinary eggs rather than forbidding them outright */
  13. if (mnum == PM_SCORPIUS) mnum = PM_SCORPION;
  14.  
  15. mnum = little_to_big(mnum);
  16. /*
  17. * Queen bees lay killer bee eggs (usually), but killer bees don't
  18. * grow into queen bees.  Ditto for [winged-]gargoyles.
  19. */
  20. if (mnum == PM_KILLER_BEE || mnum == PM_GARGOYLE ||
  21. 	    (lays_eggs(&mons[mnum]) && (BREEDER_EGG ||
  22. 		(mnum != PM_QUEEN_BEE && mnum != PM_WINGED_GARGOYLE))))
  23. 	return mnum;
  24. return NON_PM;
  25. }

egg_type_from_parent[edit]

  1. /* type of egg laid by #sit; usually matches parent */
  2. int
  3. egg_type_from_parent(mnum, force_ordinary)
  4. int mnum;	/* parent monster; caller must handle lays_eggs() check */
  5. boolean force_ordinary;
  6. {
  7. if (force_ordinary || !BREEDER_EGG) {
  8. 	if (mnum == PM_QUEEN_BEE) mnum = PM_KILLER_BEE;
  9. 	else if (mnum == PM_WINGED_GARGOYLE) mnum = PM_GARGOYLE;
  10. }
  11. return mnum;
  12. }

dead_species[edit]

  1. /* decide whether an egg of the indicated monster type is viable; */
  2. /* also used to determine whether an egg or tin can be created... */
  3. boolean
  4. dead_species(m_idx, egg)
  5. int m_idx;
  6. boolean egg;
  7. {
  8. 	/*
  9. 	 * For monsters with both baby and adult forms, genociding either
  10. 	 * form kills all eggs of that monster.  Monsters with more than
  11. 	 * two forms (small->large->giant mimics) are more or less ignored;
  12. 	 * fortunately, none of them have eggs.  Species extinction due to
  13. 	 * overpopulation does not kill eggs.
  14. 	 */
  15. 	return (boolean)
  16. 		(m_idx >= LOW_PM &&
  17. 		 ((mvitals[m_idx].mvflags & G_GENOD) != 0 ||
  18. 		  (egg &&
  19. 		   (mvitals[big_to_little(m_idx)].mvflags & G_GENOD) != 0)));
  20. }

kill_eggs[edit]

  1. /* kill off any eggs of genocided monsters */
  2. STATIC_OVL void
  3. kill_eggs(obj_list)
  4. struct obj *obj_list;
  5. {
  6. 	struct obj *otmp;
  7.  
  8. 	for (otmp = obj_list; otmp; otmp = otmp->nobj)
  9. 	    if (otmp->otyp == EGG) {
  10. 		if (dead_species(otmp->corpsenm, TRUE)) {
  11. 		    /*
  12. 		     * It seems we could also just catch this when
  13. 		     * it attempted to hatch, so we wouldn't have to
  14. 		     * search all of the objlists.. or stop all
  15. 		     * hatch timers based on a corpsenm.
  16. 		     */
  17. 		    kill_egg(otmp);
  18. 		}
  19. #if 0	/* not used */
  20. 	    } else if (otmp->otyp == TIN) {
  21. 		if (dead_species(otmp->corpsenm, FALSE))
  22. 		    otmp->corpsenm = NON_PM;	/* empty tin */
  23. 	    } else if (otmp->otyp == CORPSE) {
  24. 		if (dead_species(otmp->corpsenm, FALSE))
  25. 		    ;		/* not yet implemented... */
  26. #endif
  27. 	    } else if (Has_contents(otmp)) {
  28. 		kill_eggs(otmp->cobj);
  29. 	    }
  30. }

kill_genocided_monsters[edit]

  1. /* kill all members of genocided species */
  2. void
  3. kill_genocided_monsters()
  4. {
  5. 	struct monst *mtmp, *mtmp2;
  6. 	boolean kill_cham[CHAM_MAX_INDX+1];
  7. 	int mndx;
  8.  
  9. 	kill_cham[CHAM_ORDINARY] = FALSE;	/* (this is mndx==0) */
  10. 	for (mndx = 1; mndx <= CHAM_MAX_INDX; mndx++)
  11. 	  kill_cham[mndx] = (mvitals[cham_to_pm[mndx]].mvflags & G_GENOD) != 0;
  12. 	/*
  13. 	 * Called during genocide, and again upon level change.  The latter
  14. 	 * catches up with any migrating monsters as they finally arrive at
  15. 	 * their intended destinations, so possessions get deposited there.
  16. 	 *
  17. 	 * Chameleon handling:
  18. 	 *	1) if chameleons have been genocided, destroy them
  19. 	 *	   regardless of current form;
  20. 	 *	2) otherwise, force every chameleon which is imitating
  21. 	 *	   any genocided species to take on a new form.
  22. 	 */
  23. 	for (mtmp = fmon; mtmp; mtmp = mtmp2) {
  24. 	    mtmp2 = mtmp->nmon;
  25. 	    if (DEADMONSTER(mtmp)) continue;
  26. 	    mndx = monsndx(mtmp->data);
  27. 	    if ((mvitals[mndx].mvflags & G_GENOD) || kill_cham[mtmp->cham]) {
  28. 		if (mtmp->cham && !kill_cham[mtmp->cham])
  29. 		    (void) newcham(mtmp, (struct permonst *)0, FALSE, FALSE);
  30. 		else
  31. 		    mondead(mtmp);
  32. 	    }
  33. 	    if (mtmp->minvent) kill_eggs(mtmp->minvent);
  34. 	}
  35.  
  36. 	kill_eggs(invent);
  37. 	kill_eggs(fobj);
  38. 	kill_eggs(level.buriedobjlist);
  39. }
  40.  
  41. #endif /* OVL2 */
  42. #ifdef OVLB

golemeffects[edit]

  1. void
  2. golemeffects(mon, damtype, dam)
  3. register struct monst *mon;
  4. int damtype, dam;
  5. {
  6. int heal = 0, slow = 0;
  7.  
  8. if (mon->data == &mons[PM_FLESH_GOLEM]) {
  9. 	if (damtype == AD_ELEC) heal = dam / 6;
  10. 	else if (damtype == AD_FIRE || damtype == AD_COLD) slow = 1;
  11. } else if (mon->data == &mons[PM_IRON_GOLEM]) {
  12. 	if (damtype == AD_ELEC) slow = 1;
  13. 	else if (damtype == AD_FIRE) heal = dam;
  14. } else {
  15. 	return;
  16. }
  17. if (slow) {
  18. 	if (mon->mspeed != MSLOW)
  19. 	    mon_adjust_speed(mon, -1, (struct obj *)0);
  20. }
  21. if (heal) {
  22. 	if (mon->mhp < mon->mhpmax) {
  23. 	    mon->mhp += dam;
  24. 	    if (mon->mhp > mon->mhpmax) mon->mhp = mon->mhpmax;
  25. 	    if (cansee(mon->mx, mon->my))
  26. 		pline("%s seems healthier.", Monnam(mon));
  27. 	}
  28. }
  29. }

angry_guards[edit]

  1. boolean
  2. angry_guards(silent)
  3. register boolean silent;
  4. {
  5. 	register struct monst *mtmp;
  6. 	register int ct = 0, nct = 0, sct = 0, slct = 0;
  7.  
  8. 	for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  9. 		if (DEADMONSTER(mtmp)) continue;
  10. 		if((mtmp->data == &mons[PM_WATCHMAN] ||
  11. 			       mtmp->data == &mons[PM_WATCH_CAPTAIN])
  12. 					&& mtmp->mpeaceful) {
  13. 			ct++;
  14. 			if(cansee(mtmp->mx, mtmp->my) && mtmp->mcanmove) {
  15. 				if (distu(mtmp->mx, mtmp->my) == 2) nct++;
  16. 				else sct++;
  17. 			}
  18. 			if (mtmp->msleeping || mtmp->mfrozen) {
  19. 				slct++;
  20. 				mtmp->msleeping = mtmp->mfrozen = 0;
  21. 			}
  22. 			mtmp->mpeaceful = 0;
  23. 		}
  24. 	}
  25. 	if(ct) {
  26. 	    if(!silent) { /* do we want pline msgs? */
  27. 		if(slct) pline_The("guard%s wake%s up!",
  28. 				 slct > 1 ? "s" : "", slct == 1 ? "s" : "");
  29. 		if(nct || sct) {
  30. 			if(nct) pline_The("guard%s get%s angry!",
  31. 				nct == 1 ? "" : "s", nct == 1 ? "s" : "");
  32. 			else if(!Blind)
  33. 				You("see %sangry guard%s approaching!",
  34. 				  sct == 1 ? "an " : "", sct > 1 ? "s" : "");
  35. 		} else if(flags.soundok)
  36. 			You_hear("the shrill sound of a guard's whistle.");
  37. 	    }
  38. 	    return(TRUE);
  39. 	}
  40. 	return(FALSE);
  41. }

pacify_guards[edit]

  1. void
  2. pacify_guards()
  3. {
  4. 	register struct monst *mtmp;
  5.  
  6. 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  7. 	    if (DEADMONSTER(mtmp)) continue;
  8. 	    if (mtmp->data == &mons[PM_WATCHMAN] ||
  9. 		mtmp->data == &mons[PM_WATCH_CAPTAIN])
  10. 	    mtmp->mpeaceful = 1;
  11. 	}
  12. }

mimic_hit_msg[edit]

  1. void
  2. mimic_hit_msg(mtmp, otyp)
  3. struct monst *mtmp;
  4. short otyp;
  5. {
  6. 	short ap = mtmp->mappearance;
  7.  
  8. 	switch(mtmp->m_ap_type) {
  9. 	    case M_AP_NOTHING:			
  10. 	    case M_AP_FURNITURE:
  11. 	    case M_AP_MONSTER:
  12. 		break;
  13. 	    case M_AP_OBJECT:
  14. 		if (otyp == SPE_HEALING || otyp == SPE_EXTRA_HEALING) {
  15. 		    pline("%s seems a more vivid %s than before.",
  16. 				The(simple_typename(ap)),
  17. 				c_obj_colors[objects[ap].oc_color]);
  18. 		}
  19. 		break;
  20. 	}
  21. }
  22. #endif /* OVLB */
  23.  
  24. /*mon.c*/