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