Source:NetHack 3.4.3/src/muse.c

From NetHackWiki
(Redirected from Source:Ref/precheck)
Jump to: navigation, search

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

Top of file

  1. /*	SCCS Id: @(#)muse.c	3.4	2002/12/23	*/
  2. /*	Copyright (C) 1990 by Ken Arromdee			   */
  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. /*
  2. * Monster item usage routines.
  3. */
  4.  
  5. #include "hack.h"
  6. #include "edog.h"
  7.  
  8. extern const int monstr[];
  9.  
  10. boolean m_using = FALSE;
  11.  
  12. /* Let monsters use magic items.  Arbitrary assumptions: Monsters only use
  13. * scrolls when they can see, monsters know when wands have 0 charges, monsters
  14. * cannot recognize if items are cursed are not, monsters which are confused
  15. * don't know not to read scrolls, etc....
  16. */
  17.  
  18. STATIC_DCL struct permonst *FDECL(muse_newcham_mon, (struct monst *));
  19. STATIC_DCL int FDECL(precheck, (struct monst *,struct obj *));
  20. STATIC_DCL void FDECL(mzapmsg, (struct monst *,struct obj *,BOOLEAN_P));
  21. STATIC_DCL void FDECL(mreadmsg, (struct monst *,struct obj *));
  22. STATIC_DCL void FDECL(mquaffmsg, (struct monst *,struct obj *));
  23. STATIC_PTR int FDECL(mbhitm, (struct monst *,struct obj *));
  24. STATIC_DCL void FDECL(mbhit,
  25. 	(struct monst *,int,int FDECL((*),(MONST_P,OBJ_P)),
  26. 	int FDECL((*),(OBJ_P,OBJ_P)),struct obj *));
  27. STATIC_DCL void FDECL(you_aggravate, (struct monst *));
  28. STATIC_DCL void FDECL(mon_consume_unstone, (struct monst *,struct obj *,
  29. 	BOOLEAN_P,BOOLEAN_P));
  30.  
  31. static struct musable {
  32. 	struct obj *offensive;
  33. 	struct obj *defensive;
  34. 	struct obj *misc;
  35. 	int has_offense, has_defense, has_misc;
  36. 	/* =0, no capability; otherwise, different numbers.
  37. 	 * If it's an object, the object is also set (it's 0 otherwise).
  38. 	 */
  39. } m;
  40. static int trapx, trapy;
  41. static boolean zap_oseen;
  42. 	/* for wands which use mbhitm and are zapped at players.  We usually
  43. 	 * want an oseen local to the function, but this is impossible since the
  44. 	 * function mbhitm has to be compatible with the normal zap routines,
  45. 	 * and those routines don't remember who zapped the wand.
  46. 	 */

precheck

  1. /* Any preliminary checks which may result in the monster being unable to use
  2. * the item.  Returns 0 if nothing happened, 2 if the monster can't do anything
  3. * (i.e. it teleported) and 1 if it's dead.
  4. */
  5. STATIC_OVL int
  6. precheck(mon, obj)
  7. struct monst *mon;
  8. struct obj *obj;
  9. {
  10. 	boolean vis;
  11.  
  12. 	if (!obj) return 0;
  13. 	vis = cansee(mon->mx, mon->my);
  14.  
  15. 	if (obj->oclass == POTION_CLASS) {
  16. 	    coord cc;
  17. 	    static const char *empty = "The potion turns out to be empty.";
  18. 	    const char *potion_descr;
  19. 	    struct monst *mtmp;
  20. #define POTION_OCCUPANT_CHANCE(n) (13 + 2*(n))	/* also in potion.c */
  21.  
  22. 	    potion_descr = OBJ_DESCR(objects[obj->otyp]);
  23. 	    if (potion_descr && !strcmp(potion_descr, "milky")) {
  24. 	        if ( flags.ghost_count < MAXMONNO &&
  25. 		    !rn2(POTION_OCCUPANT_CHANCE(flags.ghost_count))) {
  26. 		    if (!enexto(&cc, mon->mx, mon->my, &mons[PM_GHOST])) return 0;
  27. 		    mquaffmsg(mon, obj);
  28. 		    m_useup(mon, obj);
  29. 		    mtmp = makemon(&mons[PM_GHOST], cc.x, cc.y, NO_MM_FLAGS);
  30. 		    if (!mtmp) {
  31. 			if (vis) pline(empty);
  32. 		    } else {
  33. 			if (vis) {
  34. 			    pline("As %s opens the bottle, an enormous %s emerges!",
  35. 			       mon_nam(mon),
  36. 			       Hallucination ? rndmonnam() : (const char *)"ghost");
  37. 			    pline("%s is frightened to death, and unable to move.",
  38. 				    Monnam(mon));
  39. 			}
  40. 			mon->mcanmove = 0;
  41. 			mon->mfrozen = 3;
  42. 		    }
  43. 		    return 2;
  44. 		}
  45. 	    }
  46. 	    if (potion_descr && !strcmp(potion_descr, "smoky") &&
  47. 		    flags.djinni_count < MAXMONNO &&
  48. 		    !rn2(POTION_OCCUPANT_CHANCE(flags.djinni_count))) {
  49. 		if (!enexto(&cc, mon->mx, mon->my, &mons[PM_DJINNI])) return 0;
  50. 		mquaffmsg(mon, obj);
  51. 		m_useup(mon, obj);
  52. 		mtmp = makemon(&mons[PM_DJINNI], cc.x, cc.y, NO_MM_FLAGS);
  53. 		if (!mtmp) {
  54. 		    if (vis) pline(empty);
  55. 		} else {
  56. 		    if (vis)
  57. 			pline("In a cloud of smoke, %s emerges!",
  58. 							a_monnam(mtmp));
  59. 		    pline("%s speaks.", vis ? Monnam(mtmp) : Something);
  60. 		/* I suspect few players will be upset that monsters */
  61. 		/* can't wish for wands of death here.... */
  62. 		    if (rn2(2)) {
  63. 			verbalize("You freed me!");
  64. 			mtmp->mpeaceful = 1;
  65. 			set_malign(mtmp);
  66. 		    } else {
  67. 			verbalize("It is about time.");
  68. 			if (vis) pline("%s vanishes.", Monnam(mtmp));
  69. 			mongone(mtmp);
  70. 		    }
  71. 		}
  72. 		return 2;
  73. 	    }
  74. 	}
  75. 	if (obj->oclass == WAND_CLASS && obj->cursed && !rn2(100)) {
  76. 	    int dam = d(obj->spe+2, 6);
  77.  
  78. 	    if (flags.soundok) {
  79. 		if (vis) pline("%s zaps %s, which suddenly explodes!",
  80. 			Monnam(mon), an(xname(obj)));
  81. 		else You_hear("a zap and an explosion in the distance.");
  82. 	    }
  83. 	    m_useup(mon, obj);
  84. 	    if (mon->mhp <= dam) {
  85. 		monkilled(mon, "", AD_RBRE);
  86. 		return 1;
  87. 	    }
  88. 	    else mon->mhp -= dam;
  89. 	    m.has_defense = m.has_offense = m.has_misc = 0;
  90. 	    /* Only one needed to be set to 0 but the others are harmless */
  91. 	}
  92. 	return 0;
  93. }

mzapmsg

  1. STATIC_OVL void
  2. mzapmsg(mtmp, otmp, self)
  3. struct monst *mtmp;
  4. struct obj *otmp;
  5. boolean self;
  6. {
  7. 	if (!canseemon(mtmp)) {
  8. 		if (flags.soundok)
  9. 			You_hear("a %s zap.",
  10. 					(distu(mtmp->mx,mtmp->my) <= (BOLT_LIM+1)*(BOLT_LIM+1)) ?
  11. 					"nearby" : "distant");
  12. 	} else if (self)
  13. 		pline("%s zaps %sself with %s!",
  14. 		      Monnam(mtmp), mhim(mtmp), doname(otmp));
  15. 	else {
  16. 		pline("%s zaps %s!", Monnam(mtmp), an(xname(otmp)));
  17. 		stop_occupation();
  18. 	}
  19. }

mreadmsg

  1. STATIC_OVL void
  2. mreadmsg(mtmp, otmp)
  3. struct monst *mtmp;
  4. struct obj *otmp;
  5. {
  6. 	boolean vismon = canseemon(mtmp);
  7. 	char onambuf[BUFSZ];
  8. 	short saverole;
  9. 	unsigned savebknown;
  10.  
  11. 	if (!vismon && !flags.soundok)
  12. 	    return;		/* no feedback */
  13.  
  14. 	otmp->dknown = 1;  /* seeing or hearing it read reveals its label */
  15. 	/* shouldn't be able to hear curse/bless status of unseen scrolls;
  16. 	   for priest characters, bknown will always be set during naming */
  17. 	savebknown = otmp->bknown;
  18. 	saverole = Role_switch;
  19. 	if (!vismon) {
  20. 	    otmp->bknown = 0;
  21. 	    if (Role_if(PM_PRIEST)) Role_switch = 0;
  22. 	}
  23. 	Strcpy(onambuf, singular(otmp, doname));
  24. 	Role_switch = saverole;
  25. 	otmp->bknown = savebknown;
  26.  
  27. 	if (vismon)
  28. 	    pline("%s reads %s!", Monnam(mtmp), onambuf);
  29. 	else
  30. 	    You_hear("%s reading %s.",
  31. 		x_monnam(mtmp, ARTICLE_A, (char *)0,
  32. 		    (SUPPRESS_IT|SUPPRESS_INVISIBLE|SUPPRESS_SADDLE), FALSE),
  33. 		onambuf);
  34.  
  35. 	if (mtmp->mconf)
  36. 	    pline("Being confused, %s mispronounces the magic words...",
  37. 		  vismon ? mon_nam(mtmp) : mhe(mtmp));
  38. }

mquaffmsg

  1. STATIC_OVL void
  2. mquaffmsg(mtmp, otmp)
  3. struct monst *mtmp;
  4. struct obj *otmp;
  5. {
  6. 	if (canseemon(mtmp)) {
  7. 		otmp->dknown = 1;
  8. 		pline("%s drinks %s!", Monnam(mtmp), singular(otmp, doname));
  9. 	} else
  10. 		if (flags.soundok)
  11. 			You_hear("a chugging sound.");
  12. }
  13.  
  14. /* Defines for various types of stuff.  The order in which monsters prefer
  15. * to use them is determined by the order of the code logic, not the
  16. * numerical order in which they are defined.
  17. */
  18. #define MUSE_SCR_TELEPORTATION 1
  19. #define MUSE_WAN_TELEPORTATION_SELF 2
  20. #define MUSE_POT_HEALING 3
  21. #define MUSE_POT_EXTRA_HEALING 4
  22. #define MUSE_WAN_DIGGING 5
  23. #define MUSE_TRAPDOOR 6
  24. #define MUSE_TELEPORT_TRAP 7
  25. #define MUSE_UPSTAIRS 8
  26. #define MUSE_DOWNSTAIRS 9
  27. #define MUSE_WAN_CREATE_MONSTER 10
  28. #define MUSE_SCR_CREATE_MONSTER 11
  29. #define MUSE_UP_LADDER 12
  30. #define MUSE_DN_LADDER 13
  31. #define MUSE_SSTAIRS 14
  32. #define MUSE_WAN_TELEPORTATION 15
  33. #define MUSE_BUGLE 16
  34. #define MUSE_UNICORN_HORN 17
  35. #define MUSE_POT_FULL_HEALING 18
  36. #define MUSE_LIZARD_CORPSE 19
  37. /*
  38. #define MUSE_INNATE_TPT 9999
  39. * We cannot use this.  Since monsters get unlimited teleportation, if they
  40. * were allowed to teleport at will you could never catch them.  Instead,
  41. * assume they only teleport at random times, despite the inconsistency that if
  42. * you polymorph into one you teleport at will.
  43. */

