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

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

private alias object.value0 : object.timer

// States
private alias 0 : HULLSEAL_OPEN
private alias 1 : HULLSEAL_CLOSING
private alias 2 : HULLSEAL_CLOSED

// Player Aliases
private alias object.ypos : player.ypos


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

event ObjectUpdate
	switch object.state
	case HULLSEAL_OPEN
		temp0 = object.ypos
		temp0 += 0x180000
		if player[0].ypos > temp0
			object.timer 		= 16
			object.drawOrder 	= 4
			object.state 		= HULLSEAL_CLOSING
		end if
		break

	case HULLSEAL_CLOSING
		object.xpos += 0x40000

		object.timer--
		if object.timer == 0
			if object.propertyValue == 1
				temp0 = object.xpos
				temp0 >>= 23
				temp1 = object.ypos
				temp1 >>= 23
				SetTileLayerEntry(262, 0, temp0, temp1)
				PlaySfx(SfxName[Hull Close], false)
			end if

			object.state = HULLSEAL_CLOSED
		end if
		break

	case HULLSEAL_CLOSED
		break
		
	end switch

	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_SOLID, object.entityPos, -32, -16, 32, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
	next
end event


event ObjectDraw
	DrawSprite(0)
end event


event ObjectStartup
	LoadSpriteSheet("SCZ/Objects2.gif")
	SpriteFrame(-32, -16, 64, 32, 1, 193)
end event


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

event RSDKEdit
	if editor.returnVariable == true
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			checkResult = object.propertyValue
			break
			
		case 0 // type
			checkResult = object.propertyValue
			break
			
		end switch
	else
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			object.propertyValue = editor.variableValue
			break
			
		case 0 // type
			object.propertyValue = editor.variableValue
			break
			
		end switch
	end if
end event


event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("SCZ/Objects2.gif")
	SpriteFrame(-32, -16, 64, 32, 1, 193)

	AddEditorVariable("type")
	SetActiveVariable("type")
	AddEnumVariable("Doesn't Update TileLayer", 0)
	AddEnumVariable("Updates TileLayer", 1)
end event
