Subversion Repositories eduke32

Rev

Rev 4421 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1696 helixhorne 1
// m32 script editor extensions.
2
// to load, enter "include samples/a" (without quotes) in the console
3
// or into a file named m32_autoexec.cfg for automatic loading on startup.
1711 helixhorne 4
// to enable all events, "enableevent all"
1695 helixhorne 5
 
1696 helixhorne 6
////////// USER SETTINGS //////////
7
 
8
// settings for the tweaking of Polymer pr_override*-variables with the keypad keys
9
define MINPARALLAXSCALE -10  // minimum pr_parallaxscale value
10
define MAXPARALLAXSCALE 10
11
define MINPARALLAXBIAS -10
12
define MAXPARALLAXBIAS 10
13
define PSCALESTEPS 1000  // 0..1 is mapped to 0..PSCALESTEPS
14
define PBIASSTEPS 1000
15
 
16
define MINSPECULARPOWER -10
17
define MAXSPECULARPOWER 1000
18
define MINSPECULARFACTOR -10
19
define MAXSPECULARFACTOR 1000
20
define SPOWERSTEPS 100
21
define SFACTORSTEPS 100
22
 
1706 helixhorne 23
// color of various drawing enhancements
1697 helixhorne 24
define PREVIEW_DRAW_COLOR 11
1730 helixhorne 25
gamevar showpal 0 0
1697 helixhorne 26
 
1706 helixhorne 27
// whether to use overridden aspect/range values when entering 3d mode (software/Polymost).
28
// tweak with keys 7,8,9,0 on the top row
1712 helixhorne 29
gamevar use_custom_aspect 0 0  // this is now the same as r_usenewaspect
1706 helixhorne 30
gamevar davr 65536 0
31
gamevar dayx 65536 0
32
 
2122 helixhorne 33
// whether to remap certain widely-available keys to rare ones
34
// (notebook/netbook convenience, see EVENT_KEYPRESS for details)
35
gamevar use_notebook_keys 0 0
1832 helixhorne 36
 
3447 helixhorne 37
// Whether RESPAWN sprites show the respawned sprite picnum unconditionally instead of
38
// only when aimed at (and locked onto) the RESPAWN sprite in 3D mode.
39
gamevar showrespawn_always 0 0
3699 helixhorne 40
// When set to 1, previewed sprites are 66% translucent instead of 33%:
41
gamevar showrespawn_fulltrans 0 0
3447 helixhorne 42
 
3704 helixhorne 43
// Set to basepal index to override
44
gamevar override_basepal -1 0
45
 
3509 helixhorne 46
gamevar move_by_one 0 0
47
 
3648 helixhorne 48
// Polymer "head" light
49
gamevar headlight_enabled 0 0
50
gamevar headlight_range 4000 0
51
 
1832 helixhorne 52
// see end of file for more user settings and examples
53
 
1696 helixhorne 54
////////// END USER SETTINGS //////////
55
 
56
 
1695 helixhorne 57
include names.h
58
 
59
// flag 1: per-block (top-level, event, or state) variable
60
gamevar i 0 1
61
gamevar j 0 1
62
gamevar k 0 1
1696 helixhorne 63
 
1695 helixhorne 64
gamevar p 0 1
65
gamevar r 0 1
66
 
67
gamevar x 0 0
68
gamevar y 0 0
69
gamevar z 0 0
70
 
71
gamevar dx 0 0
72
gamevar dy 0 0
73
gamevar dz 0 0
74
gamevar dang 0 0
75
 
76
gamevar tmp 0 0
77
gamevar cnt 0 0
78
 
1927 helixhorne 79
gamevar sec 0 0
80
gamevar wal 0 0
81
 
1695 helixhorne 82
gamevar drawcol 9 0
83
 
84
 
85
define TQUOTE 0
86
definequote TQUOTE  >>> write on me! <<<
87
 
2808 helixhorne 88
//light
1695 helixhorne 89
define LIGHTQUOTE 1
90
//                                  x  y  z       r  g  b                mins maxs
91
definequote LIGHTQUOTE light  %d   %d %d %d  %d  %d %d %d   %d %d %d %d   %d %d   %d %d
92
//                            sec          range       radius fade ang horiz    prio tile
93
 
94
 
95
define PRSCALE 1000
96
define MAXSPECULAR 100000
97
 
1697 helixhorne 98
define TMPARLEN 128
99
gamearray ar TMPARLEN
100
gamearray xx TMPARLEN
101
gamearray yy TMPARLEN
102
 
1695 helixhorne 103
gamearray parm 8
104
 
105
// prints out maphack light definitions based on SE lights in map
106
defstate printlights
1955 helixhorne 107
    "Print Polymer lights"
1696 helixhorne 108
    var flags
109
 
1695 helixhorne 110
    print "--PRLIGHTS--"
111
    for i allsprites, ifactor SECTOREFFECTOR, ifge .lotag 49, ifle .lotag 50
112
    {
113
        ife .lotag 50
114
        {
115
            set j 128, sub j .shade, shiftl j 1
116
            set k j, mul k 3, div k 4
117
        }
118
        else
119
        {
120
            set j 0, set k 0
121
        }
122
 
1696 helixhorne 123
        set flags 0
1695 helixhorne 124
        ifand .cstat 2
125
        {
126
            ifand .cstat 512
1696 helixhorne 127
                set flags 4
1695 helixhorne 128
            else
1696 helixhorne 129
                set flags 2
1695 helixhorne 130
        }
131
        //                                            range     r   g   b
132
        qsprintf TQUOTE LIGHTQUOTE .sectnum .x .y .z .hitag .xvel .yvel .zvel
1696 helixhorne 133
                                   j k    .ang .extra .xoffset .yoffset flags .owner
134
        //                    radius fade      horiz  minshade maxshade prio  tile
1695 helixhorne 135
        print TQUOTE
136
    }
137
    print "--ENDPRLIGHTS--"
138
ends
139
 
1877 helixhorne 140
defstate insertlights
1955 helixhorne 141
    "Insert active SE lights"
1877 helixhorne 142
    var sectnum
143
 
144
    set k 0
145
    for i activelights
146
    {
147
        insertsprite light[i].sector
148
 
149
        // I is the inserted sprites' index now
150
        set .picnum 1
151
 
152
        set .x light[i].x
153
        set .y light[i].y
154
        set .z light[i].z
155
 
156
        set .hitag light[i].range
157
        set .xvel light[i].r
158
        set .yvel light[i].g
159
        set .zvel light[i].b
160
 
161
        set .extra light[i].horiz
162
 
163
        set .xoffset light[i].minshade
164
        set .yoffset light[i].maxshade
165
 
166
        set .owner light[i].tilenum
167
 
1878 helixhorne 168
        set .xrepeat 48
169
        set .yrepeat 48
170
 
1877 helixhorne 171
        // now those that are calculated
172
        ifge light[i].priority 4 or .cstat 512
173
        ifge light[i].priority 2 or .cstat 2
174
 
175
        ife light[i].radius 0
176
        {
177
            set .lotag 49
178
        }
179
        else
180
        {
181
            set .lotag 50
182
            set j light[i].radius, shiftr j 1, sub j 128, inv j
183
            clamp j -128 127
184
            set .shade j
185
        }
186
 
187
        add k 1
188
    }
189
 
190
    qsprintf TQUOTE "* Inserted %d SE sprites based on active lights." k
191
    print TQUOTE
192
ends
193
 
1695 helixhorne 194
// convenient polymer SE light manipulation with keypad keys
195
// when aiming at light SE (49 or 50):
196
//  KP 4,5,6,8: angle/horiz
197
//  KP 7,9: range
198
//  KP+/-: radius
199
//  KP 1,2,3: RGB color (Shift inverts)
200
//
1848 helixhorne 201
// when aiming at wall or sector and the respective overrides are on:
1696 helixhorne 202
//  KP 5,8: parallaxscale
203
//  KP 4,6: parallaxbias
204
//  KP /,*: specularfactor
205
//  KP 7,9: specularpower
1695 helixhorne 206
//
207
// Also try Shift and/or Ctrl modifiers for different increments
208
defstate fiddlewithlights
1696 helixhorne 209
    var minval maxval
4197 helixhorne 210
    var val
1848 helixhorne 211
 
1695 helixhorne 212
    // if aiming at sector or wall