find_defensive

  1. /* Select a defensive item/action for a monster.  Returns TRUE iff one is
  2. * found.
  3. */
  4. boolean
  5. find_defensive(mtmp)
  6. struct monst *mtmp;
  7. {
  8. 	register struct obj *obj = 0;
  9. 	struct trap *t;
  10. 	int x=mtmp->mx, y=mtmp->my;
  11. 	boolean stuck = (mtmp == u.ustuck);
  12. 	boolean immobile = (mtmp->data->mmove == 0);
  13. 	int fraction;
  14.  
  15. 	if (is_animal(mtmp->data) || mindless(mtmp->data))
  16. 		return FALSE;
  17. 	if(dist2(x, y, mtmp->mux, mtmp->muy) > 25)
  18. 		return FALSE;
  19. 	if (u.uswallow && stuck) return FALSE;
  20.  
  21. 	m.defensive = (struct obj *)0;
  22. 	m.has_defense = 0;
  23.  
  24. 	/* since unicorn horns don't get used up, the monster would look
  25. 	 * silly trying to use the same cursed horn round after round
  26. 	 */
  27. 	if (mtmp->mconf || mtmp->mstun || !mtmp->mcansee) {
  28. 	    if (!is_unicorn(mtmp->data) && !nohands(mtmp->data)) {
  29. 		for(obj = mtmp->minvent; obj; obj = obj->nobj)
  30. 		    if (obj->otyp == UNICORN_HORN && !obj->cursed)
  31. 			break;
  32. 	    }
  33. 	    if (obj || is_unicorn(mtmp->data)) {
  34. 		m.defensive = obj;
  35. 		m.has_defense = MUSE_UNICORN_HORN;
  36. 		return TRUE;
  37. 	    }
  38. 	}
  39.  
  40. 	if (mtmp->mconf) {
  41. 	    for(obj = mtmp->minvent; obj; obj = obj->nobj) {
  42. 		if (obj->otyp == CORPSE && obj->corpsenm == PM_LIZARD) {
  43. 		    m.defensive = obj;
  44. 		    m.has_defense = MUSE_LIZARD_CORPSE;
  45. 		    return TRUE;
  46. 		}
  47. 	    }
  48. 	}
  49.  
  50. 	/* It so happens there are two unrelated cases when we might want to
  51. 	 * check specifically for healing alone.  The first is when the monster
  52. 	 * is blind (healing cures blindness).  The second is when the monster
  53. 	 * is peaceful; then we don't want to flee the player, and by
  54. 	 * coincidence healing is all there is that doesn't involve fleeing.
  55. 	 * These would be hard to combine because of the control flow.
  56. 	 * Pestilence won't use healing even when blind.
  57. 	 */
  58. 	if (!mtmp->mcansee && !nohands(mtmp->data) &&
  59. 		mtmp->data != &mons[PM_PESTILENCE]) {
  60. 	    if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) {
  61. 		m.defensive = obj;
  62. 		m.has_defense = MUSE_POT_FULL_HEALING;
  63. 		return TRUE;
  64. 	    }
  65. 	    if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) {
  66. 		m.defensive = obj;
  67. 		m.has_defense = MUSE_POT_EXTRA_HEALING;
  68. 		return TRUE;
  69. 	    }
  70. 	    if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) {
  71. 		m.defensive = obj;
  72. 		m.has_defense = MUSE_POT_HEALING;
  73. 		return TRUE;
  74. 	    }
  75. 	}
  76.  
  77. 	fraction = u.ulevel < 10 ? 5 : u.ulevel < 14 ? 4 : 3;
  78. 	if(mtmp->mhp >= mtmp->mhpmax ||
  79. 			(mtmp->mhp >= 10 && mtmp->mhp*fraction >= mtmp->mhpmax))
  80. 		return FALSE;
  81.  
  82. 	if (mtmp->mpeaceful) {
  83. 	    if (!nohands(mtmp->data)) {
  84. 		if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) {
  85. 		    m.defensive = obj;
  86. 		    m.has_defense = MUSE_POT_FULL_HEALING;
  87. 		    return TRUE;
  88. 		}
  89. 		if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) {
  90. 		    m.defensive = obj;
  91. 		    m.has_defense = MUSE_POT_EXTRA_HEALING;
  92. 		    return TRUE;
  93. 		}
  94. 		if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) {
  95. 		    m.defensive = obj;
  96. 		    m.has_defense = MUSE_POT_HEALING;
  97. 		    return TRUE;
  98. 		}
  99. 	    }
  100. 	    return FALSE;
  101. 	}
  102.  
  103. 	if (levl[x][y].typ == STAIRS && !stuck && !immobile) {
  104. 		if (x == xdnstair && y == ydnstair && !is_floater(mtmp->data))
  105. 			m.has_defense = MUSE_DOWNSTAIRS;
  106. 		if (x == xupstair && y == yupstair && ledger_no(&u.uz) != 1)
  107. 	/* Unfair to let the monsters leave the dungeon with the Amulet */
  108. 	/* (or go to the endlevel since you also need it, to get there) */
  109. 			m.has_defense = MUSE_UPSTAIRS;
  110. 	} else if (levl[x][y].typ == LADDER && !stuck && !immobile) {
  111. 		if (x == xupladder && y == yupladder)
  112. 			m.has_defense = MUSE_UP_LADDER;
  113. 		if (x == xdnladder && y == ydnladder && !is_floater(mtmp->data))
  114. 			m.has_defense = MUSE_DN_LADDER;
  115. 	} else if (sstairs.sx && sstairs.sx == x && sstairs.sy == y) {
  116. 		m.has_defense = MUSE_SSTAIRS;
  117. 	} else if (!stuck && !immobile) {
  118. 	/* Note: trap doors take precedence over teleport traps. */
  119. 		int xx, yy;
  120.  
  121. 		for(xx = x-1; xx <= x+1; xx++) for(yy = y-1; yy <= y+1; yy++)
  122. 		if (isok(xx,yy))
  123. 		if (xx != u.ux && yy != u.uy)
  124. 		if (mtmp->data != &mons[PM_GRID_BUG] || xx == x || yy == y)
  125. 		if ((xx==x && yy==y) || !level.monsters[xx][yy])
  126. 		if ((t = t_at(xx,yy)) != 0)
  127. 		if ((verysmall(mtmp->data) || throws_rocks(mtmp->data) ||
  128. 		     passes_walls(mtmp->data)) || !sobj_at(BOULDER, xx, yy))
  129. 		if (!onscary(xx,yy,mtmp)) {
  130. 			if ((t->ttyp == TRAPDOOR || t->ttyp == HOLE)
  131. 				&& !is_floater(mtmp->data)
  132. 				&& !mtmp->isshk && !mtmp->isgd
  133. 				&& !mtmp->ispriest
  134. 				&& Can_fall_thru(&u.uz)
  135. 						) {
  136. 				trapx = xx;
  137. 				trapy = yy;
  138. 				m.has_defense = MUSE_TRAPDOOR;
  139. 			} else if (t->ttyp == TELEP_TRAP && m.has_defense != MUSE_TRAPDOOR) {
  140. 				trapx = xx;
  141. 				trapy = yy;
  142. 				m.has_defense = MUSE_TELEPORT_TRAP;
  143. 			}
  144. 		}
  145. 	}
  146.  
  147. 	if (nohands(mtmp->data))	/* can't use objects */
  148. 		goto botm;
  149.  
  150. 	if (is_mercenary(mtmp->data) && (obj = m_carrying(mtmp, BUGLE))) {
  151. 		int xx, yy;
  152. 		struct monst *mon;
  153.  
  154. 		/* Distance is arbitrary.  What we really want to do is
  155. 		 * have the soldier play the bugle when it sees or
  156. 		 * remembers soldiers nearby...
  157. 		 */
  158. 		for(xx = x-3; xx <= x+3; xx++) for(yy = y-3; yy <= y+3; yy++)
  159. 		if (isok(xx,yy))
  160. 		if ((mon = m_at(xx,yy)) && is_mercenary(mon->data) &&
  161. 				mon->data != &mons[PM_GUARD] &&
  162. 				(mon->msleeping || (!mon->mcanmove))) {
  163. 			m.defensive = obj;
  164. 			m.has_defense = MUSE_BUGLE;
  165. 		}
  166. 	}
  167.  
  168. 	/* use immediate physical escape prior to attempting magic */
  169. 	if (m.has_defense)    /* stairs, trap door or tele-trap, bugle alert */
  170. 		goto botm;
  171.  
  172. 	/* kludge to cut down on trap destruction (particularly portals) */
  173. 	t = t_at(x,y);
  174. 	if (t && (t->ttyp == PIT || t->ttyp == SPIKED_PIT ||
  175. 		  t->ttyp == WEB || t->ttyp == BEAR_TRAP))
  176. 		t = 0;		/* ok for monster to dig here */
  177.  
  178. #define nomore(x) if(m.has_defense==x) continue;
  179. 	for (obj = mtmp->minvent; obj; obj = obj->nobj) {
  180. 		/* don't always use the same selection pattern */
  181. 		if (m.has_defense && !rn2(3)) break;
  182.  
  183. 		/* nomore(MUSE_WAN_DIGGING); */
  184. 		if (m.has_defense == MUSE_WAN_DIGGING) break;
  185. 		if (obj->otyp == WAN_DIGGING && obj->spe > 0 && !stuck && !t
  186. 		    && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest
  187. 		    && !is_floater(mtmp->data)
  188. 		    /* monsters digging in Sokoban can ruin things */
  189. 		    && !In_sokoban(&u.uz)
  190. 		    /* digging wouldn't be effective; assume they know that */
  191. 		    && !(levl[x][y].wall_info & W_NONDIGGABLE)
  192. 		    && !(Is_botlevel(&u.uz) || In_endgame(&u.uz))
  193. 		    && !(is_ice(x,y) || is_pool(x,y) || is_lava(x,y))
  194. 		    && !(mtmp->data == &mons[PM_VLAD_THE_IMPALER]
  195. 			 && In_V_tower(&u.uz))) {
  196. 			m.defensive = obj;
  197. 			m.has_defense = MUSE_WAN_DIGGING;
  198. 		}
  199. 		nomore(MUSE_WAN_TELEPORTATION_SELF);
  200. 		nomore(MUSE_WAN_TELEPORTATION);
  201. 		if(obj->otyp == WAN_TELEPORTATION && obj->spe > 0) {
  202. 		    /* use the TELEP_TRAP bit to determine if they know
  203. 		     * about noteleport on this level or not.  Avoids
  204. 		     * ineffective re-use of teleportation.  This does
  205. 		     * mean if the monster leaves the level, they'll know
  206. 		     * about teleport traps.
  207. 		     */
  208. 		    if (!level.flags.noteleport ||
  209. 			!(mtmp->mtrapseen & (1 << (TELEP_TRAP-1)))) {
  210. 			m.defensive = obj;
  211. 			m.has_defense = (mon_has_amulet(mtmp))
  212. 				? MUSE_WAN_TELEPORTATION
  213. 				: MUSE_WAN_TELEPORTATION_SELF;
  214. 		    }
  215. 		}
  216. 		nomore(MUSE_SCR_TELEPORTATION);
  217. 		if(obj->otyp == SCR_TELEPORTATION && mtmp->mcansee
  218. 		   && haseyes(mtmp->data)
  219. 		   && (!obj->cursed ||
  220. 		       (!(mtmp->isshk && inhishop(mtmp))
  221. 			    && !mtmp->isgd && !mtmp->ispriest))) {
  222. 		    /* see WAN_TELEPORTATION case above */
  223. 		    if (!level.flags.noteleport ||
  224. 			!(mtmp->mtrapseen & (1 << (TELEP_TRAP-1)))) {
  225. 			m.defensive = obj;
  226. 			m.has_defense = MUSE_SCR_TELEPORTATION;
  227. 		    }
  228. 		}
  229.  
  230. 	    if (mtmp->data != &mons[PM_PESTILENCE]) {
  231. 		nomore(MUSE_POT_FULL_HEALING);
  232. 		if(obj->otyp == POT_FULL_HEALING) {
  233. 			m.defensive = obj;
  234. 			m.has_defense = MUSE_POT_FULL_HEALING;
  235. 		}
  236. 		nomore(MUSE_POT_EXTRA_HEALING);
  237. 		if(obj->otyp == POT_EXTRA_HEALING) {
  238. 			m.defensive = obj;
  239. 			m.has_defense = MUSE_POT_EXTRA_HEALING;
  240. 		}
  241. 		nomore(MUSE_WAN_CREATE_MONSTER);
  242. 		if(obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) {
  243. 			m.defensive = obj;
  244. 			m.has_defense = MUSE_WAN_CREATE_MONSTER;
  245. 		}
  246. 		nomore(MUSE_POT_HEALING);
  247. 		if(obj->otyp == POT_HEALING) {
  248. 			m.defensive = obj;
  249. 			m.has_defense = MUSE_POT_HEALING;
  250. 		}
  251. 	    } else {	/* Pestilence */
  252. 		nomore(MUSE_POT_FULL_HEALING);
  253. 		if (obj->otyp == POT_SICKNESS) {
  254. 			m.defensive = obj;
  255. 			m.has_defense = MUSE_POT_FULL_HEALING;
  256. 		}
  257. 		nomore(MUSE_WAN_CREATE_MONSTER);
  258. 		if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) {
  259. 			m.defensive = obj;
  260. 			m.has_defense = MUSE_WAN_CREATE_MONSTER;
  261. 		}
  262. 	    }
  263. 		nomore(MUSE_SCR_CREATE_MONSTER);
  264. 		if(obj->otyp == SCR_CREATE_MONSTER) {
  265. 			m.defensive = obj;
  266. 			m.has_defense = MUSE_SCR_CREATE_MONSTER;
  267. 		}
  268. 	}
  269. botm:	return((boolean)(!!m.has_defense));
  270. #undef nomore
  271. }

