/
p_xgline.c
2732 lines (2334 loc) · 90.2 KB
/
p_xgline.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
/** @file p_xgline.c Extended generalized line types.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2007 Jamie Jones <jamie_jones_au@yahoo.com.au>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>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</small>
*/
#if __JDOOM__ || __JHERETIC__ || __JDOOM64__
#include <time.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "dmu_lib.h"
#include "p_mapsetup.h"
#include "d_net.h"
#include "p_xgline.h"
#include "p_xgsec.h"
#include "p_actor.h"
#include "p_player.h"
#include "p_map.h"
#include "p_mapspec.h"
#include "p_terraintype.h"
#include "p_tick.h"
#include "p_sound.h"
#include "p_switch.h"
#define XLTIMER_STOPPED 1 // Timer stopped.
#define EVTYPESTR(evtype) (evtype == XLE_CHAIN? "CHAIN" \
: evtype == XLE_CROSS? "CROSS" \
: evtype == XLE_USE? "USE" \
: evtype == XLE_SHOOT? "SHOOT" \
: evtype == XLE_HIT? "HIT" \
: evtype == XLE_TICKER? "TICKER" \
: evtype == XLE_AUTO? "AUTO" \
: evtype == XLE_FORCED? "FORCED" \
: evtype == XLE_FUNC? "FUNCTION" : "???")
#define LREFTYPESTR(reftype) (reftype == LREF_NONE? "NONE" \
: reftype == LREF_SELF? "SELF" \
: reftype == LREF_TAGGED? "TAGGED LINES" \
: reftype == LREF_LINE_TAGGED? "LINE TAGGED LINES" \
: reftype == LREF_ACT_TAGGED? "ACT TAGGED LINES" \
: reftype == LREF_INDEX? "INDEXED LINE" \
: reftype == LREF_ALL? "ALL LINES" : "???")
#define LPREFTYPESTR(reftype) (reftype == LPREF_NONE? "NONE" \
: reftype == LPREF_MY_FLOOR? "MY FLOOR" \
: reftype == LPREF_TAGGED_FLOORS? "TAGGED FLOORS" \
: reftype == LPREF_LINE_TAGGED_FLOORS? "LINE TAGGED FLOORS" \
: reftype == LPREF_ACT_TAGGED_FLOORS? "ACT TAGGED FLOORS" \
: reftype == LPREF_INDEX_FLOOR? "INDEXED FLOOR" \
: reftype == LPREF_ALL_FLOORS? "ALL FLOORS" \
: reftype == LPREF_MY_CEILING? "MY CEILING" \
: reftype == LPREF_TAGGED_CEILINGS? "TAGGED CEILINGS" \
: reftype == LPREF_LINE_TAGGED_CEILINGS? "LINE TAGGED CEILINGS" \
: reftype == LPREF_ACT_TAGGED_CEILINGS? "ACT TAGGED CEILINGS" \
: reftype == LPREF_INDEX_CEILING? "INDEXED CEILING" \
: reftype == LPREF_ALL_CEILINGS? "ALL CEILINGS" \
: reftype == LPREF_SPECIAL? "SPECIAL" \
: reftype == LPREF_BACK_FLOOR? "BACK FLOOR" \
: reftype == LPREF_BACK_CEILING? "BACK CEILING" \
: reftype == LPREF_THING_EXIST_FLOORS? "SECTORS WITH THING - FLOOR" \
: reftype == LPREF_THING_EXIST_CEILINGS? "SECTORS WITH THING - CEILING" \
: reftype == LPREF_THING_NOEXIST_FLOORS? "SECTORS WITHOUT THING - FLOOR" \
: reftype == LPREF_THING_NOEXIST_CEILINGS? "SECTORS WITHOUT THING - CEILING" : "???")
#define LSREFTYPESTR(reftype) (reftype == LSREF_NONE? "NONE" \
: reftype == LSREF_MY? "MY SECTOR" \
: reftype == LSREF_TAGGED? "TAGGED SECTORS" \
: reftype == LSREF_LINE_TAGGED? "LINE TAGGED SECTORS" \
: reftype == LSREF_ACT_TAGGED? "ACT TAGGED SECTORS" \
: reftype == LSREF_INDEX? "INDEXED SECTOR" \
: reftype == LSREF_ALL? "ALL SECTORS" \
: reftype == LSREF_BACK? "BACK SECTOR" \
: reftype == LSREF_THING_EXIST? "SECTORS WITH THING" \
: reftype == LSREF_THING_NOEXIST? "SECTORS WITHOUT THING" : "???")
#define TO_DMU_TOP_COLOR(x) ((x) == 0? DMU_TOP_COLOR_RED \
: (x) == 1? DMU_TOP_COLOR_GREEN \
: DMU_TOP_COLOR_BLUE)
#define TO_DMU_MIDDLE_COLOR(x) ((x) == 0? DMU_MIDDLE_COLOR_RED \
: (x) == 1? DMU_MIDDLE_COLOR_GREEN \
: (x) == 2? DMU_MIDDLE_COLOR_BLUE \
: DMU_MIDDLE_ALPHA)
#define TO_DMU_BOTTOM_COLOR(x) ((x) == 0? DMU_BOTTOM_COLOR_RED \
: (x) == 1? DMU_BOTTOM_COLOR_GREEN \
: DMU_BOTTOM_COLOR_BLUE)
void XL_ChangeMaterial(Line *line, int sidenum, int section, Material *mat,
blendmode_t blend, byte rgba[4], int flags);
int C_DECL XL_DoChainSequence();
int C_DECL XL_DoDamage();
int C_DECL XL_DoPower();
int C_DECL XL_DoKey();
int C_DECL XL_DoExplode();
int C_DECL XL_DoCommand();
int C_DECL XLTrav_ChangeLineType();
int C_DECL XLTrav_Activate();
int C_DECL XLTrav_Music();
int C_DECL XLTrav_LineCount();
int C_DECL XLTrav_LeaveMap();
int C_DECL XLTrav_DisableLine();
int C_DECL XLTrav_EnableLine();
int C_DECL XLTrav_ChangeWallMaterial();
int C_DECL XLTrav_LineTeleport();
int xgDev = 0; // Print dev messages.
static linetype_t typebuffer;
static char msgbuf[80];
struct mobj_s dummyThing;
/* ADD NEW XG CLASSES TO THE END - ORIGINAL INDICES MUST STAY THE SAME!!! */
xgclass_t xgClasses[NUMXGCLASSES] =
{
{ NULL, NULL, TRAV_NONE, 0, 1, 0, "None" },
// Dummy class (has no functions but enables use of secondary actions) (no params)
{ XL_DoChainSequence, NULL, TRAV_NONE, 0, 1, 0, "Chain Sequence",
// Excute a chain of other XG line types (a zero ends the list)
{{XGPF_INT, "Chain Flags", "chsf_", 0}, // ip0: (chsf_) chain sequence flags
{XGPF_INT, "Line Type 0", "", -1}, // ip1: Type to execute
{XGPF_INT, "Line Type 1", "", -1}, // ip2: "" "" ""
{XGPF_INT, "Line Type 2", "", -1}, // ip3: "" "" ""
{XGPF_INT, "Line Type 3", "", -1}, // ip4: "" "" ""
{XGPF_INT, "Line Type 4", "", -1}, // ip5: "" "" ""
{XGPF_INT, "Line Type 5", "", -1}, // ip6: "" "" ""
{XGPF_INT, "Line Type 6", "", -1}, // ip7: "" "" ""
{XGPF_INT, "Line Type 7", "", -1}, // ip8: "" "" ""
{XGPF_INT, "Line Type 8", "", -1}, // ip9: "" "" ""
{XGPF_INT, "Line Type 9", "", -1}, // ip10: "" "" ""
{XGPF_INT, "Line Type 10", "", -1}, // ip11: "" "" ""
{XGPF_INT, "Line Type 11", "", -1}, // ip12: "" "" ""
{XGPF_INT, "Line Type 12", "", -1}, // ip13: "" "" ""
{XGPF_INT, "Line Type 13", "", -1}, // ip14: "" "" ""
{XGPF_INT, "Line Type 14", "", -1}, // ip15: "" "" ""
{XGPF_INT, "Line Type 15", "", -1}, // ip16: "" "" ""
{XGPF_INT, "Line Type 16", "", -1}, // ip17: "" "" ""
{XGPF_INT, "Line Type 17", "", -1}, // ip18: "" "" ""
{XGPF_INT, "Line Type 18", "", -1} }}, // ip19: "" "" ""
{ XSTrav_MovePlane, XS_InitMovePlane, TRAV_PLANES, 0, 1, 0, "Move Plane",
// Move one or more planes. Optionaly change textures/types on start/end
{{XGPF_INT, "Target Ref", "lpref_", 0}, // ip0: (plane ref) plane(s) to move.
{XGPF_INT, "Target Num", "", -1}, // ip1:
{XGPF_INT, "Destination Ref", "spref_", 2}, // ip2: destination height type (zero, relative to current, surrounding highest/lowest floor/ceiling)
{XGPF_INT, "Move Flags", "pmf_", 3}, // ip3: flags (PMF_*)
{XGPF_INT, "Start Sound", "", 4 | MAP_SND}, // ip4: start sound
{XGPF_INT, "End Sound", "", 5 | MAP_SND}, // ip5: end sound
{XGPF_INT, "Move Sound", "", 6 | MAP_SND}, // ip6: move sound
{XGPF_INT, "Start Material Ref", "spref_", 7}, // ip7: start texture origin (uses same ids as i2) (spec: use ip8 as tex num)
{XGPF_INT, "Start Material Num", "", 8 | MAP_MATERIAL}, // ip8: data component or number/name of flat
{XGPF_INT, "End Material Ref", "spref_", 9}, // ip9: end texture origin (uses same ids as i2) (spec: use ip10 as tex num)
{XGPF_INT, "End Material Num", "", 10 | MAP_MATERIAL}, // ip10: data component or number/name of flat
{XGPF_INT, "Start Type Ref", "lpref_", 11}, // ip11: (plane ref) start sector type (spec: use i12 as type ID)
{XGPF_INT, "Start Type Num", "", -1}, // ip12: data component or type ID
{XGPF_INT, "End Type Ref", "lpref_", 13}, // ip13: (plane ref) end sector type (spec: use i14 as type ID)
{XGPF_INT, "End Type Num", "", -1} }}, // ip14: data component or type ID
{ XSTrav_BuildStairs, XS_InitStairBuilder, TRAV_PLANES, 0, 1, 0, "Build Stairs",
// Moves one or more planes, incrementing their height with each move
{{XGPF_INT, "Target Ref", "lpref_", 0}, // ip0: (plane ref) plane to start from
{XGPF_INT, "Target Num", "", -1}, // ip1:
{XGPF_INT, "Spread Material", "", -1}, // ip2: (true/false) stop when texture changes
{XGPF_INT, "Spread Build", "", -1}, // ip3: (true/false) spread build?
{XGPF_INT, "Start Sound", "", 4 | MAP_SND}, // ip4: start build sound (doesn't wait)
{XGPF_INT, "Step Start Sound", "", 5 | MAP_SND}, // ip5: step start sound
{XGPF_INT, "Step End Sound", "", 6 | MAP_SND}, // ip6: step end sound
{XGPF_INT, "Step Move Sound", "", 7 | MAP_SND} }}, // ip7: step move sound
{ XL_DoDamage, NULL, TRAV_NONE, 0, 1, 0, "Damage",
// Deals health damage to the activator
{{XGPF_INT, "Min Delta", "", -1}, // ip0: min damage delta
{XGPF_INT, "Max Delta", "", -1}, // ip1: max damage delta
{XGPF_INT, "Min Limit", "", -1}, // ip2: min limit (wont damage if health bellow)
{XGPF_INT, "Max Limit", "", -1} }}, // ip3: max limit (wont damage if health above)
{ XL_DoPower, NULL, TRAV_NONE, 0, 1, 0, "Power",
// Deals armor damage to the activator (must be a player)
{{XGPF_INT, "Min Delta", "", -1}, // ip0: min power delta
{XGPF_INT, "Max Delta", "", -1}, // ip1: max power delta
{XGPF_INT, "Min Limit", "", -1}, // ip2: min limit
{XGPF_INT, "Max Limit", "", -1} }}, // ip3: max limit
{ XLTrav_ChangeLineType, NULL, TRAV_LINES, 0, 1, 0, "Line Type",
// Changes a line's type (must be an XG type)
{{XGPF_INT, "Target Ref", "lref_", 0}, // ip0: (line ref) line(s) to change
{XGPF_INT, "Target Num", "", -1}, // ip1:
{XGPF_INT, "Line Type", "", -1} }}, // ip2: new type (must be an XG line type)
{ XSTrav_SectorType, NULL, TRAV_SECTORS, 0, 1, 0, "Sector Type",
// Changes a sector's type (must be an XG type)
{{XGPF_INT, "Target Ref", "lsref_", 0}, // ip0: (sector ref) sector(s) to change
{XGPF_INT, "Target Num", "", -1}, // ip1:
{XGPF_INT, "Sector Type", "", -1} }}, // ip2: new type (zero or an XG sector type)
{ XSTrav_SectorLight, NULL, TRAV_SECTORS, 0, 1, 0, "Sector Light",
// Change the light level and/or color of the target sector(s).
{{XGPF_INT, "Target Ref", "lsref_", 0}, // ip0: (sector ref) sector(s) to change
{XGPF_INT, "Target Num", "", -1}, // ip1:
{XGPF_INT, "Change Light", "", -1}, // ip2: if non-zero light level will be changed
{XGPF_INT, "Change Color", "", -1}, // ip3: if non-zero colour will be changed
{XGPF_INT, "Light Ref", "lightref_", 4}, // ip4: (light ref) sector to get the initial light delta from.
// lightref_none makes ip5 an absolute value
{XGPF_INT, "Light Delta", "", -1}, // ip5: offset to the delta or absolute value
{XGPF_INT, "Color Ref", "lightref_", 6}, // ip6: (light ref) sector to get the initial colour deltas from.
// lightref_none makes ip7-9 absolute values
{XGPF_INT, "Red Delta", "", -1}, // ip7: offset to red delta
{XGPF_INT, "Green Delta", "", -1}, // ip8: offset to green delta
{XGPF_INT, "Blue Delta", "", -1} }}, // ip9: offset to blue delta
{ XLTrav_Activate, NULL, TRAV_LINES, 0, 1, 0, "Activate",
// Sends a chain event to all the referenced lines
{{XGPF_INT, "Target Ref", "lref_", 0}, // ip0: (line ref) line(s) to activate
{XGPF_INT, "Target Num", "", -1} }}, // ip1:
{ XL_DoKey, NULL, TRAV_NONE, 0, 1, 0, "Key",
// Gives/takes keys to/from the activator (must be a player)
// Params are bitfields! Bit 1 (0x1) corresponds key 1, bit 2 (0x2) key 2, etc.
{{XGPF_INT, "Give Keys", "", -1}, // ip0: keys to give
{XGPF_INT, "Take Keys", "", -1} }}, // ip1: keys to take away.
{ XLTrav_Music, NULL, TRAV_LINES, 2, 3, 0, "Music",
// Changes the music track being played
{{XGPF_INT, "Song ID", "ldref_", 0 | MAP_MUS}, // ip0: song id/name or (line data ref from ip2)
{XGPF_INT, "Play Looped", "", -1}, // ip1: non-zero means play looped
{XGPF_INT, "Data Ref", "lref_", 2}, // ip2: (line ref) used with line data ref eg set music track to line-tag
{XGPF_INT, "Data Num", "", -1} }}, // ip3:
{ XLTrav_LineCount, NULL, TRAV_LINES, 0, 1, 0, "Line Count",
// Changes the XG line(s)' internal activation counter
{{XGPF_INT, "Target Ref", "lref_", 0}, // ip0: (line ref) line(s) to change
{XGPF_INT, "Target Num", "", -1}, // ip1:
{XGPF_INT, "Set Absolute", "", -1}, // ip2: non-zero makes ip3 absolute
{XGPF_INT, "Count Delta", "", -1} }}, // ip3: count delta or absolute
{ XLTrav_LeaveMap, NULL, TRAV_LINES, 1, 2, 0, "Leave Map",
// Exits the current map
{{XGPF_INT, "Secret Exit", "", -1}, // ip0: non-zero goto secret map
{XGPF_INT, "Data Ref", "lref_", 1}, // ip1: (line ref) line to acquire (line data ref) from
{XGPF_INT, "Data Num", "", -1}, // ip2:
{XGPF_INT, "Goto Map", "ldref_", 3} }}, // ip3: map ID or (line data ref from ip1)
{ XLTrav_DisableLine, NULL, TRAV_LINES, 0, 1, 0, "Disable Line",
// Disables the referenced line(s) if active
{{XGPF_INT, "Target Ref", "lref_", 0}, // ip0: (line ref) line(s) to disable
{XGPF_INT, "Target Num", "", -1} }}, // ip1:
{ XLTrav_EnableLine, NULL, TRAV_LINES, 0, 1, 0, "Enable Line",
// Enables the referenced line(s) if active.
{{XGPF_INT, "Target Ref", "lref_", 0}, // ip0: (line ref) line(s) to enable
{XGPF_INT, "Target Num", "", -1} }}, // ip1:
{ XL_DoExplode, NULL, TRAV_NONE, 0, 1, 0, "Explode" },
// Explodes the activator (no params).
{ XSTrav_PlaneMaterial, NULL, TRAV_PLANES, 0, 1, 0, "Plane Material",
// Change the material and/or surface color of a plane.
{{XGPF_INT, "Target Ref", "lpref_", 0}, // ip0 : (plane ref) plane(s) to change
{XGPF_INT, "Target Num", "", -1}, // ip1 : ref data
{XGPF_INT, "Material Ref", "spref_", 2}, // ip2 : Texture ref
{XGPF_INT, "Material Num", "", 3 | MAP_MATERIAL}, // ip3 : texture number (flat), used with SPREF_NONE
{XGPF_INT, "Red Delta", "", -1}, // ip4 : plane surface color (red)
{XGPF_INT, "Green Delta", "", -1}, // ip5 : "" (green)
{XGPF_INT, "Blue Delta", "", -1} }}, // ip6 : "" (blue)
{ XLTrav_ChangeWallMaterial, NULL, TRAV_LINES, 0, 1, 0, "Wall Material",
// Changes material(s) on the referenced line(s).
// Changes surface colour(s), alpha, mid textue blendmode and side flags
{{XGPF_INT, "Target Ref", "lref_", 0}, // ip0: (line ref) line(s) to change
{XGPF_INT, "Target Num", "", -1}, // ip1:
{XGPF_INT, "Side Num", "", -1}, // ip2: non-zero change the back side
{XGPF_INT, "Top Material", "", 3 | MAP_MATERIAL}, // ip3: top texture to change to (blank indicates no change)
{XGPF_INT, "Middle Material", "", 4 | MAP_MATERIAL}, // ip4: middle texture to change to (blank indicates no change)
{XGPF_INT, "Bottom Material", "", 5 | MAP_MATERIAL}, // ip5: bottom texture to change to (blank indicates no change)
{XGPF_INT, "Set Mid If None", "", -1}, // ip6: set mid texture even if previously zero
{XGPF_INT, "Sidedef Flags", "sdf_", 7}, // ip7: (sdf_) side flags (used with surface colour blending, fullbright etc)
{XGPF_INT, "Middle Blendmode", "bm_", 8}, // ip8: (bm_) middle texture blendmode
{XGPF_INT, "Top Red Delta", "", -1}, // ip9:
{XGPF_INT, "Top Green Delta", "", -1}, // ip10:
{XGPF_INT, "Top Blue Delta", "", -1}, // ip11:
{XGPF_INT, "Middle Red Delta", "", -1}, // ip12:
{XGPF_INT, "Middle Green Delta", "", -1}, // ip13:
{XGPF_INT, "Middle Blue Delta", "", -1}, // ip14:
{XGPF_INT, "Middle Alpha Delta", "", -1}, // ip15:
{XGPF_INT, "Bottom Red Delta", "", -1}, // ip16:
{XGPF_INT, "Bottom Green Delta", "", -1}, // ip17:
{XGPF_INT, "Bottom Blue Delta", "", -1} }}, // ip18:
{ XL_DoCommand, NULL, TRAV_NONE, 0, 1, 0, "Command" },
// Executes a console command (CCmd)
{ XSTrav_SectorSound, NULL, TRAV_SECTORS, 0, 1, 0, "Sector Sound",
// Plays a sound in sector(s)
{{XGPF_INT, "Target Ref", "lsref_", 0}, // ip0: (sector ref) sector(s) to play the sound in
{XGPF_INT, "Target Num", "", -1}, // ip1:
{XGPF_INT, "Sound ID", "", 2 | MAP_SND}, // ip2: sound name/id to play
{XGPF_INT, "Origin", "", -1} }}, // ip3: non-zero = play from a specific origin (1=floor, 2=ceiling) else 0=center
{ XSTrav_MimicSector, NULL, TRAV_SECTORS, 0, 1, 0, "Mimic Sector",
// Copies all properties from target sector to destination sector(s)
{{XGPF_INT, "Target Ref", "lsref_", 0}, // ip0: (sector ref) sector(s) to change
{XGPF_INT, "Target Num", "", -1}, // ip1:
{XGPF_INT, "Mimic Ref", "spref_", 2}, // ip2: (spref) sector to mimic
{XGPF_INT, "Mimic Num", "", -1} }}, // ip3:
{ XSTrav_Teleport, NULL, TRAV_SECTORS, 0, 1, 0, "Teleport",
// Teleports the activator to the first teleport exit in the target sector
{{XGPF_INT, "Target Ref", "lsref_", 0}, // ip0: (sector ref) sector(s) to teleport to (first acceptable target is used)
{XGPF_INT, "Target Num", "", -1}, // ip1:
{XGPF_INT, "No Flash", "", -1}, // ip2: non-zero = no flash (or sound)
{XGPF_INT, "No Sound", "", -1}, // ip3: non-zero = no sound
{XGPF_INT, "Always Stomp", "", -1} }}, // ip4: non-zero = Always telefrag
{ XLTrav_LineTeleport, NULL, TRAV_LINES, 0, 1, 1 | XLE_CROSS, "Line Teleport",
// Teleports the activator to the referenced line
{{XGPF_INT, "Target Ref", "lref_", 0}, // ip0: (line ref) teleport destination
{XGPF_INT, "Target Num", "", -1}, // ip1:
{XGPF_INT, "No Flash", "", -1}, // ip2: non-zero = spawn MT_TFOG
{XGPF_INT, "Teleport Sound", "", 3 | MAP_SND}, // ip3: sound ID/name to play (or silent)
{XGPF_INT, "Exit Side", "", -1}, // ip4: non-zero = exit from the back of the target line
{XGPF_INT, "Always Stomp", "", -1} }} // ip5: non-zero = Always telefrag
};
cvartemplate_t xgCVars[] =
{
{"xg-dev", CVF_NO_ARCHIVE, CVT_INT, &xgDev, 0, 1},
{NULL}
};
ccmdtemplate_t xgCCmds[] =
{
{"movefloor", NULL, CCmdMovePlane},
{"moveceil", NULL, CCmdMovePlane},
{"movesec", NULL, CCmdMovePlane},
{NULL}
};
// CODE --------------------------------------------------------------------
/**
* Register XG CCmds & CVars (called during pre init)
*/
void XG_Register(void)
{
int i;
for(i = 0; xgCVars[i].path; ++i)
Con_AddVariable(xgCVars + i);
for(i = 0; xgCCmds[i].name; ++i)
Con_AddCommand(xgCCmds + i);
}
/**
* Debug message printer.
*/
void XG_Dev(const char* format, ...)
{
static char buffer[2000];
va_list args;
if(!xgDev)
return;
va_start(args, format);
dd_vsnprintf(buffer, sizeof(buffer), format, args);
strcat(buffer, "\n");
App_Log(DE2_MAP_MSG, "%s", buffer);
va_end(args);
}
/**
* Init XG data for the map.
*/
void XG_Init(void)
{
XL_Init(); // Init lines.
XS_Init(); // Init sectors.
}
void XG_Ticker(void)
{
// Nothing to do.
}
/**
* This is called during an engine reset. Disables all XG functionality!
*/
void XG_Update(void)
{
// Clients rely on the server, they don't do XG themselves.
if(IS_CLIENT)
return;
XG_ReadTypes();
XS_Update();
XL_Update();
}
/**
* Adds the given binary format line type to the generated types array
*/
int XL_AddAutoGenType(linetype_t* newtype)
{
return true;
}
/**
* Converts a line ID number to a line type (BOOM support).
*/
int XL_AutoGenType(int id, linetype_t* outptr)
{
return false; // Cos we don't work yet.
#if 0
linetype_t *l;
// Do the magic
// is the ID in the range 12160 -> 32768
if(!(id >= 12160 && id <= 32768))
return false;
// Have we already generated a line of this type?
if(1)
{
// Then return a ptr to it
outptr = l;
return true;
}
// Which bitfield format are we generating from?
if(1) //XG format
{
/*
// Generate the new line type
l->id = id;
l->flags = def->flags[0];
l->flags2 = def->flags[1];
l->flags3 = def->flags[2];
l->lineClass = def->lineClass;
l->actType = def->actType;
l->actCount = def->actCount;
l->actTime = def->actTime;
// l->actTag = def->actTag;
for(i = 0; i < 10; i++)
{
if(i == 9)
l->aparm[i] = Def_GetMobjNum(def->aparm9);
else
l->aparm[i] = def->aparm[i];
}
// l->tickerStart = def->tickerStart;
// l->tickerEnd = def->tickerEnd;
// l->tickerInterval = def->tickerInterval;
l->actSound = Friendly(Def_GetSoundNum(def->actSound));
l->deactSound = Friendly(Def_GetSoundNum(def->deactSound));
l->evChain = def->evChain;
l->actChain = def->actChain;
l->deactChain = def->deactChain;
l->actLineType = def->actLineType;
l->deactLineType = def->deactLineType;
l->wallSection = def->wallSection;
l->actTex = Friendly(R_CheckTextureNumForName(def->actTex));
l->deactTex = Friendly(R_CheckTextureNumForName(def->deactTex));
l->actMsg = def->actMsg;
l->deactMsg = def->deactMsg;
l->texMoveAngle = def->texMoveAngle;
l->texMoveSpeed = def->texMoveSpeed;*/
// Add it to the generated line types array
XL_AddAutoGenType(l);
outptr = l;
}
#if __JDOOM__ || __JDOOM64__
else // BOOM format
{
// Generate the new line type
outptr = l;
}
#endif
return true;
#endif
}
/**
* @return @c true, if the type is defined.
*/
linetype_t* XL_GetType(int id)
{
linetype_t* ptr;
char buff[6];
// Try finding it from the DDXGDATA lump.
ptr = XG_GetLumpLine(id);
if(ptr)
{ // Got it!
memcpy(&typebuffer, ptr, sizeof(*ptr));
return &typebuffer;
}
// Does Doomsday have a definition for this?
dd_snprintf(buff, 6, "%i", id);
if(Def_Get(DD_DEF_LINE_TYPE, buff, &typebuffer))
return &typebuffer;
// Is this a type we can generate automatically?
if(XL_AutoGenType(id, &typebuffer))
return &typebuffer;
// A definition was not found.
return NULL;
}
int XG_RandomInt(int min, int max)
{
float x;
if(max == min)
return max;
x = M_Random() / 256.0f; // Never reaches 1.
return (int) (min + x * (max - min) + x);
}
float XG_RandomPercentFloat(float value, int percent)
{
float i = (2 * M_Random() / 255.0f - 1) * percent / 100.0f;
return value * (1 + i);
}
int findXLThinker(thinker_t* th, void* context)
{
xlthinker_t* xl = (xlthinker_t*) th;
if(xl->line == (Line*) context)
return true; // Stop iteration, we've found it.
return false; // Continue iteration.
}
/**
* Looks for line type definition and sets the line type if one is found.
*/
void XL_SetLineType(Line* line, int id)
{
xline_t* xline = P_ToXLine(line);
if(XL_GetType(id))
{
xline->special = id;
// Allocate memory for the line type data.
if(!xline->xg)
xline->xg = Z_Calloc(sizeof(xgline_t), PU_MAP, 0);
// Init the extended line state.
xline->xg->disabled = false;
xline->xg->timer = 0;
xline->xg->tickerTimer = 0;
memcpy(&xline->xg->info, &typebuffer, sizeof(linetype_t));
// Initial active state.
xline->xg->active = (typebuffer.flags & LTF_ACTIVE) != 0;
xline->xg->activator = &dummyThing;
XG_Dev("XL_SetLineType: Line %i (%s), ID %i.", P_ToIndex(line),
xgClasses[xline->xg->info.lineClass].className, id);
// If there is not already an xlthinker for this line, create one.
if(!Thinker_Iterate(XL_Thinker, findXLThinker, line))
{ // Not created one yet.
xlthinker_t* xl = Z_Calloc(sizeof(*xl), PU_MAP, 0);
xl->thinker.function = XL_Thinker;
Thinker_Add(&xl->thinker);
xl->line = line;
}
}
else if(id)
{
XG_Dev("XL_SetLineType: Line %i, type %i NOT DEFINED.",
P_ToIndex(line), id);
}
}
/**
* Initialize extended lines for the map.
*/
void XL_Init(void)
{
int i;
Line *line;
memset(&dummyThing, 0, sizeof(dummyThing));
// Clients rely on the server, they don't do XG themselves.
if(IS_CLIENT)
return;
for(i = 0; i < numlines; ++i)
{
line = P_ToPtr(DMU_LINE, i);
P_ToXLine(line)->xg = 0;
XL_SetLineType(line, P_ToXLine(line)->special);
}
}
/**
* Executes the specified function on all planes that match the reference
* (reftype).
*
* @return @c true, iff all callbacks return @c true.
*/
int XL_TraversePlanes(Line* line, int refType, int ref, void* data,
void* context, dd_bool travsectors, mobj_t* activator,
int (C_DECL *func)())
{
int tag;
mobj_t* mo;
dd_bool ok, findSecTagged;
Sector* sec, *frontSec, *backSec;
xsector_t* xsec;
if(xgDev)
{
char buff[50];
if(ref)
sprintf(buff, ": %i", ref);
XG_Dev("XL_Traverse%s: Line %i, ref (%s%s)",
travsectors? "Sectors":"Planes", P_ToIndex(line),
travsectors? LSREFTYPESTR(refType) : LPREFTYPESTR(refType),
ref? buff: "");
}
if(refType == LPREF_NONE)
return false; // This is not a reference!
frontSec = P_GetPtrp(line, DMU_FRONT_SECTOR);
backSec = P_GetPtrp(line, DMU_BACK_SECTOR);
// References to a single plane
if(refType == LPREF_MY_FLOOR || refType == LPREF_MY_CEILING)
{
if(frontSec)
{
return func(frontSec, refType == LPREF_MY_CEILING? true:false,
data, context, activator);
}
XG_Dev(" Line %i has no front sector!", P_ToIndex(line));
}
if(refType == LPREF_BACK_FLOOR || refType == LPREF_BACK_CEILING)
{
if(backSec)
{
return func(backSec, refType == LPREF_BACK_CEILING? true:false,
data, context, activator);
}
XG_Dev(" Line %i has no back sector!", P_ToIndex(line));
}
if(refType == LPREF_INDEX_FLOOR)
return func(P_ToPtr(DMU_SECTOR, ref), false, data, context,
activator);
if(refType == LPREF_INDEX_CEILING)
return func(P_ToPtr(DMU_SECTOR, ref), true, data, context,
activator);
// Can we use the tagged sector lists?
findSecTagged = false;
if(refType == LPREF_TAGGED_FLOORS || refType == LPREF_TAGGED_CEILINGS)
{
findSecTagged = true;
tag = ref;
}
else if(refType == LPREF_LINE_TAGGED_FLOORS ||
refType == LPREF_LINE_TAGGED_CEILINGS)
{
findSecTagged = true;
tag = P_ToXLine(line)->tag;
}
// References to multiple planes
if(findSecTagged)
{ // Use tagged sector lists for these (speed).
iterlist_t* list;
list = P_GetSectorIterListForTag(tag, false);
if(list)
{ // Find the first sector with the tag.
IterList_SetIteratorDirection(list, ITERLIST_FORWARD);
IterList_RewindIterator(list);
while((sec = IterList_MoveIterator(list)) != NULL)
{
xsec = P_ToXSector(sec);
if(refType == LPREF_TAGGED_FLOORS || refType == LPREF_TAGGED_CEILINGS)
{
if(!func(sec, refType == LPREF_TAGGED_CEILINGS, data,
context, activator))
return false;
}
if(refType == LPREF_LINE_TAGGED_FLOORS ||
refType == LPREF_LINE_TAGGED_CEILINGS)
{
if(!func(sec, refType == LPREF_LINE_TAGGED_CEILINGS,
data, context, activator))
return false;
}
}
}
}
else
{
int i;
for(i = 0; i < numsectors; ++i)
{
sec = P_ToPtr(DMU_SECTOR, i);
xsec = P_ToXSector(sec);
if(refType == LPREF_ALL_FLOORS || refType == LPREF_ALL_CEILINGS)
{
if(!func(sec, refType == LPREF_ALL_CEILINGS, data,
context, activator))
return false;
}
if((refType == LPREF_ACT_TAGGED_FLOORS ||
refType == LPREF_ACT_TAGGED_CEILINGS) && xsec->xg &&
xsec->xg->info.actTag == ref)
{
if(!func(sec, refType == LPREF_ACT_TAGGED_CEILINGS, data,
context, activator))
return false;
}
// Reference all sectors with (at least) one mobj of specified
// type inside.
if(refType == LPREF_THING_EXIST_FLOORS ||
refType == LPREF_THING_EXIST_CEILINGS)
{
ok = true;
for(mo = P_GetPtrp(sec, DMT_MOBJS); ok && mo; mo = mo->sNext)
{
if(mo->type == P_ToXLine(line)->xg->info.aparm[9])
{
XG_Dev(" Thing of type %i found in sector id %i.",
P_ToXLine(line)->xg->info.aparm[9], i);
if(!func(sec, refType == LPREF_THING_EXIST_CEILINGS,
data, context, activator))
return false;
ok = false;
}
}
}
// Reference all sectors with NONE of the specified mobj type
// inside.
if(refType == LPREF_THING_NOEXIST_FLOORS ||
refType == LPREF_THING_NOEXIST_CEILINGS)
{
ok = true;
for(mo = P_GetPtrp(sec, DMT_MOBJS); ok && mo; mo = mo->sNext)
{
if(mo->type != P_ToXLine(line)->xg->info.aparm[9])
continue;
else
ok = false;
}
if(ok)
{
XG_Dev(" No things of type %i found in sector id %i.",
P_ToXLine(line)->xg->info.aparm[9], i);
if(!func(sec, refType == LPREF_THING_NOEXIST_CEILINGS,
data, context, activator))
return false;
}
}
}
}
return true;
}
/**
* Executes the specified function on all lines that match the reference
* 'rtype'.
*
* @return @c false if 'func' returns @c false, otherwise
* @c true. Stops checking when false is returned.
*/
int XL_TraverseLines(Line* line, int rtype, int ref, void* data,
void* context, mobj_t* activator, int (C_DECL *func)())
{
int i;
int tag;
int reftype = rtype;
char buff[50];
Line *iter;
dd_bool findLineTagged;
// Binary XG data from DD_XGDATA uses the old flag values.
// Add one to the ref type.
if(xgDataLumps)
reftype+= 1;
if(ref)
sprintf(buff," : %i",ref);
XG_Dev("XL_TraverseLines: Line %i, ref (%s%s)",
P_ToIndex(line), LREFTYPESTR(reftype), ref? buff : "");
if(reftype == LREF_NONE)
return func(NULL, true, data, context, activator); // Not a real reference
// References to single lines
if(reftype == LREF_SELF) // Traversing self is simple.
return func(line, true, data, context, activator);
if(reftype == LREF_INDEX)
return func(P_ToPtr(DMU_LINE, ref), true, data, context, activator);
// Can we use the tagged line lists?
findLineTagged = false;
if(reftype == LREF_TAGGED)
{
findLineTagged = true;
tag = ref;
}
else if(reftype == LREF_LINE_TAGGED)
{
findLineTagged = true;
tag = P_ToXLine(line)->tag;
}
// References to multiple lines
if(findLineTagged)
{ // Use tagged line lists for these (speed).
iterlist_t *list = P_GetLineIterListForTag(tag, false);
if(list)
{
IterList_SetIteratorDirection(list, ITERLIST_FORWARD);
IterList_RewindIterator(list);
while((iter = IterList_MoveIterator(list)) != NULL)
{
if(reftype == LREF_TAGGED)
{
if(!func(iter, true, data, context, activator))
return false;
}
else if(reftype == LREF_LINE_TAGGED)
{
// Ref is true if line itself should be excluded.
if(!ref || iter != line)
if(!func(iter, true, data, context, activator))
return false;
}
}
}
}
else
{
for(i = 0; i < numlines; ++i)
{
iter = P_ToPtr(DMU_LINE, i);
if(reftype == LREF_ALL)
{
if(!func(iter, true, data, context, activator))
return false;
}
else if(reftype == LREF_ACT_TAGGED)
{
xline_t *xl = P_ToXLine(iter);
if(xl->xg && xl->xg->info.actTag == ref)
if(!func(iter, true, data, context, activator))
return false;
}
}
}
return true;
}
/**
* @return Value as determined by the reference type from the
* specified line, using data from either the line
* itself or context (will always be linetype_t).
*/
int XL_ValidateLineRef(Line* line, int reftype, void* context,
char* parmname)
{
int answer = 0;
Side* side;
switch(reftype)
{
case LDREF_ID: // Line ID.
answer = P_ToIndex(line);
XG_Dev("XL_ValidateLineRef: Using Line ID (%i) as %s", answer, parmname);
break;
case LDREF_SPECIAL: // Line Special.
answer = P_ToXLine(line)->special;
XG_Dev("XL_ValidateLineRef: Using Line Special (%i) as %s", answer, parmname);
break;
case LDREF_TAG: // Line Tag.
answer = P_ToXLine(line)->tag;
XG_Dev("XL_ValidateLineRef: Using Line Tag (%i) as %s", answer, parmname);
break;
case LDREF_ACTTAG: // Line ActTag.
if(!P_ToXLine(line)->xg)
{
XG_Dev("XL_ValidateLineRef: REFERENCE NOT AN XG LINE");
break;
}
if(!P_ToXLine(line)->xg->info.actTag)
{
XG_Dev("XL_ValidateLineRef: REFERENCE DOESNT HAVE AN ACT TAG");
break;
}
answer = P_ToXLine(line)->xg->info.actTag;
XG_Dev("XL_ValidateLineRef: Using Line ActTag (%i) as %s", answer, parmname);
break;
case LDREF_COUNT: // Line count.
if(!P_ToXLine(line)->xg)
{
XG_Dev("XL_ValidateLineRef: REFERENCE NOT AN XG LINE");
break;
}
answer = P_ToXLine(line)->xg->info.actCount;
XG_Dev("XL_ValidateLineRef: Using Line Count (%i) as %s", answer, parmname);
break;
case LDREF_ANGLE: { // Line angle.
coord_t d1[2];
P_GetDoublepv(line, DMU_DXY, d1);
answer = M_PointXYToAngle2(0, 0, d1[0], d1[1]) / (float) ANGLE_MAX * 360;
XG_Dev("XL_ValidateLineRef: Using Line Angle (%i) as %s", answer, parmname);
break; }
case LDREF_LENGTH: // Line length.
// Answer should be in map units.
answer = P_GetFixedp(line, DMU_LENGTH) >> FRACBITS;
XG_Dev("XL_ValidateLineRef: Using Line Length (%i) as %s", answer, parmname);
break;
case LDREF_TOP_OFFSETX:
// Can this ever fail?
side = P_GetPtrp(line, DMU_FRONT);
if(!side)
{
XG_Dev("XL_ValidateLineRef: REFERENCE MISSING FRONT SIDE!");