1696 helixhorne 213
    ifaimingsprite nullop
1695 helixhorne 214
    else ifn pr_overrideparallax 0
215
    {
216
        set j 0 set k 0
217
 
1696 helixhorne 218
        ifhitkey KEY_KP5 set j -1, ifhitkey KEY_KP8 set j 1
1695 helixhorne 219
        ifn j 0 set k 1
220
 
1696 helixhorne 221
        ifhitkey KEY_KP4 set j -1, ifhitkey KEY_KP6 set j 1
1695 helixhorne 222
        ife k 0 ifn j 0 set k 2
223
 
1698 helixhorne 224
        ifeitheralt mul j 10
1695 helixhorne 225
        ifeitherctrl mul j 10
226
 
227
        switch k
1955 helixhorne 228
        case 0: break;
1695 helixhorne 229
        case 1:
230
        {
231
            set k pr_parallaxscale
4171 helixhorne 232
            ftoi k PSCALESTEPS  // must convert to scaled integer, maps 0..1 to 0..PSCALESTEPS
1696 helixhorne 233
            set minval MINPARALLAXSCALE, mul minval PSCALESTEPS
234
            set maxval MAXPARALLAXSCALE, mul maxval PSCALESTEPS
1698 helixhorne 235
            add k j, clamp k minval maxval
1696 helixhorne 236
            itof k PSCALESTEPS  // convert back
1695 helixhorne 237
            qsprintf TQUOTE "PARALLAX SCALE: %f" k, quote TQUOTE
238
            set pr_parallaxscale k
239
            break;
240
        }
241
        case 2:
242
        {
243
            set k pr_parallaxbias
1696 helixhorne 244
            ftoi k PBIASSTEPS
245
            set minval MINPARALLAXBIAS, mul minval PBIASSTEPS
246
            set maxval MAXPARALLAXBIAS, mul maxval PBIASSTEPS
247
            add k j, clamp k minval maxval
248
            itof k PBIASSTEPS
1695 helixhorne 249
            qsprintf TQUOTE "PARALLAX BIAS: %f" k, quote TQUOTE
250
            set pr_parallaxbias k
251
            break;
252
        }
1696 helixhorne 253
        endswitch
1698 helixhorne 254
//quote "zxczxc"
1696 helixhorne 255
    }
1698 helixhorne 256
//quote "asdasd"
1696 helixhorne 257
    // if aiming at sector or wall
258
    ifaimingsprite nullop
259
    else ifn pr_overridespecular 0
260
    {
261
        set j 0 set k 0
262
 
263
        ifhitkey KEY_gSLASH set j -1, ifhitkey KEY_gSTAR set j 1
264
        ifn j 0 set k 3
265
 
266
        ifhitkey KEY_KP7 set j -1, ifhitkey KEY_KP9 set j 1
267
        ife k 0 ifn j 0 set k 4
268
 
1698 helixhorne 269
        ifeitheralt mul j 10
1696 helixhorne 270
        ifeitherctrl mul j 10
271
 
272
        switch k
1955 helixhorne 273
        case 0: break;
1695 helixhorne 274
        case 3:
275
        {
276
            set k pr_specularfactor
1696 helixhorne 277
            ftoi k SFACTORSTEPS
278
            set minval MINSPECULARFACTOR, mul minval SFACTORSTEPS
279
            set maxval MAXSPECULARFACTOR, mul maxval SFACTORSTEPS
280
            add k j, clamp k minval maxval
281
            itof k SFACTORSTEPS
1695 helixhorne 282
            qsprintf TQUOTE "SPECULAR FACTOR: %f" k, quote TQUOTE
283
            set pr_specularfactor k
284
            break;
285
        }
286
        case 4:
287
        {
288
            set k pr_specularpower
1696 helixhorne 289
            ftoi k SPOWERSTEPS
290
            set minval MINSPECULARPOWER, mul minval SPOWERSTEPS
291
            set maxval MAXSPECULARPOWER, mul maxval SPOWERSTEPS
292
            add k j, clamp k minval maxval
293
            itof k SPOWERSTEPS
1695 helixhorne 294
            qsprintf TQUOTE "SPECULAR POWER: %f" k, quote TQUOTE
295
            set pr_specularpower k
296
            break;
297
        }
298
        endswitch
299
    }
300
 
1698 helixhorne 301
//quote "qweqwe"
1695 helixhorne 302
    // if aiming at a sprite that's not a Polymer light
1696 helixhorne 303
    ifaimingsprite set k 1 else set k 0
1695 helixhorne 304
 
305
    ife k 1 ife sprite[searchwall].picnum SECTOREFFECTOR
2591 helixhorne 306
        ifge sprite[searchwall].lotag 49 ifle sprite[searchwall].lotag 50
307
            set k 0
1695 helixhorne 308
 
309
    ife k 1
310
    {
311
        seti searchwall
312
 
313
        // [xyz]vel / owner
314
        ifeitheralt
315
        {
316
            ifhitkey KEY_KP1
317
            {
1696 helixhorne 318
                getnumber256 .xvel "XVEL: " 0
319
                getnumber256 .yvel "YVEL: " 0
320
                getnumber256 .zvel "ZVEL: " 0
1695 helixhorne 321
            }
2122 helixhorne 322
            else ifeithershift ifhitkey KEY_KP2 // alt-kp2 collides with KP* replacement
1695 helixhorne 323
            {
1696 helixhorne 324
                getnumber256 .owner "OWNER: " 0
325
                ifl .owner 0 set .owner -1
1695 helixhorne 326
            }
327
        }
328
    }
329
 
330
 
331
    // if aiming at an SE with lotag 49 or 50 (Polymer light)
1696 helixhorne 332
    ifaimingsprite ife sprite[searchwall].picnum SECTOREFFECTOR
1695 helixhorne 333
    ifge sprite[searchwall].lotag 49 ifle sprite[searchwall].lotag 50
334
    {
335
        set i searchwall, seti i  // set current sprite = targeted sprite
336
 
337
        ife .lotag 50
338
        {
4197 helixhorne 339
            // KP8/KP5: horiz
1695 helixhorne 340
            ifeithershift set j 1 else set j 10
341
 
4197 helixhorne 342
            ifhitkey KEY_gUP nullop
343
            else ifhitkey KEY_gKP5 mul j -1
344
            else set j 0
345
 
346
            ifvarn j 0
347
            {
348
                // change it
349
                set val .extra
350
                add val j
351
                clamp val -32768 32767
352
                set .extra val
353
            }
354
 
355
            // KP4/KP6: angle
1695 helixhorne 356
            set j 128
357
            ifeitherctrl set j 4
358
            ifeithershift { ifeitherctrl set j 1 else set j 32 }
359
            ifhitkey KEY_gLEFT sub .ang j
360
            else ifhitkey KEY_gRIGHT add .ang j
361
 
4197 helixhorne 362
            // KP+/KP-: radius
1695 helixhorne 363
            ifeitherctrl
364
            {
365
                ifholdkey KEY_gMINUS add .shade 9
366
                else ifholdkey KEY_gPLUS sub .shade 9
367
 
368
                clamp .shade -118 117
369
            }
370
        }
371
 
372
        // range
373
        ifeithershift set j 10
374
        else ifeitherctrl set j 1000
375
        else set j 100
376
 
2227 helixhorne 377
        set k .hitag
378
        ifhitkey KEY_KP9 add k j
379
        else ifhitkey KEY_KP7 sub k j
380
        clamp k 0 32767
381
        set .hitag k
382
 
1695 helixhorne 383
        // min/max shade
384
        ifeithershift set j -1 else set j 1
385
        ifeitherctrl
386
        {
387
            ifhitkey KEY_gSLASH
388
            {
389
                set .xoffset 0
390
                set .yoffset 0
1696 helixhorne 391
                quote "Reset X and Y OFFSET (min/max shade) to 0"
1695 helixhorne 392
            }
393
        }
394
        else
395
        {
396
            set k 0
397
            ifhitkey KEY_gSLASH { add .xoffset j, set k 1 }
398
            else ifhitkey KEY_gSTAR { add .yoffset j, set k 1 }
399
 
400
            ife k 1
401
            {
1696 helixhorne 402
                qsprintf TQUOTE "XY OFFSET (min/max shade): %d %d" .xoffset .yoffset
1695 helixhorne 403
                quote TQUOTE
404
            }
405
        }
406
 
407
        // color/picnum
408
        ifeitheralt
409
        {
410
            ifhitkey KEY_KP1
411
            {
1696 helixhorne 412
                getnumber256 .xvel "XVEL (red): " 255
413
                getnumber256 .yvel "YVEL (green): " 255
414
                getnumber256 .zvel "ZVEL (blue): " 255
1695 helixhorne 415
            }
416
            else ifhitkey KEY_KP2
417
            {
1696 helixhorne 418
                getnumber256 .owner "OWNER (projection picnum): " -MAXTILES
419
                ifl .owner 0 set .owner -1
1695 helixhorne 420
            }
421
        }
422
        else
423
        {
424
            ifeitherctrl set j 1 else set j 10
425
            ifeithershift inv j
426
 
427
            set k 0
1789 helixhorne 428
            ifhitkey KEY_B { add .xvel j, set k 1 }
429
            ifhitkey KEY_N { add .yvel j, set k 1 }
430
            ifhitkey KEY_M { add .zvel j, set k 1 }
431
 
1695 helixhorne 432
            ifhitkey KEY_KP1 { add .xvel j, set k 1 }
433
            ifhitkey KEY_KP2 { add .yvel j, set k 1 }
434
            ifhitkey KEY_KP3 { add .zvel j, set k 1 }
435
 
436
            ife k 1
437
            {
438
                clamp .xvel 1 255
439
                clamp .yvel 1 255
440
                clamp .zvel 1 255
441
 
1696 helixhorne 442
                qsprintf TQUOTE "XYZ VEL (RGB color): %d %d %d" .xvel .yvel .zvel
1695 helixhorne 443
                quote TQUOTE
444
            }
445
        }
446
    }
