Fandom

Wikihack

Source:NetHack 3.4.0/pray.c

2,034pages on
this wiki
Add New Page
Talk0

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

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

Also on Fandom

Random Wiki