-
Notifications
You must be signed in to change notification settings - Fork 88
/
p_spec.c
4265 lines (3787 loc) · 125 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++ -*-
*-----------------------------------------------------------------------------
*
*
* PrBoom: a Doom port merged with LxDoom and LSDLDoom
* based on BOOM, a modified and improved DOOM engine
* Copyright (C) 1999 by
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
* Copyright (C) 1999-2000 by
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
* Copyright 2005, 2006 by
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
*
* 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 "i_sound.h"
#include "m_bbox.h" // phares 3/20/98
#include "d_deh.h"
#include "r_plane.h"
#include "hu_stuff.h"
#include "lprintf.h"
#include "e6y.h"//e6y
#include "dsda.h"
#include "dsda/global.h"
//
// source animation definition
//
//
#ifdef _MSC_VER // proff: This is the same as __attribute__ ((packed)) in GNUC
#pragma pack(push)
#pragma pack(1)
#endif //_MSC_VER
#if defined(__MWERKS__)
#pragma options align=packed
#endif
typedef struct
{
signed char istexture; //jff 3/23/98 make char for comparison // cph - make signed
char endname[9]; // if false, it is a flat
char startname[9];
int speed;
} PACKEDATTR animdef_t; //jff 3/23/98 pack to read from memory
#if defined(__MWERKS__)
#pragma options align=reset
#endif
#ifdef _MSC_VER
#pragma pack(pop)
#endif //_MSC_VER
#define MAXANIMS 32 // no longer a strict limit -- killough
static anim_t* lastanim;
static anim_t* 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
static const animdef_t heretic_animdefs[] = {
// false = flat
// true = texture
{ false, "FLTWAWA3", "FLTWAWA1", 8 }, // Water
{ false, "FLTSLUD3", "FLTSLUD1", 8 }, // Sludge
{ false, "FLTTELE4", "FLTTELE1", 6 }, // Teleport
{ false, "FLTFLWW3", "FLTFLWW1", 9 }, // River - West
{ false, "FLTLAVA4", "FLTLAVA1", 8 }, // Lava
{ false, "FLATHUH4", "FLATHUH1", 8 }, // Super Lava
{ true, "LAVAFL3", "LAVAFL1", 6 }, // Texture: Lavaflow
{ true, "WATRWAL3", "WATRWAL1", 4 }, // Texture: Waterfall
{ -1 }
};
// heretic
#define MAXLINEANIMS 64*256
static short numlinespecials;
static line_t *linespeciallist[MAXLINEANIMS];
//e6y
void MarkAnimatedTextures(void)
{
#ifdef GL_DOOM
anim_t* anim;
anim_textures = calloc(numtextures, sizeof(TAnimItemParam));
anim_flats = calloc(numflats, sizeof(TAnimItemParam));
for (anim = anims ; anim < lastanim ; anim++)
{
int i;
for (i = 0; i < anim->numpics ; i++)
{
if (anim->istexture)
{
anim_textures[anim->basepic + i].anim = anim;
anim_textures[anim->basepic + i].index = i + 1;
}
else
{
anim_flats[anim->basepic + i].anim = anim;
anim_flats[anim->basepic + i].index = i + 1;
}
}
}
#endif // GL_DOOM
}
//
// 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;
const animdef_t *animdefs; //jff 3/23/98 pointer to animation lump
int lump = -1;
// Init animation
if (heretic)
{
animdefs = heretic_animdefs;
}
else
{
lump = W_GetNumForName("ANIMATED"); // cph - new wad lump handling
//jff 3/23/98 read from predefined or wad lump instead of table
animdefs = (const animdef_t *)W_CacheLumpNum(lump);
}
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 = LittleLong(animdefs[i].speed); // killough 5/5/98: add LONG()
lastanim++;
}
if (lump != -1) W_UnlockLumpNum(lump);
MarkAnimatedTextures();//e6y
}
///////////////////////////////////////////////////////////////
//
// 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
//
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
//
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
if (comp[comp_model])
{
if (!(line->flags & ML_TWOSIDED))
return NULL;
}
if (line->frontsector == sec) {
if (comp[comp_model] || line->backsector!=sec)
return line->backsector; //jff 5/3/98 don't retn sec unless compatibility
else // fixes an intra-sector line breaking functions
return NULL; // like floor->highest floor
}
return line->frontsector;
}
//
// P_FindLowestFloorSurrounding()
//
// Returns the fixed point value of the lowest floor height
// in the sector passed or its surrounding sectors.
//
fixed_t P_FindLowestFloorSurrounding(sector_t* sec)
{
int i;
line_t* check;
sector_t* other;
fixed_t floor = sec->floorheight;
for (i=0 ;i < sec->linecount ; i++)
{
check = sec->lines[i];
other = getNextSector(check,sec);
if (!other)
continue;
if (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
//
fixed_t P_FindHighestFloorSurrounding(sector_t *sec)
{
int i;
line_t* check;
sector_t* other;
fixed_t floor = -500*FRACUNIT;
//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++)
{
check = sec->lines[i];
other = getNextSector(check,sec);
if (!other)
continue;
if (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;
// e6y
// Original P_FindNextHighestFloor() is restored for demo_compatibility
// Adapted for prboom's complevels
if (demo_compatibility && !prboom_comp[PC_FORCE_BOOM_FINDNEXTHIGHESTFLOOR].state)
{
int h;
int min;
static int MAX_ADJOINING_SECTORS = 0;
static fixed_t *heightlist = NULL;
static int heightlist_size = 0;
line_t* check;
fixed_t height = currentheight;
static fixed_t last_height_0 = 0;
// 20 adjoining sectors max!
if (!MAX_ADJOINING_SECTORS)
MAX_ADJOINING_SECTORS = M_CheckParm("-doom95") ? 500 : 20;
if (sec->linecount > heightlist_size)
{
do
{
heightlist_size = heightlist_size ? heightlist_size * 2 : 128;
} while (sec->linecount > heightlist_size);
heightlist = realloc(heightlist, heightlist_size * sizeof(heightlist[0]));
}
for (i=0, h=0 ;i < sec->linecount ; i++)
{
check = sec->lines[i];
other = getNextSector(check,sec);
if (!other)
continue;
if (other->floorheight > height)
{
// e6y
// Emulation of stack overflow.
// 20: overflow affects nothing - just a luck;
// 21: can be emulated;
// 22..26: overflow affects saved registers - unpredictable behaviour, can crash;
// 27: overflow affects return address - crash with high probability;
if (compatibility_level < dosdoom_compatibility && h >= MAX_ADJOINING_SECTORS)
{
lprintf(LO_WARN, "P_FindNextHighestFloor: Overflow of heightlist[%d] array is detected.\n", MAX_ADJOINING_SECTORS);
lprintf(LO_WARN, " Sector %d, line %d, heightlist index %d: ", sec->iSectorID, sec->lines[i]->iLineID, h);
if (h == MAX_ADJOINING_SECTORS + 1)
height = other->floorheight;
if (h <= MAX_ADJOINING_SECTORS + 1)
lprintf(LO_WARN, "successfully emulated.\n");
else if (h <= MAX_ADJOINING_SECTORS + 6)
lprintf(LO_WARN, "cannot be emulated - unpredictable behaviour.\n");
else
lprintf(LO_WARN, "cannot be emulated - crash with high probability.\n");
}
heightlist[h++] = other->floorheight;
}
// Check for overflow. Warning.
if (compatibility_level >= dosdoom_compatibility && h >= MAX_ADJOINING_SECTORS)
{
lprintf( LO_WARN, "Sector with more than 20 adjoining sectors\n" );
break;
}
}
// Find lowest height in list
if (!h)
{
// cph - my guess at doom v1.2 - 1.4beta compatibility here.
// If there are no higher neighbouring sectors, Heretic just returned
// heightlist[0] (local variable), i.e. noise off the stack. 0 is right for
// RETURN01 E1M2, so let's take that.
//
// SmileTheory's response:
// It's not *quite* random stack noise. If this function is called
// as part of a loop, heightlist will be at the same location as in
// the previous call. Doing it this way fixes 1_ON_1.WAD.
return (compatibility_level < doom_1666_compatibility ? last_height_0 : currentheight);
}
last_height_0 = heightlist[0];
min = heightlist[0];
// Range checking?
for (i = 1;i < h;i++)
{
if (heightlist[i] < min)
min = heightlist[i];
}
return min;
}
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;
}
/* cph - my guess at doom v1.2 - 1.4beta compatibility here.
* If there are no higher neighbouring sectors, Heretic just returned
* heightlist[0] (local variable), i.e. noise off the stack. 0 is right for
* RETURN01 E1M2, so let's take that. */
return (compatibility_level < doom_1666_compatibility ? 0 : 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 INT_MAX is the return
//
fixed_t P_FindLowestCeilingSurrounding(sector_t* sec)
{
int i;
line_t* check;
sector_t* other;
fixed_t height = INT_MAX;
/* jff 3/12/98 avoid ovf in height calculations */
if (!comp[comp_model]) height = 32000*FRACUNIT;
for (i=0 ;i < sec->linecount ; i++)
{
check = sec->lines[i];
other = getNextSector(check,sec);
if (!other)
continue;
if (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
//
fixed_t P_FindHighestCeilingSurrounding(sector_t* sec)
{
int i;
line_t* check;
sector_t* other;
fixed_t height = 0;
/* jff 1/26/98 Fix initial value for floor to not act differently
* in sections of wad that are below 0 units
* jff 3/12/98 avoid ovf in height calculations */
if (!comp[comp_model]) height = -32000*FRACUNIT;
for (i=0 ;i < sec->linecount ; i++)
{
check = sec->lines[i];
other = getNextSector(check,sec);
if (!other)
continue;
if (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 INT_MAX is returned
//
// jff 02/03/98 Add routine to find shortest lower texture
//
fixed_t P_FindShortestTextureAround(int secnum)
{
int minsize = INT_MAX;
side_t* side;
int i;
sector_t *sec = §ors[secnum];
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))
{
side = getSide(secnum,i,0);
if (side->bottomtexture > 0) //jff 8/14/98 texture 0 is a placeholder
if (textureheight[side->bottomtexture] < minsize)
minsize = textureheight[side->bottomtexture];
side = getSide(secnum,i,1);
if (side->bottomtexture > 0) //jff 8/14/98 texture 0 is a placeholder
if (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 INT_MAX is returned
//
// jff 03/20/98 Add routine to find shortest upper texture
//
fixed_t P_FindShortestUpperAround(int secnum)
{
int minsize = INT_MAX;
side_t* side;
int i;
sector_t *sec = §ors[secnum];
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))
{
side = getSide(secnum,i,0);
if (side->toptexture > 0) //jff 8/14/98 texture 0 is a placeholder
if (textureheight[side->toptexture] < minsize)
minsize = textureheight[side->toptexture];
side = getSide(secnum,i,1);
if (side->toptexture > 0) //jff 8/14/98 texture 0 is a placeholder
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
//
sector_t *P_FindModelFloorSector(fixed_t floordestheight,int secnum)
{
int i;
sector_t *sec=NULL;
int linecount;
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
linecount = sec->linecount;
for (i = 0; i < (demo_compatibility && sec->linecount<linecount?
sec->linecount : linecount); i++)
{
if ( twoSided(secnum, i) )
{
if (getSide(secnum,i,0)->sector->iSectorID == secnum)
sec = getSector(secnum,i,1);
else
sec = getSector(secnum,i,0);
if (heretic || sec->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
//
sector_t *P_FindModelCeilingSector(fixed_t ceildestheight,int secnum)
{
int i;
sector_t *sec=NULL;
int linecount;
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
linecount = sec->linecount;
for (i = 0; i < (demo_compatibility && sec->linecount<linecount?
sec->linecount : linecount); i++)
{
if ( twoSided(secnum, i) )
{
if (getSide(secnum,i,0)->sector->iSectorID == secnum)
sec = getSector(secnum,i,1);
else
sec = getSector(secnum,i,0);
if (sec->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.
//
int P_FindMinSurroundingLight
( sector_t* sector,
int max )
{
int i;
int min;
line_t* line;
sector_t* check;
min = max;
for (i=0 ; i < sector->linecount ; i++)
{
line = sector->lines[i];
check = getNextSector(line,sector);
if (!check)
continue;
if (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
//
dboolean 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])