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