/
moria1.c
2057 lines (1906 loc) · 46.1 KB
/
moria1.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
#include <stdio.h>
#include "constants.h"
#include "config.h"
#include "types.h"
#include "externs.h"
#ifdef USG
#include <string.h>
#else
#include <strings.h>
#endif
#ifdef sun /* correct SUN stupidity in the stdio.h file */
char *sprintf();
#endif
byteint de_statt();
byteint in_statt();
/* global flags */
extern int moria_flag; /* Next level when true */
extern int search_flag; /* Player is searching */
extern int teleport_flag; /* Handle teleport traps */
extern int player_light; /* Player carrying light */
extern int cave_flag; /* used in get_panel */
extern int light_flag; /* used in move_light */
/* Changes stats up or down for magic items -RAK- */
change_stat_factor(stat, amount, factor)
register byteint *stat;
int amount, factor;
{
register int i, j, k;
j = amount * factor;
if (amount < 0)
k = -amount;
else
k = amount;
for (i = 0; i < k; i++)
if (j < 0)
*stat = de_statt(*stat);
else
*stat = in_statt(*stat);
}
/* Changes speed of monsters relative to player -RAK- */
/* Note: When the player is sped up or slowed down, I simply */
/* change the speed of all the monsters. This greatly */
/* simplified the logic... */
change_speed(num)
register int num;
{
register int i;
py.flags.speed += num;
i = muptr;
while (i > 0)
{
m_list[i].cspeed += num;
i = m_list[i].nptr;
}
}
/* Player bonuses -RAK- */
/* When an item is worn or taken off, this re-adjusts the player */
/* bonuses. Factor==1 : wear; Factor==-1 : removed */
py_bonuses(tobj, factor)
treasure_type tobj;
int factor;
{
register unsigned int item_flags;
int old_dis_ac;
register struct flags *p_ptr;
register struct misc *m_ptr;
register treasure_type *i_ptr;
register int i;
p_ptr = &py.flags;
m_ptr = &py.misc;
if (p_ptr->slow_digest)
p_ptr->food_digested++;
if (p_ptr->regenerate)
p_ptr->food_digested -= 3;
p_ptr->see_inv = FALSE;
p_ptr->teleport = FALSE;
p_ptr->free_act = FALSE;
p_ptr->slow_digest = FALSE;
p_ptr->aggravate = FALSE;
p_ptr->sustain_str = FALSE;
p_ptr->sustain_int = FALSE;
p_ptr->sustain_wis = FALSE;
p_ptr->sustain_con = FALSE;
p_ptr->sustain_dex = FALSE;
p_ptr->sustain_chr = FALSE;
p_ptr->fire_resist = FALSE;
p_ptr->acid_resist = FALSE;
p_ptr->cold_resist = FALSE;
p_ptr->regenerate = FALSE;
p_ptr->lght_resist = FALSE;
p_ptr->ffall = FALSE;
if (0x00000001 & tobj.flags)
{
change_stat_factor(&py.stats.cstr, tobj.p1, factor);
change_stat_factor(&py.stats.str, tobj.p1, factor);
print_stat = (0x0001 | print_stat);
}
if (0x00000002 & tobj.flags)
{
change_stat_factor(&py.stats.cdex, tobj.p1, factor);
change_stat_factor(&py.stats.dex, tobj.p1, factor);
print_stat = (0x0002 | print_stat);
}
if (0x00000004 & tobj.flags)
{
change_stat_factor(&py.stats.ccon, tobj.p1, factor);
change_stat_factor(&py.stats.con, tobj.p1, factor);
print_stat = (0x0004 | print_stat);
}
if (0x00000008 & tobj.flags)
{
change_stat_factor(&py.stats.cint, tobj.p1, factor);
change_stat_factor(&py.stats.intel, tobj.p1, factor);
print_stat = (0x0008 | print_stat);
}
if (0x00000010 & tobj.flags)
{
change_stat_factor(&py.stats.cwis, tobj.p1, factor);
change_stat_factor(&py.stats.wis, tobj.p1, factor);
print_stat = (0x0010 | print_stat);
}
if (0x00000020 & tobj.flags)
{
change_stat_factor(&py.stats.cchr, tobj.p1, factor);
change_stat_factor(&py.stats.chr, tobj.p1, factor);
print_stat = (0x0020 | print_stat);
}
if (0x00000040 & tobj.flags)
{
m_ptr->srh += (tobj.p1 * factor);
m_ptr->fos -= (tobj.p1 * factor);
}
if (0x00000100 & tobj.flags)
m_ptr->stl += 2*factor;
if (0x00001000 & tobj.flags)
{
i = tobj.p1*factor;
change_speed(-i);
}
if (0x08000000 & tobj.flags)
if (factor > 0)
p_ptr->blind += 1000;
if (0x10000000 & tobj.flags)
if (factor > 0)
p_ptr->afraid += 50;
if (0x40000000 & tobj.flags)
p_ptr->see_infra += (tobj.p1 * factor);
old_dis_ac = m_ptr->dis_ac;
m_ptr->ptohit = tohit_adj(); /* Real To Hit */
m_ptr->ptodam = todam_adj(); /* Real To Dam */
m_ptr->ptoac = toac_adj(); /* Real To AC */
m_ptr->pac = 0; /* Real AC */
m_ptr->dis_th = m_ptr->ptohit; /* Display To Hit */
m_ptr->dis_td = m_ptr->ptodam; /* Display To Dam */
m_ptr->dis_ac = 0; /* Display To AC */
m_ptr->dis_tac = m_ptr->ptoac; /* Display AC */
for (i = 22; i < INVEN_MAX-2; i++)
{
i_ptr = &inventory[i];
if (i_ptr->tval != 0)
{
if ((0x80000000 & i_ptr->flags) == 0)
{
m_ptr->pac += i_ptr->ac;
m_ptr->dis_ac += i_ptr->ac;
}
m_ptr->ptohit += i_ptr->tohit;
m_ptr->ptodam += i_ptr->todam;
m_ptr->ptoac += i_ptr->toac;
if (index(i_ptr->name, '^') == 0)
{
m_ptr->dis_th += i_ptr->tohit;
m_ptr->dis_td += i_ptr->todam;
m_ptr->dis_tac += i_ptr->toac;
}
}
}
m_ptr->dis_ac += m_ptr->dis_tac;
/* Add in temporary spell increases */
if (p_ptr->invuln > 0)
{
m_ptr->pac += 100;
m_ptr->dis_ac += 100;
}
if (p_ptr->blessed > 0)
{
m_ptr->pac += 2;
m_ptr->dis_ac += 2;
}
if (p_ptr->detect_inv > 0)
p_ptr->see_inv = TRUE;
if (old_dis_ac != m_ptr->dis_ac)
print_stat = (0x0040 | print_stat);
item_flags = 0;
for (i = 22; i < INVEN_MAX-2; i++)
{
i_ptr = &inventory[i];
item_flags |= i_ptr->flags;
}
if (0x00000080 & item_flags)
p_ptr->slow_digest = TRUE;
if (0x00000200 & item_flags)
p_ptr->aggravate = TRUE;
if (0x00000400 & item_flags)
p_ptr->teleport = TRUE;
if (0x00000800 & item_flags)
p_ptr->regenerate = TRUE;
if (0x00080000 & item_flags)
p_ptr->fire_resist = TRUE;
if (0x00100000 & item_flags)
p_ptr->acid_resist = TRUE;
if (0x00200000 & item_flags)
p_ptr->cold_resist = TRUE;
if (0x00800000 & item_flags)
p_ptr->free_act = TRUE;
if (0x01000000 & item_flags)
p_ptr->see_inv = TRUE;
if (0x02000000 & item_flags)
p_ptr->lght_resist = TRUE;
if (0x04000000 & item_flags)
p_ptr->ffall = TRUE;
for (i = 22; i < INVEN_MAX-2; i++)
{
i_ptr = &inventory[i];
if (0x00400000 & i_ptr->flags)
switch(i_ptr->p1)
{
case 1: p_ptr->sustain_str = TRUE; break;
case 2: p_ptr->sustain_int = TRUE; break;
case 3: p_ptr->sustain_wis = TRUE; break;
case 4: p_ptr->sustain_con = TRUE; break;
case 5: p_ptr->sustain_dex = TRUE; break;
case 6: p_ptr->sustain_chr = TRUE; break;
default: break;
}
}
if (p_ptr->slow_digest)
p_ptr->food_digested--;
if (p_ptr->regenerate)
p_ptr->food_digested += 3;
}
/* Returns a "*" for cursed items, a ")" for normal ones -RAK- */
/* NOTE: "*" returned only if item has been identified... */
char cur_char1(item_val)
int item_val;
{
register treasure_type *i_ptr;
i_ptr = &inventory[item_val];
if ((0x80000000 & i_ptr->flags) == 0)
return(')'); /* Not cursed... */
else if (index(i_ptr->name, '^') != 0)
return(')'); /* Cursed, but not identified */
else
return('*'); /* Cursed and identified... */
}
/* Returns a "*" for cursed items, a ")" for normal ones -RAK- */
char cur_char2(item_val)
int item_val;
{
register treasure_type *i_ptr;
i_ptr = &inventory[item_val];
if ((0x80000000 & i_ptr->flags) == 0)
return(')'); /* Not cursed... */
else
return('*'); /* Cursed... */
}
/* inventory functions, define some global variables here */
/* scr_state == 0 : normal screen (i.e. map of dungeon)
or partial inventory list, (calling function sets redraw)
scr_state == 1 : inventory is displayed on the screen
scr_state == 2 : equipment list is displayed on the screen */
int scr_state;
/* Displays inventory items from r1 to r2 -RAK- */
show_inven(r1, r2)
register int r1, r2;
{
register int i;
vtype tmp_val, out_val;
if (r1 >= 0) /* R1 == 0 dummy call */
{
for (i = r1; i <= r2; i++) /* Print the items */
{
objdes(tmp_val, i, TRUE);
(void) sprintf(out_val, "%c%c %s", i+97, cur_char1(i), tmp_val);
prt(out_val, i+1, 0);
}
if (r2 < 22)
prt("", r2+2, 0); /* Clear line after */
scr_state = 1; /* Set state to 1 */
}
}
/* Displays equipment items from r1 to end -RAK- */
show_equip(r1)
register int r1;
{
register int i, j;
vtype prt1, prt2, out_val;
register treasure_type *i_ptr;
if (r1 >= equip_ctr) /* Last item gone */
prt("", equip_ctr+2, 0); /* clear the line */
else if (r1 >= 0) /* R1 == 0 dummy call */
{
j = 0;
for (i = 22; i < INVEN_MAX; i++) /* Range of equipment */
{
i_ptr = &inventory[i];
if (i_ptr->tval != 0)
{
if (j >= r1) /* Display only given range */
{
switch(i) /* Get position */
{
case 22:
(void) strcpy(prt1, " You are wielding : "); break;
case 23:
(void) strcpy(prt1, " Worn on head : "); break;
case 24:
(void) strcpy(prt1, " Worn around neck : "); break;
case 25:
(void) strcpy(prt1, " Worn on body : "); break;
case 26:
(void) strcpy(prt1, " Worn on arm : "); break;
case 27:
(void) strcpy(prt1, " Worn on hands : "); break;
case 28:
(void) strcpy(prt1, " Worn on right hand : "); break;
case 29:
(void) strcpy(prt1, " Worn on left hand : "); break;
case 30:
(void) strcpy(prt1, " Worn on feet : "); break;
case 31:
(void) strcpy(prt1, " Worn about body : "); break;
case 32:
(void) strcpy(prt1, " Light source : "); break;
case 33:
(void) strcpy(prt1, " Secondary weapon : "); break;
default:
(void) strcpy(prt1, " Unknown value : "); break;
}
objdes(prt2, i, TRUE);
(void) sprintf(out_val,
"%c%c%s%s", j+97, cur_char2(i), prt1, prt2);
prt(out_val, j+2, 0);
}
j++;
}
}
prt("", j+2, 0); /* Clear last line */
scr_state = 2; /* Set state of screen */
}
}
/* Remove item from equipment list -RAK- */
int remove_item(item_val)
int item_val;
{
register int i, j, typ;
vtype out_val, prt1, prt2;
int flag;
register treasure_type *i_ptr;
i = 0;
flag = FALSE;
typ = inventory[item_val].tval;
do
{
i_ptr = &inventory[i];
if (typ > i_ptr->tval)
{
for (j = inven_ctr-1; j >= i; j--)
inventory[j+1] = inventory[j];
inventory[i] = inventory[item_val];
inven_ctr++;
equip_ctr--;
flag = TRUE;
}
i++;
}
while (!flag);
i--;
switch(typ)
{
case 10: case 11: case 12: case 20: case 21: case 22: case 23: case 25 :
(void) strcpy(prt1, "Was wielding ");
break;
case 15:
(void) strcpy(prt1, "Light source was ");
break;
default:
(void) strcpy(prt1, "Was wearing ");
break;
}
objdes(prt2, i, TRUE);
(void) sprintf(out_val, "%s%s (%c)", prt1, prt2, i+97);
msg_print(out_val);
inventory[item_val] = blank_treasure;
if (item_val != INVEN_AUX) /* For secondary weapon */
py_bonuses(inventory[i], -1);
return(i);
}
/* Unwear routine, remove a piece of equipment -RAK- */
unwear()
{
register int i, j;
int exit_flag, test_flag, com_val;
char command;
vtype out_val;
if (scr_state == 1)
{
clear_screen(0, 0);
show_equip(0);
}
exit_flag = FALSE;
do
{
(void) sprintf(out_val,
"(a-%c, * for equipment list, ESC to exit) Take off which one ?",
equip_ctr+96);
test_flag = FALSE;
msg_print(out_val);
do
{
inkey(&command);
com_val = (command);
switch(com_val)
{
case 0: case 27:
test_flag = TRUE;
exit_flag = TRUE;
break;
case 42:
clear_screen(1, 0);
show_equip(0);
break;
default:
com_val -= 97;
if ((com_val >= 0) &&
(com_val < equip_ctr))
test_flag = TRUE;
break;
}
}
while (!test_flag);
if (!exit_flag)
{
reset_flag = FALSE; /* Player turn */
i = -1;
j = 21;
do
{
j++;
if (inventory[j].tval != 0)
i++;
}
while (i != com_val);
if (0x80000000 & inventory[j].flags)
{
msg_print("Hmmm, it seems to be cursed...");
com_val = 0;
}
else
(void) remove_item(j);
}
if (scr_state == 0)
exit_flag = TRUE;
else if (equip_ctr == 0)
exit_flag = TRUE;
else if (inven_ctr > 21)
{
exit_flag = TRUE;
show_equip(0);
}
else if (!exit_flag)
show_equip(0);
}
while (!exit_flag);
if (scr_state != 0)
if (equip_ctr == 0)
clear_screen(0, 0);
else
prt("You are currently using -", 0, 0);
}
/* Wear routine, wear or wield an item -RAK- */
wear()
{
register int i, j, k;
int com_val, tmp;
vtype out_val, prt1, prt2;
treasure_type unwear_obj;
int exit_flag, test_flag;
char command;
register treasure_type *i_ptr;
if (scr_state == 2)
{
clear_screen(0, 0);
show_inven(0, inven_ctr-1);
}
exit_flag = FALSE;
do
{
(void) sprintf(out_val,
"(a-%c, * for equipment list, ESC to exit) Wear/Wield which one?",
inven_ctr+96);
test_flag = FALSE;
msg_print(out_val);
do
{
inkey(&command);
com_val = (command);
switch(com_val)
{
case 0: case 27:
test_flag = TRUE;
exit_flag = TRUE;
break;
case 42:
clear_screen(1, 0);
show_inven(0, inven_ctr-1);
break;
default:
com_val -= 97;
if ((com_val >= 0) &&
(com_val < inven_ctr))
test_flag = TRUE;
break;
}
}
while (!test_flag);
if (!exit_flag) /* Main logic for wearing */
{
reset_flag = FALSE; /* Player turn */
test_flag = TRUE;
switch(inventory[com_val].tval) /* Slot for equipment */
{
case 10: i = 22; break;
case 11: i = 22; break;
case 12: i = 22; break;
case 15: i = 32; break;
case 20: i = 22; break;
case 21: i = 22; break;
case 22: i = 22; break;
case 23: i = 22; break;
case 25: i = 22; break;
case 30: i = 30; break;
case 31: i = 27; break;
case 32: i = 31; break;
case 33: i = 23; break;
case 34: i = 26; break;
case 35: i = 25; break;
case 36: i = 25; break;
case 40: i = 24; break;
case 45:
if (inventory[INVEN_RIGHT].tval == 0) /* Rings */
i = INVEN_RIGHT;
else
i = INVEN_LEFT;
break;
default:
msg_print("I don't see how you can use that.");
test_flag = FALSE;
com_val = 0;
break;
}
if (test_flag)
if (inventory[i].tval != 0)
{
if (0x80000000 & inventory[i].flags)
{
objdes(prt1, i, FALSE);
(void) sprintf(out_val, "The %s you are ", prt1);
switch(i)
{
case 23: (void) strcat(out_val, "wielding "); break;
default: (void) strcat(out_val, "wearing "); break;
}
msg_print(strcat(out_val, "appears to be cursed."));
test_flag = FALSE;
com_val = 0;
}
else if (inven_ctr > 21)
if (inventory[com_val].number > 1)
if (inventory[com_val].subval < 512)
{
msg_print("You will have to drop something first.");
test_flag = FALSE;
com_val = 0;
}
}
if (test_flag)
{
/* save old item */
unwear_obj = inventory[i];
/* now wear/wield new object */
inventory[i] = inventory[com_val];
i_ptr = &inventory[i];
/* Fix for torches */
if ((i_ptr->subval > 255) && (i_ptr->subval < 512))
{
i_ptr->number = 1;
i_ptr->subval -= 255;
}
/* Fix for weight */
inven_weight += i_ptr->weight*i_ptr->number;
inven_destroy(com_val); /* Subtracts weight */
equip_ctr++;
/* subtract bonuses for old item before add bonuses for new */
/* must do this after inven_destroy, otherwise inventory
may increase to 23 items thus destroying INVEN_WIELD */
if (unwear_obj.tval != 0)
{
inventory[INVEN_MAX] = unwear_obj;
/* decrements equip_ctr, and calls py_bonuses with -1 */
tmp = remove_item(INVEN_MAX);
if (tmp < com_val)
com_val = tmp;
}
py_bonuses(inventory[i], 1);
switch(i)
{
case 22: (void) strcpy(prt1, "You are wielding "); break;
case 32: (void) strcpy(prt1, "Your light source is "); break;
default: (void) strcpy(prt1, "You are wearing "); break;
}
objdes(prt2, i, TRUE);
j = -1;
k = 21;
do /* Get the right letter of equipment */
{
k++;
if (inventory[k].tval != 0)
j++;
}
while (k != i);
(void) sprintf(out_val, "%s%s (%c%c",
prt1, prt2, j+97, cur_char2(i));
msg_print(out_val);
if ((i == 22) && (py.stats.cstr*15 < i_ptr->weight))
msg_print("You have trouble wielding such a heavy weapon.");
}
}
if (scr_state == 0)
exit_flag = TRUE;
else if (inven_ctr == 0)
exit_flag = TRUE;
else if (!exit_flag)
show_inven(com_val, inven_ctr-1);
}
while (!exit_flag);
if (scr_state != 0) prt("You are currently carrying -", 0, 0);
}
/* Switch primary and secondary weapons -RAK- */
switch_weapon()
{
vtype prt1, prt2;
treasure_type tmp_obj;
if (0x80000000 & inventory[INVEN_WIELD].flags)
{
objdes(prt1, INVEN_WIELD, FALSE);
(void) sprintf(prt2,
"The %s you are wielding appears to be cursed.", prt1);
msg_print(prt2);
}
else
{
/* Switch weapons */
reset_flag = FALSE;
tmp_obj = inventory[INVEN_AUX];
inventory[INVEN_AUX] = inventory[INVEN_WIELD];
inventory[INVEN_WIELD] = tmp_obj;
py_bonuses(inventory[INVEN_AUX], -1); /* Subtract bonuses */
py_bonuses(inventory[INVEN_WIELD], 1); /* Add bonuses */
if (inventory[INVEN_WIELD].tval != 0)
{
(void) strcpy(prt1, "Primary weapon : ");
objdes(prt2, INVEN_WIELD, TRUE);
msg_print(strcat(prt1, prt2));
if (py.stats.cstr * 15 < inventory[INVEN_WIELD].weight)
msg_print("You have trouble wielding such a heavy weapon.");
}
if (inventory[INVEN_AUX].tval != 0)
{
(void) strcpy(prt1, "Secondary weapon : ");
objdes(prt2, INVEN_AUX, TRUE);
msg_print(strcat(prt1, prt2));
}
}
if (scr_state != 0)
{
/* make sure player sees last message */
msg_print(" ");
clear_screen(0, 0);
prt("You are currently using -", 0, 0);
show_equip(0);
}
}
/* Comprehensive function block to handle all inventory -RAK- */
/* and equipment routines. Five kinds of calls can take place. */
/* Note that "?" is a special call for other routines to display */
/* only a portion of the inventory, and take no other action. */
int inven_command(command, r1, r2)
char command;
int r1, r2;
{
register int com_val, inven;
register int exit_flag, test_flag;
/* Main logic for INVEN_COMMAND -RAK- */
inven = FALSE;
exit_flag = FALSE;
scr_state = 0;
do
{
switch(command)
{
case 'i': /* Inventory */
if (inven_ctr == 0)
msg_print("You are not carrying anything.");
else if (scr_state != 1)
{ /* Sets scr_state to 1 */
clear_screen(0, 0);
prt("You are currently carrying -", 0, 0);
show_inven(0, inven_ctr-1);
}
break;
case 'e': /* Equipment */
if (equip_ctr == 0)
msg_print("You are not using any equipment.");
else if (scr_state != 2)
{ /* Sets scr_state to 2 */
clear_screen(0, 0);
prt("You are currently using -", 0, 0);
show_equip(0);
}
break;
case 't': /* Take off */
if (equip_ctr == 0)
msg_print("You are not using any equipment.");
else if (inven_ctr > 21)
msg_print("You will have to drop something first.");
else
unwear(); /* May set scr_state to 2 */
break;
case 'w': /* Wear/wield */
if (inven_ctr == 0)
msg_print("You are not carrying anything.");
else
wear(); /* May set scr_state to 1 */
break;
case 'x':
if (inventory[INVEN_WIELD].tval != 0)
switch_weapon();
else if (inventory[INVEN_AUX].tval != 0)
switch_weapon();
else
msg_print("But you are wielding no weapons.");
break;
/* Special function for other routines */
case '?': /* Displays part inven, returns */
show_inven(r1, r2);
scr_state = 0; /* Clear screen state */
break;
/* Nonsense command */
default:
break;
}
if (scr_state > 0)
{
prt(
"<e>quip, <i>inven, <t>ake-off, <w>ear/wield, e<x>change, or ESC to exit.",
23, 1);
test_flag = FALSE;
do
{
inkey(&command);
com_val = (command);
switch(com_val)
{
case 0: case 27: case 32:
/* Exit from module */
exit_flag = TRUE;
test_flag = TRUE;
break;
default:
switch(command) /* Module commands */
{
case 'e': test_flag = TRUE; break;
case 'i': test_flag = TRUE; break;
case 't': test_flag = TRUE; break;
case 'w': test_flag = TRUE; break;
case 'x': test_flag = TRUE; break;
case '?': break; /* Trap special feature */
default: break; /* Nonsense command */
}
}
}
while (!test_flag);
prt("", 23, 0); /* clear the line containing command list */
}
else
exit_flag = TRUE;
}
while (!exit_flag);
if (scr_state > 0) /* If true, must redraw screen */
inven = TRUE;
return(inven);
}
/* Get the ID of an item and return the CTR value of it -RAK- */
int get_item(com_val, pmt, redraw, i, j)
int *com_val;
char *pmt;
int *redraw;
int i, j;
{
char command;
vtype out_val;
register int test_flag, item;
item = FALSE;
*com_val = 0;
if (inven_ctr > 0)
{
(void) sprintf(out_val,
"(Items %c-%c, * for inventory list, ESC to exit) %s",
i+97, j+97, pmt);
test_flag = FALSE;
prt(out_val, 0, 0);
do
{
inkey(&command);
*com_val = (command);
switch(*com_val)
{
case 0: case 27:
test_flag = TRUE;
reset_flag = TRUE;
break;
case 42:
clear_screen(1, 0);
(void) inven_command('?', i, j);
*redraw = TRUE;
break;
default:
*com_val -= 97;
if ((*com_val >= i) &&
(*com_val <= j))
{
test_flag = TRUE;
item = TRUE;
}
break;
}
}
while (!test_flag);
erase_line(MSG_LINE, 0);
}
else
msg_print("You are not carrying anything.");
return(item);
}
/* I may have written the town level code, but I'm not exactly */
/* proud of it. Adding the stores required some real slucky */
/* hooks which I have not had time to re-think. -RAK- */
/* Calculates current boundaries -RAK- */
panel_bounds()
{
panel_row_min = panel_row*(SCREEN_HEIGHT/2);
panel_row_max = panel_row_min + SCREEN_HEIGHT - 1;
panel_row_prt = panel_row_min - 1;
panel_col_min = panel_col*(SCREEN_WIDTH/2);
panel_col_max = panel_col_min + SCREEN_WIDTH - 1;
/* the value 13 puts one blank space between the stats and the map, leaving
the last column empty
the value 14 puts two blank spaces between the stats and the map, and
ends up printing in the last column
I think 14 gives a better display, but some curses wreak havoc when try to
print characters in the last column, hence the BUGGY_CURSES ifdef */
#ifdef BUGGY_CURSES
panel_col_prt = panel_col_min - 13;
#else
panel_col_prt = panel_col_min - 14;
#endif
}
/* Given an row (y) and col (x), this routine detects -RAK- */
/* when a move off the screen has occurred and figures new borders*/
int get_panel(y, x)
int y, x;
{
register int prow, pcol;
register int panel;
prow = panel_row;
pcol = panel_col;
if ((y < panel_row_min + 2) || (y > panel_row_max - 2))
{
prow = ((y - 2)/(SCREEN_HEIGHT/2));
if (prow > max_panel_rows)
prow = max_panel_rows;
}
if ((x < panel_col_min + 3) || (x > panel_col_max - 3))
{
pcol = ((x - 3)/(SCREEN_WIDTH/2));
if (pcol > max_panel_cols)
pcol = max_panel_cols;
}
if ((prow != panel_row) || (pcol != panel_col) || (!cave_flag))
{
panel_row = prow;
panel_col = pcol;
panel_bounds();
panel = TRUE;
cave_flag = TRUE;
/* stop movement if any */
if (find_flag)
find_flag = FALSE; /* no need to call move_light () */
}
else
panel = FALSE;
return(panel);
}
/* Tests a given point to see if it is within the screen -RAK- */
/* boundaries. */
int panel_contains(y, x)
int y, x;
{
register int panel;
if ((y >= panel_row_min) && (y <= panel_row_max))
if ((x >= panel_col_min) && (x <= panel_col_max))
panel = TRUE;
else
panel = FALSE;
else
panel = FALSE;
return(panel);
}
/* Returns true if player has no light -RAK- */
int no_light()
{
register int light;
register cave_type *c_ptr;
light = FALSE;
c_ptr = &cave[char_row][char_col];
if (!c_ptr->tl)
if (!c_ptr->pl)
light = TRUE;