forked from diasurgical/devilution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitems.cpp
More file actions
6045 lines (5540 loc) · 145 KB
/
items.cpp
File metadata and controls
6045 lines (5540 loc) · 145 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file items.cpp
*
* Implementation of item functionality.
*/
#include "all.h"
#ifdef HELLFIRE
#include "../3rdParty/Storm/Source/storm.h"
#endif
int itemactive[MAXITEMS];
BOOL uitemflag;
int itemavail[MAXITEMS];
ItemStruct curruitem;
ItemGetRecordStruct itemrecord[MAXITEMS];
/** Contains the items on ground in the current game. */
ItemStruct item[MAXITEMS + 1];
BOOL itemhold[3][3];
#ifdef HELLFIRE
CornerStoneStruct CornerStone;
#endif
BYTE *itemanims[ITEMTYPES];
BOOL UniqueItemFlag[128];
#ifdef HELLFIRE
int auricGold = GOLD_MAX_LIMIT * 2;
#endif
int numitems;
int gnNumGetRecords;
/* data */
#ifdef HELLFIRE
int OilLevels[] = { 1, 10, 1, 10, 4, 1, 5, 17, 1, 10 };
int OilValues[] = { 500, 2500, 500, 2500, 1500, 100, 2500, 15000, 500, 2500 };
int OilMagic[] = {
IMISC_OILACC,
IMISC_OILMAST,
IMISC_OILSHARP,
IMISC_OILDEATH,
IMISC_OILSKILL,
IMISC_OILBSMTH,
IMISC_OILFORT,
IMISC_OILPERM,
IMISC_OILHARD,
IMISC_OILIMP,
};
char OilNames[10][25] = {
"Oil of Accuracy",
"Oil of Mastery",
"Oil of Sharpness",
"Oil of Death",
"Oil of Skill",
"Blacksmith Oil",
"Oil of Fortitude",
"Oil of Permanence",
"Oil of Hardening",
"Oil of Imperviousness"
};
int MaxGold = GOLD_MAX_LIMIT;
#endif
/** Maps from item_cursor_graphic to in-memory item type. */
BYTE ItemCAnimTbl[] = {
#ifndef HELLFIRE
20, 16, 16, 16, 4, 4, 4, 12, 12, 12,
12, 12, 12, 12, 12, 21, 21, 25, 12, 28,
28, 28, 0, 0, 0, 32, 0, 0, 0, 24,
24, 26, 2, 25, 22, 23, 24, 25, 27, 27,
29, 0, 0, 0, 12, 12, 12, 12, 12, 0,
8, 8, 0, 8, 8, 8, 8, 8, 8, 6,
8, 8, 8, 6, 8, 8, 6, 8, 8, 6,
6, 6, 8, 8, 8, 5, 9, 13, 13, 13,
5, 5, 5, 15, 5, 5, 18, 18, 18, 30,
5, 5, 14, 5, 14, 13, 16, 18, 5, 5,
7, 1, 3, 17, 1, 15, 10, 14, 3, 11,
8, 0, 1, 7, 0, 7, 15, 7, 3, 3,
3, 6, 6, 11, 11, 11, 31, 14, 14, 14,
6, 6, 7, 3, 8, 14, 0, 14, 14, 0,
33, 1, 1, 1, 1, 1, 7, 7, 7, 14,
14, 17, 17, 17, 0, 34, 1, 0, 3, 17,
8, 8, 6, 1, 3, 3, 11, 3, 4
#else
20, 16, 16, 16, 4, 4, 4, 12, 12, 12,
12, 12, 12, 12, 12, 21, 21, 25, 12, 28,
28, 28, 38, 38, 38, 32, 38, 38, 38, 24,
24, 26, 2, 25, 22, 23, 24, 25, 27, 27,
29, 0, 0, 0, 12, 12, 12, 12, 12, 0,
8, 8, 0, 8, 8, 8, 8, 8, 8, 6,
8, 8, 8, 6, 8, 8, 6, 8, 8, 6,
6, 6, 8, 8, 8, 5, 9, 13, 13, 13,
5, 5, 5, 15, 5, 5, 18, 18, 18, 30,
5, 5, 14, 5, 14, 13, 16, 18, 5, 5,
7, 1, 3, 17, 1, 15, 10, 14, 3, 11,
8, 0, 1, 7, 0, 7, 15, 7, 3, 3,
3, 6, 6, 11, 11, 11, 31, 14, 14, 14,
6, 6, 7, 3, 8, 14, 0, 14, 14, 0,
33, 1, 1, 1, 1, 1, 7, 7, 7, 14,
14, 17, 17, 17, 0, 34, 1, 0, 3, 17,
8, 8, 6, 1, 3, 3, 11, 3, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 12, 35, 39, 36,
36, 36, 37, 38, 38, 38, 38, 38, 41, 42,
8, 8, 8, 17, 0, 6, 8, 11, 11, 3,
3, 1, 6, 6, 6, 1, 8, 6, 11, 3,
6, 8, 1, 6, 6, 17, 40, 0, 0
#endif
};
/** Map of item type .cel file names. */
const char *const ItemDropNames[] = {
"Armor2",
"Axe",
"FBttle",
"Bow",
"GoldFlip",
"Helmut",
"Mace",
"Shield",
"SwrdFlip",
"Rock",
"Cleaver",
"Staff",
"Ring",
"CrownF",
"LArmor",
"WShield",
"Scroll",
"FPlateAr",
"FBook",
"Food",
"FBttleBB",
"FBttleDY",
"FBttleOR",
"FBttleBR",
"FBttleBL",
"FBttleBY",
"FBttleWH",
"FBttleDB",
"FEar",
"FBrain",
"FMush",
"Innsign",
"Bldstn",
"Fanvil",
"FLazStaf",
#ifdef HELLFIRE
"bombs1",
"halfps1",
"wholeps1",
"runes1",
"teddys1",
"cows1",
"donkys1",
"mooses1",
#endif
};
/** Maps of item drop animation length. */
BYTE ItemAnimLs[] = {
15,
13,
16,
13,
10,
13,
13,
13,
13,
10,
13,
13,
13,
13,
13,
13,
13,
13,
13,
1,
16,
16,
16,
16,
16,
16,
16,
16,
13,
12,
12,
13,
13,
13,
8,
#ifdef HELLFIRE
10,
16,
16,
10,
10,
15,
15,
15,
#endif
};
/** Maps of drop sounds effect of dropping the item on ground. */
int ItemDropSnds[] = {
IS_FHARM,
IS_FAXE,
IS_FPOT,
IS_FBOW,
IS_GOLD,
IS_FCAP,
IS_FSWOR,
IS_FSHLD,
IS_FSWOR,
IS_FROCK,
IS_FAXE,
IS_FSTAF,
IS_FRING,
IS_FCAP,
IS_FLARM,
IS_FSHLD,
IS_FSCRL,
IS_FHARM,
IS_FBOOK,
IS_FLARM,
IS_FPOT,
IS_FPOT,
IS_FPOT,
IS_FPOT,
IS_FPOT,
IS_FPOT,
IS_FPOT,
IS_FPOT,
IS_FBODY,
IS_FBODY,
IS_FMUSH,
IS_ISIGN,
IS_FBLST,
IS_FANVL,
IS_FSTAF,
#ifdef HELLFIRE
IS_FROCK,
IS_FSCRL,
IS_FSCRL,
IS_FROCK,
IS_FMUSH,
IS_FHARM,
IS_FLARM,
IS_FLARM,
#endif
};
/** Maps of drop sounds effect of placing the item in the inventory. */
int ItemInvSnds[] = {
IS_IHARM,
IS_IAXE,
IS_IPOT,
IS_IBOW,
IS_GOLD,
IS_ICAP,
IS_ISWORD,
IS_ISHIEL,
IS_ISWORD,
IS_IROCK,
IS_IAXE,
IS_ISTAF,
IS_IRING,
IS_ICAP,
IS_ILARM,
IS_ISHIEL,
IS_ISCROL,
IS_IHARM,
IS_IBOOK,
IS_IHARM,
IS_IPOT,
IS_IPOT,
IS_IPOT,
IS_IPOT,
IS_IPOT,
IS_IPOT,
IS_IPOT,
IS_IPOT,
IS_IBODY,
IS_IBODY,
IS_IMUSH,
IS_ISIGN,
IS_IBLST,
IS_IANVL,
IS_ISTAF,
#ifdef HELLFIRE
IS_IROCK,
IS_ISCROL,
IS_ISCROL,
IS_IROCK,
IS_IMUSH,
IS_IHARM,
IS_ILARM,
IS_ILARM,
#endif
};
#ifdef HELLFIRE
char *CornerStoneRegKey = "SItem";
#endif
/** Specifies the current Y-coordinate used for validation of items on ground. */
int idoppely = 16;
/** Maps from Griswold premium item number to a quality level delta as added to the base quality level. */
int premiumlvladd[SMITH_PREMIUM_ITEMS] = {
// clang-format off
-1,
-1,
#ifdef HELLFIRE
-1,
#endif
0,
0,
#ifdef HELLFIRE
0,
0,
1,
1,
1,
#endif
1,
2,
#ifdef HELLFIRE
2,
3,
3,
#endif
// clang-format on
};
#ifdef HELLFIRE
int get_ring_max_value(int i)
{
int j, res;
res = 0;
for (j = 0; j < NUM_INVLOC; j++) {
if (plr[i].InvBody[j]._iClass != ITYPE_NONE && plr[i].InvBody[j]._itype == ITYPE_RING && res < plr[i].InvBody[j]._iIvalue)
res = plr[i].InvBody[j]._iIvalue;
}
for (j = 0; j < NUM_INV_GRID_ELEM; j++) {
if (plr[i].InvList[j]._iClass != ITYPE_NONE && plr[i].InvList[j]._itype == ITYPE_RING && res < plr[i].InvList[j]._iIvalue)
res = plr[i].InvList[j]._iIvalue;
}
return res;
}
int get_bow_max_value(int i)
{
int j, res;
res = 0;
for (j = 0; j < NUM_INVLOC; j++) {
if (plr[i].InvBody[j]._iClass != ITYPE_NONE && plr[i].InvBody[j]._itype == ITYPE_BOW && res < plr[i].InvBody[j]._iIvalue)
res = plr[i].InvBody[j]._iIvalue;
}
for (j = 0; j < NUM_INV_GRID_ELEM; j++) {
if (plr[i].InvList[j]._iClass != ITYPE_NONE && plr[i].InvList[j]._itype == ITYPE_BOW && res < plr[i].InvList[j]._iIvalue)
res = plr[i].InvList[j]._iIvalue;
}
return res;
}
int get_staff_max_value(int i)
{
int j, res;
res = 0;
for (j = 0; j < NUM_INVLOC; j++) {
if (plr[i].InvBody[j]._iClass != ITYPE_NONE && plr[i].InvBody[j]._itype == ITYPE_STAFF && res < plr[i].InvBody[j]._iIvalue)
res = plr[i].InvBody[j]._iIvalue;
}
for (j = 0; j < NUM_INV_GRID_ELEM; j++) {
if (plr[i].InvList[j]._iClass != ITYPE_NONE && plr[i].InvList[j]._itype == ITYPE_STAFF && res < plr[i].InvList[j]._iIvalue)
res = plr[i].InvList[j]._iIvalue;
}
return res;
}
int get_sword_max_value(int i)
{
int j, res;
res = 0;
for (j = 0; j < NUM_INVLOC; j++) {
if (plr[i].InvBody[j]._iClass != ITYPE_NONE && plr[i].InvBody[j]._itype == ITYPE_SWORD && res < plr[i].InvBody[j]._iIvalue)
res = plr[i].InvBody[j]._iIvalue;
}
for (j = 0; j < NUM_INV_GRID_ELEM; j++) {
if (plr[i].InvList[j]._iClass != ITYPE_NONE && plr[i].InvList[j]._itype == ITYPE_SWORD && res < plr[i].InvList[j]._iIvalue)
res = plr[i].InvList[j]._iIvalue;
}
return res;
}
int get_helm_max_value(int i)
{
int j, res;
res = 0;
for (j = 0; j < NUM_INVLOC; j++) {
if (plr[i].InvBody[j]._iClass != ITYPE_NONE && plr[i].InvBody[j]._itype == ITYPE_HELM && res < plr[i].InvBody[j]._iIvalue)
res = plr[i].InvBody[j]._iIvalue;
}
for (j = 0; j < NUM_INV_GRID_ELEM; j++) {
if (plr[i].InvList[j]._iClass != ITYPE_NONE && plr[i].InvList[j]._itype == ITYPE_HELM && res < plr[i].InvList[j]._iIvalue)
res = plr[i].InvList[j]._iIvalue;
}
return res;
}
int get_shield_max_value(int i)
{
int j, res;
res = 0;
for (j = 0; j < NUM_INVLOC; j++) {
if (plr[i].InvBody[j]._iClass != ITYPE_NONE && plr[i].InvBody[j]._itype == ITYPE_SHIELD && res < plr[i].InvBody[j]._iIvalue)
res = plr[i].InvBody[j]._iIvalue;
}
for (j = 0; j < NUM_INV_GRID_ELEM; j++) {
if (plr[i].InvList[j]._iClass != ITYPE_NONE && plr[i].InvList[j]._itype == ITYPE_SHIELD && res < plr[i].InvList[j]._iIvalue)
res = plr[i].InvList[j]._iIvalue;
}
return res;
}
int get_armor_max_value(int i)
{
int j, res;
res = 0;
for (j = 0; j < NUM_INVLOC; j++) {
if (plr[i].InvBody[j]._iClass != ITYPE_NONE
&& (plr[i].InvBody[j]._itype == ITYPE_LARMOR || plr[i].InvBody[j]._itype == ITYPE_MARMOR || plr[i].InvBody[j]._itype == ITYPE_HARMOR)
&& res < plr[i].InvBody[j]._iIvalue)
res = plr[i].InvBody[j]._iIvalue;
}
for (j = 0; j < NUM_INV_GRID_ELEM; j++) {
if (plr[i].InvList[j]._iClass != ITYPE_NONE
&& (plr[i].InvList[j]._itype == ITYPE_LARMOR || plr[i].InvList[j]._itype == ITYPE_MARMOR || plr[i].InvList[j]._itype == ITYPE_HARMOR)
&& res < plr[i].InvList[j]._iIvalue)
res = plr[i].InvList[j]._iIvalue;
}
return res;
}
int get_mace_max_value(int i)
{
int j, res;
res = 0;
for (j = 0; j < NUM_INVLOC; j++) {
if (plr[i].InvBody[j]._iClass != ITYPE_NONE && plr[i].InvBody[j]._itype == ITYPE_MACE && res < plr[i].InvBody[j]._iIvalue)
res = plr[i].InvBody[j]._iIvalue;
}
for (j = 0; j < NUM_INV_GRID_ELEM; j++) {
if (plr[i].InvList[j]._iClass != ITYPE_NONE && plr[i].InvList[j]._itype == ITYPE_MACE && res < plr[i].InvList[j]._iIvalue)
res = plr[i].InvList[j]._iIvalue;
}
return res;
}
int get_amulet_max_value(int i)
{
int j, res;
res = 0;
for (j = 0; j < NUM_INVLOC; j++) {
if (plr[i].InvBody[j]._iClass != ITYPE_NONE && plr[i].InvBody[j]._itype == ITYPE_AMULET && res < plr[i].InvBody[j]._iIvalue)
res = plr[i].InvBody[j]._iIvalue;
}
for (j = 0; j < NUM_INV_GRID_ELEM; j++) {
if (plr[i].InvList[j]._iClass != ITYPE_NONE && plr[i].InvList[j]._itype == ITYPE_AMULET && res < plr[i].InvList[j]._iIvalue)
res = plr[i].InvList[j]._iIvalue;
}
return res;
}
int get_axe_max_value(int i)
{
int j, res;
res = 0;
for (j = 0; j < NUM_INVLOC; j++) {
if (plr[i].InvBody[j]._iClass != ITYPE_NONE && plr[i].InvBody[j]._itype == ITYPE_AXE && res < plr[i].InvBody[j]._iIvalue)
res = plr[i].InvBody[j]._iIvalue;
}
for (j = 0; j < NUM_INV_GRID_ELEM; j++) {
if (plr[i].InvList[j]._iClass != ITYPE_NONE && plr[i].InvList[j]._itype == ITYPE_AXE && res < plr[i].InvList[j]._iIvalue)
res = plr[i].InvList[j]._iIvalue;
}
return res;
}
int items_get_currlevel()
{
int lvl;
lvl = currlevel;
if (currlevel >= 17 && currlevel <= 20)
lvl = currlevel - 8;
if (currlevel >= 21 && currlevel <= 24)
lvl = currlevel - 7;
return lvl;
}
#endif
void InitItemGFX()
{
#ifdef HELLFIRE
DWORD i;
#else
int i;
#endif
char arglist[64];
for (i = 0; i < ITEMTYPES; i++) {
sprintf(arglist, "Items\\%s.CEL", ItemDropNames[i]);
itemanims[i] = LoadFileInMem(arglist, NULL);
}
memset(UniqueItemFlag, 0, sizeof(UniqueItemFlag));
}
BOOL ItemPlace(int xp, int yp)
{
if (dMonster[xp][yp] != 0)
return FALSE;
if (dPlayer[xp][yp] != 0)
return FALSE;
if (dItem[xp][yp] != 0)
return FALSE;
if (dObject[xp][yp] != 0)
return FALSE;
if (dFlags[xp][yp] & BFLAG_POPULATED)
return FALSE;
if (nSolidTable[dPiece[xp][yp]])
return FALSE;
return TRUE;
}
void AddInitItems()
{
int x, y, i, j, rnd;
#ifdef HELLFIRE
int curlv = items_get_currlevel();
#endif
rnd = random_(11, 3) + 3;
for (j = 0; j < rnd; j++) {
i = itemavail[0];
itemavail[0] = itemavail[MAXITEMS - numitems - 1];
itemactive[numitems] = i;
x = random_(12, 80) + 16;
y = random_(12, 80) + 16;
while (!ItemPlace(x, y)) {
x = random_(12, 80) + 16;
y = random_(12, 80) + 16;
}
item[i]._ix = x;
item[i]._iy = y;
dItem[x][y] = i + 1;
item[i]._iSeed = GetRndSeed();
SetRndSeed(item[i]._iSeed);
#ifdef HELLFIRE
if (random_(12, 2) != 0)
GetItemAttrs(i, IDI_HEAL, curlv);
else
GetItemAttrs(i, IDI_MANA, curlv);
item[i]._iCreateInfo = curlv + CF_PREGEN;
#else
if (random_(12, 2) != 0)
GetItemAttrs(i, IDI_HEAL, currlevel);
else
GetItemAttrs(i, IDI_MANA, currlevel);
item[i]._iCreateInfo = currlevel + CF_PREGEN;
#endif
SetupItem(i);
item[i]._iAnimFrame = item[i]._iAnimLen;
item[i]._iAnimFlag = FALSE;
item[i]._iSelFlag = 1;
DeltaAddItem(i);
numitems++;
}
}
#ifdef HELLFIRE
static void SpawnNote()
{
int x, y, id;
x = random_(12, 80) + 16;
y = random_(12, 80) + 16;
while (!ItemPlace(x, y)) {
x = random_(12, 80) + 16;
y = random_(12, 80) + 16;
}
switch (currlevel) {
case 22:
id = IDI_NOTE2;
break;
case 23:
id = IDI_NOTE3;
break;
default:
id = IDI_NOTE1;
break;
}
SpawnQuestItem(id, x, y, 0, 1);
}
#endif
void InitItems()
{
int i;
long s;
GetItemAttrs(0, IDI_GOLD, 1);
golditem = item[0];
golditem._iStatFlag = TRUE;
numitems = 0;
for (i = 0; i < MAXITEMS; i++) {
item[i]._itype = ITYPE_MISC; // BUGFIX Should be ITYPE_NONE
item[i]._ix = 0;
item[i]._iy = 0;
item[i]._iAnimFlag = FALSE;
item[i]._iSelFlag = 0;
item[i]._iIdentified = FALSE;
item[i]._iPostDraw = FALSE;
}
for (i = 0; i < MAXITEMS; i++) {
itemavail[i] = i;
itemactive[i] = 0;
}
if (!setlevel) {
s = GetRndSeed(); /* unused */
if (QuestStatus(Q_ROCK))
SpawnRock();
if (QuestStatus(Q_ANVIL))
SpawnQuestItem(IDI_ANVIL, 2 * setpc_x + 27, 2 * setpc_y + 27, 0, 1);
#ifdef HELLFIRE
if (UseCowFarmer && currlevel == 20)
SpawnQuestItem(IDI_BROWNSUIT, 25, 25, 3, 1);
if (UseCowFarmer && currlevel == 19)
SpawnQuestItem(IDI_GREYSUIT, 25, 25, 3, 1);
#endif
if (currlevel > 0 && currlevel < 16)
AddInitItems();
#ifdef HELLFIRE
if (currlevel >= 21 && currlevel <= 23)
SpawnNote();
#endif
}
uitemflag = FALSE;
// BUGFIX: item get records not reset when resetting items.
}
void CalcPlrItemVals(int p, BOOL Loadgfx)
{
int pvid, d;
int mind = 0; // min damage
int maxd = 0; // max damage
int tac = 0; // accuracy
int g;
int i;
int mi;
int bdam = 0; // bonus damage
int btohit = 0; // bonus chance to hit
int bac = 0; // bonus accuracy
int iflgs = ISPL_NONE; // item_special_effect flags
#ifdef HELLFIRE
int pDamAcFlags = 0;
#endif
int sadd = 0; // added strength
int madd = 0; // added magic
int dadd = 0; // added dexterity
int vadd = 0; // added vitality
unsigned __int64 spl = 0; // bitarray for all enabled/active spells
int fr = 0; // fire resistance
int lr = 0; // lightning resistance
int mr = 0; // magic resistance
int dmod = 0; // bonus damage mod?
int ghit = 0; // increased damage from enemies
int lrad = 10; // light radius
int ihp = 0; // increased HP
int imana = 0; // increased mana
int spllvladd = 0; // increased spell level
int enac = 0; // enhanced accuracy
int fmin = 0; // minimum fire damage
int fmax = 0; // maximum fire damage
int lmin = 0; // minimum lightning damage
int lmax = 0; // maximum lightning damage
for (i = 0; i < NUM_INVLOC; i++) {
ItemStruct *itm = &plr[p].InvBody[i];
if (itm->_itype != ITYPE_NONE && itm->_iStatFlag) {
mind += itm->_iMinDam;
maxd += itm->_iMaxDam;
tac += itm->_iAC;
if (itm->_iSpell != SPL_NULL) {
spl |= SPELLBIT(itm->_iSpell);
}
if (itm->_iMagical == ITEM_QUALITY_NORMAL || itm->_iIdentified) {
bdam += itm->_iPLDam;
btohit += itm->_iPLToHit;
if (itm->_iPLAC) {
int tmpac = itm->_iAC;
tmpac *= itm->_iPLAC;
tmpac /= 100;
if (tmpac == 0)
tmpac = 1;
bac += tmpac;
}
iflgs |= itm->_iFlags;
#ifdef HELLFIRE
pDamAcFlags |= itm->_iDamAcFlags;
#endif
sadd += itm->_iPLStr;
madd += itm->_iPLMag;
dadd += itm->_iPLDex;
vadd += itm->_iPLVit;
fr += itm->_iPLFR;
lr += itm->_iPLLR;
mr += itm->_iPLMR;
dmod += itm->_iPLDamMod;
ghit += itm->_iPLGetHit;
lrad += itm->_iPLLight;
ihp += itm->_iPLHP;
imana += itm->_iPLMana;
spllvladd += itm->_iSplLvlAdd;
enac += itm->_iPLEnAc;
fmin += itm->_iFMinDam;
fmax += itm->_iFMaxDam;
lmin += itm->_iLMinDam;
lmax += itm->_iLMaxDam;
}
}
}
if (mind == 0 && maxd == 0) {
mind = 1;
maxd = 1;
if (plr[p].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SHIELD && plr[p].InvBody[INVLOC_HAND_LEFT]._iStatFlag) {
maxd = 3;
}
if (plr[p].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SHIELD && plr[p].InvBody[INVLOC_HAND_RIGHT]._iStatFlag) {
maxd = 3;
}
#ifdef HELLFIRE
if (plr[p]._pClass == PC_MONK) {
mind = max(mind, plr[p]._pLevel >> 1);
maxd = max(maxd, plr[p]._pLevel);
}
#endif
}
#ifdef HELLFIRE
if ((plr[p]._pSpellFlags & 2) == 2) {
sadd += 2 * plr[p]._pLevel;
dadd += plr[p]._pLevel + plr[p]._pLevel / 2;
vadd += 2 * plr[p]._pLevel;
}
if ((plr[p]._pSpellFlags & 4) == 4) {
sadd -= 2 * plr[p]._pLevel;
dadd -= plr[p]._pLevel + plr[p]._pLevel / 2;
vadd -= 2 * plr[p]._pLevel;
}
#endif
plr[p]._pIMinDam = mind;
plr[p]._pIMaxDam = maxd;
plr[p]._pIAC = tac;
plr[p]._pIBonusDam = bdam;
plr[p]._pIBonusToHit = btohit;
plr[p]._pIBonusAC = bac;
plr[p]._pIFlags = iflgs;
#ifdef HELLFIRE
plr[p].pDamAcFlags = pDamAcFlags;
#endif
plr[p]._pIBonusDamMod = dmod;
plr[p]._pIGetHit = ghit;
if (lrad < 2) {
lrad = 2;
}
if (lrad > 15) {
lrad = 15;
}
if (plr[p]._pLightRad != lrad && p == myplr) {
ChangeLightRadius(plr[p]._plid, lrad);
if (lrad < 10) {
ChangeVisionRadius(plr[p]._pvid, 10);
} else {
ChangeVisionRadius(plr[p]._pvid, lrad);
}
plr[p]._pLightRad = lrad;
}
plr[p]._pStrength = sadd + plr[p]._pBaseStr;
if (plr[myplr]._pStrength <= 0) {
plr[myplr]._pStrength = 0;
}
plr[p]._pMagic = madd + plr[p]._pBaseMag;
if (plr[myplr]._pMagic <= 0) {
plr[myplr]._pMagic = 0;
}
plr[p]._pDexterity = dadd + plr[p]._pBaseDex;
if (plr[myplr]._pDexterity <= 0) {
plr[myplr]._pDexterity = 0;
}
plr[p]._pVitality = vadd + plr[p]._pBaseVit;
if (plr[myplr]._pVitality <= 0) {
plr[myplr]._pVitality = 0;
}
if (plr[p]._pClass == PC_ROGUE) {
plr[p]._pDamageMod = plr[p]._pLevel * (plr[p]._pStrength + plr[p]._pDexterity) / 200;
}
#ifdef HELLFIRE
else if (plr[p]._pClass == PC_MONK) {
if (plr[p].InvBody[INVLOC_HAND_LEFT]._itype != ITYPE_STAFF) {
if (plr[p].InvBody[INVLOC_HAND_RIGHT]._itype != ITYPE_STAFF && (plr[p].InvBody[INVLOC_HAND_LEFT]._itype != ITYPE_NONE || plr[p].InvBody[INVLOC_HAND_RIGHT]._itype != ITYPE_NONE)) {
plr[p]._pDamageMod = plr[p]._pLevel * (plr[p]._pStrength + plr[p]._pDexterity) / 300;
} else {
plr[p]._pDamageMod = plr[p]._pLevel * (plr[p]._pStrength + plr[p]._pDexterity) / 150;
}
} else {
plr[p]._pDamageMod = plr[p]._pLevel * (plr[p]._pStrength + plr[p]._pDexterity) / 150;
}
} else if (plr[p]._pClass == PC_BARD) {
if (plr[p].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SWORD || plr[p].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SWORD)
plr[p]._pDamageMod = plr[p]._pLevel * (plr[p]._pStrength + plr[p]._pDexterity) / 150;
else if (plr[p].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_BOW || plr[p].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_BOW) {
plr[p]._pDamageMod = plr[p]._pLevel * (plr[p]._pStrength + plr[p]._pDexterity) / 250;
} else {
plr[p]._pDamageMod = plr[p]._pLevel * plr[p]._pStrength / 100;
}
} else if (plr[p]._pClass == PC_BARBARIAN) {
if (plr[p].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_AXE || plr[p].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_AXE) {
plr[p]._pDamageMod = plr[p]._pLevel * plr[p]._pStrength / 75;
} else if (plr[p].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_MACE || plr[p].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_MACE) {
plr[p]._pDamageMod = plr[p]._pLevel * plr[p]._pStrength / 75;
} else if (plr[p].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_BOW || plr[p].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_BOW) {
plr[p]._pDamageMod = plr[p]._pLevel * plr[p]._pStrength / 300;
} else {
plr[p]._pDamageMod = plr[p]._pLevel * plr[p]._pStrength / 100;
}
if (plr[p].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SHIELD || plr[p].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SHIELD) {
if (plr[p].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SHIELD)
plr[p]._pIAC -= plr[p].InvBody[INVLOC_HAND_LEFT]._iAC / 2;
else if (plr[p].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SHIELD)
plr[p]._pIAC -= plr[p].InvBody[INVLOC_HAND_RIGHT]._iAC / 2;
} else if (plr[p].InvBody[INVLOC_HAND_LEFT]._itype != ITYPE_STAFF && plr[p].InvBody[INVLOC_HAND_RIGHT]._itype != ITYPE_STAFF && plr[p].InvBody[INVLOC_HAND_LEFT]._itype != ITYPE_BOW && plr[p].InvBody[INVLOC_HAND_RIGHT]._itype != ITYPE_BOW) {
plr[p]._pDamageMod += plr[p]._pLevel * plr[p]._pVitality / 100;
}
plr[p]._pIAC += plr[p]._pLevel / 4;
}
#endif
else {
plr[p]._pDamageMod = plr[p]._pLevel * plr[p]._pStrength / 100;
}
plr[p]._pISpells = spl;
// check if the current RSplType is a valid/allowed spell
if (plr[p]._pRSplType == RSPLTYPE_CHARGES
&& !(plr[p]._pISpells & SPELLBIT(plr[p]._pRSpell))) {
plr[p]._pRSpell = SPL_INVALID;
plr[p]._pRSplType = RSPLTYPE_INVALID;
force_redraw = 255;
}
plr[p]._pISplLvlAdd = spllvladd;
plr[p]._pIEnAc = enac;
#ifdef HELLFIRE
if (plr[p]._pClass == PC_BARBARIAN) {
mr += plr[p]._pLevel;
fr += plr[p]._pLevel;
lr += plr[p]._pLevel;
}
if ((plr[p]._pSpellFlags & 4) == 4) {
mr -= plr[p]._pLevel;
fr -= plr[p]._pLevel;
lr -= plr[p]._pLevel;
}
#endif
if (iflgs & ISPL_ALLRESZERO) {
// reset resistances to zero if the respective special effect is active
mr = 0;
fr = 0;
lr = 0;
}
if (mr > MAXRESIST)
mr = MAXRESIST;
#ifdef HELLFIRE
else if (mr < 0)
mr = 0;
#endif
plr[p]._pMagResist = mr;
if (fr > MAXRESIST)
fr = MAXRESIST;
#ifdef HELLFIRE
else if (fr < 0)
fr = 0;
#endif
plr[p]._pFireResist = fr;
if (lr > MAXRESIST)
lr = MAXRESIST;
#ifdef HELLFIRE
else if (lr < 0)
lr = 0;
#endif
plr[p]._pLghtResist = lr;
if (plr[p]._pClass == PC_WARRIOR) {
vadd <<= 1;
}
#ifdef HELLFIRE
else if (plr[p]._pClass == PC_BARBARIAN) {
vadd += vadd;
vadd += (vadd >> 2);
} else if (plr[p]._pClass == PC_ROGUE || plr[p]._pClass == PC_MONK || plr[p]._pClass == PC_BARD) {
#else
if (plr[p]._pClass == PC_ROGUE) {
#endif
vadd += vadd >> 1;
}
ihp += (vadd << 6);
if (plr[p]._pClass == PC_SORCERER) {
madd <<= 1;
}
#ifdef HELLFIRE
if (plr[p]._pClass == PC_ROGUE || plr[p]._pClass == PC_MONK) {
#else
if (plr[p]._pClass == PC_ROGUE) {
#endif
madd += madd >> 1;
}
#ifdef HELLFIRE
else if (plr[p]._pClass == PC_BARD) {
madd += (madd >> 2) + (madd >> 1);
}
#endif
imana += (madd << 6);
plr[p]._pHitPoints = ihp + plr[p]._pHPBase;
plr[p]._pMaxHP = ihp + plr[p]._pMaxHPBase;
#ifdef HELLFIRE