/
specials.cpp
1396 lines (1233 loc) · 39.7 KB
/
specials.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
//-----------------------------------------------------------------------------
//
// Copyright 1993-1996 id Software
// Copyright 1994-1996 Raven Software
// Copyright 1998-1998 Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
// Copyright 1999-2016 Randy Heit
// Copyright 2002-2016 Christoph Oelckers
//
// 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 3 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, see http://www.gnu.org/licenses/
//
//-----------------------------------------------------------------------------
//
// DESCRIPTION:
// Implements special effects:
// Texture animation, height or lighting changes
// according to adjacent sectors, respective
// utility functions, etc.
// Line Tag handling. Line and Sector triggers.
// Implements donut linedef triggers
// Initializes and implements BOOM linedef triggers for
// Scrollers/Conveyors
// Friction
// Wind/Current
//
//-----------------------------------------------------------------------------
/* For code that originates from ZDoom the following applies:
**
**---------------------------------------------------------------------------
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**---------------------------------------------------------------------------
**
*/
#include <stdlib.h>
#include "templates.h"
#include "doomdef.h"
#include "doomstat.h"
#include "d_event.h"
#include "g_level.h"
#include "gstrings.h"
#include "events.h"
#include "m_random.h"
#include "p_local.h"
#include "p_spec.h"
#include "p_blockmap.h"
#include "p_lnspec.h"
#include "p_terrain.h"
#include "p_acs.h"
#include "p_3dmidtex.h"
#include "g_game.h"
#include "a_sharedglobal.h"
#include "a_keys.h"
#include "c_dispatch.h"
#include "r_sky.h"
#include "d_player.h"
#include "g_levellocals.h"
#include "actorinlines.h"
#include "vm.h"
#include "p_setup.h"
#include "c_console.h"
#include "p_spec_thinkers.h"
#include "maploader/maploader.h"
EXTERN_CVAR(Bool, forcewater)
//-----------------------------------------------------------------------------
//
// Portals
//
//-----------------------------------------------------------------------------
//============================================================================
//
// Spawns a single line portal
//
//============================================================================
void MapLoader::SpawnLinePortal(line_t* line)
{
// portal destination is special argument #0
line_t* dst = nullptr;
if (line->args[2] >= PORTT_VISUAL && line->args[2] <= PORTT_LINKED)
{
dst = Level->FindPortalDestination(line, line->args[0]);
line->portalindex = Level->linePortals.Reserve(1);
FLinePortal *port = &Level->linePortals.Last();
memset(port, 0, sizeof(FLinePortal));
port->mOrigin = line;
port->mDestination = dst;
port->mType = uint8_t(line->args[2]); // range check is done above.
if (port->mType == PORTT_LINKED)
{
// Linked portals have no z-offset ever.
port->mAlign = PORG_ABSOLUTE;
}
else
{
port->mAlign = uint8_t(line->args[3] >= PORG_ABSOLUTE && line->args[3] <= PORG_CEILING ? line->args[3] : PORG_ABSOLUTE);
if (port->mType == PORTT_INTERACTIVE && port->mAlign != PORG_ABSOLUTE)
{
// Due to the way z is often handled, these pose a major issue for parts of the code that needs to transparently handle interactive portals.
Printf(TEXTCOLOR_RED "Warning: z-offsetting not allowed for interactive portals. Changing line %d to teleport-portal!\n", line->Index());
port->mType = PORTT_TELEPORT;
}
}
port->mDefFlags = port->mType == PORTT_VISUAL ? PORTF_VISIBLE :
port->mType == PORTT_TELEPORT ? PORTF_TYPETELEPORT :
PORTF_TYPEINTERACTIVE;
}
else if (line->args[2] == PORTT_LINKEDEE && line->args[0] == 0)
{
// EE-style portals require that the first line ID is identical and the first arg of the two linked linedefs are 0 and 1 respectively.
int mytag = Level->GetFirstLineId(line);
for (auto &ln : Level->lines)
{
if (Level->GetFirstLineId(&ln) == mytag && ln.args[0] == 1 && ln.special == Line_SetPortal)
{
line->portalindex = Level->linePortals.Reserve(1);
FLinePortal *port = &Level->linePortals.Last();
memset(port, 0, sizeof(FLinePortal));
port->mOrigin = line;
port->mDestination = &ln;
port->mType = PORTT_LINKED;
port->mAlign = PORG_ABSOLUTE;
port->mDefFlags = PORTF_TYPEINTERACTIVE;
// we need to create the backlink here, too.
ln.portalindex = Level->linePortals.Reserve(1);
port = &Level->linePortals.Last();
memset(port, 0, sizeof(FLinePortal));
port->mOrigin = &ln;
port->mDestination = line;
port->mType = PORTT_LINKED;
port->mAlign = PORG_ABSOLUTE;
port->mDefFlags = PORTF_TYPEINTERACTIVE;
}
}
}
else
{
// undefined type
return;
}
}
//-----------------------------------------------------------------------------
//
// Lower stacks go in the bottom sector.
//
//-----------------------------------------------------------------------------
void MapLoader::SetupFloorPortal (AActor *point)
{
auto it = Level->GetActorIterator(NAME_LowerStackLookOnly, point->tid);
sector_t *Sector = point->Sector;
auto skyv = it.Next();
if (skyv != nullptr)
{
skyv->target = point;
if (Sector->GetAlpha(sector_t::floor) == 1.)
Sector->SetAlpha(sector_t::floor, clamp(point->args[0], 0, 255) / 255.);
Sector->Portals[sector_t::floor] = Level->GetStackPortal(skyv, sector_t::floor);
}
}
//-----------------------------------------------------------------------------
//
// Upper stacks go in the top sector.
//
//-----------------------------------------------------------------------------
void MapLoader::SetupCeilingPortal (AActor *point)
{
auto it = Level->GetActorIterator(NAME_UpperStackLookOnly, point->tid);
sector_t *Sector = point->Sector;
auto skyv = it.Next();
if (skyv != nullptr)
{
skyv->target = point;
if (Sector->GetAlpha(sector_t::ceiling) == 1.)
Sector->SetAlpha(sector_t::ceiling, clamp(point->args[0], 0, 255) / 255.);
Sector->Portals[sector_t::ceiling] = Level->GetStackPortal(skyv, sector_t::ceiling);
}
}
//-----------------------------------------------------------------------------
//
//
//
//-----------------------------------------------------------------------------
void MapLoader::SetupPortals()
{
auto it = Level->GetThinkerIterator<AActor>(NAME_StackPoint);
AActor *pt;
TArray<AActor *> points;
while ((pt = it.Next()))
{
FName nm = pt->GetClass()->TypeName;
if (nm == NAME_UpperStackLookOnly)
{
SetupFloorPortal(pt);
}
else if (nm == NAME_LowerStackLookOnly)
{
SetupCeilingPortal(pt);
}
pt->special1 = 0;
points.Push(pt);
}
// the semantics here are incredibly lax so the final setup can only be done once all portals have been created,
// because later stackpoints will happily overwrite info in older ones, if there are multiple links.
for (auto &s : Level->sectorPortals)
{
if (s.mType == PORTS_STACKEDSECTORTHING && s.mSkybox)
{
for (auto &ss : Level->sectorPortals)
{
if (ss.mType == PORTS_STACKEDSECTORTHING && ss.mSkybox == s.mSkybox->target)
{
s.mPartner = unsigned((&ss) - &Level->sectorPortals[0]);
}
}
}
}
// Now we can finally set the displacement and delete the stackpoint reference.
for (auto &s : Level->sectorPortals)
{
if (s.mType == PORTS_STACKEDSECTORTHING && s.mSkybox)
{
s.mDisplacement = s.mSkybox->Pos() - s.mSkybox->target->Pos();
s.mSkybox = nullptr;
}
}
}
//-----------------------------------------------------------------------------
//
//
//
//-----------------------------------------------------------------------------
void MapLoader::SetPortal(sector_t *sector, int plane, unsigned pnum, double alpha)
{
// plane: 0=floor, 1=ceiling, 2=both
if (plane > 0)
{
if (sector->GetPortalType(sector_t::ceiling) == PORTS_SKYVIEWPOINT)
{
sector->Portals[sector_t::ceiling] = pnum;
if (sector->GetAlpha(sector_t::ceiling) == 1.)
sector->SetAlpha(sector_t::ceiling, alpha);
if (Level->sectorPortals[pnum].mFlags & PORTSF_SKYFLATONLY)
sector->SetTexture(sector_t::ceiling, skyflatnum);
}
}
if (plane == 2 || plane == 0)
{
if (sector->GetPortalType(sector_t::floor) == PORTS_SKYVIEWPOINT)
{
sector->Portals[sector_t::floor] = pnum;
}
if (sector->GetAlpha(sector_t::floor) == 1.)
sector->SetAlpha(sector_t::floor, alpha);
if (Level->sectorPortals[pnum].mFlags & PORTSF_SKYFLATONLY)
sector->SetTexture(sector_t::floor, skyflatnum);
}
}
//-----------------------------------------------------------------------------
//
//
//
//-----------------------------------------------------------------------------
void MapLoader::CopyPortal(int sectortag, int plane, unsigned pnum, double alpha, bool tolines)
{
int s;
auto itr = Level->GetSectorTagIterator(sectortag);
while ((s = itr.Next()) >= 0)
{
SetPortal(&Level->sectors[s], plane, pnum, alpha);
}
for (auto &line : Level->lines)
{
// Check if this portal needs to be copied to other sectors
// This must be done here to ensure that it gets done only after the portal is set up
if (line.special == Sector_SetPortal &&
line.args[1] == 1 &&
(line.args[2] == plane || line.args[2] == 3) &&
line.args[3] == sectortag)
{
if (line.args[0] == 0)
{
SetPortal(line.frontsector, plane, pnum, alpha);
}
else
{
auto itr = Level->GetSectorTagIterator(line.args[0]);
while ((s = itr.Next()) >= 0)
{
SetPortal(&Level->sectors[s], plane, pnum, alpha);
}
}
}
if (tolines && line.special == Sector_SetPortal &&
line.args[1] == 5 &&
line.args[3] == sectortag)
{
if (line.args[0] == 0)
{
line.portaltransferred = pnum;
}
else
{
auto itr = Level->GetLineIdIterator(line.args[0]);
while ((s = itr.Next()) >= 0)
{
Level->lines[s].portaltransferred = pnum;
}
}
}
}
}
//-----------------------------------------------------------------------------
//
//
//
//-----------------------------------------------------------------------------
void MapLoader::SpawnPortal(line_t *line, int sectortag, int plane, int bytealpha, int linked)
{
if (plane < 0 || plane > 2 || (linked && plane == 2)) return;
for (auto &oline : Level->lines)
{
// We must look for the reference line with a linear search unless we want to waste the line ID for it
// which is not a good idea.
if (oline.special == Sector_SetPortal &&
oline.args[0] == sectortag &&
oline.args[1] == linked &&
oline.args[2] == plane &&
oline.args[3] == 1)
{
// beware of overflows.
DVector2 pos1 = line->v1->fPos() + line->Delta() / 2;
DVector2 pos2 = oline.v1->fPos() + oline.Delta() / 2;
unsigned pnum = Level->GetPortal(linked ? PORTS_LINKEDPORTAL : PORTS_PORTAL, plane, line->frontsector, oline.frontsector, pos2 - pos1);
CopyPortal(sectortag, plane, pnum, bytealpha / 255., false);
return;
}
}
}
//-----------------------------------------------------------------------------
//
// This searches the viewpoint's sector
// for a skybox line special, gets its tag and transfers the skybox to all tagged sectors.
//
//-----------------------------------------------------------------------------
void MapLoader::SpawnSkybox(AActor *origin)
{
sector_t *Sector = origin->Sector;
if (Sector == NULL)
{
Printf("Sector not initialized for SkyCamCompat\n");
origin->Sector = Sector = Level->PointInSector(origin->Pos());
}
if (Sector)
{
for(auto refline : Sector->Lines)
{
if (refline->special == Sector_SetPortal && refline->args[1] == 2)
{
// We found the setup linedef for this skybox, so let's use it for our init.
unsigned pnum = Level->GetSkyboxPortal(origin);
CopyPortal(refline->args[0], refline->args[2], pnum, 0, true);
return;
}
}
}
}
//-----------------------------------------------------------------------------
//
// P_SetSectorDamage
//
// Sets damage properties for one sector. Allows combination of original specials with explicit use of the damage properties
//
//-----------------------------------------------------------------------------
static void SetupSectorDamage(sector_t *sector, int damage, int interval, int leakchance, FName type, int flags)
{
// Only set if damage is not yet initialized. This ensures that UDMF takes precedence over sector specials.
if (sector->damageamount == 0)
{
sector->damageamount = damage;
sector->damageinterval = MAX(1, interval);
sector->leakydamage = leakchance;
sector->damagetype = type;
sector->Flags = (sector->Flags & ~SECF_DAMAGEFLAGS) | (flags & SECF_DAMAGEFLAGS);
}
}
//-----------------------------------------------------------------------------
//
// P_InitSectorSpecial
//
// Sets up everything derived from 'sector->special' for one sector
// ('fromload' is necessary to allow conversion upon savegame load.)
//
//-----------------------------------------------------------------------------
void MapLoader::InitSectorSpecial(sector_t *sector, int special)
{
// [RH] All secret sectors are marked with a BOOM-ish bitfield
if (sector->special & SECRET_MASK)
{
sector->Flags |= SECF_SECRET | SECF_WASSECRET;
Level->total_secrets++;
}
if (sector->special & FRICTION_MASK)
{
sector->Flags |= SECF_FRICTION;
}
if (sector->special & PUSH_MASK)
{
sector->Flags |= SECF_PUSH;
}
if ((sector->special & DAMAGE_MASK) == 0x100)
{
SetupSectorDamage(sector, 5, 32, 0, NAME_Fire, 0);
}
else if ((sector->special & DAMAGE_MASK) == 0x200)
{
SetupSectorDamage(sector, 10, 32, 0, NAME_Slime, 0);
}
else if ((sector->special & DAMAGE_MASK) == 0x300)
{
SetupSectorDamage(sector, 20, 32, 5, NAME_Slime, 0);
}
sector->special &= 0xff;
// [RH] Normal DOOM special or BOOM specialized?
bool keepspecial = false;
SpawnLights(sector);
switch (sector->special)
{
case dLight_Strobe_Hurt:
SetupSectorDamage(sector, 20, 32, 5, NAME_Slime, 0);
break;
case dDamage_Hellslime:
SetupSectorDamage(sector, 10, 32, 0, NAME_Slime, 0);
break;
case dDamage_Nukage:
SetupSectorDamage(sector, 5, 32, 0, NAME_Slime, 0);
break;
case dSector_DoorCloseIn30:
Level->CreateThinker<DDoor>(sector, DDoor::doorWaitClose, 2, 0, 0, 30 * TICRATE);
break;
case dDamage_End:
SetupSectorDamage(sector, 20, 32, 256, NAME_None, SECF_ENDGODMODE|SECF_ENDLEVEL);
break;
case dSector_DoorRaiseIn5Mins:
Level->CreateThinker<DDoor> (sector, DDoor::doorWaitRaise, 2, TICRATE*30/7, 0, 5*60*TICRATE);
break;
case dFriction_Low:
sector->friction = FRICTION_LOW;
sector->movefactor = 0x269/65536.;
sector->Flags |= SECF_FRICTION;
break;
case dDamage_SuperHellslime:
SetupSectorDamage(sector, 20, 32, 5, NAME_Slime, 0);
break;
case dDamage_LavaWimpy:
SetupSectorDamage(sector, 5, 16, 256, NAME_Fire, SECF_DMGTERRAINFX);
break;
case dDamage_LavaHefty:
SetupSectorDamage(sector, 8, 16, 256, NAME_Fire, SECF_DMGTERRAINFX);
break;
case dScroll_EastLavaDamage:
SetupSectorDamage(sector, 5, 16, 256, NAME_Fire, SECF_DMGTERRAINFX);
CreateScroller(EScroll::sc_floor, -4., 0, sector, 0);
keepspecial = true;
break;
case hDamage_Sludge:
SetupSectorDamage(sector, 4, 32, 0, NAME_Slime, 0);
break;
case sLight_Strobe_Hurt:
SetupSectorDamage(sector, 5, 32, 0, NAME_Slime, 0);
break;
case sDamage_Hellslime:
SetupSectorDamage(sector, 2, 32, 0, NAME_Slime, SECF_HAZARD);
break;
case Damage_InstantDeath:
// Strife's instant death sector
SetupSectorDamage(sector, TELEFRAG_DAMAGE, 1, 256, NAME_InstantDeath, 0);
break;
case sDamage_SuperHellslime:
SetupSectorDamage(sector, 4, 32, 0, NAME_Slime, SECF_HAZARD);
break;
case Sector_Hidden:
sector->MoreFlags |= SECMF_HIDDEN;
break;
case Sector_Heal:
// CoD's healing sector
SetupSectorDamage(sector, -1, 32, 0, NAME_None, 0);
break;
case Sky2:
sector->sky = PL_SKYFLAT;
break;
default:
if (sector->special >= Scroll_North_Slow && sector->special <= Scroll_SouthWest_Fast)
{ // Hexen scroll special
static const int8_t hexenScrollies[24][2] =
{
{ 0, 1 }, { 0, 2 }, { 0, 4 },
{ -1, 0 }, { -2, 0 }, { -4, 0 },
{ 0, -1 }, { 0, -2 }, { 0, -4 },
{ 1, 0 }, { 2, 0 }, { 4, 0 },
{ 1, 1 }, { 2, 2 }, { 4, 4 },
{ -1, 1 }, { -2, 2 }, { -4, 4 },
{ -1, -1 }, { -2, -2 }, { -4, -4 },
{ 1, -1 }, { 2, -2 }, { 4, -4 }
};
int i = sector->special - Scroll_North_Slow;
double dx = hexenScrollies[i][0] / 2.;
double dy = hexenScrollies[i][1] / 2.;
CreateScroller(EScroll::sc_floor, dx, dy, sector, 0);
}
else if (sector->special >= Carry_East5 && sector->special <= Carry_East35)
{
// Heretic scroll special
// Only east scrollers also scroll the texture
CreateScroller(EScroll::sc_floor, -0.5 * (1 << ((sector->special & 0xff) - Carry_East5)), 0, sector, 0);
}
keepspecial = true;
break;
}
if (!keepspecial) sector->special = 0;
}
//-----------------------------------------------------------------------------
//
// P_SpawnSpecials
//
// After the map has been loaded, scan for specials that spawn thinkers
//
//-----------------------------------------------------------------------------
void MapLoader::SpawnSpecials ()
{
SetupPortals();
for (auto &sec : Level->sectors)
{
if (sec.special == 0)
continue;
InitSectorSpecial(&sec, sec.special);
}
ProcessEDSectors();
// Init other misc stuff
SpawnScrollers(); // killough 3/7/98: Add generalized scrollers
SpawnFriction(); // phares 3/12/98: New friction model using linedefs
SpawnPushers(); // phares 3/20/98: New pusher model using linedefs
auto it2 = Level->GetThinkerIterator<AActor>(NAME_SkyCamCompat);
AActor *pt2;
while ((pt2 = it2.Next()))
{
SpawnSkybox(pt2);
}
for (auto &line : Level->lines)
{
switch (line.special)
{
int s;
sector_t *sec;
// killough 3/7/98:
// support for drawn heights coming from different sector
case Transfer_Heights:
{
sec = line.frontsector;
if (line.args[1] & 2)
{
sec->MoreFlags |= SECMF_FAKEFLOORONLY;
}
if (line.args[1] & 4)
{
sec->MoreFlags |= SECMF_CLIPFAKEPLANES;
}
if (line.args[1] & 8)
{
sec->MoreFlags |= SECMF_UNDERWATER;
}
else if (forcewater)
{
sec->MoreFlags |= SECMF_FORCEDUNDERWATER;
}
if (line.args[1] & 16)
{
sec->MoreFlags |= SECMF_IGNOREHEIGHTSEC;
}
else Level->HasHeightSecs = true;
if (line.args[1] & 32)
{
sec->MoreFlags |= SECMF_NOFAKELIGHT;
}
auto itr = Level->GetSectorTagIterator(line.args[0]);
while ((s = itr.Next()) >= 0)
{
Level->sectors[s].heightsec = sec;
sec->e->FakeFloor.Sectors.Push(&Level->sectors[s]);
Level->sectors[s].MoreFlags |= (sec->MoreFlags & SECMF_IGNOREHEIGHTSEC); // copy this to the destination sector for easier checking.
Level->sectors[s].AdjustFloorClip();
}
break;
}
// killough 3/16/98: Add support for setting
// floor lighting independently (e.g. lava)
case Transfer_FloorLight:
Level->CreateThinker<DLightTransfer> (line.frontsector, line.args[0], true);
break;
// killough 4/11/98: Add support for setting
// ceiling lighting independently
case Transfer_CeilingLight:
Level->CreateThinker<DLightTransfer> (line.frontsector, line.args[0], false);
break;
// [Graf Zahl] Add support for setting lighting
// per wall independently
case Transfer_WallLight:
Level->CreateThinker<DWallLightTransfer> (line.frontsector, line.args[0], line.args[1]);
break;
case Sector_Attach3dMidtex:
P_Attach3dMidtexLinesToSector(line.frontsector, line.args[0], line.args[1], !!line.args[2]);
break;
case Sector_SetLink:
if (line.args[0] == 0)
{
P_AddSectorLinks(line.frontsector, line.args[1], line.args[2], line.args[3]);
}
break;
case Sector_SetPortal:
// arg 0 = sector tag
// arg 1 = type
// - 0: normal (handled here)
// - 1: copy (handled by the portal they copy)
// - 2: EE-style skybox (handled by the camera object)
// - 3: EE-style flat portal (GZDoom HW renderer only for now)
// - 4: EE-style horizon portal (GZDoom HW renderer only for now)
// - 5: copy portal to line (GZDoom HW renderer only for now)
// - 6: linked portal
// other values reserved for later use
// arg 2 = 0:floor, 1:ceiling, 2:both
// arg 3 = 0: anchor, 1: reference line
// arg 4 = for the anchor only: alpha
if ((line.args[1] == 0 || line.args[1] == 6) && line.args[3] == 0)
{
SpawnPortal(&line, line.args[0], line.args[2], line.args[4], line.args[1]);
}
else if (line.args[1] == 3 || line.args[1] == 4)
{
unsigned pnum = Level->GetPortal(line.args[1] == 3 ? PORTS_PLANE : PORTS_HORIZON, line.args[2], line.frontsector, NULL, { 0,0 });
CopyPortal(line.args[0], line.args[2], pnum, 0, true);
}
break;
case Line_SetPortal:
SpawnLinePortal(&line);
break;
// [RH] ZDoom Static_Init settings
case Static_Init:
switch (line.args[1])
{
case Init_Gravity:
{
double grav = line.Delta().Length() / 100.;
auto itr = Level->GetSectorTagIterator(line.args[0]);
while ((s = itr.Next()) >= 0)
Level->sectors[s].gravity = grav;
}
break;
//case Init_Color:
// handled in P_LoadSideDefs2()
case Init_Damage:
{
int damage = int(line.Delta().Length());
auto itr = Level->GetSectorTagIterator(line.args[0]);
while ((s = itr.Next()) >= 0)
{
sector_t *sec = &Level->sectors[s];
sec->damageamount = damage;
sec->damagetype = NAME_None;
if (sec->damageamount < 20)
{
sec->leakydamage = 0;
sec->damageinterval = 32;
}
else if (sec->damageamount < 50)
{
sec->leakydamage = 5;
sec->damageinterval = 32;
}
else
{
sec->leakydamage = 256;
sec->damageinterval = 1;
}
}
}
break;
case Init_SectorLink:
if (line.args[3] == 0)
P_AddSectorLinksByID(line.frontsector, line.args[0], line.args[2]);
break;
// killough 10/98:
//
// Support for sky textures being transferred from sidedefs.
// Allows scrolling and other effects (but if scrolling is
// used, then the same sector tag needs to be used for the
// sky sector, the sky-transfer linedef, and the scroll-effect
// linedef). Still requires user to use F_SKY1 for the floor
// or ceiling texture, to distinguish floor and ceiling sky.
case Init_TransferSky:
{
auto itr = Level->GetSectorTagIterator(line.args[0]);
while ((s = itr.Next()) >= 0)
Level->sectors[s].sky = (line.Index() + 1) | PL_SKYFLAT;
break;
}
}
break;
}
}
// [RH] Start running any open scripts on this map
Level->Behaviors.StartTypedScripts (SCRIPT_Open, NULL, false);
}
//-----------------------------------------------------------------------------
//
//
//
//-----------------------------------------------------------------------------
void MapLoader::SpawnFriction()
{
line_t *l = &Level->lines[0];
for (unsigned i = 0 ; i < Level->lines.Size() ; i++,l++)
{
if (l->special == Sector_SetFriction)
{
int length;
if (l->args[1])
{ // [RH] Allow setting friction amount from parameter
length = l->args[1] <= 200 ? l->args[1] : 200;
}
else
{
length = int(l->Delta().Length());
}
P_SetSectorFriction (Level, l->args[0], length, false);
l->special = 0;
}
}
}
//==========================================================================
//
// Creates all 3D floors defined by one linedef
//
//==========================================================================
int MapLoader::Set3DFloor(line_t * line, int param, int param2, int alpha)
{
int s;
int flags;
int tag = line->args[0];
sector_t * sec = line->frontsector, *ss;
auto itr = Level->GetSectorTagIterator(tag);
while ((s = itr.Next()) >= 0)
{
ss = &Level->sectors[s];
if (param == 0)
{
flags = FF_EXISTS | FF_RENDERALL | FF_SOLID | FF_INVERTSECTOR;
alpha = 255;
for (auto l: sec->Lines)
{
if (l->special == Sector_SetContents && l->frontsector == sec)
{
alpha = clamp<int>(l->args[1], 0, 100);
if (l->args[2] & 1) flags &= ~FF_SOLID;
if (l->args[2] & 2) flags |= FF_SEETHROUGH;
if (l->args[2] & 4) flags |= FF_SHOOTTHROUGH;
if (l->args[2] & 8) flags |= FF_ADDITIVETRANS;
if (alpha != 100) flags |= FF_TRANSLUCENT;//|FF_BOTHPLANES|FF_ALLSIDES;
if (l->args[0])
{
// Yes, Vavoom's 3D-floor definitions suck!
// The content list changed in r1783 of Vavoom to be unified
// among all its supported games, so it has now ten different
// values instead of just five.
static uint32_t vavoomcolors[] = { VC_EMPTY,
VC_WATER, VC_LAVA, VC_NUKAGE, VC_SLIME, VC_HELLSLIME,
VC_BLOOD, VC_SLUDGE, VC_HAZARD, VC_BOOMWATER };
flags |= FF_SWIMMABLE | FF_BOTHPLANES | FF_ALLSIDES | FF_FLOOD;
l->frontsector->Colormap.FadeColor = vavoomcolors[l->args[0]] & VC_COLORMASK;
l->frontsector->Colormap.FogDensity = 0;
}
alpha = (alpha * 255) / 100;
break;
}
}
}
else if (param == 4)
{
flags = FF_EXISTS | FF_RENDERPLANES | FF_INVERTPLANES | FF_NOSHADE | FF_FIX;
if (param2 & 1) flags |= FF_SEETHROUGH; // marker for allowing missing texture checks
alpha = 255;
}
else
{
static const int defflags[] = { 0,
FF_SOLID,
FF_SWIMMABLE | FF_BOTHPLANES | FF_ALLSIDES | FF_SHOOTTHROUGH | FF_SEETHROUGH,
FF_SHOOTTHROUGH | FF_SEETHROUGH,
};
flags = defflags[param & 3] | FF_EXISTS | FF_RENDERALL;
if (param & 4) flags |= FF_ALLSIDES | FF_BOTHPLANES;
if (param & 16) flags ^= FF_SEETHROUGH;
if (param & 32) flags ^= FF_SHOOTTHROUGH;
if (param2 & 1) flags |= FF_NOSHADE;
if (param2 & 2) flags |= FF_DOUBLESHADOW;
if (param2 & 4) flags |= FF_FOG;
if (param2 & 8) flags |= FF_THINFLOOR;
if (param2 & 16) flags |= FF_UPPERTEXTURE;
if (param2 & 32) flags |= FF_LOWERTEXTURE;
if (param2 & 64) flags |= FF_ADDITIVETRANS | FF_TRANSLUCENT;
// if flooding is used the floor must be non-solid and is automatically made shootthrough and seethrough
if ((param2 & 128) && !(flags & FF_SOLID)) flags |= FF_FLOOD | FF_SEETHROUGH | FF_SHOOTTHROUGH;
if (param2 & 512) flags |= FF_FADEWALLS;
if (param2&1024) flags |= FF_RESET;
FTextureID tex = line->sidedef[0]->GetTexture(side_t::top);
if (!tex.Exists() && alpha < 255)
{
alpha = -tex.GetIndex();
}
alpha = clamp(alpha, 0, 255);
if (alpha == 0) flags &= ~(FF_RENDERALL | FF_BOTHPLANES | FF_ALLSIDES);
else if (alpha != 255) flags |= FF_TRANSLUCENT;
}
P_Add3DFloor(ss, sec, line, flags, alpha);
}
// To be 100% safe this should be done even if the alpha by texture value isn't used.
if (!line->sidedef[0]->GetTexture(side_t::top).isValid())
line->sidedef[0]->SetTexture(side_t::top, FNullTextureID());
return 1;
}
//==========================================================================
//
// Spawns 3D floors
//
//==========================================================================
void MapLoader::Spawn3DFloors ()
{
static int flagvals[] = {512, 2+512, 512+1024};
for (auto &line : Level->lines)
{
switch(line.special)
{
case ExtraFloor_LightOnly:
if (line.args[1] < 0 || line.args[1] > 2) line.args[1] = 0;
if (line.args[0] != 0)
Set3DFloor(&line, 3, flagvals[line.args[1]], 0);
break;
case Sector_Set3DFloor:
// The flag high-byte/line id is only needed in Hexen format.
// UDMF can set both of these parameters without any restriction of the usable values.
// In Doom format the translators can take full integers for the tag and the line ID always is the same as the tag.
if (Level->maptype == MAPTYPE_HEXEN)
{
if (line.args[1]&8)
{
Level->tagManager.AddLineID(line.Index(), line.args[4]);
}
else
{
line.args[0]+=256*line.args[4];
line.args[4]=0;
}
}