Path: blob/master/Sonic 2/Scripts/Global/ActFinish.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Act Finish Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.timer12private alias object.value1 : object.textPos13private alias object.value2 : object.gotThroughTextPos14private alias object.value3 : object.timePos15private alias object.value4 : object.ringPos16private alias object.value5 : object.perfectPos17private alias object.value6 : object.totalPos18private alias object.value7 : object.timeBonus19private alias object.value8 : object.ringBonus20private alias object.value9 : object.perfectBonus21private alias object.value10 : object.hasPerfectBonus22private alias object.value11 : object.totalScore23private alias object.value12 : object.hasContinue // (can be Coins in Origins too)2425// States26private alias -1 : ACTFINISH_NORESULTS27private alias 0 : ACTFINISH_INIT28private alias 1 : ACTFINISH_ENTERTEXT29private alias 2 : ACTFINISH_ACTFINISHJINGLE30private alias 3 : ACTFINISH_TALLYSCORE31private alias 4 : ACTFINISH_SHOWRESULTS32private alias 5 : ACTFINISH_LOADNEXTSTAGE33private alias 6 : ACTFINISH_GOTCONTINUE34private alias 7 : ACTFINISH_WAITFORCALLBACK35private alias 8 : ACTFINISH_SETSCREENFADE3637// Player Aliases38private alias object.value0 : player.rings3940// Game Modes41private alias 0 : MODE_NOSAVE42private alias 1 : MODE_SAVEGAME43private alias 2 : MODE_TIMEATTACK4445// Achievement Aliases46private alias 6 : ACHIEVEMENT_PERFECTIONIST474849// ========================50// Events51// ========================5253event ObjectUpdate54options.touchControls = false5556switch object.state57case ACTFINISH_INIT58object.drawOrder = 659object.priority = PRIORITY_ACTIVE60object.textPos = -38461object.gotThroughTextPos = 38462object.timePos = 64063object.ringPos = 65664object.perfectPos = 67265object.totalPos = 6886667switch stage.minutes68case 069if stage.seconds < 3070object.timeBonus = 5000071else72if stage.seconds < 4573object.timeBonus = 1000074else75object.timeBonus = 500076end if77end if78break7980case 181if stage.seconds < 3082object.timeBonus = 400083else84object.timeBonus = 300085end if86break8788case 289object.timeBonus = 200090break9192case 393object.timeBonus = 100094break9596case 497object.timeBonus = 50098break99100case 5101object.timeBonus = 100102break103104case 9105if stage.debugMode == false106if options.gameMode < MODE_TIMEATTACK107if stage.seconds == 59108// Cutting it really close there - give the player a ton of points109object.timeBonus = 100000110end if111end if112end if113break114115end switch116117object.ringBonus = player[0].rings118object.ringBonus *= 100119120// Calculate Perfect Bonus121122// Ring Property Values123// 0 = All124// 1 = Not needed by Sonic for perfect125// 2 = Not needed at all for perfect126127// The tallying system seems to be a bit off, though...128129switch stage.playerListPos130case PLAYER_SONIC_A131case PLAYER_SONIC_TAILS_A132#platform: USE_ORIGINS133case PLAYER_AMY_A134#endplatform135temp0 = 0136foreach (TypeName[Ring], arrayPos0, ALL_ENTITIES)137if object[arrayPos0].propertyValue <= 1 // Is this supposed to be just a `<`?138temp0++139end if140next141break142143case PLAYER_TAILS_A144case PLAYER_KNUCKLES_A145temp0 = 0146foreach (TypeName[Ring], arrayPos0, ALL_ENTITIES)147if object[arrayPos0].propertyValue != 2148temp0++149end if150next151break152153end switch154155// Perfect Bonus156if temp0 == 0157object.hasPerfectBonus = true158object.perfectBonus = 50000159if stage.debugMode == false160// Grant the "Perfectionist" Achievement, for collecting all rings in a level161CallNativeFunction2(SetAchievement, ACHIEVEMENT_PERFECTIONIST, 100)162end if163end if164165#platform: USE_STANDALONE166object.state++167#endplatform168169#platform: USE_ORIGINS170if game.playMode == BOOT_PLAYMODE_MISSION171object.state = ACTFINISH_NORESULTS172else173if game.playMode == BOOT_PLAYMODE_BOSSRUSH174object.state = ACTFINISH_NORESULTS175else176object.state++177end if178end if179180CallNativeFunction4(NotifyCallback, NOTIFY_STATS_ENEMY, StageStatsUsabilityParam1, StageStatsUsabilityParam2, StageStatsUsabilityParam3)181CallNativeFunction2(NotifyCallback, NOTIFY_STATS_RING, player[0].rings)182CallNativeFunction2(NotifyCallback, NOTIFY_ACT_FINISH, 0)183184StageStatsUsabilityParam1 = 0185StageStatsUsabilityParam2 = 0186StageStatsUsabilityParam3 = 0187StageStatsUsabilityParam4 = 0188StageStatsUsabilityParam5 = 0189190StatsUsabilityParam1 = 0191StatsUsabilityParam2 = 0192StatsUsabilityParam3 = 0193StatsUsabilityParam4 = 0194StatsUsabilityParam5 = 0195#endplatform196break197198case ACTFINISH_ENTERTEXT199if object.textPos < 0200object.textPos += 16201end if202203if object.gotThroughTextPos > 0204object.gotThroughTextPos -= 16205end if206207if object.timePos > 0208object.timePos -= 16209end if210211if object.ringPos > 0212object.ringPos -= 16213end if214215if object.perfectPos > 0216object.perfectPos -= 16217end if218219if object.totalPos > 0220object.totalPos -= 16221else222object.state++223end if224break225226case ACTFINISH_ACTFINISHJINGLE227object.timer++228if object.timer > 299229object.timer = 0230object.state++231end if232break233234case ACTFINISH_TALLYSCORE235if object.ringBonus > 0236object.ringBonus -= 100237object.totalScore += 100238player.score += 100239end if240241if object.timeBonus > 0242object.timeBonus -= 100243object.totalScore += 100244player.score += 100245end if246247if object.perfectBonus > 0248object.perfectBonus -= 100249object.totalScore += 100250player.score += 100251end if252253CheckGreater(object.ringBonus, 0)254temp0 = checkResult255CheckGreater(object.timeBonus, 0)256temp0 |= checkResult257CheckGreater(object.perfectBonus, 0)258temp0 |= checkResult259if temp0 == true260object.timer++261if object.timer == 2262PlaySfx(SfxName[Score Add], false)263object.timer = 0264end if265else266if options.vsMode == false267if object.totalScore >= 10000268object.state = ACTFINISH_GOTCONTINUE269else270object.state++271end if272else273object.state++274end if275276object.timer = 0277PlaySfx(SfxName[Score Total], false)278end if279break280281case ACTFINISH_GOTCONTINUE282object.timer++283if object.timer == 60284object.timer = 0285object.hasContinue = true286#platform: USE_ORIGINS287if game.coinMode == false288player.continues++289else290CallNativeFunction2(NotifyCallback, NOTIFY_ADD_COIN, 3)291end if292#endplatform293#platform: USE_STANDALONE294player.continues++295#endplatform296PlaySfx(SfxName[Continue], false)297object.state = ACTFINISH_SHOWRESULTS298end if299break300301case ACTFINISH_SHOWRESULTS302object.timer++303if object.timer == 160304#platform: USE_ORIGINS305if game.oneStageFlag != false306game.callbackResult = -1307CallNativeFunction4(NotifyCallback, NOTIFY_STAGE_RETRY, 1, stage.listPos, 0)308object.state = ACTFINISH_WAITFORCALLBACK309else310object.timer = 0311object.state++312end if313#endplatform314#platform: USE_STANDALONE315object.timer = 0316object.state++317#endplatform318end if319break320321case ACTFINISH_LOADNEXTSTAGE322object.timer += 4323SetScreenFade(0, 0, 0, object.timer)324if object.timer == 384325fadeColor = 0x000000326object.timer = 0327starPostID = 0328329// Huh? This object's direction doesn't really mean much, what's this supposed to mean..?330object.direction = FACING_RIGHT331332#platform: USE_ORIGINS333// These following two lines were added in Origins 1.0.4334// RSDKv5U doesn't stop all currently playing sound effects before (re)loading a scene unlike standalone RSDKv4, so we need to stop them manually335StopSfx(SfxName[Flying])336StopSfx(SfxName[Tired])337#endplatform338339stage.listPos++340341// Hidden Palace Checks342if stage.listPos > 20343stage.listPos = 12 // Make the next stage Oil Ocean Zone Act 1344if options.stageSelectFlag == false345if stage.debugMode == false346if options.gameMode == MODE_NOSAVE347ReadSaveRAM()348saveRAM[46] = true // "unlockedHPZ"349WriteSaveRAM()350else351saveRAM[46] = true // "unlockedHPZ"352end if353end if354end if355end if356357if options.gameMode == MODE_SAVEGAME358arrayPos1 = options.saveSlot359arrayPos1 <<= 3360if stage.player2Enabled == true361#platform: USE_STANDALONE362saveRAM[arrayPos1] = PLAYER_SONIC_TAILS_A363#endplatform364#platform: USE_ORIGINS365switch stage.playerListPos366case PLAYER_SONIC_A367saveRAM[arrayPos1] = PLAYER_SONIC_TAILS368break369370case PLAYER_KNUCKLES_A371saveRAM[arrayPos1] = PLAYER_KNUCKLES_TAILS372break373374case PLAYER_AMY_A375saveRAM[arrayPos1] = PLAYER_AMY_TAILS376break377end switch378#endplatform379else380saveRAM[arrayPos1] = stage.playerListPos381end if382383arrayPos1++384saveRAM[arrayPos1] = player.lives385arrayPos1++386saveRAM[arrayPos1] = player.score387arrayPos1++388saveRAM[arrayPos1] = player.scoreBonus389arrayPos1++390temp0 = stage.listPos391temp0++392if temp0 > saveRAM[arrayPos1]393saveRAM[arrayPos1] = temp0394end if395arrayPos1++396saveRAM[arrayPos1] = specialStage.emeralds397arrayPos1++398saveRAM[arrayPos1] = specialStage.listPos399WriteSaveRAM()400end if401402#platform: USE_ORIGINS403recScore = player.score404405if game.oneStageFlag != false406stage.listPos--407object.state = ACTFINISH_SETSCREENFADE408else409#endplatform410if options.gameMode == MODE_TIMEATTACK411timeAttack.result = stage.seconds412timeAttack.result *= 100413temp0 = stage.minutes414temp0 *= 6000415timeAttack.result += temp0416timeAttack.result += stage.milliSeconds417stage.listPos--418if stage.activeList == REGULAR_STAGE419CallNativeFunction2(SetLeaderboard, stage.listPos, timeAttack.result)420else421// If we're on a non-regular stage, then we're in the Boss Rush so use its special ID422// (This was written in a pre-Origins world, before anything and everything was shoved into the BONUS_STAGE list)423CallNativeFunction2(SetLeaderboard, 21, timeAttack.result)424end if425426engine.state = 8427else428temp0 = engine.trialMode429if stage.listPos >= stage.listSize430temp0 = true431end if432433if temp0 == false434LoadStage()435else436stage.activeList = PRESENTATION_STAGE437stage.listPos = 0438LoadStage()439end if440end if441#platform: USE_ORIGINS442end if443#endplatform444end if445break446447#platform: USE_ORIGINS448case ACTFINISH_WAITFORCALLBACK449if game.callbackResult >= 0450object.timer = 0451object.state = ACTFINISH_LOADNEXTSTAGE452end if453break454455case ACTFINISH_SETSCREENFADE456SetScreenFade(0, 0, 0, 0xFF)457break458#endplatform459end switch460end event461462463event ObjectDraw464SetActivePalette(0, 0, screen.ysize)465466temp7 = object.textPos467temp7 += screen.xcenter468469DrawSpriteScreenXY(0, temp7, 64)470DrawSpriteScreenXY(1, temp7, 64)471472temp7 = object.gotThroughTextPos473temp7 += screen.xcenter474DrawSpriteScreenXY(2, temp7, 82)475476// Determine whether to show `got through zone` or `got through act`477if TitleCard_showZoneText == false478DrawSpriteScreenXY(3, temp7, 82)479temp1 = stage.actNum480temp1 += 4481DrawSpriteScreenXY(temp1, temp7, 70)482else483DrawSpriteScreenXY(4, temp7, 82)484end if485486temp7 = object.timePos487temp7 += screen.xcenter488DrawSpriteScreenXY(8, temp7, 120)489DrawSpriteScreenXY(13, temp7, 120)490temp7 += 88491DrawNumbers(14, temp7, 121, object.timeBonus, 6, 8, false)492493temp7 = object.ringPos494temp7 += screen.xcenter495DrawSpriteScreenXY(9, temp7, 136)496DrawSpriteScreenXY(13, temp7, 136)497temp7 += 88498DrawNumbers(14, temp7, 137, object.ringBonus, 5, 8, false)499if object.hasPerfectBonus == true500temp7 = object.perfectPos501temp7 += screen.xcenter502DrawSpriteScreenXY(10, temp7, 152)503DrawSpriteScreenXY(11, temp7, 152)504temp7 += 88505DrawNumbers(14, temp7, 153, object.perfectBonus, 5, 8, false)506end if507508temp7 = object.totalPos509temp7 += screen.xcenter510DrawSpriteScreenXY(12, temp7, 168)511temp7 += 88512DrawNumbers(14, temp7, 169, object.totalScore, 6, 8, false)513514if object.hasContinue == true515#platform: USE_ORIGINS516if game.coinMode == false517#endplatform518// Draw the Continue icon519GetBit(temp0, oscillation, 4)520if temp0 == true521GetBit(temp0, oscillation, 5)522temp0 += 24523temp1 = screen.xcenter524temp1 += 112525temp2 = screen.ycenter526temp2 += 52527DrawSpriteScreenXY(temp0, temp1, temp2)528end if529#platform: USE_ORIGINS530else531// Draw the Coin icon532533// First, the "Coin x 3" text534// They could've used a constant value of 26 in the function rather than doing it this roundabout way, but if they really wanna ig535temp0 = 26536temp1 = screen.xcenter537temp1 += 112538temp2 = screen.ycenter539temp2 += 52540DrawSpriteScreenXY(temp0, temp1, temp2)541542// Then, the Coins icon543temp0 = oscillation544temp0 &= 15545temp0 >>= 2546temp0 += 27547DrawSpriteScreenXY(temp0, temp1, temp2)548end if549#endplatform550end if551end event552553554event ObjectStartup555LoadSpriteSheet("Global/Display.gif")556557// Assign sprite frames based on current characters in play558switch stage.playerListPos559case PLAYER_SONIC_A560case PLAYER_SONIC_TAILS_A561SpriteFrame(-64, 0, 72, 16, 1, 222) // 0 - "SONIC" large text562SpriteFrame(16, 0, 48, 16, 1, 205) // 1 - "GOT" large text563break564565case PLAYER_TAILS_A566// Determine Miles Vs Tails567if options.region == false568SpriteFrame(-61, 0, 69, 16, 74, 222) // 0 - "TAILS" large text569else570SpriteFrame(-71, 0, 79, 16, 144, 222) // 0 - "MILES" large text571end if572SpriteFrame(16, 0, 48, 16, 1, 205) // 1 - "GOT" large text573break574575case PLAYER_KNUCKLES_A576#platform: USE_ORIGINS577case PLAYER_KNUCKLES_TAILS_A578#endplatform579SpriteFrame(-94, 0, 128, 16, 34, 188) // 0 - "KNUCKLES" large text580SpriteFrame(40, 0, 48, 16, 1, 205) // 1 - "GOT" large text, note its different offset from the others581break582583#platform: USE_ORIGINS584case PLAYER_AMY_A585case PLAYER_AMY_TAILS_A586SpriteFrame(-55, 0, 54, 16, 188, 239) // 0 - "AMY" large text587SpriteFrame(7, 0, 48, 16, 1, 205) // 1 - "GOT" large text, note its different offset from the others588break589#endplatform590end switch591592// Frames that are the same for everyone593SpriteFrame(-88, 0, 112, 16, 50, 205) // 2 - "THROUGH" large text594SpriteFrame(33, 0, 46, 16, 163, 205) // 3 - "ACT" large text595SpriteFrame(33, 0, 62, 16, 83, 1) // 4 - "ZONE" large text596SpriteFrame(88, 0, 16, 29, 42, 1) // 5 - Act number 1597SpriteFrame(88, 0, 23, 29, 59, 1) // 6 - Act number 2598SpriteFrame(88, 0, 23, 32, 42, 31) // 7 - Act number 3599SpriteFrame(-91, 1, 31, 11, 2, 17) // 8 - "Time" text, cropped from normal HUD sprites600SpriteFrame(-92, 1, 32, 11, 1, 33) // 9 - "Rings" text, also cropped from normal HUD sprites601SpriteFrame(-104, 1, 56, 11, 66, 35) // 10 - "Perfect" text602SpriteFrame(-40, 0, 44, 16, 190, 1) // 11 - "Bonus" text603SpriteFrame(-71, 0, 43, 16, 146, 1) // 12 - "Total" text604SpriteFrame(-52, 0, 44, 16, 190, 1) // 13 - "Bonus" text, note its different offset605SpriteFrame(0, 0, 8, 11, 1, 50) // 14 - Number 0606SpriteFrame(0, 0, 8, 11, 10, 50) // 15 - Number 1607SpriteFrame(0, 0, 8, 11, 19, 50) // 16 - Number 2608SpriteFrame(0, 0, 8, 11, 28, 50) // 17 - Number 3609SpriteFrame(0, 0, 8, 11, 1, 62) // 18 - Number 4610SpriteFrame(0, 0, 8, 11, 10, 62) // 19 - Number 5611SpriteFrame(0, 0, 8, 11, 19, 62) // 20 - Number 6612SpriteFrame(0, 0, 8, 11, 28, 62) // 21 - Number 7613SpriteFrame(0, 0, 8, 11, 1, 74) // 22 - Number 8614SpriteFrame(0, 0, 8, 11, 10, 74) // 23 - Number 9615616switch stage.playerListPos617case PLAYER_SONIC_A618case PLAYER_SONIC_TAILS_A619SpriteFrame(-8, -11, 16, 23, 178, 113) // 24 - Sonic continue frame 1620SpriteFrame(-8, -11, 16, 23, 195, 113) // 25 - Sonic continue frame 2621break622623case PLAYER_TAILS_A624SpriteFrame(-8, -11, 16, 23, 212, 113) // 24 - Tails continue frame 1625SpriteFrame(-8, -11, 16, 23, 229, 113) // 25 - Tails continue frame 2626break627628case PLAYER_KNUCKLES_A629#platform: USE_ORIGINS630case PLAYER_KNUCKLES_TAILS_A631#endplatform632SpriteFrame(-8, -11, 16, 23, 178, 137) // 24 - Knuckles continue frame 1633SpriteFrame(-8, -11, 16, 23, 195, 137) // 25 - Knuckles continue frame 2634break635636#platform: USE_ORIGINS637case PLAYER_AMY_A638case PLAYER_AMY_TAILS_A639SpriteFrame(-8, -11, 17, 22, 212, 138) // 24 - Amy continue frame 1640SpriteFrame(-8, -11, 17, 22, 230, 138) // 25 - Amy continue frame 2641break642#endplatform643end switch644645#platform: USE_ORIGINS646SpriteFrame(-8, -5, 50, 16, 196, 180) // 26 - Coin x 3647SpriteFrame(-12, -9, 24, 24, 145, 48) // 27 - Coin Sparkle 1648SpriteFrame(-12, -9, 24, 24, 170, 48) // 28 - Coin Sparkle 2649SpriteFrame(-12, -9, 24, 24, 195, 48) // 29 - Coin Sparkle 3650SpriteFrame(-12, -9, 24, 24, 220, 48) // 30 - Coin Sparkle 4651#endplatform652end event653654655// ========================656// Editor Events657// ========================658659event RSDKDraw660DrawSprite(0)661end event662663664event RSDKLoad665LoadSpriteSheet("Global/Display.gif")666SpriteFrame(-16, -16, 32, 32, 1, 143)667668SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")669end event670671672