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