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

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

private alias object.value1 : object.valvePos1.y
private alias object.value2 : object.valvePos2.y

// States
private alias 0 : HPZEGGMANVALVE_RESETBOTH
private alias 1 : HPZEGGMANVALVE_USEL
private alias 2 : HPZEGGMANVALVE_USER
private alias 3 : HPZEGGMANVALVE_USEBOTH
private alias 4 : HPZEGGMANVALVE_DEBRIS


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

event ObjectUpdate
	switch object.state
	case HPZEGGMANVALVE_RESETBOTH
		if object.valvePos1.y > 0
			object.valvePos1.y -= 0x10000
		end if

		if object.valvePos2.y > 0
			object.valvePos2.y -= 0x10000
		end if
		break

	case HPZEGGMANVALVE_USEL
		if object.valvePos1.y < 0x50000
			object.valvePos1.y += 0x10000
		end if

		if object.valvePos2.y > 0
			object.valvePos2.y -= 0x10000
		end if
		break

	case HPZEGGMANVALVE_USER
		if object.valvePos1.y > 0
			object.valvePos1.y -= 0x10000
		end if

		if object.valvePos2.y < 0x50000
			object.valvePos2.y += 0x10000
		end if
		break

	case HPZEGGMANVALVE_USEBOTH
		if object.valvePos1.y < 0x50000
			object.valvePos1.y += 0x10000
		end if

		if object.valvePos2.y < 0x50000
			object.valvePos2.y += 0x10000
		end if
		break

	case HPZEGGMANVALVE_DEBRIS
		object.xpos += object.xvel
		object.ypos += object.yvel
		object.yvel += 0x3800

		if object.outOfBounds == true
			object.type = TypeName[Blank Object]
		end if
		break
		
	end switch
end event


event ObjectDraw
	DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)

	temp0 = object.valvePos1.y
	temp0 += object.ypos
	DrawSpriteFX(1, FX_FLIP, object.xpos, temp0)

	temp0 = object.valvePos2.y
	temp0 += object.ypos
	DrawSpriteFX(2, FX_FLIP, object.xpos, temp0)
end event


event ObjectStartup
	LoadSpriteSheet("HPZ/Objects.gif")
	SpriteFrame(8, -12, 24, 24, 405, 132) // main - #0
	SpriteFrame(10, -20, 10, 8, 407, 123) // valve 1 - #1
	SpriteFrame(20, -20, 10, 8, 407, 123) // valve 2 - #2
end event


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

event RSDKDraw
	DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
	DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)
	DrawSpriteFX(2, FX_FLIP, object.xpos, object.ypos)
end event


event RSDKLoad
	LoadSpriteSheet("HPZ/Objects.gif")
	SpriteFrame(8, -12, 24, 24, 405, 132)
	SpriteFrame(10, -20, 10, 8, 407, 123)
	SpriteFrame(20, -20, 10, 8, 407, 123)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