3648 helixhorne 447
    else
448
    {
449
        // not aiming at sprite
450
 
451
        ifeitherctrl ifeithershift ifhitkey KEY_gMINUS
452
        {
453
            ife headlight_enabled 0
454
            {
455
                set headlight_enabled 1
456
                quote "head light enabled"
457
            }
458
            else
459
            {
460
                set headlight_enabled 0
461
                quote "head light disabled"
462
            }
463
        }
464
    }
1695 helixhorne 465
ends
466
 
3509 helixhorne 467
defstate do_move_by_one
468
    ifeithershift
469
    {
470
        ifhitkey KEY_UP sub horiz 1
471
        ifhitkey KEY_DOWN add horiz 1
472
        ifhitkey KEY_LEFT sub ang 1
473
        ifhitkey KEY_RIGHT add ang 1
474
        and ang 2047
475
    }
476
    else
477
    {
478
        // absolute x/y/z navigation
479
        ifhitkey KEY_LEFT sub posx 1
480
        ifhitkey KEY_RIGHT add posx 1
481
        ifhitkey KEY_DOWN sub posy 1
482
        ifhitkey KEY_UP add posy 1
483
        ifhitkey KEY_A sub posz 1
484
        ifhitkey KEY_Z add posz 1
485
    }
486
ends
487
 
488
defstate check_move_by_one
489
    ifn move_by_one 0
490
        set hardcoded_movement 0
491
    else
492
        set hardcoded_movement 1
493
ends
494
 
1832 helixhorne 495
// forward refs
496
defstate userkeys_3d ends
497
defstate userdrawlabel ends
1731 helixhorne 498
 
1697 helixhorne 499
onevent EVENT_PREKEYS3D
500
//    state testkeyavail
3509 helixhorne 501
 
502
    state check_move_by_one
503
    ifn move_by_one 0
504
        state do_move_by_one
505
 
1697 helixhorne 506
    state fiddlewithlights
1731 helixhorne 507
    state userkeys_3d
1697 helixhorne 508
endevent
509
 
510
 
1695 helixhorne 511
// rotate highlighted sprites around selected (closest to mouse) sprite
512
// global parameter: dang
513
defstate rotselspr
514
    ifg highlightcnt 0
515
    ifge pointhighlight 16384, ifl pointhighlight 32768
516
    {
517
        ife dang 0 return
518
 
519
        set p pointhighlight, and p 16383
520
 
521
        add sprite[p].ang dang
522
 
523
        for i selsprites, ifn i p
524
        {
525
            rotatepoint sprite[p].x sprite[p].y .x .y dang (x y)
526
            add .ang dang
527
            bsetsprite I x y .z
528
        }
529
    }
530
ends
531
 
2866 helixhorne 532
 
533
gamevar do_batch_extension 0 0
534
gamevar batch_ohl_i -1 0
535
gamevar batch_tmp 0 0
536
 
537
////// sector collecting stuff
538
gamearray collectedsectors MAXSECTORS  // shared with 'old-highlighted sectors'
539
gamevar ohlsecs 0 0
540
 
541
// save or restore highlighted sectors
542
defstate save_restore_hlsectors
543
    "Save/restore hl. sectors"
544
 
545
    ifge highlightsectorcnt 0
546
    {
547
        // save
548
        for i range highlightsectorcnt
549
            set collectedsectors[i] highlightsector[i]
550
        set ohlsecs highlightsectorcnt
551
        quote "Highlighted sectors saved"
552
    }
553
    else ifl highlightcnt 0
554
    {
555
        for i range ohlsecs
556
            sethighlightsector collectedsectors[i] 1
557
        quote "Highlighted sectors restored"
558
    }
559
ends
560
 
561
defstate extendhlsectors
562
    "Extend all hl. sectors"
563
 
564
    ifvarle highlightsectorcnt 0 return
565
 
566
    state save_restore_hlsectors  // will save them
567
    for i range highlightsectorcnt
568
        sethighlightsector highlightsector[i] 0
569
 
570
    set do_batch_extension 1
571
    set batch_ohl_i 0
572
ends
573
 
574
 
1695 helixhorne 575
onevent EVENT_PREKEYS2D
3509 helixhorne 576
    state check_move_by_one
577
    ifn move_by_one 0
578
        state do_move_by_one
579
 
2866 helixhorne 580
    ifvare do_batch_extension 1
581
        set do_batch_extension 2
582
    else ifvare do_batch_extension 2
583
    {
584
        ifge batch_ohl_i ohlsecs
585
        {
586
            // done!
587
            set do_batch_extension 0
588
            set batch_ohl_i -1
589
 
590
            set keystatus[0x1d] 0
591
            set keystatus[0x12] 0
592
        }
593
        else
594
        {
595
            ifvare batch_tmp 0
596
            {
597
                // highlight that sector
598
                sethighlightsector collectedsectors[batch_ohl_i] 1
599
                set batch_tmp 1
600
            }
601
            else  // ... skip a mainloop iteration so that a frame can be displayed
602
            {
603
                set batch_tmp 0
604
                add batch_ohl_i 1
605
 
606
                // fake a Ctrl-E
607
                set keystatus[0x1d] 1
608
                set keystatus[0x12] 1
609
            }
610
        }
611
 
612
        break
613
    }
614
 
1695 helixhorne 615
//    state testkeyavail
616
 
617
    set j 0
618
    ifeitherctrl
619
    {
620
        ifhitkey KEY_COMMA set j -1
621
        ifhitkey KEY_PERIOD set j 1
622
    }
623
 
624
    ifn j 0
625
    {
626
        mul j 512
627
        set dang j
628
        state rotselspr
629
    }
630
endevent
631
 
1712 helixhorne 632
gamevar fyx 0 0
633
gamevar fvr 0 0
1695 helixhorne 634
 
635
defstate setas
1712 helixhorne 636
    set fyx dayx
637
    mul fyx 4 mul fyx 100  // the correction factor 100/107 has been found
638
    div fyx 3 div fyx 107  // out experimentally. squares ftw!
639
    set fvr davr
640
    mul fvr xdim mul fvr 3
641
    div fvr ydim div fvr 4
642
    setaspect fvr fyx //davr dayx
1695 helixhorne 643
ends
644
 
645
onevent EVENT_ENTER3DMODE
1706 helixhorne 646
    ifn use_custom_aspect 0
647
        state setas
1695 helixhorne 648
endevent
649
 
1697 helixhorne 650
 
2754 helixhorne 651
defstate try_nextsector_teleporting
1927 helixhorne 652
    var nexts
653
    set nexts RETURN
654
 
655
    set RETURN 0
656
    for i spritesofsector nexts
