/
p_spec.cpp
1095 lines (900 loc) · 28.4 KB
/
p_spec.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
/**\file
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
*\author Copyright © 1999 Activision
*
* 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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include <cstring>
#include <cstdio>
#include "jhexen.h"
#include "dmu_lib.h"
#include "g_common.h"
#include "mapinfo.h"
#include "p_inventory.h"
#include "player.h"
#include "p_map.h"
#include "p_mapsetup.h"
#include "p_mapspec.h"
#include "p_ceiling.h"
#include "p_door.h"
#include "p_plat.h"
#include "p_floor.h"
#include "p_scroll.h"
#include "p_switch.h"
#include "p_user.h"
#include "polyobjs.h"
using namespace common;
#define LIGHTNING_SPECIAL 198
#define LIGHTNING_SPECIAL2 199
#define SKYCHANGE_SPECIAL 200
static void P_LightningFlash(void);
static dd_bool CheckedLockedDoor(mobj_t* mo, byte lock);
mobj_t lavaInflictor;
materialid_t sky1Material;
materialid_t sky2Material;
float sky1ColumnOffset;
float sky2ColumnOffset;
float sky1ScrollDelta;
float sky2ScrollDelta;
bool doubleSky;
static bool mapHasLightning;
static int nextLightningFlash;
static int lightningFlash;
static float *lightningLightLevels;
void P_InitLava(void)
{
memset(&lavaInflictor, 0, sizeof(mobj_t));
lavaInflictor.type = MT_CIRCLEFLAME;
lavaInflictor.flags2 = MF2_FIREDAMAGE | MF2_NODMGTHRUST;
}
void P_InitSky(de::Uri const &mapUri)
{
if(MapInfo const *mapInfo = P_MapInfo(mapUri))
{
sky1Material = Materials_ResolveUriCString(mapInfo->gets("sky1Material").toUtf8().constData());
sky2Material = Materials_ResolveUriCString(mapInfo->gets("sky2Material").toUtf8().constData());
sky1ScrollDelta = mapInfo->getd("sky1ScrollDelta");
sky2ScrollDelta = mapInfo->getd("sky2ScrollDelta");
doubleSky = mapInfo->getb("doubleSky");
}
sky1ColumnOffset = sky2ColumnOffset = 0;
if(!IS_DEDICATED)
{
int ival;
float fval;
// First disable all sky layers.
R_SkyParams(DD_SKY, DD_DISABLE, NULL);
// Sky2 is layer zero and Sky1 is layer one.
fval = 0;
R_SkyParams(0, DD_OFFSET, &fval);
R_SkyParams(1, DD_OFFSET, &fval);
if(doubleSky && sky2Material)
{
R_SkyParams(0, DD_ENABLE, NULL);
ival = DD_NO;
R_SkyParams(0, DD_MASK, &ival);
R_SkyParams(0, DD_MATERIAL, P_ToPtr(DMU_MATERIAL, sky2Material));
R_SkyParams(1, DD_ENABLE, NULL);
ival = DD_YES;
R_SkyParams(1, DD_MASK, &ival);
R_SkyParams(1, DD_MATERIAL, P_ToPtr(DMU_MATERIAL, sky1Material));
}
else
{
R_SkyParams(0, DD_ENABLE, NULL);
ival = DD_NO;
R_SkyParams(0, DD_MASK, &ival);
R_SkyParams(0, DD_MATERIAL, P_ToPtr(DMU_MATERIAL, sky1Material));
R_SkyParams(1, DD_DISABLE, NULL);
ival = DD_NO;
R_SkyParams(1, DD_MASK, &ival);
R_SkyParams(1, DD_MATERIAL, P_ToPtr(DMU_MATERIAL, sky2Material));
}
}
}
void P_AnimateSky(void)
{
// Update sky column offsets
sky1ColumnOffset += sky1ScrollDelta;
sky2ColumnOffset += sky2ScrollDelta;
if(!IS_DEDICATED)
{
R_SkyParams(1, DD_OFFSET, &sky1ColumnOffset);
R_SkyParams(0, DD_OFFSET, &sky2ColumnOffset);
}
}
dd_bool EV_SectorSoundChange(byte *args)
{
if(!args[0]) return false;
dd_bool result = false;
if(iterlist_t *list = P_GetSectorIterListForTag((int) args[0], false))
{
IterList_SetIteratorDirection(list, ITERLIST_FORWARD);
IterList_RewindIterator(list);
Sector *sec = 0;
while((sec = (Sector *)IterList_MoveIterator(list)))
{
P_ToXSector(sec)->seqType = seqtype_t(args[1]);
result = true;
}
}
return result;
}
static dd_bool CheckedLockedDoor(mobj_t *mo, byte lock)
{
DENG2_ASSERT(mo != 0);
if(!mo->player) return false;
if(!lock) return true;
if(!(mo->player->keys & (1 << (lock - 1))))
{
char LockedBuffer[80];
sprintf(LockedBuffer, "YOU NEED THE %s\n", GET_TXT(TextKeyMessages[lock - 1]));
P_SetMessage(mo->player, 0, LockedBuffer);
S_StartSound(SFX_DOOR_LOCKED, mo);
return false;
}
return true;
}
dd_bool EV_LineSearchForPuzzleItem(Line *line, byte * /*args*/, mobj_t *mo)
{
if(!mo || !mo->player || !line)
return false;
inventoryitemtype_t type = inventoryitemtype_t(IIT_FIRSTPUZZITEM + P_ToXLine(line)->arg1);
if(type < IIT_FIRSTPUZZITEM)
return false;
// Search player's inventory for puzzle items
return P_InventoryUse(mo->player - players, type, false);
}
static de::Uri mapUriFromLogicalNumber(int number)
{
if(!number) return gameMapUri; // current map.
return G_ComposeMapUri(::gameEpisode, number - 1);
}
dd_bool P_StartLockedACS(Line *line, byte *args, mobj_t *mo, int side)
{
DENG2_ASSERT(args != 0 && mo != 0);
if(!mo->player) return false;
if(int lock = args[4])
{
if(!(mo->player->keys & (1 << (lock - 1))))
{
char LockedBuffer[80];
sprintf(LockedBuffer, "YOU NEED THE %s\n", GET_TXT(TextKeyMessages[lock - 1]));
P_SetMessage(mo->player, 0, LockedBuffer);
S_StartSound(SFX_DOOR_LOCKED, mo);
return false;
}
}
byte newArgs[5];
for(int i = 0; i < 4; ++i)
{
newArgs[i] = args[i];
}
newArgs[4] = 0;
de::Uri mapUri = mapUriFromLogicalNumber(newArgs[1]);
return Game_ACScriptInterpreter().startScript(newArgs[0], &mapUri, &newArgs[2], mo, line, side);
}
dd_bool P_ExecuteLineSpecial(int special, byte args[5], Line *line, int side, mobj_t *mo)
{
dd_bool success = false;
App_Log(DE2_MAP_VERBOSE, "Executing line special %i, mobj:%i", special, mo? mo->thinker.id : 0);
switch(special)
{
case 1: // Poly Start Line
break;
case 2: // Poly Rotate Left
success = EV_RotatePoly(line, args, 1, false);
break;
case 3: // Poly Rotate Right
success = EV_RotatePoly(line, args, -1, false);
break;
case 4: // Poly Move
success = EV_MovePoly(line, args, false, false);
break;
case 5: // Poly Explicit Line: Only used in initialization
break;
case 6: // Poly Move Times 8
success = EV_MovePoly(line, args, true, false);
break;
case 7: // Poly Door Swing
success = EV_OpenPolyDoor(line, args, PODOOR_SWING);
break;
case 8: // Poly Door Slide
success = EV_OpenPolyDoor(line, args, PODOOR_SLIDE);
break;
case 10: // Door Close
success = EV_DoDoor(line, args, DT_CLOSE);
break;
case 11: // Door Open
if(!args[0])
{
success = EV_VerticalDoor(line, mo);
}
else
{
success = EV_DoDoor(line, args, DT_OPEN);
}
break;
case 12: // Door Raise
if(!args[0])
{
success = EV_VerticalDoor(line, mo);
}
else
{
success = EV_DoDoor(line, args, DT_NORMAL);
}
break;
case 13: // Door Locked_Raise
if(CheckedLockedDoor(mo, args[3]))
{
if(!args[0])
{
success = EV_VerticalDoor(line, mo);
}
else
{
success = EV_DoDoor(line, args, DT_NORMAL);
}
}
break;
case 20: // Floor Lower by Value
success = EV_DoFloor(line, args, FT_LOWERBYVALUE);
break;
case 21: // Floor Lower to Lowest
success = EV_DoFloor(line, args, FT_LOWERTOLOWEST);
break;
case 22: // Floor Lower to Nearest
success = EV_DoFloor(line, args, FT_LOWER);
break;
case 23: // Floor Raise by Value
success = EV_DoFloor(line, args, FT_RAISEFLOORBYVALUE);
break;
case 24: // Floor Raise to Highest
success = EV_DoFloor(line, args, FT_RAISEFLOOR);
break;
case 25: // Floor Raise to Nearest
success = EV_DoFloor(line, args, FT_RAISEFLOORTONEAREST);
break;
case 26: // Stairs Build Down Normal
success = EV_BuildStairs(line, args, -1, STAIRS_NORMAL);
break;
case 27: // Build Stairs Up Normal
success = EV_BuildStairs(line, args, 1, STAIRS_NORMAL);
break;
case 28: // Floor Raise and Crush
success = EV_DoFloor(line, args, FT_RAISEFLOORCRUSH);
break;
case 29: // Build Pillar (no crushing)
success = EV_BuildPillar(line, args, false);
break;
case 30: // Open Pillar
success = EV_OpenPillar(line, args);
break;
case 31: // Stairs Build Down Sync
success = EV_BuildStairs(line, args, -1, STAIRS_SYNC);
break;
case 32: // Build Stairs Up Sync
success = EV_BuildStairs(line, args, 1, STAIRS_SYNC);
break;
case 35: // Raise Floor by Value Times 8
success = EV_DoFloor(line, args, FT_RAISEBYVALUEMUL8);
break;
case 36: // Lower Floor by Value Times 8
success = EV_DoFloor(line, args, FT_LOWERBYVALUEMUL8);
break;
case 40: // Ceiling Lower by Value
success = EV_DoCeiling(line, args, CT_LOWERBYVALUE);
break;
case 41: // Ceiling Raise by Value
success = EV_DoCeiling(line, args, CT_RAISEBYVALUE);
break;
case 42: // Ceiling Crush and Raise
success = EV_DoCeiling(line, args, CT_CRUSHANDRAISE);
break;
case 43: // Ceiling Lower and Crush
success = EV_DoCeiling(line, args, CT_LOWERANDCRUSH);
break;
case 44: // Ceiling Crush Stop
success = P_CeilingDeactivate((short) args[0]);
break;
case 45: // Ceiling Crush Raise and Stay
success = EV_DoCeiling(line, args, CT_CRUSHRAISEANDSTAY);
break;
case 46: // Floor Crush Stop
success = EV_FloorCrushStop(line, args);
break;
case 60: // Plat Perpetual Raise
success = EV_DoPlat(line, args, PT_PERPETUALRAISE, 0);
break;
case 61: // Plat Stop
P_PlatDeactivate((short) args[0]);
break;
case 62: // Plat Down-Wait-Up-Stay
success = EV_DoPlat(line, args, PT_DOWNWAITUPSTAY, 0);
break;
case 63: // Plat Down-by-Value*8-Wait-Up-Stay
success = EV_DoPlat(line, args, PT_DOWNBYVALUEWAITUPSTAY, 0);
break;
case 64: // Plat Up-Wait-Down-Stay
success = EV_DoPlat(line, args, PT_UPWAITDOWNSTAY, 0);
break;
case 65: // Plat Up-by-Value*8-Wait-Down-Stay
success = EV_DoPlat(line, args, PT_UPBYVALUEWAITDOWNSTAY, 0);
break;
case 66: // Floor Lower Instant * 8
success = EV_DoFloor(line, args, FT_LOWERMUL8INSTANT);
break;
case 67: // Floor Raise Instant * 8
success = EV_DoFloor(line, args, FT_RAISEMUL8INSTANT);
break;
case 68: // Floor Move to Value * 8
success = EV_DoFloor(line, args, FT_TOVALUEMUL8);
break;
case 69: // Ceiling Move to Value * 8
success = EV_DoCeiling(line, args, CT_MOVETOVALUEMUL8);
break;
case 70: // Teleport
if(side == 0)
{ // Only teleport when crossing the front side of a line
success = EV_Teleport(args[0], mo, true);
}
break;
case 71: // Teleport, no fog
if(side == 0)
{ // Only teleport when crossing the front side of a line
success = EV_Teleport(args[0], mo, false);
}
break;
case 72: // Thrust Mobj
if(!side) // Only thrust on side 0
{
P_ThrustMobj(mo, args[0] * (ANGLE_90 / 64), (float) args[1]);
success = 1;
}
break;
case 73: // Damage Mobj
if(args[0])
{
P_DamageMobj(mo, NULL, NULL, args[0], false);
}
else
{ // If arg1 is zero, then guarantee a kill
P_DamageMobj(mo, NULL, NULL, 10000, false);
}
success = 1;
break;
case 74: // Teleport_NewMap
if(side == 0) // Only teleport when crossing the front side of a line
{
// Players must be alive to teleport
if(!(mo && mo->player && mo->player->playerState == PST_DEAD))
{
G_SetGameActionMapCompleted(G_ComposeMapUri(::gameEpisode, args[0]!= 0? args[0]-1 : 0),
args[1], false);
success = true;
}
}
break;
case 75: // Teleport_EndGame
if(side == 0) // Only teleport when crossing the front side of a line
{
// Players must be alive to teleport
if(!(mo && mo->player && mo->player->playerState == PST_DEAD))
{
success = true;
if(G_Ruleset_Deathmatch())
{
// Winning in deathmatch goes back to the first map of the episode.
G_SetGameActionMapCompleted(G_ComposeMapUri(::gameEpisode, 0), 0, false);
}
else
{
// Passing a URI with an empty path starts the Finale
G_SetGameActionMapCompleted(de::Uri("Maps:", RC_NULL), 0, false);
}
}
}
break;
case 80: /* ACS_Execute */ {
de::Uri mapUri = mapUriFromLogicalNumber(args[1]);
success = Game_ACScriptInterpreter().startScript(args[0], &mapUri, &args[2], mo, line, side);
break; }
case 81: /* ACS_Suspend */ {
de::Uri mapUri = mapUriFromLogicalNumber(args[1]);
success = Game_ACScriptInterpreter().suspendScript(args[0], &mapUri);
break; }
case 82: /* ACS_Terminate */ {
de::Uri mapUri = mapUriFromLogicalNumber(args[1]);
success = Game_ACScriptInterpreter().terminateScript(args[0], &mapUri);
break; }
case 83: // ACS_LockedExecute
success = P_StartLockedACS(line, args, mo, side);
break;
case 90: // Poly Rotate Left Override
success = EV_RotatePoly(line, args, 1, true);
break;
case 91: // Poly Rotate Right Override
success = EV_RotatePoly(line, args, -1, true);
break;
case 92: // Poly Move Override
success = EV_MovePoly(line, args, false, true);
break;
case 93: // Poly Move Times 8 Override
success = EV_MovePoly(line, args, true, true);
break;
case 94: // Build Pillar Crush
success = EV_BuildPillar(line, args, true);
break;
case 95: // Lower Floor and Ceiling
success = EV_DoFloorAndCeiling(line, args, FT_LOWERBYVALUE, CT_LOWERBYVALUE);
break;
case 96: // Raise Floor and Ceiling
success = EV_DoFloorAndCeiling(line, args, FT_RAISEFLOORBYVALUE, CT_RAISEBYVALUE);
break;
case 109: // Force Lightning
success = true;
P_ForceLightning();
break;
case 110: // Light Raise by Value
success = EV_SpawnLight(line, args, LITE_RAISEBYVALUE);
break;
case 111: // Light Lower by Value
success = EV_SpawnLight(line, args, LITE_LOWERBYVALUE);
break;
case 112: // Light Change to Value
success = EV_SpawnLight(line, args, LITE_CHANGETOVALUE);
break;
case 113: // Light Fade
success = EV_SpawnLight(line, args, LITE_FADE);
break;
case 114: // Light Glow
success = EV_SpawnLight(line, args, LITE_GLOW);
break;
case 115: // Light Flicker
success = EV_SpawnLight(line, args, LITE_FLICKER);
break;
case 116: // Light Strobe
success = EV_SpawnLight(line, args, LITE_STROBE);
break;
case 120: // Quake Tremor
success = A_LocalQuake(args, mo);
break;
case 129: // UsePuzzleItem
success = EV_LineSearchForPuzzleItem(line, args, mo);
break;
case 130: // Thing_Activate
success = EV_ThingActivate(args[0]);
break;
case 131: // Thing_Deactivate
success = EV_ThingDeactivate(args[0]);
break;
case 132: // Thing_Remove
success = EV_ThingRemove(args[0]);
break;
case 133: // Thing_Destroy
success = EV_ThingDestroy(args[0]);
break;
case 134: // Thing_Projectile
success = EV_ThingProjectile(args, 0);
break;
case 135: // Thing_Spawn
success = EV_ThingSpawn(args, 1);
break;
case 136: // Thing_ProjectileGravity
success = EV_ThingProjectile(args, 1);
break;
case 137: // Thing_SpawnNoFog
success = EV_ThingSpawn(args, 0);
break;
case 138: // Floor_Waggle
success =
EV_StartFloorWaggle(args[0], args[1], args[2], args[3], args[4]);
break;
case 140: // Sector_SoundChange
success = EV_SectorSoundChange(args);
break;
default:
break;
}
return success;
}
dd_bool P_ActivateLine(Line *line, mobj_t *mo, int side, int activationType)
{
int lineActivation;
dd_bool repeat;
dd_bool buttonSuccess;
xline_t *xline = P_ToXLine(line);
if(IS_CLIENT)
{
// Clients do not activate lines.
return false;
}
lineActivation = GET_SPAC(xline->flags);
if(lineActivation != activationType)
return false;
if(!mo->player && !(mo->flags & MF_MISSILE))
{
if(lineActivation != SPAC_MCROSS)
{ // currently, monsters can only activate the MCROSS activation type
return false;
}
if(xline->flags & ML_SECRET)
return false; // never DT_OPEN secret doors
}
repeat = ((xline->flags & ML_REPEAT_SPECIAL)? true : false);
buttonSuccess =
P_ExecuteLineSpecial(xline->special, &xline->arg1, line, side, mo);
if(!repeat && buttonSuccess)
{
// clear the special on non-retriggerable lines
xline->special = 0;
}
if((lineActivation == SPAC_USE || lineActivation == SPAC_IMPACT) &&
buttonSuccess)
{
P_ToggleSwitch((Side *)P_GetPtrp(line, DMU_FRONT), 0, false,
repeat? BUTTONTIME : 0);
}
return true;
}
/**
* Called every tic frame that the player origin is in a special sector.
*/
void P_PlayerInSpecialSector(player_t *player)
{
static coord_t const pushTab[3] = {
1.0 / 32 * 5,
1.0 / 32 * 10,
1.0 / 32 * 25
};
Sector *sector = Mobj_Sector(player->plr->mo);
xsector_t *xsector;
if(!FEQUAL(player->plr->mo->origin[VZ], P_GetDoublep(sector, DMU_FLOOR_HEIGHT)))
return; // Player is not touching the floor
xsector = P_ToXSector(sector);
switch(xsector->special)
{
case 9: // SecretArea
if(!IS_CLIENT)
{
player->secretCount++;
player->update |= PSF_COUNTERS;
xsector->special = 0;
}
break;
case 201:
case 202:
case 203: // Scroll_North_xxx
P_Thrust(player, ANG90, pushTab[xsector->special - 201]);
break;
case 204:
case 205:
case 206: // Scroll_East_xxx
P_Thrust(player, 0, pushTab[xsector->special - 204]);
break;
case 207:
case 208:
case 209: // Scroll_South_xxx
P_Thrust(player, ANG270, pushTab[xsector->special - 207]);
break;
case 210:
case 211:
case 212: // Scroll_West_xxx
P_Thrust(player, ANG180, pushTab[xsector->special - 210]);
break;
case 213:
case 214:
case 215: // Scroll_NorthWest_xxx
P_Thrust(player, ANG90 + ANG45, pushTab[xsector->special - 213]);
break;
case 216:
case 217:
case 218: // Scroll_NorthEast_xxx
P_Thrust(player, ANG45, pushTab[xsector->special - 216]);
break;
case 219:
case 220:
case 221: // Scroll_SouthEast_xxx
P_Thrust(player, ANG270 + ANG45, pushTab[xsector->special - 219]);
break;
case 222:
case 223:
case 224: // Scroll_SouthWest_xxx
P_Thrust(player, ANG180 + ANG45, pushTab[xsector->special - 222]);
break;
case 40:
case 41:
case 42:
case 43:
case 44:
case 45:
case 46:
case 47:
case 48:
case 49:
case 50:
case 51:
// Wind specials are handled in (P_mobj):P_MobjMoveXY
break;
case 26: // Stairs_Special1
case 27: // Stairs_Special2
// Used in (P_floor):ProcessStairSector
break;
case 198: // Lightning Special
case 199: // Lightning Flash special
case 200: // Sky2
// Used in (R_plane):R_Drawplanes
break;
default:
break;
}
}
void P_PlayerOnSpecialFloor(player_t* player)
{
const terraintype_t* tt = P_MobjFloorTerrain(player->plr->mo);
if(!(tt->flags & TTF_DAMAGING))
return;
if(player->plr->mo->origin[VZ] >
P_GetDoublep(Mobj_Sector(player->plr->mo), DMU_FLOOR_HEIGHT))
{
return; // Player is not touching the floor
}
if(!(mapTime & 31))
{
P_DamageMobj(player->plr->mo, &lavaInflictor, NULL, 10, false);
S_StartSound(SFX_LAVA_SIZZLE, player->plr->mo);
}
}
void P_SpawnSectorSpecialThinkers()
{
// Clients do not spawn sector specials.
if(IS_CLIENT) return;
for(int i = 0; i < numsectors; ++i)
{
Sector *sec = (Sector *)P_ToPtr(DMU_SECTOR, i);
xsector_t *xsec = P_ToXSector(sec);
switch(xsec->special)
{
default: break;
case 1: ///< Phased light.
// Static base, use sector->lightLevel as the index.
P_SpawnPhasedLight(sec, (80.f / 255.0f), -1);
break;
case 2: ///< Phased light sequence start.
P_SpawnLightSequence(sec, 1);
break;
}
}
}
void P_SpawnLineSpecialThinkers(void)
{
// Stub.
}
void P_SpawnAllSpecialThinkers(void)
{
P_SpawnSectorSpecialThinkers();
P_SpawnLineSpecialThinkers();
}
dd_bool P_SectorTagIsBusy(int tag)
{
/// @note The sector tag lists cannot be used here as an iteration at a higher
/// level may already be in progress.
int i;
for(i = 0; i < numsectors; ++i)
{
Sector *sec = (Sector *) P_ToPtr(DMU_SECTOR, i);
xsector_t *xsec = P_ToXSector(sec);
if(xsec->tag == tag && xsec->specialData)
{
return true;
}
}
return false;
}
static dd_bool isLightningSector(Sector* sec)
{
xsector_t* xsec = P_ToXSector(sec);
if(xsec->special == LIGHTNING_SPECIAL ||
xsec->special == LIGHTNING_SPECIAL2)
return true;
if(P_GetIntp(P_GetPtrp(sec, DMU_CEILING_MATERIAL),
DMU_FLAGS) & MATF_SKYMASK)
return true;
if(P_GetIntp(P_GetPtrp(sec, DMU_FLOOR_MATERIAL),
DMU_FLAGS) & MATF_SKYMASK)
return true;
return false;
}
static void P_LightningFlash(void)
{
int i;
float *tempLight;
dd_bool foundSec;
float flashLight;
if(lightningFlash)
{
lightningFlash--;
tempLight = lightningLightLevels;
if(lightningFlash)
{
for(i = 0; i < numsectors; ++i)
{
Sector *sec = (Sector *)P_ToPtr(DMU_SECTOR, i);
if(isLightningSector(sec))
{
float lightLevel = P_GetFloat(DMU_SECTOR, i, DMU_LIGHT_LEVEL);
if(*tempLight < lightLevel - (4.f / 255))
P_SetFloat(DMU_SECTOR, i, DMU_LIGHT_LEVEL,
lightLevel - (1.f / 255) * 4);
tempLight++;
}
}
}
else
{
// Remove the alternate lightning flash special.
for(i = 0; i < numsectors; ++i)
{
Sector *sec = (Sector *)P_ToPtr(DMU_SECTOR, i);
if(isLightningSector(sec))
{
P_SetFloatp(sec, DMU_LIGHT_LEVEL, *tempLight);
tempLight++;
}
}
if(!IS_DEDICATED)
{
R_SkyParams(1, DD_DISABLE, NULL);
R_SkyParams(0, DD_ENABLE, NULL);
}
}
return;
}
lightningFlash = (P_Random() & 7) + 8;
flashLight = (float) (200 + (P_Random() & 31)) / 255.0f;
tempLight = lightningLightLevels;
foundSec = false;
for(i = 0; i < numsectors; ++i)
{
Sector *sec = (Sector *)P_ToPtr(DMU_SECTOR, i);
if(isLightningSector(sec))
{
xsector_t *xsec = P_ToXSector(sec);
float newLevel = P_GetFloatp(sec, DMU_LIGHT_LEVEL);
*tempLight = newLevel;
if(xsec->special == LIGHTNING_SPECIAL)
{
newLevel += .25f;
if(newLevel > flashLight)
newLevel = flashLight;
}
else if(xsec->special == LIGHTNING_SPECIAL2)
{
newLevel += .125f;
if(newLevel > flashLight)
newLevel = flashLight;
}
else
{
newLevel = flashLight;
}
if(newLevel < *tempLight)
newLevel = *tempLight;
P_SetFloatp(sec, DMU_LIGHT_LEVEL, newLevel);
tempLight++;
foundSec = true;
}
}
if(foundSec)
{
mobj_t *plrmo = players[DISPLAYPLAYER].plr->mo;
mobj_t *crashOrigin = 0;
if(!IS_DEDICATED)
{
// Set the alternate (lightning) sky.
R_SkyParams(0, DD_DISABLE, NULL);
R_SkyParams(1, DD_ENABLE, NULL);
}
// If 3D sounds are active, position the clap somewhere above the player.