Source:NetHack 3.3.0/pray.c

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

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

1.   /*	SCCS Id: @(#)pray.c	3.3	1999/11/26	*/ 2.   /* Copyright (c) Benson I. Margulies, Mike Stephenson, Steve Linhart, 1989. */ 3.    /* NetHack may be freely redistributed. See license for details. */ 4.     5.    #include "hack.h"  6.    #include "epri.h"  7. 8.   STATIC_PTR int NDECL(prayer_done); 9.   STATIC_DCL int NDECL(in_trouble); 10.  STATIC_DCL void FDECL(fix_worst_trouble,(int)); 11.  STATIC_DCL void FDECL(angrygods,(ALIGNTYP_P)); 12.  STATIC_DCL void FDECL(pleased,(ALIGNTYP_P)); 13.  STATIC_DCL void FDECL(godvoice,(ALIGNTYP_P,const char*)); 14.  STATIC_DCL void FDECL(god_zaps_you,(ALIGNTYP_P)); 15.  STATIC_DCL void FDECL(fry_by_god,(ALIGNTYP_P)); 16.  STATIC_DCL void FDECL(gods_angry,(ALIGNTYP_P)); 17.  STATIC_DCL void FDECL(gods_upset,(ALIGNTYP_P)); 18.  STATIC_DCL void FDECL(consume_offering,(struct obj *)); 19.  STATIC_DCL boolean FDECL(water_prayer,(BOOLEAN_P)); 20.  STATIC_DCL boolean FDECL(blocked_boulder,(int,int)); 21.   22.   /*  23.    * Logic behind deities and altars and such: 24.   * + prayers are made to your god if not on an altar, and to the altar's god 25.   *   if you are on an altar 26.   * + If possible, your god answers all prayers, which is why bad things happen 27.   *   if you try to pray on another god's altar 28.   * + sacrifices work basically the same way, but the other god may decide to  29. *  accept your allegiance, after which they are your god. If rejected, 30.   *   your god takes over with your punishment. 31.   * + if you're in Gehennom, all messages come from Moloch 32.   */  33.    34.   /*  35.    *	Moloch, who dwells in Gehennom, is the "renegade" cruel god 36.   *	responsible for the theft of the Amulet from Marduk, the Creator. 37.   *	Moloch is unaligned. 38.   */  39.   static const char	*Moloch = "Moloch"; 40.   41.   static const char *godvoices[] = { 42.      "booms out", 43.      "thunders", 44.      "rings out", 45.      "booms", 46.  };  47.    48.   /* values calculated when prayer starts, and used when completed */ 49.  static aligntyp p_aligntyp; 50.  static int p_trouble; 51.  static int p_type; /* (-1)-3: (-1)=really naughty, 3=really good */ 52.   53.   #define PIOUS 20 54.  #define DEVOUT 14 55.  #define FERVENT 9 56.  #define STRIDENT 4 57.   58.   #define TROUBLE_STONED 12 59.  #define TROUBLE_SLIMED 11 60.  #define TROUBLE_STRANGLED 10 61.  #define TROUBLE_LAVA 9 62.  #define TROUBLE_SICK 8 63.  #define TROUBLE_STARVING 7 64.  #define TROUBLE_HIT 6 65.  #define TROUBLE_LYCANTHROPE 5 66.  #define TROUBLE_COLLAPSING 4 67.  #define TROUBLE_STUCK_IN_WALL 3 68.  #define TROUBLE_CURSED_BLINDFOLD 2 69.  #define TROUBLE_CURSED_LEVITATION 1 70.   71.   #define TROUBLE_PUNISHED (-1) 72.  #define TROUBLE_CURSED_ITEMS (-2) 73.  #define TROUBLE_BLIND (-3) 74.  #define TROUBLE_POISONED (-4) 75.  #define TROUBLE_WOUNDED_LEGS (-5) 76.  #define TROUBLE_HUNGRY (-6) 77.  #define TROUBLE_STUNNED (-7) 78.  #define TROUBLE_CONFUSED (-8) 79.  #define TROUBLE_HALLUCINATION (-9) 80.   81.   /* We could force rehumanize of polyselfed people, but we can't tell 82.     unintentional shape changes from the other kind. Oh well. */ 83.    84.   /* Return 0 if nothing particular seems wrong, positive numbers for 85.     serious trouble, and negative numbers for comparative annoyances. This 86.     returns the worst problem. There may be others, and the gods may fix 87.     more than one. 88.   89.   This could get as bizarre as noting surrounding opponents, (or hostile dogs), 90.  but that's really hard. 91.   */  92.    93.   #define ugod_is_angry (u.ualign.record < 0) 94.  #define on_altar	IS_ALTAR(levl[u.ux][u.uy].typ) 95.  #define on_shrine	((levl[u.ux][u.uy].altarmask & AM_SHRINE) != 0) 96.  #define a_align(x,y)	((aligntyp)Amask2align(levl[x][y].altarmask & AM_MASK)) 97.   98.   STATIC_OVL int 99.  in_trouble 100. {  101.  	register struct obj *otmp; 102. 	int i, j, count=0; 103.  104.  /* Borrowed from eat.c */ 105.  106.  #define SATIATED	0 107. #define NOT_HUNGRY	1 108. #define HUNGRY		2 109. #define WEAK		3 110. #define FAINTING	4 111. #define FAINTED		5 112. #define STARVED		6 113.  114.  	if(Stoned) return(TROUBLE_STONED); 115. 	if(Slimed) return(TROUBLE_SLIMED); 116. 	if(Strangled) return(TROUBLE_STRANGLED); 117. 	if(u.utrap && u.utraptype == TT_LAVA) return(TROUBLE_LAVA); 118. 	if(Sick) return(TROUBLE_SICK); 119. 	if(u.uhs >= WEAK) return(TROUBLE_STARVING); 120. 	if (Upolyd ? (u.mh <= 5 || u.mh*7 <= u.mhmax) :  121.  		(u.uhp <= 5 || u.uhp*7 <= u.uhpmax)) return TROUBLE_HIT; 122. 	if(u.ulycn >= LOW_PM) return(TROUBLE_LYCANTHROPE); 123. 	if(near_capacity >= EXT_ENCUMBER && AMAX(A_STR)-ABASE(A_STR) > 3) 124. 		return(TROUBLE_COLLAPSING); 125.  126.  	for (i= -1; i<=1; i++) for(j= -1; j<=1; j++) { 127. 		if (!i && !j) continue; 128. 		if (!isok(u.ux+i, u.uy+j) || IS_ROCK(levl[u.ux+i][u.uy+j].typ)  129.  		    || (blocked_boulder(i,j) && !throws_rocks(youmonst.data))) 130. 			count++; 131. 	}  132.  	if (count == 8 && !Passes_walls) 133. 		return(TROUBLE_STUCK_IN_WALL); 134.  135.  	if((uarmf && uarmf->otyp==LEVITATION_BOOTS && uarmf->cursed) ||  136.  		(uleft && uleft->otyp==RIN_LEVITATION && uleft->cursed) ||  137.  		(uright && uright->otyp==RIN_LEVITATION && uright->cursed)) 138. 		return(TROUBLE_CURSED_LEVITATION); 139. 	if(ublindf && ublindf->cursed) return(TROUBLE_CURSED_BLINDFOLD); 140.  141.  	if(Punished) return(TROUBLE_PUNISHED); 142. 	for(otmp=invent; otmp; otmp=otmp->nobj) 143. 		if((otmp->otyp==LOADSTONE || otmp->otyp==LUCKSTONE) &&  144.  			otmp->cursed) 145. 		    return(TROUBLE_CURSED_ITEMS); 146. 	if((uarmh && uarmh->cursed) ||	/* helmet */  147.  	   (uarms && uarms->cursed) ||	/* shield */  148.  	   (uarmg && uarmg->cursed) ||	/* gloves */  149.  	   (uarm && uarm->cursed) ||	/* armor */  150.  	   (uarmc && uarmc->cursed) ||	/* cloak */  151.  	   (uarmf && uarmf->cursed && uarmf->otyp != LEVITATION_BOOTS) ||  152.  					/* boots */  153.  #ifdef TOURIST  154.  	   (uarmu && uarmu->cursed) ||  /* shirt */  155.  #endif  156.  	   (welded(uwep)) ||  157.  	   (uleft && uleft->cursed && uleft->otyp != RIN_LEVITATION) ||  158.  	   (uright && uright->cursed && uright->otyp != RIN_LEVITATION) ||  159.  	   (uamul && uamul->cursed)) 160. 	    return(TROUBLE_CURSED_ITEMS); 161.  162.  	if(Blinded > 1) return(TROUBLE_BLIND); 163. 	for(i=0; i= HUNGRY) return(TROUBLE_HUNGRY); 167. 	if(HStun) return (TROUBLE_STUNNED); 168. 	if(HConfusion) return (TROUBLE_CONFUSED); 169. 	if(Hallucination) return(TROUBLE_HALLUCINATION); 170.  171.  	return(0); 172. }  173.   174.  const char leftglow[] = "left ring softly glows"; 175. const char rightglow[] = "right ring softly glows"; 176.  177.  STATIC_OVL void 178. fix_worst_trouble(trouble) 179. register int trouble; 180. {  181.  	int i;  182. struct obj *otmp; 183. 	const char *what = (const char *)0; 184.  185.  	switch (trouble) { 186. 	    case TROUBLE_STONED: 187. 		    You_feel("more limber."); 188. 		    Stoned = 0; 189. 		    break; 190. 	    case TROUBLE_SLIMED: 191. 		    pline_The("slime disappears."); 192. 		    Slimed = 0; 193. 		    break; 194. 	    case TROUBLE_STRANGLED: 195. 		    if (uamul && uamul->otyp == AMULET_OF_STRANGULATION) { 196. 			Your("amulet vanishes!"); 197. 			useup(uamul); 198. 		    }  199.  		    You("can breathe again."); 200. 		    Strangled = 0; 201. 		    break; 202. 	    case TROUBLE_LAVA: 203. 		    You("are back on solid ground."); 204. 		    /* teleport should always succeed, but if not, 205. 		     * just untrap them. 206. 		     */  207.  		    if(!safe_teleds) 208. 			u.utrap = 0; 209. 		    break; 210. 	    case TROUBLE_STARVING: 211. 		    losestr(-1); 212. 		    /* fall into... */ 213.  	    case TROUBLE_HUNGRY: 214. 		    Your("stomach feels content."); 215. 		    init_uhunger; 216. 		    flags.botl = 1; 217. 		    break; 218. 	    case TROUBLE_SICK: 219. 		    You_feel("better."); 220. 		    make_sick(0L, (char *) 0, FALSE, SICK_ALL); 221. 		    break; 222. 	    case TROUBLE_HIT: 223. 		    You_feel("much better."); 224. 		    if (Upolyd) u.mh = u.mhmax += rnd(5); 225. 		    if (u.uhpmax < u.ulevel * 5 + 11) u.uhpmax += rnd(5); 226. 		    u.uhp = u.uhpmax; 227. 		    flags.botl = 1; 228. 		    break; 229. 	    case TROUBLE_COLLAPSING: 230. 		    ABASE(A_STR) = AMAX(A_STR); 231. 		    flags.botl = 1; 232. 		    break; 233. 	    case TROUBLE_STUCK_IN_WALL: 234. 		    Your("surroundings change."); 235. 		    /* no control, but works on no-teleport levels */ 236. 		    (void) safe_teleds; 237. 		    break; 238. 	    case TROUBLE_CURSED_LEVITATION: 239. 		    if (uarmf && uarmf->otyp==LEVITATION_BOOTS  240.  						&& uarmf->cursed) 241. 			otmp = uarmf; 242. 		    else if (uleft && uleft->otyp==RIN_LEVITATION  243.  						&& uleft->cursed) { 244. 			otmp = uleft; 245. 			what = leftglow; 246. 		    } else { 247. 			otmp = uright; 248. 			what = rightglow; 249. 		    }  250.  		    goto decurse; 251. 	    case TROUBLE_CURSED_BLINDFOLD: 252. 		    otmp = ublindf; 253. 		    goto decurse; 254. 	    case TROUBLE_LYCANTHROPE: 255. 		    you_unwere(TRUE); 256. 		    break; 257. 	    case TROUBLE_PUNISHED: 258. 		    Your("chain disappears."); 259. 		    unpunish; 260. 		    break; 261. 	    case TROUBLE_CURSED_ITEMS: 262. 		    /* weapon takes precedence if it interferes 263. 		       with taking off a ring or shield */ 264. 		    if (welded(uwep) &&			/* weapon */  265.  			(uright || (bimanual(uwep) && (uleft || uarms)))) 266. 			    otmp = uwep; 267. 		    /* gloves come next, due to rings */ 268. 		    else if (uarmg && uarmg->cursed)	/* gloves */ 269. 			    otmp = uarmg; 270. 		    /* then shield due to two handed weapons and spells */ 271. 		    else if (uarms && uarms->cursed)	/* shield */ 272. 			    otmp = uarms; 273. 		    /* then cloak due to body armor */ 274. 		    else if (uarmc && uarmc->cursed)	/* cloak */ 275. 			    otmp = uarmc; 276. 		    else if (uarm && uarm->cursed)	/* armor */ 277. 			    otmp = uarm; 278. 		    else if (uarmh && uarmh->cursed)	/* helmet */ 279. 			    otmp = uarmh; 280. 		    else if (uarmf && uarmf->cursed)	/* boots */ 281. 			    otmp = uarmf; 282. #ifdef TOURIST 283. 		    else if (uarmu && uarmu->cursed)	/* shirt */ 284. 			    otmp = uarmu; 285. #endif 286. 		    /* (perhaps amulet should take precedence over rings?) */ 287. 		    else if (uleft && uleft->cursed) { 288. 			    otmp = uleft; 289. 			    what = leftglow; 290. 		    } else if (uright && uright->cursed) { 291. 			    otmp = uright; 292. 			    what = rightglow; 293. 		    } else if (uamul && uamul->cursed) /* amulet */ 294. 			    otmp = uamul; 295. 		    /* if weapon wasn't handled above, do it now */ 296. 		    else if (welded(uwep))		/* weapon */ 297. 			    otmp = uwep; 298. 		    else { 299. 			    for(otmp=invent; otmp; otmp=otmp->nobj) 300. 				if ((otmp->otyp==LOADSTONE || 301. 				     otmp->otyp==LUCKSTONE) && otmp->cursed) 302. 					break; 303. 		    }  304.  decurse: 305. 		    uncurse(otmp); 306. 		    otmp->bknown = TRUE; 307. 		    if (!Blind) 308. 			    Your("%s %s.",  309.  				 what ? what :  310.  				 (const char *)aobjnam (otmp, "softly glow"),  311.  				 hcolor(amber)); 312. 		    break; 313. 	    case TROUBLE_POISONED: 314. 		    if (Hallucination) 315. 			pline("There's a tiger in your tank."); 316. 		    else 317. 			You_feel("in good health again."); 318. 		    for(i=0; i<A_MAX; i++) { 319. 			if(ABASE(i) < AMAX(i)) { 320. 				ABASE(i) = AMAX(i); 321. 				flags.botl = 1; 322. 			}  323.  		    }  324.  		    (void) encumber_msg; 325. 		    break; 326. 	    case TROUBLE_BLIND: 327. 		    Your("%s feel better.", makeplural(body_part(EYE))); 328. 		    make_blinded(0L,FALSE); 329. 		    break; 330. 	    case TROUBLE_WOUNDED_LEGS: 331. 		    heal_legs; 332. 		    break; 333. 	    case TROUBLE_STUNNED: 334. 		    make_stunned(0L,TRUE); 335. 		    break; 336. 	    case TROUBLE_CONFUSED: 337. 		    make_confused(0L,TRUE); 338. 		    break; 339. 	    case TROUBLE_HALLUCINATION: 340. 		    pline ("Looks like you are back in Kansas."); 341. 		    make_hallucinated(0L,FALSE,0L); 342. 		    break; 343. 	}  344.  }  345.   346.  /* "I am sometimes shocked by...  the nuns who never take a bath without  347.   * wearing a bathrobe all the time.  When asked why, since no man can see them,  348.   * they reply 'Oh, but you forget the good God'.  Apparently they conceive of  349.   * the Deity as a Peeping Tom, whose omnipotence enables Him to see through  350.   * bathroom walls, but who is foiled by bathrobes." --Bertrand Russell, 1943 351.  * Divine wrath, dungeon walls, and armor follow the same principle. 352.  */  353.  STATIC_OVL void 354. god_zaps_you(resp_god) 355. aligntyp resp_god; 356. {  357.  	if (u.uswallow) { 358. 	    pline("Suddenly a bolt of lightning comes down at you from the heavens!"); 359. 	    pline("It strikes %s!", mon_nam(u.ustuck)); 360. 	    if (!resists_elec(u.ustuck)) { 361. 		pline("%s fries to a crisp!", Monnam(u.ustuck)); 362. 		/* Yup, you get experience. It takes guts to successfully 363. 		 * pull off this trick on your god, anyway. 364. 		 */  365.  		xkilled(u.ustuck, 0); 366. 	    } else 367. 		pline("%s seems unaffected.", Monnam(u.ustuck)); 368. 	} else { 369. 	    pline("Suddenly, a bolt of lightning strikes you!"); 370. 	    if (Reflecting) { 371. 		shieldeff(u.ux, u.uy); 372. 		if (Blind) 373. 		    pline("For some reason you're unaffected."); 374. 		else 375. 		    (void) ureflects("%s reflects from your %s.", "It"); 376. 	    } else if (Shock_resistance) { 377. 		shieldeff(u.ux, u.uy); 378. 		pline("It seems not to affect you."); 379. 	    } else 380. 		fry_by_god(resp_god); 381. 	}  382.   383.  	pline("%s is not deterred...", align_gname(resp_god)); 384. 	if (u.uswallow) { 385. 	    pline("A wide-angle disintegration beam aimed at you hits %s!",  386.  			mon_nam(u.ustuck)); 387. 	    if (!resists_disint(u.ustuck)) { 388. 		pline("%s fries to a crisp!", Monnam(u.ustuck)); 389. 		xkilled(u.ustuck, 2); /* no corpse */ 390. 	    } else 391. 		pline("%s seems unaffected.", Monnam(u.ustuck)); 392. 	} else { 393. 	    pline("A wide-angle disintegration beam hits you!"); 394.  395.  	    /* disintegrate shield and body armor before disintegrating 396. 	     * the impudent mortal, like black dragon breath -3. 397. 	     */  398.  	    if (uarms && !(EReflecting & W_ARMS) &&  399.  	    		!(EDisint_resistance & W_ARMS)) 400. 		(void) destroy_arm(uarms); 401. 	    if (uarmc && !(EReflecting & W_ARMC) &&  402.  	    		!(EDisint_resistance & W_ARMC)) 403. 		(void) destroy_arm(uarmc); 404. 	    if (uarm && !(EReflecting & W_ARM) &&  405.  	    		!(EDisint_resistance & W_ARM) && !uarmc) 406. 		(void) destroy_arm(uarm); 407. #ifdef TOURIST 408. 	    if (uarmu && !uarm && !uarmc) (void) destroy_arm(uarmu); 409. #endif 410. 	    if (!Disint_resistance) 411. 		fry_by_god(resp_god); 412. 	    else { 413. 		You("bask in its %s glow for a minute...", Black); 414. 		godvoice(resp_god, "I believe it not!"); 415. 	    }  416.  	    if (Is_astralevel(&u.uz) || Is_sanctum(&u.uz)) { 417. 		/* one more try for high altars */ 418. 		verbalize("Thou cannot escape my wrath, mortal!"); 419. 		summon_minion(resp_god, FALSE); 420. 		summon_minion(resp_god, FALSE); 421. 		summon_minion(resp_god, FALSE); 422. 		verbalize("Destroy %s, my servants!", him[flags.female]); 423. 	    }  424.  	}  425.  }  426.   427.  STATIC_OVL void 428. fry_by_god(resp_god) 429. aligntyp resp_god; 430. {  431.  	char killerbuf[64]; 432.  433.  	You("fry to a crisp."); 434. 	killer_format = KILLED_BY; 435. 	Sprintf(killerbuf, "the wrath of %s", align_gname(resp_god)); 436. 	killer = killerbuf; 437. 	done(DIED); 438. }  439.   440.  STATIC_OVL void 441. angrygods(resp_god) 442. aligntyp resp_god; 443. {  444.  	register int	maxanger; 445.  446.  	if(Inhell) resp_god = A_NONE; 447. 	u.ublessed = 0; 448.  449.  	/* changed from tmp = u.ugangr + abs (u.uluck) -- rph */ 450. 	/* added test for alignment diff -dlc */ 451. 	if(resp_god != u.ualign.type) 452. 	    maxanger =  u.ualign.record/2 + (Luck > 0 ? -Luck/3 : -Luck); 453. 	else 454. 	    maxanger =  3*u.ugangr + 455. 		((Luck > 0 || u.ualign.record >= STRIDENT) ? -Luck/3 : -Luck); 456. 	if (maxanger < 1) maxanger = 1; /* possible if bad align & good luck */ 457. 	else if (maxanger > 15) maxanger = 15;	/* be reasonable */ 458.  459.  	switch (rn2(maxanger)) { 460. 	    case 0: 461. 	    case 1:	You_feel("that %s is %s.", align_gname(resp_god),  462.  			    Hallucination ? "bummed" : "displeased"); 463. 			break; 464. 	    case 2: 465. 	    case 3: 466. 			godvoice(resp_god,(char *)0); 467. 			pline("\"Thou %s, %s.\"",  468.  			    (ugod_is_angry && resp_god == u.ualign.type)  469.  				? "hast strayed from the path" :  470.  						"art arrogant",  471.  			      youmonst.data->mlet == S_HUMAN ? "mortal" : "creature"); 472. 			verbalize("Thou must relearn thy lessons!"); 473. 			(void) adjattrib(A_WIS, -1, FALSE); 474. 			if (u.ulevel > 1) { 475. 			    losexp; 476. 			    if(u.uhp < 1) u.uhp = 1; 477. 			    if(u.uhpmax < 1) u.uhpmax = 1; 478. 			} else  { 479. 			    u.uexp = 0; 480. 			    flags.botl = 1; 481. 			}  482.  			break; 483. 	    case 6:	if (!Punished) { 484. 			    gods_angry(resp_god); 485. 			    punish((struct obj *)0); 486. 			    break; 487. 			} /* else fall thru */ 488. 	    case 4: 489. 	    case 5:	gods_angry(resp_god); 490. 			if (!Blind && !Antimagic) 491. 			    pline("%s glow surrounds you.",  492.  				  An(hcolor(Black))); 493. 			rndcurse; 494. 			break; 495. 	    case 7: 496. 	    case 8:	godvoice(resp_god,(char *)0); 497. 			verbalize("Thou durst %s me?",  498.  				  (on_altar && 499. 				   (a_align(u.ux,u.uy) != resp_god)) ?  500.  				  "scorn":"call upon"); 501. 			pline("\"Then die, %s!\"",  502.  			      youmonst.data->mlet == S_HUMAN ? "mortal" : "creature"); 503. 			summon_minion(resp_god, FALSE); 504. 			break; 505.  506.  	    default:	gods_angry(resp_god); 507. 			god_zaps_you(resp_god); 508. 			break; 509. 	}  510.  	u.ublesscnt = rnz(300); 511. 	return; 512. }  513.   514.  STATIC_OVL void 515. pleased(g_align) 516. 	aligntyp g_align; 517. {  518.  	int trouble = p_trouble;	/* what's your worst difficulty? */ 519.  	int pat_on_head = 0, kick_on_butt; 520.  521.  	You_feel("that %s is %s.", align_gname(g_align),  522.  	    u.ualign.record >= DEVOUT ?  523.  	    Hallucination ? "pleased as punch" : "well-pleased" :  524.  	    u.ualign.record >= STRIDENT ?  525.  	    Hallucination ? "ticklish" : "pleased" :  526.  	    Hallucination ? "full" : "satisfied"); 527.  528.  	/* not your deity */ 529. 	if (on_altar && p_aligntyp != u.ualign.type) { 530. 		adjalign(-1); 531. 		return; 532. 	} else if (u.ualign.record < 2 && trouble <= 0) adjalign(1); 533.  534.  	/* depending on your luck & align level, the god you prayed to will: 535. 	   - fix your worst problem if it's major. 536. 	   - fix all your major problems. 537. 	   - fix your worst problem if it's minor. 538. 	   - fix all of your problems. 539. 	   - do you a gratuitous favor. 540.  541.  	   if you make it to the the last category, you roll randomly again 542. 	   to see what they do for you. 543.  544.  	   If your luck is at least 0, then you are guaranteed rescued 545. 	   from your worst major problem. */ 546.   547.  	if (!trouble && u.ualign.record >= DEVOUT) pat_on_head = 1; 548. 	else { 549. 	    int action = rn1(on_altar ? 3 + on_shrine : 2, Luck+1); 550.  551.  	    if (!on_altar) action = max(action,2); 552. 	    if (u.ualign.record < STRIDENT) 553. 		action = (u.ualign.record > 0 || !rnl(2)) ? 1 : 0; 554.   555.  	    switch(min(action,5)) { 556. 	    case 5: pat_on_head = 1; 557. 	    case 4: do fix_worst_trouble(trouble); 558. 		    while ((trouble = in_trouble) != 0); 559. 		    break; 560.  561.  	    case 3: fix_worst_trouble(trouble); 562. 	    case 2: while ((trouble = in_trouble) > 0) 563. 		    fix_worst_trouble(trouble); 564. 		    break; 565.  566.  	    case 1: if (trouble > 0) fix_worst_trouble(trouble); 567. 	    case 0: break; /* your god blows you off, too bad */ 568. 	    }  569.  	}  570.   571.      if(pat_on_head) 572. 	switch(rn2((Luck + 6)>>1)) { 573. 	case 0:	break; 574. 	case 1: 575. 	    if (uwep && (welded(uwep) || uwep->oclass == WEAPON_CLASS || 576. 			 is_weptool(uwep))) { 577. 		char repair_buf[BUFSZ]; 578.  579.  		*repair_buf = '\0'; 580. 		if (uwep->oeroded || uwep->oeroded2) 581. 		    Sprintf(repair_buf, " and %s now as good as new",  582.  			    uwep->quan == 1L ? "is" : "are"); 583.  584.  		if (uwep->cursed) { 585. 		    uncurse(uwep); 586. 		    uwep->bknown = TRUE; 587. 		    if (!Blind) 588. 			Your("%s %s%s.", aobjnam(uwep, "softly glow"),  589.  			     hcolor(amber), repair_buf); 590. 		    else You_feel("the power of %s over your %s.",  591.  			u_gname, xname(uwep)); 592. 		    *repair_buf = '\0'; 593. 		} else if (!uwep->blessed) { 594. 		    bless(uwep); 595. 		    uwep->bknown = TRUE; 596. 		    if (!Blind) 597. 			Your("%s with %s aura%s.",  598.  			     aobjnam(uwep, "softly glow"),  599.  			     an(hcolor(light_blue)), repair_buf); 600. 		    else You_feel("the blessing of %s over your %s.",  601.  			u_gname, xname(uwep)); 602. 		    *repair_buf = '\0'; 603. 		}  604.   605.  		/* fix any rust/burn/rot damage, but don't protect 606. 		   against future damage */ 607. 		if (uwep->oeroded || uwep->oeroded2) { 608. 		    uwep->oeroded = uwep->oeroded2 = 0; 609. 		    /* only give this message if we didn't just bless 610. 		       or uncurse (which has already given a message) */ 611. 		    if (*repair_buf) 612. 			Your("%s as good as new!",  613.  			     aobjnam(uwep, Blind ? "feel" : "look")); 614. 		}  615.  	    }  616.  	    break; 617. 	case 3: 618. 	    /* takes 2 hints to get the music to enter the stronghold */ 619. 	    if (flags.soundok && !u.uevent.uopened_dbridge) { 620. 		if(u.uevent.uheard_tune < 1) { 621. 		    godvoice(g_align,(char *)0); 622. 		    verbalize("Hark, %s!",  623.  			  youmonst.data->mlet == S_HUMAN ? "mortal" : "creature"); 624. 		    verbalize(  625.  			"To enter the castle, thou must play the right tune!"); 626. 		    u.uevent.uheard_tune++; 627. 		    break; 628. 		} else if (u.uevent.uheard_tune < 2) { 629. 		    You_hear(Hallucination ? "a funeral march..." : "a divine music..."); 630. 		    pline("It sounds like:  \"%s\".", tune); 631. 		    u.uevent.uheard_tune++; 632. 		    break; 633. 		}  634.  	    }  635.  	    /* Otherwise, falls into next case */ 636. 	case 2: 637. 	    if (!Blind) 638. 		You("are surrounded by %s glow.",  639.  		    an(hcolor(golden))); 640. 	    if (Upolyd) u.mh = u.mhmax += 5; 641. 	    u.uhp = u.uhpmax += 5; 642. 	    ABASE(A_STR) = AMAX(A_STR); 643. 	    if (u.uhunger < 900) init_uhunger; 644. 	    if (u.uluck < 0) u.uluck = 0; 645. 	    make_blinded(0L,TRUE); 646. 	    flags.botl = 1; 647. 	    break; 648. 	case 4: { 649. 	    register struct obj *otmp; 650.  651.  	    if (Blind) 652. 		You_feel("the power of %s.", u_gname); 653. 	    else You("are surrounded by %s aura.",  654.  		     an(hcolor(light_blue))); 655. 	    for(otmp=invent; otmp; otmp=otmp->nobj) { 656. 		if (otmp->cursed) { 657. 		    uncurse(otmp); 658. 		    if (!Blind) { 659. 			Your("%s %s.", aobjnam(otmp, "softly glow"),  660.  			     hcolor(amber)); 661. 			otmp->bknown = TRUE; 662. 		    }  663.  		}  664.  	    }  665.  	    break; 666. 	}  667.  	case 5: { 668. 	    const char *msg="\"and thus I grant thee the gift of %s!\""; 669. 	    godvoice(u.ualign.type, "Thou hast pleased me with thy progress,"); 670. 	    if (!(HTelepat & INTRINSIC))  { 671. 		HTelepat |= FROMOUTSIDE; 672. 		pline(msg, "Telepathy"); 673. 		if (Blind) see_monsters; 674. 	    } else if (!(HFast & INTRINSIC))  { 675. 		HFast |= FROMOUTSIDE; 676. 		pline(msg, "Speed"); 677. 	    } else if (!(HStealth & INTRINSIC))  { 678. 		HStealth |= FROMOUTSIDE; 679. 		pline(msg, "Stealth"); 680. 	    } else { 681. 		if (!(HProtection & INTRINSIC))  { 682. 		    HProtection |= FROMOUTSIDE; 683. 		    if (!u.ublessed)  u.ublessed = rn1(3, 2); 684. 		} else u.ublessed++; 685. 		pline(msg, "my protection"); 686. 	    }  687.  	    verbalize("Use it wisely in my name!"); 688. 	    break; 689. 	}  690.  	case 7: 691. 	case 8: 692. 	case 9:		/* KMH -- can occur during full moons */ 693. #ifdef ELBERETH 694. 	    if (u.ualign.record >= PIOUS && !u.uevent.uhand_of_elbereth) { 695. 		register struct obj *obj = uwep;	/* to be blessed */ 696. 		boolean already_exists, in_hand; 697. 		const char *dropped_item; 698. 		int sp_no; 699.  700.  		HSee_invisible |= FROMOUTSIDE; 701. 		HFire_resistance |= FROMOUTSIDE; 702. 		HCold_resistance |= FROMOUTSIDE; 703. 		HPoison_resistance |= FROMOUTSIDE; 704. 		godvoice(u.ualign.type,(char *)0); 705.  706.  		switch(u.ualign.type) { 707. 		case A_LAWFUL: 708. 		    u.uevent.uhand_of_elbereth = 1; 709. 		    verbalize("I crown thee...      The Hand of Elbereth!"); 710. 		    if (obj && (obj->otyp == LONG_SWORD) && !obj->oartifact) { 711. 			obj = oname(obj, artiname(ART_EXCALIBUR)); 712. 			if (obj && obj->oartifact == ART_EXCALIBUR) u.ugifts++; 713. 		    }  714.  		    /* acquire this skill regardless of weapon */ 715. 		    unrestrict_weapon_skill(P_LONG_SWORD); 716. 		    if (obj && obj->oartifact == ART_EXCALIBUR) 717. 			discover_artifact(ART_EXCALIBUR); 718. 		    break; 719. 		case A_NEUTRAL: 720. 		    u.uevent.uhand_of_elbereth = 2; 721. 		    verbalize("Thou shalt be my Envoy of Balance!"); 722. 		    dropped_item = 0; 723. 		    if (uwep && uwep->oartifact == ART_VORPAL_BLADE) { 724. 			obj = uwep;	/* to be blessed and rustproofed */ 725. 			Your("%s goes snicker-snack!", xname(obj)); 726. 			obj->dknown = TRUE; 727. 		    } else if (Role_if(PM_WIZARD) &&  728.  			    !carrying(SPE_FINGER_OF_DEATH)) { 729. 			obj = mksobj(SPE_FINGER_OF_DEATH, TRUE, FALSE); 730. 			bless(obj); 731. 			for (sp_no = 0; sp_no < MAXSPELL; sp_no++) 732. 			    if (spl_book[sp_no].sp_id == SPE_FINGER_OF_DEATH) { 733. 				/* if spell is already known, enhance weapon */ 734. 				if (uwep) obj = uwep;	/* to be blessed,&c */ 735. 				break; 736. 			    }  737.  			dropped_item = "A spellbook appears"; 738. 		    } else if (!exist_artifact(LONG_SWORD, 739. 					       artiname(ART_VORPAL_BLADE))) { 740. 			obj = mksobj(LONG_SWORD, FALSE, FALSE); 741. 			obj = oname(obj, artiname(ART_VORPAL_BLADE)); 742. 			obj->spe = 1; 743. 			dropped_item = "A sword appears"; 744. 		    }  745.  		    if (dropped_item) { 746. 			if (Blind) dropped_item = "Something lands"; 747. 			pline("%s %s your %s!", dropped_item,  748.  			      Levitation ? "beneath" : "at",  749.  			      makeplural(body_part(FOOT))); 750. 			dropy(obj); 751. 			u.ugifts++; 752. 		    }  753.  		    /* acquire this skill regardless of weapon */ 754. 		    unrestrict_weapon_skill(P_LONG_SWORD); 755. 		    if (obj && obj->oartifact == ART_VORPAL_BLADE) 756. 			discover_artifact(ART_VORPAL_BLADE); 757. 		    break; 758. 		case A_CHAOTIC: 759. 		    u.uevent.uhand_of_elbereth = 3; 760. 		    in_hand = (uwep && uwep->oartifact == ART_STORMBRINGER); 761. 		    already_exists = exist_artifact(RUNESWORD,  762.  						artiname(ART_STORMBRINGER)); 763. 		    verbalize("Thou art chosen to %s for My Glory!",  764.  			      already_exists && !in_hand ?  765.  			      "take lives" : "steal souls"); 766. 		    if (in_hand) { 767. 			obj = uwep;	/* to be blessed and rustproofed */ 768. 		    } else if (!already_exists) { 769. 			obj = mksobj(RUNESWORD, FALSE, FALSE); 770. 			obj = oname(obj, artiname(ART_STORMBRINGER)); 771. 			pline("%s %s %s your %s!", Blind ? Something :  772.  			      An(hcolor(Black)),  773.  			      Blind ? "lands" : "sword appears",  774.  			      Levitation ? "beneath" : "at",  775.  			      makeplural(body_part(FOOT))); 776. 			obj->spe = 1; 777. 			dropy(obj); 778. 			u.ugifts++; 779. 		    }  780.  		    /* acquire this skill regardless of weapon */ 781. 		    unrestrict_weapon_skill(P_BROAD_SWORD); 782. 		    if (obj && obj->oartifact == ART_STORMBRINGER) 783. 			discover_artifact(ART_STORMBRINGER); 784. 		    break; 785. 		default: 786. 		    obj = 0;	/* lint */ 787. 		    break; 788. 		}  789.  		/* enhance weapon regardless of alignment or artifact status */ 790. 		if (obj && (obj->oclass == WEAPON_CLASS || is_weptool(obj))) { 791. 		    bless(obj); 792. 		    obj->oeroded = obj->oeroded2 = 0; 793. 		    obj->oerodeproof = TRUE; 794. 		    obj->bknown = obj->rknown = TRUE; 795. 		    if (obj->spe < 1) obj->spe = 1; 796. 		    /* acquire skill in this weapon */ 797. 		    unrestrict_weapon_skill(weapon_type(obj)); 798. 		} else if (obj && (obj->oclass == SPBOOK_CLASS)) { 799. 		    obj->bknown = TRUE; 800. 		} else	/* opportunity knocked, but there was nobody home... */ 801.  		    You_feel("unworthy."); 802. 		break; 803. 	    }  804.  #endif	/*ELBERETH*/ 805.  806.  	case 6:	{ 807. 	    struct obj *otmp; 808. 	    int sp_no, trycnt = u.ulevel + 1; 809.  810.  	    pline("An object appears at your %s!",  811.  		  makeplural(body_part(FOOT))); 812. 	    /* not yet known spells given preference over already known ones */ 813. 	    otmp = mkobj(SPBOOK_CLASS, TRUE); 814. 	    while (--trycnt > 0) { 815. 		if (otmp->otyp != SPE_BLANK_PAPER) { 816. 		    for (sp_no = 0; sp_no < MAXSPELL; sp_no++) 817. 			if (spl_book[sp_no].sp_id == otmp->otyp) break; 818. 		    if (sp_no == MAXSPELL) break;	/* not yet known */ 819. 		} else { 820. 		    if (!objects[SPE_BLANK_PAPER].oc_name_known ||  821.  			    carrying(MAGIC_MARKER)) break; 822. 		}  823.  		otmp->otyp = rnd_class(bases[SPBOOK_CLASS], SPE_BLANK_PAPER); 824. 	    }  825.  	    bless(otmp); 826. 	    place_object(otmp, u.ux, u.uy); 827. 	    break; 828. 	}  829.  	default:	impossible("Confused deity!"); 830. 	    break; 831. 	}  832.   833.  	u.ublesscnt = rnz(350); 834. 	kick_on_butt = u.uevent.udemigod ? 1 : 0; 835.  #ifdef ELBERETH 836. 	if (u.uevent.uhand_of_elbereth) kick_on_butt++; 837. #endif 838. 	if (kick_on_butt) u.ublesscnt += kick_on_butt * rnz(1000); 839.  840.  	return; 841. }  842.   843.  /* either blesses or curses water on the altar, 844.  * returns true if it found any water here. 845.  */  846.  STATIC_OVL boolean 847. water_prayer(bless_water) 848.     boolean bless_water; 849. {  850.      register struct obj* otmp; 851.     register long changed = 0; 852.     boolean other = FALSE, bc_known = !(Blind || Hallucination); 853.  854.      for(otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) { 855. 	/* turn water into (un)holy water */ 856. 	if (otmp->otyp == POT_WATER && (boolean)otmp->blessed != bless_water) { 857. 	    otmp->blessed = bless_water; 858. 	    otmp->cursed = !bless_water; 859. 	    otmp->bknown = bc_known; 860. 	    changed += otmp->quan; 861. 	} else if(otmp->oclass == POTION_CLASS) 862. 	    other = TRUE; 863.     }  864.      if(!Blind && changed) { 865. 	pline("%s potion%s on the altar glow%s %s for a moment.",  866.  	      ((other && changed > 1L) ? "Some of the" : 867. 					(other ? "One of the" : "The")),  868.  	      ((other || changed > 1L) ? "s" : ""), (changed > 1L ? "" : "s"), 869.  	      (bless_water ? hcolor(light_blue) : hcolor(Black))); 870.     }  871.      return((boolean)(changed > 0L)); 872. }  873.   874.  STATIC_OVL void 875. godvoice(g_align, words) 876.     aligntyp g_align; 877.     const char *words; 878. {  879.      const char *quot = ""; 880.     if(words) 881. 	quot = "\"";  882.      else  883.  	words = "";  884.   885.      pline_The("voice of %s %s: %s%s%s", align_gname(g_align),  886.  	  godvoices[rn2(SIZE(godvoices))], quot, words, quot);  887.  }  888.   889.  STATIC_OVL void  890.  gods_angry(g_align)  891.      aligntyp g_align;  892.  {  893.      godvoice(g_align, "Thou hast angered me.");  894.  }  895.   896.  /* The g_align god is upset with you. */  897.  STATIC_OVL void  898.  gods_upset(g_align)  899.  	aligntyp g_align;  900.  {  901.  	if(g_align == u.ualign.type) u.ugangr++;  902.  	else if(u.ugangr) u.ugangr--;  903.  	angrygods(g_align);  904.  }  905.   906.  static NEARDATA const char sacrifice_types[] = { FOOD_CLASS, AMULET_CLASS, 0 };  907.   908.  STATIC_OVL void  909.  consume_offering(otmp)  910.  register struct obj *otmp;  911.  {  912.      if (Hallucination)  913.  	switch (rn2(3)) {  914.  	    case 0: 915. 		Your("sacrifice sprouts wings and a propeller and roars away!"); 916. 		break; 917. 	    case 1: 918. 		Your("sacrifice puffs up, swelling bigger and bigger, and pops!"); 919. 		break; 920. 	    case 2: 921. 		Your("sacrifice collapses into a cloud of dancing particles and fades away!"); 922. 		break; 923. 	}  924.      else if (Blind && u.ualign.type == A_LAWFUL) 925. 	Your("sacrifice disappears!"); 926.     else Your("sacrifice is consumed in a %s!",  927.  	      u.ualign.type == A_LAWFUL ? "flash of light" : "burst of flame"); 928.     if (carried(otmp)) useup(otmp); 929.     else useupf(otmp, 1L); 930.     exercise(A_WIS, TRUE); 931. }  932.   933.  int 934. dosacrifice 935. {  936.      register struct obj *otmp; 937.     int value = 0; 938.     aligntyp altaralign = a_align(u.ux,u.uy); 939.  940.      if (!on_altar) { 941. 	You("are not standing on an altar."); 942. 	return 0; 943.     }  944.   945.      if (In_endgame(&u.uz)) { 946. 	if (!(otmp = getobj(sacrifice_types, "sacrifice"))) return 0; 947.     } else { 948. 	if (!(otmp = floorfood("sacrifice", 1))) return 0; 949.     }  950.      /*  951.        Was based on nutritional value and aging behavior (< 50 moves). 952.       Sacrificing a food ration got you max luck instantly, making the 953.       gods as easy to please as an angry dog! 954.  955.        Now only accepts corpses, based on the game's evaluation of their 956.       toughness. Human sacrifice, as well as sacrificing unicorns of 957. your alignment, is strongly discouraged. (We can't tell whether 958.        a pet corpse was tame, so you can still sacrifice it.) 959.      */  960.   961.  #define MAXVALUE 24 /* Highest corpse value (besides Wiz) */ 962.  963.      if (otmp->otyp == CORPSE) { 964. 	register struct permonst *ptr = &mons[otmp->corpsenm]; 965. 	extern const int monstr[]; 966.  967.  	/* KMH, conduct */ 968. 	u.uconduct.gnostic++; 969.  970.  	/* you're handling this corpse, even if it was killed upon the altar */ 971. 	feel_cockatrice(otmp, TRUE); 972.  973.  	if (otmp->corpsenm == PM_ACID_BLOB  974.  		|| (monstermoves <= peek_at_iced_corpse_age(otmp) + 50)) { 975. 	    value = monstr[otmp->corpsenm] + 1; 976. 	    if (otmp->oeaten) 977. 		value = eaten_stat(value, otmp); 978. 	}  979.   980.  	if (your_race(ptr)) { 981. 	    if (is_demon(youmonst.data)) { 982. 		You("find the idea very satisfying."); 983. 		exercise(A_WIS, TRUE); 984. 	    } else if (u.ualign.type != A_CHAOTIC) { 985. 		    pline("You'll regret this infamous offense!"); 986. 		    exercise(A_WIS, FALSE); 987. 	    }  988.   989.  	    if (altaralign != A_CHAOTIC && altaralign != A_NONE) { 990. 		/* curse the lawful/neutral altar */ 991. 		pline_The("altar is stained with %s blood.", urace.adj); 992. 		if(!Is_astralevel(&u.uz)) 993. 		    levl[u.ux][u.uy].altarmask = AM_CHAOTIC; 994. 		angry_priest; 995. 	    } else { 996. 		struct monst *dmon; 997. 		const char *demonless_msg; 998.  999.  		/* Human sacrifice on a chaotic or unaligned altar */ 1000. 		/* is equivalent to demon summoning */ 1001. 		if (altaralign == A_CHAOTIC && u.ualign.type != A_CHAOTIC) { 1002. 		   pline(  1003. 		     "The blood floods the altar, which vanishes in %s cloud!",  1004. 			  an(hcolor(Black))); 1005. 		   levl[u.ux][u.uy].typ = ROOM; 1006. 		   levl[u.ux][u.uy].altarmask = 0; 1007. 		   if(Invisible) newsym(u.ux, u.uy); 1008. 		   angry_priest; 1009. 		   demonless_msg = "cloud dissipates"; 1010. 		} else { 1011. 		   /* either you're chaotic or altar is Moloch's or both */ 1012. 		   pline_The("blood covers the altar!"); 1013. 		   change_luck(altaralign == A_NONE ? -2 : 2); 1014. 		   demonless_msg = "blood coagulates"; 1015. 		} 1016. 		if ((dmon = makemon(&mons[dlord(altaralign)],  1017. 						u.ux, u.uy, NO_MM_FLAGS ))) { 1018. 		   You("have summoned %s!", a_monnam(dmon)); 1019. 		   if (sgn(u.ualign.type) == sgn(dmon->data->maligntyp)) 1020. 			dmon->mpeaceful = TRUE; 1021. 		   You("are terrified, and unable to move."); 1022. 		   nomul(-3); 1023. 		} else pline_The("%s.", demonless_msg); 1024. 	   }  1025.  1026. 	    if (u.ualign.type != A_CHAOTIC) { 1027. 		adjalign(-5); 1028. 		u.ugangr += 3; 1029. 		(void) adjattrib(A_WIS, -1, TRUE); 1030. 		if (!Inhell) angrygods(u.ualign.type); 1031. 		change_luck(-5); 1032. 	   } else adjalign(5); 1033. 	   if (carried(otmp)) useup(otmp); 1034. 	   else useupf(otmp, 1L); 1035. 	   return(1); 1036. 	} else if (is_undead(ptr)) { /* Not demons--no demon corpses */ 1037. 	   if (u.ualign.type != A_CHAOTIC) 1038. 		value += 1; 1039. 	} else if (is_unicorn(ptr)) { 1040. 	   int unicalign = sgn(ptr->maligntyp); 1041. 1042. 	    /* If same as altar, always a very bad action. */ 1043. 	    if (unicalign == altaralign) { 1044. 		pline("Such an action is an insult to %s!", 1045. 		      (unicalign == A_CHAOTIC)  1046. 		      ? "chaos" : unicalign ? "law" : "balance"); 1047. 		(void) adjattrib(A_WIS, -1, TRUE); 1048. 		value = -5; 1049. 	   } else if (u.ualign.type == altaralign) { 1050. 		/* If different from altar, and altar is same as yours, */ 1051. 		/* it's a very good action */ 1052. 		if (u.ualign.record < ALIGNLIM) 1053. 		   You_feel("appropriately %s.", align_str(u.ualign.type)); 1054. 		else You_feel("you are thoroughly on the right path."); 1055. 		adjalign(5); 1056. 		value += 3; 1057. 	   } else 1058. 		/* If sacrificing unicorn of your alignment to altar not of */ 1059. 		/* your alignment, your god gets angry and it's a conversion */ 1060. 		if (unicalign == u.ualign.type) { 1061. 		   u.ualign.record = -1; 1062. 		   value = 1; 1063. 		} else value += 3; 1064. 	} 1065.     } /* corpse */ 1066. 1067.     if (otmp->otyp == AMULET_OF_YENDOR) { 1068. 	if (!In_endgame(&u.uz)) { 1069. 	   if (Hallucination) 1070. 		   You_feel("homesick."); 1071. 	   else 1072. 		   You_feel("an urge to return to the surface."); 1073. 	   return 1; 1074. 	} else { 1075. 	   /* The final Test. Did you win? */ 1076. 	    if(uamul == otmp) Amulet_off; 1077. 	   u.uevent.ascended = 1; 1078. 	   if(carried(otmp)) useup(otmp); /* well, it's gone now */ 1079. 	   else useupf(otmp, 1L); 1080. 	   You("offer the Amulet of Yendor to %s...", a_gname); 1081. 	   if (u.ualign.type != altaralign) { 1082. 		/* And the opposing team picks you up and 1083. 		  carries you off on their shoulders */ 1084. 		adjalign(-99); 1085. 		pline("%s accepts your gift, and gains dominion over %s...", 1086. 		      a_gname, u_gname); 1087. 		pline("%s is enraged...", u_gname); 1088. 		pline("Fortunately, %s permits you to live...", a_gname); 1089. 		pline("A cloud of %s smoke surrounds you...", 1090. 		      hcolor((const char *)"orange")); 1091. 		done(ESCAPED); 1092. 	   } else { /* super big win */ 1093. 		adjalign(10); 1094. pline("An invisible choir sings, and you are bathed in radiance..."); 1095. 		godvoice(altaralign, "Congratulations, mortal!"); 1096. 		display_nhwindow(WIN_MESSAGE, FALSE); 1097. verbalize("In return for thy service, I grant thee the gift of Immortality!"); 1098. 		You("ascend to the status of Demigod%s...", 1099. 		    flags.female ? "dess" : ""); 1100. 		done(ASCENDED); 1101. 	   }  1102. 	}  1103.     } /* real Amulet */ 1104. 1105.     if (otmp->otyp == FAKE_AMULET_OF_YENDOR) { 1106. 	   if (flags.soundok) 1107. 		You_hear("a nearby thunderclap."); 1108. 	   if (!otmp->known) { 1109. 		You("realize you have made a %s.", 1110. 		    Hallucination ? "boo-boo" : "mistake"); 1111. 		otmp->known = TRUE; 1112. 		change_luck(-1); 1113. 		return 1; 1114. 	   } else { 1115. 		/* don't you dare try to fool the gods */ 1116. 		change_luck(-3); 1117. 		adjalign(-1); 1118. 		u.ugangr += 3; 1119. 		value = -3; 1120. 	   }  1121.     } /* fake Amulet */ 1122. 1123.     if (value == 0) { 1124. 	pline(nothing_happens); 1125. 	return (1); 1126.    }  1127.  1128.     if (altaralign != u.ualign.type &&  1129. 	(Is_astralevel(&u.uz) || Is_sanctum(&u.uz))) { 1130. 	/* 1131. 	 * REAL BAD NEWS!!! High altars cannot be converted. Even an attempt 1132. 	 * gets the god who owns it truely pissed off. 1133. 	 */ 1134. 	You_feel("the air around you grow charged..."); 1135. 	pline("Suddenly, you realize that %s has noticed you...", a_gname); 1136. 	godvoice(altaralign, "So, mortal! You dare desecrate my High Temple!"); 1137. 	/* Throw everything we have at the player */ 1138. 	god_zaps_you(altaralign); 1139.    } else if (value < 0) { /* I don't think the gods are gonna like this... */ 1140. 	gods_upset(altaralign); 1141.    } else { 1142. 	int saved_anger = u.ugangr; 1143. 	int saved_cnt = u.ublesscnt; 1144. 	int saved_luck = u.uluck; 1145. 1146. 	/* Sacrificing at an altar of a different alignment */ 1147. 	if (u.ualign.type != altaralign) { 1148. 	   /* Is this a conversion ? */ 1149. 	    /* An unaligned altar in Gehennom will always elicit rejection. */ 1150. 	    if (ugod_is_angry || (altaralign == A_NONE && Inhell)) { 1151. 		if(u.ualignbase[0] == u.ualignbase[1] && 1152. 		   altaralign != A_NONE) { 1153. 		   You("have a strong feeling that %s is angry...", u_gname); 1154. 		   consume_offering(otmp); 1155. 		   pline("%s accepts your allegiance.", a_gname); 1156. 1157. 		    /* The player wears a helm of opposite alignment? */ 1158. 		    if (uarmh && uarmh->otyp == HELM_OF_OPPOSITE_ALIGNMENT) 1159. 			u.ualignbase[0] = altaralign; 1160. 		   else 1161. 			u.ualign.type = u.ualignbase[0] = altaralign; 1162. 		   u.ublessed = 0; 1163. 		   flags.botl = 1; 1164. 1165. 		    You("have a sudden sense of a new direction."); 1166. 		   /* Beware, Conversion is costly */ 1167. 		   change_luck(-3); 1168. 		   u.ublesscnt += 300; 1169. 		   adjalign((int)(u.ualignbase[1] * (ALIGNLIM / 2))); 1170. 		} else { 1171. 		   u.ugangr += 3; 1172. 		   adjalign(-5); 1173. 		   pline("%s rejects your sacrifice!", a_gname); 1174. 		   godvoice(altaralign, "Suffer, infidel!"); 1175. 		   change_luck(-5); 1176. 		   (void) adjattrib(A_WIS, -2, TRUE); 1177. 		   if (!Inhell) angrygods(u.ualign.type); 1178. 		} 1179. 		return(1); 1180. 	   } else { 1181. 		consume_offering(otmp); 1182. 		You("sense a conflict between %s and %s.", 1183. 		    u_gname, a_gname); 1184. 		if (rn2(8 + u.ulevel) > 5) { 1185. 		   struct monst *pri; 1186. 		   You_feel("the power of %s increase.", u_gname); 1187. 		   exercise(A_WIS, TRUE); 1188. 		   change_luck(1); 1189. 		   /* Yes, this is supposed to be &=, not |= */ 1190. 		   levl[u.ux][u.uy].altarmask &= AM_SHRINE; 1191. 		   /* the following accommodates stupid compilers */ 1192. 		   levl[u.ux][u.uy].altarmask = 1193. 			levl[u.ux][u.uy].altarmask | (Align2amask(u.ualign.type)); 1194. 		   if (!Blind) 1195. 			pline_The("altar glows %s.", 1196. 			      hcolor( 1197. 			     u.ualign.type == A_LAWFUL ? White : 1198. 			     u.ualign.type ? Black : (const char *)"gray")); 1199. 1200. 		    if (rnl(u.ulevel) > 6 && u.ualign.record > 0 &&  1201. 		       rnd(u.ualign.record) > (3*ALIGNLIM)/4) 1202. 			summon_minion(altaralign, TRUE); 1203. 		   /* anger priest; test handles bones files */ 1204. 		   if((pri = findpriest(temple_occupied(u.urooms))) &&  1205. 		       !p_coaligned(pri)) 1206. 			angry_priest; 1207. 		} else { 1208. 		   pline("Unluckily, you feel the power of %s decrease.",  1209. 			  u_gname); 1210. 		   change_luck(-1); 1211. 		   exercise(A_WIS, FALSE); 1212. 		   if (rnl(u.ulevel) > 6 && u.ualign.record > 0 &&  1213. 		       rnd(u.ualign.record) > (7*ALIGNLIM)/8) 1214. 			summon_minion(altaralign, TRUE); 1215. 		} 1216. 		return(1); 1217. 	   }  1218. 	}  1219.  1220. 	consume_offering(otmp); 1221. 	/* OK, you get brownie points. */ 1222. 	if(u.ugangr) { 1223. 	   u.ugangr -= 1224. 		((value * (u.ualign.type == A_CHAOTIC ? 2 : 3)) / MAXVALUE); 1225. 	   if(u.ugangr < 0) u.ugangr = 0; 1226. 	   if(u.ugangr != saved_anger) { 1227. 		if (u.ugangr) { 1228. 		   pline("%s seems %s.", u_gname,  1229. 			  Hallucination ? "groovy" : "slightly mollified"); 1230. 1231. 		    if ((int)u.uluck < 0) change_luck(1); 1232. 		} else { 1233. 		   pline("%s seems %s.", u_gname, Hallucination ?  1234. 			  "cosmic (not a new fact)" : "mollified"); 1235. 1236. 		    if ((int)u.uluck < 0) u.uluck = 0; 1237. 		} 1238. 	    } else { /* not satisfied yet */ 1239. 		if (Hallucination) 1240. 		   pline_The("gods seem tall."); 1241. 		else You("have a feeling of inadequacy."); 1242. 	   }  1243. 	} else if(ugod_is_angry) { 1244. 	   if(value > MAXVALUE) value = MAXVALUE; 1245. 	   if(value > -u.ualign.record) value = -u.ualign.record; 1246. 	   adjalign(value); 1247. 	   You_feel("partially absolved."); 1248. 	} else if (u.ublesscnt > 0) { 1249. 	   u.ublesscnt -= 1250. 		((value * (u.ualign.type == A_CHAOTIC ? 500 : 300)) / MAXVALUE); 1251. 	   if(u.ublesscnt < 0) u.ublesscnt = 0; 1252. 	   if(u.ublesscnt != saved_cnt) { 1253. 		if (u.ublesscnt) { 1254. 		   if (Hallucination) 1255. 			You("realize that the gods are not like you and I."); 1256. 		   else 1257. 			You("have a hopeful feeling."); 1258. 		   if ((int)u.uluck < 0) change_luck(1); 1259. 		} else { 1260. 		   if (Hallucination) 1261. 			pline("Overall, there is a smell of fried onions."); 1262. 		   else 1263. 			You("have a feeling of reconciliation."); 1264. 		   if ((int)u.uluck < 0) u.uluck = 0; 1265. 		} 1266. 	    }  1267. 	} else { 1268. 	   int nartifacts = nartifact_exist; 1269. 1270. 	    /* you were already in pretty good standing */ 1271. 	   /* The player can gain an artifact */ 1272. 	   /* The chance goes down as the number of artifacts goes up */ 1273. 	   if (u.ulevel > 2 && !rn2(10 + (2 * u.ugifts * nartifacts))) { 1274. 		otmp = mk_artifact((struct obj *)0, a_align(u.ux,u.uy)); 1275. 		if (otmp) { 1276. 		   if (otmp->spe < 0) otmp->spe = 0; 1277. 		   if (otmp->cursed) uncurse(otmp); 1278. 		   dropy(otmp); 1279. 		   pline("An object appears at your %s!",  1280. 			  makeplural(body_part(FOOT))); 1281. 		   godvoice(u.ualign.type, "Use my gift wisely!"); 1282. 		   u.ugifts++; 1283. 		   u.ublesscnt = rnz(300 + (50 * nartifacts)); 1284. 		   exercise(A_WIS, TRUE); 1285. 		   /* make sure we can use this weapon */ 1286. 		   unrestrict_weapon_skill(weapon_type(otmp)); 1287. 		   discover_artifact(otmp->oartifact); 1288. 		   return(1); 1289. 		} 1290. 	    }  1291. 	    change_luck((value * LUCKMAX) / (MAXVALUE * 2)); 1292. 	   if (u.uluck != saved_luck) { 1293. 		if (Blind) 1294. 		   You("think %s brushed your %s.",something, body_part(FOOT)); 1295. 		else You(Hallucination ? 1296. 		    "see crabgrass at your %s.  A funny thing in a dungeon." :  1297. 		    "glimpse a four-leaf clover at your %s.",  1298. 		    makeplural(body_part(FOOT))); 1299. 	   }  1300. 	}  1301.     }  1302.     return(1); 1303. } 1304.  1305.  1306. /* determine prayer results in advance; also used for enlightenment */ 1307. boolean 1308. can_pray(praying) 1309. boolean praying;	/* false means no messages should be given */ 1310. { 1311.     int alignment; 1312. 1313.     p_aligntyp = on_altar ? a_align(u.ux,u.uy) : u.ualign.type; 1314.    p_trouble = in_trouble; 1315. 1316.     if (is_demon(youmonst.data) && (p_aligntyp != A_CHAOTIC)) { 1317. 	if (praying) 1318. 	   pline_The("very idea of praying to a %s god is repugnant to you.",  1319. 		  p_aligntyp ? "lawful" : "neutral"); 1320. 	return FALSE; 1321.    }  1322.  1323.     if (praying) 1324. 	You("begin praying to %s.", align_gname(p_aligntyp)); 1325. 1326.     if (u.ualign.type && u.ualign.type == -p_aligntyp) 1327. 	alignment = -u.ualign.record;		/* Opposite alignment altar */ 1328.    else if (u.ualign.type != p_aligntyp) 1329. 	alignment = u.ualign.record / 2;	/* Different alignment altar */ 1330.    else alignment = u.ualign.record; 1331. 1332.     if ((p_trouble > 0) ? (u.ublesscnt > 200) : /* big trouble */  1333. 	(p_trouble < 0) ? (u.ublesscnt > 100) : /* minor difficulties */  1334. 	(u.ublesscnt > 0))			/* not in trouble */ 1335. 	p_type = 0;		/* too soon... */ 1336.     else if ((int)Luck < 0 || u.ugangr || alignment < 0) 1337. 	p_type = 1;		/* too naughty... */ 1338.     else /* alignment >= 0 */ { 1339. 	if(on_altar && u.ualign.type != p_aligntyp) 1340. 	   p_type = 2; 1341. 	else 1342. 	   p_type = 3; 1343.    }  1344.  1345.     if (is_undead(youmonst.data) && !Inhell &&  1346. 	(p_aligntyp == A_LAWFUL || (p_aligntyp == A_NEUTRAL && !rn2(10)))) 1347. 	p_type = -1; 1348.    /* Note:  when !praying, the random factor for neutrals makes the 1349.       return value a non-deterministic approximation for enlightenment. 1350.       This case should be uncommon enough to live with... */ 1351.  1352.     return !praying ? (boolean)(p_type == 3 && !Inhell) : TRUE; 1353. } 1354.  1355. int 1356. dopray 1357. { 1358. 	/* Confirm accidental slips of Alt-P */ 1359. 	if (flags.prayconfirm) 1360. 		if (yn("Are you sure you want to pray?") == 'n') 1361. 			return (0); 1362. 	u.uconduct.gnostic++; 1363. 1364.     /* set up p_type and p_alignment */ 1365.    if (!can_pray(TRUE)) return 0; 1366. 1367. #ifdef WIZARD 1368.    if (wizard && p_type >= 0) { 1369. 	if (yn("Force the gods to be pleased?") == 'y') { 1370. 	   u.ublesscnt = 0; 1371. 	   if (u.uluck < 0) u.uluck = 0; 1372. 	   if (u.ualign.record <= 0) u.ualign.record = 1; 1373. 	   u.ugangr = 0; 1374. 	   if(p_type < 2) p_type = 3; 1375. 	} 1376.     }  1377. #endif 1378.    nomul(-3); 1379.    nomovemsg = "You finish your prayer."; 1380.    afternmv = prayer_done; 1381. 1382.     if(p_type == 3 && !Inhell) { 1383. 	/* if you've been true to your god you can't die while you pray */ 1384. 	if (!Blind) 1385. 	   You("are surrounded by a shimmering light."); 1386. 	u.uinvulnerable = TRUE; 1387.    }  1388.  1389.     return(1); 1390. } 1391.  1392. STATIC_PTR int 1393. prayer_done		/* M. Stephenson (1.0.3b) */ 1394. { 1395.     aligntyp alignment = p_aligntyp; 1396. 1397.     u.uinvulnerable = FALSE; 1398.    if(p_type == -1) { 1399. 	godvoice(alignment, 1400. 		 alignment == A_LAWFUL ?  1401. 		 "Vile creature, thou durst call upon me?" :  1402. 		 "Walk no more, perversion of nature!"); 1403. 	You_feel("like you are falling apart."); 1404. 	/* KMH -- Gods have mastery over unchanging */ 1405. 	rehumanize; 1406. 	losehp(rnd(20), "residual undead turning effect", KILLED_BY_AN); 1407. 	exercise(A_CON, FALSE); 1408. 	return(1); 1409.    }  1410.     if (Inhell) { 1411. 	pline("Since you are in Gehennom, %s won't help you.", 1412. 	      align_gname(alignment)); 1413. 	/* haltingly aligned is least likely to anger */ 1414. 	if (u.ualign.record <= 0 || rnl(u.ualign.record)) 1415. 	   angrygods(u.ualign.type); 1416. 	return(0); 1417.    }  1418.  1419.     if (p_type == 0) { 1420. 	if(on_altar && u.ualign.type != alignment) 1421. 	   (void) water_prayer(FALSE); 1422. 	u.ublesscnt += rnz(250); 1423. 	change_luck(-3); 1424. 	gods_upset(u.ualign.type); 1425.    } else if(p_type == 1) { 1426. 	if(on_altar && u.ualign.type != alignment) 1427. 	   (void) water_prayer(FALSE); 1428. 	angrygods(u.ualign.type);	/* naughty */ 1429.    } else if(p_type == 2) { 1430. 	if(water_prayer(FALSE)) { 1431. 	   /* attempted water prayer on a non-coaligned altar */ 1432. 	   u.ublesscnt += rnz(250); 1433. 	   change_luck(-3); 1434. 	   gods_upset(u.ualign.type); 1435. 	} else pleased(alignment); 1436.    } else { 1437. 	/* coaligned */ 1438. 	if(on_altar) 1439. 	   (void) water_prayer(TRUE); 1440. 	pleased(alignment); /* nice */ 1441.    }  1442.     return(1); 1443. } 1444.  1445. int 1446. doturn 1447. {	/* Knights & Priest(esse)s only please */ 1448. 1449. 	struct monst *mtmp, *mtmp2; 1450. 	int once, range, xlev; 1451. 1452. 	if (!Role_if(PM_PRIEST) && !Role_if(PM_KNIGHT)) { 1453. 		/* Try to use turn undead spell. */ 1454. 		if (objects[SPE_TURN_UNDEAD].oc_name_known) { 1455. 		   register int sp_no; 1456. 		   for (sp_no = 0; sp_no < MAXSPELL &&  1457. 			 spl_book[sp_no].sp_id != NO_SPELL &&  1458. 			 spl_book[sp_no].sp_id != SPE_TURN_UNDEAD; sp_no++); 1459. 1460. 		    if (sp_no < MAXSPELL &&  1461. 			spl_book[sp_no].sp_id == SPE_TURN_UNDEAD) 1462. 			   return spelleffects(sp_no, TRUE); 1463. 		} 1464.  1465. 		You("don't know how to turn undead!"); 1466. 		return(0); 1467. 	} 1468. 	if ((u.ualign.type != A_CHAOTIC && 1469. 		   (is_demon(youmonst.data) || is_undead(youmonst.data))) ||  1470. 				u.ugangr > 6 /* "Die, mortal!" */) { 1471. 1472. 		pline("For some reason, %s seems to ignore you.", u_gname); 1473. 		aggravate; 1474. 		exercise(A_WIS, FALSE); 1475. 		return(0); 1476. 	} 1477.  1478. 	if (Inhell) { 1479. 	   pline("Since you are in Gehennom, %s won't help you.", u_gname); 1480. 	   aggravate; 1481. 	   return(0); 1482. 	} 1483. 	pline("Calling upon %s, you chant an arcane formula.", u_gname); 1484. 	exercise(A_WIS, TRUE); 1485. 1486. 	/* note: does not perform unturn_dead on victims' inventories */ 1487. 	range = BOLT_LIM + (u.ulevel / 5);	/* 5 to 11 */ 1488. 	range *= range; 1489. 	once = 0; 1490. 	for(mtmp = fmon; mtmp; mtmp = mtmp2) { 1491. 	   mtmp2 = mtmp->nmon; 1492. 	   if (!cansee(mtmp->mx,mtmp->my) ||  1493. 		distu(mtmp->mx,mtmp->my) > range) continue; 1494. 1495. 	    if (!mtmp->mpeaceful && (is_undead(mtmp->data) || 1496. 		  (is_demon(mtmp->data) && (u.ulevel > (MAXULEV/2))))) { 1497. 1498. 		    mtmp->msleeping = 0; 1499. 		   if (Confusion) { 1500. 			if (!once++) 1501. 			   pline("Unfortunately, your voice falters."); 1502. 			mtmp->mflee = 0; 1503. 			mtmp->mfrozen = 0; 1504. 			mtmp->mcanmove = 1; 1505. 		   } else if (!resist(mtmp, '\0', 0, TELL)) { 1506. 			xlev = 6; 1507. 			switch (mtmp->data->mlet) { 1508. 			   /* this is intentional, lichs are tougher 1509. 			      than zombies. */ 1510. 			case S_LICH:    xlev += 2; 1511. 			case S_GHOST:  xlev += 2; 1512. 			case S_VAMPIRE: xlev += 2; 1513. 			case S_WRAITH: xlev += 2; 1514. 			case S_MUMMY:  xlev += 2; 1515. 			case S_ZOMBIE: 1516. 			   mtmp->mflee = 1;	/* at least */ 1517. 			   if(u.ulevel >= xlev &&  1518. 			       !resist(mtmp, '\0', 0, NOTELL)) { 1519. 				if(u.ualign.type == A_CHAOTIC) { 1520. 				   mtmp->mpeaceful = 1; 1521. 				} else { /* damn them */ 1522. 				   killed(mtmp); 1523. 				} 1524. 			    }  1525. 			    break; 1526. 			default:   mtmp->mflee = 1; 1527. 			   break; 1528. 			} 1529. 		    }  1530. 	    }  1531. 	}  1532. 	nomul(-5); 1533. 	return(1); 1534. } 1535.  1536. const char * 1537. a_gname 1538. { 1539.     return(a_gname_at(u.ux, u.uy)); 1540. } 1541.  1542. const char * 1543. a_gname_at(x,y)    /* returns the name of an altar's deity */ 1544. xchar x, y; 1545. { 1546.     if(!IS_ALTAR(levl[x][y].typ)) return((char *)0); 1547. 1548.     return align_gname(a_align(x,y)); 1549. } 1550.  1551. const char * 1552. u_gname /* returns the name of the player's deity */ 1553. { 1554.     return align_gname(u.ualign.type); 1555. } 1556.  1557. const char * 1558. align_gname(alignment) 1559. aligntyp alignment; 1560. { 1561.     const char *gnam; 1562. 1563.     switch (alignment) { 1564.     case A_NONE:	gnam = Moloch; break; 1565.     case A_LAWFUL:	gnam = urole.lgod; break; 1566.     case A_NEUTRAL:	gnam = urole.ngod; break; 1567.     case A_CHAOTIC:	gnam = urole.cgod; break; 1568.     default:		impossible("unknown alignment."); 1569. 			gnam = "someone"; break; 1570.    }  1571.     if (*gnam == '_') ++gnam; 1572.    return gnam; 1573. } 1574.  1575. /* hallucination handling for priest/minion names: select a random god 1576.   iff character is hallucinating */ 1577. const char * 1578. halu_gname(alignment) 1579. aligntyp alignment; 1580. { 1581.     const char *gnam; 1582.    int which; 1583. 1584.     if (!Hallucination) return align_gname(alignment); 1585. 1586.     which = randrole; 1587.    switch (rn2(3)) { 1588.     case 0:	gnam = roles[which].lgod; break; 1589.     case 1:	gnam = roles[which].ngod; break; 1590.     case 2:	gnam = roles[which].cgod; break; 1591.     default:	gnam = 0; break;		/* lint suppression */ 1592.    }  1593.     if (!gnam) gnam = Moloch; 1594.    if (*gnam == '_') ++gnam; 1595.    return gnam; 1596. } 1597.  1598. /* deity's title */ 1599. const char * 1600. align_gtitle(alignment) 1601. aligntyp alignment; 1602. { 1603.     const char *gnam, *result = "god"; 1604. 1605.     switch (alignment) { 1606.     case A_LAWFUL:	gnam = urole.lgod; break; 1607.     case A_NEUTRAL:	gnam = urole.ngod; break; 1608.     case A_CHAOTIC:	gnam = urole.cgod; break; 1609.     default:		gnam = 0; break; 1610.    }  1611.     if (gnam && *gnam == '_') result = "goddess"; 1612.    return result; 1613. } 1614.  1615. void 1616. altar_wrath(x, y) 1617. register int x, y; 1618. { 1619.     aligntyp altaralign = a_align(x,y); 1620. 1621.     if(!strcmp(align_gname(altaralign), u_gname)) { 1622. 	godvoice(altaralign, "How darest thou desecrate my altar!"); 1623. 	(void) adjattrib(A_WIS, -1, FALSE); 1624.    } else { 1625. 	pline("A voice (could it be %s?) whispers:", 1626. 	      align_gname(altaralign)); 1627. 	verbalize("Thou shalt pay, infidel!"); 1628. 	change_luck(-1); 1629.    }  1630. }  1631.  1632. /* assumes is_ok at one space away, but not necessarily at two */ 1633. STATIC_OVL boolean 1634. blocked_boulder(dx,dy) 1635. int dx,dy; 1636. { 1637.     register struct obj *otmp; 1638.    long count = 0L; 1639. 1640.     for(otmp = level.objects[u.ux+dx][u.uy+dy]; otmp; otmp = otmp->nexthere) { 1641. 	if(otmp->otyp == BOULDER) 1642. 	   count += otmp->quan; 1643.    }  1644.  1645.     switch(count) { 1646. 	case 0: return FALSE; /* no boulders--not blocked */ 1647. 	case 1: break; /* possibly blocked depending on if it's pushable */ 1648. 	default: return TRUE; /* >1 boulder--blocked after they push the top 1649. 	   one; don't force them to push it first to find out */ 1650.    }  1651.  1652.     if (!isok(u.ux+2*dx, u.uy+2*dy)) 1653. 	return TRUE; 1654.    if (IS_ROCK(levl[u.ux+2*dx][u.uy+2*dy].typ)) 1655. 	return TRUE; 1656.    if (sobj_at(BOULDER, u.ux+2*dx, u.uy+2*dy)) 1657. 	return TRUE; 1658. 1659.     return FALSE; 1660. } 1661.  1662. /*pray.c*/