657
    {
658
        ife .picnum SECTOREFFECTOR ife .lotag 7
659
        {
660
            set RETURN 1
661
            break
662
        }
663
    }
664
ends
665
 
2754 helixhorne 666
defstate try_nextsector_ceilingsky
667
    ifand sector[RETURN].ceilingstat 1
668
        set RETURN 1
669
    else
670
        set RETURN 0
671
ends
672
 
1927 helixhorne 673
defstate collect_teleporting_sectors // (sec)
1955 helixhorne 674
    "Collect telep. sectors"
1927 helixhorne 675
    var numsects
1955 helixhorne 676
 
677
    set numsects numsectors, sub numsects 1
678
    ifinteractive
679
    {
2826 helixhorne 680
        set sec searchsector
1955 helixhorne 681
        getnumberfromuser sec "starting sectnum: " numsects 8
682
        ifl sec 0, return
683
    }
684
 
2155 helixhorne 685
    set ohlsecs 0  // reset old hl'd sectors
686
 
2754 helixhorne 687
    collectsectors collectedsectors sec numsects try_nextsector_teleporting
1927 helixhorne 688
    for i range numsects
689
        sethighlightsector collectedsectors[i] 1
690
ends
691
 
2754 helixhorne 692
// XXX: CODEDUP
693
defstate collect_ceilsky_sectors // (sec)
694
    "Collect sky ceilings"
695
    var numsects
696
 
697
    set numsects numsectors, sub numsects 1
698
    ifinteractive
699
    {
2826 helixhorne 700
        set sec searchsector
2754 helixhorne 701
        getnumberfromuser sec "starting sectnum: " numsects 8
702
        ifl sec 0, return
703
    }
704
 
705
    set ohlsecs 0  // reset old hl'd sectors
706
 
707
    collectsectors collectedsectors sec numsects try_nextsector_ceilingsky
708
    for i range numsects
709
        sethighlightsector collectedsectors[i] 1
710
ends
711
 
1927 helixhorne 712
////// show LOCATORS
1695 helixhorne 713
defstate cmp_by_lotag  // comparator subroutine for sorting
714
    set RETURN sprite[SV2].lotag
715
    sub RETURN sprite[SV1].lotag
716
ends
717
 
1697 helixhorne 718
defstate connectlocators
719
    // connect LOCATORS in a sector with lines
1695 helixhorne 720
    getarraysize ar tmp
721
    set j 0
722
    for i spritesofsector cursectnum
723
    {
724
        ifge j tmp nullop else
725
        ifactor LOCATORS
726
        {
727
            set ar[j] i
728
            add j 1
729
        }
730
    }
731
 
732
    set tmp j
733
    sort ar tmp cmp_by_lotag
734
 
735
    sub tmp 1
736
    for i range tmp
737
    {
738
        set j ar[i]
739
        set k i, add k 1, set k ar[k]
1730 helixhorne 740
        drawline16z sprite[j].x sprite[j].y sprite[j].z sprite[k].x sprite[k].y sprite[k].z drawcol
1695 helixhorne 741
    }
1697 helixhorne 742
ends
1695 helixhorne 743
 
1697 helixhorne 744
defstate draw_prlightprojections
1695 helixhorne 745
////////// polymer light 2d projections //////////
1696 helixhorne 746
    var c d h r x2 y2 oldpat
1695 helixhorne 747
 
748
    array xx 2
749
    array yy 2
750
 
751
    set oldpat drawlinepat
752
    set drawlinepat 0x11111111
753
    for i spritesofsector cursectnum
754
    {
755
        ifactor SECTOREFFECTOR
756
        {
757
            ife .lotag 49  // point light
758
            {
759
                set d .hitag  // light distance
760
                mul d d, mul d 2, sqrt d d, div d 2
761
 
762
                getclosestcol .xvel .yvel .zvel c  // light color
763
                inv c
764
 
765
                set x .x, set x2 .x, set y .y, set y2 .y
766
                add x d, add y d, sub x2 d, sub y2 d
1730 helixhorne 767
                drawline16z x y .z x2 y2 .z c
1695 helixhorne 768
 
769
                set x .x, set x2 .x, set y .y, set y2 .y
770
                add x d, sub y d, sub x2 d, add y2 d
1730 helixhorne 771
                drawline16z x y .z x2 y2 .z c
772
                drawcircle16z .x .y .z .hitag c
1695 helixhorne 773
            }
774
            else ife .lotag 50  // spot light
775
            {
776
                set d .hitag  // light distance
777
                and d 65535
778
                set r 128, sub r .shade, shiftl r 1  // light cone radius (BUILD angles)
779
                getclosestcol .xvel .yvel .zvel c  // light color
780
                inv c
781
 
782
                set x .x, set y .y, add x d
783
                rotatepoint .x .y x y .ang x y
784
 
785
                set h .extra  // horiz
786
                sub h 100
787
                set tmp h, mul tmp tmp, add tmp 40000
788
                sqrt tmp tmp
789
                divscale h 200 tmp 15  // h: horizontal distance fraction
790
 
791
                set dx .x, sub dx x
792
                set dy .y, sub dy y
793
                set tmp 32768, sub tmp h
794
                mulscale dx dx tmp 15
795
                mulscale dy dy tmp 15
796
 
797
                set tmp 0, sub tmp r
798
                rotatepoint .x .y x y tmp xx[0] yy[0]
799
                set tmp 0, add tmp r
800
                rotatepoint .x .y x y tmp xx[1] yy[1]
801
 
802
                add xx[0] dx, add yy[0] dy
803
                add xx[1] dx, add yy[1] dy
804
 
1730 helixhorne 805
                drawline16z .x .y .z xx[0] yy[0] .z c
806
                drawline16z .x .y .z xx[1] yy[1] .z c
1695 helixhorne 807
            }
808
        }
809
    }
810
    set drawlinepat oldpat
1697 helixhorne 811
ends
812
 
813
defstate previewdoors2d
814
    // preview swinging and sliding doors in 2d mode
815
    var valid sect lo
816
    var i j w numw ang trange dx dy
817
 
818
    set valid 0
819
    set sect searchsector
820
 
1730 helixhorne 821
    ifge sect 0 ifl sect numsectors
1697 helixhorne 822
    {
823
        set lo sector[sect].lotag
824
        ife lo 23 set valid 1
825
        else ife lo 25 set valid 1
826
    }
827
 
828
    ife valid 1
829
    {
830
        set valid 0
831
        for i spritesofsector sect
832
            ifactor SECTOREFFECTOR
833
            {
834
                ife .lotag 11 ife lo 23 set valid 1  // swinging door
835
                ife .lotag 15 ife lo 25 set valid 1  // slide door
836
                ife valid 1 { set j i, break }
837
            }
838
 
839
        ife valid 1
840
            seti j
841
        else return
842
 
843
        ife .lotag 15
844
        {
845
            set trange 256
846
            for i spritesofsector sect
847
                ifactor GPSPEED { set trange .lotag, break }
848
            mul trange 2  // now equals distance of sliding door to travel
849
        }
850
 
851
        set i 0
852
        for w loopofwall sector[sect].wallptr
853
        {
854
            ifge i TMPARLEN break
855
            set xx[i] wall[w].x
856
            set yy[i] wall[w].y
857
            add i 1
858
        }
859
        ifl i TMPARLEN
860
        {
861
            set xx[i] xx[0]
862
            set yy[i] yy[0]
863
            add i 1
864
        }
865
        set numw i
866
 
867
        ife .lotag 11
868
        {
869
            ifg .ang 1024 set ang -512 else set ang 512
870
            for i range numw
871
                rotatepoint .x .y xx[i] yy[i] ang xx[i] yy[i]
872
        }
873
        else  // if .lotag 15
874
        {
875
            set ang .ang, add ang 1024
876
            a2xy ang dx dy
877
            mulscale dx trange dx 14
878
            mulscale dy trange dy 14
879
 
880
            for i range numw
881
            {
882
                add xx[i] dx
883
                add yy[i] dy
884
            }
885
        }
886
 
887
        set drawlinepat 0x33333333
888
        sub numw 1
889
        for i range numw
890
        {
891
            set j i, add j 1
1730 helixhorne 892
            drawline16z xx[i] yy[i] sector[sect].floorz xx[j] yy[j] sector[sect].floorz PREVIEW_DRAW_COLOR
1697 helixhorne 893
        }
894
        set drawlinepat 0xffffffff
895
    }
