Source:NetHack 5.0.0/src/pray.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to pray.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/pray.c#line12]], for example.

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

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

1. /* NetHack 5.0	pray.c	$NHDT-Date: 1762680996 2025/11/09 01:36:36 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.244 $ */
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. 
7. staticfn int prayer_done(void);
8. staticfn void maybe_turn_mon_iter(struct monst *);
9. staticfn struct obj *worst_cursed_item(void);
10. staticfn int in_trouble(void);
11. staticfn void fix_curse_trouble(struct obj *, const char *);
12. staticfn void fix_worst_trouble(int);
13. staticfn void angrygods(aligntyp);
14. staticfn void at_your_feet(const char *);
15. staticfn void gcrownu(void);
16. staticfn void give_spell(void);
17. staticfn void pleased(aligntyp);
18. staticfn void godvoice(aligntyp, const char *);
19. staticfn void god_zaps_you(aligntyp);
20. staticfn void fry_by_god(aligntyp, boolean);
21. staticfn void gods_angry(aligntyp);
22. staticfn void gods_upset(aligntyp);
23. staticfn void consume_offering(struct obj *);
24. staticfn void offer_too_soon(aligntyp);
25. staticfn void offer_real_amulet(struct obj *, aligntyp); /* NORETURN */
26. staticfn void offer_negative_valued(boolean, aligntyp);
27. staticfn void offer_fake_amulet(struct obj *, boolean, aligntyp);
28. staticfn void offer_different_alignment_altar(struct obj *, aligntyp);
29. staticfn void sacrifice_your_race(struct obj *, boolean, aligntyp);
30. staticfn int bestow_artifact(uchar);
31. staticfn int sacrifice_value(struct obj *);
32. staticfn int eval_offering(struct obj *, aligntyp);
33. staticfn void offer_corpse(struct obj *, boolean, aligntyp);
34. staticfn boolean pray_revive(void);
35. staticfn boolean water_prayer(boolean);
36. staticfn boolean blocked_boulder(int, int);
37. 
38. /* simplify a few tests */
39. #define Cursed_obj(obj, typ) ((obj) && (obj)->otyp == (typ) && (obj)->cursed)
40. 
41. /*
42.  * Logic behind deities and altars and such:
43.  * + prayers are made to your god if not on an altar, and to the altar's god
44.  *   if you are on an altar
45.  * + If possible, your god answers all prayers, which is why bad things happen
46.  *   if you try to pray on another god's altar
47.  * + sacrifices work basically the same way, but the other god may decide to
48.  *   accept your allegiance, after which they are your god.  If rejected,
49.  *   your god takes over with your punishment.
50.  * + if you're in Gehennom, all messages come from Moloch
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 *const Moloch = "Moloch";
59. 
60. static const char *const godvoices[] = {
61.     "booms out", "thunders", "rings out", "booms",
62. };
63. 
64. #define PIOUS 20
65. #define DEVOUT 14
66. #define FERVENT 9
67. #define STRIDENT 4
68. 
69. /*
70.  * The actual trouble priority is determined by the order of the
71.  * checks performed in in_trouble() rather than by these numeric
72.  * values, so keep that code and these values synchronized in
73.  * order to have the values be meaningful.
74.  */
75. 
76. #define TROUBLE_STONED 14
77. #define TROUBLE_SLIMED 13
78. #define TROUBLE_STRANGLED 12
79. #define TROUBLE_LAVA 11
80. #define TROUBLE_SICK 10
81. #define TROUBLE_STARVING 9
82. #define TROUBLE_REGION 8 /* stinking cloud */
83. #define TROUBLE_HIT 7
84. #define TROUBLE_LYCANTHROPE 6
85. #define TROUBLE_COLLAPSING 5
86. #define TROUBLE_STUCK_IN_WALL 4
87. #define TROUBLE_CURSED_LEVITATION 3
88. #define TROUBLE_UNUSEABLE_HANDS 2
89. #define TROUBLE_CURSED_BLINDFOLD 1
90. 
91. #define TROUBLE_PUNISHED (-1)
92. #define TROUBLE_FUMBLING (-2)
93. #define TROUBLE_CURSED_ITEMS (-3)
94. #define TROUBLE_SADDLE (-4)
95. #define TROUBLE_BLIND (-5)
96. #define TROUBLE_POISONED (-6)
97. #define TROUBLE_WOUNDED_LEGS (-7)
98. #define TROUBLE_HUNGRY (-8)
99. #define TROUBLE_STUNNED (-9)
100. #define TROUBLE_CONFUSED (-10)
101. #define TROUBLE_HALLUCINATION (-11)
102. 
103. 
104. #define ugod_is_angry() (u.ualign.record < 0)
105. #define on_altar() IS_ALTAR(levl[u.ux][u.uy].typ)
106. #define on_shrine() ((levl[u.ux][u.uy].altarmask & AM_SHRINE) != 0)
107. #define a_align(x, y) ((aligntyp) Amask2align(levl[x][y].altarmask & AM_MASK))
108. 
109. /* used by turn undead iteration function; always reinitialized
110.    before iterating that, so don't need to be globals */
111. static int turn_undead_range;
112. static int turn_undead_msg_cnt;
113. 
114. /* critically low hit points if hp <= 5 or hp <= maxhp/N for some N */
115. boolean
116. critically_low_hp(
117.     boolean only_if_injured) /* determines whether maxhp <= 5 matters */
118. {
119.     int divisor, hplim,
120.         curhp = Upolyd ? u.mh : u.uhp,
121.         maxhp = Upolyd ? u.mhmax : u.uhpmax;
122. 
123.     if (only_if_injured && !(curhp < maxhp))
124.         return FALSE;
125.     /* if maxhp is extremely high, use lower threshold for the division test
126.        (golden glow cuts off at 11+5*lvl, nurse interaction at 25*lvl; this
127.        ought to use monster hit dice--and a smaller multiplier--rather than
128.        ulevel when polymorphed, but polyself doesn't maintain that) */
129.     hplim = 15 * u.ulevel;
130.     if (maxhp > hplim)
131.         maxhp = hplim;
132.     /* 7 used to be the unconditional divisor */
133.     switch (xlev_to_rank(u.ulevel)) { /* maps 1..30 into 0..8 */
134.     case 0:
135.     case 1:
136.         divisor = 5;
137.         break; /* explvl 1 to 5 */
138.     case 2:
139.     case 3:
140.         divisor = 6;
141.         break; /* explvl 6 to 13 */
142.     case 4:
143.     case 5:
144.         divisor = 7;
145.         break; /* explvl 14 to 21 */
146.     case 6:
147.     case 7:
148.         divisor = 8;
149.         break; /* explvl 22 to 29 */
150.     default:
151.         divisor = 9;
152.         break; /* explvl 30+ */
153.     }
154.     /* 5 is a magic number in TROUBLE_HIT handling below */
155.     return (boolean) (curhp <= 5 || curhp * divisor <= maxhp);
156. }
157. 
158. /* return True if surrounded by impassible rock, regardless of the state
159.    of your own location (for example, inside a doorless closet) */
160. boolean
161. stuck_in_wall(void)
162. {
163.     int i, j, x, y, count = 0;
164. 
165.     if (Passes_walls)
166.         return FALSE;
167.     for (i = -1; i <= 1; i++) {
168.         x = u.ux + i;
169.         for (j = -1; j <= 1; j++) {
170.             if (!i && !j)
171.                 continue;
172.             y = u.uy + j;
173.             if (!isok(x, y)
174.                 || (IS_OBSTRUCTED(levl[x][y].typ)
175.                     && (levl[x][y].typ != SDOOR && levl[x][y].typ != SCORR))
176.                 || (blocked_boulder(i, j) && !throws_rocks(gy.youmonst.data)))
177.                 ++count;
178.         }
179.     }
180.     return (count == 8) ? TRUE : FALSE;
181. }
182. 
183. /*
184.  * Return 0 if nothing particular seems wrong, positive numbers for
185.  * serious trouble, and negative numbers for comparative annoyances.
186.  * This returns the worst problem. There may be others, and the gods
187.  * may fix more than one.
188.  *
189.  * This could get as bizarre as noting surrounding opponents, (or
190.  * hostile dogs), but that's really hard.
191.  *
192.  * We could force rehumanize of polyselfed people, but we can't tell
193.  * unintentional shape changes from the other kind. Oh well.
194.  * 3.4.2: make an exception if polymorphed into a form which lacks
195.  * hands; that's a case where the ramifications override this doubt.
196.  */
197. staticfn int
198. in_trouble(void)
199. {
200.     struct obj *otmp;
201.     int i;
202. 
203.     /*
204.      * major troubles
205.      */
206.     if (Stoned)
207.         return TROUBLE_STONED;
208.     if (Slimed)
209.         return TROUBLE_SLIMED;
210.     if (Strangled)
211.         return TROUBLE_STRANGLED;
212.     if (u.utrap && u.utraptype == TT_LAVA)
213.         return TROUBLE_LAVA;
214.     if (Sick)
215.         return TROUBLE_SICK;
216.     if (u.uhs >= WEAK)
217.         return TROUBLE_STARVING;
218.     if (region_danger())
219.         return TROUBLE_REGION;
220.     if ((!Upolyd || Unchanging) && critically_low_hp(FALSE))
221.         return TROUBLE_HIT;
222.     if (ismnum(u.ulycn))
223.         return TROUBLE_LYCANTHROPE;
224.     if (near_capacity() >= EXT_ENCUMBER && AMAX(A_STR) - ABASE(A_STR) > 3)
225.         return TROUBLE_COLLAPSING;
226.     if (stuck_in_wall())
227.         return TROUBLE_STUCK_IN_WALL;
228.     if (Cursed_obj(uarmf, LEVITATION_BOOTS)
229.         || stuck_ring(uleft, RIN_LEVITATION)
230.         || stuck_ring(uright, RIN_LEVITATION))
231.         return TROUBLE_CURSED_LEVITATION;
232.     if (nohands(gy.youmonst.data) || !freehand()) {
233.         /* for bag/box access [cf use_container()]...
234.            make sure it's a case that we know how to handle;
235.            otherwise "fix all troubles" would get stuck in a loop */
236.         if (welded(uwep))
237.             return TROUBLE_UNUSEABLE_HANDS;
238.         if (Upolyd && nohands(gy.youmonst.data)
239.             && (!Unchanging || ((otmp = unchanger()) != 0 && otmp->cursed)))
240.             return TROUBLE_UNUSEABLE_HANDS;
241.     }
242.     if (Blindfolded && ublindf->cursed)
243.         return TROUBLE_CURSED_BLINDFOLD;
244. 
245.     /*
246.      * minor troubles
247.      */
248.     if (Punished || (u.utrap && u.utraptype == TT_BURIEDBALL))
249.         return TROUBLE_PUNISHED;
250.     if (Cursed_obj(uarmg, GAUNTLETS_OF_FUMBLING)
251.         || Cursed_obj(uarmf, FUMBLE_BOOTS))
252.         return TROUBLE_FUMBLING;
253.     if (worst_cursed_item())
254.         return TROUBLE_CURSED_ITEMS;
255.     if (u.usteed) { /* can't voluntarily dismount from a cursed saddle */
256.         otmp = which_armor(u.usteed, W_SADDLE);
257.         if (Cursed_obj(otmp, SADDLE))
258.             return TROUBLE_SADDLE;
259.     }
260. 
261.     if (BlindedTimeout > 1L && !(HBlinded & ~TIMEOUT)
262.         && (!u.uswallow
263.             || !attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND)))
264.         return TROUBLE_BLIND;
265.     /* deafness isn't its own trouble; healing magic cures deafness
266.        when it cures blindness, so do the same with trouble repair */
267.     if ((HDeaf & TIMEOUT) > 1L)
268.         return TROUBLE_BLIND;
269. 
270.     for (i = 0; i < A_MAX; i++)
271.         if (ABASE(i) < AMAX(i))
272.             return TROUBLE_POISONED;
273.     if (Wounded_legs && !u.usteed)
274.         return TROUBLE_WOUNDED_LEGS;
275.     if (u.uhs >= HUNGRY)
276.         return TROUBLE_HUNGRY;
277.     if (HStun & TIMEOUT)
278.         return TROUBLE_STUNNED;
279.     if (HConfusion & TIMEOUT)
280.         return TROUBLE_CONFUSED;
281.     if (HHallucination & TIMEOUT)
282.         return TROUBLE_HALLUCINATION;
283.     return 0;
284. }
285. 
286. /* select an item for TROUBLE_CURSED_ITEMS */
287. staticfn struct obj *
288. worst_cursed_item(void)
289. {
290.     struct obj *otmp;
291. 
292.     /* if strained or worse, check for loadstone first */
293.     if (near_capacity() >= HVY_ENCUMBER) {
294.         for (otmp = gi.invent; otmp; otmp = otmp->nobj)
295.             if (Cursed_obj(otmp, LOADSTONE))
296.                 return otmp;
297.     }
298.     /* weapon takes precedence if it is interfering
299.        with taking off a ring or putting on a shield */
300.     if (welded(uwep) && (uright || bimanual(uwep))) { /* weapon */
301.         otmp = uwep;
302.     /* gloves come next, due to rings */
303.     } else if (uarmg && uarmg->cursed) { /* gloves */
304.         otmp = uarmg;
305.     /* then shield due to two handed weapons and spells */
306.     } else if (uarms && uarms->cursed) { /* shield */
307.         otmp = uarms;
308.     /* then cloak due to body armor */
309.     } else if (uarmc && uarmc->cursed) { /* cloak */
310.         otmp = uarmc;
311.     } else if (uarm && uarm->cursed) { /* suit */
312.         otmp = uarm;
313.     /* if worn helmet of opposite alignment is making you an adherent
314.        of the current god, he/she/it won't uncurse that for you */
315.     } else if (uarmh && uarmh->cursed /* helmet */
316.                && uarmh->otyp != HELM_OF_OPPOSITE_ALIGNMENT) {
317.         otmp = uarmh;
318.     } else if (uarmf && uarmf->cursed) { /* boots */
319.         otmp = uarmf;
320.     } else if (uarmu && uarmu->cursed) { /* shirt */
321.         otmp = uarmu;
322.     } else if (uamul && uamul->cursed) { /* amulet */
323.         otmp = uamul;
324.     } else if (uleft && uleft->cursed) { /* left ring */
325.         otmp = uleft;
326.     } else if (uright && uright->cursed) { /* right ring */
327.         otmp = uright;
328.     } else if (ublindf && ublindf->cursed) { /* eyewear */
329.         otmp = ublindf; /* must be non-blinding lenses */
330.     /* if weapon wasn't handled above, do it now */
331.     } else if (welded(uwep)) { /* weapon */
332.         otmp = uwep;
333.     /* active secondary weapon even though it isn't welded */
334.     } else if (uswapwep && uswapwep->cursed && u.twoweap) {
335.         otmp = uswapwep;
336.     /* all worn items ought to be handled by now */
337.     } else {
338.         for (otmp = gi.invent; otmp; otmp = otmp->nobj) {
339.             if (!otmp->cursed)
340.                 continue;
341.             if (otmp->otyp == LOADSTONE || confers_luck(otmp))
342.                 break;
343.         }
344.     }
345.     return otmp;
346. }
347. 
348. staticfn void
349. fix_curse_trouble(struct obj *otmp, const char *what)
350. {
351.     if (!otmp) {
352.         impossible("fix_curse_trouble: nothing to uncurse.");
353.         return;
354.     }
355.     if (otmp == uarmg && Glib) {
356.         make_glib(0);
357.         Your("%s are no longer slippery.", gloves_simple_name(uarmg));
358.         if (!otmp->cursed)
359.             return;
360.     }
361.     if (!Blind || (otmp == ublindf && Blindfolded_only)) {
362.         pline("%s %s.",
363.                 what ? what : (const char *) Yobjnam2(otmp, "softly glow"),
364.                 hcolor(NH_AMBER));
365.         iflags.last_msg = PLNMSG_OBJ_GLOWS;
366.         otmp->bknown = !Hallucination; /* ok to skip set_bknown() */
367.     }
368.     uncurse(otmp);
369.     update_inventory();
370. }
371. 
372. staticfn void
373. fix_worst_trouble(int trouble)
374. {
375.     int i, maxhp;
376.     struct obj *otmp = 0;
377.     const char *what = (const char *) 0;
378.     static NEARDATA const char leftglow[] = "Your left ring softly glows",
379.                                rightglow[] = "Your right ring softly glows";
380. 
381.     switch (trouble) {
382.     case TROUBLE_STONED:
383.         make_stoned(0L, "You feel more limber.", 0, (char *) 0);
384.         break;
385.     case TROUBLE_SLIMED:
386.         make_slimed(0L, "The slime disappears.");
387.         break;
388.     case TROUBLE_STRANGLED:
389.         if (uamul && uamul->otyp == AMULET_OF_STRANGULATION) {
390.             Your("amulet vanishes!");
391.             useup(uamul);
392.         }
393.         You("can breathe again.");
394.         Strangled = 0;
395.         disp.botl = TRUE;
396.         break;
397.     case TROUBLE_LAVA:
398.         /* teleport should always succeed, but if not, just untrap them */
399.         if (!safe_teleds(TELEDS_NO_FLAGS))
400.             reset_utrap(TRUE);
401.         rescued_from_terrain(DISSOLVED); /* DISSOLVED: pending cause of death
402.                                           * if trouble didn't get cured */
403.         break;
404.     case TROUBLE_STARVING:
405.         /* temporarily lost strength recovery now handled by init_uhunger() */
406.         FALLTHROUGH;
407.         /* FALLTHRU*/
408.     case TROUBLE_HUNGRY:
409.         Your("%s feels content.", body_part(STOMACH));
410.         init_uhunger();
411.         disp.botl = TRUE;
412.         break;
413.     case TROUBLE_SICK:
414.         You_feel("better.");
415.         make_sick(0L, (char *) 0, FALSE, SICK_ALL);
416.         break;
417.     case TROUBLE_REGION:
418.         /* stinking cloud, with hero vulnerable to HP loss */
419.         region_safety();
420.         break;
421.     case TROUBLE_HIT:
422.         /* "fix all troubles" will keep trying if hero has
423.            5 or less hit points, so make sure they're always
424.            boosted to be more than that */
425.         You_feel("much better.");
426.         if (Upolyd) {
427.             maxhp = u.mhmax + rnd(5);
428.             setuhpmax(max(maxhp, 5 + 1), FALSE); /* acts as setmhmax() */
429.             u.mh = u.mhmax;
430.         }
431.         maxhp = u.uhpmax;
432.         if (maxhp < u.ulevel * 5 + 11)
433.             maxhp += rnd(5);
434.         /* True: update u.uhpmax even if currently poly'd */
435.         setuhpmax(max(maxhp, 5 + 1), TRUE);
436.         u.uhp = u.uhpmax; /* setuhpmax() will do this when u.uhp is higher
437.                            * than u.uhpmax; prayer also does this if lower */
438.         disp.botl = TRUE;
439.         break;
440.     case TROUBLE_COLLAPSING:
441.         /* override Fixed_abil; uncurse that if feasible */
442.         You_feel("%sstronger.",
443.                  (AMAX(A_STR) - ABASE(A_STR) > 6) ? "much " : "");
444.         ABASE(A_STR) = AMAX(A_STR);
445.         disp.botl = TRUE;
446.         if (Fixed_abil) {
447.             if ((otmp = stuck_ring(uleft, RIN_SUSTAIN_ABILITY)) != 0) {
448.                 if (otmp == uleft)
449.                     what = leftglow;
450.             } else if ((otmp = stuck_ring(uright, RIN_SUSTAIN_ABILITY))
451.                        != 0) {
452.                 if (otmp == uright)
453.                     what = rightglow;
454.             }
455.             if (otmp) {
456.                 fix_curse_trouble(otmp, what);
457.                 break;
458.             }
459.         }
460.         break;
461.     case TROUBLE_STUCK_IN_WALL:
462.         /* no control, but works on no-teleport levels */
463.         if (safe_teleds(TELEDS_NO_FLAGS)) {
464.             Your("surroundings change.");
465.         } else {
466.             /* safe_teleds() couldn't find a safe place; perhaps the
467.                level is completely full.  As a last resort, confer
468.                intrinsic wall/rock-phazing.  Hero might get stuck
469.                again fairly soon....
470.                Without something like this, fix_all_troubles can get
471.                stuck in an infinite loop trying to fix STUCK_IN_WALL
472.                and repeatedly failing. */
473.             set_itimeout(&HPasses_walls, (long) (d(4, 4) + 4)); /* 8..20 */
474.             /* how else could you move between packed rocks or among
475.                lattice forming "solid" rock? */
476.             You_feel("much slimmer.");
477.         }
478.         break;
479.     case TROUBLE_CURSED_LEVITATION:
480.         if (Cursed_obj(uarmf, LEVITATION_BOOTS)) {
481.             otmp = uarmf;
482.         } else if ((otmp = stuck_ring(uleft, RIN_LEVITATION)) != 0) {
483.             if (otmp == uleft)
484.                 what = leftglow;
485.         } else if ((otmp = stuck_ring(uright, RIN_LEVITATION)) != 0) {
486.             if (otmp == uright)
487.                 what = rightglow;
488.         }
489.         fix_curse_trouble(otmp, what);
490.         break;
491.     case TROUBLE_UNUSEABLE_HANDS:
492.         if (welded(uwep)) {
493.             otmp = uwep;
494.             fix_curse_trouble(otmp, what);
495.             break;
496.         }
497.         if (Upolyd && nohands(gy.youmonst.data)) {
498.             if (!Unchanging) {
499.                 Your("shape becomes uncertain.");
500.                 rehumanize(); /* "You return to {normal} form." */
501.             } else if ((otmp = unchanger()) != 0 && otmp->cursed) {
502.                 /* otmp is an amulet of unchanging */
503.                 fix_curse_trouble(otmp, what);
504.                 break;
505.             }
506.         }
507.         if (nohands(gy.youmonst.data) || !freehand())
508.             impossible("fix_worst_trouble: couldn't cure hands.");
509.         break;
510.     case TROUBLE_CURSED_BLINDFOLD:
511.         otmp = ublindf;
512.         fix_curse_trouble(otmp, what);
513.         break;
514.     case TROUBLE_LYCANTHROPE:
515.         you_unwere(TRUE);
516.         break;
517.     /*
518.      */
519.     case TROUBLE_PUNISHED:
520.         Your("chain disappears.");
521.         if (u.utrap && u.utraptype == TT_BURIEDBALL)
522.             buried_ball_to_freedom();
523.         else
524.             unpunish();
525.         break;
526.     case TROUBLE_FUMBLING:
527.         if (Cursed_obj(uarmg, GAUNTLETS_OF_FUMBLING))
528.             otmp = uarmg;
529.         else if (Cursed_obj(uarmf, FUMBLE_BOOTS))
530.             otmp = uarmf;
531.         fix_curse_trouble(otmp, what);
532.         break;
533.     case TROUBLE_CURSED_ITEMS:
534.         otmp = worst_cursed_item();
535.         if (otmp == uright)
536.             what = rightglow;
537.         else if (otmp == uleft)
538.             what = leftglow;
539.         fix_curse_trouble(otmp, what);
540.         break;
541.     case TROUBLE_POISONED:
542.         /* override Fixed_abil; ignore items which confer that */
543.         if (Hallucination)
544.             pline("There's a tiger in your tank.");
545.         else
546.             You_feel("in good health again.");
547.         for (i = 0; i < A_MAX; i++) {
548.             if (ABASE(i) < AMAX(i)) {
549.                 ABASE(i) = AMAX(i);
550.                 disp.botl = TRUE;
551.             }
552.         }
553.         encumber_msg();
554.         break;
555.     case TROUBLE_BLIND: { /* handles deafness as well as blindness */
556.         char msgbuf[BUFSZ];
557.         const char *eyes = body_part(EYE);
558.         boolean cure_deaf = (HDeaf & TIMEOUT) ? TRUE : FALSE;
559. 
560.         msgbuf[0] = '\0';
561.         if (Blinded) {
562.             if (eyecount(gy.youmonst.data) != 1)
563.                 eyes = makeplural(eyes);
564.             Sprintf(msgbuf, "Your %s %s better", eyes, vtense(eyes, "feel"));
565.             u.ucreamed = 0;
566.             make_blinded(0L, FALSE);
567.         }
568.         if (cure_deaf) {
569.             make_deaf(0L, FALSE);
570.             if (!Deaf)
571.                 Sprintf(eos(msgbuf), "%s can hear again",
572.                         !*msgbuf ? "You" : " and you");
573.         }
574.         if (*msgbuf)
575.             pline("%s.", msgbuf);
576.         break;
577.     }
578.     case TROUBLE_WOUNDED_LEGS:
579.         heal_legs(0);
580.         break;
581.     case TROUBLE_STUNNED:
582.         make_stunned(0L, TRUE);
583.         break;
584.     case TROUBLE_CONFUSED:
585.         make_confused(0L, TRUE);
586.         break;
587.     case TROUBLE_HALLUCINATION:
588.         pline("Looks like you are back in Kansas.");
589.         (void) make_hallucinated(0L, FALSE, 0L);
590.         break;
591.     case TROUBLE_SADDLE:
592.         otmp = which_armor(u.usteed, W_SADDLE);
593.         if (!Blind) {
594.             pline("%s %s.", Yobjnam2(otmp, "softly glow"), hcolor(NH_AMBER));
595.             set_bknown(otmp, 1);
596.         }
597.         uncurse(otmp);
598.         break;
599.     }
600. }
601. 
602. /* "I am sometimes shocked by... the nuns who never take a bath without
603.  * wearing a bathrobe all the time.  When asked why, since no man can see them,
604.  * they reply 'Oh, but you forget the good God'.  Apparently they conceive of
605.  * the Deity as a Peeping Tom, whose omnipotence enables Him to see through
606.  * bathroom walls, but who is foiled by bathrobes." --Bertrand Russell, 1943
607.  * Divine wrath, dungeon walls, and armor follow the same principle.
608.  */
609. staticfn void
610. god_zaps_you(aligntyp resp_god)
611. {
612.     if (u.uswallow) {
613.         pline(
614.           "Suddenly a bolt of lightning comes down at you from the heavens!");
615.         pline("It strikes %s!", mon_nam(u.ustuck));
616.         if (!resists_elec(u.ustuck)) {
617.             pline("%s fries to a crisp!", Monnam(u.ustuck));
618.             /* Yup, you get experience.  It takes guts to successfully
619.              * pull off this trick on your god, anyway.
620.              * Other credit/blame applies (luck or alignment adjustments),
621.              * but not direct kill count (pacifist conduct).
622.              */
623.             xkilled(u.ustuck, XKILL_NOMSG | XKILL_NOCONDUCT);
624.         } else
625.             pline("%s seems unaffected.", Monnam(u.ustuck));
626.     } else {
627.         pline("Suddenly, a bolt of lightning strikes you!");
628.         if (Reflecting) {
629.             shieldeff(u.ux, u.uy);
630.             if (Blind)
631.                 pline("For some reason you're unaffected.");
632.             else
633.                 (void) ureflects("%s reflects from your %s.", "It");
634.             monstseesu(M_SEEN_REFL);
635.         } else if (Shock_resistance) {
636.             shieldeff(u.ux, u.uy);
637.             pline("It seems not to affect you.");
638.             monstseesu(M_SEEN_ELEC);
639.             monstunseesu(M_SEEN_REFL);
640.         } else {
641.             fry_by_god(resp_god, FALSE);
642.             monstunseesu(M_SEEN_REFL | M_SEEN_ELEC);
643.         }
644.     }
645. 
646.     pline("%s is not deterred...", align_gname(resp_god));
647.     if (u.uswallow) {
648.         pline("A wide-angle disintegration beam aimed at you hits %s!",
649.               mon_nam(u.ustuck));
650.         if (!resists_disint(u.ustuck)) {
651.             pline("%s disintegrates into a pile of dust!", Monnam(u.ustuck));
652.             xkilled(u.ustuck, XKILL_NOMSG | XKILL_NOCORPSE | XKILL_NOCONDUCT);
653.         } else
654.             pline("%s seems unaffected.", Monnam(u.ustuck));
655.     } else {
656.         pline("A wide-angle disintegration beam hits you!");
657. 
658.         /* disintegrate shield and body armor before disintegrating
659.          * the impudent mortal, like black dragon breath -3.
660.          */
661.         if (uarms && !(EReflecting & W_ARMS)
662.             && !(EDisint_resistance & W_ARMS))
663.             (void) disintegrate_arm(uarms);
664.         if (uarmc && !(EReflecting & W_ARMC)
665.             && !(EDisint_resistance & W_ARMC))
666.             (void) disintegrate_arm(uarmc);
667.         if (uarm && !(EReflecting & W_ARM) && !(EDisint_resistance & W_ARM)
668.             && !uarmc)
669.             (void) disintegrate_arm(uarm);
670.         if (uarmu && !uarm && !uarmc)
671.             (void) disintegrate_arm(uarmu);
672.         if (!Disint_resistance) {
673.             fry_by_god(resp_god, TRUE);
674.             monstunseesu(M_SEEN_DISINT);
675.         } else {
676.             You("bask in its %s glow for a minute...", NH_BLACK);
677.             godvoice(resp_god, "I believe it not!");
678.             monstseesu(M_SEEN_DISINT);
679.         }
680.         if (Is_astralevel(&u.uz) || Is_sanctum(&u.uz)) {
681.             /* one more try for high altars */
682.             SetVoice((struct monst *) 0, 0, 80, voice_deity);
683.             verbalize("Thou cannot escape my wrath, mortal!");
684.             summon_minion(resp_god, FALSE);
685.             summon_minion(resp_god, FALSE);
686.             summon_minion(resp_god, FALSE);
687.             SetVoice((struct monst *) 0, 0, 80, voice_deity);
688.             verbalize("Destroy %s, my servants!", uhim());
689.         }
690.     }
691. }
692. 
693. staticfn void
694. fry_by_god(aligntyp resp_god, boolean via_disintegration)
695. {
696.     You("%s!", !via_disintegration ? "fry to a crisp"
697.                                    : "disintegrate into a pile of dust");
698.     svk.killer.format = KILLED_BY;
699.     Sprintf(svk.killer.name, "the wrath of %s", align_gname(resp_god));
700.     done(DIED);
701. }
702. 
703. staticfn void
704. angrygods(aligntyp resp_god)
705. {
706.     int maxanger, new_ublesscnt;
707. 
708.     if (Inhell)
709.         resp_god = A_NONE;
710.     u.ublessed = 0; /* lose divine protection */
711. 
712.     /* changed from tmp = u.ugangr + abs (u.uluck) -- rph */
713.     /* added test for alignment diff -dlc */
714.     if (resp_god != u.ualign.type)
715.         maxanger = u.ualign.record / 2 + (Luck > 0 ? -Luck / 3 : -Luck);
716.     else
717.         maxanger = 3 * u.ugangr + ((Luck > 0 || u.ualign.record >= STRIDENT)
718.                                    ? -Luck / 3
719.                                    : -Luck);
720.     if (maxanger < 1)
721.         maxanger = 1; /* possible if bad align & good luck */
722.     else if (maxanger > 15)
723.         maxanger = 15; /* be reasonable */
724. 
725.     switch (rn2(maxanger)) {
726.     case 0:
727.     case 1:
728.         You_feel("that %s is %s.", align_gname(resp_god),
729.                  Hallucination ? "bummed" : "displeased");
730.         break;
731.     case 2:
732.     case 3:
733.         godvoice(resp_god, (char *) 0);
734.         pline("\"Thou %s, %s.\"",
735.               (ugod_is_angry() && resp_god == u.ualign.type)
736.                   ? "hast strayed from the path"
737.                   : "art arrogant",
738.               gy.youmonst.data->mlet == S_HUMAN ? "mortal" : "creature");
739.         SetVoice((struct monst *) 0, 0, 80, voice_deity);
740.         verbalize("Thou must relearn thy lessons!");
741.         (void) adjattrib(A_WIS, -1, FALSE);
742.         losexp((char *) 0);
743.         break;
744.     case 6:
745.         if (!Punished) {
746.             gods_angry(resp_god);
747.             punish((struct obj *) 0);
748.             break;
749.         }
750.         FALLTHROUGH;
751.         /* FALLTHRU */
752.     case 4:
753.     case 5:
754.         gods_angry(resp_god);
755.         if (!Blind && !Antimagic)
756.             pline("%s glow surrounds you.", An(hcolor(NH_BLACK)));
757.         if (rn2(2) || !attrcurse())
758.             rndcurse();
759.         break;
760.     case 7:
761.     case 8:
762.         godvoice(resp_god, (char *) 0);
763.         SetVoice((struct monst *) 0, 0, 80, voice_deity);
764.         verbalize("Thou durst %s me?",
765.                   (on_altar() && (a_align(u.ux, u.uy) != resp_god))
766.                       ? "scorn"
767.                       : "call upon");
768.         /* [why isn't this using verbalize()?] */
769.         pline("\"Then die, %s!\"",
770.               (gy.youmonst.data->mlet == S_HUMAN) ? "mortal" : "creature");
771.         summon_minion(resp_god, FALSE);
772.         break;
773. 
774.     default:
775.         gods_angry(resp_god);
776.         god_zaps_you(resp_god);
777.         break;
778.     }
779.     /* even though this might not be in response to prayer, set pray timer */
780.     new_ublesscnt = rnz(300);
781.     if (new_ublesscnt > u.ublesscnt)
782.         u.ublesscnt = new_ublesscnt;
783.     return;
784. }
785. 
786. /* helper to print "str appears at your feet", or appropriate */
787. staticfn void
788. at_your_feet(const char *str)
789. {
790.     if (Blind)
791.         str = Something;
792.     if (u.uswallow) {
793.         /* barrier between you and the floor */
794.         pline("%s %s into %s %s.", str, vtense(str, "drop"),
795.               s_suffix(mon_nam(u.ustuck)), mbodypart(u.ustuck, STOMACH));
796.     } else {
797.         pline("%s %s %s your %s!", str,
798.               vtense(str, Blind ? "land" : "appear"),
799.               Levitation ? "beneath" : "at",
800.               makeplural(body_part(FOOT)));
801.     }
802. }
803. 
804. staticfn void
805. gcrownu(void)
806. {
807.     struct obj *obj;
808.     const char *what;
809.     boolean already_exists, in_hand;
810.     short class_gift;
811. #define ok_wep(o) ((o) && ((o)->oclass == WEAPON_CLASS || is_weptool(o)))
812. 
813.     HSee_invisible |= FROMOUTSIDE;
814.     HFire_resistance |= FROMOUTSIDE;
815.     HCold_resistance |= FROMOUTSIDE;
816.     HShock_resistance |= FROMOUTSIDE;
817.     HSleep_resistance |= FROMOUTSIDE;
818.     HPoison_resistance |= FROMOUTSIDE;
819.     godvoice(u.ualign.type, (char *) 0);
820. 
821.     class_gift = STRANGE_OBJECT;
822.     /* 3.3.[01] had this in the A_NEUTRAL case,
823.        preventing chaotic wizards from receiving a spellbook */
824.     if (Role_if(PM_WIZARD)
825.         && !u_wield_art(ART_VORPAL_BLADE)
826.         && !u_wield_art(ART_STORMBRINGER)
827.         && !carrying(SPE_FINGER_OF_DEATH)) {
828.         class_gift = SPE_FINGER_OF_DEATH;
829.     } else if (Role_if(PM_MONK) && (!uwep || !uwep->oartifact)
830.                && !carrying(SPE_RESTORE_ABILITY)) {
831.         /* monks rarely wield a weapon */
832.         class_gift = SPE_RESTORE_ABILITY;
833.     }
834. 
835.     obj = ok_wep(uwep) ? uwep : 0;
836.     already_exists = in_hand = FALSE; /* lint suppression */
837.     switch (u.ualign.type) {
838.     case A_LAWFUL:
839.         u.uevent.uhand_of_elbereth = 1;
840.         SetVoice((struct monst *) 0, 0, 80, voice_deity);
841.         verbalize("I crown thee...  The Hand of Elbereth!");
842.         livelog_printf(LL_DIVINEGIFT,
843.                        "was crowned \"The Hand of Elbereth\" by %s",
844.                        u_gname());
845.         break;
846.     case A_NEUTRAL:
847.         u.uevent.uhand_of_elbereth = 2;
848.         in_hand = u_wield_art(ART_VORPAL_BLADE);
849.         already_exists = exist_artifact(LONG_SWORD,
850.                                         artiname(ART_VORPAL_BLADE));
851.         SetVoice((struct monst *) 0, 0, 80, voice_deity);
852.         verbalize("Thou shalt be my Envoy of Balance!");
853.         livelog_printf(LL_DIVINEGIFT, "became %s Envoy of Balance",
854.                        s_suffix(u_gname()));
855.         break;
856.     case A_CHAOTIC:
857.         u.uevent.uhand_of_elbereth = 3;
858.         in_hand = u_wield_art(ART_STORMBRINGER);
859.         already_exists = exist_artifact(RUNESWORD,
860.                                         artiname(ART_STORMBRINGER));
861.         what = (((already_exists && !in_hand) || class_gift != STRANGE_OBJECT)
862.                 ? "take lives"
863.                 : "steal souls");
864.         SetVoice((struct monst *) 0, 0, 80, voice_deity);
865.         verbalize("Thou art chosen to %s for My Glory!", what);
866.         livelog_printf(LL_DIVINEGIFT, "was chosen to %s for the Glory of %s",
867.                        what, u_gname());
868.         break;
869.     }
870. 
871.     if (objects[class_gift].oc_class == SPBOOK_CLASS) {
872.         char bbuf[BUFSZ];
873. 
874.         obj = mksobj(class_gift, TRUE, FALSE);
875.         /* get book type before dropping (don't think that could destroy
876.            the book because we need to be on an altar in order to become
877.            crowned, but be paranoid about it) */
878.         Strcpy(bbuf, actualoname(obj)); /* for livelog; "spellbook of <foo>"
879.                                          * even if hero doesn't know book */
880.         bless(obj);
881.         obj->bknown = 1; /* ok to skip set_bknown() */
882.         observe_object(obj);
883.         at_your_feet(upstart(ansimpleoname(obj)));
884.         dropy(obj);
885.         u.ugifts++;
886.         /* not an artifact, but treat like one for this situation;
887.            classify as a spoiler in case player hasn't IDed the book yet */
888.         livelog_printf(LL_DIVINEGIFT | LL_ARTIFACT | LL_SPOILER,
889.                        "was bestowed with %s", bbuf);
890. 
891.         /* when getting a new book for known spell, enhance
892.            currently wielded weapon rather than the book */
893.         if (known_spell(class_gift) != spe_Unknown && ok_wep(uwep))
894.             obj = uwep; /* to be blessed,&c */
895.     }
896. 
897.     switch (u.ualign.type) {
898.     case A_LAWFUL:
899.         if (class_gift != STRANGE_OBJECT) {
900.             ; /* already got bonus above */
901.         } else if (obj && obj->otyp == LONG_SWORD && !obj->oartifact) {
902.             char lbuf[BUFSZ];
903. 
904.             Strcpy(lbuf, simpleonames(obj)); /* before transformation */
905.             if (!Blind)
906.                 Your("sword shines brightly for a moment.");
907.             obj = oname(obj, artiname(ART_EXCALIBUR),
908.                         ONAME_GIFT | ONAME_KNOW_ARTI);
909.             if (is_art(obj, ART_EXCALIBUR)) {
910.                 u.ugifts++;
911.                 livelog_printf(LL_DIVINEGIFT | LL_ARTIFACT,
912.                                "had %s wielded %s transformed into %s",
913.                                uhis(), lbuf, artiname(ART_EXCALIBUR));
914.             }
915.         }
916.         /* acquire Excalibur's skill regardless of weapon or gift */
917.         unrestrict_weapon_skill(P_LONG_SWORD);
918.         if (is_art(obj, ART_EXCALIBUR))
919.             discover_artifact(ART_EXCALIBUR);
920.         break;
921.     case A_NEUTRAL:
922.         if (class_gift != STRANGE_OBJECT) {
923.             ; /* already got bonus above */
924.         } else if (obj && in_hand) {
925.             Your("%s goes snicker-snack!", xname(obj));
926.             observe_object(obj);
927.         } else if (!already_exists) {
928.             obj = mksobj(LONG_SWORD, FALSE, FALSE);
929.             obj = oname(obj, artiname(ART_VORPAL_BLADE),
930.                         ONAME_GIFT | ONAME_KNOW_ARTI);
931.             obj->spe = 1;
932.             at_your_feet("A sword");
933.             dropy(obj);
934.             u.ugifts++;
935.             livelog_printf(LL_DIVINEGIFT | LL_ARTIFACT,
936.                            "was bestowed with %s",
937.                            artiname(ART_VORPAL_BLADE));
938.         }
939.         /* acquire Vorpal Blade's skill regardless of weapon or gift */
940.         unrestrict_weapon_skill(P_LONG_SWORD);
941.         if (is_art(obj, ART_VORPAL_BLADE))
942.             discover_artifact(ART_VORPAL_BLADE);
943.         break;
944.     case A_CHAOTIC: {
945.         char swordbuf[BUFSZ];
946. 
947.         Sprintf(swordbuf, "%s sword", hcolor(NH_BLACK));
948.         if (class_gift != STRANGE_OBJECT) {
949.             ; /* already got bonus above */
950.         } else if (obj && in_hand) {
951.             Your("%s hums ominously!", swordbuf);
952.             observe_object(obj);
953.         } else if (!already_exists) {
954.             obj = mksobj(RUNESWORD, FALSE, FALSE);
955.             obj = oname(obj, artiname(ART_STORMBRINGER),
956.                         ONAME_GIFT | ONAME_KNOW_ARTI);
957.             obj->spe = 1;
958.             at_your_feet(An(swordbuf));
959.             dropy(obj);
960.             u.ugifts++;
961.             livelog_printf(LL_DIVINEGIFT | LL_ARTIFACT,
962.                            "was bestowed with %s",
963.                            artiname(ART_STORMBRINGER));
964.         }
965.         /* acquire Stormbringer's skill regardless of weapon or gift */
966.         unrestrict_weapon_skill(P_BROAD_SWORD);
967.         if (is_art(obj, ART_STORMBRINGER))
968.             discover_artifact(ART_STORMBRINGER);
969.         break;
970.     }
971.     default:
972.         obj = 0; /* lint */
973.         break;
974.     }
975. 
976.     /* enhance weapon regardless of alignment or artifact status */
977.     if (ok_wep(obj)) {
978.         bless(obj);
979.         obj->oeroded = obj->oeroded2 = 0;
980.         obj->oerodeproof = TRUE;
981.         obj->bknown = obj->rknown = 1; /* ok to skip set_bknown() */
982.         if (obj->spe < 1)
983.             obj->spe = 1;
984.         /* acquire skill in this weapon */
985.         unrestrict_weapon_skill(weapon_type(obj));
986.     } else if (class_gift == STRANGE_OBJECT) {
987.         /* opportunity knocked, but there was nobody home... */
988.         You_feel("unworthy.");
989.     }
990.     update_inventory();
991. 
992.     /* lastly, confer an extra skill slot/credit beyond the
993.        up-to-29 you can get from gaining experience levels */
994.     add_weapon_skill(1);
995.     return;
996. }
997. 
998. staticfn void
999. give_spell(void)
1000. {
1001.     struct obj *otmp;
1002.     char spe_let;
1003.     int spe_knowledge, trycnt = u.ulevel + 1;
1004. 
1005.     /* not yet known spells and forgotten spells are given preference over
1006.        usable ones; also, try to grant spell that hero could gain skill in
1007.        (even though being restricted doesn't prevent learning and casting) */
1008.     otmp = mkobj(SPBOOK_no_NOVEL, TRUE);
1009.     while (--trycnt > 0) {
1010.         if (otmp->otyp != SPE_BLANK_PAPER) {
1011.             if (known_spell(otmp->otyp) <= spe_Unknown
1012.                 && !P_RESTRICTED(spell_skilltype(otmp->otyp)))
1013.                 break; /* forgotten or not yet known */
1014.         } else {
1015.             /* blank paper is acceptable if not discovered yet or
1016.                if hero has a magic marker to write something on it
1017.                (doesn't matter if marker is out of charges); it will
1018.                become discovered (below) without needing to be read */
1019.             if (!objects[SPE_BLANK_PAPER].oc_name_known
1020.                 || carrying(MAGIC_MARKER))
1021.                 break;
1022.         }
1023.         otmp->otyp = rnd_class(svb.bases[SPBOOK_CLASS], SPE_BLANK_PAPER);
1024.     }
1025.     /*
1026.      * 25% chance of learning the spell directly instead of
1027.      * receiving the book for it, unless it's already well known.
1028.      * The chance is not influenced by whether hero is illiterate.
1029.      */
1030.     if (otmp->otyp != SPE_BLANK_PAPER && !rn2(4)
1031.         && (spe_knowledge = known_spell(otmp->otyp)) != spe_Fresh) {
1032.         /* force_learn_spell() should only return '\0' if the book
1033.            is blank paper or the spell is known and has retention
1034.            of spe_Fresh, so no 'else' case is needed here */
1035.         if ((spe_let = force_learn_spell(otmp->otyp)) != '\0') {
1036.             /* for spellbook class, OBJ_NAME() yields the name of
1037.                the spell rather than "spellbook of <spell-name>" */
1038.             const char *spe_name = OBJ_NAME(objects[otmp->otyp]);
1039. 
1040.             if (spe_knowledge == spe_Unknown) /* prior to learning */
1041.                 /* appending "spell 'a'" seems slightly silly but
1042.                    is similar to "added to your repertoire, as 'a'"
1043.                    and without any spellbook on hand a novice player
1044.                    might not recognize that 'spe_name' is a spell */
1045.                 pline("Divine knowledge of %s fills your mind!  Spell '%c'.",
1046.                       spe_name, spe_let);
1047.             else
1048.                 Your("knowledge of spell '%c' - %s is %s.",
1049.                      spe_let, spe_name,
1050.                      (spe_knowledge == spe_Forgotten) ? "restored"
1051.                                                       : "refreshed");
1052.         }
1053.         obfree(otmp, (struct obj *) 0); /* discard the book */
1054.     } else {
1055.         observe_object(otmp);
1056.         /* don't set bknown */
1057.         /* discovering blank paper will make it less likely to
1058.            be given again; small chance to arbitrarily discover
1059.            some other book type without having to read it first */
1060.         if (otmp->otyp == SPE_BLANK_PAPER || !rn2(100))
1061.             makeknown(otmp->otyp);
1062.         bless(otmp);
1063.         at_your_feet(upstart(ansimpleoname(otmp)));
1064.         place_object(otmp, u.ux, u.uy);
1065.         newsym(u.ux, u.uy);
1066.     }
1067.     return;
1068. }
1069. 
1070. staticfn void
1071. pleased(aligntyp g_align)
1072. {
1073.     /* don't use p_trouble, worst trouble may get fixed while praying */
1074.     int trouble = in_trouble(); /* what's your worst difficulty? */
1075.     int pat_on_head = 0, kick_on_butt;
1076. 
1077.     You_feel("that %s is %s.", align_gname(g_align),
1078.              (u.ualign.record >= DEVOUT)
1079.                  ? Hallucination ? "pleased as punch" : "well-pleased"
1080.                  : (u.ualign.record >= STRIDENT)
1081.                        ? Hallucination ? "ticklish" : "pleased"
1082.                        : Hallucination ? "full" : "satisfied");
1083. 
1084.     /* not your deity */
1085.     if (on_altar() && gp.p_aligntyp != u.ualign.type) {
1086.         adjalign(-1);
1087.         return;
1088.     } else if (u.ualign.record < 2 && trouble <= 0)
1089.         adjalign(1);
1090. 
1091.     /*
1092.      * Depending on your luck & align level, the god you prayed to will:
1093.      *  - fix your worst problem if it's major;
1094.      *  - fix all your major problems;
1095.      *  - fix your worst problem if it's minor;
1096.      *  - fix all of your problems;
1097.      *  - do you a gratuitous favor.
1098.      *
1099.      * If you make it to the last category, you roll randomly again
1100.      * to see what they do for you.
1101.      *
1102.      * If your luck is at least 0, then you are guaranteed rescued from
1103.      * your worst major problem.
1104.      */
1105.     if (!trouble && u.ualign.record >= DEVOUT) {
1106.         /* if hero was in trouble, but got better, no special favor */
1107.         if (gp.p_trouble == 0)
1108.             pat_on_head = 1;
1109.     } else {
1110.         int action, prayer_luck;
1111.         int tryct = 0;
1112. 
1113.         /* Negative luck is normally impossible here (can_pray() forces
1114.            prayer failure in that situation), but it's possible for
1115.            Luck to drop during the period of prayer occupation and
1116.            become negative by the time we get here.  [Reported case
1117.            was lawful character whose stinking cloud caused a delayed
1118.            killing of a peaceful human, triggering the "murderer"
1119.            penalty while successful prayer was in progress.  It could
1120.            also happen due to inconvenient timing on Friday 13th, but
1121.            the magnitude there (-1) isn't big enough to cause trouble.]
1122.            We don't bother remembering start-of-prayer luck, just make
1123.            sure it's at least -1 so that Luck+2 is big enough to avoid
1124.            a divide by zero crash when generating a random number.  */
1125.         prayer_luck = max(Luck, -1); /* => (prayer_luck + 2 > 0) */
1126.         action = rn1(prayer_luck + (on_altar() ? 3 + on_shrine() : 2), 1);
1127.         if (!on_altar())
1128.             action = min(action, 3);
1129.         if (u.ualign.record < STRIDENT)
1130.             action = (u.ualign.record > 0 || !rnl(2)) ? 1 : 0;
1131. 
1132.         switch (min(action, 5)) {
1133.         case 5:
1134.             pat_on_head = 1;
1135.             FALLTHROUGH;
1136.             /*FALLTHRU*/
1137.         case 4:
1138.             do
1139.                 fix_worst_trouble(trouble);
1140.             while ((trouble = in_trouble()) != 0);
1141.             break;
1142. 
1143.         case 3:
1144.             /* up to 10 troubles */
1145.             fix_worst_trouble(trouble);
1146.             FALLTHROUGH;
1147.             /*FALLTHRU*/
1148.         case 2:
1149.             /* up to 9 troubles */
1150.             while ((trouble = in_trouble()) > 0 && (++tryct < 10))
1151.                 fix_worst_trouble(trouble);
1152.             break;
1153. 
1154.         case 1:
1155.             if (trouble > 0)
1156.                 fix_worst_trouble(trouble);
1157.             break;
1158.         case 0:
1159.             break; /* your god blows you off, too bad */
1160.         }
1161.     }
1162. 
1163.     /* note: can't get pat_on_head unless all troubles have just been
1164.        fixed or there were no troubles to begin with; hallucination
1165.        won't be in effect so special handling for it is superfluous */
1166.     if (pat_on_head)
1167.         switch (rn2((Luck + 6) >> 1)) {
1168.         case 0:
1169.             break;
1170.         case 1:
1171.             if (uwep && (welded(uwep) || uwep->oclass == WEAPON_CLASS
1172.                          || is_weptool(uwep))) {
1173.                 char repair_buf[BUFSZ];
1174. 
1175.                 *repair_buf = '\0';
1176.                 if (uwep->oeroded || uwep->oeroded2)
1177.                     Sprintf(repair_buf, " and %s now as good as new",
1178.                             otense(uwep, "are"));
1179. 
1180.                 if (uwep->cursed) {
1181.                     if (!Blind) {
1182.                         pline("%s %s%s.", Yobjnam2(uwep, "softly glow"),
1183.                               hcolor(NH_AMBER), repair_buf);
1184.                         iflags.last_msg = PLNMSG_OBJ_GLOWS;
1185.                     } else
1186.                         You_feel("the power of %s over %s.", u_gname(),
1187.                                  yname(uwep));
1188.                     uncurse(uwep);
1189.                     uwep->bknown = 1; /* ok to bypass set_bknown() */
1190.                     *repair_buf = '\0';
1191.                 } else if (!uwep->blessed) {
1192.                     if (!Blind) {
1193.                         pline("%s with %s aura%s.",
1194.                               Yobjnam2(uwep, "softly glow"),
1195.                               an(hcolor(NH_LIGHT_BLUE)), repair_buf);
1196.                         iflags.last_msg = PLNMSG_OBJ_GLOWS;
1197.                     } else
1198.                         You_feel("the blessing of %s over %s.", u_gname(),
1199.                                  yname(uwep));
1200.                     bless(uwep);
1201.                     uwep->bknown = 1; /* ok to bypass set_bknown() */
1202.                     *repair_buf = '\0';
1203.                 }
1204. 
1205.                 /* fix any rust/burn/rot damage, but don't protect
1206.                    against future damage */
1207.                 if (uwep->oeroded || uwep->oeroded2) {
1208.                     uwep->oeroded = uwep->oeroded2 = 0;
1209.                     /* only give this message if we didn't just bless
1210.                        or uncurse (which has already given a message) */
1211.                     if (*repair_buf)
1212.                         pline("%s as good as new!",
1213.                               Yobjnam2(uwep, Blind ? "feel" : "look"));
1214.                 }
1215.                 update_inventory();
1216.             }
1217.             break;
1218.         case 3:
1219.             /* takes 2 hints to get the music to enter the stronghold;
1220.                skip if you've solved it via mastermind or destroyed the
1221.                drawbridge (both set uopened_dbridge) or if you've already
1222.                travelled past the Valley of the Dead (gehennom_entered) */
1223.             if (!u.uevent.uopened_dbridge && !u.uevent.gehennom_entered) {
1224.                 if (u.uevent.uheard_tune < 1) {
1225.                     godvoice(g_align, (char *) 0);
1226.                     SetVoice((struct monst *) 0, 0, 80, voice_deity);
1227.                     verbalize("Hark, %s!", is_human(gy.youmonst.data)
1228.                                                ? "mortal"
1229.                                                : "creature");
1230.                     SetVoice((struct monst *) 0, 0, 80, voice_deity);
1231.                     verbalize(
1232.                        "To enter the castle, thou must play the right tune!");
1233.                     u.uevent.uheard_tune++;
1234.                     break;
1235.                 } else if (u.uevent.uheard_tune < 2) {
1236.                     Soundeffect(se_divine_music, 50);
1237.                     You_hear("a divine music...");
1238.                     pline("It sounds like:  \"%s\".", svt.tune);
1239.                     u.uevent.uheard_tune++;
1240.                     record_achievement(ACH_TUNE);
1241.                     break;
1242.                 }
1243.             }
1244.             FALLTHROUGH;
1245.             /*FALLTHRU*/
1246.         case 2:
1247.             if (!Blind)
1248.                 You("are surrounded by %s glow.", an(hcolor(NH_GOLDEN)));
1249.             /* if any levels have been lost (and not yet regained),
1250.                treat this effect like blessed full healing */
1251.             if (u.ulevel < u.ulevelmax) {
1252.                 u.ulevelmax -= 1; /* see potion.c */
1253.                 pluslvl(FALSE);
1254.             } else {
1255.                 u.uhpmax += 5;
1256.                 if (u.uhpmax > u.uhppeak)
1257.                     u.uhppeak = u.uhpmax;
1258.                 if (Upolyd)
1259.                     u.mhmax += 5;
1260.             }
1261.             u.uhp = u.uhpmax;
1262.             if (Upolyd)
1263.                 u.mh = u.mhmax;
1264.             if (ABASE(A_STR) < AMAX(A_STR)) {
1265.                 ABASE(A_STR) = AMAX(A_STR);
1266.                 disp.botl = TRUE; /* before potential message */
1267.                 encumber_msg();
1268.             }
1269.             if (u.uhunger < 900)
1270.                 init_uhunger();
1271.             /* luck couldn't have been negative at start of prayer because
1272.                the prayer would have failed, but might have been decremented
1273.                due to a timed event (delayed death of peaceful monster hit
1274.                by hero-created stinking cloud) during the praying interval */
1275.             if (u.uluck < 0)
1276.                 u.uluck = 0;
1277.             /* superfluous; if hero was blinded we'd be handling trouble
1278.                rather than issuing a pat-on-head */
1279.             u.ucreamed = 0;
1280.             make_blinded(0L, TRUE);
1281.             disp.botl = TRUE;
1282.             break;
1283.         case 4: {
1284.             struct obj *otmp, *nextobj;
1285.             int any = 0;
1286. 
1287.             if (Blind)
1288.                 You_feel("the power of %s.", u_gname());
1289.             else
1290.                 You("are surrounded by %s aura.", an(hcolor(NH_LIGHT_BLUE)));
1291.             for (otmp = gi.invent; otmp; otmp = nextobj) {
1292.                 nextobj = otmp->nobj;
1293.                 if (otmp->cursed
1294.                     && (otmp != uarmh /* [see worst_cursed_item()] */
1295.                         || uarmh->otyp != HELM_OF_OPPOSITE_ALIGNMENT)) {
1296.                     if (!Blind) {
1297.                         pline("%s %s.", Yobjnam2(otmp, "softly glow"),
1298.                               hcolor(NH_AMBER));
1299.                         iflags.last_msg = PLNMSG_OBJ_GLOWS;
1300.                         otmp->bknown = 1; /* ok to bypass set_bknown() */
1301.                         ++any;
1302.                     }
1303.                     uncurse(otmp);
1304.                 }
1305.             }
1306.             if (any)
1307.                 update_inventory();
1308.             break;
1309.         }
1310.         case 5: {
1311.             static NEARDATA const char msg[] =
1312.                 "\"and thus I grant thee the gift of %s!\"";
1313. 
1314.             godvoice(u.ualign.type,
1315.                      "Thou hast pleased me with thy progress,");
1316.             if (!(HTelepat & INTRINSIC)) {
1317.                 HTelepat |= FROMOUTSIDE;
1318.                 pline(msg, "Telepathy");
1319.                 if (Blind)
1320.                     see_monsters();
1321.             } else if (!(HFast & INTRINSIC)) {
1322.                 HFast |= FROMOUTSIDE;
1323.                 pline(msg, "Speed");
1324.             } else if (!(HStealth & INTRINSIC)) {
1325.                 HStealth |= FROMOUTSIDE;
1326.                 pline(msg, "Stealth");
1327.             } else {
1328.                 if (!(HProtection & INTRINSIC)) {
1329.                     HProtection |= FROMOUTSIDE;
1330.                     if (!u.ublessed)
1331.                         u.ublessed = rn1(3, 2);
1332.                 } else
1333.                     u.ublessed++;
1334.                 pline(msg, "my protection");
1335.             }
1336.             SetVoice((struct monst *) 0, 0, 80, voice_deity);
1337.             verbalize("Use it wisely in my name!");
1338.             break;
1339.         }
1340.         case 7:
1341.         case 8:
1342.             if (u.ualign.record >= PIOUS && !u.uevent.uhand_of_elbereth) {
1343.                 gcrownu();
1344.                 break;
1345.             }
1346.             FALLTHROUGH;
1347.             /*FALLTHRU*/
1348.         case 6:
1349.             give_spell();
1350.             break;
1351.         default:
1352.             impossible("Confused deity!");
1353.             break;
1354.         }
1355. 
1356.     u.ublesscnt = rnz(350);
1357.     kick_on_butt = u.uevent.udemigod ? 1 : 0;
1358.     if (u.uevent.uhand_of_elbereth)
1359.         kick_on_butt++;
1360.     if (kick_on_butt)
1361.         u.ublesscnt += kick_on_butt * rnz(1000);
1362. 
1363.     /* Avoid games that go into infinite loops of copy-pasted commands
1364.        with no human interaction; this is a DoS vector against the
1365.        computer running NetHack.  Once the turn counter is over 100000,
1366.        every additional 100 turns increases the prayer timeout by 1,
1367.        thus eventually hunger prayers will fail and some other source
1368.        of nutrition will be required.  The increase gets throttled if
1369.        it ever reaches 32K so that configurations using 16-bit ints are
1370.        still viable. */
1371.     if (svm.moves > 100000L) {
1372.         long incr = (svm.moves - 100000L) / 100L,
1373.              largest_ublesscnt_incr = (long) (LARGEST_INT - u.ublesscnt);
1374. 
1375.         if (incr > largest_ublesscnt_incr)
1376.             incr = largest_ublesscnt_incr;
1377.         u.ublesscnt += (int) incr;
1378.     }
1379. 
1380.     return;
1381. }
1382. 
1383. /* either blesses or curses water on the altar,
1384.  * returns true if it found any water here.
1385.  */
1386. staticfn boolean
1387. water_prayer(boolean bless_water)
1388. {
1389.     struct obj *otmp;
1390.     long changed = 0;
1391.     boolean other = FALSE, bc_known = !(Blind || Hallucination);
1392. 
1393.     for (otmp = svl.level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) {
1394.         /* turn water into (un)holy water */
1395.         if (otmp->otyp == POT_WATER
1396.             && (bless_water ? !otmp->blessed : !otmp->cursed)) {
1397.             otmp->blessed = bless_water;
1398.             otmp->cursed = !bless_water;
1399.             otmp->bknown = bc_known; /* ok to bypass set_bknown() */
1400.             changed += otmp->quan;
1401.         } else if (otmp->oclass == POTION_CLASS)
1402.             other = TRUE;
1403.     }
1404.     if (!Blind && changed) {
1405.         pline("%s potion%s on the altar glow%s %s for a moment.",
1406.               ((other && changed > 1L) ? "Some of the"
1407.                                        : (other ? "One of the" : "The")),
1408.               ((other || changed > 1L) ? "s" : ""), (changed > 1L ? "" : "s"),
1409.               (bless_water ? hcolor(NH_LIGHT_BLUE) : hcolor(NH_BLACK)));
1410.     }
1411.     return (boolean) (changed > 0L);
1412. }
1413. 
1414. staticfn void
1415. godvoice(aligntyp g_align, const char *words)
1416. {
1417.     const char *quot = "";
1418. 
1419.     if (words)
1420.         quot = "\"";
1421.     else
1422.         words = "";
1423. 
1424.     pline_The("voice of %s %s: %s%s%s", align_gname(g_align),
1425.               ROLL_FROM(godvoices), quot, words, quot);
1426. }
1427. 
1428. staticfn void
1429. gods_angry(aligntyp g_align)
1430. {
1431.     godvoice(g_align, "Thou hast angered me.");
1432. }
1433. 
1434. /* The g_align god is upset with you. */
1435. staticfn void
1436. gods_upset(aligntyp g_align)
1437. {
1438.     if (g_align == u.ualign.type)
1439.         u.ugangr++;
1440.     else if (u.ugangr)
1441.         u.ugangr--;
1442.     angrygods(g_align);
1443. }
1444. 
1445. staticfn void
1446. consume_offering(struct obj *otmp)
1447. {
1448.     if (Hallucination)
1449.         switch (rn2(3)) {
1450.         case 0:
1451.             Your("sacrifice sprouts wings and a propeller and roars away!");
1452.             break;
1453.         case 1:
1454.             Your("sacrifice puffs up, swelling bigger and bigger, and pops!");
1455.             break;
1456.         case 2:
1457.             Your(
1458.      "sacrifice collapses into a cloud of dancing particles and fades away!");
1459.             break;
1460.         }
1461.     else if (Blind && u.ualign.type == A_LAWFUL)
1462.         Your("sacrifice disappears!");
1463.     else
1464.         Your("sacrifice is consumed in a %s!",
1465.              (u.ualign.type == A_LAWFUL)
1466.                 ? "flash of light"
1467.                 : (u.ualign.type == A_NEUTRAL)
1468.                     ? "plume of smoke"
1469.                     : "burst of flame");
1470.     if (carried(otmp))
1471.         useup(otmp);
1472.     else
1473.         useupf(otmp, 1L);
1474.     exercise(A_WIS, TRUE);
1475. }
1476. 
1477. /* feedback when attempting to offer the Amulet on a "low altar" (not one of
1478.    the high altars in the temples on the Astral Plane or Moloch's Sanctum) */
1479. staticfn void
1480. offer_too_soon(aligntyp altaralign)
1481. {
1482.     if (altaralign == A_NONE && Inhell) {
1483.         /* offering on an unaligned altar in Gehennom;
1484.            hero has left Moloch's Sanctum (caller handles that)
1485.            so is in the process of getting away with the Amulet;
1486.            for any unaligned altar outside of Gehennom, give the
1487.            "you feel ashamed" feedback for wrong alignment below */
1488.         gods_upset(A_NONE); /* Moloch becomes angry */
1489.         return;
1490.     }
1491.     You_feel("%s.", Hallucination
1492.                     ? "homesick"
1493.                     /* if on track, give a big hint */
1494.                     : (altaralign == u.ualign.type)
1495.                         ? "an urge to return to the surface"
1496.                         /* else headed towards celestial disgrace */
1497.                         : "ashamed");
1498. }
1499. 
1500. void
1501. desecrate_altar(boolean highaltar, aligntyp altaralign)
1502. {
1503.     char gvbuf[BUFSZ];
1504. 
1505.     /*
1506.      * REAL BAD NEWS!!! High altars cannot be converted.  Even an attempt
1507.      * gets the god who owns it truly pissed off.  The same effect for
1508.      * deliberately destroying a normal altar.
1509.      */
1510.     /* if you did this to your own altar, your god will hold a grudge... */
1511.     if (altaralign == u.ualign.type) {
1512.         adjalign(-20);
1513.         u.ugangr += 5;
1514.     }
1515.     You_feel("the air around you grow charged...");
1516.     pline("Suddenly, you realize that %s has noticed you...",
1517.           align_gname(altaralign));
1518.     Sprintf(gvbuf, "So, mortal!  You dare desecrate my %s!",
1519.             highaltar ? "High Temple" : "altar");
1520.     godvoice(altaralign, gvbuf);
1521.     /* Throw everything we have at the player */
1522.     god_zaps_you(altaralign);
1523. }
1524. 
1525. /* offering the Amulet on a high altar (checked by caller) ends the game;
1526.    we don't declare this 'NORETURN' because done() can return (if called
1527.    with some reasons other than ASCENDED and ESCAPED) */
1528. staticfn void
1529. offer_real_amulet(struct obj *otmp, aligntyp altaralign)
1530. {
1531.     static NEARDATA const char
1532.         cloud_of_smoke[] = "A cloud of %s smoke surrounds you...";
1533. 
1534.     /* The final Test.  Did you win? */
1535.     if (uamul == otmp)
1536.         Amulet_off();
1537.     if (carried(otmp))
1538.         useup(otmp); /* well, it's gone now */
1539.     else
1540.         useupf(otmp, 1L);
1541. 
1542.     You("offer the Amulet of Yendor to %s...", a_gname());
1543. 
1544.     if (altaralign == A_NONE) {
1545.         /* Moloch's high altar at the bottom of Gehennom. */
1546.         if (u.ualign.record > -99)
1547.             u.ualign.record = -99;
1548.         pline("An invisible choir chants, and you are bathed in darkness...");
1549.         /*[apparently shrug/snarl can be sensed without being seen]*/
1550.         pline("%s shrugs and retains dominion over %s,", Moloch, u_gname());
1551.         pline("then mercilessly snuffs out your life.");
1552.         Sprintf(svk.killer.name, "%s indifference", s_suffix(Moloch));
1553.         svk.killer.format = KILLED_BY;
1554.         done(DIED);
1555.         /* life-saved (or declined to die in wizard/explore mode) */
1556.         pline("%s snarls and tries again...", Moloch);
1557.         fry_by_god(A_NONE, TRUE); /* wrath of Moloch */
1558.         /* declined to die in wizard or explore mode */
1559.         pline(cloud_of_smoke, hcolor(NH_BLACK));
1560.         done(ESCAPED);
1561.         /*NOTREACHED*/
1562.     } else if (u.ualign.type != altaralign) {
1563.         /* And the opposing team picks you up and carries you off
1564.            on their shoulders. */
1565.         adjalign(-99);
1566.         pline("%s accepts your gift, and gains dominion over %s...",
1567.               a_gname(), u_gname());
1568.         pline("%s is enraged...", u_gname());
1569.         pline("Fortunately, %s permits you to live...", a_gname());
1570.         pline(cloud_of_smoke, hcolor(NH_ORANGE));
1571.         done(ESCAPED);
1572.         /*NOTREACHED*/
1573.     } else {
1574.         /* You've won the game!  Feedback-wise, it's a bit of a let down. */
1575.         u.uevent.ascended = 1;
1576.         adjalign(10);
1577.         pline("An invisible choir sings, and you are bathed in radiance...");
1578.         godvoice(altaralign, "Mortal, thou hast done well!");
1579.         display_nhwindow(WIN_MESSAGE, FALSE);
1580.         SetVoice((struct monst *) 0, 0, 80, voice_deity);
1581.         verbalize(
1582.           "In return for thy service, I grant thee the gift of Immortality!");
1583.         You("ascend to the status of Demigod%s...",
1584.             flags.female ? "dess" : "");
1585.         done(ASCENDED);
1586.         /*NOTREACHED*/
1587.     }
1588.     /*NOTREACHED*/
1589. }
1590. 
1591. staticfn void
1592. offer_negative_valued(boolean highaltar, aligntyp altaralign)
1593. {
1594.     if (altaralign != u.ualign.type && highaltar) {
1595.         desecrate_altar(highaltar, altaralign);
1596.     } else {
1597.         gods_upset(altaralign);
1598.     }
1599. }
1600. 
1601. staticfn void
1602. offer_fake_amulet(
1603.     struct obj *otmp,
1604.     boolean highaltar,
1605.     aligntyp altaralign)
1606. {
1607.     if (!highaltar && !otmp->known) {
1608.         offer_too_soon(altaralign);
1609.         return;
1610.     }
1611.     Soundeffect(se_thunderclap, 100);
1612.     You_hear("a nearby thunderclap.");
1613.     if (!otmp->known) {
1614.         You("realize you have made a %s.",
1615.             Hallucination ? "boo-boo" : "mistake");
1616.         otmp->known = TRUE;
1617.         change_luck(-1);
1618.     } else {
1619.         /* don't you dare try to fool the gods */
1620.         if (Deaf)
1621.             pline("Oh, no."); /* didn't hear thunderclap */
1622.         change_luck(-3);
1623.         adjalign(-1);
1624.         u.ugangr += 3;
1625.         offer_negative_valued(highaltar, altaralign);
1626.     }
1627. }
1628. 
1629. /* possibly convert an altar's alignment or the hero's alignment */
1630. staticfn void
1631. offer_different_alignment_altar(
1632.     struct obj *otmp,
1633.     aligntyp altaralign)
1634. {
1635.     /* Is this a conversion ? */
1636.     /* An unaligned altar in Gehennom will always elicit rejection. */
1637.     if (ugod_is_angry() || (altaralign == A_NONE && Inhell)) {
1638.         if (u.ualignbase[A_CURRENT] == u.ualignbase[A_ORIGINAL]
1639.             && altaralign != A_NONE) {
1640.             You("have a strong feeling that %s is angry...", u_gname());
1641.             consume_offering(otmp);
1642.             pline("%s accepts your allegiance.", a_gname());
1643. 
1644.             uchangealign(altaralign, A_CG_CONVERT);
1645.             /* Beware, Conversion is costly */
1646.             change_luck(-3);
1647.             u.ublesscnt += 300;
1648.         } else {
1649.             u.ugangr += 3;
1650.             adjalign(-5);
1651.             pline("%s rejects your sacrifice!", a_gname());
1652.             godvoice(altaralign, "Suffer, infidel!");
1653.             change_luck(-5);
1654.             (void) adjattrib(A_WIS, -2, TRUE);
1655.             if (!Inhell)
1656.                 angrygods(u.ualign.type);
1657.         }
1658.     } else {
1659.         consume_offering(otmp);
1660.         You("sense a conflict between %s and %s.", u_gname(), a_gname());
1661.         if (rn2(8 + u.ulevel) > 5) {
1662.             struct monst *pri;
1663.             boolean shrine;
1664. 
1665.             You_feel("the power of %s increase.", u_gname());
1666.             exercise(A_WIS, TRUE);
1667.             change_luck(1);
1668.             shrine = on_shrine();
1669.             levl[u.ux][u.uy].altarmask = Align2amask(u.ualign.type);
1670.             if (shrine)
1671.                 levl[u.ux][u.uy].altarmask |= AM_SHRINE;
1672.             newsym(u.ux, u.uy); /* in case Invisible to self */
1673.             if (!Blind)
1674.                 pline_The("altar glows %s.",
1675.                           hcolor((u.ualign.type == A_LAWFUL) ? NH_WHITE
1676.                                  : u.ualign.type ? NH_BLACK
1677.                                    : (const char *) "gray"));
1678. 
1679.             if (rnl(u.ulevel) > 6 && u.ualign.record > 0
1680.                 && rnd(u.ualign.record) > (3 * ALIGNLIM) / 4)
1681.                 summon_minion(altaralign, TRUE);
1682.             /* anger priest; test handles bones files */
1683.             if ((pri = findpriest(temple_occupied(u.urooms)))
1684.                 && !p_coaligned(pri))
1685.                 angry_priest();
1686.         } else {
1687.             pline("Unluckily, you feel the power of %s decrease.", u_gname());
1688.             change_luck(-1);
1689.             exercise(A_WIS, FALSE);
1690.             if (rnl(u.ulevel) > 6 && u.ualign.record > 0
1691.                 && rnd(u.ualign.record) > (7 * ALIGNLIM) / 8)
1692.                 summon_minion(altaralign, TRUE);
1693.         }
1694.     }
1695. }
1696. 
1697. staticfn void
1698. sacrifice_your_race(
1699.     struct obj *otmp,
1700.     boolean highaltar,
1701.     aligntyp altaralign)
1702. {
1703.     int pm;
1704. 
1705.     if (is_demon(gy.youmonst.data)) {
1706.         You("find the idea very satisfying.");
1707.         exercise(A_WIS, TRUE);
1708.     } else if (u.ualign.type != A_CHAOTIC) {
1709.         pline("You'll regret this infamous offense!");
1710.         exercise(A_WIS, FALSE);
1711.     }
1712. 
1713.     if (highaltar
1714.         && (altaralign != A_CHAOTIC || u.ualign.type != A_CHAOTIC)) {
1715.         desecrate_altar(highaltar, altaralign);
1716.         return;
1717.     } else if (altaralign != A_CHAOTIC && altaralign != A_NONE) {
1718.         /* curse the lawful/neutral altar */
1719.         pline_The("altar is stained with %s blood.", gu.urace.adj);
1720.         levl[u.ux][u.uy].altarmask = AM_CHAOTIC;
1721.         newsym(u.ux, u.uy); /* in case Invisible to self */
1722.         angry_priest();
1723.     } else {
1724.         struct monst *dmon;
1725.         const char *demonless_msg;
1726. 
1727.         /* Human sacrifice on a chaotic or unaligned altar */
1728.         /* is equivalent to demon summoning */
1729.         if (altaralign == A_CHAOTIC && u.ualign.type != A_CHAOTIC) {
1730.             pline(
1731.             "The blood floods the altar, which vanishes in %s cloud!",
1732.                     an(hcolor(NH_BLACK)));
1733.             levl[u.ux][u.uy].typ = ROOM;
1734.             levl[u.ux][u.uy].altarmask = 0;
1735.             newsym(u.ux, u.uy);
1736.             angry_priest();
1737.             demonless_msg = "cloud dissipates";
1738.         } else {
1739.             /* either you're chaotic or altar is Moloch's or both */
1740.             pline_The("blood covers the altar!");
1741.             change_luck(altaralign == A_NONE ? -2 : 2);
1742.             demonless_msg = "blood coagulates";
1743.         }
1744.         if ((pm = dlord(altaralign)) != NON_PM
1745.             && (dmon = makemon(&mons[pm], u.ux, u.uy, MM_NOMSG))
1746.                     != 0) {
1747.             char dbuf[BUFSZ];
1748. 
1749.             Strcpy(dbuf, a_monnam(dmon));
1750.             if (!strcmpi(dbuf, "it"))
1751.                 Strcpy(dbuf, "something dreadful");
1752.             else
1753.                 dmon->mstrategy &= ~STRAT_APPEARMSG;
1754.             You("have summoned %s!", dbuf);
1755.             if (sgn(u.ualign.type) == sgn(dmon->data->maligntyp))
1756.                 dmon->mpeaceful = TRUE;
1757.             You("are terrified, and unable to move.");
1758.             nomul(-3);
1759.             gm.multi_reason = "being terrified of a demon";
1760.             gn.nomovemsg = 0;
1761.         } else
1762.             pline_The("%s.", demonless_msg);
1763.     }
1764. 
1765.     if (u.ualign.type != A_CHAOTIC) {
1766.         adjalign(-5);
1767.         u.ugangr += 3;
1768.         (void) adjattrib(A_WIS, -1, TRUE);
1769.         if (!Inhell)
1770.             angrygods(u.ualign.type);
1771.         change_luck(-5);
1772.     } else
1773.         adjalign(5);
1774.     if (carried(otmp))
1775.         useup(otmp);
1776.     else
1777.         useupf(otmp, 1L);
1778. }
1779. 
1780. staticfn int
1781. bestow_artifact(uchar max_giftvalue)
1782. {
1783.     int nartifacts = nartifact_exist();
1784.     boolean do_bestow = u.ulevel > 2 && u.uluck >= 0;
1785.     if (do_bestow) {
1786.         /* you were already in pretty good standing */
1787.         /* The player can gain an artifact */
1788.         /* The chance goes down as the number of artifacts goes up */
1789.         if (wizard)
1790.             do_bestow = y_n("Gift an artifact?") == 'y';
1791.         else
1792.             do_bestow = !rn2(6 + (2 * u.ugifts * nartifacts));
1793.     }
1794. 
1795.     if (do_bestow) {
1796.         struct obj *otmp;
1797.         /* mk_artifact() with NULL obj and a_align() arg can return NULL */
1798.         otmp = mk_artifact((struct obj *) 0, a_align(u.ux, u.uy),
1799.                            max_giftvalue, TRUE);
1800.         if (otmp) {
1801.             char buf[BUFSZ];
1802. 
1803.             artifact_origin(otmp, ONAME_GIFT | ONAME_KNOW_ARTI);
1804.             if (otmp->spe < 0)
1805.                 otmp->spe = 0;
1806.             if (otmp->cursed)
1807.                 uncurse(otmp);
1808.             otmp->oerodeproof = TRUE;
1809.             Strcpy(buf, (Hallucination ? "a doodad"
1810.                             : Blind ? "an object"
1811.                             : ansimpleoname(otmp)));
1812.             if (!Blind)
1813.                 Sprintf(eos(buf), " named %s",
1814.                         bare_artifactname(otmp));
1815.             at_your_feet(upstart(buf));
1816.             dropy(otmp);
1817.             godvoice(u.ualign.type, "Use my gift wisely!");
1818.             u.ugifts++;
1819.             u.ublesscnt = rnz(300 + (50 * nartifacts));
1820.             exercise(A_WIS, TRUE);
1821.             livelog_printf (LL_DIVINEGIFT | LL_ARTIFACT,
1822.                             "was bestowed with %s by %s",
1823.                             artiname(otmp->oartifact),
1824.                             align_gname(u.ualign.type));
1825.             /* make sure we can use this weapon */
1826.             unrestrict_weapon_skill(weapon_type(otmp));
1827.             if (!Hallucination && !Blind) {
1828.                 observe_object(otmp);
1829.                 makeknown(otmp->otyp);
1830.                 discover_artifact(otmp->oartifact);
1831.             }
1832.             return TRUE;
1833.         }
1834.     }
1835.     return FALSE;
1836. }
1837. 
1838. staticfn int
1839. sacrifice_value(struct obj *otmp)
1840. {
1841.     int value = 0;
1842. 
1843.     if (otmp->corpsenm == PM_ACID_BLOB
1844.         || (svm.moves <= peek_at_iced_corpse_age(otmp) + 50)) {
1845.         value = mons[otmp->corpsenm].difficulty + 1;
1846.         if (otmp->oeaten)
1847.             value = eaten_stat(value, otmp);
1848.     }
1849.     return value;
1850. }
1851. 
1852. /* the #offer command - sacrifice something to the gods */
1853. int
1854. dosacrifice(void)
1855. {
1856.     struct obj *otmp;
1857.     boolean highaltar;
1858.     aligntyp altaralign = a_align(u.ux, u.uy);
1859. 
1860.     if (!on_altar() || u.uswallow) {
1861.         You("are not %s an altar.",
1862.             (Levitation || Flying) ? "over" : "on");
1863.         return ECMD_OK;
1864.     } else if (Confusion || Stunned) {
1865.         You("are too impaired to perform the rite.");
1866.         return ECMD_OK;
1867.     }
1868.     highaltar = (levl[u.ux][u.uy].altarmask & AM_SANCTUM);
1869. 
1870.     otmp = floorfood("sacrifice", 1);
1871.     if (!otmp)
1872.         return ECMD_OK;
1873. 
1874.     if (otmp->otyp == AMULET_OF_YENDOR) {
1875.         if (!highaltar) {
1876.             offer_too_soon(altaralign);
1877.             return ECMD_TIME;
1878.         } else {
1879.             offer_real_amulet(otmp, altaralign);
1880.             /*NOTREACHED*/
1881.         }
1882.     } /* real Amulet */
1883. 
1884.     if (otmp->otyp == FAKE_AMULET_OF_YENDOR) {
1885.         offer_fake_amulet(otmp, highaltar, altaralign);
1886.         return ECMD_TIME;
1887.     } /* fake Amulet */
1888. 
1889.     if (otmp->otyp == CORPSE) {
1890.         offer_corpse(otmp, highaltar, altaralign);
1891.         return ECMD_TIME;
1892.     }
1893. 
1894.     pline1(nothing_happens);
1895.     return ECMD_TIME;
1896. }
1897. 
1898. staticfn int
1899. eval_offering(struct obj *otmp, aligntyp altaralign)
1900. {
1901.     struct permonst *ptr;
1902.     int value;
1903. 
1904.     value = sacrifice_value(otmp);
1905. 
1906.     if (!value)
1907.         return 0;
1908. 
1909.     ptr = &mons[otmp->corpsenm];
1910. 
1911.     if (is_undead(ptr)) { /* Not demons--no demon corpses */
1912.         /* most undead that leave a corpse yield 'human' (or other race)
1913.            corpse so won't get here; the exception is wraith; give the
1914.            bonus for wraith to chaotics too because they are sacrificing
1915.            something valuable (unless hero refuses to eat such things) */
1916.         if (u.ualign.type != A_CHAOTIC
1917.             /* reaching this side of the 'or' means hero is chaotic */
1918.             || (ptr == &mons[PM_WRAITH] && u.uconduct.unvegetarian))
1919.             value += 1;
1920.     } else if (is_unicorn(ptr)) {
1921.         int unicalign = sgn(ptr->maligntyp);
1922. 
1923.         if (unicalign == altaralign) {
1924.             /* When same as altar, always a very bad action.
1925.              */
1926.             pline("Such an action is an insult to %s!",
1927.                   (unicalign == A_CHAOTIC) ? "chaos"
1928.                      : unicalign ? "law" : "balance");
1929.             (void) adjattrib(A_WIS, -1, TRUE);
1930.             return -1;
1931.         } else if (u.ualign.type == altaralign) {
1932.             /* When different from altar, and altar is same as yours,
1933.              * it's a very good action.
1934.              */
1935.             if (u.ualign.record < ALIGNLIM)
1936.                 You_feel("appropriately %s.", align_str(u.ualign.type));
1937.             else
1938.                 You_feel("you are thoroughly on the right path.");
1939.             adjalign(5);
1940.             value += 3;
1941.         } else if (unicalign == u.ualign.type) {
1942.             /* When sacrificing unicorn of your alignment to altar not of
1943.              * your alignment, your god gets angry and it's a conversion.
1944.              */
1945.             u.ualign.record = -1;
1946.             value = 1;
1947.         } else {
1948.             /* Otherwise, unicorn's alignment is different from yours
1949.              * and different from the altar's.  It's an ordinary (well,
1950.              * with a bonus) sacrifice on a cross-aligned altar.
1951.              */
1952.             value += 3;
1953.         }
1954.     }
1955.     return value;
1956. }
1957. 
1958. staticfn void
1959. offer_corpse(struct obj *otmp, boolean highaltar, aligntyp altaralign)
1960. {
1961.     int value;
1962.     struct permonst *ptr;
1963.     struct monst *mtmp;
1964. 
1965.     /*
1966.      * Was based on nutritional value and aging behavior (< 50 moves).
1967.      * Sacrificing a food ration got you max luck instantly, making the
1968.      * gods as easy to please as an angry dog!
1969.      *
1970.      * Now only accepts corpses, based on the game's evaluation of their
1971.      * toughness.  Human and pet sacrifice, as well as sacrificing unicorns
1972.      * of your alignment, is strongly discouraged.
1973.      */
1974. #define MAXVALUE 24 /* Highest corpse value (besides Wiz) */
1975. 
1976.     /* KMH, conduct */
1977.     if (!u.uconduct.gnostic++)
1978.         livelog_printf(LL_CONDUCT, "rejected atheism"
1979.                                    " by offering %s on an altar of %s",
1980.                        corpse_xname(otmp, (const char *) 0, CXN_ARTICLE),
1981.                        a_gname());
1982. 
1983.     /* you're handling this corpse, even if it was killed upon the altar
1984.      */
1985.     feel_cockatrice(otmp, TRUE);
1986.     if (rider_corpse_revival(otmp, FALSE))
1987.         return;
1988. 
1989.     ptr = &mons[otmp->corpsenm];
1990. 
1991.     /* same race or former pet results apply even if the corpse is
1992.        too old (value==0) */
1993.     if (your_race(ptr)) {
1994.         sacrifice_your_race(otmp, highaltar, altaralign);
1995.         return;
1996.     }
1997.     if (has_omonst(otmp)
1998.                && (mtmp = get_mtraits(otmp, FALSE)) != 0
1999.                && mtmp->mtame) {
2000.             /* mtmp is a temporary pointer to a tame monster's attributes,
2001.              * not a real monster */
2002.         pline("So this is how you repay loyalty?");
2003.         adjalign(-3);
2004.         HAggravate_monster |= FROMOUTSIDE;
2005.         offer_negative_valued(highaltar, altaralign);
2006.         return;
2007.     }
2008. 
2009.     value = eval_offering(otmp, altaralign);
2010.     if (value == 0) {
2011.         /* too old; don't give undead or unicorn bonus or penalty */
2012.         pline1(nothing_happens);
2013.         return;
2014.     }
2015.     if (value < 0) {
2016.         offer_negative_valued(highaltar, altaralign);
2017.         return;
2018.     }
2019. 
2020.     if (altaralign != u.ualign.type && highaltar) {
2021.         desecrate_altar(highaltar, altaralign);
2022.         return;
2023.     }
2024.     if (u.ualign.type != altaralign) {
2025.         /* Sacrificing at an altar of a different alignment */
2026.         offer_different_alignment_altar(otmp, altaralign);
2027.         return;
2028.     }
2029.     consume_offering(otmp);
2030.     /* OK, you get brownie points. */
2031.     if (u.ugangr) {
2032.         int saved_anger = u.ugangr;
2033.         u.ugangr -= ((value * (u.ualign.type == A_CHAOTIC ? 2 : 3))
2034.                      / MAXVALUE);
2035.         if (u.ugangr < 0)
2036.             u.ugangr = 0;
2037.         if (u.ugangr != saved_anger) {
2038.             if (u.ugangr) {
2039.                 pline("%s seems %s.", u_gname(),
2040.                       Hallucination ? "groovy" : "slightly mollified");
2041. 
2042.                 if ((int) u.uluck < 0)
2043.                     change_luck(1);
2044.             } else {
2045.                 pline("%s seems %s.", u_gname(),
2046.                       Hallucination ? "cosmic (not a new fact)"
2047.                                     : "mollified");
2048. 
2049.                 if ((int) u.uluck < 0)
2050.                     u.uluck = 0;
2051.             }
2052.         } else { /* not satisfied yet */
2053.             if (Hallucination)
2054.                 pline_The("gods seem tall.");
2055.             else
2056.                 You("have a feeling of inadequacy.");
2057.         }
2058.     } else if (ugod_is_angry()) {
2059.         if (value > MAXVALUE)
2060.             value = MAXVALUE;
2061.         if (value > -u.ualign.record)
2062.             value = -u.ualign.record;
2063.         adjalign(value);
2064.         You_feel("partially absolved.");
2065.     } else if (u.ublesscnt > 0) {
2066.         int saved_cnt = u.ublesscnt;
2067.         u.ublesscnt -= ((value * (u.ualign.type == A_CHAOTIC ? 500 : 300))
2068.                         / MAXVALUE);
2069.         if (u.ublesscnt < 0)
2070.             u.ublesscnt = 0;
2071.         if (u.ublesscnt != saved_cnt) {
2072.             if (u.ublesscnt) {
2073.                 if (Hallucination)
2074.                     You("realize that the gods are not like you and I.");
2075.                 else
2076.                     You("have a hopeful feeling.");
2077.                 if ((int) u.uluck < 0)
2078.                     change_luck(1);
2079.             } else {
2080.                 if (Hallucination)
2081.                     pline("Overall, there is a smell of fried onions.");
2082.                 else
2083.                     You("have a feeling of reconciliation.");
2084.                 if ((int) u.uluck < 0)
2085.                     u.uluck = 0;
2086.             }
2087.         }
2088.     } else {
2089.         int orig_luck, luck_increase;
2090. 
2091.         if (bestow_artifact(value))
2092.             return;
2093. 
2094.         orig_luck = u.uluck;
2095.         luck_increase = (value * LUCKMAX) / (MAXVALUE * 2);
2096. 
2097.         /* sacrificing can't increase non-bonus Luck to above the value of the
2098.            sacrifice; this prevents players immediately maxing their Luck as
2099.            soon as they find an altar and a few rations via sacrificing lots
2100.            of low-valued corpses, which can unbalance the early game */
2101.         if (orig_luck > value)
2102.             luck_increase = 0;
2103.         else if (orig_luck + luck_increase > value)
2104.             luck_increase = value - orig_luck;
2105. 
2106.         change_luck(luck_increase);
2107.         if ((int) u.uluck < 0)
2108.             u.uluck = 0;
2109.         if (u.uluck != orig_luck) {
2110.             if (Blind)
2111.                 You("think %s brushed your %s.", something,
2112.                     body_part(FOOT));
2113.             else
2114.                 You(Hallucination
2115.                 ? "see crabgrass at your %s.  A funny thing in a dungeon."
2116.                         : "glimpse a four-leaf clover at your %s.",
2117.                     makeplural(body_part(FOOT)));
2118.         }
2119.     }
2120. }
2121. 
2122. /* determine prayer results in advance; also used for enlightenment */
2123. boolean
2124. can_pray(boolean praying) /* false means no messages should be given */
2125. {
2126.     int alignment;
2127. 
2128.     gp.p_aligntyp = on_altar() ? a_align(u.ux, u.uy) : u.ualign.type;
2129.     gp.p_trouble = in_trouble();
2130. 
2131.     if (is_demon(gy.youmonst.data) /* ok if chaotic or none (Moloch) */
2132.         && (gp.p_aligntyp == A_LAWFUL || gp.p_aligntyp != A_NEUTRAL)) {
2133.         if (praying)
2134.             pline_The("very idea of praying to a %s god is repugnant to you.",
2135.                       gp.p_aligntyp ? "lawful" : "neutral");
2136.         return FALSE;
2137.     }
2138. 
2139.     if (praying)
2140.         You("begin praying to %s.", align_gname(gp.p_aligntyp));
2141. 
2142.     if (u.ualign.type && u.ualign.type == -gp.p_aligntyp)
2143.         alignment = -u.ualign.record; /* Opposite alignment altar */
2144.     else if (u.ualign.type != gp.p_aligntyp)
2145.         alignment = u.ualign.record / 2; /* Different alignment altar */
2146.     else
2147.         alignment = u.ualign.record;
2148. 
2149.     if (gp.p_aligntyp == A_NONE) /* praying to Moloch */
2150.         gp.p_type = -2;
2151.     else if ((gp.p_trouble > 0) ? (u.ublesscnt > 200)   /* big trouble */
2152.              : (gp.p_trouble < 0) ? (u.ublesscnt > 100) /* minor difficulty */
2153.                : (u.ublesscnt > 0))                     /* not in trouble */
2154.         gp.p_type = 0;                     /* too soon... */
2155.     else if ((int) Luck < 0 || u.ugangr || alignment < 0)
2156.         gp.p_type = 1; /* too naughty... */
2157.     else /* alignment >= 0 */ {
2158.         if (on_altar() && u.ualign.type != gp.p_aligntyp)
2159.             gp.p_type = 2;
2160.         else
2161.             gp.p_type = 3;
2162.     }
2163. 
2164.     if (is_undead(gy.youmonst.data) && !Inhell
2165.         && (gp.p_aligntyp == A_LAWFUL
2166.             || (gp.p_aligntyp == A_NEUTRAL && !rn2(10))))
2167.         gp.p_type = -1;
2168.     /* Note:  when !praying, the random factor for neutrals makes the
2169.        return value a non-deterministic approximation for enlightenment.
2170.        This case should be uncommon enough to live with... */
2171. 
2172.     return !praying ? (boolean) (gp.p_type == 3 && !Inhell) : TRUE;
2173. }
2174. 
2175. /* return TRUE if praying revived a pet corpse */
2176. staticfn boolean
2177. pray_revive(void)
2178. {
2179.     struct obj *otmp;
2180. 
2181.     for (otmp = svl.level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere)
2182.         if ((otmp->otyp == CORPSE || otmp->otyp == STATUE)
2183.             && has_omonst(otmp)
2184.             && OMONST(otmp)->mtame && !OMONST(otmp)->isminion)
2185.             break;
2186. 
2187.     if (!otmp)
2188.         return FALSE;
2189. 
2190.     if (otmp->otyp == CORPSE)
2191.         return (revive(otmp, TRUE) != NULL);
2192.     else {
2193.         return (animate_statue(otmp, u.ux, u.uy, ANIMATE_SPELL, NULL) != NULL);
2194.     }
2195. }
2196. 
2197. /* #pray command */
2198. int
2199. dopray(void)
2200. {
2201.     boolean ok;
2202. 
2203.     /*
2204.      * If ParanoidPray is set, confirm prayer to avoid accidental slips
2205.      * of Alt+p.  If ParanoidConfirm is also set, require "yes" rather
2206.      * than just "y" (will also require "no" to decline).
2207.      */
2208.     if (ParanoidPray) {
2209.         ok = paranoid_query(ParanoidConfirm,
2210.                             "Are you sure you want to pray?");
2211. #if 0
2212.         /* clear command recall buffer; otherwise ^A to repeat p(ray) would
2213.            do so without confirmation (if 'ok') or do nothing (if '!ok') */
2214.         cmdq_clear(CQ_REPEAT);
2215.         cmdq_add_ec(CQ_REPEAT, dopray);
2216. #endif
2217.         if (!ok) /* declined the "are you sure?" confirmation */
2218.             return ECMD_OK;
2219.     }
2220. 
2221.     if (!u.uconduct.gnostic++)
2222.         /* breaking conduct should probably occur in can_pray() at
2223.          * "You begin praying to %s", as demons who find praying repugnant
2224.          * should not break conduct.  Also we can add more detail to the
2225.          * livelog message as p_aligntyp will be known.
2226.          */
2227.         livelog_printf(LL_CONDUCT, "rejected atheism with a prayer");
2228. 
2229.     /* set up p_type and p_alignment */
2230.     if (!can_pray(TRUE))
2231.         return ECMD_OK;
2232. 
2233.     if (wizard && gp.p_type >= 0) {
2234.         static const char forcesuccess[] = "Force the gods to be pleased?";
2235. 
2236.         /* if we asked "are you sure?" above we suppressed the response
2237.            from the do-again buffer, so need to suppress this response too;
2238.            otherwise subsequent ^A would use this answer for "are you sure?"
2239.            and bypass confirmation */
2240.         if (ParanoidPray) {
2241.             boolean save_doagain = gi.in_doagain;
2242. 
2243.             gi.in_doagain = FALSE;
2244.             ok = (YN(forcesuccess) == 'y');
2245.             gi.in_doagain = save_doagain;
2246.         } else {
2247.             ok = (y_n(forcesuccess) == 'y');
2248.         }
2249.         if (ok) {
2250.             u.ublesscnt = 0;
2251.             if (u.uluck < 0)
2252.                 u.uluck = 0;
2253.             if (u.ualign.record <= 0)
2254.                 u.ualign.record = 1;
2255.             u.ugangr = 0;
2256.             if (gp.p_type < 2)
2257.                 gp.p_type = 3;
2258.         }
2259.     }
2260.     nomul(-3);
2261.     gm.multi_reason = "praying";
2262.     gn.nomovemsg = "You finish your prayer.";
2263.     ga.afternmv = prayer_done;
2264. 
2265.     if (gp.p_type == 3 && !Inhell) {
2266.         /* if you've been true to your god you can't die while you pray */
2267.         if (!Blind)
2268.             You("are surrounded by a shimmering light.");
2269.         u.uinvulnerable = TRUE;
2270.     }
2271. 
2272.     return ECMD_TIME;
2273. }
2274. 
2275. staticfn int
2276. prayer_done(void) /* M. Stephenson (1.0.3b) */
2277. {
2278.     aligntyp alignment = gp.p_aligntyp;
2279. 
2280.     u.uinvulnerable = FALSE;
2281.     if (gp.p_type == -2) {
2282.         /* praying at an unaligned altar, not necessarily in Gehennom */
2283.         You("%s diabolical laughter all around you...",
2284.             !Deaf ? "hear" : "intuit");
2285.         wake_nearby(FALSE);
2286.         adjalign(-2);
2287.         exercise(A_WIS, FALSE);
2288.         if (!Inhell) {
2289.             /* hero's god[dess] seems to be keeping his/her head down */
2290.             pline("Nothing else happens."); /* not actually true... */
2291.             return 1;
2292.         } /* else use regular Inhell result below */
2293.     } else if (gp.p_type == -1) {
2294.         /* praying while poly'd into an undead creature while non-chaotic */
2295.         godvoice(alignment,
2296.                  (alignment == A_LAWFUL)
2297.                     ? "Vile creature, thou durst call upon me?"
2298.                     : "Walk no more, perversion of nature!");
2299.         You_feel("like you are falling apart.");
2300.         /* KMH -- Gods have mastery over unchanging */
2301.         rehumanize();
2302.         /* no Half_physical_damage adjustment here */
2303.         losehp(rnd(20), "residual undead turning effect", KILLED_BY_AN);
2304.         exercise(A_CON, FALSE);
2305.         return 1;
2306.     }
2307.     if (Inhell) {
2308.         pline("Since you are in Gehennom, %s can't help you.",
2309.               align_gname(alignment));
2310.         /* haltingly aligned is least likely to anger */
2311.         if (u.ualign.record <= 0 || rnl(u.ualign.record))
2312.             angrygods(u.ualign.type);
2313.         return 0;
2314.     }
2315. 
2316.     if (gp.p_type == 0) {
2317.         if (on_altar() && u.ualign.type != alignment)
2318.             (void) water_prayer(FALSE);
2319.         u.ublesscnt += rnz(250);
2320.         change_luck(-3);
2321.         gods_upset(u.ualign.type);
2322.     } else if (gp.p_type == 1) {
2323.         if (on_altar() && u.ualign.type != alignment)
2324.             (void) water_prayer(FALSE);
2325.         angrygods(u.ualign.type); /* naughty */
2326.     } else if (gp.p_type == 2) {
2327.         if (water_prayer(FALSE)) {
2328.             /* attempted water prayer on a non-coaligned altar */
2329.             u.ublesscnt += rnz(250);
2330.             change_luck(-3);
2331.             gods_upset(u.ualign.type);
2332.         } else
2333.             pleased(alignment);
2334.     } else {
2335.         /* coaligned */
2336.         if (on_altar()) {
2337.             (void) pray_revive();
2338.             (void) water_prayer(TRUE);
2339.         }
2340.         pleased(alignment); /* nice */
2341.     }
2342.     return 1;
2343. }
2344. 
2345. /* iterable for undead turning by priest/knight */
2346. staticfn void
2347. maybe_turn_mon_iter(struct monst *mtmp)
2348. {
2349.     /* 3.6.3: used to use cansee() here but the purpose is to prevent
2350.        #turn operating through walls, not to require that the hero be
2351.        able to see the target location */
2352.     if (!couldsee(mtmp->mx, mtmp->my)
2353.         || mdistu(mtmp) > turn_undead_range)
2354.         return;
2355. 
2356.     if (!mtmp->mpeaceful
2357.         && (is_undead(mtmp->data) || is_vampshifter(mtmp)
2358.             || (is_demon(mtmp->data) && (u.ulevel > (MAXULEV / 2))))) {
2359.         mtmp->msleeping = 0;
2360.         if (Confusion) {
2361.             if (!turn_undead_msg_cnt++)
2362.                 pline("Unfortunately, your voice falters.");
2363.             mtmp->mflee = 0;
2364.             mtmp->mfrozen = 0;
2365.             mtmp->mcanmove = 1;
2366.         } else if (!resist(mtmp, '\0', 0, TELL)) {
2367.             int xlev = 6;
2368. 
2369.             switch (mtmp->data->mlet) {
2370.                 /* this is intentional, lichs are tougher
2371.                    than zombies. */
2372.             case S_LICH:
2373.                 xlev += 2;
2374.                 FALLTHROUGH;
2375.                 /*FALLTHRU*/
2376.             case S_GHOST:
2377.                 xlev += 2;
2378.                 FALLTHROUGH;
2379.                 /*FALLTHRU*/
2380.             case S_VAMPIRE:
2381.                 xlev += 2;
2382.                 FALLTHROUGH;
2383.                 /*FALLTHRU*/
2384.             case S_WRAITH:
2385.                 xlev += 2;
2386.                 FALLTHROUGH;
2387.                 /*FALLTHRU*/
2388.             case S_MUMMY:
2389.                 xlev += 2;
2390.                 FALLTHROUGH;
2391.                 /*FALLTHRU*/
2392.             case S_ZOMBIE:
2393.                 if (u.ulevel >= xlev && !resist(mtmp, '\0', 0, NOTELL)) {
2394.                     if (u.ualign.type == A_CHAOTIC) {
2395.                         mtmp->mpeaceful = 1;
2396.                         set_malign(mtmp);
2397.                     } else { /* damn them */
2398.                         killed(mtmp);
2399.                     }
2400.                     break;
2401.                 } /* else flee */
2402.                 FALLTHROUGH;
2403.                 /*FALLTHRU*/
2404.             default:
2405.                 monflee(mtmp, 0, FALSE, TRUE);
2406.                 break;
2407.             }
2408.         }
2409.     }
2410. }
2411. 
2412. /* #turn command */
2413. int
2414. doturn(void)
2415. {
2416.     /* Knights & Priest(esse)s only please */
2417.     const char *Gname;
2418. 
2419.     if (!Role_if(PM_CLERIC) && !Role_if(PM_KNIGHT)) {
2420.         /* Try to use the "turn undead" spell. */
2421.         if (known_spell(SPE_TURN_UNDEAD))
2422.             return spelleffects(SPE_TURN_UNDEAD, FALSE, FALSE);
2423.         You("don't know how to turn undead!");
2424.         return ECMD_OK;
2425.     }
2426.     if (!u.uconduct.gnostic++)
2427.         livelog_printf(LL_CONDUCT, "rejected atheism by turning undead");
2428. 
2429.     Gname = halu_gname(u.ualign.type);
2430. 
2431.     /* [What about needing free hands (does #turn involve any gesturing)?] */
2432.     if (!can_chant(&gy.youmonst)) {
2433.         /* "evilness": "demons and undead" is too verbose and too precise */
2434.         You("are %s upon %s to turn aside evilness.",
2435.             Strangled ? "not able to call" : "incapable of calling", Gname);
2436.         /* violates agnosticism due to intent; conduct tracking is not
2437.            supposed to affect play but we make an exception here:  use a
2438.            move if this is the first time agnostic conduct has been broken */
2439.         return (u.uconduct.gnostic == 1) ? ECMD_TIME : ECMD_OK;
2440.     }
2441.     if ((u.ualign.type != A_CHAOTIC
2442.          && (is_demon(gy.youmonst.data)
2443.              || is_undead(gy.youmonst.data) || is_vampshifter(&gy.youmonst)))
2444.         || u.ugangr > 6) { /* "Die, mortal!" */
2445.         pline("For some reason, %s seems to ignore you.", Gname);
2446.         aggravate();
2447.         exercise(A_WIS, FALSE);
2448.         return ECMD_TIME;
2449.     }
2450.     if (Inhell) {
2451.         pline("Since you are in Gehennom, %s %s help you.",
2452.               /* not actually calling upon Moloch but use alternate
2453.                  phrasing anyway if hallucinatory feedback says it's him */
2454.               Gname, !strcmp(Gname, Moloch) ? "won't" : "can't");
2455.         aggravate();
2456.         return ECMD_TIME;
2457.     }
2458.     pline("Calling upon %s, you chant an arcane formula.", Gname);
2459.     exercise(A_WIS, TRUE);
2460. 
2461.     /* note: does not perform unturn_dead() on victims' inventories */
2462.     turn_undead_range = BOLT_LIM + (u.ulevel / 5); /* 8 to 14 */
2463.     turn_undead_range *= turn_undead_range;
2464.     turn_undead_msg_cnt = 0;
2465. 
2466.     iter_mons(maybe_turn_mon_iter);
2467. 
2468.     /*
2469.      *  There is no detrimental effect on self for successful #turn
2470.      *  while in demon or undead form.  That can only be done while
2471.      *  chaotic oneself (see "For some reason" above) and chaotic
2472.      *  turning only makes targets peaceful.
2473.      *
2474.      *  Paralysis duration probably ought to be based on the strength
2475.      *  of turned creatures rather than on turner's level.
2476.      *  Why doesn't this honor Free_action?  [Because being able to
2477.      *  repeat #turn every turn would be too powerful.  Maybe instead
2478.      *  of nomul(-N) we should add the equivalent of mon->mspec_used
2479.      *  for the hero and refuse to #turn when it's non-zero?  Or have
2480.      *  both and u.uspec_used only matters when Free_action prevents
2481.      *  the brief paralysis?]
2482.      */
2483.     nomul(-(5 - ((u.ulevel - 1) / 6))); /* -5 .. -1 */
2484.     gm.multi_reason = "trying to turn the monsters";
2485.     gn.nomovemsg = You_can_move_again;
2486.     return ECMD_TIME;
2487. }
2488. 
2489. int
2490. altarmask_at(coordxy x, coordxy y)
2491. {
2492.     int res = 0;
2493. 
2494.     if (isok(x, y)) {
2495.         struct monst *mon = m_at(x, y);
2496. 
2497.         if (mon && M_AP_TYPE(mon) == M_AP_FURNITURE
2498.             && mon->mappearance == S_altar)
2499.             res = has_mcorpsenm(mon) ? MCORPSENM(mon) : 0;
2500.         else if (IS_ALTAR(levl[x][y].typ))
2501.             res = levl[x][y].altarmask;
2502.     }
2503.     return res;
2504. }
2505. 
2506. const char *
2507. a_gname(void)
2508. {
2509.     return a_gname_at(u.ux, u.uy);
2510. }
2511. 
2512. /* returns the name of an altar's deity */
2513. const char *
2514. a_gname_at(coordxy x, coordxy y)
2515. {
2516.     if (!IS_ALTAR(levl[x][y].typ))
2517.         return (char *) 0;
2518. 
2519.     return align_gname(a_align(x, y));
2520. }
2521. 
2522. /* returns the name of the hero's deity */
2523. const char *
2524. u_gname(void)
2525. {
2526.     return align_gname(u.ualign.type);
2527. }
2528. 
2529. const char *
2530. align_gname(aligntyp alignment)
2531. {
2532.     const char *gnam;
2533. 
2534.     switch (alignment) {
2535.     case A_NONE:
2536.         gnam = Moloch;
2537.         break;
2538.     case A_LAWFUL:
2539.         gnam = gu.urole.lgod;
2540.         break;
2541.     case A_NEUTRAL:
2542.         gnam = gu.urole.ngod;
2543.         break;
2544.     case A_CHAOTIC:
2545.         gnam = gu.urole.cgod;
2546.         break;
2547.     default:
2548.         impossible("unknown alignment.");
2549.         gnam = "someone";
2550.         break;
2551.     }
2552.     if (*gnam == '_')
2553.         ++gnam;
2554.     return gnam;
2555. }
2556. 
2557. static const char *const hallu_gods[] = {
2558.     "the Flying Spaghetti Monster", /* Church of the FSM */
2559.     "Eris",                         /* Discordianism */
2560.     "the Martians",                 /* every science fiction ever */
2561.     "Xom",                          /* Crawl */
2562.     "AnDoR dRaKoN",                 /* ADOM */
2563.     "the Central Bank of Yendor",   /* economics */
2564.     "Tooth Fairy",                  /* real world(?) */
2565.     "Om",                           /* Discworld */
2566.     "Yawgmoth",                     /* Magic: the Gathering */
2567.     "Morgoth",                      /* LoTR */
2568.     "Cthulhu",                      /* Lovecraft */
2569.     "the Ori",                      /* Stargate */
2570.     "destiny",                      /* why not? */
2571.     "your Friend the Computer",     /* Paranoia */
2572. };
2573. 
2574. /* hallucination handling for priest/minion names: select a random god
2575.    iff character is hallucinating */
2576. const char *
2577. halu_gname(aligntyp alignment)
2578. {
2579.     const char *gnam = NULL;
2580.     int which;
2581. 
2582.     if (!Hallucination)
2583.         return align_gname(alignment);
2584. 
2585.     /* Some roles (Priest) don't have a pantheon unless we're playing as
2586.        that role, so keep trying until we get a role which does have one.
2587.        [If playing a Priest, the current pantheon will be twice as likely
2588.        to get picked as any of the others.  That's not significant enough
2589.        to bother dealing with.] */
2590.     do
2591.         which = randrole(TRUE);
2592.     while (!roles[which].lgod);
2593. 
2594.     switch (rn2_on_display_rng(9)) {
2595.     case 0:
2596.     case 1:
2597.         gnam = roles[which].lgod;
2598.         break;
2599.     case 2:
2600.     case 3:
2601.         gnam = roles[which].ngod;
2602.         break;
2603.     case 4:
2604.     case 5:
2605.         gnam = roles[which].cgod;
2606.         break;
2607.     case 6:
2608.     case 7:
2609.         gnam = hallu_gods[rn2_on_display_rng(SIZE(hallu_gods))];
2610.         break;
2611.     case 8:
2612.         gnam = Moloch;
2613.         break;
2614.     default:
2615.         impossible("rn2 broken in halu_gname?!?");
2616.     }
2617.     if (!gnam) {
2618.         impossible("No random god name?");
2619.         gnam = "your Friend the Computer"; /* Paranoia */
2620.     }
2621.     if (*gnam == '_')
2622.         ++gnam;
2623.     return gnam;
2624. }
2625. 
2626. /* deity's title */
2627. const char *
2628. align_gtitle(aligntyp alignment)
2629. {
2630.     const char *gnam, *result = "god";
2631. 
2632.     switch (alignment) {
2633.     case A_LAWFUL:
2634.         gnam = gu.urole.lgod;
2635.         break;
2636.     case A_NEUTRAL:
2637.         gnam = gu.urole.ngod;
2638.         break;
2639.     case A_CHAOTIC:
2640.         gnam = gu.urole.cgod;
2641.         break;
2642.     default:
2643.         gnam = 0;
2644.         break;
2645.     }
2646.     if (gnam && *gnam == '_')
2647.         result = "goddess";
2648.     return result;
2649. }
2650. 
2651. void
2652. altar_wrath(coordxy x, coordxy y)
2653. {
2654.     aligntyp altaralign = a_align(x, y);
2655. 
2656.     if (u.ualign.type == altaralign && u.ualign.record > -rn2(4)) {
2657.         godvoice(altaralign, "How darest thou desecrate my altar!");
2658.         (void) adjattrib(A_WIS, -1, FALSE);
2659.         u.ualign.record--;
2660.     } else {
2661.         pline("%s %s%s:",
2662.               !Deaf ? "A voice (could it be"
2663.                     : "Despite your deafness, you seem to hear",
2664.               align_gname(altaralign),
2665.               !Deaf ? "?) whispers" : " say");
2666.         SetVoice((struct monst *) 0, 0, 80, voice_deity);
2667.         verbalize("Thou shalt pay, infidel!");
2668.         /* higher luck is more likely to be reduced; as it approaches -5
2669.            the chance to lose another point drops down, eventually to 0 */
2670.         if (Luck > -5 && rn2(Luck + 6))
2671.             change_luck(rn2(20) ? -1 : -2);
2672.     }
2673. }
2674. 
2675. /* assumes isok() at one space away, but not necessarily at two */
2676. staticfn boolean
2677. blocked_boulder(int dx, int dy)
2678. {
2679.     struct obj *otmp;
2680.     int nx, ny;
2681.     long count = 0L;
2682. 
2683.     for (otmp = svl.level.objects[u.ux + dx][u.uy + dy]; otmp;
2684.          otmp = otmp->nexthere) {
2685.         if (otmp->otyp == BOULDER)
2686.             count += otmp->quan;
2687.     }
2688. 
2689.     nx = u.ux + 2 * dx, ny = u.uy + 2 * dy; /* next spot beyond boulder(s) */
2690.     switch (count) {
2691.     case 0:
2692.         /* no boulders--not blocked */
2693.         return FALSE;
2694.     case 1:
2695.         /* possibly blocked depending on if it's pushable */
2696.         break;
2697.     case 2:
2698.         /* this is only approximate since multiple boulders might sink */
2699.         if (is_pool_or_lava(nx, ny)) /* does its own isok() check */
2700.             break; /* still need Sokoban check below */
2701.         FALLTHROUGH;
2702.         /*FALLTHRU*/
2703.     default:
2704.         /* more than one boulder--blocked after they push the top one;
2705.            don't force them to push it first to find out */
2706.         return TRUE;
2707.     }
2708. 
2709.     if (dx && dy && Sokoban) /* can't push boulder diagonally in Sokoban */
2710.         return TRUE;
2711.     if (!isok(nx, ny))
2712.         return TRUE;
2713.     if (IS_OBSTRUCTED(levl[nx][ny].typ))
2714.         return TRUE;
2715.     if (sobj_at(BOULDER, nx, ny))
2716.         return TRUE;
2717. 
2718.     return FALSE;
2719. }
2720. 
2721. /*pray.c*/