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