Path: blob/master/Sonic 2/Scripts/MBZ/MBZSetup.txt
1479 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: MBZ Setup Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value1 : object.lavaPalTimer12private alias object.value2 : object.paletteTimer13private alias object.value3 : object.lavaPalIndex114private alias object.value4 : object.lavaPalIndex215private alias object.value5 : object.lavaPalIndex316private alias object.value6 : object.lavaPalIndex417private alias object.value7 : object.oilAniTileDelay18private alias object.value8 : object.oilAniTileFrame19private alias object.value9 : object.deformTimer20private alias object.value10 : object.isDimming2122// Player Aliases23private alias object.state : player.state24private alias object.xpos : player.xpos25private alias object.ypos : player.ypos26private alias object.iypos : player.iypos27private alias object.yvel : player.yvel28private alias object.speed : player.speed29private alias object.drawOrder : player.drawOrder30private alias object.direction : player.direction31private alias object.gravity : player.gravity32private alias object.pushing : player.pushing33private alias object.left : player.left34private alias object.right : player.right35private alias object.jumpPress : player.jumpPress36private alias object.controlLock : player.controlLock37private alias object.angle : player.angle38private alias object.frame : player.frame39private alias object.animation : player.animation40private alias object.animationSpeed : player.animationSpeed41private alias object.collisionMode : player.collisionMode42private alias object.collisionBottom : player.collisionBottom43private alias object.tileCollisions : player.tileCollisions4445private alias object.value1 : player.timer46private alias object.value14 : player.skidding47private alias object.value18 : player.sortedDrawOrder48private alias object.value37 : player.shield4950// Shield Aliases51private alias 3 : SHIELD_FIRE5253// Tile Flag Aliases54private alias 0 : TILE_NORMAL55private alias 1 : TILE_OILPOOL56private alias 3 : TILE_LAVA5758// Tile Info ID Aliases59private alias 8 : TILEINFO_ANGLEB6061// Tracks62private alias 0 : TRACK_STAGE63private alias 1 : TRACK_ACTFINISH64private alias 2 : TRACK_INVINCIBLE65private alias 3 : TRACK_CONTINUE66private alias 4 : TRACK_BOSS67private alias 5 : TRACK_GAMEOVER68private alias 6 : TRACK_DROWNING69private alias 7 : TRACK_SUPER7071// Reserved object slots72private alias 10 : SLOT_ZONESETUP73private alias 25 : SLOT_MUSICEVENT_CHANGE74private alias 26 : SLOT_MUSICEVENT_BOSS7576// Music Events77private alias 2 : MUSICEVENT_TRANSITION7879private alias 0 : MUSICEVENT_FLAG_NOCHANGE80private alias 1 : MUSICEVENT_FLAG_SPEEDUP81private alias 2 : MUSICEVENT_FLAG_SLOWDOWN828384// ========================85// Function Declarations86// ========================8788reserve function MBZSetup_State_OilPool8990// These two are unused91reserve function MBZSetup_SpeedUpMusic92reserve function MBZSetup_SlowDownMusic939495// ========================96// Static Values97// ========================9899// Values here are named this way because the idea is to "mimic" CPZSetup for the CPZ objs in the stage100public value CPZSetup_rotatingStairTimer = 0101public value Water_flashTimer = 0102public value CPZSetup_hasAchievement = 0103public value CPZSetup_enteredWater = 0104105// As the name suggests, these are not used106private value MBZSetup_unused1 = 0107private value MBZSetup_unused2 = 0108private value MBZSetup_unused3 = 0109private value MBZSetup_unused4 = 0110private value MBZSetup_unknownTimer = 0 // This is used to count, but not actually used in any meaningful way111112113// ========================114// Tables115// ========================116117// Palette cycle for the stage118private table MBZSetup_lavaPalCycle1190xE00000, 0xE06000, 0xE0A000, 0xE0E0001200xE0E000, 0xE00000, 0xE06000, 0xE0A0001210xE0C020, 0xE0E000, 0xE00000, 0xE060001220xE06000, 0xE0E040, 0xE0E080, 0xE020001230xE04000, 0xE08000, 0xE0E060, 0xE0E0A01240xE0E080, 0xE02000, 0xE06000, 0xE0E0401250xE0C020, 0xE0E000, 0xE00000, 0xE060001260xE06000, 0xE0C020, 0xE0E000, 0xE000001270xE00000, 0xE06000, 0xE0A000, 0xE0E0001280xE0C000, 0xC00000, 0xE04000, 0xE080001290xE06000, 0xC0A000, 0xA00000, 0xE020001300xC00000, 0xC04000, 0xE08000, 0x8000001310xA00000, 0xE02000, 0xE06000, 0xC0A0001320xE0C000, 0xC00000, 0xE04000, 0xE080001330xE0A000, 0xE0E000, 0xE00000, 0xE060001340xE06000, 0xE0A000, 0xE0E000, 0xE00000135end table136137// Stage deformation data, used for animating the water138private table MBZSetup_deformationTable1391, 2, 1, 3, 1, 2, 2, 1, 2, 3, 1, 2, 1, 2, 0, 01402, 0, 3, 2, 2, 3, 2, 2, 1, 3, 0, 0, 1, 0, 1, 31411, 2, 1, 3, 1, 2, 2, 1, 2, 3, 1, 2, 1, 2, 0, 01422, 0, 3, 2, 2, 3, 2, 2, 1, 3, 0, 0, 1, 0, 1, 3143end table144145146// ========================147// Function Definitions148// ========================149150// Modified version of Player_State_Ground151private function MBZSetup_State_OilPool152if player.animation != ANI_SKIDDING153temp7 = true154else155temp7 = false156end if157158CallFunction(Player_HandleGroundMovement)159160if player.gravity == GRAVITY_AIR161#platform: USE_STANDALONE162player.state = Player_State_Air163#endplatform164#platform: USE_ORIGINS165player.state = Player_State_Air_NoDropDash166#endplatform167CallFunction(Player_HandleAirMovement)168else169CallFunction(Player_HandleOnGround)170171if player.speed == 0172if player.collisionMode == CMODE_FLOOR173if player.timer < 240174player.animation = ANI_STOPPED175player.timer++176else177player.animation = ANI_WAITING178if stage.playerListPos == PLAYER_KNUCKLES_A179player.timer++180if player.timer == 834181player.timer = 0182player.animation = ANI_STOPPED183end if184end if185end if186end if187else188player.timer = 0189if player.speed > 0190if player.speed < 0x5F5C2191player.animation = ANI_WALKING192CallFunction(Player_HandleWalkAnimSpeed)193else194if player.speed > 0x9FFFF195player.animation = ANI_PEELOUT196else197player.animation = ANI_RUNNING198end if199CallFunction(Player_HandleRunAnimSpeed)200end if201else202if player.speed > -0x5F5C2203player.animation = ANI_WALKING204CallFunction(Player_HandleWalkAnimSpeed)205else206if player.speed < -0x9FFFF207player.animation = ANI_PEELOUT208else209player.animation = ANI_RUNNING210end if211CallFunction(Player_HandleRunAnimSpeed)212end if213end if214end if215216if player.skidding > 0217if temp7 == true218PlaySfx(SfxName[Skidding], false)219end if220221player.animation = ANI_SKIDDING222player.animationSpeed = 0223player.skidding--224if ringTimer == 0225CreateTempObject(TypeName[Dust Puff], 0, player.xpos, player.ypos)226object[tempObjectPos].iypos += player.collisionBottom227object[tempObjectPos].drawOrder = player.sortedDrawOrder228end if229230if player.speed > 0231player.direction = FACING_RIGHT232else233player.direction = FACING_LEFT234end if235end if236237if player.collisionMode == CMODE_FLOOR238if player.pushing == 2239player.animation = ANI_PUSHING240player.animationSpeed = 0241end if242end if243244if player.jumpPress == true245CallFunction(Player_Action_Jump)246end if247end if248end function249250251// Unused - would've been used to speed up stage music252// Interestingly, it calls for "MarathonBase_F.ogg" - a song that isn't in the RSDK253// Could this have been the stage's original name..?254private function MBZSetup_SpeedUpMusic255CheckEqual(object[SLOT_MUSICEVENT_CHANGE].type, TypeName[Music Event])256temp0 = checkResult257CheckEqual(object[SLOT_MUSICEVENT_CHANGE].propertyValue, MUSICEVENT_TRANSITION)258temp0 &= checkResult259CheckEqual(stage.musicFlag, MUSICEVENT_FLAG_NOCHANGE)260temp0 &= checkResult261if temp0 == false262switch music.currentTrack263case TRACK_STAGE264SetMusicTrack("Invincibility_F.ogg", TRACK_INVINCIBLE, 30436)265SwapMusicTrack("MarathonBase_F.ogg", TRACK_STAGE, 502294, 7920)266break267268case TRACK_INVINCIBLE269SetMusicTrack("MarathonBase_F.ogg", TRACK_STAGE, 502294)270SwapMusicTrack("Invincibility_F.ogg", TRACK_INVINCIBLE, 30436, 8000)271break272273case TRACK_BOSS274SetMusicTrack("MarathonBase_F.ogg", TRACK_STAGE, 502294)275SetMusicTrack("Invincibility_F.ogg", TRACK_INVINCIBLE, 30436)276break277278end switch279else280stage.musicFlag = MUSICEVENT_FLAG_SPEEDUP281end if282end function283284285// Unused - would've been used to slow down stage music286// Interestingly, it calls for "MarathonBase.ogg" - this song isn't in the RSDK either287private function MBZSetup_SlowDownMusic288CheckEqual(object[SLOT_MUSICEVENT_CHANGE].type, TypeName[Music Event])289temp0 = checkResult290CheckEqual(object[SLOT_MUSICEVENT_CHANGE].propertyValue, MUSICEVENT_TRANSITION)291temp0 &= checkResult292CheckEqual(stage.musicFlag, MUSICEVENT_FLAG_NOCHANGE)293temp0 &= checkResult294if temp0 == false295switch music.currentTrack296case TRACK_STAGE297SetMusicTrack("Invincibility.ogg", TRACK_INVINCIBLE, 39528)298SwapMusicTrack("MarathonBase.ogg", TRACK_STAGE, 635970, 12650)299break300301case TRACK_INVINCIBLE302SetMusicTrack("MarathonBase.ogg", TRACK_STAGE, 635970)303SwapMusicTrack("Invincibility.ogg", TRACK_INVINCIBLE, 39528, 12500)304break305306case TRACK_BOSS307SetMusicTrack("MarathonBase.ogg", TRACK_STAGE, 635970)308SetMusicTrack("Invincibility.ogg", TRACK_INVINCIBLE, 39528)309break310311end switch312else313stage.musicFlag = MUSICEVENT_FLAG_SLOWDOWN314end if315end function316317318// ========================319// Events320// ========================321322event ObjectUpdate323// Pulsing palette, for the lava324object.lavaPalTimer++325if object.lavaPalTimer == 12326object.lavaPalTimer = 0327328object.lavaPalIndex1 += 4329object.lavaPalIndex1 &= 0x3F330GetTableValue(temp0, object.lavaPalIndex1, MBZSetup_lavaPalCycle)331SetPaletteEntry(0, 96, temp0)332333object.lavaPalIndex2 += 4334object.lavaPalIndex2 &= 0x3F335GetTableValue(temp0, object.lavaPalIndex2, MBZSetup_lavaPalCycle)336SetPaletteEntry(0, 97, temp0)337338object.lavaPalIndex3 += 4339object.lavaPalIndex3 &= 0x3F340GetTableValue(temp0, object.lavaPalIndex3, MBZSetup_lavaPalCycle)341SetPaletteEntry(0, 98, temp0)342343object.lavaPalIndex4 += 4344object.lavaPalIndex4 &= 0x3F345GetTableValue(temp0, object.lavaPalIndex4, MBZSetup_lavaPalCycle)346SetPaletteEntry(0, 99, temp0)347end if348349// Cycling palette350object.paletteTimer++351if object.paletteTimer == 4352object.paletteTimer = 0353RotatePalette(0, 100, 105, false)354end if355356// Ani Tiles, for the oil357if object.oilAniTileDelay < 2358temp0 = object.oilAniTileFrame359temp0 += 462360Copy16x16Tile(408, temp0)361362temp0++363Copy16x16Tile(409, temp0)364365temp0++366Copy16x16Tile(410, temp0)367368temp0++369Copy16x16Tile(411, temp0)370371temp0 += 21372Copy16x16Tile(412, temp0)373374temp0++375Copy16x16Tile(413, temp0)376377temp0++378Copy16x16Tile(414, temp0)379380temp0++381Copy16x16Tile(415, temp0)382383object.oilAniTileDelay = 18384object.oilAniTileFrame += 4385object.oilAniTileFrame %= 24386else387object.oilAniTileDelay--388end if389390// Water shining391object.deformTimer++392if object.deformTimer > 7393tileLayer[1].deformationOffset++394object.deformTimer = 0395end if396397// Update some value, though this value never really does anything beyond this398// This looks similar to how CPZ Setup's CPZSetup_rotatingStairTimer updating works, but this script's CPZSetup_rotatingStairTimer is never changed399GetTableValue(temp0, 21, StageSetup_oscillationTable)400if temp0 == 0 // (this updates the value every 180 frames)401MBZSetup_unknownTimer++402MBZSetup_unknownTimer &= 3403end if404405// Randomize the animals, looping around all the animals in the game406temp0 = oscillation407temp0 &= 15408if temp0 > 11409temp0 = 5410end if411temp0 += TypeName[Flicky] // In the object type list, all the animals are listed right after one another, starting from the Flicky412animalType1 = temp0413animalType2 = temp0414415// Check interaction with players416foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)417if player[currentPlayer].animation == ANI_TWIRL418player[currentPlayer].frame %= 24419end if420421temp1 = player[currentPlayer].xpos422temp1 >>= 16423424temp2 = player[currentPlayer].ypos425temp2 >>= 16426temp2 += 6427428// Get the B-plane "angle" of the tile the player is on429// "Angle" is actually used to hold flags and such, same goes for other stages430Get16x16TileInfo(temp0, temp1, temp2, TILEINFO_ANGLEB)431switch temp0432default433case TILE_NORMAL434break435436case TILE_OILPOOL437if player[currentPlayer].yvel > -1438player[currentPlayer].state = MBZSetup_State_OilPool439if player[currentPlayer].animation == ANI_JUMPING440player[currentPlayer].animation = ANI_WALKING441end if442player[currentPlayer].gravity = GRAVITY_GROUND443player[currentPlayer].yvel = 0444player[currentPlayer].ypos += 0x10000445end if446break447448case TILE_LAVA449// Lava tile450// Only harm the player if they don't have a flame shield451if player[currentPlayer].shield != SHIELD_FIRE452CallFunction(Player_Hit)453end if454break455456end switch457next458459// object.isDimming is set by a BG Dimmer object placed in the scene460if object.isDimming == true461// Fade in, with a max of halfway full462if object.alpha < 0x80463object.alpha += 4464end if465else466// Fade out, if not fading in467if object.alpha > 0468object.alpha -= 4469end if470end if471472// Reset it for the next frame473object.isDimming = false474end event475476477event ObjectDraw478// Draw a tint in the background, right between the BG and the FG479// -> This is always drawn, it's just that object.alpha is 0 most of the time so nothing is really seen480DrawRect(0, 0, 512, 240, 0x00, 0x20, 0x50, object.alpha)481end event482483484event ObjectStartup485SetMusicTrack("DeathEgg.ogg", TRACK_STAGE, true)486487// Reset the black color used in boss flashes488SetPaletteEntry(0, 192, 0x000000)489490object[SLOT_ZONESETUP].type = TypeName[MBZ Setup]491object[SLOT_ZONESETUP].priority = PRIORITY_ACTIVE492object[SLOT_ZONESETUP].lavaPalIndex1 = 0493object[SLOT_ZONESETUP].lavaPalIndex2 = 1494object[SLOT_ZONESETUP].lavaPalIndex3 = 2495object[SLOT_ZONESETUP].lavaPalIndex4 = 3496497// Most Zone Setups don't have a Draw Order specified, but this one needs it for the black fade in places like the MCZ boss498object[SLOT_ZONESETUP].drawOrder = 1499500// While this is primarily meant for the little snippit water in the normal background,501// it's worth noting that the third background layer has deformation enabled for its entirety, rather than just its water502arrayPos0 = 0503while arrayPos0 < 576504temp0 = arrayPos0505temp0 &= 0x3F506GetTableValue(stage.deformationData2[arrayPos0], temp0, MBZSetup_deformationTable)507arrayPos0++508loop509510CPZSetup_rotatingStairTimer = 0511Water_flashTimer = 0512CPZSetup_hasAchievement = false513CPZSetup_enteredWater = 0514MBZSetup_unused1 = 0515MBZSetup_unused2 = 0516MBZSetup_unused3 = 0517MBZSetup_unused4 = 0518end event519520521// ========================522// Editor Events523// ========================524525event RSDKDraw526DrawSprite(0)527end event528529530event RSDKLoad531LoadSpriteSheet("Global/Display.gif")532SpriteFrame(-16, -16, 32, 32, 1, 143)533534SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")535end event536537538