use_defensive

  1. /* Perform a defensive action for a monster.  Must be called immediately
  2. * after find_defensive().  Return values are 0: did something, 1: died,
  3. * 2: did something and can't attack again (i.e. teleported).
  4. */
  5. int
  6. use_defensive(mtmp)
  7. struct monst *mtmp;
  8. {
  9. 	int i, fleetim, how = 0;
  10. 	struct obj *otmp = m.defensive;
  11. 	boolean vis, vismon, oseen;
  12. 	const char *mcsa = "%s can see again.";
  13.  
  14. 	if ((i = precheck(mtmp, otmp)) != 0) return i;
  15. 	vis = cansee(mtmp->mx, mtmp->my);
  16. 	vismon = canseemon(mtmp);
  17. 	oseen = otmp && vismon;
  18.  
  19. 	/* when using defensive choice to run away, we want monster to avoid
  20. 	   rushing right straight back; don't override if already scared */
  21. 	fleetim = !mtmp->mflee ? (33 - (30 * mtmp->mhp / mtmp->mhpmax)) : 0;
  22. #define m_flee(m)	if (fleetim && !m->iswiz) \
  23. 			{ monflee(m, fleetim, FALSE, FALSE); }
  24.  
  25. 	switch(m.has_defense) {
  26. 	case MUSE_UNICORN_HORN:
  27. 		if (vismon) {
  28. 		    if (otmp)
  29. 			pline("%s uses a unicorn horn!", Monnam(mtmp));
  30. 		    else
  31. 			pline_The("tip of %s's horn glows!", mon_nam(mtmp));
  32. 		}
  33. 		if (!mtmp->mcansee) {
  34. 		    mtmp->mcansee = 1;
  35. 		    mtmp->mblinded = 0;
  36. 		    if (vismon) pline(mcsa, Monnam(mtmp));
  37. 		} else if (mtmp->mconf || mtmp->mstun) {
  38. 		    mtmp->mconf = mtmp->mstun = 0;
  39. 		    if (vismon)
  40. 			pline("%s seems steadier now.", Monnam(mtmp));
  41. 		} else impossible("No need for unicorn horn?");
  42. 		return 2;
  43. 	case MUSE_BUGLE:
  44. 		if (vismon)
  45. 			pline("%s plays %s!", Monnam(mtmp), doname(otmp));
  46. 		else if (flags.soundok)
  47. 			You_hear("a bugle playing reveille!");
  48. 		awaken_soldiers();
  49. 		return 2;
  50. 	case MUSE_WAN_TELEPORTATION_SELF:
  51. 		if ((mtmp->isshk && inhishop(mtmp))
  52. 		       || mtmp->isgd || mtmp->ispriest) return 2;
  53. 		m_flee(mtmp);
  54. 		mzapmsg(mtmp, otmp, TRUE);
  55. 		otmp->spe--;
  56. 		how = WAN_TELEPORTATION;
  57. mon_tele:
  58. 		if (tele_restrict(mtmp)) {	/* mysterious force... */
  59. 		    if (vismon && how)		/* mentions 'teleport' */
  60. 			makeknown(how);
  61. 		    /* monster learns that teleportation isn't useful here */
  62. 		    if (level.flags.noteleport)
  63. 			mtmp->mtrapseen |= (1 << (TELEP_TRAP-1));
  64. 		    return 2;
  65. 		}
  66. 		if ((
  67. #if 0
  68. 			mon_has_amulet(mtmp) ||
  69. #endif
  70. 			On_W_tower_level(&u.uz)) && !rn2(3)) {
  71. 		    if (vismon)
  72. 			pline("%s seems disoriented for a moment.",
  73. 				Monnam(mtmp));
  74. 		    return 2;
  75. 		}
  76. 		if (oseen && how) makeknown(how);
  77. 		(void) rloc(mtmp, FALSE);
  78. 		return 2;
  79. 	case MUSE_WAN_TELEPORTATION:
  80. 		zap_oseen = oseen;
  81. 		mzapmsg(mtmp, otmp, FALSE);
  82. 		otmp->spe--;
  83. 		m_using = TRUE;
  84. 		mbhit(mtmp,rn1(8,6),mbhitm,bhito,otmp);
  85. 		/* monster learns that teleportation isn't useful here */
  86. 		if (level.flags.noteleport)
  87. 		    mtmp->mtrapseen |= (1 << (TELEP_TRAP-1));
  88. 		m_using = FALSE;
  89. 		return 2;
  90. 	case MUSE_SCR_TELEPORTATION:
  91. 	    {
  92. 		int obj_is_cursed = otmp->cursed;
  93.  
  94. 		if (mtmp->isshk || mtmp->isgd || mtmp->ispriest) return 2;
  95. 		m_flee(mtmp);
  96. 		mreadmsg(mtmp, otmp);
  97. 		m_useup(mtmp, otmp);	/* otmp might be free'ed */
  98. 		how = SCR_TELEPORTATION;
  99. 		if (obj_is_cursed || mtmp->mconf) {
  100. 			int nlev;
  101. 			d_level flev;
  102.  
  103. 			if (mon_has_amulet(mtmp) || In_endgame(&u.uz)) {
  104. 			    if (vismon)
  105. 				pline("%s seems very disoriented for a moment.",
  106. 					Monnam(mtmp));
  107. 			    return 2;
  108. 			}
  109. 			nlev = random_teleport_level();
  110. 			if (nlev == depth(&u.uz)) {
  111. 			    if (vismon)
  112. 				pline("%s shudders for a moment.",
  113. 								Monnam(mtmp));
  114. 			    return 2;
  115. 			}
  116. 			get_level(&flev, nlev);
  117. 			migrate_to_level(mtmp, ledger_no(&flev), MIGR_RANDOM,
  118. 				(coord *)0);
  119. 			if (oseen) makeknown(SCR_TELEPORTATION);
  120. 		} else goto mon_tele;
  121. 		return 2;
  122. 	    }
  123. 	case MUSE_WAN_DIGGING:
  124. 	    {	struct trap *ttmp;
  125.  
  126. 		m_flee(mtmp);
  127. 		mzapmsg(mtmp, otmp, FALSE);
  128. 		otmp->spe--;
  129. 		if (oseen) makeknown(WAN_DIGGING);
  130. 		if (IS_FURNITURE(levl[mtmp->mx][mtmp->my].typ) ||
  131. 		    IS_DRAWBRIDGE(levl[mtmp->mx][mtmp->my].typ) ||
  132. 		    (is_drawbridge_wall(mtmp->mx, mtmp->my) >= 0) ||
  133. 		    (sstairs.sx && sstairs.sx == mtmp->mx &&
  134. 				   sstairs.sy == mtmp->my)) {
  135. 			pline_The("digging ray is ineffective.");
  136. 			return 2;
  137. 		}
  138. 		if (!Can_dig_down(&u.uz)) {
  139. 		    if(canseemon(mtmp))
  140. 			pline_The("%s here is too hard to dig in.",
  141. 					surface(mtmp->mx, mtmp->my));
  142. 		    return 2;
  143. 		}
  144. 		ttmp = maketrap(mtmp->mx, mtmp->my, HOLE);
  145. 		if (!ttmp) return 2;
  146. 		seetrap(ttmp);
  147. 		if (vis) {
  148. 		    pline("%s has made a hole in the %s.", Monnam(mtmp),
  149. 				surface(mtmp->mx, mtmp->my));
  150. 		    pline("%s %s through...", Monnam(mtmp),
  151. 			  is_flyer(mtmp->data) ? "dives" : "falls");
  152. 		} else if (flags.soundok)
  153. 			You_hear("%s crash through the %s.", something,
  154. 				surface(mtmp->mx, mtmp->my));
  155. 		/* we made sure that there is a level for mtmp to go to */
  156. 		migrate_to_level(mtmp, ledger_no(&u.uz) + 1,
  157. 				 MIGR_RANDOM, (coord *)0);
  158. 		return 2;
  159. 	    }
  160. 	case MUSE_WAN_CREATE_MONSTER:
  161. 	    {	coord cc;
  162. 		    /* pm: 0 => random, eel => aquatic, croc => amphibious */
  163. 		struct permonst *pm = !is_pool(mtmp->mx, mtmp->my) ? 0 :
  164. 			     &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE];
  165. 		struct monst *mon;
  166.  
  167. 		if (!enexto(&cc, mtmp->mx, mtmp->my, pm)) return 0;
  168. 		mzapmsg(mtmp, otmp, FALSE);
  169. 		otmp->spe--;
  170. 		mon = makemon((struct permonst *)0, cc.x, cc.y, NO_MM_FLAGS);
  171. 		if (mon && canspotmon(mon) && oseen)
  172. 		    makeknown(WAN_CREATE_MONSTER);
  173. 		return 2;
  174. 	    }
  175. 	case MUSE_SCR_CREATE_MONSTER:
  176. 	    {	coord cc;
  177. 		struct permonst *pm = 0, *fish = 0;
  178. 		int cnt = 1;
  179. 		struct monst *mon;
  180. 		boolean known = FALSE;
  181.  
  182. 		if (!rn2(73)) cnt += rnd(4);
  183. 		if (mtmp->mconf || otmp->cursed) cnt += 12;
  184. 		if (mtmp->mconf) pm = fish = &mons[PM_ACID_BLOB];
  185. 		else if (is_pool(mtmp->mx, mtmp->my))
  186. 		    fish = &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE];
  187. 		mreadmsg(mtmp, otmp);
  188. 		while(cnt--) {
  189. 		    /* `fish' potentially gives bias towards water locations;
  190. 		       `pm' is what to actually create (0 => random) */
  191. 		    if (!enexto(&cc, mtmp->mx, mtmp->my, fish)) break;
  192. 		    mon = makemon(pm, cc.x, cc.y, NO_MM_FLAGS);
  193. 		    if (mon && canspotmon(mon)) known = TRUE;
  194. 		}
  195. 		/* The only case where we don't use oseen.  For wands, you
  196. 		 * have to be able to see the monster zap the wand to know
  197. 		 * what type it is.  For teleport scrolls, you have to see
  198. 		 * the monster to know it teleported.
  199. 		 */
  200. 		if (known)
  201. 		    makeknown(SCR_CREATE_MONSTER);
  202. 		else if (!objects[SCR_CREATE_MONSTER].oc_name_known
  203. 			&& !objects[SCR_CREATE_MONSTER].oc_uname)
  204. 		    docall(otmp);
  205. 		m_useup(mtmp, otmp);
  206. 		return 2;
  207. 	    }
  208. 	case MUSE_TRAPDOOR:
  209. 		/* trap doors on "bottom" levels of dungeons are rock-drop
  210. 		 * trap doors, not holes in the floor.  We check here for
  211. 		 * safety.
  212. 		 */
  213. 		if (Is_botlevel(&u.uz)) return 0;
  214. 		m_flee(mtmp);
  215. 		if (vis) {
  216. 			struct trap *t;
  217. 			t = t_at(trapx,trapy);
  218. 			pline("%s %s into a %s!", Monnam(mtmp),
  219. 			makeplural(locomotion(mtmp->data, "jump")),
  220. 			t->ttyp == TRAPDOOR ? "trap door" : "hole");
  221. 			if (levl[trapx][trapy].typ == SCORR) {
  222. 			    levl[trapx][trapy].typ = CORR;
  223. 			    unblock_point(trapx, trapy);
  224. 			}
  225. 			seetrap(t_at(trapx,trapy));
  226. 		}
  227.  
  228. 		/*  don't use rloc_to() because worm tails must "move" */
  229. 		remove_monster(mtmp->mx, mtmp->my);
  230. 		newsym(mtmp->mx, mtmp->my);	/* update old location */
  231. 		place_monster(mtmp, trapx, trapy);
  232. 		if (mtmp->wormno) worm_move(mtmp);
  233. 		newsym(trapx, trapy);
  234.  
  235. 		migrate_to_level(mtmp, ledger_no(&u.uz) + 1,
  236. 				 MIGR_RANDOM, (coord *)0);
  237. 		return 2;
  238. 	case MUSE_UPSTAIRS:
  239. 		/* Monsters without amulets escape the dungeon and are
  240. 		 * gone for good when they leave up the up stairs.
  241. 		 * Monsters with amulets would reach the endlevel,
  242. 		 * which we cannot allow since that would leave the
  243. 		 * player stranded.
  244. 		 */
  245. 		if (ledger_no(&u.uz) == 1) {
  246. 			if (mon_has_special(mtmp))
  247. 				return 0;
  248. 			if (vismon)
  249. 			    pline("%s escapes the dungeon!", Monnam(mtmp));
  250. 			mongone(mtmp);
  251. 			return 2;
  252. 		}
  253. 		m_flee(mtmp);
  254. 		if (Inhell && mon_has_amulet(mtmp) && !rn2(4) &&
  255. 			(dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz) - 3)) {
  256. 		    if (vismon) pline(
  257. "As %s climbs the stairs, a mysterious force momentarily surrounds %s...",
  258. 				     mon_nam(mtmp), mhim(mtmp));
  259. 		    /* simpler than for the player; this will usually be
  260. 		       the Wizard and he'll immediately go right to the
  261. 		       upstairs, so there's not much point in having any
  262. 		       chance for a random position on the current level */
  263. 		    migrate_to_level(mtmp, ledger_no(&u.uz) + 1,
  264. 				     MIGR_RANDOM, (coord *)0);
  265. 		} else {
  266. 		    if (vismon) pline("%s escapes upstairs!", Monnam(mtmp));
  267. 		    migrate_to_level(mtmp, ledger_no(&u.uz) - 1,
  268. 				     MIGR_STAIRS_DOWN, (coord *)0);
  269. 		}
  270. 		return 2;
  271. 	case MUSE_DOWNSTAIRS:
  272. 		m_flee(mtmp);
  273. 		if (vismon) pline("%s escapes downstairs!", Monnam(mtmp));
  274. 		migrate_to_level(mtmp, ledger_no(&u.uz) + 1,
  275. 				 MIGR_STAIRS_UP, (coord *)0);
  276. 		return 2;
  277. 	case MUSE_UP_LADDER:
  278. 		m_flee(mtmp);
  279. 		if (vismon) pline("%s escapes up the ladder!", Monnam(mtmp));
  280. 		migrate_to_level(mtmp, ledger_no(&u.uz) - 1,
  281. 				 MIGR_LADDER_DOWN, (coord *)0);
  282. 		return 2;
  283. 	case MUSE_DN_LADDER:
  284. 		m_flee(mtmp);
  285. 		if (vismon) pline("%s escapes down the ladder!", Monnam(mtmp));
  286. 		migrate_to_level(mtmp, ledger_no(&u.uz) + 1,
  287. 				 MIGR_LADDER_UP, (coord *)0);
  288. 		return 2;
  289. 	case MUSE_SSTAIRS:
  290. 		m_flee(mtmp);
  291. 		/* the stairs leading up from the 1st level are */
  292. 		/* regular stairs, not sstairs.			*/
  293. 		if (sstairs.up) {
  294. 			if (vismon)
  295. 			    pline("%s escapes upstairs!", Monnam(mtmp));
  296. 			if(Inhell) {
  297. 			    migrate_to_level(mtmp, ledger_no(&sstairs.tolev),
  298. 					     MIGR_RANDOM, (coord *)0);
  299. 			    return 2;
  300. 			}
  301. 		} else	if (vismon)
  302. 		    pline("%s escapes downstairs!", Monnam(mtmp));
  303. 		migrate_to_level(mtmp, ledger_no(&sstairs.tolev),
  304. 				 MIGR_SSTAIRS, (coord *)0);
  305. 		return 2;
  306. 	case MUSE_TELEPORT_TRAP:
  307. 		m_flee(mtmp);
  308. 		if (vis) {
  309. 			pline("%s %s onto a teleport trap!", Monnam(mtmp),
  310. 				makeplural(locomotion(mtmp->data, "jump")));
  311. 			if (levl[trapx][trapy].typ == SCORR) {
  312. 			    levl[trapx][trapy].typ = CORR;
  313. 			    unblock_point(trapx, trapy);
  314. 			}
  315. 			seetrap(t_at(trapx,trapy));
  316. 		}
  317. 		/*  don't use rloc_to() because worm tails must "move" */
  318. 		remove_monster(mtmp->mx, mtmp->my);
  319. 		newsym(mtmp->mx, mtmp->my);	/* update old location */
  320. 		place_monster(mtmp, trapx, trapy);
  321. 		if (mtmp->wormno) worm_move(mtmp);
  322. 		newsym(trapx, trapy);
  323.  
  324. 		goto mon_tele;
  325. 	case MUSE_POT_HEALING:
  326. 		mquaffmsg(mtmp, otmp);
  327. 		i = d(6 + 2 * bcsign(otmp), 4);
  328. 		mtmp->mhp += i;
  329. 		if (mtmp->mhp > mtmp->mhpmax) mtmp->mhp = ++mtmp->mhpmax;
  330. 		if (!otmp->cursed && !mtmp->mcansee) {
  331. 			mtmp->mcansee = 1;
  332. 			mtmp->mblinded = 0;
  333. 			if (vismon) pline(mcsa, Monnam(mtmp));
  334. 		}
  335. 		if (vismon) pline("%s looks better.", Monnam(mtmp));
  336. 		if (oseen) makeknown(POT_HEALING);
  337. 		m_useup(mtmp, otmp);
  338. 		return 2;
  339. 	case MUSE_POT_EXTRA_HEALING:
  340. 		mquaffmsg(mtmp, otmp);
  341. 		i = d(6 + 2 * bcsign(otmp), 8);
  342. 		mtmp->mhp += i;
  343. 		if (mtmp->mhp > mtmp->mhpmax)
  344. 			mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 5 : 2));
  345. 		if (!mtmp->mcansee) {
  346. 			mtmp->mcansee = 1;
  347. 			mtmp->mblinded = 0;
  348. 			if (vismon) pline(mcsa, Monnam(mtmp));
  349. 		}
  350. 		if (vismon) pline("%s looks much better.", Monnam(mtmp));
  351. 		if (oseen) makeknown(POT_EXTRA_HEALING);
  352. 		m_useup(mtmp, otmp);
  353. 		return 2;
  354. 	case MUSE_POT_FULL_HEALING:
  355. 		mquaffmsg(mtmp, otmp);
  356. 		if (otmp->otyp == POT_SICKNESS) unbless(otmp); /* Pestilence */
  357. 		mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 8 : 4));
  358. 		if (!mtmp->mcansee && otmp->otyp != POT_SICKNESS) {
  359. 			mtmp->mcansee = 1;
  360. 			mtmp->mblinded = 0;
  361. 			if (vismon) pline(mcsa, Monnam(mtmp));
  362. 		}
  363. 		if (vismon) pline("%s looks completely healed.", Monnam(mtmp));
  364. 		if (oseen) makeknown(otmp->otyp);
  365. 		m_useup(mtmp, otmp);
  366. 		return 2;
  367. 	case MUSE_LIZARD_CORPSE:
  368. 		/* not actually called for its unstoning effect */
  369. 		mon_consume_unstone(mtmp, otmp, FALSE, FALSE);
  370. 		return 2;
  371. 	case 0: return 0; /* i.e. an exploded wand */
  372. 	default: impossible("%s wanted to perform action %d?", Monnam(mtmp),
  373. 			m.has_defense);
  374. 		break;
  375. 	}
  376. 	return 0;
  377. #undef m_flee
  378. }

