// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: SLZ Setup Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 39 : TYPE_SLZSETUP

// Function declarations
reserve function SLZSetup_Function93
reserve function SLZSetup_Function94

reserve function SLZSetup_SLZ2SpeedUp
reserve function SLZSetup_SLZ2SlowDown

// Static Values
public value SLZSetup_value29 = 0;

// Tables
public table SLZSetup_table25
	0xA0A0, 0x6060, 0x2020, 0x6060, 0xA0A0, 0xE0E0
end tablee

public table SLZSetup_table26
	0xA00000, 0xE00000, 0xA00000, 0x600000, 0x200000, 0x600000
end table

public table SLZSetup_table27
	0x202000, 0x606000, 0xA0A000, 0xE0E000, 0xA0A000, 0x606000
end table

public table SLZSetup_table3
	0xBB00000, 0x4C0000, 0, 37, 8, 36, 0, 6, 8, 204, 2, 39, 0, 159, 4, 37, 52, 1, 36, 7, 4, 47, 52, 1, 36, 33
end table

function SLZSetup_Function93
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("Invincibility_F.ogg", 2, 0x76E4)
			SwapMusicTrack("Starlight_F.ogg", 0, 0x10838, 0x1F40)
			break
		case 2
			SetMusicTrack("Starlight_F.ogg", 0, 0x10838)
			SwapMusicTrack("Invincibility_F.ogg", 2, 0x76E4, 0x1F40)
			break
		default
			SetMusicTrack("Starlight_F.ogg", 0, 0x10838)
			SetMusicTrack("Invincibility_F.ogg", 2, 0x76E4)
			break
		end switch
	else
		stage.musicFlag = 1
	end if
end function


function SLZSetup_Function94
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("Invincibility.ogg", 2, 0x9A68)
			SwapMusicTrack("Starlight.ogg", 0, 0x1498C, 0x30D4)
			break
		case 2
			SetMusicTrack("Starlight.ogg", 0, 0x1498C)
			SwapMusicTrack("Invincibility.ogg", 2, 0x9A68, 0x30D4)
			break
		default
			SetMusicTrack("Starlight.ogg", 0, 0x1498C)
			SetMusicTrack("Invincibility.ogg", 2, 0x9A68)
			break
		end switch
	else
		stage.musicFlag = 2
	end if
end function


function SLZSetup_SLZ2SpeedUp
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("Invincibility_F.ogg", 2, 0x76E4)
			SwapMusicTrack("Starlight_F.ogg", 0, 0x10838, 0x1F40)
			break
		case 2
			SetMusicTrack("Starlight_F.ogg", 0, 0x10838)
			SwapMusicTrack("Invincibility_F.ogg", 2, 0x76E4, 0x1F40)
			break
		default
			SetMusicTrack("Starlight_F.ogg", 0, 0x10838)
			SetMusicTrack("Invincibility_F.ogg", 2, 0x76E4)
			break
		end switch
	else
		stage.musicFlag = 1
	end if
end function


function SLZSetup_SLZ2SlowDown
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("Invincibility.ogg", 2, 0x9A68)
			SwapMusicTrack("Starlight2.ogg", 0, 81477, 0x30D4)
			break
		case 2
			SetMusicTrack("Starlight2.ogg", 0, 81477)
			SwapMusicTrack("Invincibility.ogg", 2, 0x9A68, 0x30D4)
			break
		default
			SetMusicTrack("Starlight2.ogg", 0, 81477)
			SetMusicTrack("Invincibility.ogg", 2, 0x9A68)
			break
		end switch
	else
		stage.musicFlag = 2
	end if
end function


event ObjectMain
	GetTableValue(temp0, 21, StageSetup_table9)
	if temp0 == 0
		SLZSetup_value29++
		SLZSetup_value29 &= 3
	end if
	object.value0++
	if object.value0 == 8
		object.value0 = 0
		object.value1++
		object.value1 %= 6
		GetTableValue(temp0, object.value1, SLZSetup_table25)
		SetPaletteEntry(0, 171, temp0)
		GetTableValue(temp0, object.value1, SLZSetup_table26)
		SetPaletteEntry(0, 173, temp0)
		GetTableValue(temp0, object.value1, SLZSetup_table27)
		SetPaletteEntry(0, 174, temp0)
	end if
end event


event ObjectDraw
	temp0 = screen.xoffset
	temp0 <<= 1
	temp0 &= 511
	FlipSign(temp0)
	temp0 += object.value2
	temp1 = screen.yoffset
	temp1 <<= 1
	temp1 &= 255
	FlipSign(temp1)
	DrawSpriteScreenXY(0, temp0, temp1)
	DrawSpriteScreenXY(1, temp0, temp1)
end event


event ObjectStartup
	LoadSpriteSheet("SLZ/Objects.gif")
	if saved.actTheme == 1
		switch stage.actNum
		case 1
			SetMusicTrack("Starlight.ogg", 0, 0x1498C)
			SpeedUpMusic = SLZSetup_Function93
			SlowDownMusic = SLZSetup_Function94	
			break
		case 2
			SetMusicTrack("Starlight2.ogg", 0, 81477)
			SpeedUpMusic = SLZSetup_SLZ2SpeedUp
			SlowDownMusic = SLZSetup_SLZ2SlowDown	
			break			
		end switch
	else
		SetMusicTrack("Starlight.ogg", 0, 0x1498C)
		SpeedUpMusic = SLZSetup_Function93
		SlowDownMusic = SLZSetup_Function94
	end if
	SpriteFrame(-16, 0, 32, 256, 224, 0)
	SpriteFrame(-16, 256, 32, 256, 224, 0)
	animalType1 = TypeName[Flicky]
	animalType2 = TypeName[Picky]
	object[10].type = TypeName[SLZ Setup]
	object[10].priority = PRIORITY_ACTIVE
	object[10].drawOrder = 5
	object[10].value2 = 496
	temp0 = screen.xcenter
	temp0 >>= 2
	object[10].value2 -= temp0
	SLZSetup_value29 = 0
	if options.attractMode == 1
		PlayerObject_ReplayTable = SLZSetup_table3
		PlayerObject_ReplaySize = 26
		PlayerObject_ReplayLength = 540
		CallFunction(PlayerObject_InitReplay)
	end if

	if stage.actNum == 1
		ResetObjectEntity(342, TypeName[Blank Object], 0, 0, 0)
		ResetObjectEntity(343, TypeName[Blank Object], 0, 0, 0)
		ResetObjectEntity(344, TypeName[Blank Object], 0, 0, 0)
	end if

	foreach (TypeName[Invisible Block], arrayPos0, ALL_ENTITIES)
		if object[arrayPos0].ypos < 0
			ResetObjectEntity(arrayPos0, TypeName[Blank Object], 0, 0, 0)
		end if
	next
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
