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

//-------Aliases-------//
private alias 40 : TYPE_WFZSETUP

// Function declarations
reserve function WFZSetup_Function97
reserve function WFZSetup_Function98
reserve function WFZSetup_Function99

// Static Values
public value WFZSetup_value33 = 0;
public value WFZSetup_value34 = 0;
public value WFZSetup_value35 = 0;
public value WFZSetup_value36 = 0;
public value WFZSetup_value37 = 0;
public value WFZSetup_value38 = 0;

// Tables
public table WFZSetup_table38
	0xE0E040, 0xE0A020, 0xE06000, 0xC02000, 0xE0E0E0, 0xE0E040, 0xE0A020, 0xE06000, 0xE0E040, 0xE0A020, 0xE06000, 0xC02000, 0xE0A020, 0xE06000, 0xC02000, 0x802000
end table

function WFZSetup_Function97
	object.gravity = GRAVITY_AIR
	if object.animation != ANI_CLINGING
		object.xvel = -0x80000
		object.speed = -0x80000
	else
		object.xvel = 0
		object.speed = 0
	end if
	if object.up == 1
		object.ypos -= 0x10000
	else
		if object.down == 1
			object.ypos += 0x10000
		end if
	end if
	object.yvel = 0
end function


function WFZSetup_Function98
	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, 0x78B1)
			SwapMusicTrack("WingFortress_F.ogg", 0, 0x138CA, 0x1F40)
			break
		case 2
			SetMusicTrack("WingFortress_F.ogg", 0, 0x138CA)
			SwapMusicTrack("Invincibility_F.ogg", 2, 0x78B1, 0x1F40)
			break
		case 4
		case 6
		case 7
			SetMusicTrack("WingFortress_F.ogg", 0, 0x138CA)
			SetMusicTrack("Invincibility_F.ogg", 2, 0x78B1)
			break
		end switch
	else
		stage.musicFlag = 1
	end if
end function


function WFZSetup_Function99
	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, 0x9717)
			SwapMusicTrack("WingFortress.ogg", 0, 0x18622, 0x30D4)
			break
		case 2
			SetMusicTrack("WingFortress.ogg", 0, 0x18622)
			SwapMusicTrack("Invincibility.ogg", 2, 0x9717, 0x30D4)
			break
		case 4
		case 6
		case 7
			SetMusicTrack("WingFortress.ogg", 0, 0x18622)
			SetMusicTrack("Invincibility.ogg", 2, 0x9717)
			break
		end switch
	else
		stage.musicFlag = 2
	end if
end function


event ObjectMain
	object.value1++
	if object.value1 == 2
		object.value1 = 0
		GetTableValue(temp0, object.value2, WFZSetup_table38)
		SetPaletteEntry(0, 167, temp0)
		object.value2++
		object.value2 &= 15
		GetTableValue(temp0, object.value2, WFZSetup_table38)
		SetPaletteEntry(0, 168, temp0)
		object.value2++
		object.value2 &= 15
		GetTableValue(temp0, object.value2, WFZSetup_table38)
		SetPaletteEntry(0, 169, temp0)
		object.value2++
		object.value2 &= 15
		GetTableValue(temp0, object.value2, WFZSetup_table38)
		SetPaletteEntry(0, 170, temp0)
		object.value2++
		object.value2 &= 15
	end if
	object.value3++
	if object.value3 == 6
		object.value3 = 0
		RotatePalette(0, 192, 195, 1)
	end if
	WFZSetup_value35 = WFZSetup_value36
	WFZSetup_value35 >>= 1
	WFZSetup_value36++
	WFZSetup_value36 %= 12
	WFZSetup_value37 = WFZSetup_value38
	WFZSetup_value37 >>= 1
	WFZSetup_value38++
	WFZSetup_value38 %= 6
end event


event ObjectStartup
	SetMusicTrack("WingFortress.ogg", 0, 0x18622)
	SpeedUpMusic = WFZSetup_Function98
	SlowDownMusic = WFZSetup_Function99
	animalType1 = TypeName[Locky]
	animalType2 = TypeName[Wocky]
	SetPaletteEntry(0, 196, 0)
	object[10].type = TypeName[WFZ Setup]
	object[10].priority = PRIORITY_ACTIVE
	WFZSetup_value33 = 0
	WFZSetup_value34 = 0
	WFZSetup_value35 = 0
	WFZSetup_value36 = 0
	WFZSetup_value37 = 0
	WFZSetup_value38 = 0
	foreach (TypeName[Animal Prison], arrayPos0, ALL_ENTITIES)
		if options.gameMode != 2
			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
