-
Notifications
You must be signed in to change notification settings - Fork 29
/
allmain.c
4844 lines (4561 loc) · 149 KB
/
allmain.c
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
/* SCCS Id: @(#)allmain.c 3.4 2003/04/02 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
/* various code that was replicated in *main.c */
#include "hack.h"
#include "artifact.h"
#include "xhity.h"
#ifndef NO_SIGNAL
#include <signal.h>
#endif
#ifdef POSITIONBAR
STATIC_DCL void NDECL(do_positionbar);
#endif
STATIC_DCL void NDECL(clothes_bite_you);
STATIC_DCL void NDECL(androidUpkeep);
STATIC_DCL void NDECL(printMons);
STATIC_DCL void NDECL(printDPR);
STATIC_DCL void NDECL(printBodies);
STATIC_DCL void NDECL(printSanAndInsight);
STATIC_DCL void FDECL(printAttacks, (char *,struct permonst *));
STATIC_DCL void FDECL(resFlags, (char *,unsigned int));
STATIC_DCL int NDECL(do_inheritor_menu);
STATIC_DCL void FDECL(spot_monster, (struct monst *));
STATIC_DCL void NDECL(sense_nearby_monsters);
STATIC_DCL void NDECL(cthulhu_mind_blast);
STATIC_DCL void FDECL(unseen_actions, (struct monst *));
STATIC_DCL void FDECL(blessed_spawn, (struct monst *));
STATIC_DCL void FDECL(good_neighbor, (struct monst *));
STATIC_DCL void FDECL(dark_pharaoh, (struct monst *));
STATIC_DCL void FDECL(dark_pharaoh_visible, (struct monst *));
STATIC_DCL void FDECL(good_neighbor_visible, (struct monst *));
STATIC_DCL void FDECL(polyp_pickup, (struct monst *));
STATIC_DCL void FDECL(goat_sacrifice, (struct monst *));
STATIC_DCL void FDECL(palid_stranger, (struct monst *));
#ifdef OVL0
extern const int monstr[];
STATIC_OVL void
digcrater(mtmp)
struct monst *mtmp;
{
int x,y,i,j;
struct trap *ttmp;
for(i=-5;i<=5;i++){
x = mtmp->mx+i;
for(j=-5;j<=5;j++){
y = mtmp->my+j;
if(isok(x,y)&& !(x == u.ux && y == u.uy)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
if(dist2(x,y,mtmp->mx,mtmp->my) <= 26){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
if(dist2(x,y,mtmp->mx,mtmp->my) <= 9) levl[x][y].typ = LAVAPOOL;
else if(dist2(x,y,mtmp->mx,mtmp->my) <= 26) digactualhole(x, y, mtmp, PIT, TRUE, FALSE);
}
}
}
}
}
}
STATIC_OVL void
digcloudcrater(mtmp)
struct monst *mtmp;
{
int x,y,i,j;
struct trap *ttmp;
for(i=-2;i<=2;i++){
x = mtmp->mx+i;
for(j=-2;j<=2;j++){
y = mtmp->my+j;
if(isok(x,y) && dist2(x,y,mtmp->mx,mtmp->my) < 8){
levl[x][y].typ = CLOUD;
}
}
}
}
STATIC_OVL void
digXchasm(mtmp)
struct monst *mtmp;
{
int x,y;
struct trap *ttmp;
int inty = rn2(4)+2;
int dy = rn2(2) ? 1 : -1;
y = mtmp->my;
x = mtmp->mx;
if(isok(x,y)&& !(x == u.ux && y == u.uy)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, HOLE, TRUE, FALSE);
}
}
y=y+1;
if(isok(x,y)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, PIT, TRUE, FALSE);
}
}
y=y-1;
y=y-1;
if(isok(x,y)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, PIT, TRUE, FALSE);
}
}
y=y+1;
for(x = mtmp->mx + 1; x < COLNO; x++){
if(!(x%inty)) y += dy;
if(isok(x,y) && !(x == u.ux && y == u.uy)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, HOLE, TRUE, FALSE);
}
}
y=y+1;
if(isok(x,y)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, PIT, TRUE, FALSE);
}
}
y=y-1;
y=y-1;
if(isok(x,y)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, PIT, TRUE, FALSE);
}
}
y=y+1;
}
y = mtmp->my;
for(x = mtmp->mx - 1; x >= 0; x--){
if(!(x%inty)) y -= dy;
if(isok(x,y)&& !(x == u.ux && y == u.uy)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, HOLE, TRUE, FALSE);
}
}
y=y+1;
if(isok(x,y)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, PIT, TRUE, FALSE);
}
}
y=y-1;
y=y-1;
if(isok(x,y)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, PIT, TRUE, FALSE);
}
}
y=y+1;
}
}
STATIC_OVL void
digYchasm(mtmp)
struct monst *mtmp;
{
int x,y;
struct trap *ttmp;
int intx = rn2(4)+2;
int dx = rn2(2) ? 1 : -1;
x = mtmp->mx;
y = mtmp->my;
if(isok(x,y)&& !(x == u.ux && y == u.uy)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, HOLE, TRUE, FALSE);
}
}
x=x+1;
if(isok(x,y)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, PIT, TRUE, FALSE);
}
}
x=x-1;
x=x-1;
if(isok(x,y)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, PIT, TRUE, FALSE);
}
}
x=x+1;
for(y = mtmp->my + 1; y < COLNO; y++){
if(!(y%intx)) x += dx;
if(isok(x,y)&& !(x == u.ux && y == u.uy)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, HOLE, TRUE, FALSE);
}
}
x=x+1;
if(isok(x,y)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, PIT, TRUE, FALSE);
}
}
x=x-1;
x=x-1;
if(isok(x,y)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, PIT, TRUE, FALSE);
}
}
x=x+1;
}
x = mtmp->mx;
for(y = mtmp->my - 1; y >= 0; y--){
if(!(y%intx)) x -= dx;
if(isok(x,y)&& !(x == u.ux && y == u.uy)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, HOLE, TRUE, FALSE);
}
}
x=x+1;
if(isok(x,y)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, PIT, TRUE, FALSE);
}
}
x=x-1;
x=x-1;
if(isok(x,y)){
ttmp = t_at(x, y);
if(levl[x][y].typ <= SCORR || levl[x][y].typ == CORR || levl[x][y].typ == ROOM){
levl[x][y].typ = CORR;
if(!does_block(x,y,&levl[x][y])) unblock_point(x,y); /* vision: can see through */
if(ttmp) delfloortrap(ttmp);
digactualhole(x, y, mtmp, PIT, TRUE, FALSE);
}
}
x=x+1;
}
}
static int prev_hp_notify;
char *
hpnotify_format_str(char *str)
{
static char buf[128];
char *f, *p, *end;
int ispercent = 0;
buf[0] = '\0';
if (!str) return NULL;
f = str;
p = buf;
end = buf + sizeof(buf) - 10;
while (*f) {
if (ispercent) {
switch (*f) {
case 'a':
snprintf (p, end + 1 - p, "%d", abs(uhp()-prev_hp_notify));
while (*p != '\0')
p++;
break;
case 'c':
snprintf (p, end + 1 - p, "%c", (prev_hp_notify > uhp() ? '-' : '+'));
p++;
break;
case 'm':
snprintf (p, end + 1 - p, "%d", uhpmax());
while (*p != '\0')
p++;
break;
case 'H':
if (uhp() == uhpmax()) {
snprintf (p, end + 1 - p, "%s", "max");
} else {
snprintf (p, end + 1 - p, "%d", uhp());
}
while (*p != '\0')
p++;
break;
case 'h':
snprintf (p, end + 1 - p, "%d", uhp());
while (*p != '\0')
p++;
break;
default:
*p = *f;
if (p < end)
p++;
}
ispercent = 0;
} else {
if (*f == '%')
ispercent = 1;
else {
*p = *f;
if (p < end)
p++;
}
}
f++;
}
*p = '\0';
return buf;
}
STATIC_OVL
void
androidUpkeep()
{
//Pay unusual upkeep here, possibly pass out
if(uandroid && !u.usleep){
int mult = HEALCYCLE/u.ulevel;
//Possibly pass out if you begin this step with 0 energy.
if(u.uen == 0 && !rn2(10+u.ulevel) && moves >= u.nextsleep){
int t = rn1(u.uenmax*mult+40, u.uenmax*mult+40);
You("pass out from exhaustion!");
u.nextsleep = moves+rnz(350)+t;
u.lastslept = moves;
fall_asleep(-t, TRUE);
nomul(-1*u.uenmax, "passed out from exhaustion");
}
if(u.phasengn){
losepw(10);
if(u.uen <= 0){
You("can no longer maintain phase!");
u.phasengn = 0;
}
}
if(u.ucspeed == HIGH_CLOCKSPEED){
losepw(1);
if(u.uen <= 0){
You("can no longer maintain emergency speed!");
u.ucspeed = NORM_CLOCKSPEED;
}
}
//Exceeding operational time
static char fatigue_warning = 0;
if(moves >= u.nextsleep+1400 && u.uen > 10 && !fatigue_warning){
fatigue_warning = 1;
You_feel("fatigued.");
}
static char e_fatigued = 0;
if(moves >= u.nextsleep+1400 && u.uen > 1 && u.uen <= 10 && !e_fatigued){
e_fatigued = 1;
You_feel("extremely fatigued.");
}
static char pass_warning = 0;
if(moves >= u.nextsleep && u.uen <= 1 && !pass_warning){
pass_warning = 1;
You_feel("like you're about to pass out.");
}
if(moves > u.nextsleep+1400 && u.uen > 0){
if(!(moves%20)) losepw(1);
}
}
}
STATIC_OVL
void
clothes_bite_you()
{
struct obj * uarmor[] = WORN_SLOTS;
int i;
for (i = 0; i < SIZE(uarmor); i++) {
if (uarmor[i] && (uarmor[i]->olarva)) {
held_item_bites(&youmonst, uarmor[i]);
if(multi >= 0) {
if (occupation)
stop_occupation();
else
nomul(0, NULL);
}
}
}
}
static long prev_dgl_extrainfo = 0;
/* perform 1 turn's worth of time-dependent hp modification, mostly silently */
/* NOTES: can rehumanize(), can print You("pass out from exertion!") if moving when overloaded at 1 hp */
void
you_regen_hp()
{
int wtcap = near_capacity();
int perX = 0;
int * hpmax;
int * hp;
boolean blockRegen = FALSE;
// set hp, maxhp pointers
hp = (Upolyd) ? (&u.mh) : (&u.uhp);
hpmax = (Upolyd) ? (&u.mhmax) : (&u.uhpmax);
if (u.uinvulnerable || u.spiritPColdowns[PWR_PHASE_STEP] >= moves + 20) {
/* for the moment at least, you're in tiptop shape */
/* do not regenerate any health */
/* you also do not lose health (e.g. from being a fish out of water) */
return;
}
// Sanity check
if (Upolyd && (*hp < 1))
rehumanize();
//Androids regenerate from active Hoon and healing doll,
////but not from other sources unless dormant
if(u.uhoon_duration && (*hp) < (*hpmax)){
flags.botl = 1;
(*hp) += 10;
if ((*hp) > (*hpmax))
(*hp) = (*hpmax);
}
if(RapidHealing && (*hp) < (*hpmax)){
//1/5th max hp
(*hp) += (*hpmax)/5+1;
if ((*hp) > (*hpmax))
(*hp) = (*hpmax);
}
perX += u.uhoon;
//Androids regenerate from active Hoon, but not from other sources unless dormant
// Notably, no bonus from passive Hoon
if(uandroid && !u.usleep)
return;
// fish out of water
if (youracedata->mlet == S_EEL && !is_pool(u.ux, u.uy, youracedata->msize == MZ_TINY) && !Is_waterlevel(&u.uz)) {
if (is_pool(u.ux, u.uy, TRUE))
perX -= HEALCYCLE * (youracedata->msize - 1) / (youracedata->msize);
else
perX -= HEALCYCLE;
blockRegen = TRUE;
}
// invidiaks out of dark
if (youracedata->mtyp == PM_INVIDIAK && !isdark(u.ux, u.uy)) {
perX -= HEALCYCLE;
blockRegen = TRUE;
}
// regeneration 'trinsic
if (Regeneration){
perX += HEALCYCLE;
}
// Corruption thought
if(active_glyph(CORRUPTION) && (*hp < (*hpmax)*.3)){
perX += HEALCYCLE;
}
// "Natural" regeneration has stricter limitations
if (blockRegen); // regeneration blocked by inclement conditions this turn.
else if (u.regen_blocked > 0) u.regen_blocked--; // regenration blocked by a curse (NOTE: decremented here)
else if (Race_if(PM_INCANTIFIER)){ // Incantifiers are special (including while polymorphed)
//Incantifiers have slow and unpredictable but comparitively efficient magical healing
// Healing spell is 3hp/power, this is 5hp/power
// Hiding in a corner waiting is less efficient than healing with the heal spell.
if(Race_if(PM_INCANTIFIER) && (*hp) < (*hpmax) && u.uen > 0){
int quantity = maybe_polyd(youmonst.data->mlevel, u.ulevel)/5 + 1;
do{
if(!rn2(HEALCYCLE)){
(*hp) += 5;
u.uen--;
}
} while(--quantity > 0 && u.uen > 0 && (*hp) < (*hpmax));
if((*hp) > (*hpmax))
(*hp) = (*hpmax);
}
} else if (!(nonliving(youracedata) && !uandroid) && // not nonliving, however, androids auto-repair while asleep
(wtcap < MOD_ENCUMBER || !u.umoved) && // not overloaded
!(uwep && uwep->oartifact == ART_ATMA_WEAPON && uwep->lamplit && !Drain_resistance && rn2(4)) // 3 in 4 chance of being prevented by Atma Weapon
// Question for Chris: what if instead, do "reglevel /= 4;" when atma weapon is active, placed either before or after the minimum reg 1 check?
){
int reglevel = maybe_polyd(youmonst.data->mlevel, u.ulevel);
// CON bonus (while in natural form)
if (!Upolyd)
reglevel += ((int)ACURR(A_CON) - 10) / 2;
// minimum 1
if (reglevel < 1)
reglevel = 1;
// Sleeping
if(u.usleep){
// To be comfortable, a bed must be "on top" of any pile of items in the square.
struct obj *bed = level.objects[u.ux][u.uy];
// on a bed
if(bed && bed->oclass == BED_CLASS){
// A bedroll must be the only object in the square, other beds can have stuff tucked under them
if((bed->otyp == BEDROLL && !bed->nexthere) || bed->otyp == GURNEY)
reglevel *= 1.5;
else if(bed->otyp == BED)
reglevel *= 2;
}
// restfully
if(RestfulSleep){
perX += HEALCYCLE;
}
}
// Barbarian role bonus
if (Role_if(PM_BARBARIAN) && !Upolyd)
reglevel *= 3;
// Melee roles can be slightly less concerned about taking hits
else if(!Upolyd && (
Role_if(PM_KNIGHT)
|| Role_if(PM_PIRATE)
|| Role_if(PM_SAMURAI)
|| Role_if(PM_VALKYRIE)
|| Role_if(PM_MONK)
|| Role_if(PM_CONVICT)
|| (u.sealsActive&SEAL_BERITH)
))
reglevel *= 2;
else if(!Upolyd && (
Role_if(PM_MADMAN)
))
reglevel *= 1.5;
//Additive bonuses
// Elf bonus
if (Race_if(PM_ELF) && !Upolyd)
reglevel += 7;
if (Race_if(PM_DROW) && !Upolyd)
reglevel += 8;
// Healer role bonus
if (Role_if(PM_HEALER) && !Upolyd)
reglevel += 10;
// penalty for being itchy
reglevel -= u_healing_penalty();
// minimum 1
if (reglevel < 1)
reglevel = 1;
perX += reglevel;
}
// The Ring of Hygiene's Disciple
if (!Upolyd && // Question for Chris: should this be enabled to also work while polymorphed?
((uleft && uleft->oartifact == ART_RING_OF_HYGIENE_S_DISCIPLE) ||
(uright && uright->oartifact == ART_RING_OF_HYGIENE_S_DISCIPLE))
){
perX += HEALCYCLE * min(4, (*hpmax) / max((*hp), 1));
}
// Buer
if (u.sealsActive&SEAL_BUER){
int dsize = spiritDsize();
if (uwep && uwep->oartifact == ART_ATMA_WEAPON && uwep->lamplit && !Drain_resistance)
perX += dsize * 6 / 4;
else
perX += dsize * 6;
}
/* moving around while encumbered is hard work */
if (wtcap > MOD_ENCUMBER && u.umoved) {
if (*hp > 1)
{
if (wtcap < EXT_ENCUMBER)
perX -= 1;
else
perX -= 3;
}
else
{
You("pass out from exertion!");
exercise(A_CON, FALSE);
fall_asleep(-10, FALSE);
}
}
if(FaintingFits && rn2(100) >= u.usanity && multi >= 0){
You("suddenly faint!");
fall_asleep((u.usanity - 100)/10 - 1, FALSE);
}
if (((perX > 0) && ((*hp) < (*hpmax))) || // if regenerating
((perX < 0)) // or dying
)
{
// update bottom line
flags.botl = 1;
// modify by 1/HEALCYCLEth of perX per turn:
*hp += perX / HEALCYCLE;
// Now deal with any remainder
if (((moves)*(abs(perX) % HEALCYCLE)) / HEALCYCLE >((moves - 1)*(abs(perX) % HEALCYCLE)) / HEALCYCLE)
*hp += 1 * sgn(perX);
// cap at maxhp
if ((*hp) > (*hpmax))
(*hp) = (*hpmax);
// check for rehumanization
if (Upolyd && (*hp < 1))
rehumanize();
}
}
/* perform 1 turn's worth of time-dependent power modification, silently */
void
you_regen_pw()
{
int wtcap = near_capacity();
int perX = 0;
// natural power regeneration
if (wtcap < MOD_ENCUMBER && // not overly encumbered
!Race_if(PM_INCANTIFIER) // not an incantifier
) {
int reglevel = u.ulevel + (((int)ACURR(A_WIS)) - 10) / 2;
// level + WISmod minimum 1
if (reglevel < 1)
reglevel = 1;
// Sleeping
if(u.usleep){
// To be comfortable, a bed must be "on top" of any pile of items in the square.
struct obj *bed = level.objects[u.ux][u.uy];
// on a bed
if(bed && bed->oclass == BED_CLASS){
// A bedroll must be the only object in the square, other beds can have stuff tucked under them
if((bed->otyp == BEDROLL && !bed->nexthere) || bed->otyp == GURNEY)
reglevel *= 1.5;
else if(bed->otyp == BED)
reglevel *= 2;
}
// restfully
if(RestfulSleep){
perX += HEALCYCLE;
}
}
// role bonuses
if (Role_if(PM_WIZARD)) reglevel += 10;
if (Role_if(PM_MADMAN)) reglevel += 9;
if (Role_if(PM_HEALER)) reglevel += 6;
if (Role_if(PM_PRIEST)) reglevel += 6;
if (Role_if(PM_VALKYRIE)) reglevel += 3;
if (Role_if(PM_MONK)) reglevel += 3;
// cornuthaum bonus for wizards (but not incantifiers, since they don't naturally regenerate power at all)
if (u.uen < u.uenmax && (Role_if(PM_WIZARD)) && uarmh && uarmh->otyp == CORNUTHAUM){
reglevel += uarmh->spe;
}
//Additive bonuses
// Elf bonus
if (Race_if(PM_ELF) && !Upolyd)
reglevel += 7;
if (Race_if(PM_DROW) && !Upolyd)
reglevel += 8;
// penalty for being itchy
reglevel -= u_healing_penalty();
// penalty from spell protection interfering with natural pw regeneration
if (u.uspellprot > 0)
reglevel -= 10 + 2 * u.uspellprot;
// minimum 1
if (reglevel < 1)
reglevel = 1;
perX += reglevel;
}
// external power regeneration
if (Energy_regeneration || // energy regeneration 'trinsic
(u.umartial && !uarmf && IS_GRASS(levl[u.ux][u.uy].typ)) // or being a bare-foot martial-artist standing on grass
)
{
perX += HEALCYCLE;
}
// Unknown God
if (u.specialSealsActive&SEAL_UNKNOWN_GOD){
perX += spiritDsize() * 6;
}
// power drain from maintained spells
if (u.maintained_en_debt > 0)
{
int reglevel = u.maintained_en_debt / 3;
int debtpaid = 0;
if (perX > reglevel)
{// can just subtract drain from pw regeneration and still have net positive
perX -= reglevel;
debtpaid += reglevel;
}
else
{// either 0 pw regen or net drain
// put the entirety of perX against the debt owed
reglevel -= perX;
debtpaid += perX;
perX = 0;
// drain further if the player has reserves to burn
if (u.uen > 0 || Race_if(PM_INCANTIFIER))
{
debtpaid += reglevel;
perX = -reglevel;
}
}
// settle the payment
u.maintained_en_debt -= debtpaid / HEALCYCLE;
//Now deal with any remainder
if (((moves)*(debtpaid % HEALCYCLE)) / HEALCYCLE >((moves - 1)*(debtpaid % HEALCYCLE)) / HEALCYCLE)
u.maintained_en_debt -= 1;
// minimum zero
if (u.maintained_en_debt < 0)
u.maintained_en_debt = 0;
}
//Naen fast energy regen applies to androids, too.
if(u.unaen_duration && (u.uen < u.uenmax)){
flags.botl = 1;
u.uen += 10;
if (u.uen > u.uenmax)
u.uen = u.uenmax;
}
//Naen passive bonus only partially applies to androids and incantifiers
if(Race_if(PM_INCANTIFIER)){
if(perX < 0)
perX += u.unaen;
if(perX > 0)
perX = 0;
}
else perX += u.unaen;
//Androids only regen power while asleep, but allow their rate to offset spell maintenance
if(uandroid && !u.usleep && perX > 0)
return;
if (((perX > 0) && (u.uen < u.uenmax)) || // if regenerating power
((perX < 0) && ((u.uen > 0) || Race_if(PM_INCANTIFIER))) // or draining power
)
{
//update bottom line
flags.botl = 1;
// modify by 1/HEALCYCLEth of perX per turn:
u.uen += perX / HEALCYCLE;
// Now deal with any remainder
if (((moves)*(abs(perX) % HEALCYCLE)) / HEALCYCLE >((moves - 1)*(abs(perX) % HEALCYCLE)) / HEALCYCLE)
u.uen += 1 * sgn(perX);
// cap at maxpw
if (u.uen > u.uenmax)
u.uen = u.uenmax;
// and at 0 (for non-incantifiers)
if (u.uen < 0 && !(Race_if(PM_INCANTIFIER)))
u.uen = 0;
}
}
/* perform 1 turn's worth of time-dependent power modification, silently */
void
you_regen_san()
{
// Threshold levels based on wis.
int reglevel = ACURR(A_WIS);
int insight = u.uinsight;
if(u.veil && In_depths(&u.uz)){
u.veil = FALSE;
change_uinsight(1);
}
// role bonuses
if (Role_if(PM_BARBARIAN)) reglevel += 10;
if (Role_if(PM_VALKYRIE)) reglevel += 9;
if (Role_if(PM_TOURIST)) reglevel += 8;
if (Role_if(PM_MONK)) reglevel += 8;
if (Role_if(PM_PRIEST)) reglevel += 7;
if (Role_if(PM_ANACHRONONAUT)) reglevel += 5;
if (Role_if(PM_TOURIST)) reglevel += 2;
if (Role_if(PM_EXILE)) reglevel += spiritDsize();
if (Role_if(PM_CONVICT)) reglevel -= 3;
if (Role_if(PM_NOBLEMAN)) reglevel -= 5;
if (Role_if(PM_MADMAN)) reglevel -= 10;
if (Race_if(PM_ELF)) reglevel += 3;
if (Race_if(PM_ORC)) reglevel -= 3;
// Unusually not-sane spirit
if (u.sealsActive&SEAL_ORTHOS){
reglevel -= 5;
}
// Bonus/penalty for insight
if(u.veil)
reglevel += 10;
else while((insight = insight/2))
reglevel--;
if(active_glyph(TRANSPARENT_SEA))
reglevel += 30;
// penalty for certain areas
if(Is_rlyeh(&u.uz)){
reglevel -= 30;
}
else if(In_nkai(&u.uz)){
reglevel -= 20;
}
else if(In_depths(&u.uz)){
reglevel -= 10;
}
if(In_quest(&u.uz)){
if(Role_if(PM_ANACHRONONAUT)){
if(Race_if(PM_ANDROID)){
// The Android PC's actual home is the locate level
if(Is_qlocate(&u.uz)){
reglevel -= 30; //net -25
}
else if(Is_qstart(&u.uz)){
reglevel -= 15; //net -10
}
else {
reglevel -= 10; //net -5, reversing bonus
}
}
else {
if(Is_qstart(&u.uz) && quest_status.leader_is_dead){
reglevel -= 30; //net -25
}
else {
reglevel -= 10; //net -5, reversing bonus
}
}
}
//Lots of stressful circumstances here!
else if(Race_if(PM_DROW)){
if(Role_if(PM_NOBLEMAN)){
if(Is_nemesis(&u.uz) && flags.initgend){
reglevel -= 30;
}
else if(Is_qstart(&u.uz) && Role_if(PM_NOBLEMAN) && !flags.initgend){
reglevel -= 30;
}
}
else if(Is_nemesis(&u.uz) && !flags.initgend && (Role_if(PM_PRIEST) || Role_if(PM_ROGUE) || Role_if(PM_RANGER) || Role_if(PM_WIZARD))){
reglevel -= 30;
}
}
}
// penalty for being itchy
reglevel -= u_healing_penalty();
// minimum 0
if (reglevel <= 0)
return;
// Fast recover to 1x, slower recovery to 2x, slowest recover to 3x.
if(u.usanity < reglevel){
if(!(moves%10))
change_usanity(1, FALSE);
}
else if(u.usanity < reglevel*2){
if(!(moves%32))
change_usanity(1, FALSE);
}
else if(u.usanity < reglevel*3){
if(!(moves%100))
change_usanity(1, FALSE);
}
}
void
moveloop()
{
#if defined(MICRO) || defined(WIN32)
char ch;
#endif
int abort_lev, i, j;
struct monst *mtmp, *nxtmon;
struct obj *pobj;
int moveamt = 0, wtcap = 0, change = 0;
boolean didmove = FALSE, monscanmove = FALSE;
int oldspiritAC=0;
int tx,ty;
int nmonsclose,nmonsnear,enkispeedlim;
static boolean oldBlind = 0, oldLightBlind = 0;
int healing_penalty = 0;
int hpDiff;
static int oldsanity = 100;
flags.moonphase = phase_of_the_moon();
if(flags.moonphase == FULL_MOON) {
You("are lucky! Full moon tonight.");
change_luck(1);
} else if(flags.moonphase == NEW_MOON) {
pline("Be careful! New moon tonight.");
}
flags.friday13 = friday_13th();
if (flags.friday13) {
pline("Watch out! Bad things can happen on Friday the 13th.");
change_luck(-1);
}
initrack();
/* Note: these initializers don't do anything except guarantee that
we're linked properly.
*/
decl_init();
monst_init();
monstr_init(); /* monster strengths */
objects_init();
commands_init();
#ifdef WIZARD
// Called twice in dNAO?
//if (wizard) add_debug_extended_commands();
#endif