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

// ========================
// Aliases
// ========================

private alias object.value0 : object.timer
private alias object.value1 : object.playingMusic

// States
private alias 0 : 2PVSSETUP_SETUP
private alias 1 : 2PVSSETUP_FADEIN
private alias 2 : 2PVSSETUP_MENUACTIVE
private alias 3 : 2PVSSETUP_TOREGULARSTAGE
private alias 4 : 2PVSSETUP_TOSPECIALSTAGE


// ========================
// Events
// ========================

event ObjectUpdate
	options.touchControls = false

	switch object.state
	case 2PVSSETUP_SETUP
		object.timer = 320
		SetScreenFade(0x00, 0x00, 0x00, object.timer)
		stage.debugMode = false
#platform: USE_ORIGINS
		SetScreenCount(1)
#endplatform
		if options.vsMode == false
			vs.player2Type = -1
			vs.stageMask = 0
			vs.match = 0
			vs.tieBreaker = false
			player.lives = 3
			player.lives2 = 3

			SetMusicTrack("Options.ogg", 0, true)
			ResetObjectEntity(1, TypeName[2P VS Menu 1], 0, 0, 0)
		else
			SetMusicTrack("Results.ogg", 0, true)

			if vs.tieBreaker == true
				ResetObjectEntity(1, TypeName[SS Single Result], 0, 0, 0)
			else
				if vs.activeList == REGULAR_STAGE
					ResetObjectEntity(1, TypeName[Act Results], 0, 0, 0)
				else
					ResetObjectEntity(1, TypeName[SS Single Result], 0, 0, 0)
				end if
			end if
		end if
		object[1].priority = PRIORITY_ACTIVE
		object.state++
		break

	case 2PVSSETUP_FADEIN
		if object.timer > 0
			object.timer -= 16
		else
			if object.playingMusic == false
				PlayMusic(0)
				object.playingMusic = true
			end if
			
			object.state++
		end if
		SetScreenFade(0x00, 0x00, 0x00, object.timer)
		break

	case 2PVSSETUP_MENUACTIVE
		break

	case 2PVSSETUP_TOREGULARSTAGE
		if object.timer < 256
			music.volume -= 10
			object.timer += 16
			SetScreenFade(0x00, 0x00, 0x00, object.timer)
		else
			player.score = 0
			player.score2 = 0
			vs.totalRings1P = 0
			vs.totalRings2P = 0
			vs.items1P = 0
			vs.items2P = 0
			vs.dataSent = false
			StopMusic()
			LoadStage()
			SetScreenFade(0x00, 0x00, 0x00, 0xFF)
		end if
		break

	case 2PVSSETUP_TOSPECIALSTAGE
		if object.timer < 768
			music.volume -= 10
			object.timer += 8
			SetScreenFade(0xD0, 0xFF, 0xE0, object.timer)
		else
			vs.checkpoint1P = 0
			vs.checkpoint2P = 0
			fadeColor = 0xD0
			fadeColor <<= 16
			temp0 = 0xFF
			temp0 <<= 8
			fadeColor += temp0
			fadeColor += 0xE0
			StopMusic()
			LoadStage()
			SetScreenFade(0xD0, 0xFF, 0xE0, 255)
		end if
		break
		
	end switch
end event


event ObjectStartup
	LoadSpriteSheet("LevelSelect/Icons.gif")
	
	// If any 2P VS Setup Objects are in the scene, then start up the 2P Menu
	foreach (TypeName[2P VS Setup], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].type = TypeName[Blank Object]
		ResetObjectEntity(0, TypeName[2P VS Setup], 0, 0, 0)
		object[0].priority = PRIORITY_ACTIVE
	next
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


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