Source:NetHack 3.2.0/pray.c

From NetHackWiki
(Redirected from NetHack 3.2.0/pray.c)
Jump to navigation Jump to search

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

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

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

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