forked from johndrinkwater/blake-stone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3D_ACT1.C
2309 lines (1897 loc) · 53 KB
/
3D_ACT1.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
// 3D_ACT1.C
#include "3D_DEF.H"
#pragma hdrstop
//===========================================================================
//
// PROTOTYPES
//
//===========================================================================
void OpenDoor (int door);
void CloseDoor (int door);
void PlaceItemNearTile(int itemtype, int tilex, int tiley);
//===========================================================================
//
// LOCALS
//
//===========================================================================
concession_t ConHintList={0};
/*
=============================================================================
STATICS
=============================================================================
*/
statobj_t statobjlist[MAXSTATS],*laststatobj;
stattype far statinfo[] =
{
{SPR_STAT_0,bo_water_puddle}, // Water Puddle SPR1V
{SPR_STAT_1,block}, // Containment Canister
{SPR_STAT_2,block}, // Lunch Table
{SPR_STAT_3,block}, // Floor Lamp
{SPR_STAT_4,block}, // Lab Table
{SPR_STAT_5,block}, // Pillar
{SPR_STAT_6}, // Blood Puddle
{SPR_STAT_7}, // Piss Puddle
{SPR_STAT_8,block}, // Ficus Tree SPR2V
{SPR_STAT_9}, // Half-Eaten Corpse
{SPR_STAT_10,block}, // Water Fountain
{SPR_STAT_11,block}, // Plant 1
{SPR_STAT_12,block}, // Vase
{SPR_STAT_13,block}, // General Table
{SPR_STAT_14}, // Ceiling Light
{SPR_STAT_15,block}, // General Chair
{SPR_STAT_16,block}, // Kitchen Trash SPR3V
{SPR_STAT_17}, // Office Trash
{SPR_STAT_18,block}, // Plant 2
{SPR_STAT_19,block}, // Gurney No-Blood
{SPR_STAT_20}, // Indirect Half-Sphere
{SPR_STAT_21}, // Exit Sign
{SPR_STAT_22}, // Transporter
{SPR_STAT_23,block}, // Body Can
{SPR_STAT_24,bo_pistol}, // PISTOL SPR4V
{SPR_STAT_25,block}, // Statue
{SPR_STAT_31,bo_clip}, // Charge Unit
{SPR_STAT_27,bo_burst_rifle}, // Auto-Burst Rifle
{SPR_STAT_28,bo_ion_cannon}, // Particle Charged ION
{SPR_STAT_29,bo_firstaid}, // First Aid
{SPR_VSPIKE8,block}, // Static VSPIKE
{SPR_STAT_26,bo_clip2}, // Big Charge pack/clip
{SPR_STAT_32,bo_red_key}, // Red Key SPR5V
{SPR_STAT_33,bo_yellow_key}, // Yellow Key
{SPR_STAT_34,bo_bfg_cannon}, // BFG Cannon
{SPR_STAT_35,bo_blue_key}, // Blue Key
{SPR_STAT_36}, // OPEN
{SPR_STAT_37,block}, // Office Desk
{SPR_STAT_38,block}, // Office Chair
{SPR_STAT_39,block}, // Security Desk
{SPR_STAT_40,bo_water}, // Full Water Bowl SPR7V
{SPR_STAT_41}, // Empty Water Bowl
{SPR_STAT_42,bo_chicken}, // Chicken Leg
{SPR_STAT_43}, // Chicken Bone
{SPR_STAT_44,bo_ham}, // Ham
{SPR_STAT_45}, // Ham Bone
{SPR_STAT_46,bo_grenade}, // Grande Launcher
{SPR_STAT_47}, // Video Game Machine
{SPR_VPOST8,block}, // Static VPOST
// -- VARIOUS --
{SPR_GURNEY_MUT_READY,block}, // 49 Gurney Mutant
{SPR_LCAN_ALIEN_READY,block}, // 50 Large Alien Canister
{SPR_SCAN_ALIEN_READY,block}, // 51 Small Alien Canister
{SPR_GURNEY_MUT_EMPTY,block}, // 52 Gurney Mutant
{SPR_LCAN_ALIEN_EMPTY,block}, // 53 Large Alien Canister
{SPR_SCAN_ALIEN_EMPTY,block}, // 54 Small Alien Canister
{SPR_OFC_DEAD}, // 55 Dead Gen Sci.
{0}, // 56 Spacer
{SPR_AIR_VENT,bo_plainvent}, // 57 Plain air vent
{SPR_AIR_VENT,bo_bloodvent}, // 58 Blood air vent
{SPR_AIR_VENT,bo_watervent}, // 59 Water air vent
{SPR_GRATE}, // 60 Floor Grate
{SPR_STEAM_PIPE}, // 61 Steam Pipe
{SPR_STAT_48,bo_money_bag}, // 62 money bag
{SPR_STAT_49,bo_loot}, // 63 loot
{SPR_STAT_50,bo_gold}, // 64 gold
{SPR_STAT_51,bo_bonus}, // 65 bonus
{SPR_STAT_52, block}, // 66 Greek Post
{SPR_STAT_53, block}, // 67 Red/Blue post
{SPR_STAT_54, block}, // 68 Red HiTech Post
{SPR_STAT_55}, // 69 Ceiling Lamp #2
{SPR_STAT_56}, // 70 Ceiling Lamp #3
{SPR_STAT_57}, // 71 Body Parts
{SPR_STAT_58}, // 72 OR Lamp
{SPR_STAT_59,block}, // 73 Office Sink
{SPR_STAT_57,0}, // EMPTY - Copy of 71 - Body Parts...
{SPR_CANDY_BAR,bo_candybar}, // 75 candy bar
{SPR_SANDWICH,bo_sandwich}, // 76 sandwich
{SPR_CRATE_1,block}, // 77 Crate #1
{SPR_CRATE_2,block}, // 78 Crate #2
{SPR_CRATE_3,block}, // 79 Crate #3
{SPR_STAT_61,block}, // 80 Table
{SPR_STAT_62,block}, // 81 Chair
{SPR_STAT_63,block}, // 82 Stool
{SPR_STAT_64}, // 83 Gore
{SPR_STAT_65,bo_gold3}, // Gold 3
{SPR_STAT_66,bo_gold2}, // Gold 2
{SPR_STAT_67,bo_gold1}, // Gold 1
{SPR_STAT_68,block}, //
{SPR_STAT_69,block}, //
{SPR_STAT_70,block}, //
{SPR_STAT_71,block}, //
{SPR_STAT_72,block}, //
{SPR_STAT_73}, //
{SPR_STAT_74}, //
{SPR_STAT_75}, //
{SPR_STAT_76}, //
{SPR_RENT_DEAD}, //
{SPR_PRO_DEAD}, //
{SPR_SWAT_DEAD}, //
{SPR_GSCOUT_DEAD}, //
{SPR_FSCOUT_DEAD}, //
{SPR_MUTHUM1_DEAD},
{SPR_MUTHUM2_DEAD},
{SPR_LCAN_ALIEN_DEAD},
{SPR_SCAN_ALIEN_DEAD},
{SPR_GURNEY_MUT_DEAD},
{SPR_TERROT_DEAD},
{SPR_POD_DIE3},
{SPR_STAT_77,bo_coin}, // Concession Machine Money
{SPR_STAT_78,bo_coin5}, // Concession Machine Money
{SPR_STAT_79}, // Auto-Charge Pistol
{SPR_DOORBOMB,bo_plasma_detonator}, // Plasma Detonator
{SPR_RUBBLE}, // Door Rubble
{SPR_AUTOMAPPER,bo_automapper1}, // Auto Mapper Bonus #1
{SPR_BONZI_TREE,block}, // BonziTree
{SPR_POT_PLANT,block}, // Yellow Potted Plant
{SPR_TUBE_PLANT,block}, // Tube Plant
{SPR_HITECH_CHAIR,block}, // Hi Tech table and chair
{SPR_DEAD_RENT}, // Dead AOG: Rent A Cop
{SPR_DEAD_PRO}, // Dead AOG: Pro Guard
{SPR_DEAD_SWAT}, // Dead AOG: Swat Guad
{-1} // terminator
};
/*
===============
=
= InitStaticList
=
===============
*/
void InitStaticList (void)
{
laststatobj = &statobjlist[0];
}
//---------------------------------------------------------------------------
// FindStatic()
//
// FUNCTION: Searches the stat obj list and returns ptr to a static obj
// at a particular tile x & tile y coords.
//
// RETURNS: Ptr == Pointer to static obj.
// NULL == No static found.
//---------------------------------------------------------------------------
statobj_t *FindStatic(unsigned tilex, unsigned tiley)
{
statobj_t *spot;
for (spot=statobjlist;spot!=laststatobj;spot++)
if (spot->shapenum != -1 && spot->tilex == tilex && spot->tiley == tiley)
return(spot);
return(NULL);
}
//---------------------------------------------------------------------------
// FindEmptyStatic()
//
// FUNCTION: Searches the stat obj list and returns ptr to an empty
// static object.
//
// RETURNS: Ptr == Pointer to empty static obj.
// NULL == static objlist full.
//---------------------------------------------------------------------------
statobj_t *FindEmptyStatic(void)
{
statobj_t *spot;
for (spot=&statobjlist[0] ; ; spot++)
{
if (spot==laststatobj)
{
if (spot == &statobjlist[MAXSTATS])
return(NULL);
laststatobj++; // space at end
break;
}
if (spot->shapenum == -1) // -1 is a free spot
break;
}
return(spot);
}
/*
===============
=
= SpawnStatic
=
===============
*/
void SpawnStatic (int tilex, int tiley, int type)
{
statobj_t *spot;
#if 0
#if IN_DEVELOPMENT
if (tilemap[tilex][tiley])
Quit("Static spawned on wall. %d,%d",tilex,tiley);
// ACT1_ERROR(SPAWNSTATIC_ON_WALL);
#endif
#endif
if (!(spot = FindEmptyStatic()))
return;
spot->shapenum = statinfo[type].picnum;
spot->tilex = tilex;
spot->tiley = tiley;
spot->visspot = &spotvis[tilex][tiley];
spot->flags = 0;
#if IN_DEVELOPMENT
#if GAME_VERSION == SHAREWARE_VERSION
if (!spot->shapenum)
Quit("Invalid static: %d %d",tilex,tiley);
#endif
#endif
switch (spot->shapenum)
{
#if GAME_VERSION != SHAREWARE_VERSION
case SPR_STAT_3: // floor lamp
#endif
case SPR_STAT_14: // ceiling light
#if GAME_VERSION != SHAREWARE_VERSION
case SPR_STAT_20: //
#endif
case SPR_STAT_47:
case SPR_STAT_51:
case SPR_STAT_55:
case SPR_STAT_56:
spot->lighting = LAMP_ON_SHADING;
break;
default:
spot->lighting = 0;
break;
}
switch (statinfo[type].type)
{
case block:
(unsigned)actorat[tilex][tiley] = 1; // consider it a blocking tile
break;
case bo_red_key:
case bo_yellow_key:
case bo_blue_key:
case bo_plasma_detonator:
TravelTable[tilex][tiley] |= TT_KEYS;
case bo_gold1:
case bo_gold2:
case bo_gold3:
case bo_gold:
case bo_bonus:
case bo_money_bag:
case bo_loot:
case bo_fullheal:
case bo_firstaid:
case bo_clip:
case bo_clip2:
case bo_burst_rifle:
case bo_ion_cannon:
case bo_grenade:
case bo_bfg_cannon:
case bo_pistol:
case bo_chicken:
case bo_ham:
case bo_water:
case bo_water_puddle:
case bo_sandwich:
case bo_candybar:
case bo_coin:
case bo_coin5:
case bo_automapper1:
spot->flags = FL_BONUS;
spot->itemnumber = statinfo[type].type;
break;
}
spot->areanumber=GetAreaNumber(spot->tilex,spot->tiley);
spot++;
if (spot == &statobjlist[MAXSTATS])
ACT1_ERROR(SPAWNSTATIC_TOO_MANY);
}
//---------------------------------------------------------------------------
// ReserveStatic()
//
// Reserves a static object at location 0,0 (unseen). This function is
// used to gaurantee that a static will be available.
//---------------------------------------------------------------------------
statobj_t *ReserveStatic(void)
{
statobj_t *spot;
if (!(spot = FindEmptyStatic()))
ACT1_ERROR(SPAWNSTATIC_TOO_MANY);
// Mark as Used.
spot->shapenum = 1;
spot->tilex = 0;
spot->tiley = 0;
spot->visspot = &spotvis[0][0];
return(spot);
}
//---------------------------------------------------------------------------
// FindReservedStatic()
//
// Finds a Reserved static object at location 0,0 (unseen). This function is
// used to gaurantee that a static will be available.
//---------------------------------------------------------------------------
statobj_t *FindReservedStatic(void)
{
statobj_t *spot;
for (spot=&statobjlist[0];spot < &statobjlist[MAXSTATS];spot++)
{
if (spot->shapenum == 1 && (!spot->tilex) && (!spot->tiley)) // -1 is a free spot
return(spot);
}
return(NULL);
}
//---------------------------------------------------------------------------
// UseReservedStatic()
//
// Finds a Reserved static object and moves it to a new location with new
// attributes.
//
// This function acts like PlaceItemType - But REQUIRES a reserved
// static. Before using this function, make sure that you have already
// reserved a static to be used using ReserveStatic();
//---------------------------------------------------------------------------
statobj_t *UseReservedStatic(int itemtype, int tilex, int tiley)
{
statobj_t *spot;
int type;
if (!(spot = FindReservedStatic()))
ACT1_ERROR(CANT_FIND_RESERVE_STATIC);
//
// find the item number
//
for (type=0;;type++)
{
if (statinfo[type].picnum == -1) // End of Static List...
ACT1_ERROR(PLACEITEMTYPE_NO_TYPE);
if (statinfo[type].type == itemtype) // Bingo, Found it!
break;
}
//
// place it
//
switch (type)
{
case bo_red_key:
case bo_yellow_key:
case bo_blue_key:
TravelTable[tilex][tiley] |= TT_KEYS;
break;
}
spot->shapenum = statinfo[type].picnum;
spot->tilex = tilex;
spot->tiley = tiley;
spot->visspot = &spotvis[tilex][tiley];
spot->flags = FL_BONUS;
spot->itemnumber = statinfo[type].type;
spot->areanumber=GetAreaNumber(spot->tilex,spot->tiley);
#if IN_DEVELOPMENT
if (spot->areanumber >= NUMAREAS)
Quit("Static Spawned on a wall at %d %d",spot->tilex,spot->tiley);
#endif
return(spot);
}
//--------------------------------------------------------------------------
// PlaceReservedItemNearTile()
//--------------------------------------------------------------------------
char far pint_xy[8][2]={{-1,-1},{-1, 0},{-1, 1},
{ 0,-1}, { 0, 1},
{ 1,-1},{ 1, 0},{ 1, 1}};
void PlaceReservedItemNearTile(int itemtype, int tilex, int tiley)
{
char loop;
for (loop=0; loop<8; loop++)
{
char x=tilex+pint_xy[loop][1], y=tiley+pint_xy[loop][0];
if (!tilemap[x][y])
{
if (actorat[x][y] == (objtype *)1) // Check for a SOLID static
continue;
UseReservedStatic(itemtype,x,y);
return;
}
}
UseReservedStatic(itemtype,tilex,tiley);
}
/*
===============
=
= PlaceItemType
=
= Called during game play to drop actors' items. It finds the proper
= item number based on the item type (bo_???). If there are no free item
= spots, nothing is done.
=
===============
*/
void PlaceItemType (int itemtype, int tilex, int tiley)
{
int type;
statobj_t *spot;
//
// find the item number
//
for (type=0 ; ; type++)
{
if (statinfo[type].picnum == -1) // end of list
ACT1_ERROR(PLACEITEMTYPE_NO_TYPE);
if (statinfo[type].type == itemtype)
break;
}
//
// find a spot in statobjlist to put it in
//
if (!(spot = FindEmptyStatic()))
return;
//
// place it
//
spot->shapenum = statinfo[type].picnum;
spot->tilex = tilex;
spot->tiley = tiley;
spot->visspot = &spotvis[tilex][tiley];
spot->flags = FL_BONUS;
spot->itemnumber = statinfo[type].type;
spot->areanumber=GetAreaNumber(spot->tilex,spot->tiley);
#if IN_DEVELOPMENT
if (spot->areanumber >= NUMAREAS)
Quit("Item Spawned on a wall at %d %d",spot->tilex,spot->tiley);
#endif
}
//--------------------------------------------------------------------------
// PlaceItemNearTile()
//--------------------------------------------------------------------------
void PlaceItemNearTile(int itemtype, int tilex, int tiley)
{
// [0] is the y offset
// [1] is the x offset
//
char loop;
for (loop=0; loop<8; loop++)
{
char x=tilex+pint_xy[loop][1], y=tiley+pint_xy[loop][0];
if (!tilemap[x][y])
{
if (actorat[x][y] == (objtype *)1) // Check for a SOLID static
continue;
PlaceItemType(itemtype,x,y);
return;
}
}
PlaceItemType(itemtype,tilex,tiley);
}
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// ExplodeStatics()
//
// NOTES: Explodes statics in a one tile radius from a given tile x and tile y
//
//--------------------------------------------------------------------------
void ExplodeStatics(int tilex, int tiley)
{
statobj_t *statobj, *spot;
objtype *obj;
int y_diff,x_diff;
boolean remove;
for (spot=&statobjlist[0] ; spot != laststatobj ; spot++)
if (spot->shapenum != -1)
{
y_diff = spot->tiley - tiley;
y_diff = ABS(y_diff);
x_diff = spot->tilex - tilex;
x_diff = ABS(x_diff);
if (x_diff < 2 && y_diff <2)
{
remove = false;
//
// Test for specific statics..
//
switch (spot->itemnumber)
{
//
// Check for Clips
//
case bo_clip:
case bo_clip2:
remove = true;
SpawnCusExplosion((((fixed)spot->tilex)<<TILESHIFT)+0x7FFF,
(((fixed)spot->tiley)<<TILESHIFT)+0x7FFF,
SPR_CLIP_EXP1, 7, 3+(US_RndT()&0x3),explosionobj);
break;
}
//
// Check to see if we remove it.
//
if (remove)
{
// Remove static
spot->shapenum = -1;
spot->itemnumber = bo_nothing;
}
}
}
}
/*
=============================================================================
DOORS
doorobjlist[] holds most of the information for the doors
doorposition[] holds the amount the door is open, ranging from 0 to 0xffff
this is directly accessed by AsmRefresh during rendering
The number of doors is limited to 64 because a spot in tilemap holds the
door number in the low 6 bits, with the high bit meaning a door center
and bit 6 meaning a door side tile
Open doors conect two areas, so sounds will travel between them and sight
will be checked when the player is in a connected area.
Areaconnect is incremented/decremented by each door. If >0 they connect
Every time a door opens or closes the areabyplayer matrix gets recalculated.
An area is true if it connects with the player's current spor.
=============================================================================
*/
#define DOORWIDTH 0x7800
#define OPENTICS 300
doorobj_t doorobjlist[MAXDOORS],*lastdoorobj;
int doornum;
unsigned doorposition[MAXDOORS]; // leading edge of door 0=closed
// 0xffff = fully open
byte far areaconnect[NUMAREAS][NUMAREAS];
boolean areabyplayer[NUMAREAS];
/*
==============
=
= ConnectAreas
=
= Scans outward from playerarea, marking all connected areas
=
==============
*/
void RecursiveConnect (int areanumber)
{
int i;
for (i=0;i<NUMAREAS;i++)
{
if (areaconnect[areanumber][i] && !areabyplayer[i])
{
areabyplayer[i] = true;
RecursiveConnect (i);
}
}
}
void ConnectAreas (void)
{
memset (areabyplayer,0,sizeof(areabyplayer));
areabyplayer[player->areanumber] = true;
RecursiveConnect (player->areanumber);
}
void InitAreas (void)
{
memset (areabyplayer,0,sizeof(areabyplayer));
areabyplayer[player->areanumber] = true;
}
/*
===============
=
= InitDoorList
=
===============
*/
void InitDoorList (void)
{
memset (areabyplayer,0,sizeof(areabyplayer));
_fmemset (areaconnect,0,sizeof(areaconnect));
lastdoorobj = &doorobjlist[0];
doornum = 0;
}
/*
===============
=
= SpawnDoor
=
===============
*/
void SpawnDoor (int tilex, int tiley, boolean vertical, keytype lock, door_t type)
{
int areanumber;
unsigned far *map[2];
map[0] = mapsegs[0] + farmapylookup[tiley]+tilex;
map[1] = mapsegs[1] + farmapylookup[tiley]+tilex;
if (doornum==64)
ACT1_ERROR(SPAWNDOOR_TOO_MANY);
doorposition[doornum] = 0; // doors start out fully closed
lastdoorobj->tilex = tilex;
lastdoorobj->tiley = tiley;
lastdoorobj->vertical = vertical;
lastdoorobj->lock = lock;
lastdoorobj->type = type;
lastdoorobj->action = dr_closed;
lastdoorobj->flags = DR_BLASTABLE; // JIM - Do something with this! jdebug
if (vertical)
{
lastdoorobj->areanumber[0]=GetAreaNumber(tilex+1,tiley);
lastdoorobj->areanumber[1]=GetAreaNumber(tilex-1,tiley);
}
else
{
lastdoorobj->areanumber[0]=GetAreaNumber(tilex,tiley-1);
lastdoorobj->areanumber[1]=GetAreaNumber(tilex,tiley+1);
}
(unsigned)actorat[tilex][tiley] = doornum | 0x80; // consider it a solid wall
//
// make the door tile a special tile, and mark the adjacent tiles
// for door sides
//
tilemap[tilex][tiley] = doornum | 0x80;
if (vertical)
{
if (*(map[0]-mapwidth-1) == TRANSPORTERTILE)
*map[0] = GetAreaNumber(tilex+1,tiley);
else
*map[0] = GetAreaNumber(tilex-1,tiley);
tilemap[tilex][tiley-1] |= 0x40;
tilemap[tilex][tiley+1] |= 0x40;
}
else
{
*map[0] = GetAreaNumber(tilex,tiley-1);
tilemap[tilex-1][tiley] |= 0x40;
tilemap[tilex+1][tiley] |= 0x40;
}
doornum++;
lastdoorobj++;
}
//===========================================================================
//--------------------------------------------------------------------------
// CheckLinkedDoors
//--------------------------------------------------------------------------
void CheckLinkedDoors(short door, short door_dir)
{
static short LinkCheck=0;
static short base_tilex;
static short base_tiley;
short tilex=doorobjlist[door].tilex,
tiley=doorobjlist[door].tiley,
next_tilex=0,
next_tiley=0;
// Find next door in link.
//
// if ((*(mapsegs[1]+(farmapylookup[tiley]+tilex+1)) & 0xff00) == 0xf900)
if (*(mapsegs[1]+(farmapylookup[tiley]+tilex)))
{
// unsigned value=*(mapsegs[1]+(farmapylookup[tiley]+tilex+2));
unsigned value=*(mapsegs[1]+(farmapylookup[tiley]+tilex));
// Define the next door in the link.
//
next_tilex = (value & 0xff00)>>8;
next_tiley = value & 0xff;
// Is this the head of the link?
//
if (!LinkCheck)
{
base_tilex=tilex;
base_tiley=tiley;
}
}
LinkCheck++;
// Recursively open/close linked doors.
//
if ((next_tilex) &&
(next_tiley) &&
((next_tilex != base_tilex) || (next_tiley != base_tiley))
)
{
short door=tilemap[next_tilex][next_tiley] & ~0x80;
switch (door_dir)
{
case dr_opening:
doorobjlist[door].lock = kt_none;
OpenDoor(door);
break;
case dr_closing:
doorobjlist[door].lock = kt_none;
CloseDoor(door);
break;
}
}
LinkCheck--;
}
/*
=====================
=
= OpenDoor
=
=====================
*/
void OpenDoor (int door)
{
if (doorobjlist[door].action == dr_jammed)
return;
if (doorobjlist[door].action == dr_open)
doorobjlist[door].ticcount = 0; // reset open time
else
doorobjlist[door].action = dr_opening; // start it opening
CheckLinkedDoors(door,dr_opening);
}
/*
=====================
=
= CloseDoor
=
=====================
*/
void CloseDoor (int door)
{
int tilex,tiley,area;
objtype *check;
if (doorobjlist[door].action == dr_jammed)
return;
//
// don't close on anything solid
//
tilex = doorobjlist[door].tilex;
tiley = doorobjlist[door].tiley;
if (actorat[tilex][tiley])
return;
if (player->tilex == tilex && player->tiley == tiley)
return;
if (doorobjlist[door].vertical)
{
if ( player->tiley == tiley )
{
if ( ((player->x+MINDIST) >>TILESHIFT) == tilex )
return;
if ( ((player->x-MINDIST) >>TILESHIFT) == tilex )
return;
}
check = actorat[tilex-1][tiley];
if (check && ((check->x+MINDIST) >> TILESHIFT) == tilex )
return;
check = actorat[tilex+1][tiley];
if (check && ((check->x-MINDIST) >> TILESHIFT) == tilex )
return;
}
else if (!doorobjlist[door].vertical)
{
if (player->tilex == tilex)
{
if ( ((player->y+MINDIST) >>TILESHIFT) == tiley )
return;
if ( ((player->y-MINDIST) >>TILESHIFT) == tiley )
return;
}
check = actorat[tilex][tiley-1];
if (check && ((check->y+MINDIST) >> TILESHIFT) == tiley )
return;
check = actorat[tilex][tiley+1];
if (check && ((check->y-MINDIST) >> TILESHIFT) == tiley )
return;
}
//
// play door sound if in a connected area
//
area = GetAreaNumber(doorobjlist[door].tilex,doorobjlist[door].tiley);
if (areabyplayer[area])
{
switch(doorobjlist[door].type)
{
case dr_bio:
case dr_office:
case dr_space:
case dr_normal:
PlaySoundLocTile(HTECHDOORCLOSESND,doorobjlist[door].tilex,doorobjlist[door].tiley);
break;
default:
PlaySoundLocTile(CLOSEDOORSND,doorobjlist[door].tilex,doorobjlist[door].tiley);
break;
}
}
doorobjlist[door].action = dr_closing;
//
// make the door space solid
//
(unsigned)actorat[tilex][tiley]
= door | 0x80;
CheckLinkedDoors(door,dr_closing);
}