rnd_defensive_item

  1. int
  2. rnd_defensive_item(mtmp)
  3. struct monst *mtmp;
  4. {
  5. 	struct permonst *pm = mtmp->data;
  6. 	int difficulty = monstr[(monsndx(pm))];
  7. 	int trycnt = 0;
  8.  
  9. 	if(is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)
  10. 			|| pm->mlet == S_GHOST
  11. # ifdef KOPS
  12. 			|| pm->mlet == S_KOP
  13. # endif
  14. 		) return 0;
  15. try_again:
  16. 	switch (rn2(8 + (difficulty > 3) + (difficulty > 6) +
  17. 				(difficulty > 8))) {
  18. 		case 6: case 9:
  19. 			if (level.flags.noteleport && ++trycnt < 2)
  20. 			    goto try_again;
  21. 			if (!rn2(3)) return WAN_TELEPORTATION;
  22. 			/* else FALLTHRU */
  23. 		case 0: case 1:
  24. 			return SCR_TELEPORTATION;
  25. 		case 8: case 10:
  26. 			if (!rn2(3)) return WAN_CREATE_MONSTER;
  27. 			/* else FALLTHRU */
  28. 		case 2: return SCR_CREATE_MONSTER;
  29. 		case 3: return POT_HEALING;
  30. 		case 4: return POT_EXTRA_HEALING;
  31. 		case 5: return (mtmp->data != &mons[PM_PESTILENCE]) ?
  32. 				POT_FULL_HEALING : POT_SICKNESS;
  33. 		case 7: if (is_floater(pm) || mtmp->isshk || mtmp->isgd
  34. 						|| mtmp->ispriest
  35. 									)
  36. 				return 0;
  37. 			else
  38. 				return WAN_DIGGING;
  39. 	}
  40. 	/*NOTREACHED*/
  41. 	return 0;
  42. }
  43.  
  44. #define MUSE_WAN_DEATH 1
  45. #define MUSE_WAN_SLEEP 2
  46. #define MUSE_WAN_FIRE 3
  47. #define MUSE_WAN_COLD 4
  48. #define MUSE_WAN_LIGHTNING 5
  49. #define MUSE_WAN_MAGIC_MISSILE 6
  50. #define MUSE_WAN_STRIKING 7
  51. #define MUSE_SCR_FIRE 8
  52. #define MUSE_POT_PARALYSIS 9
  53. #define MUSE_POT_BLINDNESS 10
  54. #define MUSE_POT_CONFUSION 11
  55. #define MUSE_FROST_HORN 12
  56. #define MUSE_FIRE_HORN 13
  57. #define MUSE_POT_ACID 14
  58. /*#define MUSE_WAN_TELEPORTATION 15*/
  59. #define MUSE_POT_SLEEPING 16
  60. #define MUSE_SCR_EARTH 17