896
ends
897
 
898
 
1695 helixhorne 899
// LOCATORS auto-incrementer
900
onevent EVENT_INSERTSPRITE2D
901
    set k I
902
    set j -1
903
    for i spritesofsector .sectnum
904
    {
905
        ifn i k, ifactor LOCATORS, ifg .lotag j
906
            set j .lotag
907
    }
908
    ifg j -1
909
    {
910
        add j 1
911
        set .lotag j
912
    }
913
endevent
914
 
2179 helixhorne 915
defstate print_parallel_midpts  // print the midpoints of parallel wall-lines
916
    var p0 p1 p2 s1dx s1dy s2dx s2dy tmp nw
1695 helixhorne 917
 
2179 helixhorne 918
    quote "----------------"
919
    for p1 allwalls
920
    {
921
        lastwall p1 p0  // get the 'inverse point2'
922
        set p2 wall[p1].point2  // ... and the forward one
923
 
924
        set tmp 0
925
 
926
        // both white: OK  (may be false positive due to TROR)
927
        ifl wall[p0].nextwall 0 ifl wall[p1].nextwall 0 set tmp 1
928
 
929
        // both red and no wall originating from midpoint on the other side: OK
930
        ifge wall[p0].nextwall 0 ifge wall[p1].nextwall 0
931
        {
932
            set nw wall[p1].nextwall
933
            ifl p1 nw, ife wall[p0].nextwall wall[nw].point2, set tmp 1
934
        }
935
 
936
        ife tmp 1
937
        {
938
            set s1dx wall[p1].x, sub s1dx wall[p0].x
939
            set s1dy wall[p1].y, sub s1dy wall[p0].y
940
 
941
            set s2dx wall[p2].x, sub s2dx wall[p1].x
942
            set s2dy wall[p2].y, sub s2dy wall[p1].y
943
 
944
            // now have segment dx/dy's
945
 
946
            mul s1dx -s2dy
947
            mul s1dy s2dx
948
            set tmp s1dx, add tmp s1dy  // tmp = (s1dx, s1dy) . (-s2dy, s2dx)
949
 
950
            ife tmp 0
951
            {
952
                qsprintf TQUOTE "%d" p1
953
                quote TQUOTE
954
            }
955
        }
956
    }
957
ends
958
 
959
 
1695 helixhorne 960
//////////////////// SPRITE DUPLICATORS ////////////////////
961
 
962
defstate transcnt
963
    ifle cnt 0 { inv cnt, add cnt 128 }
964
ends
965
 
966
define DUP_ROT_MAGIC 123
967
 
968
// duplicates and rotates selected sprites around
969
// pivot sprite with fields
970
//  .extra=123 (magic)
971
//  .ang: angle delta
972
//  .yrepeat*32: z delta (positive if pal!=0, i.e. going down)
973
//  .shade: count (-128 to 0 -> 255 to 128)
974
defstate duprot
1696 helixhorne 975
    ifaimingsprite nullop else return
1695 helixhorne 976
    ifn sprite[searchwall].extra DUP_ROT_MAGIC return
977
 
978
    set p searchwall  // pivot sprite
979
    set cnt sprite[p].shade, state transcnt
980
 
981
    set sprite[p].extra -1
982
 
983
    for i range cnt
984
    {
985
        for j selsprites, ifn j p
986
        {
987
            dupsprite j  // duplicate sprite j, I becomes index of newly created sprite
988
 
989
            set dang i, add dang 1, mul dang sprite[p].ang
990
            rotatepoint sprite[p].x sprite[p].y .x .y dang (x y)
991
            add .ang dang
992
 
993
            set z i, add z 1, mul z sprite[p].yrepeat, shiftl z 5
994
            ife sprite[p].pal 0, inv z
995
            add z .z
996
 
997
            bsetsprite I x y z
998
        }
999
    }
1000
ends
1001
 
1002
// same as above but with tsprite[], as a kind of preview
1003
defstate tduprot
1696 helixhorne 1004
    ifaimingsprite nullop else return
1706 helixhorne 1005
    ifl searchwall 0 return
1695 helixhorne 1006
    ifn sprite[searchwall].extra DUP_ROT_MAGIC return
1007
 
1008
    set p searchwall  // pivot sprite
1009
    set cnt sprite[p].shade, state transcnt
1010
 
1011
    for i range cnt
1012
    {
1013
        for j selsprites, ifn j p
1014
        {
1015
            set k spritesortcnt
1016
            tdupsprite j
1017
 
1018
            set dang i, add dang 1, mul dang sprite[p].ang
1019
            rotatepoint sprite[p].x sprite[p].y tsprite[k].x tsprite[k].y dang (x y)
1020
            add tsprite[k].ang dang
1021
 
1022
            set z i, add z 1, mul z sprite[p].yrepeat, shiftl z 5
1023
            ife sprite[p].pal 0 inv z
1024
            add z tsprite[k].z
1025
 
1026
            set tsprite[k].x x
1027
            set tsprite[k].y y
1028
            set tsprite[k].z z
1029
 
1030
            or tsprite[k].cstat 514
1031
        }
1032
    }
1033
ends
1034
 
1035
define DUP_LIN_MAGIC 234
1036
define DUP_LIN_MAGIC2 345
1037
 
1038
// duplicates and translates selected sprites in the direction between two
1039
// reference sprites with fields
1040
//  .extra=234 (1st sprite), =345 (2nd, aimed at sprite)
1041
//  .shade: count (-128 to 0 -> 255 to 128)
1042
defstate duplin
1696 helixhorne 1043
    ifaimingsprite nullop else return
1695 helixhorne 1044
    ifn sprite[searchwall].extra DUP_LIN_MAGIC2 return
1045
 
1046
    set r searchwall  // 2nd reference point
1047
 
1048
    set cnt sprite[r].shade, state transcnt
1049
 
1050
    set p -1  // 1st reference point
1051
    for i selsprites, ifn i r
1052
    {
1053
        ife .extra DUP_LIN_MAGIC { set p i, break }
1054
    }
1055
    ifl p 0 return
1056
 
1057
    set sprite[p].extra -1
1058
    set sprite[r].extra -1
1059
 
1060
    set dx sprite[r].x, sub dx sprite[p].x
1061
    set dy sprite[r].y, sub dy sprite[p].y
1062
    set dz sprite[r].z, sub dz sprite[p].z
1063
 
1064
    for i range cnt
1065
    {
1066
        for j selsprites, ifn j r
1067
        {
1068
            dupsprite j
1069
 
1070
            set x i, add x 1, mul x dx, add x .x
1071
            set y i, add y 1, mul y dy, add y .y
1072
            set z i, add z 1, mul z dz, add z .z
1073
            bsetsprite I x y z
1074
        }
1075
    }
1076
ends
1077
 
1078
defstate tduplin
1696 helixhorne 1079
    ifaimingsprite nullop else return
1695 helixhorne 1080
    ifn sprite[searchwall].extra DUP_LIN_MAGIC2 return
1081
 
1082
    set r searchwall  // 2nd reference point
1083
 
1084
    set cnt sprite[r].shade, state transcnt
1085
 
1086
    set p -1  // 1st reference point
1087
    for i selsprites, ifn i r
1088
    {
1089
        ife .extra DUP_LIN_MAGIC { set p i, break }
1090
    }
1091
    ifl p 0 return
1092
 
1093
    set dx sprite[r].x, sub dx sprite[p].x
1094
    set dy sprite[r].y, sub dy sprite[p].y
1095
    set dz sprite[r].z, sub dz sprite[p].z
1096
 
1097
    for i range cnt
1098
    {
1099
        for j selsprites, ifn j r
1100
        {
1101
            set k spritesortcnt
1102
            tdupsprite j
1103
 
1104
            set tmp i, add tmp 1, mul tmp dx
1105
            add tsprite[k].x tmp
1106
            set tmp i, add tmp 1, mul tmp dy
1107
            add tsprite[k].y tmp
1108
            set tmp i, add tmp 1, mul tmp dz
1109
            add tsprite[k].z tmp
1110
 
1111
            or tsprite[k].cstat 514
1112
//            bsetsprite I x y z
1113
        }
1114
    }
1115
ends
1116
 
