Wikia

Wikihack

Source:NetHack 3.1.0/pray.c

2,032pages on
this wiki
Talk0

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

Around Wikia's network

Random Wiki