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

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

private alias object.value17 : debugMode.currentSelection


// ========================
// Function Declarations
// ========================

reserve function Waterfall_DebugDraw
reserve function Waterfall_DebugSpawn


// ========================
// Static Values
// ========================

private value Waterfall_startDebugID = 0


// ========================
// Function Definitions
// ========================

private function Waterfall_DebugDraw
	temp0 = debugMode[0].currentSelection
	temp0 -= Waterfall_startDebugID
	DrawSprite(temp0)
end function


private function Waterfall_DebugSpawn
	temp0 = debugMode[0].currentSelection
	temp0 -= Waterfall_startDebugID
	CreateTempObject(TypeName[Waterfall], temp0, object.xpos, object.ypos)
	object[tempObjectPos].inkEffect = INK_ALPHA
	object[tempObjectPos].alpha     = 0xA0
	object[tempObjectPos].drawOrder = 5
end function


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

event ObjectUpdate
	// Empty :(
end event


event ObjectDraw
	DrawSpriteFX(object.propertyValue, FX_INK, object.xpos, object.ypos)
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone01")
	if checkResult == true
		LoadSpriteSheet("EHZ/Objects.gif")
		
		// Top 1 Frame
		SpriteFrame(-32, -128, 64, 16, 192, 0)
		
		// Huge with Top Frame
		SpriteFrame(-32, -128, 64, 256, 192, 0)
		
		// Blank 1 Frame
		SpriteFrame(0, 0, 1, 1, 1, 1)
		
		// Small Frame
		SpriteFrame(-32, -32, 64, 64, 192, 16)
		
		// Blank 2 Frame
		SpriteFrame(0, 0, 1, 1, 1, 1)
		
		// Medium Frame
		SpriteFrame(-32, -64, 64, 160, 192, 16)
		
		// Top 2 Frame
		SpriteFrame(-32, -128, 64, 16, 192, 0)
		
		// Medium Higher with Top Frame
		SpriteFrame(-32, -128, 64, 192, 192, 0)
		
		// Medium 2 Frame
		SpriteFrame(-32, -32, 64, 96, 192, 64)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		
		// Top 1 Frame
		SpriteFrame(-32, -128, 64, 16, 1, 435)
		
		// Huge with Top Frame
		SpriteFrame(-32, -128, 64, 256, 1, 435)
		
		// Blank 1 Frame
		SpriteFrame(0, 0, 1, 1, 1, 1)
		
		// Small Frame
		SpriteFrame(-32, -32, 64, 64, 1, 451)
		
		// Blank 2 Frame
		SpriteFrame(0, 0, 1, 1, 1, 1)
		
		// Medium Frame
		SpriteFrame(-32, -64, 64, 160, 1, 451)
		
		// Top 2 Frame
		SpriteFrame(-32, -128, 64, 16, 1, 435)
		
		// Medium Higher with Top Frame
		SpriteFrame(-32, -128, 64, 192, 1, 435)
		
		// Medium 2 Frame
		SpriteFrame(-32, -32, 64, 96, 1, 499)
	end if
	
	// (yeah these names are kinda weird but hey, if that's what they're officially called in S2 3.0.1's leftover dev files then we may as well stick with them)
	
	foreach (TypeName[Waterfall], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].inkEffect = INK_ALPHA
		object[arrayPos0].alpha 	= 0xA0
		object[arrayPos0].drawOrder = 5
	next

	temp0 = 0
	Waterfall_startDebugID = DebugMode_ObjCount
	while temp0 < 8
		SetTableValue(TypeName[Waterfall], DebugMode_ObjCount, DebugMode_TypesTable)
		SetTableValue(Waterfall_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
		SetTableValue(Waterfall_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
		DebugMode_ObjCount++
		temp0++
	loop
end event


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

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


event RSDKDraw
	object.inkEffect = INK_ALPHA
	object.alpha = 0xA0
	DrawSpriteFX(object.propertyValue, FX_INK, object.xpos, object.ypos)
end event


event RSDKLoad
	CheckCurrentStageFolder("Zone01")
	if checkResult == true
		LoadSpriteSheet("EHZ/Objects.gif")
		SpriteFrame(-32, -128, 64, 16, 192, 0)
		SpriteFrame(-32, -128, 64, 256, 192, 0)
		SpriteFrame(0, 0, 1, 1, 1, 1)
		SpriteFrame(-32, -32, 64, 64, 192, 16)
		SpriteFrame(0, 0, 1, 1, 1, 1)
		SpriteFrame(-32, -64, 64, 160, 192, 16)
		SpriteFrame(-32, -128, 64, 16, 192, 0)
		SpriteFrame(-32, -128, 64, 192, 192, 0)
		SpriteFrame(-32, -32, 64, 96, 192, 64)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-32, -128, 64, 16, 1, 435)
		SpriteFrame(-32, -128, 64, 256, 1, 435)
		SpriteFrame(0, 0, 1, 1, 1, 1)
		SpriteFrame(-32, -32, 64, 64, 1, 451)
		SpriteFrame(0, 0, 1, 1, 1, 1)
		SpriteFrame(-32, -64, 64, 160, 1, 451)
		SpriteFrame(-32, -128, 64, 16, 1, 435)
		SpriteFrame(-32, -128, 64, 192, 1, 435)
		SpriteFrame(-32, -32, 64, 96, 1, 499)
	end if
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "frameID")
end event