3447 helixhorne 1117
defstate respawnpreview
1118
    var ts ow pic z
1119
    var k onumtspr
1120
 
1121
    ife showrespawn_always 0
1122
    {
1123
        ifaimingsprite ife sprite[searchwall].picnum RESPAWN nullop
4880 helixhorne 1124
        else return
3447 helixhorne 1125
    }
1126
 
1127
    set onumtspr spritesortcnt
1128
 
1129
    for ts range onumtspr
1130
    {
1131
        set ow tsprite[ts].owner
1132
        ife showrespawn_always 0 ifn ow searchwall nullop else
1133
        {
1134
            ife sprite[ow].picnum RESPAWN
1135
            {
1136
                set k spritesortcnt
1137
                tdupsprite ow
1138
 
1139
                // XXX: doesn't work with E1L5 boss RESPAWN...
1140
                // Something's wrong with setting tsprite[] members.
1141
                sub tsprite[k].z 4096
1142
 
1143
                set tsprite[k].xrepeat 16
1144
                set tsprite[k].yrepeat 16
1145
 
1146
                set pic sprite[ow].hitag
1147
                ifge pic 0 ifl pic MAXTILES
1148
                    set tsprite[k].picnum pic
3699 helixhorne 1149
 
1150
                and tsprite[k].cstat 0xfffffdff  // clear bit 512 (reverse translucency)
1151
                or tsprite[k].cstat 2  // set bit 2 (33% translucency)
1152
                ifvarn showrespawn_fulltrans 0
1153
                    or tsprite[k].cstat 512
3447 helixhorne 1154
            }
1155
        }
1156
    }
1157
ends
1158
 
1695 helixhorne 1159
onevent EVENT_ANALYZESPRITES
3447 helixhorne 1160
    state respawnpreview
1695 helixhorne 1161
    state tduprot
1162
    state tduplin
1163
endevent
1164
 
3648 helixhorne 1165
defstate update_headlight
1166
    var li hrz
1167
    set li 0
1168
 
1169
    ifvare headlight_enabled 0
1170
        break
1171
 
3651 helixhorne 1172
    ifvarl cursectnum 0
1173
        break
1174
 
3648 helixhorne 1175
    ifvarn light[li].active 1
1176
        break
1177
 
1178
    set light[li].x posx
1179
    set light[li].y posy
1180
    set light[li].z posz
1181
    set light[li].sector cursectnum
1182
    set hrz horiz
1183
    set light[li].horiz hrz
1184
    set light[li].angle ang
1185
 
1186
    set light[li].range headlight_range
1187
    set light[li].radius 256
1188
    set light[li].faderadius 128
1189
 
1190
    set light[li].r 255
1191
    set light[li].g 255
1192
    set light[li].b 255
1193
    set light[li].priority 0
1194
 
1195
    set light[li].tilenum 0
1196
ends
1197
 
1198
onevent EVENT_PREDRAW3DSCREEN
1199
    state update_headlight
1200
endevent
1201
 
1695 helixhorne 1202
onevent EVENT_KEYS3D
1696 helixhorne 1203
    var l m
1204
 
3704 helixhorne 1205
    ifvarge override_basepal 0
1206
        setgamepalette override_basepal
1207
 
1695 helixhorne 1208
    // door sound tester
1848 helixhorne 1209
    ifeitherctrl ifeithershift ifaimingwall
1695 helixhorne 1210
    ifholdkey KEY_SPACE
1211
    {
1212
        set k wall[searchwall].nextsector
1213
        ifl k 0 set k searchsector
1214
 
1215
        ife sector[k].lotag 0 return
1216
 
1217
        for i spritesofsector k
1218
        {
1219
            ifactor MUSICANDSFX
1220
            ifge .lotag 0 ifl .lotag MAXSOUNDS
1221
            {
1222
                getsoundflags .lotag m
1223
                ifand m 1 nullop else soundonce .lotag
1848 helixhorne 1224
                resetkey KEY_SPACE
1695 helixhorne 1225
            }
1226
        }
1227
    }
1228
 
1848 helixhorne 1229
    // swinging doors tester -- hit Ctrl-Shift-SPACE on a door wall
1230
    ifeitherctrl ifeithershift ifaimingwall
1231
    ifholdkey KEY_SPACE  // SE11 ST23 up:ccw
1695 helixhorne 1232
    {
1233
        set k wall[searchwall].nextsector
1234
        ifl k 0 return
1235
        ifn sector[k].lotag 23 return
1848 helixhorne 1236
 
1237
        resetkey KEY_SPACE
1238
 
1695 helixhorne 1239
        set tmp 0
1240
        for i loopofwall searchwall
1241
        {
1242
            ifl wall[i].nextsector 0 set tmp 1 else
1243
            ifn wall[i].nextsector k set tmp 1
1244
        }
1245
// a weaker condition
1246
//        for i loopofwall wall[searchwall].nextwall
1247
//        {
1248
//            ifl wall[i].nextsector 0 set tmp 1 else
1249
//            ifn wall[i].nextsector searchsector set tmp 1
1250
//        }
1251
        ifn tmp 0
1252
        {
1253
            quote "door sector not an island sector!"
1254
            return
1255
        }
1256
 
1257
        set l -1
1258
        for i spritesofsector k
1259
        {
1260
            ifactor SECTOREFFECTOR ife sprite[i].lotag 11
1261
            {
1262
                set l i
1263
                ifn sprite[i].ang 512 ifn sprite[i].ang 1024 ifn sprite[i].ang 1536 set l -1
1264
            }
1265
        }
1266
        ifl l 0
1267
        {
1268
            quote "door sector has no SE sprite!"
1269
            return
1270
        }
1271
 
1272
        for tmp wallsofsector k
1273
        {
1274
            rotatepoint (sprite[l].x sprite[l].y) (wall[tmp].x wall[tmp].y) sprite[l].ang (i j)
1275
            dragpoint tmp i j
1276
        }
1277
        for tmp spritesofsector k
1278
        {
1279
            ifn tmp l
1280
            {
1281
                rotatepoint (sprite[l].x sprite[l].y) (sprite[tmp].x sprite[tmp].y) sprite[l].ang (i j)
1282
                bsetsprite tmp i j sprite[tmp].z
1283
            }
1284
        }
1285
        inv sprite[l].ang
1286
    }
1287
 
1288
    // teleporter -- works on SE7 and SE17 (elevator)
1854 helixhorne 1289
    ifeitheralt ifaimingsprite
1848 helixhorne 1290
    ifholdkey KEY_SPACE
1695 helixhorne 1291
    {
1292
        ife sprite[searchwall].picnum SECTOREFFECTOR
1293
        {
1294
            set tmp 0
1295
            ife sprite[searchwall].lotag 7 set tmp 1
1296
            ife sprite[searchwall].lotag 17 set tmp 1
1297
            ife tmp 0 return
1298
 
1848 helixhorne 1299
            resetkey KEY_SPACE
1300
 
1695 helixhorne 1301
            for i allsprites
1302
            {
1303
                ifn i searchwall, ifactor SECTOREFFECTOR, ife sprite[i].lotag sprite[searchwall].lotag
1304
                ife sprite[i].hitag sprite[searchwall].hitag
1305
                {
1306
                    add posx sprite[i].x, sub posx sprite[searchwall].x
1307
                    add posy sprite[i].y, sub posy sprite[searchwall].y
1308
                    add posz sprite[i].z, sub posz sprite[searchwall].z
1309
 
1310
                    updatecursectnum
1311
 
1312
                    return
1313
                }
1314
            }
1315
        }
1316
        else ife sprite[searchwall].extra DUP_ROT_MAGIC
1317
        {
1318
            state duprot
1848 helixhorne 1319
            resetkey KEY_SPACE
1695 helixhorne 1320
        }
1321
        else ife sprite[searchwall].extra DUP_LIN_MAGIC2
1322
        {
1323
            state duplin
1848 helixhorne 1324
            resetkey KEY_SPACE
1695 helixhorne 1325
        }
1326
    }
1327
 
1706 helixhorne 1328
 
1329
    set j 0
1330
 
1331
    set k 0
1332
    ifholdkey KEY_7 set k -1
1333
    ifholdkey KEY_0 set k 1
1334
    ifn k 0
