Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R7/Spotlights2.txt
1319 views
1
//----------------Sonic CD Spotlights 2 Script----------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
7
// Position for where the checkpoint should progress to its next version
8
#alias Object.Value1 : Object.Checkpoint
9
10
// The colors the Spotlight should use
11
// Just like everything else, these colors are in RRGGBB
12
#alias Object.Value2 : Object.PrimaryBaseColor
13
#alias Object.Value3 : Object.SecondaryBaseColor
14
#alias Object.Value4 : Object.PrimaryDisplayColor
15
#alias Object.Value5 : Object.SecondaryDisplayColor
16
17
// There are several different types of spotlights that appear in the stage
18
#alias Object.Value0 : Object.SpotlightType
19
// 0 - Pair of two primary ones
20
// - Using SSZ2A's, it's the two small green ones
21
// 1 - Single primary one
22
// - Using SSZ2A's, it's a single green one
23
// 2 - Pair of two secondary ones
24
// - Using SSZ2A's, it's a pair of big and small yellow ones
25
// 3 - Single small primary one
26
// - Using SSZ2A's, it's a single big green one
27
// 4 - Pair of primary and secondary
28
// - Using SSZ2A's, the pair of a big green one with a small yellow one
29
// Then it loops back
30
31
// HUD Alias
32
#alias Object[24].PropertyValue : HUD.CurrentTimePeriod
33
34
// Time Periods
35
#alias 0 : TIME_PRESENT
36
#alias 2 : TIME_GOOD_FUTURE
37
#alias 3 : TIME_BAD_FUTURE
38
39
// Priority
40
#alias 1 : PRIORITY_ACTIVE
41
42
// Face Buffer Flags
43
#alias 3 : FACE_FLAG_COLOURED_2D
44
45
// Function declarations
46
#function Spotlights_UpdateCorner
47
48
49
function Spotlights_UpdateCorner
50
51
// Called individually for each corner in a spotlight to update it
52
// Preconditions:
53
// - ArrayPos0 is the ID of the vertex that should be changes
54
// - TempValue0 is the X multiplier for how much extra this vertex should move
55
// - TempValue1 is the Y multiplier for how much extra this vertex should move
56
// (These last two values are here since spotlights aren't uniform in width - they can be skewed to uneven dimensions as well)
57
58
59
Sin(TempValue2, Object.Rotation)
60
TempValue2 *= TempValue1
61
62
Cos(TempValue3, Object.Rotation)
63
TempValue3 *= TempValue0
64
65
VertexBuffer[ArrayPos0].x = TempValue2
66
VertexBuffer[ArrayPos0].x -= TempValue3
67
VertexBuffer[ArrayPos0].x >>= 9
68
VertexBuffer[ArrayPos0].x += Object.XPos
69
70
Cos(TempValue2, Object.Rotation)
71
TempValue2 *= TempValue1
72
73
Sin(TempValue3, Object.Rotation)
74
TempValue3 *= TempValue0
75
76
VertexBuffer[ArrayPos0].y = TempValue2
77
VertexBuffer[ArrayPos0].y += TempValue3
78
VertexBuffer[ArrayPos0].y >>= 9
79
VertexBuffer[ArrayPos0].y += 256
80
81
end function
82
83
84
sub ObjectMain
85
TempValue0 = Oscillation
86
TempValue0 <<= 2
87
88
// Get some smooth arc movement values
89
90
Sin(TempValue1, TempValue0)
91
TempValue1 >>= 5
92
TempValue1 += 64
93
94
Cos(TempValue2, TempValue0)
95
TempValue2 >>= 5
96
TempValue2 += 64
97
98
// Make the spotlight colors oscillate
99
100
Object.PrimaryDisplayColor = TempValue1
101
Object.PrimaryDisplayColor <<= 24
102
Object.PrimaryDisplayColor += Object.PrimaryBaseColor
103
104
Object.SecondaryDisplayColor = TempValue2
105
Object.SecondaryDisplayColor <<= 24
106
Object.SecondaryDisplayColor += Object.SecondaryBaseColor
107
108
// Check to see if we need to cycle the Spotlight type now
109
110
TempValue0 = Screen.XOffset
111
TempValue0 += Screen.CenterX
112
if TempValue0 > Object.Checkpoint
113
TempValue0 -= Object.Checkpoint
114
if TempValue0 > 460
115
// We do indeed need to advance the spotlight type by 1...
116
117
// Move the next checkpoint ahead
118
Object.Checkpoint += 920
119
120
// Cycle the Spotlight type ahead
121
Object.SpotlightType++
122
123
if Object.SpotlightType > 4
124
// Keeping an upper limit of 4 in mind
125
Object.SpotlightType = 0
126
end if
127
end if
128
else
129
TempValue0 -= Object.Checkpoint
130
if TempValue0 < -460
131
// We do indeed need to go back the spotlight type by 1...
132
133
// Move the next checkpoint back a bit
134
Object.Checkpoint -= 920
135
136
// Go back a Spotlight type
137
Object.SpotlightType--
138
139
if Object.SpotlightType < 0
140
// Keeping a lower limit of 0 in mind
141
Object.SpotlightType = 4
142
end if
143
end if
144
end if
145
146
// And then position the Spotlight based on the current checkpoint
147
Object.XPos = Object.Checkpoint
148
Object.XPos -= Screen.XOffset
149
150
switch Object.SpotlightType
151
case 0
152
// Pair of two small primary Spotlights
153
154
// These should draw above everything else
155
Object.DrawOrder = 5
156
157
// 2 rectangles... 8 corners and 2 faces!
158
3DScene.NoVertices = 8
159
3DScene.NoFaces = 2
160
161
// Spotlight 1 position offset, just a wee bit to the left
162
Object.XPos -= 64
163
164
// Both in these pair will use the primary color
165
FaceBuffer[0].Color = Object.PrimaryDisplayColor
166
FaceBuffer[1].Color = Object.PrimaryDisplayColor
167
168
// Get Spotlight 1's rotation
169
TempValue0 = Oscillation
170
Sin(Object.Rotation, TempValue0)
171
Object.Rotation >>= 4
172
Object.Rotation += 520
173
174
// And now create the spotlight
175
176
// Top right of Spotlight 1
177
ArrayPos0 = 0
178
TempValue0 = -16
179
TempValue1 = -384
180
CallFunction(Spotlights_UpdateCorner)
181
182
// Top left of Spotlight 1
183
ArrayPos0++
184
TempValue0 = 16
185
TempValue1 = -384
186
CallFunction(Spotlights_UpdateCorner)
187
188
// Bottom right of Spotlight 1
189
ArrayPos0++
190
TempValue0 = -8
191
TempValue1 = 0
192
CallFunction(Spotlights_UpdateCorner)
193
194
// Bottom left of Spotlight 1
195
ArrayPos0++
196
TempValue0 = 8
197
TempValue1 = 0
198
CallFunction(Spotlights_UpdateCorner)
199
200
ArrayPos0++
201
202
// Spotlight 2 is a bit more to the right, instead
203
// (+64 gain from base Spotlight position)
204
Object.XPos += 128
205
206
// Get Spotlight 2's rotation
207
TempValue0 = Oscillation
208
TempValue0 <<= 1
209
Sin(Object.Rotation, TempValue0)
210
Object.Rotation /= 10
211
Object.Rotation += 512
212
213
// Top right of Spotlight 2
214
TempValue0 = -16
215
TempValue1 = -384
216
CallFunction(Spotlights_UpdateCorner)
217
218
// Top left of Spotlight 2
219
ArrayPos0++
220
TempValue0 = 16
221
TempValue1 = -384
222
CallFunction(Spotlights_UpdateCorner)
223
224
// Bottom right of Spotlight 2
225
ArrayPos0++
226
TempValue0 = -8
227
TempValue1 = 0
228
CallFunction(Spotlights_UpdateCorner)
229
230
// Bottom left of Spotlight 2
231
ArrayPos0++
232
TempValue0 = 8
233
TempValue1 = 0
234
CallFunction(Spotlights_UpdateCorner)
235
236
ArrayPos0++
237
break
238
239
case 1
240
// Single slim primary Spotlight
241
242
// This Spotlight will draw behind everything, way in the background
243
Object.DrawOrder = 2
244
245
// A single rectangle, that just means a single face, with 4 corners
246
3DScene.NoVertices = 4
247
3DScene.NoFaces = 1
248
249
// This Spotlight will use the primary color
250
FaceBuffer[0].Color = Object.PrimaryDisplayColor
251
252
// Get the Spotlight's rotation
253
TempValue0 = Oscillation
254
TempValue0 <<= 1
255
Sin(Object.Rotation, TempValue0)
256
Object.Rotation >>= 3
257
Object.Rotation += 512
258
259
// Top right corner of the Spotlight
260
ArrayPos0 = 0
261
TempValue0 = -16
262
TempValue1 = -384
263
CallFunction(Spotlights_UpdateCorner)
264
265
// Top left corner of the Spotlight
266
ArrayPos0++
267
TempValue0 = 16
268
TempValue1 = -384
269
CallFunction(Spotlights_UpdateCorner)
270
271
// Bottom right corner of the Spotlight
272
ArrayPos0++
273
TempValue0 = -8
274
TempValue1 = 0
275
CallFunction(Spotlights_UpdateCorner)
276
277
// Bottom left corner of the Spotlight
278
ArrayPos0++
279
TempValue0 = 8
280
TempValue1 = 0
281
CallFunction(Spotlights_UpdateCorner)
282
283
ArrayPos0++
284
break
285
286
case 2
287
// Pair of two secondary spotlights
288
289
// These pair draw above everything, being the bright and shining pair they are
290
Object.DrawOrder = 5
291
292
// 8 corners? No this isn't an octagon, it's a pair of rectangles!
293
3DScene.NoVertices = 8
294
3DScene.NoFaces = 2
295
296
// Set the colors for the Spotlights...
297
FaceBuffer[0].Color = Object.SecondaryDisplayColor
298
FaceBuffer[1].Color = Object.SecondaryDisplayColor
299
300
// Get the initial spotlight offset...
301
Object.XPos -= 48
302
303
// And then set the Spotlight colors again? What?
304
FaceBuffer[0].Color = Object.SecondaryDisplayColor
305
FaceBuffer[1].Color = Object.SecondaryDisplayColor
306
307
// Get the rotation for Spotlight 1
308
TempValue0 = Oscillation
309
TempValue0 <<= 1
310
Sin(Object.Rotation, TempValue0)
311
Object.Rotation >>= 4
312
Object.Rotation += 500
313
314
// Top right corner of Spotlight 1
315
ArrayPos0 = 0
316
TempValue0 = -20
317
TempValue1 = -384
318
CallFunction(Spotlights_UpdateCorner)
319
320
// Top left corner of Spotlight 1
321
ArrayPos0++
322
TempValue0 = 20
323
TempValue1 = -384
324
CallFunction(Spotlights_UpdateCorner)
325
326
// Bototm right corner of Spotlight 1
327
ArrayPos0++
328
TempValue0 = -10
329
TempValue1 = 0
330
CallFunction(Spotlights_UpdateCorner)
331
332
// Bottom left corner of Spotlight 1
333
ArrayPos0++
334
TempValue0 = 10
335
TempValue1 = 0
336
CallFunction(Spotlights_UpdateCorner)
337
338
ArrayPos0++
339
340
// Move Spotlight 2 to the right a bit, total change of +48 from base position
341
Object.XPos += 96
342
343
// And get the rotation for this second Spotlight, too
344
TempValue0 = Oscillation
345
TempValue0 += 32
346
TempValue0 <<= 1
347
Sin(Object.Rotation, TempValue0)
348
Object.Rotation >>= 3
349
Object.Rotation += 508
350
351
// Top right corner of Spotlight 2
352
TempValue0 = -16
353
TempValue1 = -420
354
CallFunction(Spotlights_UpdateCorner)
355
356
// Top left corner of Spotlight 2
357
ArrayPos0++
358
TempValue0 = 16
359
TempValue1 = -420
360
CallFunction(Spotlights_UpdateCorner)
361
362
// Bottom right corner of Spotlight 2
363
ArrayPos0++
364
TempValue0 = -8
365
TempValue1 = 0
366
CallFunction(Spotlights_UpdateCorner)
367
368
// Bottom left corner of Spotlight 2
369
ArrayPos0++
370
TempValue0 = 8
371
TempValue1 = 0
372
CallFunction(Spotlights_UpdateCorner)
373
374
ArrayPos0++
375
break
376
377
case 3
378
// Single large primary Spotlight
379
Object.DrawOrder = 5
380
381
// Just a single Spotlight, 4 corners, and 1 face, nothing more, nothing less
382
3DScene.NoVertices = 4
383
3DScene.NoFaces = 1
384
385
// This Spotlight will follow the Primary color for the stage
386
FaceBuffer[0].Color = Object.PrimaryDisplayColor
387
388
// Get the rotation for the Spotlight to be, well rotated at!
389
TempValue0 = 512
390
TempValue0 -= Oscillation
391
TempValue0 *= 3
392
Sin(Object.Rotation, TempValue0)
393
Object.Rotation /= 12
394
Object.Rotation += 520
395
396
// Top right corner of the Spotlight
397
ArrayPos0 = 0
398
TempValue0 = -24
399
TempValue1 = -384
400
CallFunction(Spotlights_UpdateCorner)
401
402
// Top left corner of the Spotlight
403
ArrayPos0++
404
TempValue0 = 24
405
TempValue1 = -384
406
CallFunction(Spotlights_UpdateCorner)
407
408
// Bottom right corner of the Spotlight
409
ArrayPos0++
410
TempValue0 = -16
411
TempValue1 = 0
412
CallFunction(Spotlights_UpdateCorner)
413
414
// Bottom left corner of the Spotlight
415
ArrayPos0++
416
TempValue0 = 16
417
TempValue1 = 0
418
CallFunction(Spotlights_UpdateCorner)
419
420
ArrayPos0++
421
break
422
423
case 4
424
// A big Primary one and a really small secondary one
425
426
// This pair will draw pretty low, behind the stage and all that stuff
427
Object.DrawOrder = 2
428
429
// 2 Spotlights, 2 times 4 is 8, 8 divided by 4 is 2
430
3DScene.NoVertices = 8
431
3DScene.NoFaces = 2
432
433
// Initial offset for Spotlight 1
434
Object.XPos -= 48
435
436
// Set the colors both Spotlights
437
FaceBuffer[0].Color = Object.SecondaryDisplayColor
438
FaceBuffer[1].Color = Object.PrimaryDisplayColor
439
440
// Get the rotation for the first in the pair
441
TempValue0 = Oscillation
442
TempValue0 += 64
443
TempValue0 <<= 1
444
Sin(Object.Rotation, TempValue0)
445
Object.Rotation /= 20
446
Object.Rotation += 496
447
448
// Top right corner of Spotlight 1
449
ArrayPos0 = 0
450
TempValue0 = -14
451
TempValue1 = -420
452
CallFunction(Spotlights_UpdateCorner)
453
454
// Top left corner of Spotlight 1
455
ArrayPos0++
456
TempValue0 = 14
457
TempValue1 = -420
458
CallFunction(Spotlights_UpdateCorner)
459
460
// Bottom right corner of Spotlight 1
461
ArrayPos0++
462
TempValue0 = -4
463
TempValue1 = 0
464
CallFunction(Spotlights_UpdateCorner)
465
466
// Bottom left corner of Spotlight 1
467
ArrayPos0++
468
TempValue0 = 4
469
TempValue1 = 0
470
CallFunction(Spotlights_UpdateCorner)
471
472
ArrayPos0++
473
474
// Spotlight 2 is to the right, for a total of +48 from the base position
475
Object.XPos += 96
476
477
// And get this secondary Spotlight's rotation as well
478
TempValue0 = Oscillation
479
TempValue0 <<= 2
480
Sin(Object.Rotation, TempValue0)
481
Object.Rotation >>= 4
482
Object.Rotation += 520
483
484
// Top right corner of Spotlight 2
485
TempValue0 = -20
486
TempValue1 = -420
487
CallFunction(Spotlights_UpdateCorner)
488
489
// Top left corner of Spotlight 2
490
ArrayPos0++
491
TempValue0 = 20
492
TempValue1 = -420
493
CallFunction(Spotlights_UpdateCorner)
494
495
// Bottom right corner of Spotlight 2
496
ArrayPos0++
497
TempValue0 = -14
498
TempValue1 = 0
499
CallFunction(Spotlights_UpdateCorner)
500
501
// Bottom left corner of Spotlight 2
502
ArrayPos0++
503
TempValue0 = 14
504
TempValue1 = 0
505
CallFunction(Spotlights_UpdateCorner)
506
507
ArrayPos0++
508
break
509
510
end switch
511
512
end sub
513
514
515
sub ObjectDraw
516
// The spotlights are 3d, so draw an entire 3d scene
517
Draw3DScene()
518
519
end sub
520
521
522
sub ObjectStartup
523
524
// Reset the 3d stuff
525
MatrixTranslateXYZ(MAT_WORLD, 0, 0, 0)
526
MatrixTranslateXYZ(MAT_VIEW, 0, 0, 0)
527
528
// Setup the first spotlight
529
FaceBuffer[0].a = 0
530
FaceBuffer[0].b = 1
531
FaceBuffer[0].c = 2
532
FaceBuffer[0].d = 3
533
FaceBuffer[0].Flag = FACE_FLAG_COLOURED_2D
534
535
// And now setup the second spotlight
536
// It doesn't always appear though, there are some Spotlight configurations where only 1 will show at a time
537
FaceBuffer[1].a = 4
538
FaceBuffer[1].b = 5
539
FaceBuffer[1].c = 6
540
FaceBuffer[1].d = 7
541
FaceBuffer[1].Flag = FACE_FLAG_COLOURED_2D
542
543
ArrayPos0 = 32
544
while ArrayPos0 < 1056
545
if Object[ArrayPos0].Type == TypeName[Spotlights]
546
547
// Spotlights should always be active since they're seen throughout the level
548
Object[ArrayPos0].Priority = PRIORITY_ACTIVE
549
550
// The default draw priority for a spotlight should be above the stage & objects (but below the HUD of course)
551
Object[ArrayPos0].DrawOrder = 5
552
553
// And set up the initial starting checkpoint value as well
554
Object[ArrayPos0].Checkpoint = Screen.CenterX
555
Object[ArrayPos0].Checkpoint += 192
556
557
// Setup the colors the spotlights will use depending on the current time zone
558
switch HUD.CurrentTimePeriod
559
case TIME_PRESENT
560
// Present gets standard colors - set the primary spotlight to green
561
Object[ArrayPos0].PrimaryBaseColor = 128
562
Object[ArrayPos0].PrimaryBaseColor <<= 16
563
TempValue0 = 224
564
TempValue0 <<= 8
565
Object[ArrayPos0].PrimaryBaseColor += TempValue0
566
Object[ArrayPos0].PrimaryBaseColor += 128
567
568
// Set the secondary spotlight to yellow
569
Object[ArrayPos0].SecondaryBaseColor = 224
570
Object[ArrayPos0].SecondaryBaseColor <<= 16
571
TempValue0 = 224
572
TempValue0 <<= 8
573
Object[ArrayPos0].SecondaryBaseColor += TempValue0
574
Object[ArrayPos0].SecondaryBaseColor += 0
575
break
576
577
// No case 1 since spotlights probably didn't even exist back then in the Past
578
579
case TIME_GOOD_FUTURE
580
// The Good Future gets nice and bright colors - primary spotlight is brown
581
Object[ArrayPos0].PrimaryBaseColor = 192
582
Object[ArrayPos0].PrimaryBaseColor <<= 16
583
TempValue0 = 128
584
TempValue0 <<= 8
585
Object[ArrayPos0].PrimaryBaseColor += TempValue0
586
Object[ArrayPos0].PrimaryBaseColor += 0
587
588
// And the secondary spotlight is blue
589
Object[ArrayPos0].SecondaryBaseColor = 0
590
Object[ArrayPos0].SecondaryBaseColor <<= 16
591
TempValue0 = 192
592
TempValue0 <<= 8
593
Object[ArrayPos0].SecondaryBaseColor += TempValue0
594
Object[ArrayPos0].SecondaryBaseColor += 224
595
break
596
597
case TIME_BAD_FUTURE
598
// Bad Future gets cool and fancy colors, primary spotlight is pink
599
Object[ArrayPos0].PrimaryBaseColor = 224
600
Object[ArrayPos0].PrimaryBaseColor <<= 16
601
TempValue0 = 64
602
TempValue0 <<= 8
603
Object[ArrayPos0].PrimaryBaseColor += TempValue0
604
Object[ArrayPos0].PrimaryBaseColor += 128
605
606
// And secondary spotlight is purple
607
Object[ArrayPos0].SecondaryBaseColor = 224
608
Object[ArrayPos0].SecondaryBaseColor <<= 16
609
TempValue0 = 128
610
TempValue0 <<= 8
611
Object[ArrayPos0].SecondaryBaseColor += TempValue0
612
Object[ArrayPos0].SecondaryBaseColor += 192
613
break
614
615
end switch
616
617
end if
618
619
ArrayPos0++
620
loop
621
622
Screen.XOffset = Player.XPos
623
Screen.XOffset >>= 16
624
Screen.XOffset -= Screen.CenterX
625
626
end sub
627
628
629
// ========================
630
// Editor Subs
631
// ========================
632
633
sub RSDKDraw
634
DrawSprite(0)
635
end sub
636
637
638
sub RSDKLoad
639
LoadSpriteSheet("Global/Display.gif")
640
SpriteFrame(-16, -16, 32, 32, 1, 143) // "Script" Icon
641
642
// This object uses 3d, so there's not really any good way to show it in the editor...
643
644
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
645
end sub
646
647