Source:SLASH'EM 0.0.7E7F2/read.c

Below is the full text to read.c from the source code of SLASH'EM 0.0.7E7F2. To link to a particular line, write [[SLASH'EM 0.0.7E7F2/read.c#line123 ]], for example.

The latest source code for vanilla NetHack is at Source code.

1.   /*	SCCS Id: @(#)read.c	3.4	2003/10/22	*/ 2.   /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3.    /* NetHack may be freely redistributed. See license for details. */ 4.     5.    #include "hack.h"  6. 7.    8.    /* KMH -- Copied from pray.c; this really belongs in a header file */ 9.   #define DEVOUT 14 10.  #define STRIDENT 4 11.   12.    13.   #define Your_Own_Role(mndx) \ 14.  	((mndx) == urole.malenum || \  15.   	 (urole.femalenum != NON_PM && (mndx) == urole.femalenum)) 16.  #define Your_Own_Race(mndx) \ 17.  	((mndx) == urace.malenum || \  18.   	 (urace.femalenum != NON_PM && (mndx) == urace.femalenum)) 19.   20.   #ifdef OVLB 21.   22.   boolean	known; 23.   24.   static NEARDATA const char readable[] = { 25.  		   SCROLL_CLASS, SPBOOK_CLASS, RING_CLASS, 0 }; 26.  static const char all_count[] = { ALLOW_COUNT, ALL_CLASSES, 0 }; 27.   28.    29.   #if 0 30.  static const char *warnings[] = { 31.  	"white", "pink", "red", "ruby", "purple", "black" 32.  };  33.   #endif 34.   35.   #if 0 36.  static void FDECL(wand_explode, (struct obj *)); 37.  #endif 38.  static void NDECL(do_class_genocide); 39.  static void FDECL(stripspe,(struct obj *)); 40.  static void FDECL(p_glow1,(struct obj *)); 41.  static void FDECL(p_glow2,(struct obj *,const char *)); 42.  static void FDECL(randomize,(int *, int)); 43.  static void FDECL(forget_single_object, (int)); 44.  static void FDECL(maybe_tame, (struct monst *,struct obj *)); 45.   46.   STATIC_PTR void FDECL(set_lit, (int,int,genericptr_t)); 47.   48.   int 49.  doread 50.  {  51.   	register struct obj *scroll; 52.  	register boolean confused; 53.  	char class_list[SIZE(readable) + 3]; 54.  	char *cp = class_list; 55.  	struct engr *ep = engr_at(u.ux, u.uy); 56.  	boolean cant_see = Blind; 57.  	struct obj otemp; 58.   59.   	*cp++ = ALL_CLASSES; 60.  	*cp++ = ALLOW_FLOOROBJ; 61.  	if (!u.uswallow && ep && ep->engr_txt[0]) 62.  	    *cp++ = ALLOW_THISPLACE; 63.  	Strcpy(cp, readable); 64.   65.   	known = FALSE; 66.  	if(check_capacity((char *)0)) return (0); 67.  	scroll = getobj(class_list, "read"); 68.  	if(!scroll) return(0); 69.   70.   	if (scroll == &thisplace) { 71.  	    (void) sense_engr_at(u.ux, u.uy, TRUE); 72.  	    return 0; 73.  	}  74.    75.   #ifdef INVISIBLE_OBJECTS 76.  	if (scroll->oinvis && !See_invisible) 77.  	    cant_see = TRUE; 78.  #endif 79.   80.   	/* KMH -- some rings can be read, even while illiterate */ 81.  	if (scroll->oclass == RING_CLASS) { 82.  	    const char *clr = (char *)0; 83.   84.   	    if (cant_see) { 85.  		You("cannot see it!"); 86.  		return 0; 87.  	    }  88.   	    if (scroll->where != OBJ_INVENT || !(scroll->owornmask & W_RING)) { 89.  		pline("Perhaps you should put it on first."); 90.  		return 0; 91.  	    }  92.   	    if (scroll->dknown && objects[scroll->otyp].oc_name_known) 93.  		switch (scroll->otyp) { 94.  #if 0	/* Not yet supported under 3.3.1 style warning system */ 95.  		    case RIN_WARNING: 96.  			if (warnlevel >= 100) 97.  			    clr = "light blue"; 98.  			else if (warnlevel >= SIZE(warnings)) 99.  			    clr = warnings[SIZE(warnings)-1]; 100. 			else 101. 			    clr = warnings[warnlevel]; 102. 			break; 103. #endif 104. 		    case RIN_MOOD: 105. 			if (u.ualign.record >= DEVOUT) 106. 			    clr = "green";	/* well-pleased */ 107. 			else if (u.ualign.record >= STRIDENT) 108. 			    clr = "yellow";	/* pleased */ 109. 			else if (u.ualign.record > 0) 110. 			    clr = "orange";	/* satisfied */ 111. 			else 112. 			    clr = "red";	/* you've been naughty */ 113. 			break; 114. 		    default: 115. 			break; 116. 		}  117.  	    if (!clr) 118. 		pline("There seems to be nothing special about this ring."); 119. 	    else if (scroll->cursed) 120. 		pline("It appears dark."); 121. 	    else 122. 		pline("It glows %s!", hcolor(clr)); 123. 	    return 1; 124. 	}  125.   126.  	/* outrumor has its own blindness check */ 127. 	if(scroll->otyp == FORTUNE_COOKIE) { 128. 	    long save_Blinded = Blinded; 129. 	    if(flags.verbose) 130. 		You("break up the cookie and throw away the pieces."); 131. 	    Blinded = cant_see;	/* Treat invisible fortunes as if blind */ 132. 	    outrumor(bcsign(scroll), BY_COOKIE); 133. 	    Blinded = save_Blinded; 134. 	    if (!cant_see) u.uconduct.literate++; 135. 	    if (carried(scroll)) useup(scroll); 136. 	    else useupf(scroll, 1L); 137. 	    return(1); 138. #ifdef TOURIST 139. 	} else if (scroll->otyp == T_SHIRT) { 140. 	    static const char *shirt_msgs[] = { /* Scott Bigham */ 141.     "I explored the Dungeons of Doom and all I got was this lousy T-shirt!", 142.     "Is that Mjollnir in your pocket or are you just happy to see me?", 143.     "It's not the size of your sword, it's how #enhance'd you are with it.", 144.     "Madame Elvira's House O' Succubi Lifetime Customer", 145.     "Madame Elvira's House O' Succubi Employee of the Month", 146.     "Ludios Vault Guards Do It In Small, Dark Rooms", 147.     "Yendor Military Soldiers Do It In Large Groups", 148.     "I survived Yendor Military Boot Camp", 149.     "Ludios Accounting School Intra-Mural Lacrosse Team", 150.     "Oracle(TM) Fountains 10th Annual Wet T-Shirt Contest", 151.     "Hey, black dragon!  Disintegrate THIS!", 152.     "I'm With Stupid -->", 153.     "Don't blame me, I voted for Izchak!", 154.     "Don't Panic",				/* HHGTTG */ 155.     "Furinkan High School Athletic Dept.",	/* Ranma 1/2 */ 156.     "Hel-LOOO, Nurse!",			/* Animaniacs */ 157. 	    };  158.  	    char buf[BUFSZ]; 159. 	    int erosion; 160.  161.  	    if (cant_see) { 162. 		You_cant("feel any Braille writing."); 163. 		return 0; 164. 	    }  165.  	    u.uconduct.literate++; 166. 	    if(flags.verbose) 167. 		pline("It reads:"); 168. 	    Strcpy(buf, shirt_msgs[scroll->o_id % SIZE(shirt_msgs)]); 169. 	    erosion = greatest_erosion(scroll); 170. 	    if (erosion) 171. 		wipeout_text(buf,  172.  			(int)(strlen(buf) * erosion / (2*MAX_ERODE)),  173.  			     scroll->o_id ^ (unsigned)u.ubirthday); 174. 	    pline("\"%s\"", buf); 175. 	    return 1; 176. #endif	/* TOURIST */ 177. 	} else if (scroll->oclass != SCROLL_CLASS  178.  		&& scroll->oclass != SPBOOK_CLASS) { 179. 	    pline(silly_thing_to, "read"); 180. 	    return(0); 181. 	} else if (Blind) { 182. 	    const char *what = 0; 183. 	    if (scroll->oclass == SPBOOK_CLASS) 184. 		what = "mystic runes"; 185. 	    else if (!scroll->dknown) 186. 		what = "formula on the scroll"; 187. 	    if (what) { 188. 		pline("Being blind, you cannot read the %s.", what); 189. 		return(0); 190. 	    }  191.  	} else if (cant_see) { 192. 	    if (scroll->oclass == SPBOOK_CLASS) 193. 	    {  194.  		You_cant("read the mystic runes in the invisible spellbook."); 195. 		return(0); 196. 	    }  197.  	    else if (!scroll->dknown) 198. 	    {  199.  		You_cant("read the formula on the invisible scroll."); 200. 		return(0); 201. 	    }  202.  	}  203.   204.  	/* Actions required to win the game aren't counted towards conduct */ 205. 	if (scroll->otyp != SPE_BOOK_OF_THE_DEAD &&  206.  		scroll->otyp != SPE_BLANK_PAPER &&  207.  		scroll->otyp != SCR_BLANK_PAPER) 208. 	    u.uconduct.literate++; 209.  210.  	confused = (Confusion != 0); 211. #ifdef MAIL 212. 	if (scroll->otyp == SCR_MAIL) confused = FALSE; 213. #endif 214. 	if(scroll->oclass == SPBOOK_CLASS) { 215. 	    return(study_book(scroll)); 216. 	}  217.  	scroll->in_use = TRUE;	/* scroll, not spellbook, now being read */ 218. 	if(scroll->otyp != SCR_BLANK_PAPER) { 219. 	  if(Blind) 220. 	    pline("As you %s the formula on it, the scroll disappears.",  221.  			is_silent(youmonst.data) ? "cogitate" : "pronounce"); 222. 	  else 223. 	    pline("As you read the scroll, it disappears."); 224. 	  if(confused) { 225. 	    if (Hallucination) 226. 		pline("Being so trippy, you screw up..."); 227. 	    else 228. 		pline("Being confused, you mis%s the magic words...",  229.  			is_silent(youmonst.data) ? "understand" : "pronounce"); 230. 	  }  231.  	}  232.  	/*  233.  	 * When reading scrolls of teleportation off the floor special 234. 	 * care needs to be taken so that the scroll is used up before 235. 	 * a potential level teleport occurs. 236. 	 */  237.  	if (scroll->otyp == SCR_TELEPORTATION) { 238. 	    otemp = *scroll; 239. 	    otemp.where = OBJ_FREE; 240. 	    otemp.nobj = (struct obj *)0; 241. 	    if (carried(scroll)) useup(scroll); 242. 	    else if (mcarried(scroll)) m_useup(scroll->ocarry, scroll); 243. 	    else useupf(scroll, 1L); 244. 	    scroll = &otemp; 245. 	}  246.  	if(!seffects(scroll))  { 247. 		if(!objects[scroll->otyp].oc_name_known) { 248. 		    if(known) { 249. 			makeknown(scroll->otyp); 250. 			more_experienced(0,10); 251. 		    } else if(!objects[scroll->otyp].oc_uname) 252. 			docall(scroll); 253. 		}  254.  		if (spell_skilltype(scroll->otyp) != P_NONE) { 255. 			use_skill(spell_skilltype(scroll->otyp),  256.  				(scroll->blessed ? 2 : 1)); 257.  		}  258.  		if(scroll->otyp != SCR_BLANK_PAPER &&  259.  		  scroll->otyp != SCR_TELEPORTATION) { 260. 		    if (carried(scroll)) useup(scroll); 261. 		    else if (mcarried(scroll)) m_useup(scroll->ocarry, scroll); 262. 		    else useupf(scroll, 1L); 263. 		}  264.  		else scroll->in_use = FALSE; 265. 	}  266.  	return(1); 267. }  268.   269.  static void 270. stripspe(obj) 271. register struct obj *obj; 272. {  273.  	if (obj->blessed) pline(nothing_happens); 274. 	else { 275. 		if (obj->spe > 0) { 276. 		    obj->spe = 0; 277. 		    if (obj->otyp == OIL_LAMP || obj->otyp == BRASS_LANTERN) 278. 			obj->age = 0; 279. 		    Your("%s %s briefly.",xname(obj), otense(obj, "vibrate")); 280. 		} else pline(nothing_happens); 281. 	}  282.  }  283.   284.  static void 285. p_glow1(otmp) 286. register struct obj	*otmp; 287. {  288.  	Your("%s %s briefly.", xname(otmp),  289.  	     otense(otmp, Blind ? "vibrate" : "glow")); 290. }  291.   292.  static void 293. p_glow2(otmp,color) 294. register struct obj	*otmp; 295. register const char *color; 296. {  297.  	Your("%s %s%s%s for a moment.",  298.  		xname(otmp),  299.  		otense(otmp, Blind ? "vibrate" : "glow"), 300.  		Blind ? "" : " ",  301.  		Blind ? nul : hcolor(color)); 302. }  303.   304.  /* Is the object chargeable? For purposes of inventory display; it is */ 305. /* possible to be able to charge things for which this returns FALSE. */ 306.  boolean 307. is_chargeable(obj) 308. struct obj *obj; 309. {  310.  	if (obj->oclass == WAND_CLASS || obj->oclass == SPBOOK_CLASS) return TRUE; 311. 	/* known && !uname is possible after amnesia/mind flayer */ 312. 	if (obj->oclass == RING_CLASS) 313. 	    return (boolean)(objects[obj->otyp].oc_charged &&  314.  			(obj->known || objects[obj->otyp].oc_uname)); 315. #ifdef LIGHTSABERS 316. 	if (is_lightsaber(obj)) 317. 	    return TRUE; 318. #endif 319. 	if (is_weptool(obj))	/* specific check before general tools */ 320. 	    return FALSE; 321. 	if (obj->oclass == TOOL_CLASS) 322. 	    return (boolean)(objects[obj->otyp].oc_charged); 323. 	return FALSE; /* why are weapons/armor considered charged anyway? */ 324.  }  325.   326.  /*  327.   * recharge an object; curse_bless is -1 if the recharging implement 328.  * was cursed, +1 if blessed, 0 otherwise. 329.  */  330.  void 331. recharge(obj, curse_bless) 332. struct obj *obj; 333. int curse_bless; 334. {  335.  	register int n;  336. boolean is_cursed, is_blessed; 337.  338.  	is_cursed = curse_bless < 0; 339. 	is_blessed = curse_bless > 0; 340.  341.  	if (obj->oclass == WAND_CLASS) { 342.  343.  	    /* undo any prior cancellation, even when is_cursed */ 344. 	    if (obj->spe == -1) obj->spe = 0; 345.  346.  	    /*  347.  	     * Recharging might cause wands to explode. 348. 	     *	v = number of previous recharges 349. 	     *	      v = percentage chance to explode on this attempt 350. 	     *		      v = cumulative odds for exploding 351. 	     *	0 :   0       0  352.  	     *	1 :   0.29    0.29  353.  	     *	2 :   2.33    2.62  354.  	     *	3 :   7.87   10.28  355.  	     *	4 :  18.66   27.02  356.  	     *	5 :  36.44   53.62  357.  	     *	6 :  62.97   82.83  358.  	     *	7 : 100     100  359.  	     */  360.  	    n = (int)obj->recharged; 361. 	    if (n > 0 && (obj->otyp == WAN_WISHING || 362. 		    (n * n * n > rn2(7*7*7)))) {	/* recharge_limit */ 363. 		Your("%s vibrates violently, and explodes!",xname(obj)); 364. 		wand_explode(obj, FALSE); 365. 		return; 366. 	    }  367.  	    /* didn't explode, so increment the recharge count */ 368. 	    obj->recharged = (unsigned)(n + 1); 369.  370.  	    /* now handle the actual recharging */ 371. 	    if (is_cursed) { 372. 		stripspe(obj); 373. 	    } else { 374. 		int lim = (obj->otyp == WAN_WISHING) ? 3 : 375.  			(objects[obj->otyp].oc_dir != NODIR) ? 8 : 15; 376.   377.  		n = (lim == 3) ? 3 : rn1(5, lim + 1 - 5); 378. 		if (!is_blessed) n = rnd(n); 379.  380.  		if (obj->spe < n) obj->spe = n;  381. else obj->spe++; 382. 		if (obj->otyp == WAN_WISHING && obj->spe > 3) { 383. 		    Your("%s vibrates violently, and explodes!",xname(obj)); 384. 		    wand_explode(obj, FALSE); 385. 		    return; 386. 		}  387.  		if (obj->spe >= lim) p_glow2(obj, NH_BLUE); 388. 		else p_glow1(obj); 389. 	    }  390.   391.  	} else if (obj->oclass == SPBOOK_CLASS) { 392.  393.  	    if (obj->otyp == SPE_BOOK_OF_THE_DEAD) { 394. 	    	pline(nothing_happens); 395. 		return; 396. 	    }  397.      398.  	    /*  399.  	     * Recharging might cause spellbooks to crumble. 400. 	     *	 v = number of previous recharges 401. 	     *	       v = percentage chance to crumble on this attempt 402. 	     *	               v = cumulative odds for crumbling 403. 	     *	 0 :   0       0  404.  	     *	 1 :   0.15    0.15  405.  	     *	 2 :   0.73    0.87  406.  	     *	 3 :   1.97    2.82  407.  	     *	 4 :   4.08    6.79  408.  	     *	 5 :   7.29   13.58  409.  	     *	 6 :  11.81   23.79  410.  	     *	 7 :  17.86   37.40  411.  	     *	 8 :  25.17   53.16  412.  	     *	 9 :  33.03   68.63  413.  	     *	10 :  40.68   81.39  414.  	     *	11 :  47.64   90.26  415.  	     *	12 :  53.72   95.49  416.  	     *	13 :  58.90   98.15  417.  	     *	14 :  63.29   99.32  418.  	     */  419.  	    n = (int)obj->recharged; 420. 	    if (n > 0 && (n * n * n > rn2(7*7*7))) {	/* recharge_limit */ 421. 		Your("%s crumbles to dust!", xname(obj)); 422. 		useup(obj); 423. 		    return; 424. 		}  425.  	    /* didn't crumble, so possibly increment the recharge count */ 426. 	    if (!rn2(2)) obj->recharged = (unsigned)(n + 1); 427.  428.  	    /* now handle the actual recharging */ 429. 	    if (is_cursed) { 430. 		stripspe(obj); 431.   	    } else { 432. 		int lim = (objects[obj->otyp].oc_dir != NODIR) ? 8 : 15; 433.   434.  		n = rn1(5, lim + 1 - 5); 435. 		if (!is_blessed) n = rnd(n); 436.  437.  		if (obj->spe < n) obj->spe = n;  438. else obj->spe++; 439. 		if (obj->spe >= lim) p_glow2(obj, NH_BLUE); 440. 		else p_glow1(obj); 441. 	    }  442.   443.  	} else if (obj->oclass == RING_CLASS &&  444.  					objects[obj->otyp].oc_charged) { 445. 	    /* charging does not affect ring's curse/bless status */ 446. 	    int s = is_blessed ? rnd(3) : is_cursed ? -rnd(2) : 1; 447. 	    boolean is_on = (obj == uleft || obj == uright); 448.  449.  	    /* destruction depends on current state, not adjustment */ 450. 	    if (obj->spe > rn2(7) || obj->spe <= -5) { 451. 		Your("%s %s momentarily, then %s!",  452.  		     xname(obj), otense(obj,"pulsate"), otense(obj,"explode")); 453. 		if (is_on) Ring_gone(obj); 454. 		s = rnd(3 * abs(obj->spe));	/* amount of damage */ 455. 		useup(obj); 456. 		losehp(s, "exploding ring", KILLED_BY_AN); 457. 	    } else { 458. 		long mask = is_on ? (obj == uleft ? LEFT_RING : 459.  				     RIGHT_RING) : 0L; 460. 		Your("%s spins %sclockwise for a moment.",  461.  		     xname(obj), s < 0 ? "counter" : ""); 462. 		/* cause attributes and/or properties to be updated */ 463. 		if (is_on) Ring_off(obj); 464. 		obj->spe += s;	/* update the ring while it's off */ 465. 		if (is_on) setworn(obj, mask), Ring_on(obj); 466. 		/* oartifact: if a touch-sensitive artifact ring is  467. ever created the above will need to be revised */ 468. 	    }  469.   470.  	} else if (obj->oclass == TOOL_CLASS) { 471. 	    int rechrg = (int)obj->recharged; 472.  473.  	    if (objects[obj->otyp].oc_charged) { 474. 		/* tools don't have a limit, but the counter used does */ 475. 		if (rechrg < 7)	/* recharge_limit */ 476. 		    obj->recharged++; 477. 	    }  478.  	    switch(obj->otyp) { 479. 	    case BELL_OF_OPENING: 480. 		if (is_cursed) stripspe(obj); 481. 		else if (is_blessed) obj->spe += rnd(3); 482. 		else obj->spe += 1; 483. 		if (obj->spe > 5) obj->spe = 5; 484. 		break; 485. 	    case MAGIC_MARKER: 486. 	    case TINNING_KIT: 487. #ifdef TOURIST 488. 	    case EXPENSIVE_CAMERA: 489. #endif 490. 		if (is_cursed) stripspe(obj); 491. 		else if (rechrg && obj->otyp == MAGIC_MARKER) {	/* previously recharged */ 492. 		    obj->recharged = 1;	/* override increment done above */ 493. 		    if (obj->spe < 3) 494. 			Your("marker seems permanently dried out."); 495. 		    else 496. 			pline(nothing_happens); 497. 		} else if (is_blessed) { 498. 		    n = rn1(16,15);		/* 15..30 */ 499. 		    if (obj->spe + n <= 50) 500. 			obj->spe = 50; 501. 		    else if (obj->spe + n <= 75) 502. 			obj->spe = 75; 503. 		    else { 504. 			int chrg = (int)obj->spe; 505. 			if ((chrg + n) > 127) 506. 				obj->spe = 127; 507. 			else 508. 				obj->spe += n;  509. } 510.  		    p_glow2(obj, NH_BLUE); 511. 		} else { 512. 		    n = rn1(11,10);		/* 10..20 */ 513. 		    if (obj->spe + n <= 50) 514. 			obj->spe = 50; 515. 		    else { 516. 			int chrg = (int)obj->spe; 517. 			if ((chrg + n) > 127) 518. 				obj->spe = 127; 519. 			else 520. 				obj->spe += n;  521. } 522.  		    p_glow2(obj, NH_WHITE); 523. 		}  524.  		break; 525. 	    case OIL_LAMP: 526. 	    case BRASS_LANTERN: 527. 		if (is_cursed) { 528. 		    stripspe(obj); 529. 		    if (obj->lamplit) { 530. 			if (!Blind) 531. 			    pline("%s out!", Tobjnam(obj, "go")); 532. 			end_burn(obj, TRUE); 533. 		    }  534.  		} else if (is_blessed) { 535. 		    obj->spe = 1; 536. 		    obj->age = 1500; 537. 		    p_glow2(obj, NH_BLUE); 538. 		} else { 539. 		    obj->spe = 1; 540. 		    obj->age += 750; 541. 		    if (obj->age > 1500) obj->age = 1500; 542. 		    p_glow1(obj); 543. 		}  544.  		break; 545. #ifdef LIGHTSABERS 546. 	    case GREEN_LIGHTSABER: 547. #ifdef D_SABER 548. 	    case BLUE_LIGHTSABER: 549. #endif 550. 	    case RED_LIGHTSABER: 551. 	    case RED_DOUBLE_LIGHTSABER: 552. 		if (is_cursed) { 553. 		    if (obj->lamplit) { 554. 			end_burn(obj, TRUE); 555. 			obj->age = 0; 556. 			if (!Blind) 557. 			    pline("%s deactivates!", The(xname(obj))); 558. 		    } else 559. 			obj->age = 0; 560. 		} else if (is_blessed) { 561. 		    obj->age = 1500; 562. 		    p_glow2(obj, NH_BLUE); 563. 		} else { 564. 		    obj->age += 750; 565. 		    if (obj->age > 1500) obj->age = 1500; 566. 		    p_glow1(obj); 567. 		}  568.  		break; 569. #endif 570. 	    case CRYSTAL_BALL: 571. 		if (is_cursed) stripspe(obj); 572. 		else if (is_blessed) { 573. 		    obj->spe = 6; 574. 		    p_glow2(obj, NH_BLUE); 575. 		} else { 576. 		    if (obj->spe < 5) { 577. 			obj->spe++; 578. 			p_glow1(obj); 579. 		    } else pline(nothing_happens); 580. 		}  581.  		break; 582. 	    case HORN_OF_PLENTY: 583. 	    case BAG_OF_TRICKS: 584. 	    case CAN_OF_GREASE: 585. 		if (is_cursed) stripspe(obj); 586. 		else if (is_blessed) { 587. 		    if (obj->spe <= 10) 588. 			obj->spe += rn1(10, 6); 589. 		    else obj->spe += rn1(5, 6); 590. 		    if (obj->spe > 50) obj->spe = 50; 591. 		    p_glow2(obj, NH_BLUE); 592. 		} else { 593. 		    obj->spe += rnd(5); 594. 		    if (obj->spe > 50) obj->spe = 50; 595. 		    p_glow1(obj); 596. 		}  597.  		break; 598. 	    case MAGIC_FLUTE: 599. 	    case MAGIC_HARP: 600. 	    case FROST_HORN: 601. 	    case FIRE_HORN: 602. 	    case DRUM_OF_EARTHQUAKE: 603. 		if (is_cursed) { 604. 		    stripspe(obj); 605. 		} else if (is_blessed) { 606. 		    obj->spe += d(2,4); 607. 		    if (obj->spe > 20) obj->spe = 20; 608. 		    p_glow2(obj, NH_BLUE); 609. 		} else { 610. 		    obj->spe += rnd(4); 611. 		    if (obj->spe > 20) obj->spe = 20; 612. 		    p_glow1(obj); 613. 		}  614.  		break; 615. 	    default: 616. 		goto not_chargable; 617. 		/*NOTREACHED*/ 618. 		break; 619. 	    } /* switch */ 620.  621.  	} else { 622.  not_chargable: 623. 	    You("have a feeling of loss."); 624. 	}  625.  }  626.   627.   628.  /* Forget known information about this object class. */ 629.  static void 630. forget_single_object(obj_id) 631. 	int obj_id; 632. {  633.  	objects[obj_id].oc_name_known = 0; 634. 	objects[obj_id].oc_pre_discovered = 0;	/* a discovery when relearned */ 635. 	if (objects[obj_id].oc_uname) { 636. 	    free((genericptr_t)objects[obj_id].oc_uname); 637. 	    objects[obj_id].oc_uname = 0; 638. 	}  639.  	undiscover_object(obj_id);	/* after clearing oc_name_known */ 640.  641.  	/* clear & free object names from matching inventory items too? */ 642.  }  643.   644.   645.  #if 0	/* here if anyone wants it.... */ 646.  /* Forget everything known about a particular object class. */ 647.  static void 648. forget_objclass(oclass) 649. 	int oclass; 650. {  651.  	int i;  652. 653. 	for (i=bases[oclass];  654.  		i < NUM_OBJECTS && objects[i].oc_class==oclass; i++) 655. 	    forget_single_object(i); 656. }  657.  #endif 658.  659.   660.  /* randomize the given list of numbers  0 <= i < count */ 661. static void 662. randomize(indices, count) 663. 	int *indices; 664. 	int count; 665. {  666.  	int i, iswap, temp; 667.  668.  	for (i = count - 1; i > 0; i--) { 669. 	    if ((iswap = rn2(i + 1)) == i) continue; 670. 	    temp = indices[i]; 671. 	    indices[i] = indices[iswap]; 672. 	    indices[iswap] = temp; 673. 	}  674.  }  675.   676.   677.  /* Forget % of known objects. */ 678.  void 679. forget_objects(percent) 680. 	int percent; 681. {  682.  	int i, count; 683. 	int indices[NUM_OBJECTS]; 684.  685.  	if (percent == 0) return; 686. 	if (percent <= 0 || percent > 100) { 687. 	    impossible("forget_objects: bad percent %d", percent); 688. 	    return; 689. 	}  690.   691.  	for (count = 0, i = 1; i < NUM_OBJECTS; i++) 692. 	    if (OBJ_DESCR(objects[i]) &&  693.  		    (objects[i].oc_name_known || objects[i].oc_uname)) 694. 		indices[count++] = i;  695. 696. 	randomize(indices, count); 697.  698.  	/* forget first % of randomized indices */ 699. 	count = ((count * percent) + 50) / 100; 700. 	for (i = 0; i < count; i++) 701. 	    forget_single_object(indices[i]); 702. }  703.   704.   705.  /* Forget some or all of map (depends on parameters). */ 706.  void 707. forget_map(howmuch) 708. 	int howmuch; 709. {  710.  	register int zx, zy; 711.  712.  	if (In_sokoban(&u.uz)) 713. 	    return; 714.  715.  	known = TRUE; 716. 	for(zx = 0; zx < COLNO; zx++) for(zy = 0; zy < ROWNO; zy++) 717. 	    if (howmuch & ALL_MAP || rn2(7)) { 718. 		/* Zonk all memory of this location. */ 719.  		levl[zx][zy].seenv = 0; 720. 		levl[zx][zy].waslit = 0; 721. 		clear_memory_glyph(zx, zy, S_stone); 722. 	    }  723.  }  724.   725.  /* Forget all traps on the level. */ 726.  void 727. forget_traps 728. {  729.  	register struct trap *trap; 730.  731.  	/* forget all traps (except the one the hero is in :-) */ 732. 	for (trap = ftrap; trap; trap = trap->ntrap) 733. 	    if ((trap->tx != u.ux || trap->ty != u.uy) && (trap->ttyp != HOLE)) 734. 		trap->tseen = 0; 735. }  736.   737.  /*  738.   * Forget given % of all levels that the hero has visited and not forgotten, 739.  * except this one. 740.  */  741.  void 742. forget_levels(percent) 743. 	int percent; 744. {  745.  	int i, count; 746. 	xchar  maxl, this_lev; 747. 	int indices[MAXLINFO]; 748.  749.  	if (percent == 0) return; 750.  751.  	if (percent <= 0 || percent > 100) { 752. 	    impossible("forget_levels: bad percent %d", percent); 753. 	    return; 754. 	}  755.   756.  	this_lev = ledger_no(&u.uz); 757. 	maxl = maxledgerno; 758.  759.  	/* count & save indices of non-forgotten visited levels */ 760. 	/* Sokoban levels are pre-mapped for the player, and should stay 761. 	 * so, or they become nearly impossible to solve. But try to 762. * shift the forgetting elsewhere by fiddling with percent 763. 	 * instead of forgetting fewer levels. 764. 	 */  765.  	for (count = 0, i = 0; i <= maxl; i++) 766. 	    if ((level_info[i].flags & VISITED) &&  767.  			!(level_info[i].flags & FORGOTTEN) && i != this_lev) { 768. 		if (ledger_to_dnum(i) == sokoban_dnum) 769. 		    percent += 2; 770. 		else 771. 		    indices[count++] = i;  772. } 773.  	  774.  	if (percent > 100) percent = 100; 775.  776.  	randomize(indices, count); 777.  778.  	/* forget first % of randomized indices */ 779. 	count = ((count * percent) + 50) / 100; 780. 	for (i = 0; i < count; i++) { 781. 	    level_info[indices[i]].flags |= FORGOTTEN; 782. 	}  783.  }  784.   785.  /*  786.   * Forget some things (e.g. after reading a scroll of amnesia). When called, 787.  * the following are always forgotten: 788.  *  789.   *	- felt ball & chain 790.  *	- traps 791.  *	- part (6 out of 7) of the map 792.  *  793.   * Other things are subject to flags: 794.  *  795.   *	howmuch & ALL_MAP	= forget whole map 796.  *	howmuch & ALL_SPELLS	= forget all spells 797.  */  798.  void 799. forget(howmuch) 800. int howmuch; 801. {  802.   803.  	if (Punished) u.bc_felt = 0;	/* forget felt ball&chain */ 804.  805.  	forget_map(howmuch); 806. 	forget_traps; 807.  808.  	/* 1 in 3 chance of forgetting some levels */ 809. 	if (!rn2(3)) forget_levels(rn2(25)); 810.  811.  	/* 1 in 3 chance of forgeting some objects */ 812. 	if (!rn2(3)) forget_objects(rn2(25)); 813.  814.  	if (howmuch & ALL_SPELLS) losespells; 815. 	/*  816.  	 * Make sure that what was seen is restored correctly. To do this, 817. 	 * we need to go blind for an instant --- turn off the display, 818. 	 * then restart it. All this work is needed to correctly handle 819. 	 * walls which are stone on one side and wall on the other. Turning 820. 	 * off the seen bits above will make the wall revert to stone,  but 821. 	 * there are cases where we don't want this to happen. The easiest 822. 	 * thing to do is to run it through the vision system again, which 823. 	 * is always correct. 824. 	 */  825.  	docrt;		/* this correctly will reset vision */ 826. }  827.   828.  /* monster is hit by scroll of taming's effect */ 829. static void 830. maybe_tame(mtmp, sobj) 831. struct monst *mtmp; 832. struct obj *sobj; 833. {  834.  #ifdef BLACKMARKET 835. 	if (sobj->cursed || Is_blackmarket(&u.uz)) { 836. #else 837. 	if (sobj->cursed) { 838. #endif 839. 	    setmangry(mtmp); 840. 	} else { 841. 	    if (mtmp->isshk) 842. 		make_happy_shk(mtmp, FALSE); 843. 	    else if (!resist(mtmp, sobj->oclass, 0, NOTELL)) 844. 		(void) tamedog(mtmp, (struct obj *) 0); 845. 	}  846.  }  847.   848.  int 849. seffects(sobj) 850. register struct obj	*sobj; 851. {  852.  	register int cval; 853. 	register boolean confused = (Confusion != 0); 854. 	register struct obj *otmp; 855.  856.  	if (objects[sobj->otyp].oc_magic) 857. 		exercise(A_WIS, TRUE);		/* just for trying */ 858. 	switch(sobj->otyp) { 859. #ifdef MAIL 860. 	case SCR_MAIL: 861. 		known = TRUE; 862. 		if (sobj->spe) 863. 		    pline("This seems to be junk mail addressed to the finder of the Eye of Larn."); 864. 		/* note to the puzzled: the game Larn actually sends you junk 865. 		 * mail if you win! 866. 		 */  867.  		else readmail(sobj); 868. 		break; 869. #endif 870. 	case SPE_ENCHANT_ARMOR: 871. 	case SCR_ENCHANT_ARMOR: 872. 	    {  873.  		register schar s;  874. boolean special_armor; 875. 		boolean same_color; 876.  877.  		otmp = some_armor(&youmonst); 878. 		if(!otmp) { 879. 			strange_feeling(sobj,  880.  					!Blind ? "Your skin glows then fades." :  881.  					"Your skin feels warm for a moment."); 882. 			exercise(A_CON, !sobj->cursed); 883. 			exercise(A_STR, !sobj->cursed); 884. 			return(1); 885. 		}  886.  		if(confused) { 887. 			otmp->oerodeproof = !(sobj->cursed); 888. 			if(Blind) { 889. 			    otmp->rknown = FALSE; 890. 			    Your("%s %s warm for a moment.",  891.  				xname(otmp), otense(otmp, "feel")); 892. 			} else { 893. 			    otmp->rknown = TRUE; 894. 			    Your("%s %s covered by a %s %s %s!",  895.  				xname(otmp), otense(otmp, "are"),  896.  				sobj->cursed ? "mottled" : "shimmering",  897.  				 hcolor(sobj->cursed ? NH_BLACK : NH_GOLDEN), 898.  				sobj->cursed ? "glow" :  899.  				  (is_shield(otmp) ? "layer" : "shield")); 900. 			}  901.  			if (otmp->oerodeproof &&  902.  			    (otmp->oeroded || otmp->oeroded2)) { 903. 			    otmp->oeroded = otmp->oeroded2 = 0; 904. 			    Your("%s %s as good as new!",  905.  				 xname(otmp),  906.  				 otense(otmp, Blind ? "feel" : "look")); 907. 			}  908.  			break; 909. 		}  910.  		/* elven armor vibrates warningly when enchanted beyond a limit */ 911. 		special_armor = is_elven_armor(otmp) || 912. 		  (Role_if(PM_WIZARD) && otmp->otyp == CORNUTHAUM) || 913. 		  (Role_if(PM_VALKYRIE) && otmp->otyp == GAUNTLETS_OF_POWER); 914.  915.  		if (sobj->cursed) 916. 		    same_color = 917. 			(otmp->otyp == BLACK_DRAGON_SCALE_MAIL ||  918.  			 otmp->otyp == BLACK_DRAGON_SCALES); 919. 		else 920. 		    same_color = 921. 			(otmp->otyp == SILVER_DRAGON_SCALE_MAIL ||  922.  			 otmp->otyp == SILVER_DRAGON_SCALES ||  923.  			 otmp->otyp == SHIELD_OF_REFLECTION); 924. 		if (Blind) same_color = FALSE; 925.  926.  		/* KMH -- catch underflow */ 927. 		s = sobj->cursed ? -otmp->spe : otmp->spe; 928. 		  929.  		if (s > (special_armor ? 5 : 3) && rn2(s)) { 930. 		Your("%s violently %s%s%s for a while, then %s.",  931.  		     xname(otmp),  932.  		     otense(otmp, Blind ? "vibrate" : "glow"), 933.  		     (!Blind && !same_color) ? " " : nul,  934.  		     (Blind || same_color) ? nul :  935.  			hcolor(sobj->cursed ? NH_BLACK : NH_SILVER), 936.  		     otense(otmp, "evaporate")); 937. 			if(is_cloak(otmp)) (void) Cloak_off; 938. 			if(is_boots(otmp)) (void) Boots_off; 939. 			if(is_helmet(otmp)) (void) Helmet_off; 940. 			if(is_gloves(otmp)) (void) Gloves_off; 941. 			if(is_shield(otmp)) (void) Shield_off; 942. 			if(otmp == uarm) (void) Armor_gone; 943. 			useup(otmp); 944. 			break; 945. 		}  946.   947.  		/* KMH, balance patch -- Restore the NetHack success rate */ 948. 		/* We'll introduce a disenchantment attack later */ 949. 		s = sobj->cursed ? -1 : 950.  		    otmp->spe >= 9 ? (rn2(otmp->spe) == 0) : 951. 		    sobj->blessed ? rnd(3-otmp->spe/3) : 1; 952. /*		s = sobj->cursed ? -rnd(2) : 953. 		    otmp->spe >= 3 ? (rn2(otmp->spe) == 0) : 954. 		    sobj->blessed ? rnd(2) : 1;*/ 955. 		if (s >= 0 && otmp->otyp >= GRAY_DRAGON_SCALES &&  956.  					otmp->otyp <= YELLOW_DRAGON_SCALES) { 957. 			/* dragon scales get turned into dragon scale mail */ 958. 			Your("%s merges and hardens!", xname(otmp)); 959. 			setworn((struct obj *)0, W_ARM); 960. 			/* assumes same order */ 961. 			otmp->otyp = GRAY_DRAGON_SCALE_MAIL + 962. 						otmp->otyp - GRAY_DRAGON_SCALES; 963. 			otmp->cursed = 0; 964. 			if (sobj->blessed) { 965. 				otmp->spe++; 966. 				otmp->blessed = 1; 967. 			}  968.  			otmp->known = 1; 969. 			setworn(otmp, W_ARM); 970. 			break; 971. 		}  972.  		Your("%s %s%s%s%s for a %s.",  973.  			xname(otmp),  974.  		        s == 0 ? "violently " : nul,  975.  			otense(otmp, Blind ? "vibrate" : "glow"), 976.  			(!Blind && !same_color) ? " " : nul,  977.  			(Blind || same_color) ? nul : hcolor(sobj->cursed ? NH_BLACK : NH_SILVER), 978.  			  (s*s>1) ? "while" : "moment"); 979. 		otmp->cursed = sobj->cursed; 980. 		if (!otmp->blessed || sobj->cursed) 981. 			otmp->blessed = sobj->blessed; 982. 		if (s) { 983. 			otmp->spe += s;  984. adj_abon(otmp, s); 985. 			known = otmp->known; 986. 		}  987.   988.  		if ((otmp->spe > (special_armor ? 5 : 3)) &&  989.  		    (special_armor || !rn2(7))) 990. 			Your("%s suddenly %s %s.",  991.  				xname(otmp), otense(otmp, "vibrate"),  992.  				Blind ? "again" : "unexpectedly"); 993. 		break; 994. 	    }  995.  	case SCR_DESTROY_ARMOR: 996. 	    {  997.  		otmp = some_armor(&youmonst); 998. 		if(confused) { 999. 			if(!otmp) { 1000. 				strange_feeling(sobj,"Your bones itch."); 1001. 				exercise(A_STR, FALSE); 1002. 				exercise(A_CON, FALSE); 1003. 				return(1); 1004. 			} 1005. 			otmp->oerodeproof = sobj->cursed; 1006. 			p_glow2(otmp, NH_PURPLE); 1007. 			break; 1008. 		} 1009. 		if(!sobj->cursed || !otmp || !otmp->cursed) { 1010. 		   if(!destroy_arm(otmp)) { 1011. 			strange_feeling(sobj,"Your skin itches."); 1012. 			exercise(A_STR, FALSE); 1013. 			exercise(A_CON, FALSE); 1014. 			return(1); 1015. 		   } else 1016. 			known = TRUE; 1017. 		} else {	/* armor and scroll both cursed */ 1018. 		   Your("%s %s.", xname(otmp), otense(otmp, "vibrate")); 1019. 		   if (otmp->spe >= -6) otmp->spe--; 1020. 		   make_stunned(HStun + rn1(10, 10), TRUE); 1021. 		} 1022. 	    }  1023. 	    break; 1024. 	case SCR_CONFUSE_MONSTER: 1025. 	case SPE_CONFUSE_MONSTER: 1026. 		if(youmonst.data->mlet != S_HUMAN || sobj->cursed) { 1027. 			if(!HConfusion) You_feel("confused."); 1028. 			make_confused(HConfusion + rnd(100),FALSE); 1029. 		} else if(confused) { 1030. 		   if(!sobj->blessed) { 1031. 			Your("%s begin to %s%s.", 1032. 			    makeplural(body_part(HAND)),  1033. 			    Blind ? "tingle" : "glow ",  1034. 			    Blind ? nul : hcolor(NH_PURPLE)); 1035. 			make_confused(HConfusion + rnd(100),FALSE); 1036. 		   } else { 1037. 			pline("A %s%s surrounds your %s.", 1038. 			    Blind ? nul : hcolor(NH_RED),  1039. 			    Blind ? "faint buzz" : " glow",  1040. 			    body_part(HEAD)); 1041. 			make_confused(0L,TRUE); 1042. 		   }  1043. 		} else { 1044. 		   if (!sobj->blessed) { 1045. 			Your("%s%s %s%s.", 1046. 			makeplural(body_part(HAND)),  1047. 			Blind ? "" : " begin to glow",  1048. 			Blind ? (const char *)"tingle" : hcolor(NH_RED),  1049. 			u.umconf ? " even more" : ""); 1050. 			u.umconf++; 1051. 		   } else { 1052. 			if (Blind) 1053. 			   Your("%s tingle %s sharply.",  1054. 				makeplural(body_part(HAND)),  1055. 				u.umconf ? "even more" : "very"); 1056. 			else 1057. 			   Your("%s glow a%s brilliant %s.",  1058. 				makeplural(body_part(HAND)),  1059. 				u.umconf ? "n even more" : "",  1060. 				hcolor(NH_RED)); 1061. 			/* after a while, repeated uses become less effective */ 1062. 			if (u.umconf >= 40) 1063. 			   u.umconf++; 1064. 			else 1065. 			   u.umconf += rn1(8, 2); 1066. 		   }  1067. 		}  1068. 		break; 1069. 	case SCR_SCARE_MONSTER: 1070. 	case SPE_CAUSE_FEAR: 1071. 	   {	register int ct = 0; 1072. 		register struct monst *mtmp; 1073. 1074. 		for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 1075. 		   if (DEADMONSTER(mtmp)) continue; 1076. 		   if(cansee(mtmp->mx,mtmp->my)) { 1077. 			if(confused || sobj->cursed) { 1078. 			   mtmp->mflee = mtmp->mfrozen = mtmp->msleeping = 0; 1079. 			   mtmp->mcanmove = 1; 1080. 			} else 1081. 			   if (! resist(mtmp, sobj->oclass, 0, NOTELL)) 1082. 				monflee(mtmp, 0, FALSE, FALSE); 1083. 			if(!mtmp->mtame) ct++;	/* pets don't laugh at you */ 1084. 		   }  1085. 		}  1086. 		if(!ct) 1087. 		     You_hear("%s in the distance.",  1088. 			       (confused || sobj->cursed) ? "sad wailing" :  1089. 							"maniacal laughter"); 1090. 		else if(sobj->otyp == SCR_SCARE_MONSTER) 1091. 			You_hear("%s close by.", 1092. 				  (confused || sobj->cursed) ? "sad wailing" :  1093. 						 "maniacal laughter"); 1094. 		break; 1095. 	   }  1096. 	case SCR_BLANK_PAPER: 1097. 	   if (Blind) 1098. 		You("don't remember there being any magic words on this scroll."); 1099. 	   else 1100. 		pline("This scroll seems to be blank."); 1101. 	   known = TRUE; 1102. 	   break; 1103. 	/* KMH, balance patch -- removed 1104. 	case SCR_TRAP_DETECTION: 1105. 		if (!sobj->cursed) return(trap_detect(sobj)); 1106. 	   break;*/ 1107. 	case SCR_REMOVE_CURSE: 1108. 	case SPE_REMOVE_CURSE: 1109. 	   {	register struct obj *obj; 1110. 		if(confused) { 1111. 		   if (Hallucination) 1112. 			You_feel("the power of the Force against you!"); 1113. 		   else 1114. 			You_feel("like you need some help."); 1115. 		} else 1116. 		   if (Hallucination) 1117. 			You_feel("in touch with the Universal Oneness."); 1118. 		   else 1119. 			You_feel("like someone is helping you."); 1120. 1121. 		if (sobj->cursed) { 1122. 		   pline_The("scroll disintegrates."); 1123. 		} else { 1124. 		   for (obj = invent; obj; obj = obj->nobj) { 1125. 			long wornmask; 1126. #ifdef GOLDOBJ 1127. 			/* gold isn't subject to cursing and blessing */ 1128. 			if (obj->oclass == COIN_CLASS) continue; 1129. #endif 1130. 			wornmask = (obj->owornmask & ~(W_BALL|W_ART|W_ARTI)); 1131. 			if (wornmask && !sobj->blessed) { 1132. 			   /* handle a couple of special cases; we don't  1133. allow auxiliary weapon slots to be used to 1134. artificially increase number of worn items */ 1135. 			   if (obj == uswapwep) { 1136. 				if (!u.twoweap) wornmask = 0L; 1137. 			   } else if (obj == uquiver) { 1138. 				if (obj->oclass == WEAPON_CLASS) { 1139. 				   /* mergeable weapon test covers ammo, 1140. 				      missiles, spears, daggers & knives */ 1141. 				   if (!objects[obj->otyp].oc_merge) 1142. 					wornmask = 0L; 1143. 				} else if (obj->oclass == GEM_CLASS) { 1144. 				   /* possibly ought to check whether 1145. 				      alternate weapon is a sling... */ 1146. 				    if (!uslinging) wornmask = 0L; 1147. 				} else { 1148. 				   /* weptools don't merge and aren't  1149. reasonable quivered weapons */ 1150. 				   wornmask = 0L; 1151. 				} 1152. 			    }  1153. 			}  1154. 			if (sobj->blessed || wornmask ||  1155. 			     obj->otyp == LOADSTONE ||  1156. 			     obj->otyp == HEALTHSTONE ||  1157. 			     (obj->otyp == LEASH && obj->leashmon)) { 1158. 			   if(confused) blessorcurse(obj, 2); 1159. 			   else uncurse(obj); 1160. 			} 1161. 		    }  1162. 		}  1163. 		if(Punished && !confused) unpunish; 1164. 		update_inventory; 1165. 		break; 1166. 	   }  1167. 	case SCR_CREATE_MONSTER: 1168. 	case SPE_CREATE_MONSTER: 1169. 	   if (create_critters(1 + ((confused || sobj->cursed) ? 12 : 0) + 1170. 				((sobj->blessed || rn2(73)) ? 0 : rnd(4)), 1171. 			confused ? &mons[PM_ACID_BLOB] : (struct permonst *)0)) 1172. 		known = TRUE; 1173. 	   /* no need to flush monsters; we ask for identification only if the 1174. 	    * monsters are not visible 1175. 	    */  1176. 	    break; 1177. 	case SPE_SUMMON_UNDEAD: 1178. 	   {  1179. 		int cnt = 1, oldmulti = multi; 1180.                struct monst *mtmp; 1181. 		multi = 0; 1182.   1183. 		if(!rn2(73) && !sobj->blessed) cnt += rnd(4); 1184. 		if(confused || sobj->cursed) cnt += 12; 1185. 		while(cnt--) { 1186. #ifdef WIZARD 1187. 		   if(!wizard || !(mtmp = create_particular)) 1188. #endif 1189. 		   switch (rn2(10)+1) { 1190. 		   case 1: 1191. 			mtmp = makemon(mkclass(S_VAMPIRE,0), u.ux, u.uy, NO_MM_FLAGS); 1192. 			break; 1193. 		   case 2: 1194. 		   case 3: 1195. 		   case 4: 1196. 		   case 5: 1197. 			mtmp = makemon(mkclass(S_ZOMBIE,0), u.ux, u.uy, NO_MM_FLAGS); 1198. 			break; 1199. 		   case 6: 1200. 		   case 7: 1201. 		   case 8: 1202. 			mtmp = makemon(mkclass(S_MUMMY,0), u.ux, u.uy, NO_MM_FLAGS); 1203. 			break; 1204. 		   case 9: 1205. 			mtmp = makemon(mkclass(S_GHOST,0), u.ux, u.uy, NO_MM_FLAGS); 1206. 			break; 1207. 		   case 10: 1208. 			mtmp = makemon(mkclass(S_WRAITH,0), u.ux, u.uy, NO_MM_FLAGS); 1209. 			break; 1210. 		   }  1211. 		    /* WAC Give N a shot at controlling the beasties 1212. 		    * (if not cursed ). Check curse status in case 1213. 		    * this ever becomes a scroll 1214. 		    */  1215. 		    if (mtmp) 1216. 			if (!sobj->cursed && Role_if(PM_NECROMANCER)) { 1217. 			   if (!resist(mtmp, sobj->oclass, 0, TELL)) { 1218. 				mtmp = tamedog(mtmp, (struct obj *) 0); 1219. 				if (mtmp) You("dominate %s!", mon_nam(mtmp)); 1220. 			   }  1221. 			} else setmangry(mtmp); 1222. 		} 1223. 		multi = oldmulti; 1224. 		/* WAC Give those who know command undead a shot at control. 1225. 		 * Since spell is area affect, do this after all undead 1226. 		 * are summoned 1227. 		 */ 1228. 		if (!Role_if(PM_NECROMANCER) && !(sobj->cursed)) { 1229. 		   if (objects[SPE_COMMAND_UNDEAD].oc_name_known) { 1230. 			int sp_no; 1231. 			for (sp_no = 0; sp_no < MAXSPELL; sp_no++) 1232. 			   if (spl_book[sp_no].sp_id == SPE_COMMAND_UNDEAD) { 1233. 				You("try to command %s", mon_nam(mtmp)); 1234. 				spelleffects(sp_no, TRUE); 1235. 				break; 1236. 			   }  1237. 			if (sp_no == MAXSPELL) 1238. 			   You("don't seem to have the spell command undead memorized!"); 1239. 		   } else You("don't know how to command undead..."); 1240. 		} 1241. 		/* flush monsters before asking for identification */ 1242. 		flush_screen(0); 1243. 		break; 1244. 	   }  1245. 	case SPE_ENCHANT_WEAPON: 1246. 	case SCR_ENCHANT_WEAPON: 1247. 		if(uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep)) 1248. 			&& confused) { 1249. 		/* oclass check added 10/25/86 GAN */ 1250. 			uwep->oerodeproof = !(sobj->cursed); 1251. 			if (Blind) { 1252. 			   uwep->rknown = FALSE; 1253. 			   Your("weapon feels warm for a moment."); 1254. 			} else { 1255. 			   uwep->rknown = TRUE; 1256. 			   Your("%s covered by a %s %s %s!",  1257. 				aobjnam(uwep, "are"),  1258. 				sobj->cursed ? "mottled" : "shimmering",  1259. 				hcolor(sobj->cursed ? NH_PURPLE : NH_GOLDEN), 1260. 				sobj->cursed ? "glow" : "shield"); 1261. 			} 1262. 			if (uwep->oerodeproof && (uwep->oeroded || uwep->oeroded2)) { 1263. 			   uwep->oeroded = uwep->oeroded2 = 0; 1264. 			   Your("%s as good as new!",  1265. 				 aobjnam(uwep, Blind ? "feel" : "look")); 1266. 			} 1267. 		/* KMH, balance patch -- Restore the NetHack success rate */ 1268. 		} else return !chwepon(sobj, 1269. 				       sobj->cursed ? -1 :  1270. 				       !uwep ? 1 :  1271. 				       uwep->spe >= 9 ? (rn2(uwep->spe) == 0) :  1272. 				       sobj->blessed ? rnd(3-uwep->spe/3) : 1); 1273. /*		else return !chwepon(sobj, 1274. 				       sobj->cursed ? -rnd(2) :  1275. 				       !uwep ? 1 :  1276. 				       uwep->spe >= 3 ? (rn2(uwep->spe) == 0) :  1277. 				       sobj->blessed ? rnd(2) : 1);*/ 1278. 		break; 1279. 	case SCR_TAMING: 1280. 	case SPE_CHARM_MONSTER: 1281. 		if (u.uswallow) { 1282. 		   maybe_tame(u.ustuck, sobj); 1283. 		} else { 1284. 		   int i, j, bd = confused ? 5 : 1; 1285. 		    struct monst *mtmp; 1286. 1287. 		    for (i = -bd; i <= bd; i++) for(j = -bd; j <= bd; j++) { 1288. 			if (!isok(u.ux + i, u.uy + j)) continue; 1289. 			if ((mtmp = m_at(u.ux + i, u.uy + j)) != 0) 1290. 			   maybe_tame(mtmp, sobj); 1291. 		   }  1292. 		}  1293. 		break; 1294. 	case SPE_COMMAND_UNDEAD: 1295. 		if (u.uswallow) { 1296. 		   if (is_undead(u.ustuck->data)) maybe_tame(u.ustuck, sobj); 1297. 		} else { 1298. 		   int i, j, bd = confused ? 5 : 1; 1299. 		    struct monst *mtmp; 1300. 1301. 		    for(i = -bd; i <= bd; i++) for(j = -bd; j <= bd; j++) { 1302. 			if (!isok(u.ux + i, u.uy + j)) continue; 1303. 			if ((mtmp = m_at(u.ux + i, u.uy + j)) != 0 && 1304. 				is_undead(mtmp->data)) 1305. 			   maybe_tame(mtmp, sobj); 1306. 		   }  1307. 		}  1308. 		break; 1309. 	case SCR_GENOCIDE: 1310. 		You("have found a scroll of genocide!"); 1311. 		known = TRUE; 1312. 		if (sobj->blessed) do_class_genocide; 1313. 		else do_genocide(!sobj->cursed | (2 * !!Confusion)); 1314. 		break; 1315. 	case SCR_LIGHT: 1316. 		if(!Blind) known = TRUE; 1317. 		litroom(!confused && !sobj->cursed, sobj); 1318. 		break; 1319. 	case SCR_TELEPORTATION: 1320. 		if(confused || sobj->cursed) level_tele; 1321. 		else { 1322. 			if (sobj->blessed && !Teleport_control) { 1323. 				known = TRUE; 1324. 				HTeleport_control = 2; 1325. 				/* if (yn("Do you wish to teleport?")=='n') 1326. 				 *        break; 1327. 				 */ 1328. 			}  1329. 			tele; 1330. 			if(Teleport_control || !couldsee(u.ux0, u.uy0) || 1331. 			   (distu(u.ux0, u.uy0) >= 16)) 1332. 				known = TRUE; 1333. 		} 1334. 		break; 1335. 	case SCR_GOLD_DETECTION: 1336. 		if (confused || sobj->cursed) return(trap_detect(sobj)); 1337. 		else return(gold_detect(sobj)); 1338. 	case SCR_FOOD_DETECTION: 1339. 	case SPE_DETECT_FOOD: 1340. 		if (food_detect(sobj)) 1341. 			return(1);	/* nothing detected */ 1342. 		break; 1343. 	case SPE_IDENTIFY: 1344. 		cval = rn2(5); 1345. 		goto id; 1346. 	case SCR_IDENTIFY: 1347. 		/* known = TRUE; */ 1348. 		if(confused) 1349. 			You("identify this as an identify scroll."); 1350. 		else 1351. 			pline("This is an identify scroll."); 1352. 		if (sobj->blessed || (!sobj->cursed && !rn2(5))) { 1353. 			cval = rn2(5); 1354. 			/* Note: if rn2(5)==0, identify all items */ 1355. 			if (cval == 1 && sobj->blessed && Luck > 0) ++cval; 1356. 		} else	cval = 1; 1357. 		if(!objects[sobj->otyp].oc_name_known) more_experienced(0,10); 1358. 		if (carried(sobj)) useup(sobj); 1359. 		else useupf(sobj, 1L); 1360. 		makeknown(SCR_IDENTIFY); 1361. 	id: 1362. 		if(invent && !confused) { 1363. 		   identify_pack(cval); 1364. 		} 1365. 		return(1); 1366. 	case SCR_CHARGING: 1367. 		if (confused) { 1368. 		   You_feel("charged up!"); 1369. 		   if (u.uen < u.uenmax) 1370. 			u.uen = u.uenmax; 1371. 		   else 1372. 			u.uen = (u.uenmax += d(5,4)); 1373. 		   flags.botl = 1; 1374. 		   break; 1375. 		} 1376. 		known = TRUE; 1377. 		pline("This is a charging scroll."); 1378. 		otmp = getobj(all_count, "charge"); 1379. 		if (!otmp) break; 1380. 		recharge(otmp, sobj->cursed ? -1 : (sobj->blessed ? 1 : 0)); 1381. 		break; 1382. 	case SCR_MAGIC_MAPPING: 1383. 		if (level.flags.nommap) { 1384. 		   Your("mind is filled with crazy lines!"); 1385. 		   if (Hallucination) 1386. 			pline("Wow! Modern art."); 1387. 		   else 1388. 			Your("%s spins in bewilderment.", body_part(HEAD)); 1389. 		   make_confused(HConfusion + rnd(30), FALSE); 1390. 		   break; 1391. 		} 1392. 		if (sobj->blessed) { 1393. 		   register int x, y;  1394. 1395. 		   for (x = 1; x < COLNO; x++) 1396. 		   	for (y = 0; y < ROWNO; y++) 1397. 		   	    if (levl[x][y].typ == SDOOR) 1398. 		   	    	cvt_sdoor_to_door(&levl[x][y]); 1399. 		   /* do_mapping already reveals secret passages */ 1400. 		} 1401. 		known = TRUE; 1402. 	case SPE_MAGIC_MAPPING: 1403. 		if (level.flags.nommap) { 1404. 		   Your("%s spins as %s blocks the spell!", body_part(HEAD), something); 1405. 		   make_confused(HConfusion + rnd(30), FALSE); 1406. 		   break; 1407. 		} 1408. 		pline("A map coalesces in your mind!"); 1409. 		cval = (sobj->cursed && !confused); 1410. 		if(cval) HConfusion = 1;	/* to screw up map */ 1411. 		do_mapping; 1412. 		if (sobj->blessed && !cval) /* objects, too, pal! */ 1413. 		  object_detect(sobj,0); 1414. 		if(cval) { 1415. 		   HConfusion = 0;		/* restore */ 1416. 		   pline("Unfortunately, you can't grasp the details."); 1417. 		} 1418. 		break; 1419. 	case SCR_AMNESIA: 1420. 		known = TRUE; 1421. 		forget(	(!sobj->blessed ? ALL_SPELLS : 0) | 1422. 			(!confused || sobj->cursed ? ALL_MAP : 0) ); 1423. 		if (Hallucination) /* Ommmmmm! */ 1424. 			Your("mind releases itself from mundane concerns."); 1425. 		else if (!strncmpi(plname, "Maud", 4)) 1426. 			pline("As your mind turns inward on itself, you forget everything else."); 1427. 		else if (rn2(2)) 1428. 			pline("Who was that Maud person anyway?"); 1429. 		else 1430. 			pline("Thinking of Maud you forget everything else."); 1431. 		exercise(A_WIS, FALSE); 1432. 		break; 1433. 	case SCR_FIRE: 1434. 		/* 1435. 		 * Note: Modifications have been made as of 3.0 to allow for 1436. 		 * some damage under all potential cases. 1437. 		 */ 1438. 		cval = bcsign(sobj); 1439. 		if(!objects[sobj->otyp].oc_name_known) more_experienced(0,10); 1440. 		if (carried(sobj)) useup(sobj); 1441. 		else useupf(sobj, 1L); 1442. 		makeknown(SCR_FIRE); 1443. 		if(confused) { 1444. 		   if(Fire_resistance) { 1445. 			shieldeff(u.ux, u.uy); 1446. 			if(!Blind) 1447. 			   pline("Oh, look, what a pretty fire in your %s.",  1448. 				makeplural(body_part(HAND))); 1449. 			else You_feel("a pleasant warmth in your %s.", 1450. 				makeplural(body_part(HAND))); 1451. 		   } else { 1452. 			pline_The("scroll catches fire and you burn your %s.", 1453. 				makeplural(body_part(HAND))); 1454. 			losehp(1, "scroll of fire", KILLED_BY_AN); 1455. 		   }  1456. 		    return(1); 1457. 		} 1458. 		if (Underwater) 1459. 			pline_The("water around you vaporizes violently!"); 1460. 		else { 1461. 		   pline_The("scroll erupts in a tower of flame!"); 1462. 		   burn_away_slime; 1463. 		} 1464. 		explode(u.ux, u.uy, ZT_SPELL(ZT_FIRE), (2*(rn1(3, 3) + 2 * cval) + 1)/3,  1465. 							SCROLL_CLASS, EXPL_FIERY); 1466. 		return(1); 1467. 	case SCR_EARTH: 1468. 	   /* TODO: handle steeds */ 1469. 	   if (  1470. #ifdef REINCARNATION  1471. 		!Is_rogue_level(&u.uz) &&  1472. #endif  1473. 	    	 (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) { 1474. 	   	register int x, y;  1475. 1476. 	   	/* Identify the scroll */ 1477. 	   	pline_The("%s rumbles %s you!", ceiling(u.ux,u.uy),  1478. 	    			sobj->blessed ? "around" : "above"); 1479. 	   	known = 1; 1480. 	   	if (In_sokoban(&u.uz)) 1481. 	   	    change_luck(-1);	/* Sokoban guilt */ 1482. 1483. 	    	/* Loop through the surrounding squares */ 1484. 	   	if (!sobj->cursed) for (x = u.ux-1; x <= u.ux+1; x++) { 1485. 	   	    for (y = u.uy-1; y <= u.uy+1; y++) { 1486. 1487. 	    	    	/* Is this a suitable spot? */ 1488. 	    	    	if (isok(x, y) && !closed_door(x, y) &&  1489. 	    	    			!IS_ROCK(levl[x][y].typ) &&  1490. 	    	    			!IS_AIR(levl[x][y].typ) &&  1491. 					(x != u.ux || y != u.uy)) { 1492. 			   register struct obj *otmp2; 1493. 			   register struct monst *mtmp; 1494. 1495. 	    	    	    /* Make the object(s) */ 1496. 	   	    	    otmp2 = mksobj(confused ? ROCK : BOULDER,  1497. 	    	    	    		FALSE, FALSE); 1498. 	   	    	    if (!otmp2) continue;  /* Shouldn't happen */ 1499. 	   	    	    otmp2->quan = confused ? rn1(5,2) : 1; 1500. 	   	    	    otmp2->owt = weight(otmp2); 1501. 1502. 	    	    	    /* Find the monster here (won't be player) */ 1503. 	   	    	    mtmp = m_at(x, y); 1504. 	   	    	    if (mtmp && !amorphous(mtmp->data) &&  1505. 	    	    	    		!passes_walls(mtmp->data) &&  1506. 	    	    	    		!noncorporeal(mtmp->data) &&  1507. 	    	    	    		!unsolid(mtmp->data)) { 1508. 				struct obj *helmet = which_armor(mtmp, W_ARMH); 1509. 				int mdmg; 1510. 1511. 				if (cansee(mtmp->mx, mtmp->my)) { 1512. 				   pline("%s is hit by %s!", Monnam(mtmp),  1513. 	    	    	    			doname(otmp2)); 1514. 				   if (mtmp->minvis && !canspotmon(mtmp)) 1515. 					map_invisible(mtmp->mx, mtmp->my); 1516. 				} 1517. 	    	    	    	mdmg = dmgval(otmp2, mtmp) * otmp2->quan; 1518. 				if (helmet) { 1519. 				   if(is_metallic(helmet)) { 1520. 					if (canspotmon(mtmp)) 1521. 					   pline("Fortunately, %s is wearing a hard helmet.", mon_nam(mtmp)); 1522. 					else if (flags.soundok) 1523. 					   You_hear("a clanging sound."); 1524. 					if (mdmg > 2) mdmg = 2; 1525. 				   } else { 1526. 					if (canspotmon(mtmp)) 1527. 					   pline("%s's %s does not protect %s.",  1528. 						Monnam(mtmp), xname(helmet),  1529. 						mhim(mtmp)); 1530. 				   }  1531. 				}  1532. 	    	    	    	mtmp->mhp -= mdmg; 1533. 	   	    	    	if (mtmp->mhp <= 0) 1534. 	   	    	    	    xkilled(mtmp, 1); 1535. 	   	    	    }  1536. 	    	    	    /* Drop the rock/boulder to the floor */ 1537. 	   	    	    if (!flooreffects(otmp2, x, y, "fall")) { 1538. 	   	    	    	place_object(otmp2, x, y); 1539. 	   	    	    	stackobj(otmp2); 1540. 	   	    	    	newsym(x, y);  /* map the rock */ 1541. 	   	    	    }  1542. 	    	    	}  1543. 		    }  1544. 		}  1545. 		/* Attack the player */ 1546. 		if (!sobj->blessed) { 1547. 		   int dmg; 1548. 		   struct obj *otmp2; 1549. 1550. 		    /* Okay, _you_ write this without repeating the code */ 1551. 		   otmp2 = mksobj(confused ? ROCK : BOULDER,  1552. 				FALSE, FALSE); 1553. 		   if (!otmp2) break; 1554. 		   otmp2->quan = confused ? rn1(5,2) : 1; 1555. 		   otmp2->owt = weight(otmp2); 1556. 		   if (!amorphous(youmonst.data) &&  1557. 				!Passes_walls &&  1558. 				!noncorporeal(youmonst.data) &&  1559. 				!unsolid(youmonst.data)) { 1560. 			You("are hit by %s!", doname(otmp2)); 1561. 			dmg = dmgval(otmp2, &youmonst) * otmp2->quan; 1562. 			if (uarmh && !sobj->cursed) { 1563. 			   if(is_metallic(uarmh)) { 1564. 				pline("Fortunately, you are wearing a hard helmet."); 1565. 				if (dmg > 2) dmg = 2; 1566. 			   } else if (flags.verbose) { 1567. 				Your("%s does not protect you.", 1568. 						xname(uarmh)); 1569. 			   }  1570. 			}  1571. 		    } else 1572. 			dmg = 0; 1573. 		   /* Must be before the losehp, for bones files */ 1574. 		   if (!flooreffects(otmp2, u.ux, u.uy, "fall")) { 1575. 			place_object(otmp2, u.ux, u.uy); 1576. 			stackobj(otmp2); 1577. 			newsym(u.ux, u.uy); 1578. 		   }  1579. 		    if (dmg) losehp(dmg, "scroll of earth", KILLED_BY_AN); 1580. 		} 1581. 	    }  1582. 	    break; 1583. 	case SCR_PUNISHMENT: 1584. 		known = TRUE; 1585. 		if(confused || sobj->blessed) { 1586. 			You_feel("guilty."); 1587. 			break; 1588. 		} 1589. 		punish(sobj); 1590. 		break; 1591. 	case SCR_STINKING_CLOUD: { 1592. 	       coord cc; 1593. 1594. 		You("have found a scroll of stinking cloud!"); 1595. 		known = TRUE; 1596. 		pline("Where do you want to center the cloud?"); 1597. 		cc.x = u.ux; 1598. 		cc.y = u.uy; 1599. 		if (getpos(&cc, TRUE, "the desired position") < 0) { 1600. 		   pline(Never_mind); 1601. 		   return 0; 1602. 		} 1603. 		if (!cansee(cc.x, cc.y) || distu(cc.x, cc.y) >= 32) { 1604. 		   You("smell rotten eggs."); 1605. 		   return 0; 1606. 		} 1607. 		(void) create_gas_cloud(cc.x, cc.y, 3+bcsign(sobj),  1608. 						8+4*bcsign(sobj)); 1609. 		break; 1610. 	} 1611. 	default: 1612. 		impossible("What weird effect is this? (%u)", sobj->otyp); 1613. 	} 1614. 	return(0); 1615. } 1616.  1617. #if 0 1618. static void 1619. wand_explode(obj) 1620. register struct obj *obj; 1621. { 1622.     obj->in_use = TRUE;	/* in case losehp is fatal */ 1623.    Your("%s vibrates violently, and explodes!",xname(obj)); 1624.    nhbell; 1625.    losehp(rnd(2*(u.uhpmax+1)/3), "exploding wand", KILLED_BY_AN); 1626.    useup(obj); 1627.    exercise(A_STR, FALSE); 1628. } 1629. #endif 1630. 1631. /*  1632.  * Low-level lit-field update routine. 1633. */  1634. STATIC_PTR void 1635. set_lit(x,y,val) 1636. int x, y; 1637. genericptr_t val; 1638. { 1639. 	if (val) 1640. 	   levl[x][y].lit = 1; 1641. 	else { 1642. 	   levl[x][y].lit = 0; 1643. 	   snuff_light_source(x, y); 1644. 	} 1645. }  1646.  1647. void 1648. litroom(on,obj) 1649. register boolean on; 1650. struct obj *obj; 1651. { 1652. 	char is_lit;	/* value is irrelevant; we use its address 1653. 			  as a `not null' flag for set_lit */ 1654. 1655. 	/* first produce the text (provided you're not blind) */ 1656. 	if(!on) { 1657. 		register struct obj *otmp; 1658. 1659. 		if (!Blind) { 1660. 		   if(u.uswallow) { 1661. 			pline("It seems even darker in here than before."); 1662. 			return; 1663. 		   }  1664. 		    if (uwep && artifact_light(uwep) && uwep->lamplit) 1665. 			pline("Suddenly, the only light left comes from %s!", 1666. 				the(xname(uwep))); 1667. 		   else 1668. 			You("are surrounded by darkness!"); 1669. 		} 1670.  1671. 		/* the magic douses lamps, et al, too */ 1672. 		for(otmp = invent; otmp; otmp = otmp->nobj) 1673. 		   if (otmp->lamplit) 1674. 			(void) snuff_lit(otmp); 1675. 		if (Blind) goto do_it; 1676. 	} else { 1677. 		if (Blind) goto do_it; 1678. 		if(u.uswallow){ 1679. 			if (is_animal(u.ustuck->data)) 1680. 				pline("%s %s is lit.", 1681. 				        s_suffix(Monnam(u.ustuck)),  1682. 					mbodypart(u.ustuck, STOMACH)); 1683. 			else 1684. 				if (is_whirly(u.ustuck->data)) 1685. 					pline("%s shines briefly.", 1686. 					      Monnam(u.ustuck)); 1687. 				else 1688. 					pline("%s glistens.", Monnam(u.ustuck)); 1689. 			return; 1690. 		} 1691. 		pline("A lit field surrounds you!"); 1692. 	} 1693.  1694. do_it: 1695. 	/* No-op in water - can only see the adjacent squares and that's it! */ 1696. 	if (Underwater || Is_waterlevel(&u.uz)) return; 1697. 	/* 1698. 	 *  If we are darkening the room and the hero is punished but not 1699. 	 * blind, then we have to pick up and replace the ball and chain so  1700. * that we don't remember them if they are out of sight. 1701. 	 */ 1702. 	if (Punished && !on && !Blind) 1703. 	   move_bc(1, 0, uball->ox, uball->oy, uchain->ox, uchain->oy); 1704. 1705. #ifdef REINCARNATION 1706. 	if (Is_rogue_level(&u.uz)) { 1707. 	   /* Can't use do_clear_area because MAX_RADIUS is too small */ 1708. 	   /* rogue lighting must light the entire room */ 1709. 	   int rnum = levl[u.ux][u.uy].roomno - ROOMOFFSET; 1710. 	   int rx, ry; 1711. 	   if(rnum >= 0) { 1712. 		for(rx = rooms[rnum].lx-1; rx <= rooms[rnum].hx+1; rx++) 1713. 		   for(ry = rooms[rnum].ly-1; ry <= rooms[rnum].hy+1; ry++) 1714. 			set_lit(rx, ry, 1715. 				(genericptr_t)(on ? &is_lit : (char *)0)); 1716. 		rooms[rnum].rlit = on; 1717. 	   }  1718. 	    /* hallways remain dark on the rogue level */ 1719. 	} else 1720. #endif 1721. 	   do_clear_area(u.ux,u.uy,  1722. 		obj->oartifact ? 12 :  1723. 		(obj && obj->oclass==SCROLL_CLASS && obj->blessed) ? 9 : 5,  1724. 		set_lit, (genericptr_t)(on ? &is_lit : (char *)0)); 1725. 1726. 	/*  1727. 	 *  If we are not blind, then force a redraw on all positions in sight 1728. 	 * by temporarily blinding the hero. The vision recalculation will 1729. 	 * correctly update all previously seen positions *and* correctly 1730. 	 * set the waslit bit [could be messed up from above]. 1731. 	 */ 1732. 	if (!Blind) { 1733. 	   vision_recalc(2); 1734. 1735. 	    /* replace ball&chain */ 1736. 	   if (Punished && !on) 1737. 		move_bc(0, 0, uball->ox, uball->oy, uchain->ox, uchain->oy); 1738. 	} 1739.  1740. 	vision_full_recalc = 1;	/* delayed vision recalculation */ 1741. } 1742.  1743. static void 1744. do_class_genocide 1745. { 1746. /*WAC adding windowstuff*/ 1747.        winid tmpwin; 1748. 	anything any; 1749.        int n;  1750. menu_item *selected; 1751. 1752. 	int i, j, immunecnt, gonecnt, goodcnt, class, feel_dead = 0; 1753. 	char buf[BUFSZ]; 1754. 	boolean gameover = FALSE;	/* true iff killed self */ 1755. 1756. 	for(j=0; ; j++) { 1757. 		if (j >= 5) { 1758. 			pline(thats_enough_tries); 1759. 			return; 1760. 		} 1761. 		do { 1762.                    getlin("What class of monsters do you wish to genocide? [? for help]",  1763. 			buf); 1764. 		   (void)mungspaces(buf); 1765. 		} while (buf[0]=='\033' || !buf[0]); 1766. 		/* choosing "none" preserves genocideless conduct */ 1767. 		if (!strcmpi(buf, "none") || 1768. 		    !strcmpi(buf, "nothing")) return; 1769. 1770. 		if (strlen(buf) == 1) { 1771. 		   /*WAC adding "help" for those who use graphical displays*/ 1772.                    if (buf[0]=='?'){ 1773.                        tmpwin = create_nhwindow(NHW_MENU); 1774.                        start_menu(tmpwin); 1775.                        any.a_void = 0;         /* zero out all bits */ 1776.                        for (i = 1; i < (MAXMCLASSES - MISCMCLASSES); i++) { 1777.                           any.a_int = i;        /* must be non-zero */ 1778. 			  if (monexplain[i]) 1779. 			      add_menu(tmpwin, NO_GLYPH, &any,  1780. 				   def_monsyms[i], 0, ATR_NONE,  1781. 				   an(monexplain[i]), MENU_UNSELECTED); 1782.                        }  1783.                         end_menu(tmpwin, "Monster Types"); 1784.                        n = 0; 1785.                        while (n == 0) n = select_menu(tmpwin, PICK_ONE,  1786.                                 &selected); 1787.                        destroy_nhwindow(tmpwin); 1788.                        if (n== -1) continue;  /*user hit escape*/ 1789.                        class = selected[0].item.a_int; 1790.                    } else { 1791. 		   if (buf[0] == ILLOBJ_SYM) 1792. 			buf[0] = def_monsyms[S_MIMIC]; 1793. 		   class = def_char_to_monclass(buf[0]); 1794.                    }  1795. 		} else { 1796. 		   char buf2[BUFSZ]; 1797. 1798. 		    class = 0; 1799. 		   Strcpy(buf2, makesingular(buf)); 1800. 		   Strcpy(buf, buf2); 1801. 		} 1802. 		immunecnt = gonecnt = goodcnt = 0; 1803. 		for (i = LOW_PM; i < NUMMONS; i++) { 1804. 		   if (class == 0 &&  1805. 			    strstri(monexplain[(int)mons[i].mlet], buf) != 0) 1806. 			class = mons[i].mlet; 1807. 		   if (mons[i].mlet == class) { 1808. 			if (!(mons[i].geno & G_GENO)) immunecnt++; 1809. 			else if(mvitals[i].mvflags & G_GENOD) gonecnt++; 1810. 			else goodcnt++; 1811. 		   }  1812. 		}  1813. 		/*  1814. 		 * TODO[?]: If user's input doesn't match any class 1815. 		 *	   description, check individual species names. 1816. 		 */ 1817. 		if (!goodcnt && class != mons[urole.malenum].mlet &&  1818. 				class != mons[urace.malenum].mlet) { 1819. 			if (gonecnt) 1820. 	pline("All such monsters are already nonexistent."); 1821. 			else if (immunecnt || 1822. 				(buf[0] == DEF_INVISIBLE && buf[1] == '\0')) 1823. 	You("aren't permitted to genocide such monsters."); 1824. 			else 1825. #ifdef WIZARD	/* to aid in topology testing; remove pesky monsters */ 1826. 			 if (wizard && buf[0] == '*') { 1827. 			   register struct monst *mtmp, *mtmp2; 1828. 1829. 			    gonecnt = 0; 1830. 			   for (mtmp = fmon; mtmp; mtmp = mtmp2) { 1831. 				mtmp2 = mtmp->nmon; 1832. 			   	if (DEADMONSTER(mtmp)) continue; 1833. 				mongone(mtmp); 1834. 				gonecnt++; 1835. 			   }  1836. 	pline("Eliminated %d monster%s.", gonecnt, plur(gonecnt)); 1837. 			   return; 1838. 			} else 1839. #endif 1840. 	pline("That symbol does not represent any monster."); 1841. 			continue; 1842. 		} 1843.  1844. 		for (i = LOW_PM; i < NUMMONS; i++) { 1845. 		   if(mons[i].mlet == class) { 1846. 			char nam[BUFSZ]; 1847. 1848. 			Strcpy(nam, makeplural(mons[i].mname)); 1849. 			/* Although "genus" is Latin for race, the hero benefits 1850. 			 * from both race and role; thus genocide affects either. 1851. 			 */ 1852. 			if (Your_Own_Role(i) || Your_Own_Race(i) ||  1853. 				((mons[i].geno & G_GENO) 1854. 				&& !(mvitals[i].mvflags & G_GENOD))) { 1855. 			/* This check must be first since player monsters might 1856. 			 * have G_GENOD or !G_GENO. 1857. 			 */ 1858. 			    mvitals[i].mvflags |= (G_GENOD|G_NOCORPSE); 1859. 			   reset_rndmonst(i); 1860. 			   kill_genocided_monsters; 1861. 			   update_inventory;		/* eggs & tins */ 1862. 			   pline("Wiped out all %s.", nam); 1863. 			   if (Upolyd && i == u.umonnum) { 1864. 				u.mh = -1; 1865. 				if (Unchanging) { 1866. 				   if (!feel_dead++) You("die."); 1867. 				   /* finish genociding this class of  1868. monsters before ultimately dying */ 1869. 				   gameover = TRUE; 1870. 				} else 1871. 				   rehumanize; 1872. 			   }  1873. 			    /* Self-genocide if it matches either your race 1874. 			      or role. Assumption: male and female forms 1875. 			      share same monster class. */ 1876. 			    if (i == urole.malenum || i == urace.malenum) { 1877. 				u.uhp = -1; 1878. 				if (Upolyd) { 1879. 				   if (!feel_dead++) You_feel("dead inside."); 1880. 				} else { 1881. 				   if (!feel_dead++) You("die."); 1882. 				   gameover = TRUE; 1883. 				} 1884. 			    }  1885. 			} else if (mvitals[i].mvflags & G_GENOD) { 1886. 			   if (!gameover) 1887. 				pline("All %s are already nonexistent.", nam); 1888. 			} else if (!gameover) { 1889. 			 /* suppress feedback about quest beings except 1890. 			    for those applicable to our own role */ 1891. 			 if ((mons[i].msound != MS_LEADER || 1892. 			      quest_info(MS_LEADER) == i)  1893. 			   && (mons[i].msound != MS_NEMESIS || 1894. 			      quest_info(MS_NEMESIS) == i)  1895. 			   && (mons[i].msound != MS_GUARDIAN || 1896. 			      quest_info(MS_GUARDIAN) == i)  1897. 			/* non-leader/nemesis/guardian role-specific monster */  1898. 			   && (i != PM_NINJA ||		/* nuisance */ 1899. 			      Role_if(PM_SAMURAI))) { 1900. 				boolean named, uniq; 1901. 1902. 				named = type_is_pname(&mons[i]) ? TRUE : FALSE; 1903. 				uniq = (mons[i].geno & G_UNIQ) ? TRUE : FALSE; 1904. 				/* one special case */ 1905. 				if (i == PM_HIGH_PRIEST) uniq = FALSE; 1906. 1907. 				You("aren't permitted to genocide %s%s.",  1908. 				    (uniq && !named) ? "the " : "",  1909. 				    (uniq || named) ? mons[i].mname : nam); 1910. 			   }  1911. 			}  1912. 		    }  1913. 		}  1914. 		if (gameover || u.uhp == -1) { 1915. 		   killer_format = KILLED_BY_AN; 1916. 		   killer = "scroll of genocide"; 1917. 		   if (gameover) done(GENOCIDED); 1918. 		} 1919. 		return; 1920. 	} 1921. }  1922.  1923. #define REALLY 1 1924. #define PLAYER 2 1925. #define ONTHRONE 4 1926. void 1927. do_genocide(how) 1928. int how; 1929. /* 0 = no genocide; create monsters (cursed scroll) */ 1930. /* 1 = normal genocide */ 1931. /* 3 = forced genocide of player */ 1932. /* 5 (4 | 1) = normal genocide from throne */ 1933. { 1934. 	char buf[BUFSZ]; 1935. 	register int	i, killplayer = 0; 1936. 	register int mndx; 1937. 	register struct permonst *ptr; 1938. 	const char *which; 1939. 1940. 	if (how & PLAYER) { 1941. 		mndx = u.umonster;	/* non-polymorphed mon num */ 1942. 		ptr = &mons[mndx]; 1943. 		Strcpy(buf, ptr->mname); 1944. 		killplayer++; 1945. 	} else { 1946. 	   for(i = 0; ; i++) { 1947. 		if(i >= 5) { 1948. 		   pline(thats_enough_tries); 1949. 		   return; 1950. 		} 1951. 		getlin("What monster do you want to genocide? [type the name]",  1952. 			buf); 1953. 		(void)mungspaces(buf); 1954. 		/* choosing "none" preserves genocideless conduct */ 1955. 		if (!strcmpi(buf, "none") || !strcmpi(buf, "nothing")) { 1956. 		   /* ... but no free pass if cursed */ 1957. 		   if (!(how & REALLY)) { 1958. 			ptr = rndmonst; 1959. 			if (!ptr) return; /* no message, like normal case */ 1960. 			mndx = monsndx(ptr); 1961. 			break;		/* remaining checks don't apply */ 1962. 		   } else return; 1963. 		} 1964.  1965. 		mndx = name_to_mon(buf); 1966. 		if (mndx == NON_PM || (mvitals[mndx].mvflags & G_GENOD)) { 1967. 			pline("Such creatures %s exist in this world.", 1968. 			      (mndx == NON_PM) ? "do not" : "no longer"); 1969. 			continue; 1970. 		} 1971. 		ptr = &mons[mndx]; 1972. 		/* Although "genus" is Latin for race, the hero benefits 1973. 		 * from both race and role; thus genocide affects either. 1974. 		 */ 1975. 		if (Your_Own_Role(mndx) || Your_Own_Race(mndx)) { 1976. 			killplayer++; 1977. 			break; 1978. 		} 1979. 		if (is_human(ptr)) adjalign(-sgn(u.ualign.type)); 1980. 		if (is_demon(ptr)) adjalign(sgn(u.ualign.type)); 1981. 1982. 		if(!(ptr->geno & G_GENO)) { 1983. 			if(flags.soundok) { 1984. 	/* fixme: unconditional "caverns" will be silly in some circumstances */ 1985. 			   if(flags.verbose) 1986. 			pline("A thunderous voice booms through the caverns:"); 1987. 			   verbalize("No, mortal!  That will not be done."); 1988. 			} 1989. 			continue; 1990. 		} 1991. 		/* KMH -- Unchanging prevents rehumanization */ 1992. 		if (Unchanging && ptr == youmonst.data) 1993. 		   killplayer++; 1994. 		break; 1995. 	   }  1996. 	}  1997.  1998. 	which = "all "; 1999. 	if (Hallucination) { 2000. 	   if (Upolyd) 2001. 		Strcpy(buf,youmonst.data->mname); 2002. 	   else { 2003. 		Strcpy(buf, (flags.female && urole.name.f) ? 2004. 				urole.name.f : urole.name.m); 2005. 		buf[0] = lowc(buf[0]); 2006. 	   }  2007. 	} else { 2008. 	   Strcpy(buf, ptr->mname); /* make sure we have standard singular */ 2009. 	   if ((ptr->geno & G_UNIQ) && ptr != &mons[PM_HIGH_PRIEST]) 2010. 		which = !type_is_pname(ptr) ? "the " : ""; 2011. 	} 2012. 	if (how & REALLY) { 2013. 	   /* setting no-corpse affects wishing and random tin generation */ 2014. 	   mvitals[mndx].mvflags |= (G_GENOD | G_NOCORPSE); 2015. 	   pline("Wiped out %s%s.", which,  2016. 		  (*which != 'a') ? buf : makeplural(buf)); 2017. 2018. 	    if (killplayer) { 2019. 		/* might need to wipe out dual role */ 2020. 		if (urole.femalenum != NON_PM && mndx == urole.malenum) 2021. 		   mvitals[urole.femalenum].mvflags |= (G_GENOD | G_NOCORPSE); 2022. 		if (urole.femalenum != NON_PM && mndx == urole.femalenum) 2023. 		   mvitals[urole.malenum].mvflags |= (G_GENOD | G_NOCORPSE); 2024. 		if (urace.femalenum != NON_PM && mndx == urace.malenum) 2025. 		   mvitals[urace.femalenum].mvflags |= (G_GENOD | G_NOCORPSE); 2026. 		if (urace.femalenum != NON_PM && mndx == urace.femalenum) 2027. 		   mvitals[urace.malenum].mvflags |= (G_GENOD | G_NOCORPSE); 2028. 2029. 		u.uhp = -1; 2030. 		if (how & PLAYER) { 2031. 		   killer_format = KILLED_BY; 2032. 		   killer = "genocidal confusion"; 2033. 		} else if (how & ONTHRONE) { 2034. 		   /* player selected while on a throne */ 2035. 		   killer_format = KILLED_BY_AN; 2036. 		   killer = "imperious order"; 2037. 		} else { /* selected player deliberately, not confused */ 2038. 		   killer_format = KILLED_BY_AN; 2039. 		   killer = "scroll of genocide"; 2040. 		} 2041.  2042. 	/* Polymorphed characters will die as soon as they're rehumanized. */ 2043. 	/* KMH -- Unchanging prevents rehumanization */ 2044. 		if (Upolyd && ptr != youmonst.data) { 2045. 			delayed_killer = killer; 2046. 			killer = 0; 2047. 			You_feel("dead inside."); 2048. 		} else 2049. 			done(GENOCIDED); 2050. 	   } else if (ptr == youmonst.data) { 2051. 		rehumanize; 2052. 	   }  2053. 	    reset_rndmonst(mndx); 2054. 	   kill_genocided_monsters; 2055. 	   update_inventory;	/* in case identified eggs were affected */ 2056. 	} else { 2057. 	   int cnt = 0; 2058. 2059. 	    if (!(mons[mndx].geno & G_UNIQ) &&  2060. 		    !(mvitals[mndx].mvflags & (G_GENOD | G_EXTINCT))) 2061. 		for (i = rn1(3, 4); i > 0; i--) { 2062. 		   if (!makemon(ptr, u.ux, u.uy, NO_MINVENT)) 2063. 			break;	/* couldn't make one */ 2064. 		   ++cnt; 2065. 		   if (mvitals[mndx].mvflags & G_EXTINCT) 2066. 			break;	/* just made last one */ 2067. 		} 2068. 	    if (cnt) 2069. 		pline("Sent in some %s.", makeplural(buf)); 2070. 	   else 2071. 		pline(nothing_happens); 2072. 	} 2073. }  2074.  2075. void 2076. punish(sobj) 2077. register struct obj	*sobj; 2078. { 2079. 	/* KMH -- Punishment is still okay when you are riding */ 2080. 	/* KMH -- Punishment is still okay when you are riding */ 2081. 	You("are being punished for your misbehavior!"); 2082. 	if(Punished){ 2083. 		Your("iron ball gets heavier."); 2084. 		uball->owt += 160 * (1 + sobj->cursed); 2085. 		return; 2086. 	} 2087. 	if (amorphous(youmonst.data) || is_whirly(youmonst.data) || unsolid(youmonst.data)) { 2088. 		pline("A ball and chain appears, then falls away."); 2089. 		dropy(mkobj(BALL_CLASS, TRUE)); 2090. 		return; 2091. 	} 2092. 	setworn(mkobj(CHAIN_CLASS, TRUE), W_CHAIN); 2093. 	setworn(mkobj(BALL_CLASS, TRUE), W_BALL); 2094. 	uball->spe = 1;		/* special ball (see save) */ 2095. 2096. 	/*  2097. 	 *  Place ball & chain if not swallowed. If swallowed, the ball & 2098. 	 * chain variables will be set at the next call to placebc. 2099. 	 */ 2100. 	if (!u.uswallow) { 2101. 	   placebc; 2102. 	   if (Blind) set_bc(1);	/* set up ball and chain variables */ 2103. 	   newsym(u.ux,u.uy);		/* see ball&chain if can't see self */ 2104. 	} 2105. }  2106.  2107. void 2108. unpunish 2109. {	   /* remove the ball and chain */ 2110. 	struct obj *savechain = uchain; 2111. 2112. 	obj_extract_self(uchain); 2113. 	newsym(uchain->ox,uchain->oy); 2114. 	setworn((struct obj *)0, W_CHAIN); 2115. 	dealloc_obj(savechain); 2116. 	uball->spe = 0; 2117. 	setworn((struct obj *)0, W_BALL); 2118. } 2119.  2120. /* some creatures have special data structures that only make sense in their 2121. * normal locations -- if the player tries to create one elsewhere, or to revive 2122. * one, the disoriented creature becomes a zombie 2123. */  2124. boolean 2125. cant_create(mtype, revival) 2126. int *mtype; 2127. boolean revival; 2128. { 2129.  2130. 	/* SHOPKEEPERS can be revived now */ 2131. 	if (*mtype==PM_GUARD || (*mtype==PM_SHOPKEEPER && !revival) 2132. 	     || *mtype==PM_ALIGNED_PRIEST || *mtype==PM_ANGEL) { 2133. 		*mtype = PM_HUMAN_ZOMBIE; 2134. 		return TRUE; 2135. 	} else if (*mtype==PM_LONG_WORM_TAIL) {	/* for create_particular */ 2136. 		*mtype = PM_LONG_WORM; 2137. 		return TRUE; 2138. 	} 2139. 	return FALSE; 2140. } 2141.  2142. #ifdef WIZARD 2143. /* 2144.  * Make a new monster with the type controlled by the user. 2145. *  2146.  * Note:  when creating a monster by class letter, specifying the 2147. * "strange object" (']') symbol produces a random monster rather 2148. * than a mimic; this behavior quirk is useful so don't "fix" it...  2149. */ 2150. struct monst * 2151. create_particular 2152. { 2153. 	char buf[BUFSZ], *bufp, monclass = MAXMCLASSES; 2154. 	int which, tries, i; 2155. struct permonst *whichpm; 2156. 	struct monst *mtmp = (struct monst *)0; 2157. 	boolean maketame, makepeaceful, makehostile; 2158. 2159. 	tries = 0; 2160. 	do { 2161. 	   which = urole.malenum;      /* an arbitrary index into mons[] */ 2162. 	   maketame = makepeaceful = makehostile = FALSE; 2163. 	   getlin("Create what kind of monster? [type the name or symbol]",  2164. 		   buf); 2165. 	   bufp = mungspaces(buf); 2166. 	   if (*bufp == '\033') return (struct monst *)0; 2167. 	   /* allow the initial disposition to be specified */ 2168. 	   if (!strncmpi(bufp, "tame ", 5)) { 2169. 		bufp += 5; 2170. 		maketame = TRUE; 2171. 	   } else if (!strncmpi(bufp, "peaceful ", 9)) { 2172. 		bufp += 9; 2173. 		makepeaceful = TRUE; 2174. 	   } else if (!strncmpi(bufp, "hostile ", 8)) { 2175. 		bufp += 8; 2176. 		makehostile = TRUE; 2177. 	   }  2178. 	    /* decide whether a valid monster was chosen */ 2179. 	   if (strlen(bufp) == 1) { 2180. 		monclass = def_char_to_monclass(*bufp); 2181. 		if (monclass != MAXMCLASSES) break;	/* got one */ 2182. 	   } else { 2183. 		which = name_to_mon(bufp); 2184. 		if (which >= LOW_PM) break;		/* got one */ 2185. 	   }  2186. 	    /* no good; try again... */ 2187. 	    pline("I've never heard of such monsters."); 2188. 	} while (++tries < 5); 2189. 2190. 	if (tries == 5) { 2191. 	   pline(thats_enough_tries); 2192. 	} else { 2193. 	   (void) cant_create(&which, FALSE); 2194. 	   whichpm = &mons[which]; 2195. 	   for (i = 0; i <= multi; i++) { 2196. 		if (monclass != MAXMCLASSES) 2197. 		   whichpm = mkclass(monclass, 0); 2198. 		if (maketame) { 2199. 		   mtmp = makemon(whichpm, u.ux, u.uy, MM_EDOG); 2200. 		   if (mtmp) { 2201. 			initedog(mtmp); 2202. 			set_malign(mtmp); 2203. 		   }  2204. 		} else { 2205. 		   mtmp = makemon(whichpm, u.ux, u.uy, NO_MM_FLAGS); 2206. 		   if ((makepeaceful || makehostile) && mtmp) { 2207. 			mtmp->mtame = 0;       /* sanity precaution */ 2208. 			mtmp->mpeaceful = makepeaceful ? 1 : 0; 2209. 			set_malign(mtmp); 2210. 		   }  2211. 		}  2212. 	    }  2213. 	}  2214. 	return mtmp; 2215. } 2216. #endif /* WIZARD */ 2217. 2218. #endif /* OVLB */ 2219. 2220. /*read.c*/