1695 helixhorne 1335
    {
1706 helixhorne 1336
        set j 1
1337
        ifeithershift nullop else mul k 256
1338
        add davr k
1695 helixhorne 1339
        ifl davr 32768 set davr 32768
1340
        ifg davr 256000 set davr 256000
1706 helixhorne 1341
    }
1342
 
1343
    set k 0
1344
    ifholdkey KEY_8 set k -1
1345
    ifholdkey KEY_9 set k 1
1346
    ifn k 0
1347
    {
1348
        set j 1
1349
        ifeithershift nullop else mul k 256
1350
        add dayx k
1351
        ifl dayx 32768 set dayx 32768
1352
        ifg dayx 256000 set dayx 256000
1353
    }
1354
    ife j 1
1355
    {
1712 helixhorne 1356
//        setaspect davr dayx
1357
        state setas
1358
        qsprintf TQUOTE "ASPECT: davr=%d, dayx=%d | FVR=%d, FYX=%d" davr dayx fvr fyx
1695 helixhorne 1359
        quote TQUOTE
1360
    }
1361
endevent
1362
 
1363
defstate replacestuff
1364
    for i spritesofsector searchsector
1365
//        ife sprite[i].picnum AMMO set sprite[i].picnum BATTERYAMMO
1366
        ifactor parm[0] cactor parm[1]
1367
ends
1368
 
1369
defstate convlights  // convert (0,0,0) lights to (255,255,255)-ones
1370
	for i allsprites ifactor 1 ifge .lotag 49 ifle .lotag 50 ife .xvel 0 ife .yvel 0 ife .zvel 0
1371
        { set .xvel 255 set .yvel 255 set .zvel 255 }
1372
ends
1373
 
1374
defstate resetallws  // reset all sprites and walls to default repeat/panning
1375
    for i allsprites
1376
	{
1377
		set .xrepeat 64
1378
        set .yrepeat 64
1379
	}
1380
    for i allwalls
1381
	{
1382
		set wall[i].cstat 0
1383
		set wall[i].xpanning 0
1384
		set wall[i].ypanning 0
1385
		set wall[i].yrepeat 8
1386
		fixrepeats i
1387
	}
1388
ends
1389
 
1390
defstate js  // jump to current sprite
1391
    set posx .x
1392
    set posy .y
1393
    set posz .z
1394
    updatecursectnum
1395
ends
1396
 
1836 helixhorne 1397
defstate jumptowal  // (wal)
1398
    ifge wal 0 ifl wal numwalls nullop else return
1399
    set posx wall[wal].x
1400
    set posy wall[wal].y
1695 helixhorne 1401
    updatecursectnum
1402
ends
1403
 
1836 helixhorne 1404
defstate jumptosec  // (sec)
1405
    ifge sec 0 ifl sec numsectors nullop else return
1406
    set wal sector[sec].wallptr
1407
    state jumptowal
1408
ends
1695 helixhorne 1409
 
1836 helixhorne 1410
 
1722 helixhorne 1411
onevent EVENT_DRAW2DSCREEN
1412
    var tmp
4421 helixhorne 1413
    var xx yy
1722 helixhorne 1414
 
1832 helixhorne 1415
    state userdrawlabel
1416
 
1722 helixhorne 1417
    ifge cursectnum 0
1418
    {
1419
        state connectlocators
1420
        state draw_prlightprojections
1421
    }
1422
 
1423
    state previewdoors2d
1424
 
1730 helixhorne 1425
    ifn showpal 0
1426
    {
1427
        set xx 100
1428
        for tmp range 256
1429
        {
1430
            drawline16 xx 100 xx 200 -tmp
1431
            add xx 1
1432
            drawline16 xx 100 xx 200 -tmp
1433
            add xx 1
1434
            ifge tmp 240
1435
            {
1436
                drawline16 xx 100 xx 200 -tmp
1437
                add xx 1
1438
                drawline16 xx 100 xx 200 -tmp
1439
                add xx 1
1440
            }
1441
        }
4421 helixhorne 1442
 
1443
        set yy 208
1444
        for tmp range 16
1445
        {
1446
            qsprintf TQUOTE "editor color %d" tmp
1447
            printext16 TQUOTE 100 yy tmp 0 0
1448
            printext16 TQUOTE 260 yy 0 tmp 0
1449
            add yy 8
1450
        }
1730 helixhorne 1451
    }
1722 helixhorne 1452
endevent
1453
 
1454
 
1710 helixhorne 1455
defstate mkterrain
1456
    var w2 w3 idx bit tmp sec
1457
    var warned
1458
 
1459
    set warned 0
1460
 
1461
    for i selwalls
1462
    {
1463
        sectorofwall j i
1464
        set tmp 0, ifand sector[j].floorstat 2, set tmp 1  // already handled
1465
        ife tmp 0 ife sector[j].wallnum 3
1466
        {
1467
            set w2 wall[i].point2
1468
            set idx w2, shiftr idx 3
1469
            set tmp w2, and tmp 7, set bit 1, shiftl bit tmp
1470
            ifand show2dwall[idx] bit
1471
            {
1472
                setfirstwall j i
1473
 
1474
                set z 0x7ffffff
1475
                ifin3dmode
1476
                {
1477
                    ife searchstat 2  // floor
1478
                        set z sector[searchsector].floorz
1479
                }
1480
                else
1481
                {
1482
                    for k allsectors
1483
                    {
1484
                        ifinside mousxplc mousyplc k
1485
                        {
1486
                            set z sector[k].floorz
1487
                            break
1488
                        }
1489
                    }
1490
                }
1491
 
1492
                ife z 0x7ffffff
1493
                {
1494
                    ife warned 0
1495
                    {
1496
                        quote "Mouse pointer must be aiming at sector floor."
1497
                        set warned 1
1498
                    }
1499
                }
1500
                else
1501
                {
1502
                    set w3 wall[w2].point2
1503
                    set sec wall[i].nextsector
1504
                    ifge sec 0
1505
                        set sector[j].floorz sector[sec].floorz
1506
                    alignflorslope j wall[w3].x wall[w3].y z
1507
                }
1508
            }
1509
        }
1510
    }
1511
ends
1731 helixhorne 1512
 
1513
defstate chselshade
1514
    for i selsectors
1515
    {
1516
        set sector[i].floorshade tempshade
1517
        set sector[i].ceilingshade tempshade
1518
 
1519
        for j spritesofsector i
1520
            set .shade tempshade
1521
 
1522
        for j wallsofsector i
1523
            set wall[j].shade tempshade
1524
    }
1525
ends
1526
 
2590 helixhorne 1527
defstate listusedtags
1528
    for i allsprites
1529
    {
1530
        getspritelinktype i k
1531
 
1532
        ifn k 0
1533
        {
1534
            ife k 1
1535
                qsprintf TQUOTE "sprite %d lotag %d" i sprite[i].lotag
1536
            else ife k 2
1537
                qsprintf TQUOTE "sprite %d hitag %d" i sprite[i].hitag
1538
            quote TQUOTE
1539
        }
1540
    }
1541
ends
1542
 
4042 helixhorne 1543
defstate moveselsects
1544
    var p1 dx dy
1545
 
1546
    for i selsectors
1547
    {
1548
        set p1 sector[i].wallptr
1549
        set dx wall[p1].x, set dy wall[p1].y
1550
        for j wallsofsector i
1551
        {
1552
            sub wall[j].x dx
1553
            sub wall[j].y dy
1554
        }
1555
        for j spritesofsector i
1556
        {
1557
            sub .x dx
1558
            sub .y dy
1559
        }
1560
    }
1561
ends
1562
 
4169 helixhorne 1563
defstate sanitize_underwater_sprites
1564
    "Xvel=1 for wall/flr spr."
1565
    for i selsprites
1566
    {
1567
        set j .cstat
1568
        and j 49
1569
        ife j 17 set .xvel 1
1570
        ife j 33 set .xvel 1
1571
    }
1572
    printmessage16 "Set xvel=1 on highlighted wall/floor sprites"
1573
ends
1574
 
4357 helixhorne 1575
define BZ_MAX 8388608
1576
 
1577
defstate uniformceil
1578
    var avgz n
1579
 
1580
    for i selsectors
1581
    {
1582
        ifand sector[i].ceilingstat 2 xor sector[i].ceilingstat 2
1583
        add avgz sector[i].ceilingz
1584
        add n 1
1585
    }
1586
 
1587
    ife n 0 break
1588
 
