-
Notifications
You must be signed in to change notification settings - Fork 2
/
objects.cpp
3329 lines (3170 loc) · 87.5 KB
/
objects.cpp
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
//----- (0045C890) --------------------------------------------------------
void __cdecl InitObjectGFX()
{
char pszName; // [esp+Ch] [ebp-54h]
int j; // [esp+2Ch] [ebp-34h]
int i; // [esp+30h] [ebp-30h]
char fileload[44]; // [esp+34h] [ebp-2Ch]
memset(fileload, 0, 0x2Cu);
for ( i = 0; AllObjects[i].oload != -1; ++i )
{
if ( AllObjects[i].oload == 1
&& AllObjects[i].ominlvl <= (signed int)currlevel
&& AllObjects[i].omaxlvl >= (signed int)currlevel )
{
fileload[AllObjects[i].ofindex] = 1;
}
if ( AllObjects[i].otheme != -1 )
{
for ( j = 0; numthemes > j; ++j )
{
if ( AllObjects[i].otheme == themes[j].ttype )
fileload[AllObjects[i].ofindex] = 1;
}
}
}
numobjfiles = 0;
for ( i = 0; i < 44; ++i )
{
if ( fileload[i] )
{
ObjFileList[numobjfiles] = i;
sprintf(&pszName, "Objects\\%s.CEL", ObjMasterLoadList[i]);
if ( pObjCels[numobjfiles] )
assertion_failed(123, "C:\\Diablo\\Direct\\OBJECTS.CPP");
pObjCels[numobjfiles++] = LoadFileInMem(&pszName, 0, 124, "C:\\Diablo\\Direct\\OBJECTS.CPP");
}
}
}
//----- (0045CA91) --------------------------------------------------------
void __cdecl FreeObjectGFX()
{
int i; // [esp+Ch] [ebp-4h]
for ( i = 0; i < numobjfiles; ++i )
{
mem_free_dbg(pObjCels[i], 134, "C:\\Diablo\\Direct\\OBJECTS.CPP");
pObjCels[i] = 0;
}
}
//----- (0045CAED) --------------------------------------------------------
BOOL __fastcall RndLocOk(int xp, int yp)
{
if ( dMonster[xp][yp] )
return 0;
if ( dPlayer[xp][yp] )
return 0;
if ( dObject[xp][yp] )
return 0;
if ( dFlags[xp][yp] & 8 )
return 0;
if ( nSolidTable[dPiece[xp][yp]] )
return 0;
if ( leveltype != 1 || dPiece[xp][yp] <= 126 || dPiece[xp][yp] >= 144 )
return 1;
return 0;
}
//----- (0045CC29) --------------------------------------------------------
BOOL __fastcall objects_45CC29(int x, int y)
{
BOOL result; // eax
if ( dFlags[x][y] & 8 )
result = 0;
else
result = nSolidTable[dPiece[x][y]] == 0;
return result;
}
//----- (0045CD5D) --------------------------------------------------------
void __fastcall InitRndLocObj(int min, int max, _object_id objtype)
{
int v3; // eax
int yp; // [esp+14h] [ebp-10h]
int i; // [esp+18h] [ebp-Ch]
int xp; // [esp+1Ch] [ebp-8h]
int v7; // [esp+20h] [ebp-4h]
v7 = random(139, max - min) + min;
for ( i = 0; i < v7; ++i )
{
do
{
do
{
xp = random(139, 80) + 16;
v3 = random(139, 80);
yp = v3 + 16;
}
while ( !RndLocOk(xp - 1, v3 + 15) );
}
while ( !RndLocOk(xp, yp - 1)
|| !RndLocOk(xp + 1, yp - 1)
|| !RndLocOk(xp - 1, yp)
|| !RndLocOk(xp, yp)
|| !RndLocOk(xp + 1, yp)
|| !RndLocOk(xp - 1, yp + 1)
|| !RndLocOk(xp, yp + 1)
|| !RndLocOk(xp + 1, yp + 1) );
AddObject(objtype, xp, yp);
}
}
//----- (0045CED9) --------------------------------------------------------
void __fastcall InitRndLocBigObj(int min, int max, _object_id objtype)
{
int v3; // eax
int yp; // [esp+14h] [ebp-10h]
int i; // [esp+18h] [ebp-Ch]
int xp; // [esp+1Ch] [ebp-8h]
int v7; // [esp+20h] [ebp-4h]
v7 = random(140, max - min) + min;
for ( i = 0; i < v7; ++i )
{
do
{
do
{
xp = random(140, 80) + 16;
v3 = random(140, 80);
yp = v3 + 16;
}
while ( !RndLocOk(xp - 1, v3 + 14) );
}
while ( !RndLocOk(xp, yp - 2)
|| !RndLocOk(xp + 1, yp - 2)
|| !RndLocOk(xp - 1, yp - 1)
|| !RndLocOk(xp, yp - 1)
|| !RndLocOk(xp + 1, yp - 1)
|| !RndLocOk(xp - 1, yp)
|| !RndLocOk(xp, yp)
|| !RndLocOk(xp + 1, yp)
|| !RndLocOk(xp - 1, yp + 1)
|| !RndLocOk(xp, yp + 1)
|| !RndLocOk(xp + 1, yp + 1) );
AddObject(objtype, xp, yp);
}
}
//----- (0045D0A8) --------------------------------------------------------
void __cdecl ClrAllObjects()
{
signed int i; // [esp+Ch] [ebp-4h]
int j; // [esp+Ch] [ebp-4h]
for ( i = 0; i < 127; ++i )
{
object[i]._ox = 0;
object[i]._oy = 0;
object[i]._oAnimData = 0;
object[i]._oAnimDelay = 0;
object[i]._oAnimCnt = 0;
object[i]._oAnimLen = 0;
object[i]._oAnimFrame = 0;
object[i]._oDelFlag = 0;
object[i]._oVar1 = 0;
object[i]._oVar2 = 0;
object[i]._oVar3 = 0;
object[i]._oVar4 = 0;
}
nobjects = 0;
for ( j = 0; j < 127; ++j )
{
objectavail[j] = j;
objectactive[j] = 0;
}
trapid = 1;
trapdir = 0;
leverid = 1;
}
//----- (0045D22A) --------------------------------------------------------
void __cdecl AddTortures()
{
int oy; // [esp+Ch] [ebp-8h]
int ox; // [esp+10h] [ebp-4h]
for ( oy = 0; oy < 112; ++oy )
{
for ( ox = 0; ox < 112; ++ox )
{
if ( dPiece[ox][oy] == 367 )
{
AddObject(OBJ_TORTURE1, ox, oy + 1);
AddObject(OBJ_TORTURE3, ox + 2, oy - 1);
AddObject(OBJ_TORTURE2, ox, oy + 3);
AddObject(OBJ_TORTURE4, ox + 4, oy - 1);
AddObject(OBJ_TORTURE5, ox, oy + 5);
AddObject(OBJ_TNUDEM1, ox + 1, oy + 3);
AddObject(OBJ_TNUDEM2, ox + 4, oy + 5);
AddObject(OBJ_TNUDEM3, ox + 2, oy);
AddObject(OBJ_TNUDEM4, ox + 3, oy + 2);
AddObject(OBJ_TNUDEW1, ox + 2, oy + 4);
AddObject(OBJ_TNUDEW2, ox + 2, oy + 1);
AddObject(OBJ_TNUDEW3, ox + 4, oy + 2);
}
}
}
}
//----- (0045D398) --------------------------------------------------------
int __fastcall unused_sub_45D398(int a1, int a2, int ot, int a4)
{
int result; // eax
int v5; // ST1C_4
int v6; // ST1C_4
int v7; // ST1C_4
int v8; // ST1C_4
int v9; // ST1C_4
int v10; // ST1C_4
int v11; // ST1C_4
int v12; // ST1C_4
int v13; // ST1C_4
int v14; // ST1C_4
int v15; // ST1C_4
int v16; // ST1C_4
int oy; // [esp+14h] [ebp-3Ch]
int v18; // [esp+18h] [ebp-38h]
int v19; // [esp+1Ch] [ebp-34h]
signed int v20; // [esp+20h] [ebp-30h]
int v21; // [esp+24h] [ebp-2Ch]
int yp; // [esp+28h] [ebp-28h]
int ypa; // [esp+28h] [ebp-28h]
int v24; // [esp+2Ch] [ebp-24h]
int ox; // [esp+30h] [ebp-20h]
signed int j; // [esp+34h] [ebp-1Ch]
int i; // [esp+38h] [ebp-18h]
signed int v28; // [esp+3Ch] [ebp-14h]
int x; // [esp+40h] [ebp-10h]
int xa; // [esp+40h] [ebp-10h]
signed int v31; // [esp+44h] [ebp-Ch]
int v32; // [esp+48h] [ebp-8h]
int v33; // [esp+4Ch] [ebp-4h]
v32 = random(0, a2 - a1) + a1;
for ( i = 0; ; ++i )
{
result = i;
if ( v32 <= i )
break;
v18 = 0;
while ( !v18 )
{
v18 = 1;
x = random(0, 80) + 16;
yp = random(0, 80) + 16;
if ( random(0, 2) )
{
while ( objects_45CC29(x, yp - 1) )
--yp;
v24 = x;
v19 = yp;
v28 = 0;
v20 = 1;
v31 = 0;
while ( objects_45CC29(x, yp + 1) && v18 )
{
v5 = RndLocOk(x - 3, yp) & v18;
v6 = RndLocOk(x - 2, yp) & v5;
v7 = RndLocOk(x - 1, yp) & v6;
v8 = RndLocOk(x, yp) & v7;
v9 = RndLocOk(x + 1, yp) & v8;
v10 = RndLocOk(x + 2, yp) & v9;
v18 = RndLocOk(x + 3, yp++) & v10;
++v31;
}
ox = x - 2;
oy = random(0, v31 - 1) + v19 + 1;
v21 = x + 2;
v33 = random(0, v31 - 1) + v19 + 1;
trapdir = 2;
}
else
{
while ( objects_45CC29(x - 1, yp) )
--x;
v24 = x;
v19 = yp;
v28 = 1;
v20 = 0;
v31 = 0;
while ( objects_45CC29(x + 1, yp) && v18 )
{
v11 = RndLocOk(x, yp - 3) & v18;
v12 = RndLocOk(x, yp - 2) & v11;
v13 = RndLocOk(x, yp - 1) & v12;
v14 = RndLocOk(x, yp) & v13;
v15 = RndLocOk(x, yp + 1) & v14;
v16 = RndLocOk(x, yp + 2) & v15;
v18 = RndLocOk(x++, yp + 3) & v16;
++v31;
}
ox = random(0, v31 - 1) + v24 + 1;
oy = yp - 2;
v21 = random(0, v31 - 1) + v24 + 1;
v33 = yp + 2;
trapdir = 1;
}
if ( v31 < 5 || v31 > 12 )
v18 = 0;
}
xa = v24;
ypa = v19;
for ( j = 0; v31 >= j; ++j )
{
AddObject((_object_id)ot, xa, ypa);
xa += v28;
ypa += v20;
}
AddObject((_object_id)a4, ox, oy);
AddObject((_object_id)a4, v21, v33);
++trapid;
}
return result;
}
//----- (0045D6FE) --------------------------------------------------------
void __fastcall unused_sub_45D6FE_lever(int a1, int a2, int a3, int a4, int x1, int y1, int x2, int y2)
{
int v8; // [esp+Ch] [ebp-1Ch]
int v9; // [esp+10h] [ebp-18h]
int yp; // [esp+14h] [ebp-14h]
int xp; // [esp+18h] [ebp-10h]
int oy; // [esp+1Ch] [ebp-Ch]
int ox; // [esp+24h] [ebp-4h]
v8 = a2;
v9 = a1;
do
{
do
{
xp = random(141, a3 - v9 + 1) + v9;
yp = random(141, a4 - v8 + 1) + v8;
}
while ( !RndLocOk(xp - 1, yp - 1) );
}
while ( !RndLocOk(xp, yp - 1)
|| !RndLocOk(xp + 1, yp - 1)
|| !RndLocOk(xp - 1, yp)
|| !RndLocOk(xp, yp)
|| !RndLocOk(xp + 1, yp)
|| !RndLocOk(xp - 1, yp + 1)
|| !RndLocOk(xp, yp + 1)
|| !RndLocOk(xp + 1, yp + 1) );
AddObject(OBJ_LEVER, ox, oy);
SetObjMapRange(dObject[ox][oy] - 1, x1, y1, x2, y2, leverid);
++leverid;
}
//----- (0045D88D) --------------------------------------------------------
void __fastcall objects_45D88D(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int msg)
{
int i; // ST28_4
int yp; // [esp+14h] [ebp-Ch]
int xp; // [esp+1Ch] [ebp-4h]
do
{
do
{
xp = random(142, x2 - x1 + 1) + x1;
yp = random(142, y2 - y1 + 1) + y1;
}
while ( !RndLocOk(xp - 1, yp - 1) );
}
while ( !RndLocOk(xp, yp - 1)
|| !RndLocOk(xp + 1, yp - 1)
|| !RndLocOk(xp - 1, yp)
|| !RndLocOk(xp, yp)
|| !RndLocOk(xp + 1, yp)
|| !RndLocOk(xp - 1, yp + 1)
|| !RndLocOk(xp, yp + 1)
|| !RndLocOk(xp + 1, yp + 1) );
if ( quests[4]._qlevel == currlevel )
AddObject(OBJ_BOOKLVR, xp, yp);
if ( quests[8]._qlevel == currlevel )
AddObject(OBJ_BLINDBOOK, xp, yp);
if ( quests[9]._qlevel == currlevel )
{
xp = 2 * setpc_x + 25;
yp = 2 * setpc_y + 40;
AddObject(OBJ_BLOODBOOK, xp, yp);
}
i = dObject[xp][yp] - 1;
SetObjMapRange(i, x3, y3, x4, y4, leverid);
SetBookMsg(i, msg);
++leverid;
}
//----- (0045DAA8) --------------------------------------------------------
void __cdecl InitRndBarrels()
{
int v0; // ST24_4
BOOL v1; // [esp+Ch] [ebp-24h]
_object_id ot; // [esp+10h] [ebp-20h]
_object_id ota; // [esp+10h] [ebp-20h]
int yp; // [esp+14h] [ebp-1Ch]
int i; // [esp+18h] [ebp-18h]
int xp; // [esp+1Ch] [ebp-14h]
signed int v7; // [esp+24h] [ebp-Ch]
signed int v8; // [esp+28h] [ebp-8h]
int v9; // [esp+2Ch] [ebp-4h]
v9 = random(143, 5) + 3;
for ( i = 0; i < v9; ++i )
{
do
{
xp = random(143, 80) + 16;
yp = random(143, 80) + 16;
}
while ( !RndLocOk(xp, yp) );
if ( random(143, 4) )
ot = OBJ_BARREL;
else
ot = OBJ_BARRELEX;
AddObject(ot, xp, yp);
v8 = 1;
v1 = 1;
while ( !random(143, v8 >> 1) && v1 )
{
v7 = 0;
v1 = 0;
while ( !v1 && v7 < 3 )
{
v0 = random(143, 8);
xp += bxadd[v0];
yp += byadd[v0];
v1 = RndLocOk(xp, yp);
++v7;
}
if ( v1 )
{
if ( random(143, 5) )
ota = OBJ_BARREL;
else
ota = OBJ_BARRELEX;
AddObject(ota, xp, yp);
++v8;
}
}
}
}
//----- (0045DC55) --------------------------------------------------------
void __fastcall AddL1Objs(int x1, int y1, int x2, int y2)
{
int oy; // [esp+14h] [ebp-Ch]
int ox; // [esp+18h] [ebp-8h]
int v7; // [esp+1Ch] [ebp-4h]
for ( oy = y1; oy < y2; ++oy )
{
for ( ox = x1; ox < x2; ++ox )
{
v7 = dPiece[ox][oy];
if ( v7 == 270 )
AddObject(0, ox, oy);
if ( v7 == 44 || v7 == 51 || v7 == 214 )
AddObject(OBJ_L1LDOOR, ox, oy);
if ( v7 == 46 || v7 == 56 )
AddObject(OBJ_L1RDOOR, ox, oy);
}
}
}
//----- (0045DD3A) --------------------------------------------------------
void __fastcall AddL2Objs(int x1, int y1, int x2, int y2)
{
int oy; // [esp+14h] [ebp-Ch]
int ox; // [esp+18h] [ebp-8h]
int v7; // [esp+1Ch] [ebp-4h]
for ( oy = y1; oy < y2; ++oy )
{
for ( ox = x1; ox < x2; ++ox )
{
v7 = dPiece[ox][oy];
if ( v7 == 13 )
AddObject(OBJ_L2LDOOR, ox, oy);
if ( v7 == 541 )
AddObject(OBJ_L2LDOOR, ox, oy);
if ( v7 == 17 )
AddObject(OBJ_L2RDOOR, ox, oy);
if ( v7 == 542 )
AddObject(OBJ_L2RDOOR, ox, oy);
}
}
}
//----- (0045DE1F) --------------------------------------------------------
BOOL __fastcall WallTrapLocOk(int xp, int yp)
{
return (dFlags[xp][yp] & 8) == 0;
}
//----- (0045DE64) --------------------------------------------------------
void __cdecl AddL2Torches()
{
int yp; // [esp+Ch] [ebp-Ch]
int xp; // [esp+10h] [ebp-8h]
int v2; // [esp+14h] [ebp-4h]
for ( yp = 0; yp < 112; ++yp )
{
for ( xp = 0; xp < 112; ++xp )
{
if ( WallTrapLocOk(xp, yp) )
{
v2 = dPiece[xp][yp];
if ( v2 == 1 && !random(145, 3) )
AddObject(OBJ_TORCHL2, xp, yp);
if ( v2 == 5 && !random(145, 3) )
AddObject(OBJ_TORCHR2, xp, yp);
if ( v2 == 37 && !random(145, 10) && !dObject[xp - 1][yp] )
AddObject(OBJ_TORCHL, xp - 1, yp);
if ( v2 == 41 && !random(145, 10) && !dungeon[39][112 * xp + 39 + yp] )
AddObject(OBJ_TORCHR, xp, yp - 1);
}
}
}
}
//----- (0045DFEB) --------------------------------------------------------
BOOL __fastcall TorchLocOK(int xp, int yp)
{
BOOL result; // eax
if ( dFlags[xp][yp] & 8 )
result = 0;
else
result = nTrapTable[dPiece[xp][yp]] != 0;
return result;
}
//----- (0045E05E) --------------------------------------------------------
void __cdecl AddObjTraps()
{
char v0; // ST28_1
char v1; // ST28_1
char v2; // [esp+Ch] [ebp-1Ch]
int y; // [esp+10h] [ebp-18h]
int x; // [esp+14h] [ebp-14h]
int yp; // [esp+18h] [ebp-10h]
int v6; // [esp+1Ch] [ebp-Ch]
int xp; // [esp+20h] [ebp-8h]
if ( currlevel == 1 )
v6 = 10;
if ( (signed int)currlevel >= 2 )
v6 = 15;
if ( (signed int)currlevel >= 5 )
v6 = 20;
if ( (signed int)currlevel >= 7 )
v6 = 25;
for ( y = 0; y < 112; ++y )
{
for ( x = 0; x < 112; ++x )
{
if ( dObject[x][y] > 0 && random(144, 100) < v6 )
{
v2 = dObject[x][y] - 1;
if ( AllObjects[object[v2]._otype].oTrapFlag )
{
if ( random(144, 2) )
{
for ( yp = y - 1; !nSolidTable[dPiece[x][yp]]; --yp )
;
if ( TorchLocOK(x, yp) && y - yp > 1 )
{
AddObject(OBJ_TRAPR, x, yp);
v1 = dObject[x][yp] - 1;
object[v1]._oVar1 = x;
object[v1]._oVar2 = y;
object[v2]._oTrapFlag = 1;
}
}
else
{
for ( xp = x - 1; !nSolidTable[dPiece[xp][y]]; --xp )
;
if ( TorchLocOK(xp, y) )
{
if ( x - xp > 1 )
{
AddObject(OBJ_TRAPL, xp, y);
v0 = dObject[xp][y] - 1;
object[v0]._oVar1 = x;
object[v0]._oVar2 = y;
object[v2]._oTrapFlag = 1;
}
}
}
}
}
}
}
}
//----- (0045E329) --------------------------------------------------------
void __cdecl AddChestTraps()
{
char v0; // [esp+Ch] [ebp-Ch]
signed int i; // [esp+10h] [ebp-8h]
signed int j; // [esp+14h] [ebp-4h]
for ( i = 0; i < 112; ++i )
{
for ( j = 0; j < 112; ++j )
{
if ( dObject[j][i] > 0 )
{
v0 = dObject[j][i] - 1;
if ( object[v0]._otype >= 5 && object[v0]._otype <= 7 && !object[v0]._oTrapFlag && random(0, 100) < 10 )
{
object[v0]._otype += 63;
object[v0]._oTrapFlag = 1;
object[v0]._oVar4 = random(0, 3);
}
}
}
}
}
//----- (0045E455) --------------------------------------------------------
void __fastcall InitObjects(int a1)
{
ClrAllObjects();
InitObjFlag = 1;
GetRndSeed();
if ( leveltype == 1 )
{
if ( quests[1]._qlevel == currlevel )
AddTortures();
InitRndLocBigObj(10, 15, OBJ_SARC);
AddL1Objs(0, 0, 112, 112);
if ( quests[4]._qlevel == currlevel )
objects_45D88D(0, 0, 112, 112, setpc_x, setpc_y, setpc_x + setpc_w + 1, setpc_y + setpc_h + 1, 11);
InitRndBarrels();
}
if ( leveltype == 2 )
{
AddL2Objs(0, 0, 112, 112);
AddL2Torches();
if ( quests[8]._qlevel == currlevel )
objects_45D88D(0, 0, 112, 112, setpc_x, setpc_y, setpc_x + setpc_w + 1, setpc_y + setpc_h + 1, 23);
if ( quests[9]._qlevel == currlevel )
objects_45D88D(0, 0, 112, 112, setpc_x, setpc_y, setpc_x + setpc_w + 1, setpc_y + setpc_h + 1, 24);
InitRndBarrels();
}
if ( quests[2]._qlevel == currlevel )
InitRndLocObj(1, 1, OBJ_STAND);
if ( quests[3]._qlevel - 1 == currlevel )
InitRndLocObj(1, 1, OBJ_BOOK2R);
InitRndLocObj(5, 10, OBJ_CHEST1);
InitRndLocObj(3, 6, OBJ_CHEST2);
InitRndLocObj(1, 5, OBJ_CHEST3);
if ( leveltype != 4 )
AddObjTraps();
if ( (signed int)(unsigned __int8)leveltype > 1 )
AddChestTraps();
InitObjFlag = 0;
}
//----- (0045E691) --------------------------------------------------------
void __fastcall SetMapObjects(char *pMap, int startx, int starty)
{
int v3; // ST38_4
int v4; // ST34_4
int v5; // ST44_4
int k; // [esp+18h] [ebp-F4h]
int n; // [esp+18h] [ebp-F4h]
signed int i; // [esp+20h] [ebp-ECh]
int j; // [esp+20h] [ebp-ECh]
int l; // [esp+20h] [ebp-ECh]
signed int m; // [esp+20h] [ebp-ECh]
int ii; // [esp+20h] [ebp-ECh]
int v15; // [esp+28h] [ebp-E4h]
int v16; // [esp+2Ch] [ebp-E0h]
char *v17; // [esp+34h] [ebp-D8h]
char *v18; // [esp+34h] [ebp-D8h]
int v19; // [esp+38h] [ebp-D4h]
int fileload[44]; // [esp+3Ch] [ebp-D0h]
char pszName[32]; // [esp+ECh] [ebp-20h]
ClrAllObjects();
InitObjFlag = 1;
for ( i = 0; i < 44; ++i )
fileload[i] = 0;
for ( j = 0; AllObjects[j].oload != -1; ++j )
{
if ( AllObjects[j].oload == 1 && AllObjects[j].olvltype == (unsigned __int8)leveltype )
fileload[AllObjects[j].ofindex] = 1;
}
v3 = (unsigned __int8)*pMap;
v4 = (unsigned __int8)pMap[2];
v5 = 2 * v3 * v4 + 2;
v16 = 2 * v3;
v15 = 2 * v4;
v19 = 4 * v16 * v15 + v5;
v17 = &pMap[v19 + 2];
for ( k = 0; v15 > k; ++k )
{
for ( l = 0; v16 > l; ++l )
{
if ( *v17 )
fileload[AllObjects[ObjTypeConv[(unsigned __int8)*v17]].ofindex] = 1;
v17 += 2;
}
}
numobjfiles = 0;
for ( m = 0; m < 44; ++m )
{
if ( fileload[m] )
{
ObjFileList[numobjfiles] = m;
sprintf(pszName, "Objects\\%s.CEL", ObjMasterLoadList[m]);
if ( pObjCels[numobjfiles] )
assertion_failed(715, "C:\\Diablo\\Direct\\OBJECTS.CPP");
pObjCels[numobjfiles++] = LoadFileInMem(pszName, 0, 716, "C:\\Diablo\\Direct\\OBJECTS.CPP");
}
}
v18 = &pMap[v19 + 2];
for ( n = 0; v15 > n; ++n )
{
for ( ii = 0; v16 > ii; ++ii )
{
if ( *v18 )
AddObject(ObjTypeConv[(unsigned __int8)*v18], startx + ii + 16, starty + n + 16);
v18 += 2;
}
}
InitObjFlag = 0;
}
//----- (0045EA7B) --------------------------------------------------------
void __fastcall DeleteObject(int oi, int i)
{
dObject[object[oi]._ox][object[oi]._oy] = 0;
objectavail[127 - nobjects--] = oi;
if ( nobjects > 0 && nobjects != i )
objectactive[i] = objectactive[nobjects];
}
//----- (0045EB1F) --------------------------------------------------------
void __fastcall SetupObject(int i, int x, int y, int ot)
{
int j; // [esp+14h] [ebp-8h]
object[i]._otype = ot;
object[i]._ox = x;
object[i]._oy = y;
for ( j = 0; ObjFileList[j] != AllObjects[ot].ofindex; ++j )
;
object[i]._oAnimData = pObjCels[j];
object[i]._oAnimFlag = AllObjects[ot].oAnimFlag;
if ( object[i]._oAnimFlag )
{
object[i]._oAnimDelay = AllObjects[ot].oAnimDelay;
object[i]._oAnimCnt = random(146, AllObjects[ot].oAnimDelay);
object[i]._oAnimLen = AllObjects[ot].oAnimLen;
object[i]._oAnimFrame = random(146, AllObjects[ot].oAnimLen - 1) + 1;
}
else
{
object[i]._oAnimDelay = 1000;
object[i]._oAnimCnt = 0;
object[i]._oAnimLen = AllObjects[ot].oAnimLen;
object[i]._oAnimFrame = AllObjects[ot].oAnimDelay;
}
object[i]._oAnimWidth = AllObjects[ot].oAnimWidth;
object[i]._oSolidFlag = AllObjects[ot].oSolidFlag;
object[i]._oMissFlag = AllObjects[ot].oMissFlag;
object[i]._oLight = AllObjects[ot].oLightFlag;
object[i]._oDelFlag = 0;
object[i]._oBreak = AllObjects[ot].oBreak;
object[i]._oSelFlag = AllObjects[ot].oSelFlag;
object[i]._oPreFlag = 0;
object[i]._oTrapFlag = 0;
object[i]._oDoorFlag = 0;
}
//----- (0045EE3C) --------------------------------------------------------
void __fastcall SetObjMapRange(int i, int x1, int y1, int x2, int y2, int v)
{
object[i]._oVar1 = x1;
object[i]._oVar2 = y1;
object[i]._oVar3 = x2;
object[i]._oVar4 = y2;
object[i]._oVar8 = v;
}
//----- (0045EEB6) --------------------------------------------------------
void __fastcall SetBookMsg(int i, int msg)
{
object[i]._oVar7 = msg;
}
//----- (0045EEE2) --------------------------------------------------------
void __fastcall AddL1Door(int i, int x, int y, _object_id ot)
{
int v4; // eax
object[i]._oDoorFlag = 1;
if ( ot == 1 )
{
object[i]._oVar1 = dPiece[x][y];
v4 = dPiece[x - 1][y + 111];
}
else
{
object[i]._oVar1 = dPiece[x][y];
v4 = dPiece[x - 1][y];
}
object[i]._oVar2 = v4;
object[i]._oVar4 = 0;
}
//----- (0045EFD1) --------------------------------------------------------
void __fastcall AddSCambBook(int i)
{
if ( quests[3]._qactive != 1 )
{
object[i]._oSelFlag = 0;
object[i]._oAnimFrame = 6;
}
}
//----- (0045F01C) --------------------------------------------------------
void __fastcall AddChest(int i, int t)
{
int v2; // [esp+10h] [ebp-8h]
int v3; // [esp+14h] [ebp-4h]
v2 = t;
v3 = i;
if ( !random(147, 2) )
object[v3]._oAnimFrame += 3;
object[v3]._oRndSeed = GetRndSeed();
switch ( v2 )
{
case 5:
case 68:
object[v3]._oVar1 = random(147, 2);
break;
case 6:
case 69:
object[v3]._oVar1 = random(147, 3);
break;
case 7:
case 70:
object[v3]._oVar1 = random(147, 4);
break;
default:
break;
}
object[v3]._oVar2 = random(147, 8);
}
//----- (0045F18B) --------------------------------------------------------
void __fastcall AddL2Door(int i, int x, int y, _object_id ot)
{
int v4; // [esp+10h] [ebp-4h]
v4 = i;
object[i]._oDoorFlag = 1;
if ( ot == 42 )
ObjSetMicro(x, y, 538);
else
ObjSetMicro(x, y, 540);
object[v4]._oVar4 = 0;
}
//----- (0045F1FD) --------------------------------------------------------
void __fastcall AddSarc(int i)
{
int v1; // [esp+Ch] [ebp-Ch]
v1 = i;
dObject[object[i]._ox][object[i]._oy - 1] = -1 - i;
object[i]._oVar1 = random(153, 10);
object[v1]._oRndSeed = GetRndSeed();
if ( object[v1]._oVar1 >= 8 )
object[v1]._oVar2 = PreSpawnSkeleton();
}
//----- (0045F2BC) --------------------------------------------------------
void __fastcall AddFlameTrap(int i)
{
object[i]._oVar1 = trapid;
object[i]._oVar2 = 0;
object[i]._oVar3 = trapdir;
object[i]._oVar4 = 0;
}
//----- (0045F324) --------------------------------------------------------
void __fastcall AddFlameLvr(int i)
{
object[i]._oVar1 = trapid;
object[i]._oVar2 = 49;
}
//----- (0045F363) --------------------------------------------------------
void __fastcall AddTrap(int i)
{
int v1; // [esp+10h] [ebp-Ch]
int v2; // [esp+14h] [ebp-8h]
v1 = i;
v2 = random(148, currlevel / 3 + 1);
if ( !v2 )
object[v1]._oVar3 = 0;
if ( v2 == 1 )
object[v1]._oVar3 = 1;
if ( v2 == 2 )
object[v1]._oVar3 = 7;
object[v1]._oVar4 = 0;
}
//----- (0045F40D) --------------------------------------------------------
void __fastcall AddObjLight(int i, int r)
{
int v2; // [esp+10h] [ebp-4h]
v2 = i;
if ( InitObjFlag )
{
DoLighting(object[i]._ox, object[i]._oy, r, -1);
object[v2]._oVar1 = -1;
}
else
{
object[i]._oVar1 = 0;
}
}
//----- (0045F48B) --------------------------------------------------------
void __fastcall AddBarrel(int i)
{
int v1; // [esp+10h] [ebp-4h]
v1 = i;
object[i]._oVar1 = random(149, 5) + 5;
object[v1]._oRndSeed = GetRndSeed();
object[v1]._oVar2 = random(149, 5);
object[v1]._oVar3 = random(149, 3);
if ( object[v1]._oVar2 == 4 )
object[v1]._oVar4 = PreSpawnSkeleton();
}
//----- (0045F545) --------------------------------------------------------
int __fastcall objects_45F545(int a1)
{
int result; // eax
int v2; // [esp+Ch] [ebp-8h]
v2 = a1;
object[a1]._oPreFlag = 1;
result = random(150, 13);
object[v2]._oVar1 = result;
if ( result == 3 || result == 7 || result == 9 )
{
object[v2]._oAnimFrame = 12;
result = 24 * v2;
object[v2]._oAnimLen = 22;
}
return result;
}
//----- (0045F5DA) --------------------------------------------------------
void __fastcall AddBookcase(int i)
{
int v1; // ST0C_4
v1 = i;
object[i]._oRndSeed = GetRndSeed();
object[v1]._oPreFlag = 1;
}
//----- (0045F619) --------------------------------------------------------
int __fastcall objects_45F619(int a1)
{
int v1; // ST0C_4
int result; // eax