-
Notifications
You must be signed in to change notification settings - Fork 1
/
command.c
1305 lines (1199 loc) · 44.9 KB
/
command.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
/*
command.c - Read and execute the user commands
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 <signal.h>
#include "mach_dep.h"
#include "rogue.h"
/*
* command:
* Process the user commands
*/
command()
{
unsigned int ch;
struct linked_list *item;
unsigned int countch = 0, direction = 0, newcount = FALSE;
int segment = 1;
int monst_limit, monst_current;
monst_limit = monst_current = 1;
while (playing) {
/*
* Let the daemons start up, but only do them once a round
* (round = 10 segments).
*/
if (segment >= 10) {
do_daemons(BEFORE);
do_fuses(BEFORE);
}
after = TRUE;
do {
/* One more tick of the clock. */
if (segment >= 10 && after && (++turns % DAYLENGTH) == 0) {
daytime ^= TRUE;
if (levtype == OUTSIDE) {
if (daytime) msg("A bright star flares above the horizon.");
else msg("The bright star travels beyond the horizon.");
}
light(&hero);
}
/*
* Don't bother with these updates unless the player's going
* to do something.
*/
if (player.t_action == A_NIL && player.t_no_move <= 1) {
look(after, FALSE);
lastscore = purse;
wmove(cw, hero.y, hero.x);
if (!((running || count) && jump)) {
status(FALSE);
}
}
/* Draw the screen */
if (!((running || count) && jump)) {
wmove(cw, hero.y, hero.x);
draw(cw);
}
after = TRUE;
/*
* Read command or continue run
*/
if (--player.t_no_move <= 0) {
take = 0; /* Nothing here to start with */
player.t_no_move = 0; /* Be sure we don't go too negative */
if (!running) door_stop = FALSE;
/* Was the player being held? */
if (player.t_action == A_FREEZE) {
player.t_action = A_NIL;
msg("You can move again.");
}
if (player.t_action != A_NIL) ch = player.t_action;
else if (running) {
char scratch;
/* If in a corridor or maze, if we are at a turn with
* only one way to go, turn that way.
*/
scratch = winat(hero.y, hero.x);
if ((scratch==PASSAGE||scratch==DOOR||levtype==MAZELEV) &&
off(player, ISHUH) &&
off(player, ISBLIND)) {
int y, x;
if (getdelta(runch, &y, &x) == TRUE) {
corr_move(y, x);
}
}
ch = runch;
}
else if (count) ch = countch;
else {
ch = wgetch(cw);
if (mpos != 0 && !running) /* Erase message if its there */
msg("");
}
/*
* check for prefixes
*/
if (isascii(ch) && isdigit(ch))
{
count = 0;
newcount = TRUE;
while (isascii(ch) && isdigit(ch))
{
count = count * 10 + (ch - '0');
ch = wgetch(cw);
}
countch = ch;
/*
* turn off count for commands which don't make sense
* to repeat
*/
switch (ch) {
case 'h': case 'j': case 'k': case 'l':
case 'y': case 'u': case 'b': case 'n':
case 'H': case 'J': case 'K': case 'L':
case 'Y': case 'U': case 'B': case 'N':
case C_SEARCH: case '.':
break;
default:
count = 0;
}
}
/* Save current direction */
if (!running) { /* If running, it is already saved */
switch (ch) {
case 'h': case 'j': case 'k': case 'l':
case 'y': case 'u': case 'b': case 'n':
case 'H': case 'J': case 'K': case 'L':
case 'Y': case 'U': case 'B': case 'N':
runch = tolower(ch);
}
}
/* Perform the action */
switch (ch) {
case 'f':
if (!on(player, ISBLIND))
{
door_stop = TRUE;
firstmove = TRUE;
}
if (count && !newcount)
ch = direction;
else
ch = wgetch(cw);
switch (ch)
{
case 'h': case 'j': case 'k': case 'l':
case 'y': case 'u': case 'b': case 'n':
ch = toupper(ch);
}
direction = ch;
}
newcount = FALSE;
/*
* execute a command
*/
if (count && !running)
count--;
switch (ch) {
case '!' : shell();
case KEY_LEFT : do_move(0, -1);
when KEY_DOWN : do_move(1, 0);
when KEY_UP : do_move(-1, 0);
when KEY_RIGHT : do_move(0, 1);
when KEY_HOME : do_move(-1, -1);
when KEY_A1 : do_move(-1, -1);
when KEY_PPAGE : do_move(-1, 1);
when KEY_A3 : do_move(-1, 1);
when KEY_END : do_move(1, -1);
when KEY_C1 : do_move(1, -1);
when KEY_NPAGE : do_move(1, 1);
when KEY_C3 : do_move(1, 1);
#ifdef CTL_RIGHT
when CTL_RIGHT : do_run('l');
when CTL_LEFT : do_run('h');
when CTL_UP : do_run('k');
when CTL_DOWN : do_run('j');
when CTL_HOME : do_run('y');
when CTL_PGUP : do_run('u');
when CTL_END : do_run('b');
when CTL_PGDN : do_run('n');
#endif
when 'h' : do_move(0, -1);
when 'j' : do_move(1, 0);
when 'k' : do_move(-1, 0);
when 'l' : do_move(0, 1);
when 'y' : do_move(-1, -1);
when 'u' : do_move(-1, 1);
when 'b' : do_move(1, -1);
when 'n' : do_move(1, 1);
when 'H' : do_run('h');
when 'J' : do_run('j');
when 'K' : do_run('k');
when 'L' : do_run('l');
when 'Y' : do_run('y');
when 'U' : do_run('u');
when 'B' : do_run('b');
when 'N' : do_run('n');
when A_ATTACK:
/* Is our attackee still there? */
if (isalpha(winat(player.t_newpos.y,
player.t_newpos.x))) {
/* Our friend is still here */
player.t_action = A_NIL;
fight(&player.t_newpos, cur_weapon, FALSE);
}
else { /* Our monster has moved */
player.t_action = A_NIL;
}
when A_PICKUP:
player.t_action = A_NIL;
if (add_pack((struct linked_list *)NULL, FALSE)) {
char tch;
tch = mvwinch(stdscr, hero.y, hero.x);
if (tch != FLOOR && tch != PASSAGE) {
player.t_action = A_PICKUP; /*get more */
player.t_no_move += 2 * movement(&player);
}
}
when A_THROW:
if (player.t_action == A_NIL) {
item = get_item(pack, "throw", ALL, FALSE, FALSE);
if (item != NULL && get_dir(&player.t_newpos)) {
player.t_action = A_THROW;
player.t_using = item;
player.t_no_move = 2 * movement(&player);
}
else
after = FALSE;
}
else {
missile(player.t_newpos.y, player.t_newpos.x,
player.t_using, &player);
player.t_action = A_NIL;
player.t_using = 0;
}
when 'a' :
if (player.t_action == A_NIL) {
if (get_dir(&player.t_newpos)) {
player.t_action = 'a';
player.t_no_move = 1 + movement(&player);
}
else
after = FALSE;
}
else {
affect();
player.t_action = A_NIL;
}
when 'A' : choose_qst();
when 'F' : /* frighten a monster */
if (player.t_action == A_NIL) {
player.t_action = 'F';
player.t_no_move = 2*movement(&player);
}
else {
after = FALSE;
player.t_action = A_NIL;
fright();
}
when 'g' : /* Give command: give slime-molds to monsters */
if (player.t_action == A_NIL) {
player.t_action = 'g';
player.t_no_move = 2*movement(&player);
}
else {
after = FALSE;
player.t_action = A_NIL;
give();
}
when 'G' :
if (player.t_action == A_NIL) {
player.t_action = 'G';
player.t_no_move = movement(&player);
}
else {
player.t_action = A_NIL;
gsense();
}
when 'i' : after = FALSE; inventory(pack, ALL);
when 'I' : after = FALSE; picky_inven();
when 'm' : nameitem((struct linked_list *)NULL, TRUE);
when 'o' : option();
when 'O' : msg("Charactor type: %s Quest item: %s", char_class[char_type].name, rel_magic[quest_item].mi_name);
when ',' :
case 'P' :
if (levtype != POSTLEV) {
/* We charge 2 movement units per item */
player.t_no_move =
2 * grab(hero.y, hero.x) * movement(&player);
}
else {
/* Let's quote the wise guy a price */
buy_it();
after = FALSE;
}
when 'Q' : after = FALSE; quit(0);
when 'S' :
after = FALSE;
if (save_game())
exit_game(EXIT_CLS | EXIT_ENDWIN);
when 'v' : after = FALSE;
msg("Advanced xrogue, Version %s ", release);
when 'X' : /* trap sense */
after = FALSE;
if (player.t_action == A_NIL) {
player.t_action = 'X';
player.t_no_move = movement(&player);
}
else {
xsense();
player.t_action = A_NIL;
}
when '.' :
player.t_no_move = movement(&player); /* Rest */
player.t_action = A_NIL;
when ' ' : after = FALSE; /* Do Nothing */
when '>' : after = FALSE; d_level();
when '<' : after = FALSE; u_level();
when '=' : after = FALSE; display();
when '?' : after = FALSE; help();
/* no character descriptions yet until updated (help.c) */
/* when '\\' : after = FALSE; ident_hero(); */
when '\\' : msg("Charon (the Boatman) looks at you... ");
when '/' : after = FALSE; identify(NULL);
when C_COUNT : count_gold();
when C_DIP : dip_it();
when C_DROP : player.t_action = C_DROP;
drop((struct linked_list *)NULL);
when C_EAT : eat();
when C_QUAFF : quaff(-1, NULL, NULL, TRUE);
when C_READ : read_scroll(-1, NULL, TRUE);
when C_SETTRAP : set_trap(&player, hero.y, hero.x);
when C_SEARCH :
if (player.t_action == A_NIL) {
player.t_action = C_SEARCH;
player.t_no_move = 2 + movement(&player);
}
else {
search(FALSE, FALSE);
player.t_action = A_NIL;
}
when C_TAKEOFF : take_off();
when C_USE : use_mm(-1);
when C_WEAR : wear();
when C_WIELD : wield();
when C_ZAP : if (!player_zap(NULL, FALSE)) after=FALSE;
when C_CAST : cast();
when C_CHANT : chant();
when C_PRAY : pray();
when CTRL('B') : msg("Current score: %d",
pstats.s_exp + (long) purse);
when CTRL('E') : msg("Current food level: %d(2000)",
food_left);
when CTRL('L') : after = FALSE; clearok(curscr, TRUE);
touchwin(cw);
when CTRL('N') : nameit();
when CTRL('O') : after = FALSE; opt_player();
when CTRL('R') : after = FALSE; msg(huh);
when CTRL('T') :
if (player.t_action == A_NIL) {
if (get_dir(&player.t_newpos)) {
player.t_action = CTRL('T');
player.t_no_move = 2 * movement(&player);
}
else
after = FALSE;
}
else {
steal();
player.t_action = A_NIL;
}
when ESC : /* Escape */
door_stop = FALSE;
count = 0;
after = FALSE;
when '#':
if (levtype == POSTLEV) /* buy something */
buy_it();
after = FALSE;
when '$':
if (levtype == POSTLEV) /* price something */
price_it();
after = FALSE;
when '%':
if (levtype == POSTLEV) /* sell something */
sell_it();
after = FALSE;
when '+': /* instant karma! */
switch (rnd(100)) {
case 0: msg("You waste some time. ");
when 5: msg("An oak tree in the garden. ");
when 10: msg("Character is what you become in the dark. ");
when 15: msg("May you live all the days of your life. ");
when 20: msg("A hero is no braver than an ordinary man, but he is brave five minutes longer. ");
when 25: msg("Get down! ");
when 30: msg("Go back to sleep. ");
when 35: msg("Be here now. ");
when 40: msg("Choose the rock that feels right to you. ");
when 45: msg("Wait... ");
when 50: msg("You take a break (yawn)... ");
when 55: msg("Without danger there is no pleasure. ");
when 60: msg("Define meaningless? ");
when 65: msg("Don't push your luck! ");
when 70: msg("Gung ho. ");
when 75: msg("You are inside a computer. ");
when 80: msg("Directive is now required... ");
when 85: msg("Charon (the Boatman) awaits you... ");
when 95: msg(nothing);
otherwise: msg("");
}
after = FALSE;
when CTRL('P') :
after = FALSE;
if (wizard)
{
wizard = FALSE;
trader = 0;
msg("Not wizard any more");
}
else
{
if (waswizard || passwd())
{
msg("Welcome, O Mighty Wizard! ");
wizard = waswizard = TRUE;
}
else
msg("Sorry");
}
otherwise :
after = FALSE;
if (wizard) switch (ch) {
case 'M' : create_obj(TRUE, 0, 0);
when 'V' : msg("vlevel = %d turns = %d",
vlevel, turns);
when CTRL('A') : activity();
when CTRL('C') : do_teleport();
when CTRL('D') : level++;
take_with();
new_level(NORMLEV);
when CTRL('F') : overlay(stdscr,cw);
when CTRL('G') :
{
item=get_item(pack,"charge",STICK,FALSE,FALSE);
if (item != NULL) {
(OBJPTR(item))->o_charges=10000;
}
}
when CTRL('H') :
{
register int i, j;
register struct object *obj;
for (i = 0; i < 9; i++)
raise_level();
/*
* Give the rogue a sword
*/
if (cur_weapon==NULL || cur_weapon->o_type !=
RELIC) {
if (player.t_ctype == C_THIEF ||
player.t_ctype == C_ASSASSIN ||
player.t_ctype == C_MONK)
item = spec_item(WEAPON, BASWORD, 20, 20);
else
item = spec_item(WEAPON,TWOSWORD, 20, 20);
if (add_pack(item, TRUE))
{
cur_weapon = OBJPTR(item);
(OBJPTR(item))->o_flags |= (ISKNOW|ISPROT);
}
else
o_discard(item);
/*
* And his suit of armor
*/
if (player.t_ctype == C_THIEF ||
player.t_ctype == C_ASSASSIN ||
player.t_ctype == C_MONK)
j = PADDED_ARMOR;
else
j = PLATE_ARMOR;
item = spec_item(ARMOR, j, 20, 0);
obj = OBJPTR(item);
obj->o_flags |= (ISKNOW | ISPROT);
obj->o_weight = armors[j].a_wght;
if (add_pack(item, TRUE))
cur_armor = obj;
else
o_discard(item);
}
purse += 20000;
}
when CTRL('I') : inventory(lvl_obj, ALL);
when CTRL('J') : teleport();
when CTRL('K') : whatis((struct linked_list *)NULL);
when CTRL('W') : wanderer();
when CTRL('X') : overlay(mw,cw);
when CTRL('Y') : msg("food left: %d\tfood level: %d",
food_left, foodlev);
otherwise :
msg("Illegal wizard command '%s'.", unctrl(ch));
count = 0;
}
else
{
msg("Illegal command '%s'.", unctrl(ch));
count = 0;
after = FALSE;
}
}
/*
* If he ran into something to take, let him pick it up.
* unless it's a trading post
*/
if (auto_pickup && take != 0 && levtype != POSTLEV) {
/* get ready to pick it up */
player.t_action = A_PICKUP;
player.t_no_move += 2 * movement(&player);
}
}
/* If he was fighting, let's stop (for now) */
if (player.t_quiet < 0) player.t_quiet = 0;
if (!running)
door_stop = FALSE;
if (after && segment >= 10) {
/*
* Kick off the rest if the daemons and fuses
*/
/*
* If player is infested, take off a hit point
*/
if (on(player, HASINFEST)) {
pstats.s_hpt -= infest_dam;
if (pstats.s_hpt == 50 || pstats.s_hpt == 25)
msg("You feel yourself withering away... ");
if (pstats.s_hpt < 1) {
msg("You die a festering mass. --More--");
wait_for(' ');
pstats.s_hpt = -1;
death(D_INFESTATION);
}
}
/*
* The eye of Vecna is a constant drain on the player
*/
if (cur_relic[EYE_VECNA]) {
pstats.s_hpt -= 1;
if (pstats.s_hpt == 50 || pstats.s_hpt == 25)
msg("You feel Vecna's eye looking about. ");
if (pstats.s_hpt <= 10 && pstats.s_hpt >= 3)
msg("Vecna's eye moves about very quickly. ");
if (pstats.s_hpt < 1) {
msg("Vecna's curse is upon you! --More--");
wait_for(' ');
pstats.s_hpt = -1;
death(D_RELIC);
}
}
/*
* if player has body rot then take off three hits
*/
if (on(player, DOROT)) {
pstats.s_hpt -= rnd(3)+1;
if (pstats.s_hpt == 50 || pstats.s_hpt == 25)
msg("Something really begins to stink and smell! ");
if (pstats.s_hpt < 1) {
msg("You keel over with rot. --More--");
wait_for(' ');
pstats.s_hpt = -1;
death(D_ROT);
}
}
do_daemons(AFTER);
do_fuses(AFTER);
}
} while (after == FALSE);
/* Make the monsters go */
if (--monst_current <= 0)
monst_current = monst_limit = runners(monst_limit);
if (++segment > 10) segment = 1;
reap(); /* bury all the dead monsters */
}
}
/*
* display
* tell the player what is at a certain coordinates assuming
* it can be seen.
*/
display()
{
coord c;
struct linked_list *item;
struct thing *tp;
int what;
msg("What do you want to display (* for help)?");
c = get_coordinates();
mpos = 0;
if (!cansee(c.y, c.x)) {
msg("You can't see what is there.");
return;
}
what = mvwinch(cw, c.y, c.x);
if (isalpha(what)) {
item = find_mons(c.y, c.x);
tp = THINGPTR(item);
msg("%s", monster_name(tp));
return;
}
if ((item = find_obj(c.y, c.x)) != NULL) {
msg("%s", inv_name(OBJPTR(item), FALSE));
return;
}
identify(what);
}
/*
* quit:
* Have player make certain, then exit.
*/
/*UNUSED*/
void
quit(sig)
int sig;
{
register int oy, ox;
NOOP(sig);
/*
* Reset the signal in case we got here via an interrupt
*/
if ((VOID(*)())signal(SIGINT, quit) != (VOID(*)())quit)
mpos = 0;
getyx(cw, oy, ox);
if (level < 1) { /* if not down in the dungeon proper; exit the game */
wclear(hw);
wmove(hw, lines-1, 0);
draw(hw);
wmove(hw, 12, 30);
wprintw(hw, "Good-bye!");
draw(hw);
exit_game(EXIT_ENDWIN);
}
msg("Really quit? <yes or no> "); /* otherwise ask about quitting */
draw(cw);
prbuf[0] = '\0';
if ((get_str(prbuf, msgw) == NORM) && strcmp(prbuf, "yes") == 0) {
clear();
move(lines-1, 0);
draw(stdscr);
score(pstats.s_exp + (long) purse, CHICKEN, 0);
exit_game(EXIT_ENDWIN);
}
else {
signal(SIGINT, quit);
wmove(msgw, 0, 0);
wclrtoeol(msgw);
draw(msgw);
status(FALSE);
wmove(cw, oy, ox);
draw(cw);
mpos = 0;
count = 0;
running = FALSE;
}
}
/*
* bugkill:
* killed by a program bug instead of voluntarily.
*/
bugkill(sig)
int sig;
{
signal(sig, quit); /* If we get it again, give up */
if (levtype == OUTSIDE) {
msg("Oh no! You walk right into a flying swarm of nasty little bugs!! ");
msg("One of them penetrates your brain!!! --More--");
}
else {
msg("Charon (the Boatman) has finally come for you... --More--");
}
wait_for(' ');
pstats.s_hpt = -1;
death(D_SIGNAL); /* Killed by a bug */
}
/*
* search:
* Player gropes about him to find hidden things.
*/
search(is_thief, door_chime)
register bool is_thief, door_chime;
{
register int x, y;
register char ch, /* The trap or door character */
sch; /* Trap or door character (as seen on screen) */
register unsigned char mch; /* Monster, if a monster is on the trap or door */
register struct linked_list *item;
register struct thing *mp; /* Status on surrounding monster */
/*
* Look all around the hero, if there is something hidden there,
* give him a chance to find it. If its found, display it.
*/
if (on(player, ISBLIND))
return;
for (x = hero.x - 1; x <= hero.x + 1; x++)
for (y = hero.y - 1; y <= hero.y + 1; y++)
{
if (y==hero.y && x==hero.x)
continue;
if (x < 0 || y < 0 || x >= cols || y >= lines)
continue;
/* Mch and ch will be the same unless there is a monster here */
mch = winat(y, x);
ch = mvwinch(stdscr, y, x);
sch = mvwinch(cw, y, x); /* What's on the screen */
if (door_chime == FALSE && isatrap(ch)) {
register struct trap *tp;
/* Is there a monster on the trap? */
if (mch != ch && (item = find_mons(y, x)) != NULL) {
mp = THINGPTR(item);
if (sch == mch) sch = mp->t_oldch;
}
else mp = NULL;
/*
* is this one found already?
*/
if (isatrap(sch))
continue; /* give him chance for other traps */
tp = trap_at(y, x);
/*
* if the thief set it then don't display it.
* if its not a thief he has 50/50 shot
*/
if((tp->tr_flags&ISTHIEFSET) || (!is_thief && rnd(100)>50))
continue; /* give him chance for other traps */
tp->tr_flags |= ISFOUND;
/* Let's update the screen */
if (mp != NULL && mvwinch(cw, y, x) == mch)
mp->t_oldch = ch; /* Will change when monst moves */
else mvwaddch(cw, y, x, ch);
count = 0;
running = FALSE;
/* Stop what we were doing */
player.t_no_move = movement(&player);
player.t_action = A_NIL;
player.t_using = NULL;
if (fight_flush) flushinp();
msg(tr_name(tp->tr_type));
}
else if (ch == SECRETDOOR) {
if (door_chime == TRUE || (!is_thief && rnd(100) < 20)) {
struct room *rp;
coord cp;
/* Is there a monster on the door? */
if (mch != ch && (item = find_mons(y, x)) != NULL) {
mp = THINGPTR(item);
/* Screen will change when monster moves */
if (sch == mch) mp->t_oldch = ch;
}
mvaddch(y, x, DOOR);
count = 0;
/*
* if its the entrance to a treasure room, wake it up
*/
cp.y = y;
cp.x = x;
rp = roomin(&cp);
if (rp->r_flags & ISTREAS)
wake_room(rp);
/* Make sure we don't shoot into the room */
if (door_chime == FALSE) {
count = 0;
running = FALSE;
/* Stop what we were doing */
player.t_no_move = movement(&player);
player.t_action = A_NIL;
player.t_using = NULL;
}
}
}
}
}
/*
* d_level:
* He wants to go down a level
*/
d_level()
{
bool no_phase=FALSE;
char position = winat(hero.y, hero.x);
int au;
/* If we are on a trading post, go to a trading post level. */
if (position == POST) {
take_with(); /* Take charmed monsters with you while shopping */
new_level(POSTLEV);
return;
}
/* Dive for gold */
if (position == POOL) {
if (rnd(300) < 2) {
msg("Oh no!!! You drown in the pool!!! --More--");
pstats.s_hpt = -1;
wait_for(' ');
death(D_DROWN);
}
else if (rnd(125) < 25) {
au = rnd(350) + (level * 10);
msg("You dive under the water momentarily.. ");
msg("You found %d gold pieces! ", au);
purse = purse + au;
return;
}
else return; /* doesn't happen all of the time */
}
/* Going down traps is hazardous */
switch (position) {
case WORMHOLE:
case TRAPDOOR:
case MAZETRAP:
case DARTTRAP:
case SLEEPTRAP:
case ARROWTRAP:
case BEARTRAP:
case TELTRAP:
msg ("You find yourself in some sort of quicksand!? ");
msg ("Hey! There are rock maggots in here!! ");
player.t_no_move += movement(&player) * FREEZETIME;
player.t_action = A_FREEZE;
msg("You can't move. "); /* spare monks */
if (!ISWEARING(R_HEALTH) && player.t_ctype != C_MONK) {
turn_on(player, DOROT);
msg("You feel your skin starting to rot and peel away!! ");
}
return;
}
/* If we are at a top-level trading post, we probably can't go down */
if (levtype == POSTLEV && level == 0 && position != STAIRS) {
msg("I see no way down.");
return;
}
if (winat(hero.y, hero.x) != STAIRS) {
if (off(player, CANINWALL) || /* Must use stairs if can't phase */
(levtype == OUTSIDE && rnd(100) < 90)) {
msg("I see no way down.");
return;
}
if (levtype == OUTSIDE) {
level++;
take_with();
new_level(NORMLEV);
if (no_phase) unphase();
return;
}
/* Is there any dungeon left below? */
if (level >= nfloors) {
msg("There is only solid rock below.");
return;
}
extinguish(unphase); /* Using phase to go down gets rid of it */
no_phase = TRUE;
}
/* Is this the bottom? */
if (level >= nfloors) {
msg("The stairway only goes up.");
return;
}
level++;
take_with();
new_level(NORMLEV);
if (no_phase) unphase();
}
/*
* u_level:
* He wants to go up a level
*/
u_level()
{
bool no_phase = FALSE;
register struct linked_list *item;
char position = winat(hero.y, hero.x);
struct thing *tp;
struct object *obj;
/* You can go up into the outside if standing on top of a worm hole */
if (position == WORMHOLE) {
prev_max = 1000;
level--;
if (level <= 0) level = 1;
msg("You find yourself in strange surroundings... ");
if (wizard) addmsg("Going up through a worm hole. ");
take_with();
new_level(OUTSIDE);
return;
}
if (winat(hero.y, hero.x) != STAIRS) {
if (off(player, CANINWALL)) { /* Must use stairs if can't phase */
msg("I see no way up.");
return;
}
extinguish(unphase);
no_phase = TRUE;
}
if (position != STAIRS) return;
if (level == 0 || levtype == OUTSIDE) {
msg("The stairway only goes down.");
return;
}
/*
* does he have the item he was quested to get?
*/
if (level == 1) {
for (item = pack; item != NULL; item = next(item)) {
obj = OBJPTR(item);
if (obj->o_type == RELIC && obj->o_which == quest_item)