-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.c
1313 lines (1165 loc) · 36.5 KB
/
util.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
/*
util.c - all sorts of miscellaneous routines
XRogue: Expeditions into the Dungeons of Doom
Copyright (C) 1991 Robert Pietkivitch
All rights reserved.
Based on "Advanced Rogue"
Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
All rights reserved.
Based on "Rogue: Exploring the Dungeons of Doom"
Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
All rights reserved.
See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
#include <ctype.h>
#include "rogue.h"
/*
* this routine computes the players current AC without dex bonus's
*/
int
ac_compute(ignoremetal)
bool ignoremetal;
{
register int ac;
ac = pstats.s_arm; /* base armor of "skin" */
if (cur_armor) {
if (!ignoremetal ||
(cur_armor->o_which != LEATHER &&
cur_armor->o_which != STUDDED_LEATHER &&
cur_armor->o_which != PADDED_ARMOR))
ac -= (10 - cur_armor->o_ac);
}
if (player.t_ctype == C_MONK)
ac -= pstats.s_lvl * 3 / 5;
ac -= ring_value(R_PROTECT);
if (cur_misc[WEAR_BRACERS] != NULL)
ac -= cur_misc[WEAR_BRACERS]->o_ac;
if (cur_misc[WEAR_CLOAK] != NULL)
ac -= cur_misc[WEAR_CLOAK]->o_ac;
/* If player has the cloak, must be wearing it */
if (cur_relic[EMORI_CLOAK]) ac -= 15;
if (ac > 25)
ac = 25;
return(ac);
}
/*
* aggravate:
* aggravate all the monsters on this level
*/
aggravate(do_uniques, do_good)
bool do_uniques, do_good;
{
register struct linked_list *mi;
register struct thing *thingptr;
for (mi = mlist; mi != NULL; mi = next(mi)) {
thingptr = THINGPTR(mi);
if (do_good == FALSE && off(*thingptr, ISMEAN)) continue;
if (do_uniques || off(*thingptr, ISUNIQUE)) runto(thingptr, &hero);
}
}
/*
* cansee:
* returns true if the hero can see a certain coordinate.
*/
cansee(y, x)
register int y, x;
{
register struct room *rer;
register int radius;
coord tp;
if (on(player, ISBLIND))
return FALSE;
tp.y = y;
tp.x = x;
rer = roomin(&tp);
/* How far can we see? */
if (levtype == OUTSIDE) {
if (daytime) radius = 36;
else if (lit_room(rer)) radius = 9;
else radius = 3;
}
else radius = 3;
/*
* We can only see if the hero in the same room as
* the coordinate and the room is lit or if it is close.
*/
return ((rer != NULL &&
levtype != OUTSIDE &&
(levtype != MAZELEV || /* Maze level needs direct line */
maze_view(tp.y, tp.x)) &&
rer == roomin(&hero) &&
lit_room(rer)) ||
DISTANCE(y, x, hero.y, hero.x) < radius);
}
/*
* check_level:
* Check to see if the guy has gone up a level.
*
* Return points needed to obtain next level.
*
* These are certain beginning experience levels for all players.
* All further experience levels are computed by muliplying by 2
* up through MAXDOUBLE. Then the cap is added in to compute
* further levels
*/
long
check_level()
{
register int i, j, add = 0;
register unsigned long exp;
long retval; /* Return value */
int nsides;
pstats.s_lvl -= pstats.s_lvladj; /* correct for level adjustment */
/* See if we are past the doubling stage */
exp = char_class[player.t_ctype].cap;
if (pstats.s_exp >= exp) {
i = pstats.s_exp/exp; /* First get amount above doubling area */
retval = exp + i * exp; /* Compute next higher boundary */
i += MAXDOUBLE; /* Add in the previous doubled levels */
}
else {
i = 0;
exp = char_class[player.t_ctype].start_exp;
while (exp <= pstats.s_exp) {
i++;
exp <<= 1;
}
retval = exp;
}
if (++i > pstats.s_lvl) {
nsides = char_class[player.t_ctype].hit_pts;
for (j=0; j<(i-pstats.s_lvl); j++) /* Take care of multi-level jumps */
add += max(1, roll(1,nsides) + const_bonus());
max_stats.s_hpt += add;
if ((pstats.s_hpt += add) > max_stats.s_hpt)
pstats.s_hpt = max_stats.s_hpt;
msg("Welcome, %s, to level %d",
cnames[player.t_ctype][min(i-1, NUM_CNAMES-1)], i);
}
pstats.s_lvl = i;
pstats.s_lvl += pstats.s_lvladj; /* correct for level adjustment */
return(retval);
}
/*
* Used to modify the players strength
* it keeps track of the highest it has been, just in case
*/
chg_str(amt)
register int amt;
{
register int ring_str; /* ring strengths */
register struct stats *ptr; /* for speed */
ptr = &pstats;
ring_str = ring_value(R_ADDSTR);
ptr->s_str -= ring_str;
ptr->s_str += amt;
if (ptr->s_str > MAXATT) ptr->s_str = MAXATT;
if (ptr->s_str > max_stats.s_str)
max_stats.s_str = ptr->s_str;
ptr->s_str += ring_str;
if (ptr->s_str <= 0) {
pstats.s_hpt = -1;
death(D_STRENGTH);
}
updpack(TRUE, &player);
}
/*
* let's confuse the player
*/
confus_player()
{
if (off(player, ISCLEAR))
{
msg("Wait, what's going on here! Huh? What? Who?");
if (find_slot(unconfuse))
lengthen(unconfuse, HUHDURATION);
else
fuse(unconfuse, (VOID *)NULL, HUHDURATION, AFTER);
turn_on(player, ISHUH);
}
else msg("You feel dizzy for a moment, but it quickly passes.");
}
/*
* this routine computes the players current dexterity
*/
dex_compute()
{
if (cur_misc[WEAR_GAUNTLET] != NULL &&
cur_misc[WEAR_GAUNTLET]->o_which == MM_G_DEXTERITY) {
if (cur_misc[WEAR_GAUNTLET]->o_flags & ISCURSED)
return (3);
else
return (21);
}
else
return (pstats.s_dext);
}
/*
* diag_ok:
* Check to see if the move is legal if it is diagonal
*/
diag_ok(sp, ep, flgptr)
register coord *sp, *ep;
struct thing *flgptr;
{
register int numpaths = 0;
/* Horizontal and vertical moves are always ok */
if (ep->x == sp->x || ep->y == sp->y)
return TRUE;
/* Diagonal moves are not allowed if there is a horizontal or
* vertical path to the destination
*/
if (step_ok(ep->y, sp->x, MONSTOK, flgptr)) numpaths++;
if (step_ok(sp->y, ep->x, MONSTOK, flgptr)) numpaths++;
return(numpaths != 1);
}
/*
* pick a random position around the give (y, x) coordinates
*/
coord *
fallpos(pos, be_clear, range)
register coord *pos;
bool be_clear;
int range;
{
register int tried, i, j;
register char ch;
static coord ret;
static short masks[] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x100 };
/*
* Pick a spot at random centered on the position given by 'pos' and
* up to 'range' squares away from 'pos'
*
* If 'be_clear' is TRUE, the spot must be either FLOOR or PASSAGE
* inorder to be considered valid
*
* Generate a number from 0 to 8, representing the position to pick.
* Note that this DOES include the positon 'pos' itself
*
* If this position is not valid, mark it as 'tried', and pick another.
* Whenever a position is picked that has been tried before,
* sequentially find the next untried position. This eliminates costly
* random number generation
*/
tried = 0;
while( tried != 0x1ff ) {
i = rnd(9);
while( tried & masks[i] )
i = (i + 1) % 9;
tried |= masks[i];
for( j = 1; j <= range; j++ ) {
ret.x = pos->x + j*grid[i].x;
ret.y = pos->y + j*grid[i].y;
if (ret.x == hero.x && ret.y == hero.y)
continue; /* skip the hero */
if (ret.x < 0 || ret.x > cols - 1 ||
ret.y < 1 || ret.y > lines - 3)
continue; /* off the screen? */
ch = winat(ret.y, ret.x);
/*
* Check to make certain the spot is valid
*/
switch( ch ) {
case FLOOR:
case PASSAGE:
return( &ret );
case GOLD:
case SCROLL:
case POTION:
case STICK:
case RING:
case WEAPON:
case ARMOR:
case MM:
case FOOD:
if(!be_clear && levtype != POSTLEV)
return( &ret );
default:
break;
}
}
}
return( NULL );
}
/*
* findmindex:
* Find the index into the monster table of a monster given its name.
*/
findmindex(name)
char *name;
{
int which;
for (which=1; which<NUMMONST; which++) {
if (strcmp(name, monsters[which].m_name) == 0)
break;
}
if (which >= NUMMONST) {
debug("couldn't find monster index");
which = 1;
}
return(which);
}
/*
* find_mons:
* Find the monster from his coordinates
*/
struct linked_list *
find_mons(y, x)
register int y;
register int x;
{
register struct linked_list *item;
register struct thing *th;
for (item = mlist; item != NULL; item = next(item))
{
th = THINGPTR(item);
if (th->t_pos.y == y && th->t_pos.x == x)
return item;
}
return NULL;
}
/*
* find_obj:
* find the unclaimed object at y, x
*/
struct linked_list *
find_obj(y, x)
register int y;
register int x;
{
register struct linked_list *obj;
register struct object *op;
for (obj = lvl_obj; obj != NULL; obj = next(obj))
{
op = OBJPTR(obj);
if (op->o_pos.y == y && op->o_pos.x == x)
return obj;
}
return NULL;
}
/*
* get coordinates from the player using the cursor keys (or mouse)
*/
coord
get_coordinates()
{
register int which;
coord c;
c = hero;
wmove(cw, hero.y, hero.x);
draw(cw);
for (;;) {
which = (wgetch(cw) & 0177);
switch(which) {
case ESC:
c = hero;
wmove(cw, c.y, c.x);
draw(cw);
case '\n':
case '\r':
return(c);
when 'h':
case 'H':
c.x--;
when 'j':
case 'J':
c.y++;
when 'k':
case 'K':
c.y--;
when 'l':
case 'L':
c.x++;
when 'y':
case 'Y':
c.x--; c.y--;
when 'u':
case 'U':
c.x++; c.y--;
when 'b':
case 'B':
c.x--; c.y++;
when 'n':
case 'N':
c.x++; c.y++;
when '*':
mpos = 0;
msg("Use h,j,k,l,y,u,b,n to position cursor, then press enter.");
}
c.y = max(c.y, 1);
c.y = min(c.y, lines - 3);
c.x = max(c.x, 0);
c.x = min(c.x, cols - 1);
wmove(cw, c.y, c.x);
draw(cw);
}
}
/*
* set up the direction co_ordinate for use in various "prefix" commands
*/
bool
get_dir(direction)
coord *direction;
{
register char *prompt;
register bool gotit;
int x,y;
prompt = terse ? "Direction?" : "Which direction? ";
msg(prompt);
do
{
gotit = TRUE;
switch (wgetch(msgw))
{
case 'h': case'H': direction->y = 0; direction->x = -1;
when 'j': case'J': direction->y = 1; direction->x = 0;
when 'k': case'K': direction->y = -1; direction->x = 0;
when 'l': case'L': direction->y = 0; direction->x = 1;
when 'y': case'Y': direction->y = -1; direction->x = -1;
when 'u': case'U': direction->y = -1; direction->x = 1;
when 'b': case'B': direction->y = 1; direction->x = -1;
when 'n': case'N': direction->y = 1; direction->x = 1;
when ESC: return (FALSE);
otherwise:
mpos = 0;
msg(prompt);
gotit = FALSE;
}
} until (gotit);
if ((on(player, ISHUH) || on(player, ISDANCE)) && rnd(100) > 20) {
do
{
*direction = grid[rnd(9)];
} while (direction->y == 0 && direction->x == 0);
}
else if (on(player, ISFLEE)) {
y = hero.y;
x = hero.x;
while (shoot_ok(winat(y, x))) {
y += direction->y;
x += direction->x;
}
if (isalpha(mvwinch(mw, y, x))) {
if (y == player.t_dest->y && x == player.t_dest->x) {
mpos = 0;
msg("You are too frightened to!");
return(FALSE);
}
}
}
mpos = 0;
return TRUE;
}
/*
* get_worth:
* Calculate an objects worth in gold
*/
long
get_worth(obj)
reg struct object *obj;
{
reg long worth, wh;
worth = 0;
wh = obj->o_which;
switch (obj->o_type) {
case FOOD:
worth = 2;
when WEAPON:
if (wh < MAXWEAPONS) {
worth = weaps[wh].w_worth;
worth += s_magic[S_ALLENCH].mi_worth *
(obj->o_hplus + obj->o_dplus);
}
when ARMOR:
if (wh < MAXARMORS) {
worth = armors[wh].a_worth;
worth += s_magic[S_ALLENCH].mi_worth *
(armors[wh].a_class - obj->o_ac);
}
when SCROLL:
if (wh < MAXSCROLLS)
worth = s_magic[wh].mi_worth;
when POTION:
if (wh < MAXPOTIONS)
worth = p_magic[wh].mi_worth;
when RING:
if (wh < MAXRINGS) {
worth = r_magic[wh].mi_worth;
worth += obj->o_ac * 40;
}
when STICK:
if (wh < MAXSTICKS) {
worth = ws_magic[wh].mi_worth;
worth += 20 * obj->o_charges;
}
when MM:
if (wh < MAXMM) {
worth = m_magic[wh].mi_worth;
switch (wh) {
case MM_BRACERS: worth += 40 * obj->o_ac;
when MM_PROTECT: worth += 60 * obj->o_ac;
when MM_DISP: /* ac already figured in price*/
otherwise: worth += 20 * obj->o_ac;
}
}
when RELIC:
if (wh < MAXRELIC) {
worth = rel_magic[wh].mi_worth;
if (wh == quest_item) worth *= 10;
}
otherwise:
worth = 0;
}
if (obj->o_flags & ISPROT) /* 300% more for protected */
worth *= 3;
if (obj->o_flags & ISBLESSED) /* 50% more for blessed */
worth = worth * 3 / 2;
if (obj->o_flags & ISCURSED) /* half for cursed */
worth /= 2;
if (worth < 0)
worth = 0;
return worth;
}
/*
* invisible()
*/
bool
invisible(monst)
register struct thing *monst;
{
register bool ret_code;
ret_code = on(*monst, CANSURPRISE);
ret_code &= !ISWEARING(R_ALERT);
ret_code |= (on(*monst, ISINVIS) ||
(on(*monst, ISSHADOW) && rnd(100) < 90)) &&
off(player, CANSEE);
return( ret_code );
}
/*
* see if the object is one of the currently used items
*/
is_current(obj)
register struct object *obj;
{
if (obj == NULL)
return FALSE;
if (obj == cur_armor || obj == cur_weapon ||
obj == cur_ring[LEFT_1] || obj == cur_ring[LEFT_2] ||
obj == cur_ring[LEFT_3] || obj == cur_ring[LEFT_4] ||
obj == cur_ring[RIGHT_1] || obj == cur_ring[RIGHT_2] ||
obj == cur_ring[RIGHT_3] || obj == cur_ring[RIGHT_4] ||
obj == cur_misc[WEAR_BOOTS] || obj == cur_misc[WEAR_JEWEL] ||
obj == cur_misc[WEAR_BRACERS] || obj == cur_misc[WEAR_CLOAK] ||
obj == cur_misc[WEAR_GAUNTLET] || obj == cur_misc[WEAR_NECKLACE]) {
return TRUE;
}
/* Is it a "current" relic? */
if (obj->o_type == RELIC) {
switch (obj->o_which) {
case MUSTY_DAGGER:
case EMORI_CLOAK:
case HEIL_ANKH:
case YENDOR_AMULET:
case STONEBONES_AMULET:
case HRUGGEK_MSTAR:
case AXE_AKLAD:
case YEENOGHU_FLAIL:
case SURTUR_RING:
if (cur_relic[obj->o_which]) return TRUE;
}
}
return FALSE;
}
/*
* Look:
* A quick glance all around the player
*/
look(wakeup, runend)
bool wakeup; /* Should we wake up monsters */
bool runend; /* At end of a run -- for mazes */
{
register int x, y, radius;
register unsigned char ch, och;
register int oldx, oldy;
register bool inpass, horiz, vert, do_light = FALSE, do_blank = FALSE;
register int passcount = 0, curfloorcount = 0, nextfloorcount = 0;
register struct room *rp;
register int ey, ex;
inpass = ((rp = roomin(&hero)) == NULL); /* Are we in a passage? */
/* Are we moving vertically or horizontally? */
if (runch == 'h' || runch == 'l') horiz = TRUE;
else horiz = FALSE;
if (runch == 'j' || runch == 'k') vert = TRUE;
else vert = FALSE;
/* How far around himself can the player see? */
if (levtype == OUTSIDE) {
if (daytime) radius = 9;
else if (lit_room(rp)) radius = 3;
else radius = 1;
}
else radius = 1;
getyx(cw, oldy, oldx); /* Save current position */
/* Blank out the floor around our last position and check for
* moving out of a corridor in a maze.
*/
if (levtype == OUTSIDE) do_blank = !daytime;
else if (oldrp != NULL && !lit_room(oldrp) && off(player, ISBLIND))
do_blank = TRUE;
/* Now move around the old position and blank things out */
ey = player.t_oldpos.y + radius;
ex = player.t_oldpos.x + radius;
for (x = player.t_oldpos.x - radius; x <= ex; x++)
if (x >= 0 && x < cols)
for (y = player.t_oldpos.y - radius; y <= ey; y++) {
struct linked_list *it;
coord here; /* Current <x,y> coordinate */
unsigned char savech; /* Saves character in monster window */
bool in_room; /* Are we in a room? */
if (y < 1 || y > lines - 3) continue;
/* See what's there -- ignore monsters, just see what they're on */
savech = mvwinch(mw, y, x);
waddch(mw, ' ');
ch = show(y, x);
mvwaddch(mw, y, x, savech); /* Restore monster */
/*
* If we have a monster that we can't see anymore, make sure
* that we can note that fact.
*/
if (isalpha(savech) &&
(y < hero.y - radius || y > hero.y + radius ||
x < hero.x - radius || x > hero.x + radius)) {
/* Find the monster */
it = find_mons(y, x);
}
else it = NULL;
/* Are we in a room? */
here.y = y;
here.x = x;
in_room = (roomin(&here) != NULL);
if ((do_blank || !in_room) && (y != hero.y || x != hero.x))
switch (ch) {
case DOOR:
case SECRETDOOR:
case PASSAGE:
case STAIRS:
case TRAPDOOR:
case TELTRAP:
case BEARTRAP:
case SLEEPTRAP:
case ARROWTRAP:
case DARTTRAP:
case WORMHOLE:
case MAZETRAP:
case POOL:
case POST:
case VERTWALL:
case HORZWALL:
case WALL:
/* If there was a monster showing, make it disappear */
if (isalpha(savech)) {
mvwaddch(cw, y, x, ch);
/*
* If we found it (we should!), set it to
* the right character!
*/
if (it) (THINGPTR(it))->t_oldch = ch;
}
break;
when FLOOR:
case FOREST:
default:
mvwaddch(cw, y, x, in_room ? ' ' : PASSAGE);
/* If we found a monster, set it to darkness! */
if (it) (THINGPTR(it))->t_oldch = mvwinch(cw, y, x);
}
/* Moving out of a corridor? */
if (levtype == MAZELEV && !ce(hero, player.t_oldpos) &&
!running && !isrock(ch) && /* Not running and not a wall */
((vert && x != player.t_oldpos.x && y==player.t_oldpos.y) ||
(horiz && y != player.t_oldpos.y && x==player.t_oldpos.x)))
do_light = off(player, ISBLIND);
}
/* Take care of unlighting a corridor */
if (do_light && lit_room(rp)) light(&player.t_oldpos);
/* Are we coming or going between a wall and a corridor in a maze? */
och = show(player.t_oldpos.y, player.t_oldpos.x);
ch = show(hero.y, hero.x);
if (levtype == MAZELEV &&
((isrock(och) && !isrock(ch)) || (isrock(ch) && !isrock(och)))) {
do_light = off(player, ISBLIND); /* Light it up if not blind */
/* Unlight what we just saw */
if (do_light && lit_room(&rooms[0])) light(&player.t_oldpos);
}
/* Look around the player */
ey = hero.y + radius;
ex = hero.x + radius;
for (x = hero.x - radius; x <= ex; x++)
if (x >= 0 && x < cols) for (y = hero.y - radius; y <= ey; y++) {
if (y < 1 || y >= lines - 2)
continue;
if (isalpha(mvwinch(mw, y, x)))
{
register struct linked_list *it;
register struct thing *tp;
if (wakeup)
it = wake_monster(y, x);
else
it = find_mons(y, x);
if (it) {
tp = THINGPTR(it);
tp->t_oldch = mvinch(y, x);
if (isatrap(tp->t_oldch)) {
register struct trap *trp = trap_at(y, x);
tp->t_oldch = (trp->tr_flags & ISFOUND) ? tp->t_oldch
: trp->tr_show;
}
if (tp->t_oldch == FLOOR && !lit_room(rp) &&
off(player, ISBLIND))
tp->t_oldch = ' ';
}
}
/*
* Secret doors show as walls
*/
if ((ch = show(y, x)) == SECRETDOOR)
ch = secretdoor(y, x);
/*
* Don't show room walls if he is in a passage and
* check for maze turns
*/
if (off(player, ISBLIND))
{
if (y == hero.y && x == hero.x
|| (inpass && (ch == HORZWALL || ch == VERTWALL)))
continue;
/* Did we come to a crossroads in a maze? */
if (levtype == MAZELEV &&
(runend || !ce(hero, player.t_oldpos)) &&
!isrock(ch) && /* Not a wall */
((vert && x != hero.x && y == hero.y) ||
(horiz && y != hero.y && x == hero.x)))
/* Just came to a turn */
do_light = off(player, ISBLIND);
}
else if (y != hero.y || x != hero.x)
continue;
wmove(cw, y, x);
waddch(cw, ch);
if (door_stop && !firstmove && running)
{
switch (runch)
{
case 'h':
if (x == hero.x + 1)
continue;
when 'j':
if (y == hero.y - 1)
continue;
when 'k':
if (y == hero.y + 1)
continue;
when 'l':
if (x == hero.x - 1)
continue;
when 'y':
if ((x + y) - (hero.x + hero.y) >= 1)
continue;
when 'u':
if ((y - x) - (hero.y - hero.x) >= 1)
continue;
when 'n':
if ((x + y) - (hero.x + hero.y) <= -1)
continue;
when 'b':
if ((y - x) - (hero.y - hero.x) <= -1)
continue;
}
switch (ch)
{
case DOOR:
if (x == hero.x || y == hero.y)
running = FALSE;
break;
case PASSAGE:
if (x == hero.x || y == hero.y)
passcount++;
break;
case FLOOR:
/* Stop by new passages in a maze (floor next to us) */
if ((levtype == MAZELEV) &&
!(hero.y == y && hero.x == x)) {
if (vert) { /* Moving vertically */
/* We have a passage on our row */
if (y == hero.y) curfloorcount++;
/* Some passage on the next row */
else if (y != player.t_oldpos.y)
nextfloorcount++;
}
else { /* Moving horizontally */
/* We have a passage on our column */
if (x == hero.x) curfloorcount++;
/* Some passage in the next column */
else if (x != player.t_oldpos.x)
nextfloorcount++;
}
}
case VERTWALL:
case HORZWALL:
case ' ':
break;
default:
running = FALSE;
break;
}
}
}
/* Have we passed a side passage, with multiple choices? */
if (curfloorcount > 0 && nextfloorcount > 0) running = FALSE;
else if (door_stop && !firstmove && passcount > 1)
running = FALSE;
/* Do we have to light up the area (just stepped into a new corridor)? */
if (do_light && !running && lit_room(rp)) light(&hero);
mvwaddch(cw, hero.y, hero.x, PLAYER);
wmove(cw, oldy, oldx);
if (!ce(player.t_oldpos, hero)) {
player.t_oldpos = hero; /* Don't change if we didn't move */
oldrp = rp;
}
}
/*
* Lower a level of experience
*/
lower_level(who)
short who;
{
int fewer, nsides;
unsigned long exp;
msg("You suddenly feel less skillful.");
if (--pstats.s_lvl == 0) {
pstats.s_hpt = -1;
death(who); /* All levels gone */
}
if (pstats.s_lvladj > 0) { /* lose artificial levels first */
pstats.s_lvladj--;
return;
}
exp = char_class[player.t_ctype].cap;
if (pstats.s_exp >= exp*2)
pstats.s_exp -= exp;
else
pstats.s_exp /= 2;
nsides = char_class[player.t_ctype].hit_pts;
fewer = max(1, roll(1,nsides) + const_bonus());
pstats.s_hpt -= fewer;
max_stats.s_hpt -= fewer;
if (max_stats.s_hpt <= 0)
max_stats.s_hpt = 0;
if (pstats.s_hpt <= 0) {
pstats.s_hpt = -1;
death(who);
}
}
/*
* print out the name of a monster
*/
char *
monster_name(tp)
register struct thing *tp;
{
prbuf[0] = '\0';
if (on(*tp, ISFLEE) || on(*tp, WASTURNED))
strcat(prbuf, "terrified ");
if (on(*tp, ISHUH))
strcat(prbuf, "confused ");
if (on(*tp, ISCHARMED))
strcat(prbuf, "charmed ");
else if (on(*tp, ISFLY))
strcat(prbuf, "flying ");
/* If it is sleeping or stoned, write over any of the above attributes */
if (off(*tp, ISRUN))
strcpy(prbuf, "sleeping ");
if (on(*tp, ISSTONE))
strcpy(prbuf, "petrified ");
if (tp->t_name) strcat(prbuf, tp->t_name);
else strcat(prbuf, monsters[tp->t_index].m_name);
return(prbuf);
}