Path: blob/main/Scripts/R7/Spotlights2.txt
1319 views
//----------------Sonic CD Spotlights 2 Script----------------//1//--------Scripted by Christian Whitehead 'The Taxman'--------//2//-------Unpacked By Rubberduckycooly's Script Unpacker-------//34// Aliases56// Position for where the checkpoint should progress to its next version7#alias Object.Value1 : Object.Checkpoint89// The colors the Spotlight should use10// Just like everything else, these colors are in RRGGBB11#alias Object.Value2 : Object.PrimaryBaseColor12#alias Object.Value3 : Object.SecondaryBaseColor13#alias Object.Value4 : Object.PrimaryDisplayColor14#alias Object.Value5 : Object.SecondaryDisplayColor1516// There are several different types of spotlights that appear in the stage17#alias Object.Value0 : Object.SpotlightType18// 0 - Pair of two primary ones19// - Using SSZ2A's, it's the two small green ones20// 1 - Single primary one21// - Using SSZ2A's, it's a single green one22// 2 - Pair of two secondary ones23// - Using SSZ2A's, it's a pair of big and small yellow ones24// 3 - Single small primary one25// - Using SSZ2A's, it's a single big green one26// 4 - Pair of primary and secondary27// - Using SSZ2A's, the pair of a big green one with a small yellow one28// Then it loops back2930// HUD Alias31#alias Object[24].PropertyValue : HUD.CurrentTimePeriod3233// Time Periods34#alias 0 : TIME_PRESENT35#alias 2 : TIME_GOOD_FUTURE36#alias 3 : TIME_BAD_FUTURE3738// Priority39#alias 1 : PRIORITY_ACTIVE4041// Face Buffer Flags42#alias 3 : FACE_FLAG_COLOURED_2D4344// Function declarations45#function Spotlights_UpdateCorner464748function Spotlights_UpdateCorner4950// Called individually for each corner in a spotlight to update it51// Preconditions:52// - ArrayPos0 is the ID of the vertex that should be changes53// - TempValue0 is the X multiplier for how much extra this vertex should move54// - TempValue1 is the Y multiplier for how much extra this vertex should move55// (These last two values are here since spotlights aren't uniform in width - they can be skewed to uneven dimensions as well)565758Sin(TempValue2, Object.Rotation)59TempValue2 *= TempValue16061Cos(TempValue3, Object.Rotation)62TempValue3 *= TempValue06364VertexBuffer[ArrayPos0].x = TempValue265VertexBuffer[ArrayPos0].x -= TempValue366VertexBuffer[ArrayPos0].x >>= 967VertexBuffer[ArrayPos0].x += Object.XPos6869Cos(TempValue2, Object.Rotation)70TempValue2 *= TempValue17172Sin(TempValue3, Object.Rotation)73TempValue3 *= TempValue07475VertexBuffer[ArrayPos0].y = TempValue276VertexBuffer[ArrayPos0].y += TempValue377VertexBuffer[ArrayPos0].y >>= 978VertexBuffer[ArrayPos0].y += 2567980end function818283sub ObjectMain84TempValue0 = Oscillation85TempValue0 <<= 28687// Get some smooth arc movement values8889Sin(TempValue1, TempValue0)90TempValue1 >>= 591TempValue1 += 649293Cos(TempValue2, TempValue0)94TempValue2 >>= 595TempValue2 += 649697// Make the spotlight colors oscillate9899Object.PrimaryDisplayColor = TempValue1100Object.PrimaryDisplayColor <<= 24101Object.PrimaryDisplayColor += Object.PrimaryBaseColor102103Object.SecondaryDisplayColor = TempValue2104Object.SecondaryDisplayColor <<= 24105Object.SecondaryDisplayColor += Object.SecondaryBaseColor106107// Check to see if we need to cycle the Spotlight type now108109TempValue0 = Screen.XOffset110TempValue0 += Screen.CenterX111if TempValue0 > Object.Checkpoint112TempValue0 -= Object.Checkpoint113if TempValue0 > 460114// We do indeed need to advance the spotlight type by 1...115116// Move the next checkpoint ahead117Object.Checkpoint += 920118119// Cycle the Spotlight type ahead120Object.SpotlightType++121122if Object.SpotlightType > 4123// Keeping an upper limit of 4 in mind124Object.SpotlightType = 0125end if126end if127else128TempValue0 -= Object.Checkpoint129if TempValue0 < -460130// We do indeed need to go back the spotlight type by 1...131132// Move the next checkpoint back a bit133Object.Checkpoint -= 920134135// Go back a Spotlight type136Object.SpotlightType--137138if Object.SpotlightType < 0139// Keeping a lower limit of 0 in mind140Object.SpotlightType = 4141end if142end if143end if144145// And then position the Spotlight based on the current checkpoint146Object.XPos = Object.Checkpoint147Object.XPos -= Screen.XOffset148149switch Object.SpotlightType150case 0151// Pair of two small primary Spotlights152153// These should draw above everything else154Object.DrawOrder = 5155156// 2 rectangles... 8 corners and 2 faces!1573DScene.NoVertices = 81583DScene.NoFaces = 2159160// Spotlight 1 position offset, just a wee bit to the left161Object.XPos -= 64162163// Both in these pair will use the primary color164FaceBuffer[0].Color = Object.PrimaryDisplayColor165FaceBuffer[1].Color = Object.PrimaryDisplayColor166167// Get Spotlight 1's rotation168TempValue0 = Oscillation169Sin(Object.Rotation, TempValue0)170Object.Rotation >>= 4171Object.Rotation += 520172173// And now create the spotlight174175// Top right of Spotlight 1176ArrayPos0 = 0177TempValue0 = -16178TempValue1 = -384179CallFunction(Spotlights_UpdateCorner)180181// Top left of Spotlight 1182ArrayPos0++183TempValue0 = 16184TempValue1 = -384185CallFunction(Spotlights_UpdateCorner)186187// Bottom right of Spotlight 1188ArrayPos0++189TempValue0 = -8190TempValue1 = 0191CallFunction(Spotlights_UpdateCorner)192193// Bottom left of Spotlight 1194ArrayPos0++195TempValue0 = 8196TempValue1 = 0197CallFunction(Spotlights_UpdateCorner)198199ArrayPos0++200201// Spotlight 2 is a bit more to the right, instead202// (+64 gain from base Spotlight position)203Object.XPos += 128204205// Get Spotlight 2's rotation206TempValue0 = Oscillation207TempValue0 <<= 1208Sin(Object.Rotation, TempValue0)209Object.Rotation /= 10210Object.Rotation += 512211212// Top right of Spotlight 2213TempValue0 = -16214TempValue1 = -384215CallFunction(Spotlights_UpdateCorner)216217// Top left of Spotlight 2218ArrayPos0++219TempValue0 = 16220TempValue1 = -384221CallFunction(Spotlights_UpdateCorner)222223// Bottom right of Spotlight 2224ArrayPos0++225TempValue0 = -8226TempValue1 = 0227CallFunction(Spotlights_UpdateCorner)228229// Bottom left of Spotlight 2230ArrayPos0++231TempValue0 = 8232TempValue1 = 0233CallFunction(Spotlights_UpdateCorner)234235ArrayPos0++236break237238case 1239// Single slim primary Spotlight240241// This Spotlight will draw behind everything, way in the background242Object.DrawOrder = 2243244// A single rectangle, that just means a single face, with 4 corners2453DScene.NoVertices = 42463DScene.NoFaces = 1247248// This Spotlight will use the primary color249FaceBuffer[0].Color = Object.PrimaryDisplayColor250251// Get the Spotlight's rotation252TempValue0 = Oscillation253TempValue0 <<= 1254Sin(Object.Rotation, TempValue0)255Object.Rotation >>= 3256Object.Rotation += 512257258// Top right corner of the Spotlight259ArrayPos0 = 0260TempValue0 = -16261TempValue1 = -384262CallFunction(Spotlights_UpdateCorner)263264// Top left corner of the Spotlight265ArrayPos0++266TempValue0 = 16267TempValue1 = -384268CallFunction(Spotlights_UpdateCorner)269270// Bottom right corner of the Spotlight271ArrayPos0++272TempValue0 = -8273TempValue1 = 0274CallFunction(Spotlights_UpdateCorner)275276// Bottom left corner of the Spotlight277ArrayPos0++278TempValue0 = 8279TempValue1 = 0280CallFunction(Spotlights_UpdateCorner)281282ArrayPos0++283break284285case 2286// Pair of two secondary spotlights287288// These pair draw above everything, being the bright and shining pair they are289Object.DrawOrder = 5290291// 8 corners? No this isn't an octagon, it's a pair of rectangles!2923DScene.NoVertices = 82933DScene.NoFaces = 2294295// Set the colors for the Spotlights...296FaceBuffer[0].Color = Object.SecondaryDisplayColor297FaceBuffer[1].Color = Object.SecondaryDisplayColor298299// Get the initial spotlight offset...300Object.XPos -= 48301302// And then set the Spotlight colors again? What?303FaceBuffer[0].Color = Object.SecondaryDisplayColor304FaceBuffer[1].Color = Object.SecondaryDisplayColor305306// Get the rotation for Spotlight 1307TempValue0 = Oscillation308TempValue0 <<= 1309Sin(Object.Rotation, TempValue0)310Object.Rotation >>= 4311Object.Rotation += 500312313// Top right corner of Spotlight 1314ArrayPos0 = 0315TempValue0 = -20316TempValue1 = -384317CallFunction(Spotlights_UpdateCorner)318319// Top left corner of Spotlight 1320ArrayPos0++321TempValue0 = 20322TempValue1 = -384323CallFunction(Spotlights_UpdateCorner)324325// Bototm right corner of Spotlight 1326ArrayPos0++327TempValue0 = -10328TempValue1 = 0329CallFunction(Spotlights_UpdateCorner)330331// Bottom left corner of Spotlight 1332ArrayPos0++333TempValue0 = 10334TempValue1 = 0335CallFunction(Spotlights_UpdateCorner)336337ArrayPos0++338339// Move Spotlight 2 to the right a bit, total change of +48 from base position340Object.XPos += 96341342// And get the rotation for this second Spotlight, too343TempValue0 = Oscillation344TempValue0 += 32345TempValue0 <<= 1346Sin(Object.Rotation, TempValue0)347Object.Rotation >>= 3348Object.Rotation += 508349350// Top right corner of Spotlight 2351TempValue0 = -16352TempValue1 = -420353CallFunction(Spotlights_UpdateCorner)354355// Top left corner of Spotlight 2356ArrayPos0++357TempValue0 = 16358TempValue1 = -420359CallFunction(Spotlights_UpdateCorner)360361// Bottom right corner of Spotlight 2362ArrayPos0++363TempValue0 = -8364TempValue1 = 0365CallFunction(Spotlights_UpdateCorner)366367// Bottom left corner of Spotlight 2368ArrayPos0++369TempValue0 = 8370TempValue1 = 0371CallFunction(Spotlights_UpdateCorner)372373ArrayPos0++374break375376case 3377// Single large primary Spotlight378Object.DrawOrder = 5379380// Just a single Spotlight, 4 corners, and 1 face, nothing more, nothing less3813DScene.NoVertices = 43823DScene.NoFaces = 1383384// This Spotlight will follow the Primary color for the stage385FaceBuffer[0].Color = Object.PrimaryDisplayColor386387// Get the rotation for the Spotlight to be, well rotated at!388TempValue0 = 512389TempValue0 -= Oscillation390TempValue0 *= 3391Sin(Object.Rotation, TempValue0)392Object.Rotation /= 12393Object.Rotation += 520394395// Top right corner of the Spotlight396ArrayPos0 = 0397TempValue0 = -24398TempValue1 = -384399CallFunction(Spotlights_UpdateCorner)400401// Top left corner of the Spotlight402ArrayPos0++403TempValue0 = 24404TempValue1 = -384405CallFunction(Spotlights_UpdateCorner)406407// Bottom right corner of the Spotlight408ArrayPos0++409TempValue0 = -16410TempValue1 = 0411CallFunction(Spotlights_UpdateCorner)412413// Bottom left corner of the Spotlight414ArrayPos0++415TempValue0 = 16416TempValue1 = 0417CallFunction(Spotlights_UpdateCorner)418419ArrayPos0++420break421422case 4423// A big Primary one and a really small secondary one424425// This pair will draw pretty low, behind the stage and all that stuff426Object.DrawOrder = 2427428// 2 Spotlights, 2 times 4 is 8, 8 divided by 4 is 24293DScene.NoVertices = 84303DScene.NoFaces = 2431432// Initial offset for Spotlight 1433Object.XPos -= 48434435// Set the colors both Spotlights436FaceBuffer[0].Color = Object.SecondaryDisplayColor437FaceBuffer[1].Color = Object.PrimaryDisplayColor438439// Get the rotation for the first in the pair440TempValue0 = Oscillation441TempValue0 += 64442TempValue0 <<= 1443Sin(Object.Rotation, TempValue0)444Object.Rotation /= 20445Object.Rotation += 496446447// Top right corner of Spotlight 1448ArrayPos0 = 0449TempValue0 = -14450TempValue1 = -420451CallFunction(Spotlights_UpdateCorner)452453// Top left corner of Spotlight 1454ArrayPos0++455TempValue0 = 14456TempValue1 = -420457CallFunction(Spotlights_UpdateCorner)458459// Bottom right corner of Spotlight 1460ArrayPos0++461TempValue0 = -4462TempValue1 = 0463CallFunction(Spotlights_UpdateCorner)464465// Bottom left corner of Spotlight 1466ArrayPos0++467TempValue0 = 4468TempValue1 = 0469CallFunction(Spotlights_UpdateCorner)470471ArrayPos0++472473// Spotlight 2 is to the right, for a total of +48 from the base position474Object.XPos += 96475476// And get this secondary Spotlight's rotation as well477TempValue0 = Oscillation478TempValue0 <<= 2479Sin(Object.Rotation, TempValue0)480Object.Rotation >>= 4481Object.Rotation += 520482483// Top right corner of Spotlight 2484TempValue0 = -20485TempValue1 = -420486CallFunction(Spotlights_UpdateCorner)487488// Top left corner of Spotlight 2489ArrayPos0++490TempValue0 = 20491TempValue1 = -420492CallFunction(Spotlights_UpdateCorner)493494// Bottom right corner of Spotlight 2495ArrayPos0++496TempValue0 = -14497TempValue1 = 0498CallFunction(Spotlights_UpdateCorner)499500// Bottom left corner of Spotlight 2501ArrayPos0++502TempValue0 = 14503TempValue1 = 0504CallFunction(Spotlights_UpdateCorner)505506ArrayPos0++507break508509end switch510511end sub512513514sub ObjectDraw515// The spotlights are 3d, so draw an entire 3d scene516Draw3DScene()517518end sub519520521sub ObjectStartup522523// Reset the 3d stuff524MatrixTranslateXYZ(MAT_WORLD, 0, 0, 0)525MatrixTranslateXYZ(MAT_VIEW, 0, 0, 0)526527// Setup the first spotlight528FaceBuffer[0].a = 0529FaceBuffer[0].b = 1530FaceBuffer[0].c = 2531FaceBuffer[0].d = 3532FaceBuffer[0].Flag = FACE_FLAG_COLOURED_2D533534// And now setup the second spotlight535// It doesn't always appear though, there are some Spotlight configurations where only 1 will show at a time536FaceBuffer[1].a = 4537FaceBuffer[1].b = 5538FaceBuffer[1].c = 6539FaceBuffer[1].d = 7540FaceBuffer[1].Flag = FACE_FLAG_COLOURED_2D541542ArrayPos0 = 32543while ArrayPos0 < 1056544if Object[ArrayPos0].Type == TypeName[Spotlights]545546// Spotlights should always be active since they're seen throughout the level547Object[ArrayPos0].Priority = PRIORITY_ACTIVE548549// The default draw priority for a spotlight should be above the stage & objects (but below the HUD of course)550Object[ArrayPos0].DrawOrder = 5551552// And set up the initial starting checkpoint value as well553Object[ArrayPos0].Checkpoint = Screen.CenterX554Object[ArrayPos0].Checkpoint += 192555556// Setup the colors the spotlights will use depending on the current time zone557switch HUD.CurrentTimePeriod558case TIME_PRESENT559// Present gets standard colors - set the primary spotlight to green560Object[ArrayPos0].PrimaryBaseColor = 128561Object[ArrayPos0].PrimaryBaseColor <<= 16562TempValue0 = 224563TempValue0 <<= 8564Object[ArrayPos0].PrimaryBaseColor += TempValue0565Object[ArrayPos0].PrimaryBaseColor += 128566567// Set the secondary spotlight to yellow568Object[ArrayPos0].SecondaryBaseColor = 224569Object[ArrayPos0].SecondaryBaseColor <<= 16570TempValue0 = 224571TempValue0 <<= 8572Object[ArrayPos0].SecondaryBaseColor += TempValue0573Object[ArrayPos0].SecondaryBaseColor += 0574break575576// No case 1 since spotlights probably didn't even exist back then in the Past577578case TIME_GOOD_FUTURE579// The Good Future gets nice and bright colors - primary spotlight is brown580Object[ArrayPos0].PrimaryBaseColor = 192581Object[ArrayPos0].PrimaryBaseColor <<= 16582TempValue0 = 128583TempValue0 <<= 8584Object[ArrayPos0].PrimaryBaseColor += TempValue0585Object[ArrayPos0].PrimaryBaseColor += 0586587// And the secondary spotlight is blue588Object[ArrayPos0].SecondaryBaseColor = 0589Object[ArrayPos0].SecondaryBaseColor <<= 16590TempValue0 = 192591TempValue0 <<= 8592Object[ArrayPos0].SecondaryBaseColor += TempValue0593Object[ArrayPos0].SecondaryBaseColor += 224594break595596case TIME_BAD_FUTURE597// Bad Future gets cool and fancy colors, primary spotlight is pink598Object[ArrayPos0].PrimaryBaseColor = 224599Object[ArrayPos0].PrimaryBaseColor <<= 16600TempValue0 = 64601TempValue0 <<= 8602Object[ArrayPos0].PrimaryBaseColor += TempValue0603Object[ArrayPos0].PrimaryBaseColor += 128604605// And secondary spotlight is purple606Object[ArrayPos0].SecondaryBaseColor = 224607Object[ArrayPos0].SecondaryBaseColor <<= 16608TempValue0 = 128609TempValue0 <<= 8610Object[ArrayPos0].SecondaryBaseColor += TempValue0611Object[ArrayPos0].SecondaryBaseColor += 192612break613614end switch615616end if617618ArrayPos0++619loop620621Screen.XOffset = Player.XPos622Screen.XOffset >>= 16623Screen.XOffset -= Screen.CenterX624625end sub626627628// ========================629// Editor Subs630// ========================631632sub RSDKDraw633DrawSprite(0)634end sub635636637sub RSDKLoad638LoadSpriteSheet("Global/Display.gif")639SpriteFrame(-16, -16, 32, 32, 1, 143) // "Script" Icon640641// This object uses 3d, so there's not really any good way to show it in the editor...642643SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")644end sub645646647