1589
    div avgz n
1590
    and avgz 0xfffffc00  // round to one PGUP/PNDN unit (1024 z units)
1591
 
1592
    ifvarge avgz -BZ_MAX ifvarle avgz BZ_MAX nullop
1593
    else quote "ERROR: average z value outside [-8388608 .. 8388608]"  // BZ_MAX
1594
 
1595
    for i selsectors
1596
        set sector[i].ceilingz avgz
1597
ends
1598
 
1599
// XXX: CODEDUP
1600
defstate uniformfloor
1601
    var avgz n
1602
 
1603
    for i selsectors
1604
    {
1605
        ifand sector[i].floorstat 2 xor sector[i].floorstat 2
1606
        add avgz sector[i].floorz
1607
        add n 1
1608
    }
1609
 
1610
    ife n 0 break
1611
 
1612
    div avgz n
1613
    and avgz 0xfffffc00  // round to one PGUP/PNDN unit (1024 z units)
1614
 
1615
    ifvarge avgz -BZ_MAX ifvarle avgz BZ_MAX nullop
1616
    else quote "ERROR: average z value outside [-8388608 .. 8388608]"  // BZ_MAX
1617
 
1618
    for i selsectors
1619
        set sector[i].floorz avgz
1620
ends
1621
 
4414 helixhorne 1622
defstate for_sprites_near_picnum
1623
    "Ch. lotag for near spr."
1624
 
1625
    var ii dst
1626
    var picnumi picnumj maxldist lotag
1627
 
1628
    getnumberfromuser picnumi "picnum i: " MAXTILES 10
1629
    ifvarl picnumi 0 break
1630
    getnumberfromuser picnumj "picnum j: " MAXTILES 10
1631
    ifvarl picnumj 0 break
1632
 
1633
    getnumberfromuser maxldist "max ldist: " 65536 8
1634
    ifvarl maxldist 0 break
1635
 
1636
    getnumberfromuser lotag "lotag (unsigned) to change to: " 65536 8
1637
    ifvarl lotag 0 break
1638
 
1639
    for i allsprites ife sprite[i].picnum picnumi
1640
        for j allsprites ife sprite[j].picnum picnumj
1641
        {
1642
            ldist dst i j
1643
            ifle dst maxldist
1644
                set sprite[j].lotag lotag
1645
        }
1646
 
1647
    qsprintf TQUOTE "changed lotag of sprites w/ tile %d near those w/ tile %d to %d" picnumj picnumi lotag
1648
    quote TQUOTE
1649
ends
1650
 
2808 helixhorne 1651
// This must be *compiled* with script_expertmode
1652
/*
1653
defstate setstartpos
1654
    "Set start pos. from spr."
1655
    var spr
1656
    getnumberfromuser spr "sprite number: " MAXSPRITES 8
1657
 
1658
    seti spr
1659
    set startposx .x
1660
    set startposy .y
1661
    set startposz .z
1662
    set startsector .sectnum
1663
    set startang .ang
1664
ends
1665
*/
1666
 
1832 helixhorne 1667
////////// USER AREA //////////
1668
 
1669
// key settings
1731 helixhorne 1670
defstate userkeys_3d
2820 helixhorne 1671
/*
1672
    ifge searchwall 0 ifl searchwall MAXWALLS
1673
    ifholdkey KEY_KP5
1674
    {
1675
        add wall[searchwall].ypanning 1
1676
        set DOSCRSHOT 1
1677
    }
1678
*/
1731 helixhorne 1679
    ifholdkey KEY_SEMI ifhitkey KEY_C state chselshade
1680
ends
1832 helixhorne 1681
 
2820 helixhorne 1682
gamevar scrshot 0 1
1683
 
3752 helixhorne 1684
////////// DRAW TILE (ROTATESPRITE) TESTING //////////
1685
gamevar dt_t -1 0  // tilenum
1686
gamevar dt_x 160 0 // x
1687
gamevar dt_y 100 0 // y
1688
gamevar dt_z 65536 0  // zoom
1689
gamevar dt_a 0 0  // angle
1690
gamevar dt_s 0 0  // shade
1691
gamevar dt_p 0 0  // pal
1692
gamevar dt_o 0 0  // orientation
1693
gamevar dt_A 0 0  // alpha
1694
 
3509 helixhorne 1695
onevent EVENT_DRAW3DSCREEN
3752 helixhorne 1696
    ifge dt_t 0
1697
        rotatespritea dt_x dt_y dt_z dt_a dt_t dt_s dt_p dt_o dt_A 0 0 xdim ydim
1698
 
3509 helixhorne 1699
    ifn move_by_one 0
1700
    {
1701
        qsprintf TQUOTE "x,y,z = %d, %d, %d" posx posy posz
1702
        printext256 TQUOTE 30 30 -15 0 0
1703
 
1704
        qsprintf TQUOTE "horiz,ang = %d, %d" horiz ang
1705
        printext256 TQUOTE 30 40 -15 0 0
1706
    }
1707
 
2820 helixhorne 1708
/*
1709
    ifge searchwall 0, ifl searchwall MAXWALLS
1710
    {
3395 helixhorne 1711
        // Which wall is considered targeted?
1712
        qsprintf TQUOTE "searchwall = %d" searchwall
1713
        printext256 TQUOTE 30 30 -15 0 0
1714
 
2820 helixhorne 1715
        qsprintf TQUOTE "y panning = %d" wall[searchwall].ypanning
3447 helixhorne 1716
        printext256 TQUOTE 30 40 -15 0 0
2820 helixhorne 1717
    }
3509 helixhorne 1718
*/
2820 helixhorne 1719
endevent
1720
 
2122 helixhorne 1721
// convenience rebindings for notebooks:
1722
//  Alt-F11 --> SCROLL LOCK (set first position)
1723
//  Alt-arrows --> KP arrows (change pan/repeat in 3D mode)
1724
onevent EVENT_KEYPRESS
1725
    var thekey
1726
    set thekey RETURN
1727
 
1728
    ifvare use_notebook_keys 0, return
1832 helixhorne 1729
/*
2122 helixhorne 1730
    ifholdkey thekey
1731
        qsprintf TQUOTE "pressed %d" thekey
1732
    else
1733
        qsprintf TQUOTE "released %d" thekey
1734
    print TQUOTE
1735
*/
1736
    ifholdkey thekey  // if the callback key was pressed (and not released)
1737
    {
1738
        ifholdkey KEY_LALT
1739
        {
1740
            ifhitkey KEY_F11, setkey KEY_SCROLL
1741
 
1742
            ifhitkey KEY_UP, setkey KEY_KP8
1743
            ifhitkey KEY_DOWN, setkey KEY_KP2
1744
            ifhitkey KEY_LEFT, setkey KEY_KP4
1745
            ifhitkey KEY_RIGHT, setkey KEY_KP6
1746
 
1747
// would be 'cleaner' (only checking cb key) but is too much code for my taste:
1748
/*
1749
            switch (thekey)
1750
            {
1751
                case KEY_F11: setkey KEY_SCROLL; resetkey thekey; break;
1752
 
1753
                // and so on with the rest...
1754
            }
1755
            endswitch
1756
*/
1757
        }
1758
    }
1759
    else  // cb key was released
1760
    {
1761
        switch (thekey)
1762
        {
1763
            case KEY_LALT:
1764
            {
1765
                resetkey KEY_KP8;
1766
                resetkey KEY_KP2;
1767
                resetkey KEY_KP4;
1768
                resetkey KEY_KP6;
1769
                break;
1770
            }
1771
 
1772
            case KEY_UP: resetkey KEY_KP8; break;
1773
            case KEY_DOWN: resetkey KEY_KP2; break;
1774
            case KEY_LEFT: resetkey KEY_KP4; break;
1775
            case KEY_RIGHT: resetkey KEY_KP6; break;
1776
        }
1777
        endswitch
1778
    }
1779
endevent
1780
 
1781
/*
1832 helixhorne 1782
// example for custom labels
1783
defstate userdrawlabel
1784
    for i allsprites
1785
    {
1786
        ifactor 2978
1787
        {
1788
            qsprintf TQUOTE "MOVABLE EX:%d OW:%d", sprite[i].owner, sprite[i].extra
1789
            drawlabel TQUOTE .x .y .z 0 31
1790
        }
1791
    }
1792
ends
1793
*/