find_offensive

  1. /* Select an offensive item/action for a monster.  Returns TRUE iff one is
  2. * found.
  3. */
  4. boolean
  5. find_offensive(mtmp)
  6. struct monst *mtmp;
  7. {
  8. 	register struct obj *obj;
  9. 	boolean ranged_stuff = lined_up(mtmp);
  10. 	boolean reflection_skip = (Reflecting && rn2(2));
  11. 	struct obj *helmet = which_armor(mtmp, W_ARMH);
  12.  
  13. 	m.offensive = (struct obj *)0;
  14. 	m.has_offense = 0;
  15. 	if (mtmp->mpeaceful || is_animal(mtmp->data) ||
  16. 				mindless(mtmp->data) || nohands(mtmp->data))
  17. 		return FALSE;
  18. 	if (u.uswallow) return FALSE;
  19. 	if (in_your_sanctuary(mtmp, 0, 0)) return FALSE;
  20. 	if (dmgtype(mtmp->data, AD_HEAL) && !uwep
  21. #ifdef TOURIST
  22. 	    && !uarmu
  23. #endif
  24. 	    && !uarm && !uarmh && !uarms && !uarmg && !uarmc && !uarmf)
  25. 		return FALSE;
  26.  
  27. 	if (!ranged_stuff) return FALSE;
  28. #define nomore(x) if(m.has_offense==x) continue;
  29. 	for(obj=mtmp->minvent; obj; obj=obj->nobj) {
  30. 		/* nomore(MUSE_WAN_DEATH); */
  31. 		if (!reflection_skip) {
  32. 		    if(obj->otyp == WAN_DEATH && obj->spe > 0) {
  33. 			m.offensive = obj;
  34. 			m.has_offense = MUSE_WAN_DEATH;
  35. 		    }
  36. 		    nomore(MUSE_WAN_SLEEP);
  37. 		    if(obj->otyp == WAN_SLEEP && obj->spe > 0 && multi >= 0) {
  38. 			m.offensive = obj;
  39. 			m.has_offense = MUSE_WAN_SLEEP;
  40. 		    }
  41. 		    nomore(MUSE_WAN_FIRE);
  42. 		    if(obj->otyp == WAN_FIRE && obj->spe > 0) {
  43. 			m.offensive = obj;
  44. 			m.has_offense = MUSE_WAN_FIRE;
  45. 		    }
  46. 		    nomore(MUSE_FIRE_HORN);
  47. 		    if(obj->otyp == FIRE_HORN && obj->spe > 0) {
  48. 			m.offensive = obj;
  49. 			m.has_offense = MUSE_FIRE_HORN;
  50. 		    }
  51. 		    nomore(MUSE_WAN_COLD);
  52. 		    if(obj->otyp == WAN_COLD && obj->spe > 0) {
  53. 			m.offensive = obj;
  54. 			m.has_offense = MUSE_WAN_COLD;
  55. 		    }
  56. 		    nomore(MUSE_FROST_HORN);
  57. 		    if(obj->otyp == FROST_HORN && obj->spe > 0) {
  58. 			m.offensive = obj;
  59. 			m.has_offense = MUSE_FROST_HORN;
  60. 		    }
  61. 		    nomore(MUSE_WAN_LIGHTNING);
  62. 		    if(obj->otyp == WAN_LIGHTNING && obj->spe > 0) {
  63. 			m.offensive = obj;
  64. 			m.has_offense = MUSE_WAN_LIGHTNING;
  65. 		    }
  66. 		    nomore(MUSE_WAN_MAGIC_MISSILE);
  67. 		    if(obj->otyp == WAN_MAGIC_MISSILE && obj->spe > 0) {
  68. 			m.offensive = obj;
  69. 			m.has_offense = MUSE_WAN_MAGIC_MISSILE;
  70. 		    }
  71. 		}
  72. 		nomore(MUSE_WAN_STRIKING);
  73. 		if(obj->otyp == WAN_STRIKING && obj->spe > 0) {
  74. 			m.offensive = obj;
  75. 			m.has_offense = MUSE_WAN_STRIKING;
  76. 		}
  77. 		nomore(MUSE_POT_PARALYSIS);
  78. 		if(obj->otyp == POT_PARALYSIS && multi >= 0) {
  79. 			m.offensive = obj;
  80. 			m.has_offense = MUSE_POT_PARALYSIS;
  81. 		}
  82. 		nomore(MUSE_POT_BLINDNESS);
  83. 		if(obj->otyp == POT_BLINDNESS && !attacktype(mtmp->data, AT_GAZE)) {
  84. 			m.offensive = obj;
  85. 			m.has_offense = MUSE_POT_BLINDNESS;
  86. 		}
  87. 		nomore(MUSE_POT_CONFUSION);
  88. 		if(obj->otyp == POT_CONFUSION) {
  89. 			m.offensive = obj;
  90. 			m.has_offense = MUSE_POT_CONFUSION;
  91. 		}
  92. 		nomore(MUSE_POT_SLEEPING);
  93. 		if(obj->otyp == POT_SLEEPING) {
  94. 			m.offensive = obj;
  95. 			m.has_offense = MUSE_POT_SLEEPING;
  96. 		}
  97. 		nomore(MUSE_POT_ACID);
  98. 		if(obj->otyp == POT_ACID) {
  99. 			m.offensive = obj;
  100. 			m.has_offense = MUSE_POT_ACID;
  101. 		}
  102. 		/* we can safely put this scroll here since the locations that
  103. 		 * are in a 1 square radius are a subset of the locations that
  104. 		 * are in wand range
  105. 		 */
  106. 		nomore(MUSE_SCR_EARTH);
  107. 		if (obj->otyp == SCR_EARTH
  108. 		       && ((helmet && is_metallic(helmet)) ||
  109. 				mtmp->mconf || amorphous(mtmp->data) ||
  110. 				passes_walls(mtmp->data) ||
  111. 				noncorporeal(mtmp->data) ||
  112. 				unsolid(mtmp->data) || !rn2(10))
  113. 		       && dist2(mtmp->mx,mtmp->my,mtmp->mux,mtmp->muy) <= 2
  114. 		       && mtmp->mcansee && haseyes(mtmp->data)
  115. #ifdef REINCARNATION
  116. 		       && !Is_rogue_level(&u.uz)
  117. #endif
  118. 		       && (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) {
  119. 		    m.offensive = obj;
  120. 		    m.has_offense = MUSE_SCR_EARTH;
  121. 		}
  122. #if 0
  123. 		nomore(MUSE_SCR_FIRE);
  124. 		if (obj->otyp == SCR_FIRE && resists_fire(mtmp)
  125. 		   && dist2(mtmp->mx,mtmp->my,mtmp->mux,mtmp->muy) <= 2
  126. 		   && mtmp->mcansee && haseyes(mtmp->data)) {
  127. 			m.offensive = obj;
  128. 			m.has_offense = MUSE_SCR_FIRE;
  129. 		}
  130. #endif
  131. 	}
  132. 	return((boolean)(!!m.has_offense));
  133. #undef nomore
  134. }

mbhitm

  1. STATIC_PTR
  2. int
  3. mbhitm(mtmp, otmp)
  4. register struct monst *mtmp;
  5. register struct obj *otmp;
  6. {
  7. 	int tmp;
  8.  
  9. 	boolean reveal_invis = FALSE;
  10. 	if (mtmp != &youmonst) {
  11. 		mtmp->msleeping = 0;
  12. 		if (mtmp->m_ap_type) seemimic(mtmp);
  13. 	}
  14. 	switch(otmp->otyp) {
  15. 	case WAN_STRIKING:
  16. 		reveal_invis = TRUE;
  17. 		if (mtmp == &youmonst) {
  18. 			if (zap_oseen) makeknown(WAN_STRIKING);
  19. 			if (Antimagic) {
  20. 			    shieldeff(u.ux, u.uy);
  21. 			    pline("Boing!");
  22. 			} else if (rnd(20) < 10 + u.uac) {
  23. 			    pline_The("wand hits you!");
  24. 			    tmp = d(2,12);
  25. 			    if(Half_spell_damage) tmp = (tmp+1) / 2;
  26. 			    losehp(tmp, "wand", KILLED_BY_AN);
  27. 			} else pline_The("wand misses you.");
  28. 			stop_occupation();
  29. 			nomul(0);
  30. 		} else if (resists_magm(mtmp)) {
  31. 			shieldeff(mtmp->mx, mtmp->my);
  32. 			pline("Boing!");
  33. 		} else if (rnd(20) < 10+find_mac(mtmp)) {
  34. 			tmp = d(2,12);
  35. 			hit("wand", mtmp, exclam(tmp));
  36. 			(void) resist(mtmp, otmp->oclass, tmp, TELL);
  37. 			if (cansee(mtmp->mx, mtmp->my) && zap_oseen)
  38. 				makeknown(WAN_STRIKING);
  39. 		} else {
  40. 			miss("wand", mtmp);
  41. 			if (cansee(mtmp->mx, mtmp->my) && zap_oseen)
  42. 				makeknown(WAN_STRIKING);
  43. 		}
  44. 		break;
  45. 	case WAN_TELEPORTATION:
  46. 		if (mtmp == &youmonst) {
  47. 			if (zap_oseen) makeknown(WAN_TELEPORTATION);
  48. 			tele();
  49. 		} else {
  50. 			/* for consistency with zap.c, don't identify */
  51. 			if (mtmp->ispriest &&
  52. 				*in_rooms(mtmp->mx, mtmp->my, TEMPLE)) {
  53. 			    if (cansee(mtmp->mx, mtmp->my))
  54. 				pline("%s resists the magic!", Monnam(mtmp));
  55. 			    mtmp->msleeping = 0;
  56. 			    if(mtmp->m_ap_type) seemimic(mtmp);
  57. 			} else if (!tele_restrict(mtmp))
  58. 			    (void) rloc(mtmp, FALSE);
  59. 		}
  60. 		break;
  61. 	case WAN_CANCELLATION:
  62. 	case SPE_CANCELLATION:
  63. 		(void) cancel_monst(mtmp, otmp, FALSE, TRUE, FALSE);
  64. 		break;
  65. 	}
  66. 	if (reveal_invis) {
  67. 	    if (mtmp->mhp > 0 && cansee(bhitpos.x,bhitpos.y)
  68. 							&& !canspotmon(mtmp))
  69. 		map_invisible(bhitpos.x, bhitpos.y);
  70. 	}
  71. 	return 0;
  72. }

mbhit

  1. /* A modified bhit() for monsters.  Based on bhit() in zap.c.  Unlike
  2. * buzz(), bhit() doesn't take into account the possibility of a monster
  3. * zapping you, so we need a special function for it.  (Unless someone wants
  4. * to merge the two functions...)
  5. */
  6. STATIC_OVL void
  7. mbhit(mon,range,fhitm,fhito,obj)
  8. struct monst *mon;			/* monster shooting the wand */
  9. register int range;			/* direction and range */
  10. int FDECL((*fhitm),(MONST_P,OBJ_P));
  11. int FDECL((*fhito),(OBJ_P,OBJ_P));	/* fns called when mon/obj hit */
  12. struct obj *obj;			/* 2nd arg to fhitm/fhito */
  13. {
  14. 	register struct monst *mtmp;
  15. 	register struct obj *otmp;
  16. 	register uchar typ;
  17. 	int ddx, ddy;
  18.  
  19. 	bhitpos.x = mon->mx;
  20. 	bhitpos.y = mon->my;
  21. 	ddx = sgn(mon->mux - mon->mx);
  22. 	ddy = sgn(mon->muy - mon->my);
  23.  
  24. 	while(range-- > 0) {
  25. 		int x,y;
  26.  
  27. 		bhitpos.x += ddx;
  28. 		bhitpos.y += ddy;
  29. 		x = bhitpos.x; y = bhitpos.y;
  30.  
  31. 		if (!isok(x,y)) {
  32. 		    bhitpos.x -= ddx;
  33. 		    bhitpos.y -= ddy;
  34. 		    break;
  35. 		}
  36. 		if (find_drawbridge(&x,&y))
  37. 		    switch (obj->otyp) {
  38. 			case WAN_STRIKING:
  39. 			    destroy_drawbridge(x,y);
  40. 		    }
  41. 		if(bhitpos.x==u.ux && bhitpos.y==u.uy) {
  42. 			(*fhitm)(&youmonst, obj);
  43. 			range -= 3;
  44. 		} else if(MON_AT(bhitpos.x, bhitpos.y)){
  45. 			mtmp = m_at(bhitpos.x,bhitpos.y);
  46. 			if (cansee(bhitpos.x,bhitpos.y) && !canspotmon(mtmp))
  47. 			    map_invisible(bhitpos.x, bhitpos.y);
  48. 			(*fhitm)(mtmp, obj);
  49. 			range -= 3;
  50. 		}
  51. 		/* modified by GAN to hit all objects */
  52. 		if(fhito){
  53. 		    int hitanything = 0;
  54. 		    register struct obj *next_obj;
  55.  
  56. 		    for(otmp = level.objects[bhitpos.x][bhitpos.y];
  57. 							otmp; otmp = next_obj) {
  58. 			/* Fix for polymorph bug, Tim Wright */
  59. 			next_obj = otmp->nexthere;
  60. 			hitanything += (*fhito)(otmp, obj);
  61. 		    }
  62. 		    if(hitanything)	range--;
  63. 		}
  64. 		typ = levl[bhitpos.x][bhitpos.y].typ;
  65. 		if(IS_DOOR(typ) || typ == SDOOR) {
  66. 		    switch (obj->otyp) {
  67. 			/* note: monsters don't use opening or locking magic
  68. 			   at present, but keep these as placeholders */
  69. 			case WAN_OPENING:
  70. 			case WAN_LOCKING:
  71. 			case WAN_STRIKING:
  72. 			    if (doorlock(obj, bhitpos.x, bhitpos.y)) {
  73. 				makeknown(obj->otyp);
  74. 				/* if a shop door gets broken, add it to
  75. 				   the shk's fix list (no cost to player) */
  76. 				if (levl[bhitpos.x][bhitpos.y].doormask ==
  77. 					D_BROKEN &&
  78. 				    *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE))
  79. 				    add_damage(bhitpos.x, bhitpos.y, 0L);
  80. 			    }
  81. 			    break;
  82. 		    }
  83. 		}
  84. 		if(!ZAP_POS(typ) || (IS_DOOR(typ) &&
  85. 		   (levl[bhitpos.x][bhitpos.y].doormask & (D_LOCKED | D_CLOSED)))
  86. 		  ) {
  87. 			bhitpos.x -= ddx;
  88. 			bhitpos.y -= ddy;
  89. 			break;
  90. 		}
  91. 	}
  92. }

