forked from msearle5/slicehack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpray.c
More file actions
2899 lines (2725 loc) · 102 KB
/
Copy pathpray.c
File metadata and controls
2899 lines (2725 loc) · 102 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* NetHack 3.6 pray.c $NHDT-Date: 1573346192 2019/11/10 00:36:32 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.118 $ */
/* Copyright (c) Benson I. Margulies, Mike Stephenson, Steve Linhart, 1989. */
/* NetHack may be freely redistributed. See license for details. */
/* Edited on 5/8/18 by NullCGT */
#include "hack.h"
STATIC_PTR int NDECL(prayer_done);
STATIC_DCL struct obj *NDECL(worst_cursed_item);
STATIC_DCL int NDECL(in_trouble);
STATIC_DCL void FDECL(fix_worst_trouble, (int));
STATIC_DCL void FDECL(angrygods, (ALIGNTYP_P));
STATIC_DCL void FDECL(at_your_feet, (const char *));
STATIC_DCL void NDECL(gcrownu);
STATIC_DCL void FDECL(pleased, (ALIGNTYP_P));
STATIC_DCL void FDECL(godvoice, (ALIGNTYP_P, const char *));
STATIC_DCL void FDECL(god_zaps_you, (ALIGNTYP_P));
STATIC_DCL void FDECL(fry_by_god, (ALIGNTYP_P, BOOLEAN_P));
STATIC_DCL void FDECL(gods_angry, (ALIGNTYP_P));
STATIC_DCL void FDECL(gods_upset, (ALIGNTYP_P));
STATIC_DCL void FDECL(consume_offering, (struct obj *));
STATIC_DCL boolean FDECL(water_prayer, (BOOLEAN_P));
STATIC_DCL boolean FDECL(blocked_boulder, (int, int));
/* simplify a few tests */
#define Cursed_obj(obj, typ) ((obj) && (obj)->otyp == (typ) && (obj)->cursed)
/*
* Logic behind deities and altars and such:
* + prayers are made to your god if not on an altar, and to the altar's god
* if you are on an altar
* + If possible, your god answers all prayers, which is why bad things happen
* if you try to pray on another god's altar
* + sacrifices work basically the same way, but the other god may decide to
* accept your allegiance, after which they are your god. If rejected,
* your god takes over with your punishment.
* + if you're in Gehennom, all messages come from Moloch
*/
/*
* Moloch, who dwells in Gehennom, is the "renegade" cruel god
* responsible for the theft of the Amulet from Marduk, the Creator.
* Moloch is unaligned.
*/
static const char *Moloch = "Moloch";
static const char *godvoices[] = {
"booms out", "thunders", "rings out", "booms",
};
static const char *hgodvoices[] = {
"ka-BOOMs out", "belches", "ring-a-lings out", "squeaks",
"squeals", "screeches", "drones", "buzzes", "pipes",
"tinkles", "rumbulates", "moos", "brays", "barks", "screeeeeeeeams"
};
/* values calculated when prayer starts, and used when completed */
static aligntyp p_aligntyp;
static int p_trouble;
static int p_type; /* (-1)-3: (-1)=really naughty, 3=really good */
/*
* The actual trouble priority is determined by the order of the
* checks performed in in_trouble() rather than by these numeric
* values, so keep that code and these values synchronized in
* order to have the values be meaningful.
*/
#define TROUBLE_STONED 18
#define TROUBLE_SLIMED 17
#define TROUBLE_STRANGLED 16
#define TROUBLE_LAVA 15
#define TROUBLE_SICK 14
#define TROUBLE_WITHERING 13
#define TROUBLE_STARVING 12
#define TROUBLE_CARRIER 11
#define TROUBLE_REGION 10 /* stinking cloud */
#define TROUBLE_SURROUNDED 9
#define TROUBLE_HIT_CRITICAL 8
#define TROUBLE_LYCANTHROPE 7
#define TROUBLE_COLLAPSING 6
#define TROUBLE_STUCK_IN_WALL 5
#define TROUBLE_CURSED_LEVITATION 4
#define TROUBLE_UNUSEABLE_HANDS 3
#define TROUBLE_CURSED_BLINDFOLD 2
#define TROUBLE_HIT_MAJOR 1
#define TROUBLE_HIT_MID (-1)
#define TROUBLE_PUNISHED (-2)
#define TROUBLE_FUMBLING (-3)
#define TROUBLE_CURSED_ITEMS (-4)
#define TROUBLE_SADDLE (-5)
#define TROUBLE_HIT_MINOR (-6)
#define TROUBLE_BLIND (-7)
#define TROUBLE_POISONED (-8)
#define TROUBLE_WOUNDED_LEGS (-9)
#define TROUBLE_HUNGRY (-10)
#define TROUBLE_STUNNED (-11)
#define TROUBLE_CONFUSED (-12)
#define TROUBLE_HALLUCINATION (-13)
#define ugod_is_angry() (u.ualign.record < 0)
#define on_altar() IS_ALTAR(levl[u.ux][u.uy].typ)
#define on_shrine() ((levl[u.ux][u.uy].altarmask & AM_SHRINE) != 0)
/* critically low hit points if hp <= 5 or hp <= maxhp/N for some N.
* uses a multiplier for less critical levels
**/
boolean
critically_low_hp(only_if_injured, multiplier)
boolean only_if_injured; /* determines whether maxhp <= 5 matters */
int multiplier;
{
int divisor, hplim, curhp = Upolyd ? u.mh : u.uhp,
maxhp = Upolyd ? u.mhmax : u.uhpmax;
if (only_if_injured && !(curhp < maxhp))
return FALSE;
/* if maxhp is extremely high, use lower threshold for the division test
(golden glow cuts off at 11+5*lvl, nurse interaction at 25*lvl; this
ought to use monster hit dice--and a smaller multiplier--rather than
ulevel when polymorphed, but polyself doesn't maintain that) */
hplim = 15 * u.ulevel;
if (maxhp > hplim)
maxhp = hplim;
/* 7 used to be the unconditional divisor - these are multiplied by 2,
* i.e. pass multiplier = 2 to get something similar to the original
* behaviour
**/
divisor = 10 + xlev_to_rank(u.ulevel);
/* 5 is a magic number in TROUBLE_HIT handling below */
return (boolean) (curhp <= 5 || curhp * divisor <= maxhp * multiplier);
}
/* return True if surrounded by impassible rock, regardless of the state
of your own location (for example, inside a doorless closet) */
boolean
stuck_in_wall()
{
int i, j, x, y, count = 0;
if (Passes_walls)
return FALSE;
for (i = -1; i <= 1; i++) {
x = u.ux + i;
for (j = -1; j <= 1; j++) {
if (!i && !j)
continue;
y = u.uy + j;
if (!isok(x, y)
|| (IS_ROCK(levl[x][y].typ)
&& (levl[x][y].typ != SDOOR && levl[x][y].typ != SCORR))
|| (blocked_boulder(i, j) && !throws_rocks(youmonst.data)))
++count;
}
}
return (count == 8) ? TRUE : FALSE;
}
/* see starving(), below */
STATIC_OVL long
starvingCount(otmp, food, hiddenfood, toplevel)
struct obj *otmp;
long *food;
long *hiddenfood;
boolean toplevel;
{
long value = 0;
if (otmp->oclass == FOOD_CLASS) {
switch(otmp->otyp) {
case TIN:
case EGG:
case TRIPE_RATION:
case PINCH_OF_CATNIP:
case CLOVE_OF_GARLIC:
case SPRIG_OF_WOLFSBANE:
case EUCALYPTUS_LEAF:
/* ignore */
break;
case GLOB_OF_GRAY_OOZE:
case GLOB_OF_BROWN_PUDDING:
case GLOB_OF_GREEN_SLIME:
case GLOB_OF_BLACK_PUDDING:
case CORPSE: {
int pm = otmp->corpsenm;
if (otmp->otyp == GLOB_OF_GRAY_OOZE)
pm = PM_GRAY_OOZE;
if (otmp->otyp == GLOB_OF_BROWN_PUDDING)
pm = PM_BROWN_PUDDING;
if (otmp->otyp == GLOB_OF_GREEN_SLIME)
pm = PM_GREEN_SLIME;
if (otmp->otyp == GLOB_OF_BLACK_PUDDING)
pm = PM_BLACK_PUDDING;
/* Not if it is slime */
if ((pm == PM_GREEN_SLIME) &&
(!Unchanging && !slimeproof(youmonst.data)))
break;
/* or petrifying */
if ((flesh_petrifies(&mons[pm])) && !Stone_resistance)
break;
/* or poisonous */
if (poisonous(&mons[pm]) && !Poison_resistance)
break;
/* or acidic */
if (acidic(&mons[pm]) && !Acid_resistance && (u.uhp > 15))
break;
/* or a lizard */
if (pm == PM_LIZARD)
break;
/* or tainted - you don't know this precisely, not just because you haven't
* counted moves but because there is a random check in eatcorpse(). So use
* a five-second rule - based on the eatcorpse() code but non-random, and
* assuming the worst case if BUC is unknown. (This is the usual case, in
* which case you have 20 moves.)
**/
if (!nonrotting_corpse(pm) && !Sick_resistance) {
long age = peek_at_iced_corpse_age(otmp);
int rotted = (monstermoves - age) / 10L;
if (otmp->bknown) {
if (otmp->cursed)
rotted += 2L;
else if (otmp->blessed)
rotted -= 2L;
} else
rotted += 2L;
if (rotted > 3L)
break;
}
/* or cannibal / domestic animal */
if (is_cannibal(pm) || is_inedible_pet(pm))
break;
}
/* fall thru */
default:
value = obj_nutrition(otmp);
}
} else if (Has_contents(otmp)) {
struct obj *ot;
for (ot = otmp->cobj; ot; ot = ot->nobj)
starvingCount(ot, &food, &hiddenfood, FALSE);
}
if (toplevel)
*food += value;
else
*hiddenfood += value;
}
/* Are you starving of the hunger?
* If you are at HUNGRY or better, then no.
*
* Otherwise, see if you are carrying anything edible in open inventory.
* Check carried containers, too - but not if you can't get into them.
*
* Tins don't count (because there is a delay before eating which may be too much).
* Tripe doesn't count, as it may make you sick.
* Corpses may count, but not if they are old (being cautious here), poisonous (if
* you don't resist), stoning, sliming, acidic (if low HP), cannibal/domestic...
* Globs count, but like corpses not if they are sliming or acidic.
* Eggs don't count as you don't generally know if they are cockatrice eggs.
*
* This may be too generous - although it doesn't make much difference as none of
* these items have much food value - but lizards, eucalyptus leaves, catnip,
* wolfsbane and garlic shouldn't be considered food items.
*
* Currently it only cares about food. It could and would be more accurate to also
* count potions of fruit juice, (charged, identified) horns of plenty, etc.
*
* Some foods have very little food value, so if the total is below a certain amount
* (in estimated turns) this counts as effectively none (returns true).
*/
boolean
starving()
{
long food = 0;
long hiddenfood = 0;
long rate;
struct obj *otmp;
if (u.uhs < WEAK) return FALSE;
/* Recursively descend into containers to find food. Returns two counts for
* food in open inventory (food) and food in containers (hiddenfood)
*/
for (otmp = invent; otmp; otmp = otmp->nobj)
starvingCount(otmp, &food, &hiddenfood, TRUE);
/* Include food in containers if containers are accessible to you */
if (!(nohands(youmonst.data) || !freehand()))
food += hiddenfood;
/* Convert to turns, based on the hunger rate. */
rate = hungerrate();
if (rate <= 1) rate = 1;
food /= rate;
/* You are 'starving' if you have less than the equivalent of a fortune cookie
* (scales from 40 to 2 as the hunger rate is per 20 turns) which is the least
* nutritious common (randomly generated) non-perishable foodstuff.
*/
return (food < 2);
}
/* Return true if surrounded by monsters (or wall).
* Checks up to 4 grids away, but grids further away are worth less.
* Intended to catch both being trapped in a tight space by 1 or 2 monsters,
* and being mobbed by lots of monsters in an open space.
* Pets don't count as monsters, but they do count as an obstruction.
**/
boolean
surrounded()
{
int monsters = 0;
int freespace = 0;
int i, j, x, y;
/* Count monsters and blocked grids */
for(i = -4; i <= 4; i++) {
x = u.ux + i;
for(j = -4; j <= 4; j++) {
if ((i != 0) || (j != 0)) {
boolean ok = FALSE;
boolean mon = FALSE;
int dist;
y = u.uy + j;
if (isok(x, y)) {
ok = TRUE;
if (IS_ROCK(levl[x][y].typ)) ok = FALSE;
if (m_at(x, y) != 0) {
ok = FALSE;
if (!(m_at(x, y)->mtame)) {
mon = TRUE;
}
}
}
dist = isqrt((i*i)+(j*j));
if (mon) monsters += (1000 / dist);
if (ok) freespace += (1000 / (dist*dist));
}
}
}
if (freespace == 0) return TRUE;
return (monsters >= freespace);
}
/*
* Return 0 if nothing particular seems wrong, positive numbers for
* serious trouble, and negative numbers for comparative annoyances.
* This returns the worst problem. There may be others, and the gods
* may fix more than one.
*
* This could get as bizarre as noting surrounding opponents, (or
* hostile dogs), but that's really hard.
*
* We could force rehumanize of polyselfed people, but we can't tell
* unintentional shape changes from the other kind. Oh well.
* 3.4.2: make an exception if polymorphed into a form which lacks
* hands; that's a case where the ramifications override this doubt.
*/
STATIC_OVL int
in_trouble()
{
struct obj *otmp;
int i;
/*
* major troubles
*/
if (Stoned)
return TROUBLE_STONED;
if (Slimed)
return TROUBLE_SLIMED;
if (Strangled)
return TROUBLE_STRANGLED;
if (u.utrap && u.utraptype == TT_LAVA)
return TROUBLE_LAVA;
if (Sick)
return TROUBLE_SICK;
if (Withering)
return TROUBLE_WITHERING;
if (starving())
return TROUBLE_STARVING;
if (LarvaCarrier)
return TROUBLE_CARRIER;
if (region_danger())
return TROUBLE_REGION;
if (surrounded())
return TROUBLE_SURROUNDED;
if (critically_low_hp(FALSE, 2))
return TROUBLE_HIT_CRITICAL;
if ((u.ulycn >= LOW_PM) && !Race_if(PM_HUMAN_WEREWOLF))
return TROUBLE_LYCANTHROPE;
if (near_capacity() >= EXT_ENCUMBER && AMAX(A_STR) - ABASE(A_STR) > 3)
return TROUBLE_COLLAPSING;
if (stuck_in_wall())
return TROUBLE_STUCK_IN_WALL;
if (Cursed_obj(uarmf, LEVITATION_BOOTS)
|| stuck_ring(uleft, RIN_LEVITATION)
|| stuck_ring(uright, RIN_LEVITATION))
return TROUBLE_CURSED_LEVITATION;
if (nohands(youmonst.data) || !freehand()) {
/* for bag/box access [cf use_container()]...
make sure it's a case that we know how to handle;
otherwise "fix all troubles" would get stuck in a loop */
if (welded(uwep))
return TROUBLE_UNUSEABLE_HANDS;
if (Upolyd && nohands(youmonst.data)
&& (!Unchanging || ((otmp = unchanger()) != 0 && otmp->cursed)))
return TROUBLE_UNUSEABLE_HANDS;
}
if (Blindfolded && ublindf->cursed)
return TROUBLE_CURSED_BLINDFOLD;
if (critically_low_hp(FALSE, 3))
return TROUBLE_HIT_MAJOR;
/*
* minor troubles
*/
if (critically_low_hp(FALSE, 5))
return TROUBLE_HIT_MID;
if (Punished || (u.utrap && u.utraptype == TT_BURIEDBALL))
return TROUBLE_PUNISHED;
if (Cursed_obj(uarmg, GAUNTLETS_OF_FUMBLING)
|| Cursed_obj(uarmf, FUMBLE_BOOTS))
return TROUBLE_FUMBLING;
if (worst_cursed_item())
return TROUBLE_CURSED_ITEMS;
if (u.usteed) { /* can't voluntarily dismount from a cursed saddle */
otmp = which_armor(u.usteed, W_SADDLE);
if (Cursed_obj(otmp, SADDLE))
return TROUBLE_SADDLE;
}
if (critically_low_hp(FALSE, 6))
return TROUBLE_HIT_MINOR;
if (Blinded > 1 && haseyes(youmonst.data)
&& (!u.uswallow
|| !attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND)))
return TROUBLE_BLIND;
/* deafness isn't it's own trouble; healing magic cures deafness
when it cures blindness, so do the same with trouble repair */
if ((HDeaf & TIMEOUT) > 1L)
return TROUBLE_BLIND;
for (i = 0; i < A_MAX; i++)
if (ABASE(i) < AMAX(i))
return TROUBLE_POISONED;
if (Wounded_legs && !u.usteed)
return TROUBLE_WOUNDED_LEGS;
if (u.uhs >= HUNGRY)
return TROUBLE_HUNGRY;
if (HStun & TIMEOUT)
return TROUBLE_STUNNED;
if (HConfusion & TIMEOUT)
return TROUBLE_CONFUSED;
if (HHallucination & TIMEOUT)
return TROUBLE_HALLUCINATION;
return 0;
}
/* select an item for TROUBLE_CURSED_ITEMS */
STATIC_OVL struct obj *
worst_cursed_item()
{
register struct obj *otmp;
/* if strained or worse, check for loadstone first */
if (near_capacity() >= HVY_ENCUMBER) {
for (otmp = invent; otmp; otmp = otmp->nobj)
if (Cursed_obj(otmp, LOADSTONE))
return otmp;
}
/* weapon takes precedence if it is interfering
with taking off a ring or putting on a shield */
if (welded(uwep) && (uright || bimanual(uwep))) { /* weapon */
otmp = uwep;
/* gloves come next, due to rings */
} else if (uarmg && uarmg->cursed) { /* gloves */
otmp = uarmg;
/* then shield due to two handed weapons and spells */
} else if (uarms && uarms->cursed) { /* shield */
otmp = uarms;
/* then cloak due to body armor */
} else if (uarmc && uarmc->cursed) { /* cloak */
otmp = uarmc;
} else if (uarm && uarm->cursed) { /* suit */
otmp = uarm;
/* if worn helmet of opposite alignment is making you an adherent
of the current god, he/she/it won't uncurse that for you */
} else if (uarmh && uarmh->cursed /* helmet */
&& uarmh->otyp != HELM_OF_OPPOSITE_ALIGNMENT) {
otmp = uarmh;
} else if (uarmf && uarmf->cursed) { /* boots */
otmp = uarmf;
} else if (uarmu && uarmu->cursed) { /* shirt */
otmp = uarmu;
} else if (uamul && uamul->cursed) { /* amulet */
otmp = uamul;
} else if (uleft && uleft->cursed) { /* left ring */
otmp = uleft;
} else if (uright && uright->cursed) { /* right ring */
otmp = uright;
} else if (ublindf && ublindf->cursed) { /* eyewear */
otmp = ublindf; /* must be non-blinding lenses */
/* if weapon wasn't handled above, do it now */
} else if (welded(uwep)) { /* weapon */
otmp = uwep;
/* active secondary weapon even though it isn't welded */
} else if (uswapwep && uswapwep->cursed && u.twoweap) {
otmp = uswapwep;
/* all worn items ought to be handled by now */
} else {
for (otmp = invent; otmp; otmp = otmp->nobj) {
if (!otmp->cursed)
continue;
if (otmp->otyp == LOADSTONE || confers_luck(otmp))
break;
}
}
return otmp;
}
STATIC_OVL void
fix_worst_trouble(trouble)
int trouble;
{
int i;
struct obj *otmp = 0;
const char *what = (const char *) 0;
static NEARDATA const char leftglow[] = "Your left ring softly glows",
rightglow[] = "Your right ring softly glows";
switch (trouble) {
case TROUBLE_STONED:
make_stoned(0L, "You feel more limber.", 0, (char *) 0);
break;
case TROUBLE_SLIMED:
make_slimed(0L, "The slime disappears.");
break;
case TROUBLE_STRANGLED:
if (uamul && uamul->otyp == AMULET_OF_STRANGULATION) {
Your("amulet vanishes!");
useup(uamul);
}
You("can breathe again.");
Strangled = 0;
context.botl = 1;
break;
case TROUBLE_LAVA:
You("are back on solid ground.");
/* teleport should always succeed, but if not, just untrap them */
if (!safe_teleds(FALSE))
reset_utrap(TRUE);
break;
case TROUBLE_STARVING:
/* temporarily lost strength recovery now handled by init_uhunger() */
/*FALLTHRU*/
case TROUBLE_HUNGRY:
Your("%s feels content.", body_part(STOMACH));
init_uhunger();
context.botl = 1;
break;
case TROUBLE_SICK:
You_feel("better.");
make_sick(0L, (char *) 0, FALSE, SICK_ALL);
break;
case TROUBLE_WITHERING:
You_feel("hardier.");
set_itimeout(&HWithering, (long) 0);
break;
case TROUBLE_CARRIER:
You_feel("the things infesting you vanish.");
make_carrier(0L, TRUE);
break;
case TROUBLE_REGION:
/* stinking cloud, with hero vulnerable to HP loss */
region_safety();
break;
case TROUBLE_SURROUNDED:
safe_teleds(FALSE);
if (!critically_low_hp(FALSE, 2)) break;
/*FALLTHRU*/
case TROUBLE_HIT_CRITICAL:
case TROUBLE_HIT_MAJOR:
case TROUBLE_HIT_MID:
case TROUBLE_HIT_MINOR:
/* "fix all troubles" will keep trying if hero has
5 or less hit points, so make sure they're always
boosted to be more than that */
You_feel("much better.");
if (Upolyd) {
u.mhmax += rnd(5);
if (u.mhmax <= 5)
u.mhmax = 5 + 1;
u.mh = u.mhmax;
}
if (u.uhpmax < u.ulevel * 5 + 11)
u.uhpmax += rnd(5);
if (u.uhpmax <= 5)
u.uhpmax = 5 + 1;
u.uhp = u.uhpmax;
context.botl = 1;
break;
case TROUBLE_COLLAPSING:
/* override Fixed_abil; uncurse that if feasible */
You_feel("%sstronger.",
(AMAX(A_STR) - ABASE(A_STR) > 6) ? "much " : "");
ABASE(A_STR) = AMAX(A_STR);
context.botl = 1;
if (Fixed_abil) {
if ((otmp = stuck_ring(uleft, RIN_SUSTAIN_ABILITY)) != 0) {
if (otmp == uleft)
what = leftglow;
} else if ((otmp = stuck_ring(uright, RIN_SUSTAIN_ABILITY)) != 0) {
if (otmp == uright)
what = rightglow;
}
if (otmp)
goto decurse;
}
break;
case TROUBLE_STUCK_IN_WALL:
/* no control, but works on no-teleport levels */
if (safe_teleds(FALSE)) {
Your("surroundings change.");
} else {
/* safe_teleds() couldn't find a safe place; perhaps the
level is completely full. As a last resort, confer
intrinsic wall/rock-phazing. Hero might get stuck
again fairly soon....
Without something like this, fix_all_troubles can get
stuck in an infinite loop trying to fix STUCK_IN_WALL
and repeatedly failing. */
set_itimeout(&HPasses_walls, (long) (d(4, 4) + 4)); /* 8..20 */
/* how else could you move between packed rocks or among
lattice forming "solid" rock? */
You_feel("much slimmer.");
}
break;
case TROUBLE_CURSED_LEVITATION:
if (Cursed_obj(uarmf, LEVITATION_BOOTS)) {
otmp = uarmf;
} else if ((otmp = stuck_ring(uleft, RIN_LEVITATION)) != 0) {
if (otmp == uleft)
what = leftglow;
} else if ((otmp = stuck_ring(uright, RIN_LEVITATION)) != 0) {
if (otmp == uright)
what = rightglow;
}
goto decurse;
case TROUBLE_UNUSEABLE_HANDS:
if (welded(uwep)) {
otmp = uwep;
goto decurse;
}
if (Upolyd && nohands(youmonst.data)) {
if (!Unchanging) {
Your("shape becomes uncertain.");
rehumanize(); /* "You return to {normal} form." */
} else if ((otmp = unchanger()) != 0 && otmp->cursed) {
/* otmp is an amulet of unchanging */
goto decurse;
}
}
if (nohands(youmonst.data) || !freehand())
impossible("fix_worst_trouble: couldn't cure hands.");
break;
case TROUBLE_CURSED_BLINDFOLD:
otmp = ublindf;
goto decurse;
case TROUBLE_LYCANTHROPE:
you_unwere(TRUE);
break;
/*
*/
case TROUBLE_PUNISHED:
Your("chain disappears.");
if (u.utrap && u.utraptype == TT_BURIEDBALL)
buried_ball_to_freedom();
else
unpunish();
break;
case TROUBLE_FUMBLING:
if (Cursed_obj(uarmg, GAUNTLETS_OF_FUMBLING))
otmp = uarmg;
else if (Cursed_obj(uarmf, FUMBLE_BOOTS))
otmp = uarmf;
goto decurse;
/*NOTREACHED*/
break;
case TROUBLE_CURSED_ITEMS:
otmp = worst_cursed_item();
if (otmp == uright)
what = rightglow;
else if (otmp == uleft)
what = leftglow;
decurse:
if (!otmp) {
impossible("fix_worst_trouble: nothing to uncurse.");
return;
}
if (otmp == uarmg && Glib) {
make_glib(0);
Your("%s are no longer slippery.", gloves_simple_name(uarmg));
if (!otmp->cursed)
break;
}
if (!Blind || (otmp == ublindf && Blindfolded_only)) {
pline("%s %s.",
what ? what : (const char *) Yobjnam2(otmp, "softly glow"),
hcolor(NH_AMBER));
iflags.last_msg = PLNMSG_OBJ_GLOWS;
otmp->bknown = !Hallucination; /* ok to skip set_bknown() */
}
uncurse(otmp);
update_inventory();
break;
case TROUBLE_POISONED:
/* override Fixed_abil; ignore items which confer that */
if (Hallucination)
pline("There's a tiger in your tank.");
else
You_feel("in good health again.");
for (i = 0; i < A_MAX; i++) {
if (ABASE(i) < AMAX(i)) {
ABASE(i) = AMAX(i);
context.botl = 1;
}
}
(void) encumber_msg();
break;
case TROUBLE_BLIND: { /* handles deafness as well as blindness */
char msgbuf[BUFSZ];
const char *eyes = body_part(EYE);
boolean cure_deaf = (HDeaf & TIMEOUT) ? TRUE : FALSE;
msgbuf[0] = '\0';
if (Blinded) {
if (eyecount(youmonst.data) != 1)
eyes = makeplural(eyes);
Sprintf(msgbuf, "Your %s %s better", eyes, vtense(eyes, "feel"));
u.ucreamed = 0;
make_blinded(0L, FALSE);
}
if (cure_deaf) {
make_deaf(0L, FALSE);
if (!Deaf)
Sprintf(eos(msgbuf), "%s can hear again",
!*msgbuf ? "You" : " and you");
}
if (*msgbuf)
pline("%s.", msgbuf);
break;
}
case TROUBLE_WOUNDED_LEGS:
heal_legs(0);
break;
case TROUBLE_STUNNED:
make_stunned(0L, TRUE);
break;
case TROUBLE_CONFUSED:
make_confused(0L, TRUE);
break;
case TROUBLE_HALLUCINATION:
pline("Looks like you are back in Kansas.");
(void) make_hallucinated(0L, FALSE, 0L);
break;
case TROUBLE_SADDLE:
otmp = which_armor(u.usteed, W_SADDLE);
if (!Blind) {
pline("%s %s.", Yobjnam2(otmp, "softly glow"), hcolor(NH_AMBER));
set_bknown(otmp, 1);
}
uncurse(otmp);
break;
}
}
/* "I am sometimes shocked by... the nuns who never take a bath without
* wearing a bathrobe all the time. When asked why, since no man can see them,
* they reply 'Oh, but you forget the good God'. Apparently they conceive of
* the Deity as a Peeping Tom, whose omnipotence enables Him to see through
* bathroom walls, but who is foiled by bathrobes." --Bertrand Russell, 1943
* Divine wrath, dungeon walls, and armor follow the same principle.
*/
STATIC_OVL void
god_zaps_you(resp_god)
aligntyp resp_god;
{
if (u.uswallow) {
pline(
"Suddenly a bolt of lightning comes down at you from the heavens!");
pline("It strikes %s!", mon_nam(u.ustuck));
if (!resists_elec(u.ustuck)) {
pline("%s fries to a crisp!", Monnam(u.ustuck));
/* Yup, you get experience. It takes guts to successfully
* pull off this trick on your god, anyway.
* Other credit/blame applies (luck or alignment adjustments),
* but not direct kill count (pacifist conduct).
*/
xkilled(u.ustuck, XKILL_NOMSG | XKILL_NOCONDUCT);
} else
pline("%s seems unaffected.", Monnam(u.ustuck));
} else {
pline("Suddenly, a bolt of lightning strikes you!");
if (Reflecting) {
shieldeff(u.ux, u.uy);
if (Blind)
pline("For some reason you're unaffected.");
else
(void) ureflects("%s reflects from your %s.", "It");
} else if (Shock_resistance) {
shieldeff(u.ux, u.uy);
pline("It seems not to affect you.");
} else
fry_by_god(resp_god, FALSE);
}
pline("%s is not deterred...", align_gname(resp_god));
if (u.uswallow) {
pline("A wide-angle disintegration beam aimed at you hits %s!",
mon_nam(u.ustuck));
if (!resists_disint(u.ustuck)) {
pline("%s disintegrates into a pile of dust!", Monnam(u.ustuck));
xkilled(u.ustuck, XKILL_NOMSG | XKILL_NOCORPSE | XKILL_NOCONDUCT);
} else
pline("%s seems unaffected.", Monnam(u.ustuck));
} else {
pline("A wide-angle disintegration beam hits you!");
/* disintegrate shield and body armor before disintegrating
* the impudent mortal, like black dragon breath -3.
*/
if (uarms && !(EReflecting & W_ARMS)
&& !(EDisint_resistance & W_ARMS))
(void) destroy_arm(uarms);
if (uarmc && !(EReflecting & W_ARMC)
&& !(EDisint_resistance & W_ARMC))
(void) destroy_arm(uarmc);
if (uarm && !(EReflecting & W_ARM) && !(EDisint_resistance & W_ARM)
&& !uarmc)
(void) destroy_arm(uarm);
if (uarmu && !uarm && !uarmc)
(void) destroy_arm(uarmu);
if (!Disint_resistance) {
fry_by_god(resp_god, TRUE);
} else {
You("bask in its %s glow for a minute...", NH_BLACK);
godvoice(resp_god, "I believe it not!");
}
if (Is_astralevel(&u.uz) || Is_sanctum(&u.uz)) {
/* one more try for high altars */
verbalize("Thou cannot escape my wrath, mortal!");
summon_minion(resp_god, FALSE);
summon_minion(resp_god, FALSE);
summon_minion(resp_god, FALSE);
verbalize("Destroy %s, my servants!", uhim());
}
}
}
STATIC_OVL void
fry_by_god(resp_god, via_disintegration)
aligntyp resp_god;
boolean via_disintegration;
{
You("%s!", !via_disintegration ? "fry to a crisp"
: "disintegrate into a pile of dust");
killer.format = KILLED_BY;
Sprintf(killer.name, "the wrath of %s", align_gname(resp_god));
done(DIED);
}
STATIC_OVL void
angrygods(resp_god)
aligntyp resp_god;
{
int maxanger;
if (Inhell)
resp_god = A_NONE;
u.ublessed = 0;
/* changed from tmp = u.ugangr + abs (u.uluck) -- rph */
/* added test for alignment diff -dlc */
if (resp_god != u.ualign.type)
maxanger = u.ualign.record / 2 + (Luck > 0 ? -Luck / 3 : -Luck);
else
maxanger = 3 * u.ugangr + ((Luck > 0 || u.ualign.record >= STRIDENT)
? -Luck / 3
: -Luck);
if (maxanger < 1)
maxanger = 1; /* possible if bad align & good luck */
else if (maxanger > 15)
maxanger = 15; /* be reasonable */
switch (rn2(maxanger)) {
case 0:
case 1:
You_feel("that %s is %s.", align_gname(resp_god),
Hallucination ? "bummed" : "displeased");
break;
case 2:
case 3:
godvoice(resp_god, (char *) 0);
pline("\"Thou %s, %s.\"",
(ugod_is_angry() && resp_god == u.ualign.type)
? "hast strayed from the path"
: "art arrogant",
youmonst.data->mlet == S_HUMAN ? "mortal" : "creature");
verbalize("Thou must relearn thy lessons!");
(void) adjattrib(A_WIS, -1, FALSE);
losexp((char *) 0);
break;
case 6:
if (!Punished) {
gods_angry(resp_god);
punish((struct obj *) 0);
break;
} /* else fall thru */
case 4:
case 5:
gods_angry(resp_god);
if (!Blind && !Antimagic)
pline("%s glow surrounds you.", An(hcolor(NH_BLACK)));
rndcurse();
break;
case 7:
case 8:
godvoice(resp_god, (char *) 0);
verbalize("Thou durst %s me?",
(on_altar() && (a_align(u.ux, u.uy) != resp_god))
? "scorn"
: "call upon");
/* [why isn't this using verbalize()?] */
pline("\"Then die, %s!\"",
(youmonst.data->mlet == S_HUMAN) ? "mortal" : "creature");
summon_minion(resp_god, FALSE);
break;
default:
gods_angry(resp_god);
god_zaps_you(resp_god);
break;
}
u.ublesscnt = rnz(300);
holy_symbol();
return;
}
/* helper to print "str appears at your feet", or appropriate */
static void
at_your_feet(str)
const char *str;
{
if (Blind)
str = Something;
if (u.uswallow) {
/* barrier between you and the floor */
pline("%s %s into %s %s.", str, vtense(str, "drop"),
s_suffix(mon_nam(u.ustuck)), mbodypart(u.ustuck, STOMACH));
} else {
pline("%s %s %s your %s!", str,
Blind ? "lands" : vtense(str, "appear"),
Levitation ? "beneath" : "at", makeplural(body_part(FOOT)));
}
}
STATIC_OVL void
gcrownu()
{
struct obj *obj;
boolean already_exists, in_hand;
short class_gift;
int sp_no;
#define ok_wep(o) ((o) && ((o)->oclass == WEAPON_CLASS || is_weptool(o)))
HSee_invisible |= FROMOUTSIDE;
HFire_resistance |= FROMOUTSIDE;
HCold_resistance |= FROMOUTSIDE;
HShock_resistance |= FROMOUTSIDE;
HSleep_resistance |= FROMOUTSIDE;
HPoison_resistance |= FROMOUTSIDE;
godvoice(u.ualign.type, (char *) 0);
class_gift = STRANGE_OBJECT;
/* 3.3.[01] had this in the A_NEUTRAL case,
preventing chaotic wizards from receiving a spellbook */
if (Role_if(PM_WIZARD)
&& (!uwep || (uwep->oartifact != ART_VORPAL_BLADE
&& uwep->oartifact != ART_STORMBRINGER))
&& !carrying(SPE_FINGER_OF_DEATH)) {