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