use_offensive

  1. /* Perform an offensive action for a monster.  Must be called immediately
  2. * after find_offensive().  Return values are same as use_defensive().
  3. */
  4. int
  5. use_offensive(mtmp)
  6. struct monst *mtmp;
  7. {
  8. 	int i;
  9. 	struct obj *otmp = m.offensive;
  10. 	boolean oseen;
  11.  
  12. 	/* offensive potions are not drunk, they're thrown */
  13. 	if (otmp->oclass != POTION_CLASS && (i = precheck(mtmp, otmp)) != 0)
  14. 		return i;
  15. 	oseen = otmp && canseemon(mtmp);
  16.  
  17. 	switch(m.has_offense) {
  18. 	case MUSE_WAN_DEATH:
  19. 	case MUSE_WAN_SLEEP:
  20. 	case MUSE_WAN_FIRE:
  21. 	case MUSE_WAN_COLD:
  22. 	case MUSE_WAN_LIGHTNING:
  23. 	case MUSE_WAN_MAGIC_MISSILE:
  24. 		mzapmsg(mtmp, otmp, FALSE);
  25. 		otmp->spe--;
  26. 		if (oseen) makeknown(otmp->otyp);
  27. 		m_using = TRUE;
  28. 		buzz((int)(-30 - (otmp->otyp - WAN_MAGIC_MISSILE)),
  29. 			(otmp->otyp == WAN_MAGIC_MISSILE) ? 2 : 6,
  30. 			mtmp->mx, mtmp->my,
  31. 			sgn(mtmp->mux-mtmp->mx), sgn(mtmp->muy-mtmp->my));
  32. 		m_using = FALSE;
  33. 		return (mtmp->mhp <= 0) ? 1 : 2;
  34. 	case MUSE_FIRE_HORN:
  35. 	case MUSE_FROST_HORN:
  36. 		if (oseen) {
  37. 			makeknown(otmp->otyp);
  38. 			pline("%s plays a %s!", Monnam(mtmp), xname(otmp));
  39. 		} else
  40. 			You_hear("a horn being played.");
  41. 		otmp->spe--;
  42. 		m_using = TRUE;
  43. 		buzz(-30 - ((otmp->otyp==FROST_HORN) ? AD_COLD-1 : AD_FIRE-1),
  44. 			rn1(6,6), mtmp->mx, mtmp->my,
  45. 			sgn(mtmp->mux-mtmp->mx), sgn(mtmp->muy-mtmp->my));
  46. 		m_using = FALSE;
  47. 		return (mtmp->mhp <= 0) ? 1 : 2;
  48. 	case MUSE_WAN_TELEPORTATION:
  49. 	case MUSE_WAN_STRIKING:
  50. 		zap_oseen = oseen;
  51. 		mzapmsg(mtmp, otmp, FALSE);
  52. 		otmp->spe--;
  53. 		m_using = TRUE;
  54. 		mbhit(mtmp,rn1(8,6),mbhitm,bhito,otmp);
  55. 		m_using = FALSE;
  56. 		return 2;
  57. 	case MUSE_SCR_EARTH:
  58. 	    {
  59. 		/* TODO: handle steeds */
  60. 	    	register int x, y;
  61. 		/* don't use monster fields after killing it */
  62. 		boolean confused = (mtmp->mconf ? TRUE : FALSE);
  63. 		int mmx = mtmp->mx, mmy = mtmp->my;
  64.  
  65. 		mreadmsg(mtmp, otmp);
  66. 	    	/* Identify the scroll */
  67. 		if (canspotmon(mtmp)) {
  68. 		    pline_The("%s rumbles %s %s!", ceiling(mtmp->mx, mtmp->my),
  69. 	    			otmp->blessed ? "around" : "above",
  70. 				mon_nam(mtmp));
  71. 		    if (oseen) makeknown(otmp->otyp);
  72. 		} else if (cansee(mtmp->mx, mtmp->my)) {
  73. 		    pline_The("%s rumbles in the middle of nowhere!",
  74. 			ceiling(mtmp->mx, mtmp->my));
  75. 		    if (mtmp->minvis)
  76. 			map_invisible(mtmp->mx, mtmp->my);
  77. 		    if (oseen) makeknown(otmp->otyp);
  78. 		}
  79.  
  80. 	    	/* Loop through the surrounding squares */
  81. 	    	for (x = mmx-1; x <= mmx+1; x++) {
  82. 	    	    for (y = mmy-1; y <= mmy+1; y++) {
  83. 	    	    	/* Is this a suitable spot? */
  84. 	    	    	if (isok(x, y) && !closed_door(x, y) &&
  85. 	    	    			!IS_ROCK(levl[x][y].typ) &&
  86. 	    	    			!IS_AIR(levl[x][y].typ) &&
  87. 	    	    			(((x == mmx) && (y == mmy)) ?
  88. 	    	    			    !otmp->blessed : !otmp->cursed) &&
  89. 					(x != u.ux || y != u.uy)) {
  90. 			    register struct obj *otmp2;
  91. 			    register struct monst *mtmp2;
  92.  
  93. 	    	    	    /* Make the object(s) */
  94. 	    	    	    otmp2 = mksobj(confused ? ROCK : BOULDER,
  95. 	    	    	    		FALSE, FALSE);
  96. 	    	    	    if (!otmp2) continue;  /* Shouldn't happen */
  97. 	    	    	    otmp2->quan = confused ? rn1(5,2) : 1;
  98. 	    	    	    otmp2->owt = weight(otmp2);
  99.  
  100. 	    	    	    /* Find the monster here (might be same as mtmp) */
  101. 	    	    	    mtmp2 = m_at(x, y);
  102. 	    	    	    if (mtmp2 && !amorphous(mtmp2->data) &&
  103. 	    	    	    		!passes_walls(mtmp2->data) &&
  104. 	    	    	    		!noncorporeal(mtmp2->data) &&
  105. 	    	    	    		!unsolid(mtmp2->data)) {
  106. 				struct obj *helmet = which_armor(mtmp2, W_ARMH);
  107. 				int mdmg;
  108.  
  109. 				if (cansee(mtmp2->mx, mtmp2->my)) {
  110. 				    pline("%s is hit by %s!", Monnam(mtmp2),
  111. 	    	    	    			doname(otmp2));
  112. 				    if (mtmp2->minvis && !canspotmon(mtmp2))
  113. 					map_invisible(mtmp2->mx, mtmp2->my);
  114. 				}
  115. 	    	    	    	mdmg = dmgval(otmp2, mtmp2) * otmp2->quan;
  116. 				if (helmet) {
  117. 				    if(is_metallic(helmet)) {
  118. 					if (canspotmon(mtmp2))
  119. 					    pline("Fortunately, %s is wearing a hard helmet.", mon_nam(mtmp2));
  120. 					else if (flags.soundok)
  121. 					    You_hear("a clanging sound.");
  122. 					if (mdmg > 2) mdmg = 2;
  123. 				    } else {
  124. 					if (canspotmon(mtmp2))
  125. 					    pline("%s's %s does not protect %s.",
  126. 						Monnam(mtmp2), xname(helmet),
  127. 						mhim(mtmp2));
  128. 				    }
  129. 				}
  130. 	    	    	    	mtmp2->mhp -= mdmg;
  131. 	    	    	    	if (mtmp2->mhp <= 0) {
  132. 				    pline("%s is killed.", Monnam(mtmp2));
  133. 	    	    	    	    mondied(mtmp2);
  134. 				}
  135. 	    	    	    }
  136. 	    	    	    /* Drop the rock/boulder to the floor */
  137. 	    	    	    if (!flooreffects(otmp2, x, y, "fall")) {
  138. 	    	    	    	place_object(otmp2, x, y);
  139. 	    	    	    	stackobj(otmp2);
  140. 	    	    	    	newsym(x, y);  /* map the rock */
  141. 	    	    	    }
  142. 	    	    	}
  143. 		    }
  144. 		}
  145. 		m_useup(mtmp, otmp);
  146. 		/* Attack the player */
  147. 		if (distmin(mmx, mmy, u.ux, u.uy) == 1 && !otmp->cursed) {
  148. 		    int dmg;
  149. 		    struct obj *otmp2;
  150.  
  151. 		    /* Okay, _you_ write this without repeating the code */
  152. 		    otmp2 = mksobj(confused ? ROCK : BOULDER,
  153. 				FALSE, FALSE);
  154. 		    if (!otmp2) goto xxx_noobj;  /* Shouldn't happen */
  155. 		    otmp2->quan = confused ? rn1(5,2) : 1;
  156. 		    otmp2->owt = weight(otmp2);
  157. 		    if (!amorphous(youmonst.data) &&
  158. 			    !Passes_walls &&
  159. 			    !noncorporeal(youmonst.data) &&
  160. 			    !unsolid(youmonst.data)) {
  161. 			You("are hit by %s!", doname(otmp2));
  162. 			dmg = dmgval(otmp2, &youmonst) * otmp2->quan;
  163. 			if (uarmh) {
  164. 			    if(is_metallic(uarmh)) {
  165. 				pline("Fortunately, you are wearing a hard helmet.");
  166. 				if (dmg > 2) dmg = 2;
  167. 			    } else if (flags.verbose) {
  168. 				Your("%s does not protect you.",
  169. 						xname(uarmh));
  170. 			    }
  171. 			}
  172. 		    } else
  173. 			dmg = 0;
  174. 		    if (!flooreffects(otmp2, u.ux, u.uy, "fall")) {
  175. 			place_object(otmp2, u.ux, u.uy);
  176. 			stackobj(otmp2);
  177. 			newsym(u.ux, u.uy);
  178. 		    }
  179. 		    if (dmg) losehp(dmg, "scroll of earth", KILLED_BY_AN);
  180. 		}
  181. 	    xxx_noobj:
  182.  
  183. 		return (mtmp->mhp <= 0) ? 1 : 2;
  184. 	    }
  185. #if 0
  186. 	case MUSE_SCR_FIRE:
  187. 	      {
  188. 		boolean vis = cansee(mtmp->mx, mtmp->my);
  189.  
  190. 		mreadmsg(mtmp, otmp);
  191. 		if (mtmp->mconf) {
  192. 			if (vis)
  193. 			    pline("Oh, what a pretty fire!");
  194. 		} else {
  195. 			struct monst *mtmp2;
  196. 			int num;
  197.  
  198. 			if (vis)
  199. 			    pline_The("scroll erupts in a tower of flame!");
  200. 			shieldeff(mtmp->mx, mtmp->my);
  201. 			pline("%s is uninjured.", Monnam(mtmp));
  202. 			(void) destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE);
  203. 			(void) destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE);
  204. 			(void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE);
  205. 			num = (2*(rn1(3, 3) + 2 * bcsign(otmp)) + 1)/3;
  206. 			if (Fire_resistance)
  207. 			    You("are not harmed.");
  208. 			burn_away_slime();
  209. 			if (Half_spell_damage) num = (num+1) / 2;
  210. 			else losehp(num, "scroll of fire", KILLED_BY_AN);
  211. 			for(mtmp2 = fmon; mtmp2; mtmp2 = mtmp2->nmon) {
  212. 			   if(DEADMONSTER(mtmp2)) continue;
  213. 			   if(mtmp == mtmp2) continue;
  214. 			   if(dist2(mtmp2->mx,mtmp2->my,mtmp->mx,mtmp->my) < 3){
  215. 				if (resists_fire(mtmp2)) continue;
  216. 				mtmp2->mhp -= num;
  217. 				if (resists_cold(mtmp2))
  218. 				    mtmp2->mhp -= 3*num;
  219. 				if(mtmp2->mhp < 1) {
  220. 				    mondied(mtmp2);
  221. 				    break;
  222. 				}
  223. 			    }
  224. 			}
  225. 		}
  226. 		return 2;
  227. 	      }
  228. #endif	/* 0 */
  229. 	case MUSE_POT_PARALYSIS:
  230. 	case MUSE_POT_BLINDNESS:
  231. 	case MUSE_POT_CONFUSION:
  232. 	case MUSE_POT_SLEEPING:
  233. 	case MUSE_POT_ACID:
  234. 		/* Note: this setting of dknown doesn't suffice.  A monster
  235. 		 * which is out of sight might throw and it hits something _in_
  236. 		 * sight, a problem not existing with wands because wand rays
  237. 		 * are not objects.  Also set dknown in mthrowu.c.
  238. 		 */
  239. 		if (cansee(mtmp->mx, mtmp->my)) {
  240. 			otmp->dknown = 1;
  241. 			pline("%s hurls %s!", Monnam(mtmp),
  242. 						singular(otmp, doname));
  243. 		}
  244. 		m_throw(mtmp, mtmp->mx, mtmp->my, sgn(mtmp->mux-mtmp->mx),
  245. 			sgn(mtmp->muy-mtmp->my),
  246. 			distmin(mtmp->mx,mtmp->my,mtmp->mux,mtmp->muy), otmp);
  247. 		return 2;
  248. 	case 0: return 0; /* i.e. an exploded wand */
  249. 	default: impossible("%s wanted to perform action %d?", Monnam(mtmp),
  250. 			m.has_offense);
  251. 		break;
  252. 	}
  253. 	return 0;
  254. }

rnd_offensive_item

  1. int
  2. rnd_offensive_item(mtmp)
  3. struct monst *mtmp;
  4. {
  5. 	struct permonst *pm = mtmp->data;
  6. 	int difficulty = monstr[(monsndx(pm))];
  7.  
  8. 	if(is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)
  9. 			|| pm->mlet == S_GHOST
  10. # ifdef KOPS
  11. 			|| pm->mlet == S_KOP
  12. # endif
  13. 		) return 0;
  14. 	if (difficulty > 7 && !rn2(35)) return WAN_DEATH;
  15. 	switch (rn2(9 - (difficulty < 4) + 4 * (difficulty > 6))) {
  16. 		case 0: {
  17. 		    struct obj *helmet = which_armor(mtmp, W_ARMH);
  18.  
  19. 		    if ((helmet && is_metallic(helmet)) || amorphous(pm) || passes_walls(pm) || noncorporeal(pm) || unsolid(pm))
  20. 			return SCR_EARTH;
  21. 		} /* fall through */
  22. 		case 1: return WAN_STRIKING;
  23. 		case 2: return POT_ACID;
  24. 		case 3: return POT_CONFUSION;
  25. 		case 4: return POT_BLINDNESS;
  26. 		case 5: return POT_SLEEPING;
  27. 		case 6: return POT_PARALYSIS;
  28. 		case 7: case 8:
  29. 			return WAN_MAGIC_MISSILE;
  30. 		case 9: return WAN_SLEEP;
  31. 		case 10: return WAN_FIRE;
  32. 		case 11: return WAN_COLD;
  33. 		case 12: return WAN_LIGHTNING;
  34. 	}
  35. 	/*NOTREACHED*/
  36. 	return 0;
  37. }
  38.  
  39. #define MUSE_POT_GAIN_LEVEL 1
  40. #define MUSE_WAN_MAKE_INVISIBLE 2
  41. #define MUSE_POT_INVISIBILITY 3
  42. #define MUSE_POLY_TRAP 4
  43. #define MUSE_WAN_POLYMORPH 5
  44. #define MUSE_POT_SPEED 6
  45. #define MUSE_WAN_SPEED_MONSTER 7
  46. #define MUSE_BULLWHIP 8
  47. #define MUSE_POT_POLYMORPH 9

