-
Notifications
You must be signed in to change notification settings - Fork 31
/
p_spec.c
3436 lines (3014 loc) · 104 KB
/
p_spec.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
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id: p_spec.c,v 1.56 1998/05/25 10:40:30 killough Exp $
//
// Copyright (C) 1999 by
// id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
// DESCRIPTION:
// -Loads and initializes texture and flat animation sequences
// -Implements utility functions for all linedef/sector special handlers
// -Dispatches walkover and gun line triggers
// -Initializes and implements special sector types
// -Implements donut linedef triggers
// -Initializes and implements BOOM linedef triggers for
// Scrollers/Conveyors
// Friction
// Wind/Current
//
//-----------------------------------------------------------------------------
#include "doomstat.h"
#include "p_spec.h"
#include "p_tick.h"
#include "p_setup.h"
#include "m_random.h"
#include "d_englsh.h"
#include "m_argv.h"
#include "w_wad.h"
#include "r_main.h"
#include "p_maputl.h"
#include "p_map.h"
#include "g_game.h"
#include "p_inter.h"
#include "s_sound.h"
#include "sounds.h"
#include "m_bbox.h" // phares 3/20/98
#include "d_deh.h"
#include "r_plane.h" // killough 10/98
#include "i_sound.h"
#include "r_draw.h" // R_SetFuzzPosTic
//
// Animating textures and planes
// There is another anim_t used in wi_stuff, unrelated.
//
typedef struct
{
boolean istexture;
int picnum;
int basepic;
int numpics;
int speed;
} anim_t;
//
// source animation definition
//
typedef PACKED_STRUCT (
{
// [FG] signed char!
signed char istexture; //jff 3/23/98 make char for comparison
char endname[9]; // if false, it is a flat
char startname[9];
int speed;
}) animdef_t; //jff 3/23/98 pack to read from memory
#define MAXANIMS 32 // no longer a strict limit -- killough
static anim_t *lastanim, *anims; // new structure w/o limits -- killough
static size_t maxanims;
// killough 3/7/98: Initialize generalized scrolling
static void P_SpawnScrollers(void);
static void P_SpawnFriction(void); // phares 3/16/98
static void P_SpawnPushers(void); // phares 3/20/98
//
// P_InitPicAnims
//
// Load the table of animation definitions, checking for existence of
// the start and end of each frame. If the start doesn't exist the sequence
// is skipped, if the last doesn't exist, BOOM exits.
//
// Wall/Flat animation sequences, defined by name of first and last frame,
// The full animation sequence is given using all lumps between the start
// and end entry, in the order found in the WAD file.
//
// This routine modified to read its data from a predefined lump or
// PWAD lump called ANIMATED rather than a static table in this module to
// allow wad designers to insert or modify animation sequences.
//
// Lump format is an array of byte packed animdef_t structures, terminated
// by a structure with istexture == -1. The lump can be generated from a
// text source file using SWANTBLS.EXE, distributed with the BOOM utils.
// The standard list of switches and animations is contained in the example
// source text file DEFSWANI.DAT also in the BOOM util distribution.
//
//
void P_InitPicAnims (void)
{
int i;
animdef_t *animdefs; //jff 3/23/98 pointer to animation lump
// Init animation
//jff 3/23/98 read from predefined or wad lump instead of table
animdefs = W_CacheLumpName("ANIMATED",PU_STATIC);
lastanim = anims;
for (i=0 ; animdefs[i].istexture != -1 ; i++)
{
// 1/11/98 killough -- removed limit by array-doubling
if (lastanim >= anims + maxanims)
{
size_t newmax = maxanims ? maxanims*2 : MAXANIMS;
anims = realloc(anims, newmax*sizeof(*anims)); // killough
lastanim = anims + maxanims;
maxanims = newmax;
}
if (animdefs[i].istexture)
{
// different episode ?
if (R_CheckTextureNumForName(animdefs[i].startname) == -1)
continue;
lastanim->picnum = R_TextureNumForName (animdefs[i].endname);
lastanim->basepic = R_TextureNumForName (animdefs[i].startname);
}
else
{
if ((W_CheckNumForName)(animdefs[i].startname, ns_flats) == -1) // killough 4/17/98
continue;
lastanim->picnum = R_FlatNumForName (animdefs[i].endname);
lastanim->basepic = R_FlatNumForName (animdefs[i].startname);
}
lastanim->istexture = animdefs[i].istexture;
lastanim->numpics = lastanim->picnum - lastanim->basepic + 1;
if (lastanim->numpics < 2)
I_Error ("P_InitPicAnims: bad cycle from %s to %s",
animdefs[i].startname,
animdefs[i].endname);
lastanim->speed = LONG(animdefs[i].speed); // killough 5/5/98: add LONG()
lastanim++;
}
Z_ChangeTag (animdefs,PU_CACHE); //jff 3/23/98 allow table to be freed
}
///////////////////////////////////////////////////////////////
//
// Linedef and Sector Special Implementation Utility Functions
//
///////////////////////////////////////////////////////////////
//
// getSide()
//
// Will return a side_t*
// given the number of the current sector,
// the line number, and the side (0/1) that you want.
//
// Note: if side=1 is specified, it must exist or results undefined
//
side_t *getSide(int currentSector, int line, int side)
{
return &sides[sectors[currentSector].lines[line]->sidenum[side]];
}
//
// getSector()
//
// Will return a sector_t*
// given the number of the current sector,
// the line number and the side (0/1) that you want.
//
// Note: if side=1 is specified, it must exist or results undefined
//
sector_t *getSector(int currentSector, int line, int side)
{
return sides[sectors[currentSector].lines[line]->sidenum[side]].sector;
}
//
// twoSided()
//
// Given the sector number and the line number,
// it will tell you whether the line is two-sided or not.
//
// modified to return actual two-sidedness rather than presence
// of 2S flag unless compatibility optioned
//
// killough 11/98: reformatted
int twoSided(int sector, int line)
{
//jff 1/26/98 return what is actually needed, whether the line
//has two sidedefs, rather than whether the 2S flag is set
return comp[comp_model] ? sectors[sector].lines[line]->flags & ML_TWOSIDED :
sectors[sector].lines[line]->sidenum[1] != NO_INDEX;
}
//
// getNextSector()
//
// Return sector_t * of sector next to current across line.
//
// Note: returns NULL if not two-sided line, or both sides refer to sector
//
// killough 11/98: reformatted
sector_t *getNextSector(line_t *line, sector_t *sec)
{
//jff 1/26/98 check unneeded since line->backsector already
//returns NULL if the line is not two sided, and does so from
//the actual two-sidedness of the line, rather than its 2S flag
//
//jff 5/3/98 don't retn sec unless compatibility
// fixes an intra-sector line breaking functions
// like floor->highest floor
return comp[comp_model] && !(line->flags & ML_TWOSIDED) ? NULL :
line->frontsector == sec ? comp[comp_model] || line->backsector != sec ?
line->backsector : NULL : line->frontsector;
}
//
// P_FindLowestFloorSurrounding()
//
// Returns the fixed point value of the lowest floor height
// in the sector passed or its surrounding sectors.
//
// killough 11/98: reformatted
fixed_t P_FindLowestFloorSurrounding(sector_t* sec)
{
fixed_t floor = sec->floorheight;
const sector_t *other;
int i;
for (i = 0; i < sec->linecount; i++)
if ((other = getNextSector(sec->lines[i], sec)) &&
other->floorheight < floor)
floor = other->floorheight;
return floor;
}
//
// P_FindHighestFloorSurrounding()
//
// Passed a sector, returns the fixed point value of the largest
// floor height in the surrounding sectors, not including that passed
//
// NOTE: if no surrounding sector exists -32000*FRACUINT is returned
// if compatibility then -500*FRACUNIT is the smallest return possible
//
// killough 11/98: reformatted
fixed_t P_FindHighestFloorSurrounding(sector_t *sec)
{
fixed_t floor = -500*FRACUNIT;
const sector_t *other;
int i;
//jff 1/26/98 Fix initial value for floor to not act differently
//in sections of wad that are below -500 units
if (!comp[comp_model]) //jff 3/12/98 avoid ovf
floor = -32000*FRACUNIT; // in height calculations
for (i=0 ;i < sec->linecount ; i++)
if ((other = getNextSector(sec->lines[i],sec)) &&
other->floorheight > floor)
floor = other->floorheight;
return floor;
}
//
// P_FindNextHighestFloor()
//
// Passed a sector and a floor height, returns the fixed point value
// of the smallest floor height in a surrounding sector larger than
// the floor height passed. If no such height exists the floorheight
// passed is returned.
//
// Rewritten by Lee Killough to avoid fixed array and to be faster
//
fixed_t P_FindNextHighestFloor(sector_t *sec, int currentheight)
{
sector_t *other;
int i;
for (i=0 ;i < sec->linecount ; i++)
if ((other = getNextSector(sec->lines[i],sec)) &&
other->floorheight > currentheight)
{
int height = other->floorheight;
while (++i < sec->linecount)
if ((other = getNextSector(sec->lines[i],sec)) &&
other->floorheight < height &&
other->floorheight > currentheight)
height = other->floorheight;
return height;
}
return currentheight;
}
//
// P_FindNextLowestFloor()
//
// Passed a sector and a floor height, returns the fixed point value
// of the largest floor height in a surrounding sector smaller than
// the floor height passed. If no such height exists the floorheight
// passed is returned.
//
// jff 02/03/98 Twiddled Lee's P_FindNextHighestFloor to make this
fixed_t P_FindNextLowestFloor(sector_t *sec, int currentheight)
{
sector_t *other;
int i;
for (i=0 ;i < sec->linecount ; i++)
if ((other = getNextSector(sec->lines[i],sec)) &&
other->floorheight < currentheight)
{
int height = other->floorheight;
while (++i < sec->linecount)
if ((other = getNextSector(sec->lines[i],sec)) &&
other->floorheight > height &&
other->floorheight < currentheight)
height = other->floorheight;
return height;
}
return currentheight;
}
//
// P_FindNextLowestCeiling()
//
// Passed a sector and a ceiling height, returns the fixed point value
// of the largest ceiling height in a surrounding sector smaller than
// the ceiling height passed. If no such height exists the ceiling height
// passed is returned.
//
// jff 02/03/98 Twiddled Lee's P_FindNextHighestFloor to make this
fixed_t P_FindNextLowestCeiling(sector_t *sec, int currentheight)
{
sector_t *other;
int i;
for (i=0 ;i < sec->linecount ; i++)
if ((other = getNextSector(sec->lines[i],sec)) &&
other->ceilingheight < currentheight)
{
int height = other->ceilingheight;
while (++i < sec->linecount)
if ((other = getNextSector(sec->lines[i],sec)) &&
other->ceilingheight > height &&
other->ceilingheight < currentheight)
height = other->ceilingheight;
return height;
}
return currentheight;
}
//
// P_FindNextHighestCeiling()
//
// Passed a sector and a ceiling height, returns the fixed point value
// of the smallest ceiling height in a surrounding sector larger than
// the ceiling height passed. If no such height exists the ceiling height
// passed is returned.
//
// jff 02/03/98 Twiddled Lee's P_FindNextHighestFloor to make this
fixed_t P_FindNextHighestCeiling(sector_t *sec, int currentheight)
{
sector_t *other;
int i;
for (i=0 ;i < sec->linecount ; i++)
if ((other = getNextSector(sec->lines[i],sec)) &&
other->ceilingheight > currentheight)
{
int height = other->ceilingheight;
while (++i < sec->linecount)
if ((other = getNextSector(sec->lines[i],sec)) &&
other->ceilingheight < height &&
other->ceilingheight > currentheight)
height = other->ceilingheight;
return height;
}
return currentheight;
}
//
// P_FindLowestCeilingSurrounding()
//
// Passed a sector, returns the fixed point value of the smallest
// ceiling height in the surrounding sectors, not including that passed
//
// NOTE: if no surrounding sector exists 32000*FRACUINT is returned
// but if compatibility then MAXINT is the return
//
// killough 11/98: reformatted
fixed_t P_FindLowestCeilingSurrounding(sector_t* sec)
{
const sector_t *other;
fixed_t height = D_MAXINT;
int i;
if (!comp[comp_model])
height = 32000*FRACUNIT; //jff 3/12/98 avoid ovf in
// height calculations
for (i=0; i < sec->linecount; i++)
if ((other = getNextSector(sec->lines[i],sec)) &&
other->ceilingheight < height)
height = other->ceilingheight;
return height;
}
//
// P_FindHighestCeilingSurrounding()
//
// Passed a sector, returns the fixed point value of the largest
// ceiling height in the surrounding sectors, not including that passed
//
// NOTE: if no surrounding sector exists -32000*FRACUINT is returned
// but if compatibility then 0 is the smallest return possible
//
// killough 11/98: reformatted
fixed_t P_FindHighestCeilingSurrounding(sector_t* sec)
{
const sector_t *other;
fixed_t height = 0;
int i;
//jff 1/26/98 Fix initial value for floor to not act differently
//in sections of wad that are below 0 units
if (!comp[comp_model])
height = -32000*FRACUNIT; //jff 3/12/98 avoid ovf in
// height calculations
for (i=0 ;i < sec->linecount ; i++)
if ((other = getNextSector(sec->lines[i],sec)) &&
other->ceilingheight > height)
height = other->ceilingheight;
return height;
}
//
// P_FindShortestTextureAround()
//
// Passed a sector number, returns the shortest lower texture on a
// linedef bounding the sector.
//
// Note: If no lower texture exists 32000*FRACUNIT is returned.
// but if compatibility then MAXINT is returned
//
// jff 02/03/98 Add routine to find shortest lower texture
//
// killough 11/98: reformatted
fixed_t P_FindShortestTextureAround(int secnum)
{
const sector_t *sec = §ors[secnum];
int i, minsize = D_MAXINT;
#ifdef MBF_STRICT
static const int mintex = 0;
#else
static const int mintex = 1; //jff 8/14/98 texture 0 is a placeholder
#endif
if (!comp[comp_model])
minsize = 32000<<FRACBITS; //jff 3/13/98 prevent overflow in height calcs
for (i = 0; i < sec->linecount; i++)
if (twoSided(secnum, i))
{
const side_t *side;
if ((side = getSide(secnum,i,0))->bottomtexture >= mintex &&
textureheight[side->bottomtexture] < minsize)
minsize = textureheight[side->bottomtexture];
if ((side = getSide(secnum,i,1))->bottomtexture >= mintex &&
textureheight[side->bottomtexture] < minsize)
minsize = textureheight[side->bottomtexture];
}
return minsize;
}
//
// P_FindShortestUpperAround()
//
// Passed a sector number, returns the shortest upper texture on a
// linedef bounding the sector.
//
// Note: If no upper texture exists 32000*FRACUNIT is returned.
// but if compatibility then MAXINT is returned
//
// jff 03/20/98 Add routine to find shortest upper texture
//
// killough 11/98: reformatted
fixed_t P_FindShortestUpperAround(int secnum)
{
const sector_t *sec = §ors[secnum];
int i, minsize = D_MAXINT;
#ifdef MBF_STRICT
static const int mintex = 0;
#else
static const int mintex = 1; //jff 8/14/98 texture 0 is a placeholder
#endif
if (!comp[comp_model])
minsize = 32000<<FRACBITS; //jff 3/13/98 prevent overflow
// in height calcs
for (i = 0; i < sec->linecount; i++)
if (twoSided(secnum, i))
{
const side_t *side;
if ((side = getSide(secnum,i,0))->toptexture >= mintex)
if (textureheight[side->toptexture] < minsize)
minsize = textureheight[side->toptexture];
if ((side = getSide(secnum,i,1))->toptexture >= mintex)
if (textureheight[side->toptexture] < minsize)
minsize = textureheight[side->toptexture];
}
return minsize;
}
//
// P_FindModelFloorSector()
//
// Passed a floor height and a sector number, return a pointer to a
// a sector with that floor height across the lowest numbered two sided
// line surrounding the sector.
//
// Note: If no sector at that height bounds the sector passed, return NULL
//
// jff 02/03/98 Add routine to find numeric model floor
// around a sector specified by sector number
// jff 3/14/98 change first parameter to plain height to allow call
// from routine not using floormove_t
//
// killough 11/98: reformatted
sector_t *P_FindModelFloorSector(fixed_t floordestheight, int secnum)
{
sector_t *sec = §ors[secnum]; //jff 3/2/98 woops! better do this
//jff 5/23/98 don't disturb sec->linecount while searching
// but allow early exit in old demos
int i, linecount = sec->linecount;
for (i = 0; i < (demo_compatibility && sec->linecount < linecount ?
sec->linecount : linecount); i++)
if (twoSided(secnum, i) &&
(sec = getSector(secnum, i,
getSide(secnum,i,0)->sector-sectors == secnum))->
floorheight == floordestheight)
return sec;
return NULL;
}
//
// P_FindModelCeilingSector()
//
// Passed a ceiling height and a sector number, return a pointer to a
// a sector with that ceiling height across the lowest numbered two sided
// line surrounding the sector.
//
// Note: If no sector at that height bounds the sector passed, return NULL
//
// jff 02/03/98 Add routine to find numeric model ceiling
// around a sector specified by sector number
// used only from generalized ceiling types
// jff 3/14/98 change first parameter to plain height to allow call
// from routine not using ceiling_t
//
// killough 11/98: reformatted
sector_t *P_FindModelCeilingSector(fixed_t ceildestheight, int secnum)
{
sector_t *sec = §ors[secnum]; //jff 3/2/98 woops! better do this
//jff 5/23/98 don't disturb sec->linecount while searching
// but allow early exit in old demos
int i, linecount = sec->linecount;
for (i = 0; i < (demo_compatibility && sec->linecount<linecount?
sec->linecount : linecount); i++)
if (twoSided(secnum, i) &&
(sec = getSector(secnum, i,
getSide(secnum,i,0)->sector-sectors == secnum))->
ceilingheight == ceildestheight)
return sec;
return NULL;
}
//
// RETURN NEXT SECTOR # THAT LINE TAG REFERS TO
//
// Find the next sector with the same tag as a linedef.
// Rewritten by Lee Killough to use chained hashing to improve speed
int P_FindSectorFromLineTag(const line_t *line, int start)
{
start = start >= 0 ? sectors[start].nexttag :
sectors[(unsigned) line->tag % (unsigned) numsectors].firsttag;
while (start >= 0 && sectors[start].tag != line->tag)
start = sectors[start].nexttag;
return start;
}
// killough 4/16/98: Same thing, only for linedefs
int P_FindLineFromLineTag(const line_t *line, int start)
{
start = start >= 0 ? lines[start].nexttag :
lines[(unsigned) line->tag % (unsigned) numlines].firsttag;
while (start >= 0 && lines[start].tag != line->tag)
start = lines[start].nexttag;
return start;
}
// Hash the sector tags across the sectors and linedefs.
static void P_InitTagLists(void)
{
register int i;
for (i=numsectors; --i>=0; ) // Initially make all slots empty.
sectors[i].firsttag = -1;
for (i=numsectors; --i>=0; ) // Proceed from last to first sector
{ // so that lower sectors appear first
int j = (unsigned) sectors[i].tag % (unsigned) numsectors; // Hash func
sectors[i].nexttag = sectors[j].firsttag; // Prepend sector to chain
sectors[j].firsttag = i;
}
// killough 4/17/98: same thing, only for linedefs
for (i=numlines; --i>=0; ) // Initially make all slots empty.
lines[i].firsttag = -1;
for (i=numlines; --i>=0; ) // Proceed from last to first linedef
{ // so that lower linedefs appear first
int j = (unsigned) lines[i].tag % (unsigned) numlines; // Hash func
lines[i].nexttag = lines[j].firsttag; // Prepend linedef to chain
lines[j].firsttag = i;
}
}
//
// P_FindMinSurroundingLight()
//
// Passed a sector and a light level, returns the smallest light level
// in a surrounding sector less than that passed. If no smaller light
// level exists, the light level passed is returned.
//
// killough 11/98: reformatted
int P_FindMinSurroundingLight(sector_t *sector, int min)
{
const sector_t *check;
int i;
for (i=0; i < sector->linecount; i++)
if ((check = getNextSector(sector->lines[i], sector)) &&
check->lightlevel < min)
min = check->lightlevel;
return min;
}
//
// P_CanUnlockGenDoor()
//
// Passed a generalized locked door linedef and a player, returns whether
// the player has the keys necessary to unlock that door.
//
// Note: The linedef passed MUST be a generalized locked door type
// or results are undefined.
//
// jff 02/05/98 routine added to test for unlockability of
// generalized locked doors
//
// killough 11/98: reformatted
boolean P_CanUnlockGenDoor(line_t *line, player_t *player)
{
// does this line special distinguish between skulls and keys?
int skulliscard = (line->special & LockedNKeys)>>LockedNKeysShift;
// determine for each case of lock type if player's keys are adequate
switch((line->special & LockedKey)>>LockedKeyShift)
{
case AnyKey:
if (!player->cards[it_redcard] &&
!player->cards[it_redskull] &&
!player->cards[it_bluecard] &&
!player->cards[it_blueskull] &&
!player->cards[it_yellowcard] &&
!player->cards[it_yellowskull])
{
player->message = s_PD_ANY; // Ty 03/27/98 - externalized
S_StartSound(player->mo,sfx_oof); // killough 3/20/98
return false;
}
break;
case RCard:
if (!player->cards[it_redcard] &&
(!skulliscard || !player->cards[it_redskull]))
{
player->message = skulliscard? s_PD_REDK : s_PD_REDC; // Ty 03/27/98 - externalized
S_StartSound(player->mo,sfx_oof); // killough 3/20/98
return false;
}
break;
case BCard:
if (!player->cards[it_bluecard] &&
(!skulliscard || !player->cards[it_blueskull]))
{
player->message = skulliscard? s_PD_BLUEK : s_PD_BLUEC; // Ty 03/27/98 - externalized
S_StartSound(player->mo,sfx_oof); // killough 3/20/98
return false;
}
break;
case YCard:
if (!player->cards[it_yellowcard] &&
(!skulliscard || !player->cards[it_yellowskull]))
{
player->message = skulliscard? s_PD_YELLOWK : s_PD_YELLOWC; // Ty 03/27/98 - externalized
S_StartSound(player->mo,sfx_oof); // killough 3/20/98
return false;
}
break;
case RSkull:
if (!player->cards[it_redskull] &&
(!skulliscard || !player->cards[it_redcard]))
{
player->message = skulliscard? s_PD_REDK : s_PD_REDS; // Ty 03/27/98 - externalized
S_StartSound(player->mo,sfx_oof); // killough 3/20/98
return false;
}
break;
case BSkull:
if (!player->cards[it_blueskull] &&
(!skulliscard || !player->cards[it_bluecard]))
{
player->message = skulliscard? s_PD_BLUEK : s_PD_BLUES; // Ty 03/27/98 - externalized
S_StartSound(player->mo,sfx_oof); // killough 3/20/98
return false;
}
break;
case YSkull:
if (!player->cards[it_yellowskull] &&
(!skulliscard || !player->cards[it_yellowcard]))
{
player->message = skulliscard? s_PD_YELLOWK : s_PD_YELLOWS; // Ty 03/27/98 - externalized
S_StartSound(player->mo,sfx_oof); // killough 3/20/98
return false;
}
break;
case AllKeys:
if (!skulliscard &&
(!player->cards[it_redcard] ||
!player->cards[it_redskull] ||
!player->cards[it_bluecard] ||
!player->cards[it_blueskull] ||
!player->cards[it_yellowcard] ||
!player->cards[it_yellowskull]))
{
player->message = s_PD_ALL6; // Ty 03/27/98 - externalized
S_StartSound(player->mo,sfx_oof); // killough 3/20/98
return false;
}
if (skulliscard &&
(!(player->cards[it_redcard] | player->cards[it_redskull]) ||
!(player->cards[it_bluecard] | player->cards[it_blueskull]) ||
// [FG] 3-key door works with only 2 keys
// http://prboom.sourceforge.net/mbf-bugs.html
!(player->cards[it_yellowcard] | (demo_version == 203 ? !player->cards[it_yellowskull] : player->cards[it_yellowskull]))))
{
player->message = s_PD_ALL3; // Ty 03/27/98 - externalized
S_StartSound(player->mo,sfx_oof); // killough 3/20/98
return false;
}
break;
}
return true;
}
//
// P_SectorActive()
//
// Passed a linedef special class (floor, ceiling, lighting) and a sector
// returns whether the sector is already busy with a linedef special of the
// same class. If old demo compatibility true, all linedef special classes
// are the same.
//
// jff 2/23/98 added to prevent old demos from
// succeeding in starting multiple specials on one sector
//
// killough 11/98: reformatted
int P_SectorActive(special_e t,sector_t *sec)
{
return demo_compatibility ? // return whether any thinker is active
sec->floordata || sec->ceilingdata || sec->lightingdata :
t == floor_special ? !!sec->floordata : // return whether
t == ceiling_special ? !!sec->ceilingdata : // thinker of same
t == lighting_special ? !!sec->lightingdata : // type is active
1; // don't know which special, must be active, shouldn't be here
}
//
// P_CheckTag()
//
// Passed a line, returns true if the tag is non-zero or the line special
// allows no tag without harm. If compatibility, all linedef specials are
// allowed to have zero tag.
//
// Note: Only line specials activated by walkover, pushing, or shooting are
// checked by this routine.
//
// jff 2/27/98 Added to check for zero tag allowed for regular special types
int P_CheckTag(line_t *line)
{
// killough 11/98: compatibility option:
if (comp[comp_zerotags] || line->tag)
return 1;
switch (line->special)
{
case 1: // Manual door specials
case 26:
case 27:
case 28:
case 31:
case 32:
case 33:
case 34:
case 117:
case 118:
case 139: // Lighting specials
case 170:
case 79:
case 35:
case 138:
case 171:
case 81:
case 13:
case 192:
case 169:
case 80:
case 12:
case 194:
case 173:
case 157:
case 104:
case 193:
case 172:
case 156:
case 17:
case 195: // Thing teleporters
case 174:
case 97:
case 39:
case 126:
case 125:
case 210:
case 209:
case 208:
case 207:
case 11: // Exits
case 52:
case 197:
case 51:
case 124:
case 198:
case 48: // Scrolling walls
case 85:
return 1;
}
return 0;
}
//
// P_IsSecret()
//
// Passed a sector, returns if the sector secret type is still active, i.e.
// secret type is set and the secret has not yet been obtained.
//
// jff 3/14/98 added to simplify checks for whether sector is secret
// in automap and other places
//
boolean P_IsSecret(sector_t *sec)
{
return sec->special == 9 || sec->special & SECRET_MASK;
}
//
// P_WasSecret()
//
// Passed a sector, returns if the sector secret type is was active, i.e.
// secret type was set and the secret has been obtained already.
//
// jff 3/14/98 added to simplify checks for whether sector is secret
// in automap and other places
//
boolean P_WasSecret(sector_t *sec)
{
return sec->oldspecial == 9 || sec->oldspecial & SECRET_MASK;
}
//////////////////////////////////////////////////////////////////////////
//
// Events
//
// Events are operations triggered by using, crossing,
// or shooting special lines, or by timed thinkers.
//
/////////////////////////////////////////////////////////////////////////
//
// P_CrossSpecialLine - Walkover Trigger Dispatcher
//
// Called every time a thing origin is about
// to cross a line with a non 0 special, whether a walkover type or not.
//
// jff 02/12/98 all W1 lines were fixed to check the result from the EV_
// function before clearing the special. This avoids losing the function
// of the line, should the sector already be active when the line is
// crossed. Change is qualified by demo_compatibility.
//
// killough 11/98: change linenum parameter to a line_t pointer
void P_CrossSpecialLine(line_t *line, int side, mobj_t *thing, boolean bossaction)
{
int ok;
// Things that should never trigger lines
if (!thing->player && !bossaction)
switch(thing->type) // Things that should NOT trigger specials...
{
case MT_ROCKET:
case MT_PLASMA:
case MT_BFG:
case MT_TROOPSHOT:
case MT_HEADSHOT:
case MT_BRUISERSHOT:
case MT_PLASMA1: // killough 8/28/98: exclude beta fireballs
case MT_PLASMA2:
return;
default:
break;