Source:NetHack 3.4.0/muse.c

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

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

1.   /*	SCCS Id: @(#)muse.c	3.4	2002/02/07	*/ 2.   /*	Copyright (C) 1990 by Ken Arromdee			   */ 3.   /* NetHack may be freely redistributed. See license for details. */ 4.     5.    /*  6.     * Monster item usage routines. 7.    */  8.     9.    #include "hack.h"  10. #include "edog.h" 11. 12.  extern const int monstr[]; 13.   14.   boolean m_using = FALSE; 15.   16.   /* Let monsters use magic items. Arbitrary assumptions: Monsters only use 17.   * scrolls when they can see, monsters know when wands have 0 charges, monsters 18.   * cannot recognize if items are cursed are not, monsters which are confused 19.   * don't know not to read scrolls, etc....  20. */ 21.    22.   STATIC_DCL struct permonst *FDECL(muse_newcham_mon, (struct monst *)); 23.  STATIC_DCL int FDECL(precheck, (struct monst *,struct obj *)); 24.  STATIC_DCL void FDECL(mzapmsg, (struct monst *,struct obj *,BOOLEAN_P)); 25.  STATIC_DCL void FDECL(mreadmsg, (struct monst *,struct obj *)); 26.  STATIC_DCL void FDECL(mquaffmsg, (struct monst *,struct obj *)); 27.  STATIC_PTR int FDECL(mbhitm, (struct monst *,struct obj *)); 28.  STATIC_DCL void FDECL(mbhit,  29.   	(struct monst *,int,int FDECL((*),(MONST_P,OBJ_P)), 30.  	int FDECL((*),(OBJ_P,OBJ_P)),struct obj *)); 31.  STATIC_DCL void FDECL(you_aggravate, (struct monst *)); 32.  STATIC_DCL void FDECL(mon_consume_unstone, (struct monst *,struct obj *, 33.  	BOOLEAN_P,BOOLEAN_P)); 34.   35.   static struct musable { 36.  	struct obj *offensive; 37.  	struct obj *defensive; 38.  	struct obj *misc; 39.  	int has_offense, has_defense, has_misc; 40.  	/* =0, no capability; otherwise, different numbers. 41.  	 * If it's an object, the object is also set (it's 0 otherwise). 42.  	 */  43.   } m;  44. static int trapx, trapy; 45.  static boolean zap_oseen; 46.  	/* for wands which use mbhitm and are zapped at players. We usually 47.  	 * want an oseen local to the function, but this is impossible since the 48.  	 * function mbhitm has to be compatible with the normal zap routines, 49.  	 * and those routines don't remember who zapped the wand. 50.  	 */  51.    52.   /* Any preliminary checks which may result in the monster being unable to use 53.   * the item. Returns 0 if nothing happened, 2 if the monster can't do anything 54.   * (i.e. it teleported) and 1 if it's dead. 55.   */  56.   STATIC_OVL int 57.  precheck(mon, obj) 58.  struct monst *mon; 59.  struct obj *obj; 60.  {  61.   	boolean vis; 62.   63.   	if (!obj) return 0; 64.  	vis = cansee(mon->mx, mon->my); 65.   66.   	if (obj->oclass == POTION_CLASS) { 67.  	    coord cc; 68.  	    static const char *empty = "The potion turns out to be empty."; 69.  	    const char *potion_descr; 70.  	    struct monst *mtmp; 71.  #define POTION_OCCUPANT_CHANCE(n) (13 + 2*(n))	/* also in potion.c */ 72.   73.   	    potion_descr = OBJ_DESCR(objects[obj->otyp]); 74.  	    if (potion_descr && !strcmp(potion_descr, "milky")) { 75.  	        if ( flags.ghost_count < MAXMONNO &&  76.   		    !rn2(POTION_OCCUPANT_CHANCE(flags.ghost_count))) { 77.  		    if (!enexto(&cc, mon->mx, mon->my, &mons[PM_GHOST])) return 0; 78.  		    mquaffmsg(mon, obj); 79.  		    m_useup(mon, obj); 80.  		    mtmp = makemon(&mons[PM_GHOST], cc.x, cc.y, NO_MM_FLAGS); 81.  		    if (!mtmp) { 82.  			if (vis) pline(empty); 83.  		    } else { 84.  			if (vis) { 85.  			    pline("As %s opens the bottle, an enormous %s emerges!",  86.   			       mon_nam(mon),  87.   			       Hallucination ? rndmonnam : (const char *)"ghost"); 88.  			    pline("%s is frightened to death, and unable to move.",  89.   				    Monnam(mon)); 90.  			}  91.   			mon->mcanmove = 0; 92.  			mon->mfrozen = 3; 93.  		    }  94.   		    return 2; 95.  		}  96.   	    }  97.   	    if (potion_descr && !strcmp(potion_descr, "smoky") &&  98.   		    flags.djinni_count < MAXMONNO &&  99.   		    !rn2(POTION_OCCUPANT_CHANCE(flags.djinni_count))) { 100. 		if (!enexto(&cc, mon->mx, mon->my, &mons[PM_DJINNI])) return 0; 101. 		mquaffmsg(mon, obj); 102. 		m_useup(mon, obj); 103. 		mtmp = makemon(&mons[PM_DJINNI], cc.x, cc.y, NO_MM_FLAGS); 104. 		if (!mtmp) { 105. 		    if (vis) pline(empty); 106. 		} else { 107. 		    if (vis) 108. 			pline("In a cloud of smoke, %s emerges!",  109.  							a_monnam(mtmp)); 110. 		    pline("%s speaks.", vis ? Monnam(mtmp) : Something); 111. 		/* I suspect few players will be upset that monsters */ 112. 		/* can't wish for wands of death here.... */ 113.  		    if (rn2(2)) { 114. 			verbalize("You freed me!"); 115. 			mtmp->mpeaceful = 1; 116. 			set_malign(mtmp); 117. 		    } else { 118. 			verbalize("It is about time."); 119. 			if (vis) pline("%s vanishes.", Monnam(mtmp)); 120. 			mongone(mtmp); 121. 		    }  122.  		}  123.  		return 2; 124. 	    }  125.  	}  126.  	if (obj->oclass == WAND_CLASS && obj->cursed && !rn2(100)) { 127. 	    int dam = d(obj->spe+2, 6); 128.  129.  	    if (flags.soundok) { 130. 		if (vis) pline("%s zaps %s, which suddenly explodes!",  131.  			Monnam(mon), an(xname(obj))); 132. 		else You_hear("a zap and an explosion in the distance."); 133. 	    }  134.  	    m_useup(mon, obj); 135. 	    if (mon->mhp <= dam) { 136. 		monkilled(mon, "", AD_RBRE); 137. 		return 1; 138. 	    }  139.  	    else mon->mhp -= dam; 140. 	    m.has_defense = m.has_offense = m.has_misc = 0; 141. 	    /* Only one needed to be set to 0 but the others are harmless */ 142. 	}  143.  	return 0; 144. }  145.   146.  STATIC_OVL void 147. mzapmsg(mtmp, otmp, self) 148. struct monst *mtmp; 149. struct obj *otmp; 150. boolean self; 151. {  152.  	if (!canseemon(mtmp)) { 153. 		if (flags.soundok) 154. 			You_hear("a %s zap.",  155.  					(distu(mtmp->mx,mtmp->my) <= (BOLT_LIM+1)*(BOLT_LIM+1)) ?  156.  					"nearby" : "distant"); 157. 	} else if (self) 158. 		pline("%s zaps %sself with %s!",  159.  		      Monnam(mtmp), mhim(mtmp), doname(otmp)); 160. 	else { 161. 		pline("%s zaps %s!", Monnam(mtmp), an(xname(otmp))); 162. 		stop_occupation; 163. 	}  164.  }  165.   166.  STATIC_OVL void 167. mreadmsg(mtmp, otmp) 168. struct monst *mtmp; 169. struct obj *otmp; 170. {  171.  	boolean vismon = canseemon(mtmp); 172. 	char onambuf[BUFSZ]; 173. 	short saverole; 174. 	unsigned savebknown; 175.  176.  	if (!vismon && !flags.soundok) 177. 	    return;		/* no feedback */ 178.  179.  	otmp->dknown = 1;  /* seeing or hearing it read reveals its label */ 180. 	/* shouldn't be able to hear curse/bless status of unseen scrolls; 181. 	   for priest characters, bknown will always be set during naming */ 182. 	savebknown = otmp->bknown; 183. 	saverole = Role_switch; 184. 	if (!vismon) { 185. 	    otmp->bknown = 0; 186. 	    if (Role_if(PM_PRIEST)) Role_switch = 0; 187. 	}  188.  	Strcpy(onambuf, singular(otmp, doname)); 189. 	Role_switch = saverole; 190. 	otmp->bknown = savebknown; 191.  192.  	if (vismon) 193. 	    pline("%s reads %s!", Monnam(mtmp), onambuf); 194. 	else 195. 	    You_hear("%s reading %s.",  196.  		x_monnam(mtmp, ARTICLE_A, (char *)0, 197. 		    (SUPPRESS_IT|SUPPRESS_INVISIBLE|SUPPRESS_SADDLE), FALSE),  198.  		onambuf); 199.  200.  	if (mtmp->mconf) 201. 	    pline("Being confused, %s mispronounces the magic words...",  202.  		  vismon ? mon_nam(mtmp) : mhe(mtmp)); 203. }  204.   205.  STATIC_OVL void 206. mquaffmsg(mtmp, otmp) 207. struct monst *mtmp; 208. struct obj *otmp; 209. {  210.  	if (canseemon(mtmp)) { 211. 		otmp->dknown = 1; 212. 		pline("%s drinks %s!", Monnam(mtmp), singular(otmp, doname)); 213. 	} else 214. 		if (flags.soundok) 215. 			You_hear("a chugging sound."); 216. }  217.   218.  /* Defines for various types of stuff. The order in which monsters prefer 219.  * to use them is determined by the order of the code logic, not the 220.  * numerical order in which they are defined. 221.  */  222.  #define MUSE_SCR_TELEPORTATION 1 223. #define MUSE_WAN_TELEPORTATION_SELF 2 224. #define MUSE_POT_HEALING 3 225. #define MUSE_POT_EXTRA_HEALING 4 226. #define MUSE_WAN_DIGGING 5 227. #define MUSE_TRAPDOOR 6 228. #define MUSE_TELEPORT_TRAP 7 229. #define MUSE_UPSTAIRS 8 230. #define MUSE_DOWNSTAIRS 9 231. #define MUSE_WAN_CREATE_MONSTER 10 232. #define MUSE_SCR_CREATE_MONSTER 11 233. #define MUSE_UP_LADDER 12 234. #define MUSE_DN_LADDER 13 235. #define MUSE_SSTAIRS 14 236. #define MUSE_WAN_TELEPORTATION 15 237. #define MUSE_BUGLE 16 238. #define MUSE_UNICORN_HORN 17 239. #define MUSE_POT_FULL_HEALING 18 240. #define MUSE_LIZARD_CORPSE 19 241. /*  242.  #define MUSE_INNATE_TPT 9999 243.  * We cannot use this. Since monsters get unlimited teleportation, if they 244.  * were allowed to teleport at will you could never catch them. Instead, 245.  * assume they only teleport at random times, despite the inconsistency that if  246. * you polymorph into one you teleport at will. 247.  */  248.   249.  /* Select a defensive item/action for a monster. Returns TRUE iff one is 250. * found. 251.  */  252.  boolean 253. find_defensive(mtmp) 254. struct monst *mtmp; 255. {  256.  	register struct obj *obj = 0; 257. 	struct trap *t; 258. 	int x=mtmp->mx, y=mtmp->my; 259. 	boolean stuck = (mtmp == u.ustuck); 260. 	boolean immobile = (mtmp->data->mmove == 0); 261. 	int fraction; 262.  263.  	if (is_animal(mtmp->data) || mindless(mtmp->data)) 264. 		return FALSE; 265. 	if(dist2(x, y, mtmp->mux, mtmp->muy) > 25) 266. 		return FALSE; 267. 	if (u.uswallow && stuck) return FALSE; 268.  269.  	m.defensive = (struct obj *)0; 270. 	m.has_defense = 0; 271.  272.  	/* since unicorn horns don't get used up, the monster would look 273. 	 * silly trying to use the same cursed horn round after round 274. 	 */  275.  	if (mtmp->mconf || mtmp->mstun || !mtmp->mcansee) { 276. 	    if (!is_unicorn(mtmp->data) && !nohands(mtmp->data)) { 277. 		for(obj = mtmp->minvent; obj; obj = obj->nobj) 278. 		    if (obj->otyp == UNICORN_HORN && !obj->cursed) 279. 			break; 280. 	    }  281.  	    if (obj || is_unicorn(mtmp->data)) { 282. 		m.defensive = obj; 283. 		m.has_defense = MUSE_UNICORN_HORN; 284. 		return TRUE; 285. 	    }  286.  	}  287.   288.  	if (mtmp->mconf) { 289. 	    for(obj = mtmp->minvent; obj; obj = obj->nobj) { 290. 		if (obj->otyp == CORPSE && obj->corpsenm == PM_LIZARD) { 291. 		    m.defensive = obj; 292. 		    m.has_defense = MUSE_LIZARD_CORPSE; 293. 		    return TRUE; 294. 		}  295.  	    }  296.  	}  297.   298.  	/* It so happens there are two unrelated cases when we might want to  299. * check specifically for healing alone. The first is when the monster 300. 	 * is blind (healing cures blindness). The second is when the monster 301. 	 * is peaceful; then we don't want to flee the player, and by  302. * coincidence healing is all there is that doesn't involve fleeing. 303. 	 * These would be hard to combine because of the control flow. 304. 	 * Pestilence won't use healing even when blind. 305. 	 */  306.  	if (!mtmp->mcansee && !nohands(mtmp->data) &&  307.  		mtmp->data != &mons[PM_PESTILENCE]) { 308. 	    if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) { 309. 		m.defensive = obj; 310. 		m.has_defense = MUSE_POT_FULL_HEALING; 311. 		return TRUE; 312. 	    }  313.  	    if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) { 314. 		m.defensive = obj; 315. 		m.has_defense = MUSE_POT_EXTRA_HEALING; 316. 		return TRUE; 317. 	    }  318.  	    if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) { 319. 		m.defensive = obj; 320. 		m.has_defense = MUSE_POT_HEALING; 321. 		return TRUE; 322. 	    }  323.  	}  324.   325.  	fraction = u.ulevel < 10 ? 5 : u.ulevel < 14 ? 4 : 3; 326.  	if(mtmp->mhp >= mtmp->mhpmax ||  327.  			(mtmp->mhp >= 10 && mtmp->mhp*fraction >= mtmp->mhpmax)) 328. 		return FALSE; 329.  330.  	if (mtmp->mpeaceful) { 331. 	    if (!nohands(mtmp->data)) { 332. 		if ((obj = m_carrying(mtmp, POT_FULL_HEALING)) != 0) { 333. 		    m.defensive = obj; 334. 		    m.has_defense = MUSE_POT_FULL_HEALING; 335. 		    return TRUE; 336. 		}  337.  		if ((obj = m_carrying(mtmp, POT_EXTRA_HEALING)) != 0) { 338. 		    m.defensive = obj; 339. 		    m.has_defense = MUSE_POT_EXTRA_HEALING; 340. 		    return TRUE; 341. 		}  342.  		if ((obj = m_carrying(mtmp, POT_HEALING)) != 0) { 343. 		    m.defensive = obj; 344. 		    m.has_defense = MUSE_POT_HEALING; 345. 		    return TRUE; 346. 		}  347.  	    }  348.  	    return FALSE; 349. 	}  350.   351.  	if (levl[x][y].typ == STAIRS && !stuck && !immobile) { 352. 		if (x == xdnstair && y == ydnstair && !is_floater(mtmp->data)) 353. 			m.has_defense = MUSE_DOWNSTAIRS; 354. 		if (x == xupstair && y == yupstair && ledger_no(&u.uz) != 1) 355. 	/* Unfair to let the monsters leave the dungeon with the Amulet */ 356. 	/* (or go to the endlevel since you also need it, to get there) */ 357. 			m.has_defense = MUSE_UPSTAIRS; 358. 	} else if (levl[x][y].typ == LADDER && !stuck && !immobile) { 359. 		if (x == xupladder && y == yupladder) 360. 			m.has_defense = MUSE_UP_LADDER; 361. 		if (x == xdnladder && y == ydnladder && !is_floater(mtmp->data)) 362. 			m.has_defense = MUSE_DN_LADDER; 363. 	} else if (sstairs.sx && sstairs.sx == x && sstairs.sy == y) { 364. 		m.has_defense = MUSE_SSTAIRS; 365. 	} else if (!stuck && !immobile) { 366. 	/* Note: trap doors take precedence over teleport traps. */ 367.  		int xx, yy; 368.  369.  		for(xx = x-1; xx <= x+1; xx++) for(yy = y-1; yy <= y+1; yy++) 370. 		if (isok(xx,yy)) 371. 		if (xx != u.ux && yy != u.uy) 372. 		if (mtmp->data != &mons[PM_GRID_BUG] || xx == x || yy == y)  373. if ((xx==x && yy==y) || !level.monsters[xx][yy]) 374. 		if ((t = t_at(xx,yy)) != 0) 375. 		if ((verysmall(mtmp->data) || throws_rocks(mtmp->data) || 376. 		     passes_walls(mtmp->data)) || !sobj_at(BOULDER, xx, yy)) 377. 		if (!onscary(xx,yy,mtmp)) { 378. 			if ((t->ttyp == TRAPDOOR || t->ttyp == HOLE)  379.  				&& !is_floater(mtmp->data)  380.  				&& !mtmp->isshk && !mtmp->isgd  381.  				&& !mtmp->ispriest  382.  				&& Can_fall_thru(&u.uz)  383.  						) { 384. 				trapx = xx; 385. 				trapy = yy; 386. 				m.has_defense = MUSE_TRAPDOOR; 387. 			} else if (t->ttyp == TELEP_TRAP && m.has_defense != MUSE_TRAPDOOR) { 388. 				trapx = xx; 389. 				trapy = yy; 390. 				m.has_defense = MUSE_TELEPORT_TRAP; 391. 			}  392.  		}  393.  	}  394.   395.  	if (nohands(mtmp->data))	/* can't use objects */ 396. 		goto botm; 397.  398.  	if (is_mercenary(mtmp->data) && (obj = m_carrying(mtmp, BUGLE))) { 399. 		int xx, yy; 400. 		struct monst *mon; 401.  402.  		/* Distance is arbitrary. What we really want to do is 403. * have the soldier play the bugle when it sees or 404. * remembers soldiers nearby... 405. */ 406.  		for(xx = x-3; xx <= x+3; xx++) for(yy = y-3; yy <= y+3; yy++) 407. 		if (isok(xx,yy)) 408. 		if ((mon = m_at(xx,yy)) && is_mercenary(mon->data) &&  409.  				mon->data != &mons[PM_GUARD] &&  410.  				(mon->msleeping || (!mon->mcanmove))) { 411. 			m.defensive = obj; 412. 			m.has_defense = MUSE_BUGLE; 413. 		}  414.  	}  415.   416.  	/* use immediate physical escape prior to attempting magic */ 417. 	if (m.has_defense)    /* stairs, trap door or tele-trap, bugle alert */ 418. 		goto botm; 419.  420.  	/* kludge to cut down on trap destruction (particularly portals) */ 421. 	t = t_at(x,y); 422. 	if (t && (t->ttyp == PIT || t->ttyp == SPIKED_PIT || 423. 		  t->ttyp == WEB || t->ttyp == BEAR_TRAP)) 424. 		t = 0;		/* ok for monster to dig here */ 425.  426.  #define nomore(x) if(m.has_defense==x) continue; 427. 	for (obj = mtmp->minvent; obj; obj = obj->nobj) { 428. 		/* don't always use the same selection pattern */ 429. 		if (m.has_defense && !rn2(3)) break; 430.  431.  		/* nomore(MUSE_WAN_DIGGING); */ 432. 		if (m.has_defense == MUSE_WAN_DIGGING) break; 433. 		if (obj->otyp == WAN_DIGGING && obj->spe > 0 && !stuck && !t  434.  		    && !mtmp->isshk && !mtmp->isgd && !mtmp->ispriest  435.  		    && !is_floater(mtmp->data)  436.  		    /* monsters digging in Sokoban can ruin things */  437.  		    && !In_sokoban(&u.uz)  438.  		    /* digging wouldn't be effective; assume they know that */  439.  		    && !(levl[x][y].wall_info & W_NONDIGGABLE)  440.  		    && !(Is_botlevel(&u.uz) || In_endgame(&u.uz))  441.  		    && !(is_ice(x,y) || is_pool(x,y) || is_lava(x,y))) { 442. 			m.defensive = obj; 443. 			m.has_defense = MUSE_WAN_DIGGING; 444. 		}  445.  		nomore(MUSE_WAN_TELEPORTATION_SELF); 446. 		nomore(MUSE_WAN_TELEPORTATION); 447. 		if(obj->otyp == WAN_TELEPORTATION && obj->spe > 0) { 448. 			m.defensive = obj; 449. 			m.has_defense = (mon_has_amulet(mtmp)) 450. 				? MUSE_WAN_TELEPORTATION 451. 				: MUSE_WAN_TELEPORTATION_SELF; 452. 		}  453.  		nomore(MUSE_SCR_TELEPORTATION); 454. 		if(obj->otyp == SCR_TELEPORTATION && mtmp->mcansee  455.  		   && haseyes(mtmp->data)  456.  		   && (!obj->cursed || 457. 		       (!(mtmp->isshk && inhishop(mtmp))  458.  			    && !mtmp->isgd && !mtmp->ispriest))) { 459. 			m.defensive = obj; 460. 			m.has_defense = MUSE_SCR_TELEPORTATION; 461. 		}  462.   463.  	    if (mtmp->data != &mons[PM_PESTILENCE]) { 464. 		nomore(MUSE_POT_FULL_HEALING); 465. 		if(obj->otyp == POT_FULL_HEALING) { 466. 			m.defensive = obj; 467. 			m.has_defense = MUSE_POT_FULL_HEALING; 468. 		}  469.  		nomore(MUSE_POT_EXTRA_HEALING); 470. 		if(obj->otyp == POT_EXTRA_HEALING) { 471. 			m.defensive = obj; 472. 			m.has_defense = MUSE_POT_EXTRA_HEALING; 473. 		}  474.  		nomore(MUSE_WAN_CREATE_MONSTER); 475. 		if(obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) { 476. 			m.defensive = obj; 477. 			m.has_defense = MUSE_WAN_CREATE_MONSTER; 478. 		}  479.  		nomore(MUSE_POT_HEALING); 480. 		if(obj->otyp == POT_HEALING) { 481. 			m.defensive = obj; 482. 			m.has_defense = MUSE_POT_HEALING; 483. 		}  484.  	    } else {	/* Pestilence */ 485. 		nomore(MUSE_POT_FULL_HEALING); 486. 		if (obj->otyp == POT_SICKNESS) { 487. 			m.defensive = obj; 488. 			m.has_defense = MUSE_POT_FULL_HEALING; 489. 		}  490.  		nomore(MUSE_WAN_CREATE_MONSTER); 491. 		if (obj->otyp == WAN_CREATE_MONSTER && obj->spe > 0) { 492. 			m.defensive = obj; 493. 			m.has_defense = MUSE_WAN_CREATE_MONSTER; 494. 		}  495.  	    }  496.  		nomore(MUSE_SCR_CREATE_MONSTER); 497. 		if(obj->otyp == SCR_CREATE_MONSTER) { 498. 			m.defensive = obj; 499. 			m.has_defense = MUSE_SCR_CREATE_MONSTER; 500. 		}  501.  	}  502.  botm:	return((boolean)(!!m.has_defense)); 503. #undef nomore 504. }  505.   506.  /* Perform a defensive action for a monster. Must be called immediately 507.  * after find_defensive. Return values are 0: did something, 1: died, 508.  * 2: did something and can't attack again (i.e. teleported). 509.  */  510.  int 511. use_defensive(mtmp) 512. struct monst *mtmp; 513. {  514.  	int i, fleetim, how = 0; 515. 	struct obj *otmp = m.defensive; 516. 	boolean vis, vismon, oseen; 517. 	const char *mcsa = "%s can see again."; 518.  519.  	if ((i = precheck(mtmp, otmp)) != 0) return i;  520. vis = cansee(mtmp->mx, mtmp->my); 521. 	vismon = canseemon(mtmp); 522. 	oseen = otmp && vismon; 523.  524.  	/* when using defensive choice to run away, we want monster to avoid 525. 	   rushing right straight back; don't override if already scared */ 526. 	fleetim = !mtmp->mflee ? (33 - (30 * mtmp->mhp / mtmp->mhpmax)) : 0; 527. #define m_flee(m)	if (fleetim && !m->iswiz) \ 528. 			{ monflee(m, fleetim, FALSE, FALSE); } 529.  530.  	switch(m.has_defense) { 531. 	case MUSE_UNICORN_HORN: 532. 		if (vismon) { 533. 		    if (otmp) 534. 			pline("%s uses a unicorn horn!", Monnam(mtmp)); 535. 		    else 536. 			pline_The("tip of %s's horn glows!", mon_nam(mtmp)); 537. 		}  538.  		if (!mtmp->mcansee) { 539. 		    mtmp->mcansee = 1; 540. 		    mtmp->mblinded = 0; 541. 		    if (vismon) pline(mcsa, Monnam(mtmp)); 542. 		} else if (mtmp->mconf || mtmp->mstun) { 543. 		    mtmp->mconf = mtmp->mstun = 0; 544. 		    if (vismon) 545. 			pline("%s seems steadier now.", Monnam(mtmp)); 546. 		} else impossible("No need for unicorn horn?"); 547. 		return 2; 548. 	case MUSE_BUGLE: 549. 		if (vismon) 550. 			pline("%s plays %s!", Monnam(mtmp), doname(otmp)); 551. 		else if (flags.soundok) 552. 			You_hear("a bugle playing reveille!"); 553. 		awaken_soldiers; 554. 		return 2; 555. 	case MUSE_WAN_TELEPORTATION_SELF: 556. 		if ((mtmp->isshk && inhishop(mtmp))  557.  		       || mtmp->isgd || mtmp->ispriest) return 2; 558. 		m_flee(mtmp); 559. 		mzapmsg(mtmp, otmp, TRUE); 560. 		otmp->spe--; 561. 		how = WAN_TELEPORTATION; 562. mon_tele: 563. 		if (tele_restrict(mtmp)) {	/* mysterious force... */ 564.  		    if (vismon && how)		/* mentions 'teleport' */ 565. 			makeknown(how); 566. 		    return 2; 567. 		}  568.  		if (( 569. #if 0 570. 			mon_has_amulet(mtmp) || 571. #endif 572. 			On_W_tower_level(&u.uz)) && !rn2(3)) { 573. 		    if (vismon) 574. 			pline("%s seems disoriented for a moment.",  575.  				Monnam(mtmp)); 576. 		    return 2; 577. 		}  578.  		if (oseen && how) makeknown(how); 579. 		rloc(mtmp); 580. 		return 2; 581. 	case MUSE_WAN_TELEPORTATION: 582. 		zap_oseen = oseen; 583. 		mzapmsg(mtmp, otmp, FALSE); 584. 		otmp->spe--; 585. 		m_using = TRUE; 586. 		mbhit(mtmp,rn1(8,6),mbhitm,bhito,otmp); 587. 		m_using = FALSE; 588. 		return 2; 589. 	case MUSE_SCR_TELEPORTATION: 590. 	    {  591.  		int obj_is_cursed = otmp->cursed; 592.  593.  		if (mtmp->isshk || mtmp->isgd || mtmp->ispriest) return 2; 594. 		m_flee(mtmp); 595. 		mreadmsg(mtmp, otmp); 596. 		m_useup(mtmp, otmp);	/* otmp might be free'ed */ 597. 		how = SCR_TELEPORTATION; 598. 		if (obj_is_cursed || mtmp->mconf) { 599. 			int nlev; 600. 			d_level flev; 601.  602.  			if (mon_has_amulet(mtmp) || In_endgame(&u.uz)) { 603. 			    if (vismon) 604. 				pline("%s seems very disoriented for a moment.",  605.  					Monnam(mtmp)); 606. 			    return 2; 607. 			}  608.  			nlev = random_teleport_level; 609. 			if (nlev == depth(&u.uz)) { 610. 			    if (vismon) 611. 				pline("%s shudders for a moment.",  612.  								Monnam(mtmp)); 613. 			    return 2; 614. 			}  615.  			get_level(&flev, nlev); 616. 			migrate_to_level(mtmp, ledger_no(&flev), MIGR_RANDOM,  617.  				(coord *)0); 618. 			if (oseen) makeknown(SCR_TELEPORTATION); 619. 		} else goto mon_tele; 620. 		return 2; 621. 	    }  622.  	case MUSE_WAN_DIGGING: 623. 	    {	struct trap *ttmp; 624.  625.  		m_flee(mtmp); 626. 		mzapmsg(mtmp, otmp, FALSE); 627. 		otmp->spe--; 628. 		if (oseen) makeknown(WAN_DIGGING); 629. 		if (IS_FURNITURE(levl[mtmp->mx][mtmp->my].typ) ||  630.  		    IS_DRAWBRIDGE(levl[mtmp->mx][mtmp->my].typ) ||  631.  		    (is_drawbridge_wall(mtmp->mx, mtmp->my) >= 0) ||  632.  		    (sstairs.sx && sstairs.sx == mtmp->mx && 633. 				   sstairs.sy == mtmp->my)) { 634. 			pline_The("digging ray is ineffective."); 635. 			return 2; 636. 		}  637.  		if (!Can_dig_down(&u.uz)) { 638. 		    if(canseemon(mtmp)) 639. 			pline_The("%s here is too hard to dig in.",  640.  					surface(mtmp->mx, mtmp->my)); 641. 		    return 2; 642. 		}  643.  		ttmp = maketrap(mtmp->mx, mtmp->my, HOLE); 644. 		if (!ttmp) return 2; 645. 		seetrap(ttmp); 646. 		if (vis) { 647. 		    pline("%s has made a hole in the %s.", Monnam(mtmp),  648.  				surface(mtmp->mx, mtmp->my)); 649. 		    pline("%s %s through...", Monnam(mtmp),  650.  			  is_flyer(mtmp->data) ? "dives" : "falls"); 651. 		} else if (flags.soundok) 652. 			You_hear("%s crash through the %s.", something,  653.  				surface(mtmp->mx, mtmp->my)); 654. 		/* we made sure that there is a level for mtmp to go to */ 655. 		migrate_to_level(mtmp, ledger_no(&u.uz) + 1,  656.  				 MIGR_RANDOM, (coord *)0); 657. 		return 2; 658. 	    }  659.  	case MUSE_WAN_CREATE_MONSTER: 660. 	    {	coord cc; 661. 		    /* pm: 0 => random, eel => aquatic, croc => amphibious */ 662. 		struct permonst *pm = !is_pool(mtmp->mx, mtmp->my) ? 0 : 663.  			     &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE]; 664. 		struct monst *mon; 665.  666.  		if (!enexto(&cc, mtmp->mx, mtmp->my, pm)) return 0; 667. 		mzapmsg(mtmp, otmp, FALSE); 668. 		otmp->spe--; 669. 		mon = makemon((struct permonst *)0, cc.x, cc.y, NO_MM_FLAGS); 670. 		if (mon && canspotmon(mon) && oseen) 671. 		    makeknown(WAN_CREATE_MONSTER); 672. 		return 2; 673. 	    }  674.  	case MUSE_SCR_CREATE_MONSTER: 675. 	    {	coord cc; 676. 		struct permonst *pm = 0, *fish = 0; 677. 		int cnt = 1; 678. 		struct monst *mon; 679. 		boolean known = FALSE; 680.  681.  		if (!rn2(73)) cnt += rnd(4); 682. 		if (mtmp->mconf || otmp->cursed) cnt += 12; 683. 		if (mtmp->mconf) pm = fish = &mons[PM_ACID_BLOB]; 684. 		else if (is_pool(mtmp->mx, mtmp->my)) 685. 		    fish = &mons[u.uinwater ? PM_GIANT_EEL : PM_CROCODILE]; 686. 		mreadmsg(mtmp, otmp); 687. 		while(cnt--) { 688. 		    /* `fish' potentially gives bias towards water locations; 689. 		       `pm' is what to actually create (0 => random) */ 690. 		    if (!enexto(&cc, mtmp->mx, mtmp->my, fish)) break; 691. 		    mon = makemon(pm, cc.x, cc.y, NO_MM_FLAGS); 692. 		    if (mon && canspotmon(mon)) known = TRUE; 693. 		}  694.  		/* The only case where we don't use oseen. For wands, you 695. 		 * have to be able to see the monster zap the wand to know 696. 		 * what type it is. For teleport scrolls, you have to see 697. 		 * the monster to know it teleported. 698. 		 */  699.  		if (known) 700. 		    makeknown(SCR_CREATE_MONSTER); 701. 		else if (!objects[SCR_CREATE_MONSTER].oc_name_known  702.  			&& !objects[SCR_CREATE_MONSTER].oc_uname) 703. 		    docall(otmp); 704. 		m_useup(mtmp, otmp); 705. 		return 2; 706. 	    }  707.  	case MUSE_TRAPDOOR: 708. 		/* trap doors on "bottom" levels of dungeons are rock-drop 709. 		 * trap doors, not holes in the floor. We check here for 710. 		 * safety. 711. 		 */  712.  		if (Is_botlevel(&u.uz)) return 0; 713. 		m_flee(mtmp); 714. 		if (vis) { 715. 			struct trap *t; 716. 			t = t_at(trapx,trapy); 717. 			pline("%s %s into a %s!", Monnam(mtmp),  718.  			makeplural(locomotion(mtmp->data, "jump")),  719.  			t->ttyp == TRAPDOOR ? "trap door" : "hole"); 720. 			if (levl[trapx][trapy].typ == SCORR) { 721. 			    levl[trapx][trapy].typ = CORR; 722. 			    unblock_point(trapx, trapy); 723. 			}  724.  			seetrap(t_at(trapx,trapy)); 725. 		}  726.   727.  		/*  don't use rloc_to because worm tails must "move" */ 728. 		remove_monster(mtmp->mx, mtmp->my); 729. 		newsym(mtmp->mx, mtmp->my);	/* update old location */ 730. 		place_monster(mtmp, trapx, trapy); 731. 		if (mtmp->wormno) worm_move(mtmp); 732. 		newsym(trapx, trapy); 733.  734.  		migrate_to_level(mtmp, ledger_no(&u.uz) + 1,  735.  				 MIGR_RANDOM, (coord *)0); 736. 		return 2; 737. 	case MUSE_UPSTAIRS: 738. 		/* Monsters without amulets escape the dungeon and are 739. 		 * gone for good when they leave up the up stairs. 740. 		 * Monsters with amulets would reach the endlevel, 741. 		 * which we cannot allow since that would leave the 742. 		 * player stranded. 743. 		 */  744.  		if (ledger_no(&u.uz) == 1) { 745. 			if (mon_has_special(mtmp)) 746. 				return 0; 747. 			if (vismon) 748. 			    pline("%s escapes the dungeon!", Monnam(mtmp)); 749. 			mongone(mtmp); 750. 			return 2; 751. 		}  752.  		m_flee(mtmp); 753. 		if (Inhell && mon_has_amulet(mtmp) && !rn2(4) &&  754.  			(dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz) - 3)) { 755. 		    if (vismon) pline(  756.       "As %s climbs the stairs, a mysterious force momentarily surrounds %s...",  757.  				     mon_nam(mtmp), mhim(mtmp)); 758. 		    /* simpler than for the player; this will usually be  759. the Wizard and he'll immediately go right to the 760. 		       upstairs, so there's not much point in having any 761. 		       chance for a random position on the current level */ 762. 		    migrate_to_level(mtmp, ledger_no(&u.uz) + 1,  763.  				     MIGR_RANDOM, (coord *)0); 764. 		} else { 765. 		    if (vismon) pline("%s escapes upstairs!", Monnam(mtmp)); 766. 		    migrate_to_level(mtmp, ledger_no(&u.uz) - 1,  767.  				     MIGR_STAIRS_DOWN, (coord *)0); 768. 		}  769.  		return 2; 770. 	case MUSE_DOWNSTAIRS: 771. 		m_flee(mtmp); 772. 		if (vismon) pline("%s escapes downstairs!", Monnam(mtmp)); 773. 		migrate_to_level(mtmp, ledger_no(&u.uz) + 1,  774.  				 MIGR_STAIRS_UP, (coord *)0); 775. 		return 2; 776. 	case MUSE_UP_LADDER: 777. 		m_flee(mtmp); 778. 		if (vismon) pline("%s escapes up the ladder!", Monnam(mtmp)); 779. 		migrate_to_level(mtmp, ledger_no(&u.uz) - 1,  780.  				 MIGR_LADDER_DOWN, (coord *)0); 781. 		return 2; 782. 	case MUSE_DN_LADDER: 783. 		m_flee(mtmp); 784. 		if (vismon) pline("%s escapes down the ladder!", Monnam(mtmp)); 785. 		migrate_to_level(mtmp, ledger_no(&u.uz) + 1,  786.  				 MIGR_LADDER_UP, (coord *)0); 787. 		return 2; 788. 	case MUSE_SSTAIRS: 789. 		m_flee(mtmp); 790. 		/* the stairs leading up from the 1st level are */ 791. 		/* regular stairs, not sstairs. */ 792.  		if (sstairs.up) { 793. 			if (vismon) 794. 			    pline("%s escapes upstairs!", Monnam(mtmp)); 795. 			if(Inhell) { 796. 			    migrate_to_level(mtmp, ledger_no(&sstairs.tolev),  797.  					     MIGR_RANDOM, (coord *)0); 798. 			    return 2; 799. 			}  800.  		} else	if (vismon) 801. 		    pline("%s escapes downstairs!", Monnam(mtmp)); 802. 		migrate_to_level(mtmp, ledger_no(&sstairs.tolev),  803.  				 MIGR_SSTAIRS, (coord *)0); 804. 		return 2; 805. 	case MUSE_TELEPORT_TRAP: 806. 		m_flee(mtmp); 807. 		if (vis) { 808. 			pline("%s %s onto a teleport trap!", Monnam(mtmp),  809.  				makeplural(locomotion(mtmp->data, "jump"))); 810. 			if (levl[trapx][trapy].typ == SCORR) { 811. 			    levl[trapx][trapy].typ = CORR; 812. 			    unblock_point(trapx, trapy); 813. 			}  814.  			seetrap(t_at(trapx,trapy)); 815. 		}  816.  		/*  don't use rloc_to because worm tails must "move" */ 817. 		remove_monster(mtmp->mx, mtmp->my); 818. 		newsym(mtmp->mx, mtmp->my);	/* update old location */ 819. 		place_monster(mtmp, trapx, trapy); 820. 		if (mtmp->wormno) worm_move(mtmp); 821. 		newsym(trapx, trapy); 822.  823.  		goto mon_tele; 824. 	case MUSE_POT_HEALING: 825. 		mquaffmsg(mtmp, otmp); 826. 		i = d(6 + 2 * bcsign(otmp), 4); 827. 		mtmp->mhp += i;  828. if (mtmp->mhp > mtmp->mhpmax) mtmp->mhp = ++mtmp->mhpmax; 829. 		if (!otmp->cursed && !mtmp->mcansee) { 830. 			mtmp->mcansee = 1; 831. 			mtmp->mblinded = 0; 832. 			if (vismon) pline(mcsa, Monnam(mtmp)); 833. 		}  834.  		if (vismon) pline("%s looks better.", Monnam(mtmp)); 835. 		if (oseen) makeknown(POT_HEALING); 836. 		m_useup(mtmp, otmp); 837. 		return 2; 838. 	case MUSE_POT_EXTRA_HEALING: 839. 		mquaffmsg(mtmp, otmp); 840. 		i = d(6 + 2 * bcsign(otmp), 8); 841. 		mtmp->mhp += i;  842. if (mtmp->mhp > mtmp->mhpmax) 843. 			mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 5 : 2)); 844.  		if (!mtmp->mcansee) { 845. 			mtmp->mcansee = 1; 846. 			mtmp->mblinded = 0; 847. 			if (vismon) pline(mcsa, Monnam(mtmp)); 848. 		}  849.  		if (vismon) pline("%s looks much better.", Monnam(mtmp)); 850. 		if (oseen) makeknown(POT_EXTRA_HEALING); 851. 		m_useup(mtmp, otmp); 852. 		return 2; 853. 	case MUSE_POT_FULL_HEALING: 854. 		mquaffmsg(mtmp, otmp); 855. 		if (otmp->otyp == POT_SICKNESS) unbless(otmp); /* Pestilence */ 856. 		mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 8 : 4)); 857.  		if (!mtmp->mcansee && otmp->otyp != POT_SICKNESS) { 858. 			mtmp->mcansee = 1; 859. 			mtmp->mblinded = 0; 860. 			if (vismon) pline(mcsa, Monnam(mtmp)); 861. 		}  862.  		if (vismon) pline("%s looks completely healed.", Monnam(mtmp)); 863. 		if (oseen) makeknown(otmp->otyp); 864. 		m_useup(mtmp, otmp); 865. 		return 2; 866. 	case MUSE_LIZARD_CORPSE: 867. 		/* not actually called for its unstoning effect */ 868. 		mon_consume_unstone(mtmp, otmp, FALSE, FALSE); 869. 		return 2; 870. 	case 0: return 0; /* i.e. an exploded wand */ 871. 	default: impossible("%s wanted to perform action %d?", Monnam(mtmp),  872.  			m.has_defense); 873. 		break; 874. 	}  875.  	return 0; 876. #undef m_flee 877. }  878.   879.  int 880. rnd_defensive_item(mtmp) 881. struct monst *mtmp; 882. {  883.  	struct permonst *pm = mtmp->data; 884. 	int difficulty = monstr[(monsndx(pm))]; 885.  886.  	if(is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)  887.  			|| pm->mlet == S_GHOST  888.  # ifdef KOPS  889.  			|| pm->mlet == S_KOP  890.  # endif  891.  		) return 0; 892. 	switch (rn2(8 + (difficulty > 3) + (difficulty > 6) + 893. 				(difficulty > 8))) { 894. 		case 6: case 9: 895. 			if (!rn2(3)) return WAN_TELEPORTATION; 896. 			/* else FALLTHRU */ 897. 		case 0: case 1: 898. 			return SCR_TELEPORTATION; 899. 		case 8: case 10: 900. 			if (!rn2(3)) return WAN_CREATE_MONSTER; 901. 			/* else FALLTHRU */ 902. 		case 2: return SCR_CREATE_MONSTER; 903. 		case 3: return POT_HEALING; 904. 		case 4: return POT_EXTRA_HEALING; 905. 		case 5: return (mtmp->data != &mons[PM_PESTILENCE]) ? 906. 				POT_FULL_HEALING : POT_SICKNESS; 907. 		case 7: if (is_floater(pm) || mtmp->isshk || mtmp->isgd  908.  						|| mtmp->ispriest  909.  									) 910. 				return 0; 911. 			else 912. 				return WAN_DIGGING; 913. 	}  914.  	/*NOTREACHED*/ 915. 	return 0; 916. }  917.   918.  #define MUSE_WAN_DEATH 1 919. #define MUSE_WAN_SLEEP 2 920. #define MUSE_WAN_FIRE 3 921. #define MUSE_WAN_COLD 4 922. #define MUSE_WAN_LIGHTNING 5 923. #define MUSE_WAN_MAGIC_MISSILE 6 924. #define MUSE_WAN_STRIKING 7 925. #define MUSE_SCR_FIRE 8 926. #define MUSE_POT_PARALYSIS 9 927. #define MUSE_POT_BLINDNESS 10 928. #define MUSE_POT_CONFUSION 11 929. #define MUSE_FROST_HORN 12 930. #define MUSE_FIRE_HORN 13 931. #define MUSE_POT_ACID 14 932. /*#define MUSE_WAN_TELEPORTATION 15*/ 933. #define MUSE_POT_SLEEPING 16 934. #define MUSE_SCR_EARTH 17 935.  936.  /* Select an offensive item/action for a monster. Returns TRUE iff one is 937. * found. 938.  */  939.  boolean 940. find_offensive(mtmp) 941. struct monst *mtmp; 942. {  943.  	register struct obj *obj; 944. 	boolean ranged_stuff = lined_up(mtmp); 945. 	boolean reflection_skip = (Reflecting && rn2(2)); 946. 	struct obj *helmet = which_armor(mtmp, W_ARMH); 947.  948.  	m.offensive = (struct obj *)0; 949. 	m.has_offense = 0; 950. 	if (mtmp->mpeaceful || is_animal(mtmp->data) ||  951.  				mindless(mtmp->data) || nohands(mtmp->data)) 952. 		return FALSE; 953. 	if (u.uswallow) return FALSE; 954. 	if (in_your_sanctuary(mtmp, 0, 0)) return FALSE; 955. 	if (dmgtype(mtmp->data, AD_HEAL) && !uwep  956.  #ifdef TOURIST  957.  	    && !uarmu  958.  #endif  959.  	    && !uarm && !uarmh && !uarms && !uarmg && !uarmc && !uarmf) 960. 		return FALSE; 961.  962.  	if (!ranged_stuff) return FALSE; 963. #define nomore(x) if(m.has_offense==x) continue; 964. 	for(obj=mtmp->minvent; obj; obj=obj->nobj) { 965. 		/* nomore(MUSE_WAN_DEATH); */ 966. 		if (!reflection_skip) { 967. 		    if(obj->otyp == WAN_DEATH && obj->spe > 0) { 968. 			m.offensive = obj; 969. 			m.has_offense = MUSE_WAN_DEATH; 970. 		    }  971.  		    nomore(MUSE_WAN_SLEEP); 972. 		    if(obj->otyp == WAN_SLEEP && obj->spe > 0 && multi >= 0) { 973. 			m.offensive = obj; 974. 			m.has_offense = MUSE_WAN_SLEEP; 975. 		    }  976.  		    nomore(MUSE_WAN_FIRE); 977. 		    if(obj->otyp == WAN_FIRE && obj->spe > 0) { 978. 			m.offensive = obj; 979. 			m.has_offense = MUSE_WAN_FIRE; 980. 		    }  981.  		    nomore(MUSE_FIRE_HORN); 982. 		    if(obj->otyp == FIRE_HORN && obj->spe > 0) { 983. 			m.offensive = obj; 984. 			m.has_offense = MUSE_FIRE_HORN; 985. 		    }  986.  		    nomore(MUSE_WAN_COLD); 987. 		    if(obj->otyp == WAN_COLD && obj->spe > 0) { 988. 			m.offensive = obj; 989. 			m.has_offense = MUSE_WAN_COLD; 990. 		    }  991.  		    nomore(MUSE_FROST_HORN); 992. 		    if(obj->otyp == FROST_HORN && obj->spe > 0) { 993. 			m.offensive = obj; 994. 			m.has_offense = MUSE_FROST_HORN; 995. 		    }  996.  		    nomore(MUSE_WAN_LIGHTNING); 997. 		    if(obj->otyp == WAN_LIGHTNING && obj->spe > 0) { 998. 			m.offensive = obj; 999. 			m.has_offense = MUSE_WAN_LIGHTNING; 1000. 		   }  1001. 		    nomore(MUSE_WAN_MAGIC_MISSILE); 1002. 		   if(obj->otyp == WAN_MAGIC_MISSILE && obj->spe > 0) { 1003. 			m.offensive = obj; 1004. 			m.has_offense = MUSE_WAN_MAGIC_MISSILE; 1005. 		   }  1006. 		}  1007. 		nomore(MUSE_WAN_STRIKING); 1008. 		if(obj->otyp == WAN_STRIKING && obj->spe > 0) { 1009. 			m.offensive = obj; 1010. 			m.has_offense = MUSE_WAN_STRIKING; 1011. 		} 1012. 		nomore(MUSE_POT_PARALYSIS); 1013. 		if(obj->otyp == POT_PARALYSIS && multi >= 0) { 1014. 			m.offensive = obj; 1015. 			m.has_offense = MUSE_POT_PARALYSIS; 1016. 		} 1017. 		nomore(MUSE_POT_BLINDNESS); 1018. 		if(obj->otyp == POT_BLINDNESS && !attacktype(mtmp->data, AT_GAZE)) { 1019. 			m.offensive = obj; 1020. 			m.has_offense = MUSE_POT_BLINDNESS; 1021. 		} 1022. 		nomore(MUSE_POT_CONFUSION); 1023. 		if(obj->otyp == POT_CONFUSION) { 1024. 			m.offensive = obj; 1025. 			m.has_offense = MUSE_POT_CONFUSION; 1026. 		} 1027. 		nomore(MUSE_POT_SLEEPING); 1028. 		if(obj->otyp == POT_SLEEPING) { 1029. 			m.offensive = obj; 1030. 			m.has_offense = MUSE_POT_SLEEPING; 1031. 		} 1032. 		nomore(MUSE_POT_ACID); 1033. 		if(obj->otyp == POT_ACID) { 1034. 			m.offensive = obj; 1035. 			m.has_offense = MUSE_POT_ACID; 1036. 		} 1037. 		/* we can safely put this scroll here since the locations that 1038. 		 * are in a 1 square radius are a subset of the locations that 1039. 		 * are in wand range 1040. 		 */ 1041. 		nomore(MUSE_SCR_EARTH); 1042. 		if (obj->otyp == SCR_EARTH 1043. 		       && ((helmet && is_metallic(helmet)) || 1044. 				mtmp->mconf || amorphous(mtmp->data) || 1045. 				passes_walls(mtmp->data) || 1046. 				noncorporeal(mtmp->data) || 1047. 				unsolid(mtmp->data) || !rn2(10)) 1048. 		       && dist2(mtmp->mx,mtmp->my,mtmp->mux,mtmp->muy) <= 2  1049. 		       && mtmp->mcansee && haseyes(mtmp->data)  1050. #ifdef REINCARNATION  1051. 		       && !Is_rogue_level(&u.uz)  1052. #endif  1053. 		       && (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) { 1054. 		   m.offensive = obj; 1055. 		   m.has_offense = MUSE_SCR_EARTH; 1056. 		} 1057. #if 0 1058. 		nomore(MUSE_SCR_FIRE); 1059. 		if (obj->otyp == SCR_FIRE && resists_fire(mtmp) 1060. 		   && dist2(mtmp->mx,mtmp->my,mtmp->mux,mtmp->muy) <= 2  1061. 		   && mtmp->mcansee && haseyes(mtmp->data)) { 1062. 			m.offensive = obj; 1063. 			m.has_offense = MUSE_SCR_FIRE; 1064. 		} 1065. #endif 1066. 	} 1067. 	return((boolean)(!!m.has_offense)); 1068. #undef nomore 1069. } 1070.  1071. STATIC_PTR 1072. int 1073. mbhitm(mtmp, otmp) 1074. register struct monst *mtmp; 1075. register struct obj *otmp; 1076. { 1077. 	int tmp; 1078. 1079. 	boolean reveal_invis = FALSE; 1080. 	if (mtmp != &youmonst) { 1081. 		mtmp->msleeping = 0; 1082. 		if (mtmp->m_ap_type) seemimic(mtmp); 1083. 	} 1084. 	switch(otmp->otyp) { 1085. 	case WAN_STRIKING: 1086. 		reveal_invis = TRUE; 1087. 		if (mtmp == &youmonst) { 1088. 			if (zap_oseen) makeknown(WAN_STRIKING); 1089. 			if (Antimagic) { 1090. 			   shieldeff(u.ux, u.uy); 1091. 			   pline("Boing!"); 1092. 			} else if (rnd(20) < 10 + u.uac) { 1093. 			   pline_The("wand hits you!"); 1094. 			   tmp = d(2,12); 1095. 			   if(Half_spell_damage) tmp = (tmp+1) / 2; 1096. 			   losehp(tmp, "wand", KILLED_BY_AN); 1097. 			} else pline_The("wand misses you."); 1098. 			stop_occupation; 1099. 			nomul(0); 1100. 		} else if (resists_magm(mtmp)) { 1101. 			shieldeff(mtmp->mx, mtmp->my); 1102. 			pline("Boing!"); 1103. 		} else if (rnd(20) < 10+find_mac(mtmp)) { 1104. 			tmp = d(2,12); 1105. 			hit("wand", mtmp, exclam(tmp)); 1106. 			(void) resist(mtmp, otmp->oclass, tmp, TELL); 1107. 			if (cansee(mtmp->mx, mtmp->my) && zap_oseen) 1108. 				makeknown(WAN_STRIKING); 1109. 		} else { 1110. 			miss("wand", mtmp); 1111. 			if (cansee(mtmp->mx, mtmp->my) && zap_oseen) 1112. 				makeknown(WAN_STRIKING); 1113. 		} 1114. 		break; 1115. 	case WAN_TELEPORTATION: 1116. 		if (mtmp == &youmonst) { 1117. 			if (zap_oseen) makeknown(WAN_TELEPORTATION); 1118. 			tele; 1119. 		} else { 1120. 			/* for consistency with zap.c, don't identify */ 1121. 			if (mtmp->ispriest && 1122. 				*in_rooms(mtmp->mx, mtmp->my, TEMPLE)) { 1123. 			   if (cansee(mtmp->mx, mtmp->my)) 1124. 				pline("%s resists the magic!", Monnam(mtmp)); 1125. 			   mtmp->msleeping = 0; 1126. 			   if(mtmp->m_ap_type) seemimic(mtmp); 1127. 			} else if (!tele_restrict(mtmp)) 1128. 			   rloc(mtmp); 1129. 		} 1130. 		break; 1131. 	case WAN_CANCELLATION: 1132. 	case SPE_CANCELLATION: 1133. 		cancel_monst(mtmp, otmp, FALSE, TRUE, FALSE); 1134. 		break; 1135. 	} 1136. 	if (reveal_invis) { 1137. 	   if (mtmp->mhp > 0 && cansee(bhitpos.x,bhitpos.y)  1138. 							&& !canspotmon(mtmp)) 1139. 		map_invisible(bhitpos.x, bhitpos.y); 1140. 	} 1141. 	return 0; 1142. } 1143.  1144. /* A modified bhit for monsters. Based on bhit in zap.c. Unlike 1145. * buzz, bhit doesn't take into account the possibility of a monster 1146. * zapping you, so we need a special function for it. (Unless someone wants 1147.  * to merge the two functions...) 1148. */  1149. STATIC_OVL void 1150. mbhit(mon,range,fhitm,fhito,obj) 1151. struct monst *mon;			/* monster shooting the wand */ 1152. register int range;			/* direction and range */ 1153. int FDECL((*fhitm),(MONST_P,OBJ_P)); 1154. int FDECL((*fhito),(OBJ_P,OBJ_P));	/* fns called when mon/obj hit */ 1155. struct obj *obj;			/* 2nd arg to fhitm/fhito */ 1156. { 1157. 	register struct monst *mtmp; 1158. 	register struct obj *otmp; 1159. 	register uchar typ; 1160. 	int ddx, ddy; 1161. 1162. 	bhitpos.x = mon->mx; 1163. 	bhitpos.y = mon->my; 1164. 	ddx = sgn(mon->mux - mon->mx); 1165. 	ddy = sgn(mon->muy - mon->my); 1166. 1167. 	while(range-- > 0) { 1168. 		int x,y; 1169. 1170. 		bhitpos.x += ddx; 1171. 		bhitpos.y += ddy; 1172. 		x = bhitpos.x; y = bhitpos.y; 1173. 1174. 		if (!isok(x,y)) { 1175. 		   bhitpos.x -= ddx; 1176. 		   bhitpos.y -= ddy; 1177. 		   break; 1178. 		} 1179. 		if (find_drawbridge(&x,&y)) 1180. 		   switch (obj->otyp) { 1181. 			case WAN_STRIKING: 1182. 			   destroy_drawbridge(x,y); 1183. 		   }  1184. 		if(bhitpos.x==u.ux && bhitpos.y==u.uy) { 1185. 			(*fhitm)(&youmonst, obj); 1186. 			range -= 3; 1187. 		} else if(MON_AT(bhitpos.x, bhitpos.y)){ 1188. 			mtmp = m_at(bhitpos.x,bhitpos.y); 1189. 			if (cansee(bhitpos.x,bhitpos.y) && !canspotmon(mtmp)) 1190. 			   map_invisible(bhitpos.x, bhitpos.y); 1191. 			(*fhitm)(mtmp, obj); 1192. 			range -= 3; 1193. 		} 1194. 		/* modified by GAN to hit all objects */ 1195. 		if(fhito){ 1196. 		   int hitanything = 0; 1197. 		   register struct obj *next_obj; 1198. 1199. 		    for(otmp = level.objects[bhitpos.x][bhitpos.y];  1200. 							otmp; otmp = next_obj) { 1201. 			/* Fix for polymorph bug, Tim Wright */ 1202. 			next_obj = otmp->nexthere; 1203. 			hitanything += (*fhito)(otmp, obj); 1204. 		   }  1205. 		    if(hitanything)	range--; 1206. 		} 1207. 		typ = levl[bhitpos.x][bhitpos.y].typ; 1208. 		if(IS_DOOR(typ) || typ == SDOOR) { 1209. 		   switch (obj->otyp) { 1210. 			/* note: monsters don't use opening or locking magic 1211. 			  at present, but keep these as placeholders */ 1212. 			case WAN_OPENING: 1213. 			case WAN_LOCKING: 1214. 			case WAN_STRIKING: 1215. 			   if (doorlock(obj, bhitpos.x, bhitpos.y)) { 1216. 				makeknown(obj->otyp); 1217. 				/* if a shop door gets broken, add it to 1218. the shk's fix list (no cost to player) */ 1219. 				if (levl[bhitpos.x][bhitpos.y].doormask == 1220. 					D_BROKEN &&  1221. 				    *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE)) 1222. 				   add_damage(bhitpos.x, bhitpos.y, 0L); 1223. 			   }  1224. 			    break; 1225. 		   }  1226. 		}  1227. 		if(!ZAP_POS(typ) || (IS_DOOR(typ) && 1228. 		  (levl[bhitpos.x][bhitpos.y].doormask & (D_LOCKED | D_CLOSED)))  1229. 		  ) { 1230. 			bhitpos.x -= ddx; 1231. 			bhitpos.y -= ddy; 1232. 			break; 1233. 		} 1234. 	}  1235. }  1236.  1237. /* Perform an offensive action for a monster. Must be called immediately 1238. * after find_offensive. Return values are same as use_defensive. 1239. */  1240. int 1241. use_offensive(mtmp) 1242. struct monst *mtmp; 1243. { 1244. 	int i;  1245. struct obj *otmp = m.offensive; 1246. 	boolean oseen; 1247. 1248. 	/* offensive potions are not drunk, they're thrown */ 1249. 	if (otmp->oclass != POTION_CLASS && (i = precheck(mtmp, otmp)) != 0) 1250. 		return i; 1251. oseen = otmp && canseemon(mtmp); 1252. 1253. 	switch(m.has_offense) { 1254. 	case MUSE_WAN_DEATH: 1255. 	case MUSE_WAN_SLEEP: 1256. 	case MUSE_WAN_FIRE: 1257. 	case MUSE_WAN_COLD: 1258. 	case MUSE_WAN_LIGHTNING: 1259. 	case MUSE_WAN_MAGIC_MISSILE: 1260. 		mzapmsg(mtmp, otmp, FALSE); 1261. 		otmp->spe--; 1262. 		if (oseen) makeknown(otmp->otyp); 1263. 		m_using = TRUE; 1264. 		buzz((int)(-30 - (otmp->otyp - WAN_MAGIC_MISSILE)), 1265. 			(otmp->otyp == WAN_MAGIC_MISSILE) ? 2 : 6,  1266. 			mtmp->mx, mtmp->my,  1267. 			sgn(mtmp->mux-mtmp->mx), sgn(mtmp->muy-mtmp->my)); 1268. 		m_using = FALSE; 1269. 		return (mtmp->mhp <= 0) ? 1 : 2; 1270. 	case MUSE_FIRE_HORN: 1271. 	case MUSE_FROST_HORN: 1272. 		if (oseen) { 1273. 			makeknown(otmp->otyp); 1274. 			pline("%s plays a %s!", Monnam(mtmp), xname(otmp)); 1275. 		} else 1276. 			You_hear("a horn being played."); 1277. 		otmp->spe--; 1278. 		m_using = TRUE; 1279. 		buzz(-30 - ((otmp->otyp==FROST_HORN) ? AD_COLD-1 : AD_FIRE-1), 1280. 			rn1(6,6), mtmp->mx, mtmp->my,  1281. 			sgn(mtmp->mux-mtmp->mx), sgn(mtmp->muy-mtmp->my)); 1282. 		m_using = FALSE; 1283. 		return (mtmp->mhp <= 0) ? 1 : 2; 1284. 	case MUSE_WAN_TELEPORTATION: 1285. 	case MUSE_WAN_STRIKING: 1286. 		zap_oseen = oseen; 1287. 		mzapmsg(mtmp, otmp, FALSE); 1288. 		otmp->spe--; 1289. 		m_using = TRUE; 1290. 		mbhit(mtmp,rn1(8,6),mbhitm,bhito,otmp); 1291. 		m_using = FALSE; 1292. 		return 2; 1293. 	case MUSE_SCR_EARTH: 1294. 	   {  1295. 		/* TODO: handle steeds */ 1296. 	   	register int x, y;  1297. /* don't use monster fields after killing it */ 1298. 		boolean confused = (mtmp->mconf ? TRUE : FALSE); 1299. 		int mmx = mtmp->mx, mmy = mtmp->my; 1300. 1301. 		mreadmsg(mtmp, otmp); 1302. 	   	/* Identify the scroll */ 1303. 		if (canspotmon(mtmp)) { 1304. 		   pline_The("%s rumbles %s %s!", ceiling(mtmp->mx, mtmp->my),  1305. 	    			otmp->blessed ? "around" : "above",  1306. 				mon_nam(mtmp)); 1307. 		   if (oseen) makeknown(otmp->otyp); 1308. 		} else if (cansee(mtmp->mx, mtmp->my)) { 1309. 		   pline_The("%s rumbles in the middle of nowhere!",  1310. 			ceiling(mtmp->mx, mtmp->my)); 1311. 		   if (mtmp->minvis) 1312. 			map_invisible(mtmp->mx, mtmp->my); 1313. 		   if (oseen) makeknown(otmp->otyp); 1314. 		} 1315.  1316. 	    	/* Loop through the surrounding squares */ 1317. 	   	for (x = mmx-1; x <= mmx+1; x++) { 1318. 	   	    for (y = mmy-1; y <= mmy+1; y++) { 1319. 	   	    	/* Is this a suitable spot? */ 1320. 	    	    	if (isok(x, y) && !closed_door(x, y) &&  1321. 	    	    			!IS_ROCK(levl[x][y].typ) &&  1322. 	    	    			!IS_AIR(levl[x][y].typ) &&  1323. 	    	    			(((x == mmx) && (y == mmy)) ? 1324. 	   	    			    !otmp->blessed : !otmp->cursed) &&  1325. 					(x != u.ux || y != u.uy)) { 1326. 			   register struct obj *otmp2; 1327. 			   register struct monst *mtmp2; 1328. 1329. 	    	    	    /* Make the object(s) */ 1330. 	   	    	    otmp2 = mksobj(confused ? ROCK : BOULDER,  1331. 	    	    	    		FALSE, FALSE); 1332. 	   	    	    if (!otmp2) continue;  /* Shouldn't happen */ 1333. 	   	    	    otmp2->quan = confused ? rn1(5,2) : 1; 1334. 	   	    	    otmp2->owt = weight(otmp2); 1335. 1336. 	    	    	    /* Find the monster here (might be same as mtmp) */ 1337. 	   	    	    mtmp2 = m_at(x, y); 1338. 	   	    	    if (mtmp2 && !amorphous(mtmp2->data) &&  1339. 	    	    	    		!passes_walls(mtmp2->data) &&  1340. 	    	    	    		!noncorporeal(mtmp2->data) &&  1341. 	    	    	    		!unsolid(mtmp2->data)) { 1342. 				struct obj *helmet = which_armor(mtmp2, W_ARMH); 1343. 				int mdmg; 1344. 1345. 				if (cansee(mtmp2->mx, mtmp2->my)) { 1346. 				   pline("%s is hit by %s!", Monnam(mtmp2),  1347. 	    	    	    			doname(otmp2)); 1348. 				   if (mtmp2->minvis && !canspotmon(mtmp2)) 1349. 					map_invisible(mtmp2->mx, mtmp2->my); 1350. 				} 1351. 	    	    	    	mdmg = dmgval(otmp2, mtmp2) * otmp2->quan; 1352. 				if (helmet) { 1353. 				   if(is_metallic(helmet)) { 1354. 					if (canspotmon(mtmp2)) 1355. 					   pline("Fortunately, %s is wearing a hard helmet.", mon_nam(mtmp2)); 1356. 					else if (flags.soundok) 1357. 					   You_hear("a clanging sound."); 1358. 					if (mdmg > 2) mdmg = 2; 1359. 				   } else { 1360. 					if (canspotmon(mtmp2)) 1361. 					   pline("%s's %s does not protect %s.",  1362. 						Monnam(mtmp2), xname(helmet),  1363. 						mhim(mtmp2)); 1364. 				   }  1365. 				}  1366. 	    	    	    	mtmp2->mhp -= mdmg; 1367. 	   	    	    	if (mtmp2->mhp <= 0) { 1368. 				   pline("%s is killed.", Monnam(mtmp2)); 1369. 	   	    	    	    mondied(mtmp2); 1370. 				} 1371. 	    	    	    }  1372. 	    	    	    /* Drop the rock/boulder to the floor */ 1373. 	   	    	    if (!flooreffects(otmp2, x, y, "fall")) { 1374. 	   	    	    	place_object(otmp2, x, y); 1375. 	   	    	    	stackobj(otmp2); 1376. 	   	    	    	newsym(x, y);  /* map the rock */ 1377. 	   	    	    }  1378. 	    	    	}  1379. 		    }  1380. 		}  1381. 		m_useup(mtmp, otmp); 1382. 		/* Attack the player */ 1383. 		if (distmin(mmx, mmy, u.ux, u.uy) == 1 && !otmp->cursed) { 1384. 		   int dmg; 1385. 		   struct obj *otmp2; 1386. 1387. 		    /* Okay, _you_ write this without repeating the code */ 1388. 		   otmp2 = mksobj(confused ? ROCK : BOULDER,  1389. 				FALSE, FALSE); 1390. 		   if (!otmp2) goto xxx_noobj;  /* Shouldn't happen */ 1391. 		   otmp2->quan = confused ? rn1(5,2) : 1; 1392. 		   otmp2->owt = weight(otmp2); 1393. 		   if (!amorphous(youmonst.data) &&  1394. 			    !Passes_walls &&  1395. 			    !noncorporeal(youmonst.data) &&  1396. 			    !unsolid(youmonst.data)) { 1397. 			You("are hit by %s!", doname(otmp2)); 1398. 			dmg = dmgval(otmp2, &youmonst) * otmp2->quan; 1399. 			if (uarmh) { 1400. 			   if(is_metallic(uarmh)) { 1401. 				pline("Fortunately, you are wearing a hard helmet."); 1402. 				if (dmg > 2) dmg = 2; 1403. 			   } else if (flags.verbose) { 1404. 				Your("%s does not protect you.", 1405. 						xname(uarmh)); 1406. 			   }  1407. 			}  1408. 		    } else 1409. 			dmg = 0; 1410. 		   if (!flooreffects(otmp2, u.ux, u.uy, "fall")) { 1411. 			place_object(otmp2, u.ux, u.uy); 1412. 			stackobj(otmp2); 1413. 			newsym(u.ux, u.uy); 1414. 		   }  1415. 		    if (dmg) losehp(dmg, "scroll of earth", KILLED_BY_AN); 1416. 		} 1417. 	    xxx_noobj: 1418. 1419. 		return (mtmp->mhp <= 0) ? 1 : 2; 1420. 	    }  1421. #if 0 1422. 	case MUSE_SCR_FIRE: 1423. 	     {  1424. 		boolean vis = cansee(mtmp->mx, mtmp->my); 1425. 1426. 		mreadmsg(mtmp, otmp); 1427. 		if (mtmp->mconf) { 1428. 			if (vis) 1429. 			   pline("Oh, what a pretty fire!"); 1430. 		} else { 1431. 			struct monst *mtmp2; 1432. 			int num; 1433. 1434. 			if (vis) 1435. 			   pline_The("scroll erupts in a tower of flame!"); 1436. 			shieldeff(mtmp->mx, mtmp->my); 1437. 			pline("%s is uninjured.", Monnam(mtmp)); 1438. 			(void) destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE); 1439. 			(void) destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE); 1440. 			(void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE); 1441. 			num = (2*(rn1(3, 3) + 2 * bcsign(otmp)) + 1)/3; 1442. 			if (Fire_resistance) 1443. 			   You("are not harmed."); 1444. 			burn_away_slime; 1445. 			if (Half_spell_damage) num = (num+1) / 2; 1446. 			else losehp(num, "scroll of fire", KILLED_BY_AN); 1447. 			for(mtmp2 = fmon; mtmp2; mtmp2 = mtmp2->nmon) { 1448. 			  if(DEADMONSTER(mtmp2)) continue; 1449. 			  if(mtmp == mtmp2) continue; 1450. 			  if(dist2(mtmp2->mx,mtmp2->my,mtmp->mx,mtmp->my) < 3){ 1451. 				if (resists_fire(mtmp2)) continue; 1452. 				mtmp2->mhp -= num; 1453. 				if (resists_cold(mtmp2)) 1454. 				   mtmp2->mhp -= 3*num; 1455. 				if(mtmp2->mhp < 1) { 1456. 				   mondied(mtmp2); 1457. 				   break; 1458. 				} 1459. 			    }  1460. 			}  1461. 		}  1462. 		return 2; 1463. 	     }  1464. #endif	/* 0 */ 1465. 	case MUSE_POT_PARALYSIS: 1466. 	case MUSE_POT_BLINDNESS: 1467. 	case MUSE_POT_CONFUSION: 1468. 	case MUSE_POT_SLEEPING: 1469. 	case MUSE_POT_ACID: 1470. 		/* Note: this setting of dknown doesn't suffice. A monster 1471. 		 * which is out of sight might throw and it hits something _in_ 1472. 		 * sight, a problem not existing with wands because wand rays 1473. 		 * are not objects. Also set dknown in mthrowu.c. 1474. */ 1475. 		if (cansee(mtmp->mx, mtmp->my)) { 1476. 			otmp->dknown = 1; 1477. 			pline("%s hurls %s!", Monnam(mtmp), 1478. 						singular(otmp, doname)); 1479. 		} 1480. 		m_throw(mtmp, mtmp->mx, mtmp->my, sgn(mtmp->mux-mtmp->mx),  1481. 			sgn(mtmp->muy-mtmp->my),  1482. 			distmin(mtmp->mx,mtmp->my,mtmp->mux,mtmp->muy), otmp); 1483. 		return 2; 1484. 	case 0: return 0; /* i.e. an exploded wand */ 1485. 	default: impossible("%s wanted to perform action %d?", Monnam(mtmp), 1486. 			m.has_offense); 1487. 		break; 1488. 	} 1489. 	return 0; 1490. } 1491.  1492. int 1493. rnd_offensive_item(mtmp) 1494. struct monst *mtmp; 1495. { 1496. 	struct permonst *pm = mtmp->data; 1497. 	int difficulty = monstr[(monsndx(pm))]; 1498. 1499. 	if(is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)  1500. 			|| pm->mlet == S_GHOST  1501. # ifdef KOPS  1502. 			|| pm->mlet == S_KOP  1503. # endif  1504. 		) return 0; 1505. 	if (difficulty > 7 && !rn2(35)) return WAN_DEATH; 1506. 	switch (rn2(9 - (difficulty < 4) + 4 * (difficulty > 6))) { 1507. 		case 0: { 1508. 		   struct obj *helmet = which_armor(mtmp, W_ARMH); 1509. 1510. 		    if ((helmet && is_metallic(helmet)) || amorphous(pm) || passes_walls(pm) || noncorporeal(pm) || unsolid(pm)) 1511. 			return SCR_EARTH; 1512. 		} /* fall through */ 1513. 		case 1: return WAN_STRIKING; 1514. 		case 2: return POT_ACID; 1515. 		case 3: return POT_CONFUSION; 1516. 		case 4: return POT_BLINDNESS; 1517. 		case 5: return POT_SLEEPING; 1518. 		case 6: return POT_PARALYSIS; 1519. 		case 7: case 8: 1520. 			return WAN_MAGIC_MISSILE; 1521. 		case 9: return WAN_SLEEP; 1522. 		case 10: return WAN_FIRE; 1523. 		case 11: return WAN_COLD; 1524. 		case 12: return WAN_LIGHTNING; 1525. 	} 1526. 	/*NOTREACHED*/ 1527. 	return 0; 1528. } 1529.  1530. #define MUSE_POT_GAIN_LEVEL 1 1531. #define MUSE_WAN_MAKE_INVISIBLE 2 1532. #define MUSE_POT_INVISIBILITY 3 1533. #define MUSE_POLY_TRAP 4 1534. #define MUSE_WAN_POLYMORPH 5 1535. #define MUSE_POT_SPEED 6 1536. #define MUSE_WAN_SPEED_MONSTER 7 1537. #define MUSE_BULLWHIP 8 1538. #define MUSE_POT_POLYMORPH 9 1539. 1540. boolean 1541. find_misc(mtmp) 1542. struct monst *mtmp; 1543. { 1544. 	register struct obj *obj; 1545. 	struct permonst *mdat = mtmp->data; 1546. 	int x = mtmp->mx, y = mtmp->my; 1547. 	struct trap *t; 1548. 	int xx, yy; 1549. 	boolean immobile = (mdat->mmove == 0); 1550. 	boolean stuck = (mtmp == u.ustuck); 1551. 1552. 	m.misc = (struct obj *)0; 1553. 	m.has_misc = 0; 1554. 	if (is_animal(mdat) || mindless(mdat)) 1555. 		return 0; 1556. 	if (u.uswallow && stuck) return FALSE; 1557. 1558. 	/* We arbitrarily limit to times when a player is nearby for the 1559. 	 * same reason as Junior Pac-Man doesn't have energizers eaten until 1560. 	 * you can see them... 1561. */ 1562. 	if(dist2(x, y, mtmp->mux, mtmp->muy) > 36) 1563. 		return FALSE; 1564. 1565. 	if (!stuck && !immobile && !mtmp->cham && monstr[monsndx(mdat)] < 6) { 1566. 	 boolean ignore_boulders = (verysmall(mdat) ||  1567. 				     throws_rocks(mdat) ||  1568. 				     passes_walls(mdat)); 1569. 	 for(xx = x-1; xx <= x+1; xx++) 1570. 	   for(yy = y-1; yy <= y+1; yy++) 1571. 		if (isok(xx,yy) && (xx != u.ux || yy != u.uy)) 1572. 		   if (mdat != &mons[PM_GRID_BUG] || xx == x || yy == y)  1573. if (/* (xx==x && yy==y) || */ !level.monsters[xx][yy]) 1574. 			   if ((t = t_at(xx, yy)) != 0 &&  1575. 			      (ignore_boulders || !sobj_at(BOULDER, xx, yy))  1576. 			      && !onscary(xx, yy, mtmp)) { 1577. 				if (t->ttyp == POLY_TRAP) { 1578. 				   trapx = xx; 1579. 				   trapy = yy; 1580. 				   m.has_misc = MUSE_POLY_TRAP; 1581. 				   return TRUE; 1582. 				} 1583. 			    }  1584. 	}  1585. 	if (nohands(mdat)) 1586. 		return 0; 1587. 1588. #define nomore(x) if(m.has_misc==x) continue; 1589. 	for(obj=mtmp->minvent; obj; obj=obj->nobj) { 1590. 		/* Monsters shouldn't recognize cursed items; this kludge is */ 1591. 		/* necessary to prevent serious problems though... */ 1592. 		if(obj->otyp == POT_GAIN_LEVEL && (!obj->cursed || 1593. 			   (!mtmp->isgd && !mtmp->isshk && !mtmp->ispriest))) { 1594. 			m.misc = obj; 1595. 			m.has_misc = MUSE_POT_GAIN_LEVEL; 1596. 		} 1597. 		nomore(MUSE_BULLWHIP); 1598. 		if(obj->otyp == BULLWHIP && (MON_WEP(mtmp) == obj) && 1599. 		   distu(mtmp->mx,mtmp->my)==1 && uwep && !mtmp->mpeaceful) { 1600. 			m.misc = obj; 1601. 			m.has_misc = MUSE_BULLWHIP; 1602. 		} 1603. 		/* Note: peaceful/tame monsters won't make themselves 1604. 		 * invisible unless you can see them. Not really right, but... 1605. */ 1606. 		nomore(MUSE_WAN_MAKE_INVISIBLE); 1607. 		if(obj->otyp == WAN_MAKE_INVISIBLE && obj->spe > 0 && 1608. 		    !mtmp->minvis && !mtmp->invis_blkd &&  1609. 		    (!mtmp->mpeaceful || See_invisible) &&  1610. 		    (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) { 1611. 			m.misc = obj; 1612. 			m.has_misc = MUSE_WAN_MAKE_INVISIBLE; 1613. 		} 1614. 		nomore(MUSE_POT_INVISIBILITY); 1615. 		if(obj->otyp == POT_INVISIBILITY && 1616. 		    !mtmp->minvis && !mtmp->invis_blkd &&  1617. 		    (!mtmp->mpeaceful || See_invisible) &&  1618. 		    (!attacktype(mtmp->data, AT_GAZE) || mtmp->mcan)) { 1619. 			m.misc = obj; 1620. 			m.has_misc = MUSE_POT_INVISIBILITY; 1621. 		} 1622. 		nomore(MUSE_WAN_SPEED_MONSTER); 1623. 		if(obj->otyp == WAN_SPEED_MONSTER && obj->spe > 0 1624. 				&& mtmp->mspeed != MFAST && !mtmp->isgd) { 1625. 			m.misc = obj; 1626. 			m.has_misc = MUSE_WAN_SPEED_MONSTER; 1627. 		} 1628. 		nomore(MUSE_POT_SPEED); 1629. 		if(obj->otyp == POT_SPEED && mtmp->mspeed != MFAST 1630. 							&& !mtmp->isgd) { 1631. 			m.misc = obj; 1632. 			m.has_misc = MUSE_POT_SPEED; 1633. 		} 1634. 		nomore(MUSE_WAN_POLYMORPH); 1635. 		if(obj->otyp == WAN_POLYMORPH && obj->spe > 0 && !mtmp->cham 1636. 				&& monstr[monsndx(mdat)] < 6) { 1637. 			m.misc = obj; 1638. 			m.has_misc = MUSE_WAN_POLYMORPH; 1639. 		} 1640. 		nomore(MUSE_POT_POLYMORPH); 1641. 		if(obj->otyp == POT_POLYMORPH && !mtmp->cham 1642. 				&& monstr[monsndx(mdat)] < 6) { 1643. 			m.misc = obj; 1644. 			m.has_misc = MUSE_POT_POLYMORPH; 1645. 		} 1646. 	}  1647. 	return((boolean)(!!m.has_misc)); 1648. #undef nomore 1649. } 1650.  1651. /* type of monster to polymorph into; defaults to one suitable for the 1652.   current level rather than the totally arbitrary choice of newcham */ 1653. static struct permonst * 1654. muse_newcham_mon(mon) 1655. struct monst *mon; 1656. { 1657. 	struct obj *m_armr; 1658. 1659. 	if ((m_armr = which_armor(mon, W_ARM)) != 0) { 1660. 	   if (Is_dragon_scales(m_armr)) 1661. 		return Dragon_scales_to_pm(m_armr); 1662. 	   else if (Is_dragon_mail(m_armr)) 1663. 		return Dragon_mail_to_pm(m_armr); 1664. 	} 1665. 	return rndmonst; 1666. } 1667.  1668. int 1669. use_misc(mtmp) 1670. struct monst *mtmp; 1671. { 1672. 	int i;  1673. struct obj *otmp = m.misc; 1674. 	boolean vis, vismon, oseen; 1675. 	char nambuf[BUFSZ]; 1676. 1677. 	if ((i = precheck(mtmp, otmp)) != 0) return i;  1678. vis = cansee(mtmp->mx, mtmp->my); 1679. 	vismon = canseemon(mtmp); 1680. 	oseen = otmp && vismon; 1681. 1682. 	switch(m.has_misc) { 1683. 	case MUSE_POT_GAIN_LEVEL: 1684. 		mquaffmsg(mtmp, otmp); 1685. 		if (otmp->cursed) { 1686. 		   if (Can_rise_up(mtmp->mx, mtmp->my, &u.uz)) { 1687. 			register int tolev = depth(&u.uz)-1; 1688. 			d_level tolevel; 1689. 1690. 			get_level(&tolevel, tolev); 1691. 			/* insurance against future changes... */ 1692. 			if(on_level(&tolevel, &u.uz)) goto skipmsg; 1693. 			if (vismon) { 1694. 			   pline("%s rises up, through the %s!",  1695. 				  Monnam(mtmp), ceiling(mtmp->mx, mtmp->my)); 1696. 			   if(!objects[POT_GAIN_LEVEL].oc_name_known  1697. 			      && !objects[POT_GAIN_LEVEL].oc_uname) 1698. 				docall(otmp); 1699. 			} 1700. 			m_useup(mtmp, otmp); 1701. 			migrate_to_level(mtmp, ledger_no(&tolevel), 1702. 					 MIGR_RANDOM, (coord *)0); 1703. 			return 2; 1704. 		   } else { 1705. skipmsg: 1706. 			if (vismon) { 1707. 			   pline("%s looks uneasy.", Monnam(mtmp)); 1708. 			   if(!objects[POT_GAIN_LEVEL].oc_name_known  1709. 			      && !objects[POT_GAIN_LEVEL].oc_uname) 1710. 				docall(otmp); 1711. 			} 1712. 			m_useup(mtmp, otmp); 1713. 			return 2; 1714. 		   }  1715. 		}  1716. 		if (vismon) pline("%s seems more experienced.", Monnam(mtmp)); 1717. 		if (oseen) makeknown(POT_GAIN_LEVEL); 1718. 		m_useup(mtmp, otmp); 1719. 		if (!grow_up(mtmp,(struct monst *)0)) return 1; 1720. 			/* grew into genocided monster */ 1721. 		return 2; 1722. 	case MUSE_WAN_MAKE_INVISIBLE: 1723. 	case MUSE_POT_INVISIBILITY: 1724. 		if (otmp->otyp == WAN_MAKE_INVISIBLE) { 1725. 		   mzapmsg(mtmp, otmp, TRUE); 1726. 		   otmp->spe--; 1727. 		} else 1728. 		   mquaffmsg(mtmp, otmp); 1729. 		/* format monster's name before altering its visibility */ 1730. 		Strcpy(nambuf, See_invisible ? Monnam(mtmp) : mon_nam(mtmp)); 1731. 		mon_set_minvis(mtmp); 1732. 		if (vismon && mtmp->minvis) {	/* was seen, now invisible */ 1733. 		   if (See_invisible) 1734. 			pline("%s body takes on a %s transparency.", 1735. 			      s_suffix(nambuf),  1736. 			      Hallucination ? "normal" : "strange"); 1737. 		   else 1738. 			pline("Suddenly you cannot see %s.", nambuf); 1739. 		   if (oseen) makeknown(otmp->otyp); 1740. 		} 1741. 		if (otmp->otyp == POT_INVISIBILITY) { 1742. 		   if (otmp->cursed) you_aggravate(mtmp); 1743. 		   m_useup(mtmp, otmp); 1744. 		} 1745. 		return 2; 1746. 	case MUSE_WAN_SPEED_MONSTER: 1747. 		mzapmsg(mtmp, otmp, TRUE); 1748. 		otmp->spe--; 1749. 		mon_adjust_speed(mtmp, 1, otmp); 1750. 		return 2; 1751. 	case MUSE_POT_SPEED: 1752. 		mquaffmsg(mtmp, otmp); 1753. 		/* note difference in potion effect due to substantially 1754. 		  different methods of maintaining speed ratings: 1755. 		  player's character becomes "very fast" temporarily; 1756. 		  monster becomes "one stage faster" permanently */ 1757. 		mon_adjust_speed(mtmp, 1, otmp); 1758. 		m_useup(mtmp, otmp); 1759. 		return 2; 1760. 	case MUSE_WAN_POLYMORPH: 1761. 		mzapmsg(mtmp, otmp, TRUE); 1762. 		otmp->spe--; 1763. 		(void) newcham(mtmp, muse_newcham_mon(mtmp), TRUE); 1764. 		if (oseen) makeknown(WAN_POLYMORPH); 1765. 		return 2; 1766. 	case MUSE_POT_POLYMORPH: 1767. 		mquaffmsg(mtmp, otmp); 1768. 		if (vismon) pline("%s suddenly mutates!", Monnam(mtmp)); 1769. 		(void) newcham(mtmp, muse_newcham_mon(mtmp), FALSE); 1770. 		if (oseen) makeknown(POT_POLYMORPH); 1771. 		m_useup(mtmp, otmp); 1772. 		return 2; 1773. 	case MUSE_POLY_TRAP: 1774. 		if (vismon) 1775. 		   pline("%s deliberately %s onto a polymorph trap!",  1776. 			Monnam(mtmp),  1777. 			makeplural(locomotion(mtmp->data, "jump"))); 1778. 		if (vis) seetrap(t_at(trapx,trapy)); 1779. 1780. 		/*  don't use rloc due to worms */ 1781. 		remove_monster(mtmp->mx, mtmp->my); 1782. 		newsym(mtmp->mx, mtmp->my); 1783. 		place_monster(mtmp, trapx, trapy); 1784. 		if (mtmp->wormno) worm_move(mtmp); 1785. 		newsym(trapx, trapy); 1786. 1787. 		(void) newcham(mtmp, (struct permonst *)0, FALSE); 1788. 		return 2; 1789. 	case MUSE_BULLWHIP: 1790. 		/* attempt to disarm hero */ 1791. 		if (uwep && !rn2(5)) { 1792. 		   const char *The_whip = vismon ? "The bullwhip" : "A whip"; 1793. 		   int where_to = rn2(4); 1794. 		   struct obj *obj = uwep; 1795. 		   const char *hand; 1796. 		   char the_weapon[BUFSZ]; 1797. 1798. 		    Strcpy(the_weapon, the(xname(obj))); 1799. 		   hand = body_part(HAND); 1800. 		   if (bimanual(obj)) hand = makeplural(hand); 1801. 1802. 		    if (vismon) 1803. 			pline("%s flicks a bullwhip towards your %s!", 1804. 			      Monnam(mtmp), hand); 1805. 		   if (obj->otyp == HEAVY_IRON_BALL) { 1806. 			pline("%s fails to wrap around %s.", 1807. 			      The_whip, the_weapon); 1808. 			return 1; 1809. 		   }  1810. 		    pline("%s wraps around %s you're wielding!",  1811. 			  The_whip, the_weapon); 1812. 		   if (welded(obj)) { 1813. 			pline("%s welded to your %s%c", 1814. 			      !is_plural(obj) ? "It is" : "They are",  1815. 			      hand, !obj->bknown ? '!' : '.'); 1816. 			/* obj->bknown = 1; */ /* welded takes care of this */ 1817. 			where_to = 0; 1818. 		   }  1819. 		    if (!where_to) { 1820. 			pline_The("whip slips free."); /* not `The_whip' */ 1821. 			return 1; 1822. 		   } else if (where_to == 3 && hates_silver(mtmp->data) &&  1823. 			    objects[obj->otyp].oc_material == SILVER) { 1824. 			/* this monster won't want to catch a silver 1825. 			  weapon; drop it at hero's feet instead */ 1826. 			where_to = 2; 1827. 		   }  1828. 		    freeinv(obj); 1829. 		   uwepgone; 1830. 		   switch (where_to) { 1831. 			case 1:		/* onto floor beneath mon */ 1832. 			   pline("%s yanks %s from your %s!", Monnam(mtmp),  1833. 				  the_weapon, hand); 1834. 			   place_object(obj, mtmp->mx, mtmp->my); 1835. 			   break; 1836. 			case 2:		/* onto floor beneath you */ 1837. 			   pline("%s yanks %s to the %s!", Monnam(mtmp),  1838. 				  the_weapon, surface(u.ux, u.uy)); 1839. 			   dropy(obj); 1840. 			   break; 1841. 			case 3:		/* into mon's inventory */ 1842. 			   pline("%s snatches %s!", Monnam(mtmp),  1843. 				  the_weapon); 1844. 			   (void) mpickobj(mtmp,obj); 1845. 			   break; 1846. 		   }  1847. 		    return 1; 1848. 		} 1849. 		return 0; 1850. 	case 0: return 0; /* i.e. an exploded wand */ 1851. 	default: impossible("%s wanted to perform action %d?", Monnam(mtmp), 1852. 			m.has_misc); 1853. 		break; 1854. 	} 1855. 	return 0; 1856. } 1857.  1858. STATIC_OVL void 1859. you_aggravate(mtmp) 1860. struct monst *mtmp; 1861. { 1862. 	pline("For some reason, %s presence is known to you.",  1863. 		s_suffix(noit_mon_nam(mtmp))); 1864. 	cls; 1865. #ifdef CLIPPING 1866. 	cliparound(mtmp->mx, mtmp->my); 1867. #endif 1868. 	show_glyph(mtmp->mx, mtmp->my, mon_to_glyph(mtmp)); 1869. 	display_self; 1870. 	You_feel("aggravated at %s.", noit_mon_nam(mtmp)); 1871. 	display_nhwindow(WIN_MAP, TRUE); 1872. 	docrt; 1873. 	if (unconscious) { 1874. 		multi = -1; 1875. 		nomovemsg = 1876. 		     "Aggravated, you are jolted into full consciousness."; 1877. 	} 1878. 	newsym(mtmp->mx,mtmp->my); 1879. 	if (!canspotmon(mtmp)) 1880. 	   map_invisible(mtmp->mx, mtmp->my); 1881. } 1882.  1883. int 1884. rnd_misc_item(mtmp) 1885. struct monst *mtmp; 1886. { 1887. 	struct permonst *pm = mtmp->data; 1888. 	int difficulty = monstr[(monsndx(pm))]; 1889. 1890. 	if(is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)  1891. 			|| pm->mlet == S_GHOST  1892. # ifdef KOPS  1893. 			|| pm->mlet == S_KOP  1894. # endif  1895. 		) return 0; 1896. 	/* Unlike other rnd_item functions, we only allow _weak_ monsters 1897. 	 * to have this item; after all, the item will be used to strengthen 1898. 	 * the monster and strong monsters won't use it at all... 1899. */ 1900. 	if (difficulty < 6 && !rn2(30)) 1901. 	   return rn2(6) ? POT_POLYMORPH : WAN_POLYMORPH; 1902. 1903. 	if (!rn2(40) && !nonliving(pm)) return AMULET_OF_LIFE_SAVING; 1904. 1905. 	switch (rn2(3)) { 1906. 		case 0: 1907. 			if (mtmp->isgd) return 0; 1908. 			return rn2(6) ? POT_SPEED : WAN_SPEED_MONSTER; 1909. 		case 1: 1910. 			if (mtmp->mpeaceful && !See_invisible) return 0; 1911. 			return rn2(6) ? POT_INVISIBILITY : WAN_MAKE_INVISIBLE; 1912. 		case 2: 1913. 			return POT_GAIN_LEVEL; 1914. 	} 1915. 	/*NOTREACHED*/ 1916. 	return 0; 1917. } 1918.  1919. boolean 1920. searches_for_item(mon, obj) 1921. struct monst *mon; 1922. struct obj *obj; 1923. { 1924. 	int typ = obj->otyp; 1925. 1926. 	if (is_animal(mon->data) ||  1927. 		mindless(mon->data) ||  1928. 		mon->data == &mons[PM_GHOST])	/* don't loot bones piles */ 1929. 	   return FALSE; 1930. 1931. 	if (typ == WAN_MAKE_INVISIBLE || typ == POT_INVISIBILITY) 1932. 	   return (boolean)(!mon->minvis && !mon->invis_blkd && !attacktype(mon->data, AT_GAZE)); 1933. 	if (typ == WAN_SPEED_MONSTER || typ == POT_SPEED) 1934. 	   return (boolean)(mon->mspeed != MFAST); 1935. 1936. 	switch (obj->oclass) { 1937. 	case WAND_CLASS: 1938. 	   if (obj->spe <= 0) 1939. 		return FALSE; 1940. 	   if (typ == WAN_DIGGING) 1941. 		return (boolean)(!is_floater(mon->data)); 1942. 	   if (typ == WAN_POLYMORPH) 1943. 		return (boolean)(monstr[monsndx(mon->data)] < 6); 1944. 	   if (objects[typ].oc_dir == RAY ||  1945. 		    typ == WAN_STRIKING ||  1946. 		    typ == WAN_TELEPORTATION ||  1947. 		    typ == WAN_CREATE_MONSTER) 1948. 		return TRUE; 1949. 	   break; 1950. 	case POTION_CLASS: 1951. 	   if (typ == POT_HEALING ||  1952. 		    typ == POT_EXTRA_HEALING ||  1953. 		    typ == POT_FULL_HEALING ||  1954. 		    typ == POT_POLYMORPH ||  1955. 		    typ == POT_GAIN_LEVEL ||  1956. 		    typ == POT_PARALYSIS ||  1957. 		    typ == POT_SLEEPING ||  1958. 		    typ == POT_ACID ||  1959. 		    typ == POT_CONFUSION) 1960. 		return TRUE; 1961. 	   if (typ == POT_BLINDNESS && !attacktype(mon->data, AT_GAZE)) 1962. 		return TRUE; 1963. 	   break; 1964. 	case SCROLL_CLASS: 1965. 	   if (typ == SCR_TELEPORTATION || typ == SCR_CREATE_MONSTER  1966. 		    || typ == SCR_EARTH) 1967. 		return TRUE; 1968. 	   break; 1969. 	case AMULET_CLASS: 1970. 	   if (typ == AMULET_OF_LIFE_SAVING) 1971. 		return (boolean)(!nonliving(mon->data)); 1972. 	   if (typ == AMULET_OF_REFLECTION) 1973. 		return TRUE; 1974. 	   break; 1975. 	case TOOL_CLASS: 1976. 	   if (typ == PICK_AXE) 1977. 		return (boolean)needspick(mon->data); 1978. 	   if (typ == UNICORN_HORN) 1979. 		return (boolean)(!obj->cursed && !is_unicorn(mon->data)); 1980. 	   if (typ == FROST_HORN || typ == FIRE_HORN) 1981. 		return (obj->spe > 0); 1982. 	   break; 1983. 	case FOOD_CLASS: 1984. 	   if (typ == CORPSE) 1985. 		return (boolean)(((mon->misc_worn_check & W_ARMG) && 1986. 				   touch_petrifies(&mons[obj->corpsenm])) ||  1987. 				(!resists_ston(mon) && 1988. 				   (obj->corpsenm == PM_LIZARD ||  1989. 					(acidic(&mons[obj->corpsenm]) && 1990. 					 obj->corpsenm != PM_GREEN_SLIME)))); 1991. 	   if (typ == EGG) 1992. 		return (boolean)(touch_petrifies(&mons[obj->corpsenm])); 1993. 	   break; 1994. 	default: 1995. 	   break; 1996. 	} 1997.  1998. 	return FALSE; 1999. } 2000.  2001. boolean 2002. mon_reflects(mon,str) 2003. struct monst *mon; 2004. const char *str; 2005. { 2006. 	struct obj *orefl = which_armor(mon, W_ARMS); 2007. 2008. 	if (orefl && orefl->otyp == SHIELD_OF_REFLECTION) { 2009. 	   if (str) { 2010. 		pline(str, s_suffix(mon_nam(mon)), "shield"); 2011. 		makeknown(SHIELD_OF_REFLECTION); 2012. 	   }  2013. 	    return TRUE; 2014. 	} else if ((orefl = which_armor(mon, W_AMUL)) && 2015. 				orefl->otyp == AMULET_OF_REFLECTION) { 2016. 	   if (str) { 2017. 		pline(str, s_suffix(mon_nam(mon)), "amulet"); 2018. 		makeknown(AMULET_OF_REFLECTION); 2019. 	   }  2020. 	    return TRUE; 2021. 	} else if ((orefl = which_armor(mon, W_ARM)) && 2022. 		(orefl->otyp == SILVER_DRAGON_SCALES || orefl->otyp == SILVER_DRAGON_SCALE_MAIL)) { 2023. 	   if (str) 2024. 		pline(str, s_suffix(mon_nam(mon)), "armor"); 2025. 	   return TRUE; 2026. 	} else if (mon->data == &mons[PM_SILVER_DRAGON] || 2027. 		mon->data == &mons[PM_CHROMATIC_DRAGON]) { 2028. 	   /* Silver dragons only reflect when mature; babies do not */ 2029. 	   if (str) 2030. 		pline(str, s_suffix(mon_nam(mon)), "scales"); 2031. 	   return TRUE; 2032. 	} 2033. 	return FALSE; 2034. } 2035.  2036. boolean 2037. ureflects (fmt, str) 2038. const char *fmt, *str; 2039. { 2040. 	/* Check from outermost to innermost objects */ 2041. 	if (EReflecting & W_ARMS) { 2042. 	   if (fmt && str) { 2043. 	   	pline(fmt, str, "shield"); 2044. 	   	makeknown(SHIELD_OF_REFLECTION); 2045. 	   }  2046. 	    return TRUE; 2047. 	} else if (EReflecting & W_WEP) { 2048. 	   /* Due to wielded artifact weapon */ 2049. 	   if (fmt && str) 2050. 	   	pline(fmt, str, "weapon"); 2051. 	   return TRUE; 2052. 	} else if (EReflecting & W_AMUL) { 2053. 	   if (fmt && str) { 2054. 	   	pline(fmt, str, "medallion"); 2055. 	   	makeknown(AMULET_OF_REFLECTION); 2056. 	   }  2057. 	    return TRUE; 2058. 	} else if (EReflecting & W_ARM) { 2059. 	   if (fmt && str) 2060. 	   	pline(fmt, str, "armor"); 2061. 	   return TRUE; 2062. 	} else if (youmonst.data == &mons[PM_SILVER_DRAGON]) { 2063. 	   if (fmt && str) 2064. 	   	pline(fmt, str, "scales"); 2065. 	   return TRUE; 2066. 	} 2067. 	return FALSE; 2068. } 2069.  2070.  2071. /* TRUE if the monster ate something */ 2072. boolean 2073. munstone(mon, by_you) 2074. struct monst *mon; 2075. boolean by_you; 2076. { 2077. 	struct obj *obj; 2078. 2079. 	if (resists_ston(mon)) return FALSE; 2080. 	if (mon->meating || !mon->mcanmove || mon->msleeping) return FALSE; 2081. 2082. 	for(obj = mon->minvent; obj; obj = obj->nobj) { 2083. 	   /* Monsters can also use potions of acid */ 2084. 	   if ((obj->otyp == POT_ACID) || (obj->otyp == CORPSE && 2085. 	   		(obj->corpsenm == PM_LIZARD || (acidic(&mons[obj->corpsenm]) && obj->corpsenm != PM_GREEN_SLIME)))) { 2086. 		mon_consume_unstone(mon, obj, by_you, TRUE); 2087. 		return TRUE; 2088. 	   }  2089. 	}  2090. 	return FALSE; 2091. } 2092.  2093. STATIC_OVL void 2094. mon_consume_unstone(mon, obj, by_you, stoning) 2095. struct monst *mon; 2096. struct obj *obj; 2097. boolean by_you; 2098. boolean stoning; 2099. { 2100.     int nutrit = (obj->otyp == CORPSE) ? dog_nutrition(mon, obj) : 0; 2101.    /* also sets meating */ 2102. 2103.     if (canseemon(mon)) { 2104. 	long save_quan = obj->quan; 2105. 2106. 	obj->quan = 1L; 2107. 	pline("%s %ss %s.", Monnam(mon), 2108. 		    (obj->otyp == POT_ACID) ? "quaff" : "eat",  2109. 		    distant_name(obj,doname)); 2110. 	obj->quan = save_quan; 2111.    } else if (flags.soundok) 2112. 	You_hear("%s.", (obj->otyp == POT_ACID) ? "drinking" : "chewing"); 2113.    m_useup(mon, obj); 2114.    if (((obj->otyp == POT_ACID) || acidic(&mons[obj->corpsenm])) &&  2115. 		    !resists_acid(mon)) { 2116. 	mon->mhp -= rnd(15); 2117. 	pline("%s has a very bad case of stomach acid.", 2118. 	    Monnam(mon)); 2119.    }  2120.     if (mon->mhp <= 0) { 2121. 	pline("%s dies!", Monnam(mon)); 2122. 	if (by_you) xkilled(mon, 0); 2123. 	else mondead(mon); 2124. 	return; 2125.    }  2126.     if (stoning && canseemon(mon)) { 2127. 	if (Hallucination) 2128.    pline("What a pity - %s just ruined a future piece of art!",  2129. 	    mon_nam(mon)); 2130. 	else 2131. 	   pline("%s seems limber!", Monnam(mon)); 2132.    }  2133.     if (obj->otyp == CORPSE && obj->corpsenm == PM_LIZARD && mon->mconf) { 2134. 	mon->mconf = 0; 2135. 	if (canseemon(mon)) 2136. 	   pline("%s seems steadier now.", Monnam(mon)); 2137.    }  2138.     if (mon->mtame && !mon->isminion && nutrit > 0) { 2139. 	struct edog *edog = EDOG(mon); 2140. 2141. 	if (edog->hungrytime < monstermoves) edog->hungrytime = monstermoves; 2142. 	edog->hungrytime += nutrit; 2143. 	mon->mconf = 0; 2144.    }  2145.     mon->mlstmv = monstermoves; /* it takes a turn */ 2146. } 2147.  2148. /*muse.c*/