find_misc

  1. boolean
  2. find_misc(mtmp)
  3. struct monst *mtmp;
  4. {
  5. 	register struct obj *obj;
  6. 	struct permonst *mdat = mtmp->data;
  7. 	int x = mtmp->mx, y = mtmp->my;
  8. 	struct trap *t;
  9. 	int xx, yy;
  10. 	boolean immobile = (mdat->mmove == 0);
  11. 	boolean stuck = (mtmp == u.ustuck);
  12.  
  13. 	m.misc = (struct obj *)0;
  14. 	m.has_misc = 0;
  15. 	if (is_animal(mdat) || mindless(mdat))
  16. 		return 0;
  17. 	if (u.uswallow && stuck) return FALSE;
  18.  
  19. 	/* We arbitrarily limit to times when a player is nearby for the
  20. 	 * same reason as Junior Pac-Man doesn't have energizers eaten until
  21. 	 * you can see them...
  22. 	 */
  23. 	if(dist2(x, y, mtmp->mux, mtmp->muy) > 36)
  24. 		return FALSE;
  25.  
  26. 	if (!stuck && !immobile && !mtmp->cham && monstr[monsndx(mdat)] < 6) {
  27. 	  boolean ignore_boulders = (verysmall(mdat) ||
  28. 				     throws_rocks(mdat) ||
  29. 				     passes_walls(mdat));
  30. 	  for(xx = x-1; xx <= x+1; xx++)
  31. 	    for(yy = y-1; yy <= y+1; yy++)
  32. 		if (isok(xx,yy) && (xx != u.ux || yy != u.uy))
  33. 		    if (mdat != &mons[PM_GRID_BUG] || xx == x || yy == y)
  34. 			if (/* (xx==x && yy==y) || */ !level.monsters[xx][yy])
  35. 			    if ((t = t_at(xx, yy)) != 0 &&
  36. 			      (ignore_boulders || !sobj_at(BOULDER, xx, yy))
  37. 			      && !onscary(xx, yy, mtmp)) {
  38. 				if (t->ttyp == POLY_TRAP) {
  39. 				    trapx = xx;
  40. 				    trapy = yy;
  41. 				    m.has_misc = MUSE_POLY_TRAP;
  42. 				    return TRUE;
  43. 				}
  44. 			    }
  45. 	}
  46. 	if (nohands(mdat))
  47. 		return 0;
  48.  
  49. #define nomore(x) if(m.has_misc==x) continue;
  50. 	for(obj=mtmp->minvent; obj; obj=obj->nobj) {
  51. 		/* Monsters shouldn't recognize cursed items; this kludge is */
  52. 		/* necessary to prevent serious problems though... */
  53. 		if(obj->otyp == POT_GAIN_LEVEL && (!obj->cursed ||
  54. 			    (!mtmp->isgd && !mtmp->isshk && !mtmp->ispriest))) {
  55. 			m.misc = obj;
  56. 			m.has_misc = MUSE_POT_GAIN_LEVEL;
  57. 		}
  58. 		nomore(MUSE_BULLWHIP);
  59. 		if(obj->otyp == BULLWHIP && (MON_WEP(mtmp) == obj) &&
  60. 		   distu(mtmp->mx,mtmp->my)==1 && uwep && !mtmp->mpeaceful) {
  61. 			m.misc = obj;
  62. 			m.has_misc = MUSE_BULLWHIP;
  63. 		}
  64. 		/* Note: peaceful/tame monsters won't make themselves
  65. 		 * invisible unless you can see them.  Not really right, but...
  66. 		 */
  67. 		nomore(MUSE_WAN_MAKE_INVISIBLE);
  68. 		if(obj->otyp == WAN_MAKE_INVISIBLE && obj->spe > 0 &&
  69. 		    !mtmp->minvis && !mtmp->invis_blkd &&
  70. 		    (!mtmp->mpeaceful || See_invisible) &&
  71. 		    (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) {
  72. 			m.misc = obj;
  73. 			m.has_misc = MUSE_WAN_MAKE_INVISIBLE;
  74. 		}
  75. 		nomore(MUSE_POT_INVISIBILITY);
  76. 		if(obj->otyp == POT_INVISIBILITY &&
  77. 		    !mtmp->minvis && !mtmp->invis_blkd &&
  78. 		    (!mtmp->mpeaceful || See_invisible) &&
  79. 		    (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) {
  80. 			m.misc = obj;
  81. 			m.has_misc = MUSE_POT_INVISIBILITY;
  82. 		}
  83. 		nomore(MUSE_WAN_SPEED_MONSTER);
  84. 		if(obj->otyp == WAN_SPEED_MONSTER && obj->spe > 0
  85. 				&& mtmp->mspeed != MFAST && !mtmp->isgd) {
  86. 			m.misc = obj;
  87. 			m.has_misc = MUSE_WAN_SPEED_MONSTER;
  88. 		}
  89. 		nomore(MUSE_POT_SPEED);
  90. 		if(obj->otyp == POT_SPEED && mtmp->mspeed != MFAST
  91. 							&& !mtmp->isgd) {
  92. 			m.misc = obj;
  93. 			m.has_misc = MUSE_POT_SPEED;
  94. 		}
  95. 		nomore(MUSE_WAN_POLYMORPH);
  96. 		if(obj->otyp == WAN_POLYMORPH && obj->spe > 0 && !mtmp->cham
  97. 				&& monstr[monsndx(mdat)] < 6) {
  98. 			m.misc = obj;
  99. 			m.has_misc = MUSE_WAN_POLYMORPH;
  100. 		}
  101. 		nomore(MUSE_POT_POLYMORPH);
  102. 		if(obj->otyp == POT_POLYMORPH && !mtmp->cham
  103. 				&& monstr[monsndx(mdat)] < 6) {
  104. 			m.misc = obj;
  105. 			m.has_misc = MUSE_POT_POLYMORPH;
  106. 		}
  107. 	}
  108. 	return((boolean)(!!m.has_misc));
  109. #undef nomore
  110. }

muse_newcham_mon

  1. /* type of monster to polymorph into; defaults to one suitable for the
  2. current level rather than the totally arbitrary choice of newcham() */
  3. static struct permonst *
  4. muse_newcham_mon(mon)
  5. struct monst *mon;
  6. {
  7. 	struct obj *m_armr;
  8.  
  9. 	if ((m_armr = which_armor(mon, W_ARM)) != 0) {
  10. 	    if (Is_dragon_scales(m_armr))
  11. 		return Dragon_scales_to_pm(m_armr);
  12. 	    else if (Is_dragon_mail(m_armr))
  13. 		return Dragon_mail_to_pm(m_armr);
  14. 	}
  15. 	return rndmonst();
  16. }

use_misc

  1. int
  2. use_misc(mtmp)
  3. struct monst *mtmp;
  4. {
  5. 	int i;
  6. 	struct obj *otmp = m.misc;
  7. 	boolean vis, vismon, oseen;
  8. 	char nambuf[BUFSZ];
  9.  
  10. 	if ((i = precheck(mtmp, otmp)) != 0) return i;
  11. 	vis = cansee(mtmp->mx, mtmp->my);
  12. 	vismon = canseemon(mtmp);
  13. 	oseen = otmp && vismon;
  14.  
  15. 	switch(m.has_misc) {
  16. 	case MUSE_POT_GAIN_LEVEL:
  17. 		mquaffmsg(mtmp, otmp);
  18. 		if (otmp->cursed) {
  19. 		    if (Can_rise_up(mtmp->mx, mtmp->my, &u.uz)) {
  20. 			register int tolev = depth(&u.uz)-1;
  21. 			d_level tolevel;
  22.  
  23. 			get_level(&tolevel, tolev);
  24. 			/* insurance against future changes... */
  25. 			if(on_level(&tolevel, &u.uz)) goto skipmsg;
  26. 			if (vismon) {
  27. 			    pline("%s rises up, through the %s!",
  28. 				  Monnam(mtmp), ceiling(mtmp->mx, mtmp->my));
  29. 			    if(!objects[POT_GAIN_LEVEL].oc_name_known
  30. 			      && !objects[POT_GAIN_LEVEL].oc_uname)
  31. 				docall(otmp);
  32. 			}
  33. 			m_useup(mtmp, otmp);
  34. 			migrate_to_level(mtmp, ledger_no(&tolevel),
  35. 					 MIGR_RANDOM, (coord *)0);
  36. 			return 2;
  37. 		    } else {
  38. skipmsg:
  39. 			if (vismon) {
  40. 			    pline("%s looks uneasy.", Monnam(mtmp));
  41. 			    if(!objects[POT_GAIN_LEVEL].oc_name_known
  42. 			      && !objects[POT_GAIN_LEVEL].oc_uname)
  43. 				docall(otmp);
  44. 			}
  45. 			m_useup(mtmp, otmp);
  46. 			return 2;
  47. 		    }
  48. 		}
  49. 		if (vismon) pline("%s seems more experienced.", Monnam(mtmp));
  50. 		if (oseen) makeknown(POT_GAIN_LEVEL);
  51. 		m_useup(mtmp, otmp);
  52. 		if (!grow_up(mtmp,(struct monst *)0)) return 1;
  53. 			/* grew into genocided monster */
  54. 		return 2;
  55. 	case MUSE_WAN_MAKE_INVISIBLE:
  56. 	case MUSE_POT_INVISIBILITY:
  57. 		if (otmp->otyp == WAN_MAKE_INVISIBLE) {
  58. 		    mzapmsg(mtmp, otmp, TRUE);
  59. 		    otmp->spe--;
  60. 		} else
  61. 		    mquaffmsg(mtmp, otmp);
  62. 		/* format monster's name before altering its visibility */
  63. 		Strcpy(nambuf, See_invisible ? Monnam(mtmp) : mon_nam(mtmp));
  64. 		mon_set_minvis(mtmp);
  65. 		if (vismon && mtmp->minvis) {	/* was seen, now invisible */
  66. 		    if (See_invisible)
  67. 			pline("%s body takes on a %s transparency.",
  68. 			      s_suffix(nambuf),
  69. 			      Hallucination ? "normal" : "strange");
  70. 		    else
  71. 			pline("Suddenly you cannot see %s.", nambuf);
  72. 		    if (oseen) makeknown(otmp->otyp);
  73. 		}
  74. 		if (otmp->otyp == POT_INVISIBILITY) {
  75. 		    if (otmp->cursed) you_aggravate(mtmp);
  76. 		    m_useup(mtmp, otmp);
  77. 		}
  78. 		return 2;
  79. 	case MUSE_WAN_SPEED_MONSTER:
  80. 		mzapmsg(mtmp, otmp, TRUE);
  81. 		otmp->spe--;
  82. 		mon_adjust_speed(mtmp, 1, otmp);
  83. 		return 2;
  84. 	case MUSE_POT_SPEED:
  85. 		mquaffmsg(mtmp, otmp);
  86. 		/* note difference in potion effect due to substantially
  87. 		   different methods of maintaining speed ratings:
  88. 		   player's character becomes "very fast" temporarily;
  89. 		   monster becomes "one stage faster" permanently */
  90. 		mon_adjust_speed(mtmp, 1, otmp);
  91. 		m_useup(mtmp, otmp);
  92. 		return 2;
  93. 	case MUSE_WAN_POLYMORPH:
  94. 		mzapmsg(mtmp, otmp, TRUE);
  95. 		otmp->spe--;
  96. 		(void) newcham(mtmp, muse_newcham_mon(mtmp), TRUE, FALSE);
  97. 		if (oseen) makeknown(WAN_POLYMORPH);
  98. 		return 2;
  99. 	case MUSE_POT_POLYMORPH:
  100. 		mquaffmsg(mtmp, otmp);
  101. 		if (vismon) pline("%s suddenly mutates!", Monnam(mtmp));
  102. 		(void) newcham(mtmp, muse_newcham_mon(mtmp), FALSE, FALSE);
  103. 		if (oseen) makeknown(POT_POLYMORPH);
  104. 		m_useup(mtmp, otmp);
  105. 		return 2;
  106. 	case MUSE_POLY_TRAP:
  107. 		if (vismon)
  108. 		    pline("%s deliberately %s onto a polymorph trap!",
  109. 			Monnam(mtmp),
  110. 			makeplural(locomotion(mtmp->data, "jump")));
  111. 		if (vis) seetrap(t_at(trapx,trapy));
  112.  
  113. 		/*  don't use rloc() due to worms */
  114. 		remove_monster(mtmp->mx, mtmp->my);
  115. 		newsym(mtmp->mx, mtmp->my);
  116. 		place_monster(mtmp, trapx, trapy);
  117. 		if (mtmp->wormno) worm_move(mtmp);
  118. 		newsym(trapx, trapy);
  119.  
  120. 		(void) newcham(mtmp, (struct permonst *)0, FALSE, FALSE);
  121. 		return 2;
  122. 	case MUSE_BULLWHIP:
  123. 		/* attempt to disarm hero */
  124. 		if (uwep && !rn2(5)) {
  125. 		    const char *The_whip = vismon ? "The bullwhip" : "A whip";
  126. 		    int where_to = rn2(4);
  127. 		    struct obj *obj = uwep;
  128. 		    const char *hand;
  129. 		    char the_weapon[BUFSZ];
  130.  
  131. 		    Strcpy(the_weapon, the(xname(obj)));
  132. 		    hand = body_part(HAND);
  133. 		    if (bimanual(obj)) hand = makeplural(hand);
  134.  
  135. 		    if (vismon)
  136. 			pline("%s flicks a bullwhip towards your %s!",
  137. 			      Monnam(mtmp), hand);
  138. 		    if (obj->otyp == HEAVY_IRON_BALL) {
  139. 			pline("%s fails to wrap around %s.",
  140. 			      The_whip, the_weapon);
  141. 			return 1;
  142. 		    }
  143. 		    pline("%s wraps around %s you're wielding!",
  144. 			  The_whip, the_weapon);
  145. 		    if (welded(obj)) {
  146. 			pline("%s welded to your %s%c",
  147. 			      !is_plural(obj) ? "It is" : "They are",
  148. 			      hand, !obj->bknown ? '!' : '.');
  149. 			/* obj->bknown = 1; */ /* welded() takes care of this */
  150. 			where_to = 0;
  151. 		    }
  152. 		    if (!where_to) {
  153. 			pline_The("whip slips free.");  /* not `The_whip' */
  154. 			return 1;
  155. 		    } else if (where_to == 3 && hates_silver(mtmp->data) &&
  156. 			    objects[obj->otyp].oc_material == SILVER) {
  157. 			/* this monster won't want to catch a silver
  158. 			   weapon; drop it at hero's feet instead */
  159. 			where_to = 2;
  160. 		    }
  161. 		    freeinv(obj);
  162. 		    uwepgone();
  163. 		    switch (where_to) {
  164. 			case 1:		/* onto floor beneath mon */
  165. 			    pline("%s yanks %s from your %s!", Monnam(mtmp),
  166. 				  the_weapon, hand);
  167. 			    place_object(obj, mtmp->mx, mtmp->my);
  168. 			    break;
  169. 			case 2:		/* onto floor beneath you */
  170. 			    pline("%s yanks %s to the %s!", Monnam(mtmp),
  171. 				  the_weapon, surface(u.ux, u.uy));
  172. 			    dropy(obj);
  173. 			    break;
  174. 			case 3:		/* into mon's inventory */
  175. 			    pline("%s snatches %s!", Monnam(mtmp),
  176. 				  the_weapon);
  177. 			    (void) mpickobj(mtmp,obj);
  178. 			    break;
  179. 		    }
  180. 		    return 1;
  181. 		}
  182. 		return 0;
  183. 	case 0: return 0; /* i.e. an exploded wand */
  184. 	default: impossible("%s wanted to perform action %d?", Monnam(mtmp),
  185. 			m.has_misc);
  186. 		break;
  187. 	}
  188. 	return 0;
  189. }

you_aggravate

  1. STATIC_OVL void
  2. you_aggravate(mtmp)
  3. struct monst *mtmp;
  4. {
  5. 	pline("For some reason, %s presence is known to you.",
  6. 		s_suffix(noit_mon_nam(mtmp)));
  7. 	cls();
  8. #ifdef CLIPPING
  9. 	cliparound(mtmp->mx, mtmp->my);
  10. #endif
  11. 	show_glyph(mtmp->mx, mtmp->my, mon_to_glyph(mtmp));
  12. 	display_self();
  13. 	You_feel("aggravated at %s.", noit_mon_nam(mtmp));
  14. 	display_nhwindow(WIN_MAP, TRUE);
  15. 	docrt();
  16. 	if (unconscious()) {
  17. 		multi = -1;
  18. 		nomovemsg =
  19. 		      "Aggravated, you are jolted into full consciousness.";
  20. 	}
  21. 	newsym(mtmp->mx,mtmp->my);
  22. 	if (!canspotmon(mtmp))
  23. 	    map_invisible(mtmp->mx, mtmp->my);
  24. }

rnd_misc_item

  1. int
  2. rnd_misc_item(mtmp)
  3. struct monst *mtmp;
  4. {
  5. 	struct permonst *pm = mtmp->data;
  6. 	int difficulty = monstr[(monsndx(pm))];
  7.  
  8. 	if(is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)
  9. 			|| pm->mlet == S_GHOST
  10. # ifdef KOPS
  11. 			|| pm->mlet == S_KOP
  12. # endif
  13. 		) return 0;
  14. 	/* Unlike other rnd_item functions, we only allow _weak_ monsters
  15. 	 * to have this item; after all, the item will be used to strengthen
  16. 	 * the monster and strong monsters won't use it at all...
  17. 	 */
  18. 	if (difficulty < 6 && !rn2(30))
  19. 	    return rn2(6) ? POT_POLYMORPH : WAN_POLYMORPH;
  20.  
  21. 	if (!rn2(40) && !nonliving(pm)) return AMULET_OF_LIFE_SAVING;
  22.  
  23. 	switch (rn2(3)) {
  24. 		case 0:
  25. 			if (mtmp->isgd) return 0;
  26. 			return rn2(6) ? POT_SPEED : WAN_SPEED_MONSTER;
  27. 		case 1:
  28. 			if (mtmp->mpeaceful && !See_invisible) return 0;
  29. 			return rn2(6) ? POT_INVISIBILITY : WAN_MAKE_INVISIBLE;
  30. 		case 2:
  31. 			return POT_GAIN_LEVEL;
  32. 	}
  33. 	/*NOTREACHED*/
  34. 	return 0;
  35. }

searches_for_item

  1. boolean
  2. searches_for_item(mon, obj)
  3. struct monst *mon;
  4. struct obj *obj;
  5. {
  6. 	int typ = obj->otyp;
  7.  
  8. 	if (is_animal(mon->data) ||
  9. 		mindless(mon->data) ||
  10. 		mon->data == &mons[PM_GHOST])	/* don't loot bones piles */
  11. 	    return FALSE;
  12.  
  13. 	if (typ == WAN_MAKE_INVISIBLE || typ == POT_INVISIBILITY)
  14. 	    return (boolean)(!mon->minvis && !mon->invis_blkd && !attacktype(mon->data, AT_GAZE));
  15. 	if (typ == WAN_SPEED_MONSTER || typ == POT_SPEED)
  16. 	    return (boolean)(mon->mspeed != MFAST);
  17.  
  18. 	switch (obj->oclass) {
  19. 	case WAND_CLASS:
  20. 	    if (obj->spe <= 0)
  21. 		return FALSE;
  22. 	    if (typ == WAN_DIGGING)
  23. 		return (boolean)(!is_floater(mon->data));
  24. 	    if (typ == WAN_POLYMORPH)
  25. 		return (boolean)(monstr[monsndx(mon->data)] < 6);
  26. 	    if (objects[typ].oc_dir == RAY ||
  27. 		    typ == WAN_STRIKING ||
  28. 		    typ == WAN_TELEPORTATION ||
  29. 		    typ == WAN_CREATE_MONSTER)
  30. 		return TRUE;
  31. 	    break;
  32. 	case POTION_CLASS:
  33. 	    if (typ == POT_HEALING ||
  34. 		    typ == POT_EXTRA_HEALING ||
  35. 		    typ == POT_FULL_HEALING ||
  36. 		    typ == POT_POLYMORPH ||
  37. 		    typ == POT_GAIN_LEVEL ||
  38. 		    typ == POT_PARALYSIS ||
  39. 		    typ == POT_SLEEPING ||
  40. 		    typ == POT_ACID ||
  41. 		    typ == POT_CONFUSION)
  42. 		return TRUE;
  43. 	    if (typ == POT_BLINDNESS && !attacktype(mon->data, AT_GAZE))
  44. 		return TRUE;
  45. 	    break;
  46. 	case SCROLL_CLASS:
  47. 	    if (typ == SCR_TELEPORTATION || typ == SCR_CREATE_MONSTER
  48. 		    || typ == SCR_EARTH)
  49. 		return TRUE;
  50. 	    break;
  51. 	case AMULET_CLASS:
  52. 	    if (typ == AMULET_OF_LIFE_SAVING)
  53. 		return (boolean)(!nonliving(mon->data));
  54. 	    if (typ == AMULET_OF_REFLECTION)
  55. 		return TRUE;
  56. 	    break;
  57. 	case TOOL_CLASS:
  58. 	    if (typ == PICK_AXE)
  59. 		return (boolean)needspick(mon->data);
  60. 	    if (typ == UNICORN_HORN)
  61. 		return (boolean)(!obj->cursed && !is_unicorn(mon->data));
  62. 	    if (typ == FROST_HORN || typ == FIRE_HORN)
  63. 		return (obj->spe > 0);
  64. 	    break;
  65. 	case FOOD_CLASS:
  66. 	    if (typ == CORPSE)
  67. 		return (boolean)(((mon->misc_worn_check & W_ARMG) &&
  68. 				    touch_petrifies(&mons[obj->corpsenm])) ||
  69. 				(!resists_ston(mon) &&
  70. 				    (obj->corpsenm == PM_LIZARD ||
  71. 					(acidic(&mons[obj->corpsenm]) &&
  72. 					 obj->corpsenm != PM_GREEN_SLIME))));
  73. 	    if (typ == EGG)
  74. 		return (boolean)(touch_petrifies(&mons[obj->corpsenm]));
  75. 	    break;
  76. 	default:
  77. 	    break;
  78. 	}
  79.  
  80. 	return FALSE;
  81. }

mon_reflects

  1. boolean
  2. mon_reflects(mon,str)
  3. struct monst *mon;
  4. const char *str;
  5. {
  6. 	struct obj *orefl = which_armor(mon, W_ARMS);
  7.  
  8. 	if (orefl && orefl->otyp == SHIELD_OF_REFLECTION) {
  9. 	    if (str) {
  10. 		pline(str, s_suffix(mon_nam(mon)), "shield");
  11. 		makeknown(SHIELD_OF_REFLECTION);
  12. 	    }
  13. 	    return TRUE;
  14. 	} else if (arti_reflects(MON_WEP(mon))) {
  15. 	    /* due to wielded artifact weapon */
  16. 	    if (str)
  17. 		pline(str, s_suffix(mon_nam(mon)), "weapon");
  18. 	    return TRUE;
  19. 	} else if ((orefl = which_armor(mon, W_AMUL)) &&
  20. 				orefl->otyp == AMULET_OF_REFLECTION) {
  21. 	    if (str) {
  22. 		pline(str, s_suffix(mon_nam(mon)), "amulet");
  23. 		makeknown(AMULET_OF_REFLECTION);
  24. 	    }
  25. 	    return TRUE;
  26. 	} else if ((orefl = which_armor(mon, W_ARM)) &&
  27. 		(orefl->otyp == SILVER_DRAGON_SCALES || orefl->otyp == SILVER_DRAGON_SCALE_MAIL)) {
  28. 	    if (str)
  29. 		pline(str, s_suffix(mon_nam(mon)), "armor");
  30. 	    return TRUE;
  31. 	} else if (mon->data == &mons[PM_SILVER_DRAGON] ||
  32. 		mon->data == &mons[PM_CHROMATIC_DRAGON]) {
  33. 	    /* Silver dragons only reflect when mature; babies do not */
  34. 	    if (str)
  35. 		pline(str, s_suffix(mon_nam(mon)), "scales");
  36. 	    return TRUE;
  37. 	}
  38. 	return FALSE;
  39. }

ureflects

  1. boolean
  2. ureflects (fmt, str)
  3. const char *fmt, *str;
  4. {
  5. 	/* Check from outermost to innermost objects */
  6. 	if (EReflecting & W_ARMS) {
  7. 	    if (fmt && str) {
  8. 	    	pline(fmt, str, "shield");
  9. 	    	makeknown(SHIELD_OF_REFLECTION);
  10. 	    }
  11. 	    return TRUE;
  12. 	} else if (EReflecting & W_WEP) {
  13. 	    /* Due to wielded artifact weapon */
  14. 	    if (fmt && str)
  15. 	    	pline(fmt, str, "weapon");
  16. 	    return TRUE;
  17. 	} else if (EReflecting & W_AMUL) {
  18. 	    if (fmt && str) {
  19. 	    	pline(fmt, str, "medallion");
  20. 	    	makeknown(AMULET_OF_REFLECTION);
  21. 	    }
  22. 	    return TRUE;
  23. 	} else if (EReflecting & W_ARM) {
  24. 	    if (fmt && str)
  25. 	    	pline(fmt, str, "armor");
  26. 	    return TRUE;
  27. 	} else if (youmonst.data == &mons[PM_SILVER_DRAGON]) {
  28. 	    if (fmt && str)
  29. 	    	pline(fmt, str, "scales");
  30. 	    return TRUE;
  31. 	}
  32. 	return FALSE;
  33. }

munstone

  1. /* TRUE if the monster ate something */
  2. boolean
  3. munstone(mon, by_you)
  4. struct monst *mon;
  5. boolean by_you;
  6. {
  7. 	struct obj *obj;
  8.  
  9. 	if (resists_ston(mon)) return FALSE;
  10. 	if (mon->meating || !mon->mcanmove || mon->msleeping) return FALSE;
  11.  
  12. 	for(obj = mon->minvent; obj; obj = obj->nobj) {
  13. 	    /* Monsters can also use potions of acid */
  14. 	    if ((obj->otyp == POT_ACID) || (obj->otyp == CORPSE &&
  15. 	    		(obj->corpsenm == PM_LIZARD || (acidic(&mons[obj->corpsenm]) && obj->corpsenm != PM_GREEN_SLIME)))) {
  16. 		mon_consume_unstone(mon, obj, by_you, TRUE);
  17. 		return TRUE;
  18. 	    }
  19. 	}
  20. 	return FALSE;
  21. }

mon_consume_unstone

  1. STATIC_OVL void
  2. mon_consume_unstone(mon, obj, by_you, stoning)
  3. struct monst *mon;
  4. struct obj *obj;
  5. boolean by_you;
  6. boolean stoning;
  7. {
  8. int nutrit = (obj->otyp == CORPSE) ? dog_nutrition(mon, obj) : 0;
  9. /* also sets meating */
  10.  
  11. /* give a "<mon> is slowing down" message and also remove
  12. intrinsic speed (comparable to similar effect on the hero) */
  13. mon_adjust_speed(mon, -3, (struct obj *)0);
  14.  
  15. if (canseemon(mon)) {
  16. 	long save_quan = obj->quan;
  17.  
  18. 	obj->quan = 1L;
  19. 	pline("%s %ss %s.", Monnam(mon),
  20. 		    (obj->otyp == POT_ACID) ? "quaff" : "eat",
  21. 		    distant_name(obj,doname));
  22. 	obj->quan = save_quan;
  23. } else if (flags.soundok)
  24. 	You_hear("%s.", (obj->otyp == POT_ACID) ? "drinking" : "chewing");
  25. m_useup(mon, obj);
  26. if (((obj->otyp == POT_ACID) || acidic(&mons[obj->corpsenm])) &&
  27. 		    !resists_acid(mon)) {
  28. 	mon->mhp -= rnd(15);
  29. 	pline("%s has a very bad case of stomach acid.",
  30. 	    Monnam(mon));
  31. }
  32. if (mon->mhp <= 0) {
  33. 	pline("%s dies!", Monnam(mon));
  34. 	if (by_you) xkilled(mon, 0);
  35. 	else mondead(mon);
  36. 	return;
  37. }
  38. if (stoning && canseemon(mon)) {
  39. 	if (Hallucination)
  40. pline("What a pity - %s just ruined a future piece of art!",
  41. 	    mon_nam(mon));
  42. 	else
  43. 	    pline("%s seems limber!", Monnam(mon));
  44. }
  45. if (obj->otyp == CORPSE && obj->corpsenm == PM_LIZARD && mon->mconf) {
  46. 	mon->mconf = 0;
  47. 	if (canseemon(mon))
  48. 	    pline("%s seems steadier now.", Monnam(mon));
  49. }
  50. if (mon->mtame && !mon->isminion && nutrit > 0) {
  51. 	struct edog *edog = EDOG(mon);
  52.  
  53. 	if (edog->hungrytime < monstermoves) edog->hungrytime = monstermoves;
  54. 	edog->hungrytime += nutrit;
  55. 	mon->mconf = 0;
  56. }
  57. mon->mlstmv = monstermoves; /* it takes a turn */
  58. }
  59.  
  60. /*muse.c*/