// ----------------------------------
// RSDK Project: Sonic 1
// Script Description: Plane Sw L Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

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

private alias object.value0 : object.extendTop
private alias object.value1 : object.extendBottom

// Player Aliases
private alias object.speed : player.speed
private alias object.gravity : player.gravity
private alias object.collisionPlane : player.collisionPlane


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

event ObjectUpdate
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		if player[currentPlayer].gravity == GRAVITY_GROUND
			BoxCollisionTest(C_TOUCH, object.entityPos, -12, object.extendTop, 12, object.extendBottom, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			if checkResult == true
				if player[currentPlayer].speed > 0
					player[currentPlayer].collisionPlane = 1
				else
					player[currentPlayer].collisionPlane = 0
				end if
			end if
		end if
	next
end event


event ObjectStartup
	foreach (TypeName[Plane Sw L], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].extendTop = object[arrayPos0].propertyValue
		object[arrayPos0].extendTop <<= 3
		object[arrayPos0].extendBottom = object[arrayPos0].extendTop
		FlipSign(object[arrayPos0].extendTop)
		object[arrayPos0].extendTop -= 8
		object[arrayPos0].extendBottom += 8
	next
end event


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

event RSDKEdit
	if editor.returnVariable == true
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			checkResult = object.propertyValue
			checkResult &= 3
			break
			
		case 0 // size
			checkResult = object.propertyValue
			checkResult &= 3
			break
			
		end switch
	else
		switch editor.variableID
		case EDIT_VAR_PROPVAL // property value
			object.propertyValue = editor.variableValue
			object.propertyValue &= 3
			break
			
		case 0 // size
			temp1 = 3
			Not(temp1)
			object.propertyValue &= temp1

			temp0 = editor.variableValue
			temp0 &= 3
			object.propertyValue = temp0
			break
			
		end switch
	end if
end event


event RSDKDraw
	// Grabbed this and edited it from from S2's debug view, since S1 doesn't have one

	// size
	temp1 = object.propertyValue
	temp1 &= 3
	temp1 += 2

	temp0 = 1
	temp0 <<= temp1
	temp1 = temp0
	temp0 <<= 19
	FlipSign(temp0)
	temp0 += object.ypos
	temp0 += 0x80000
	
	temp4 = 0
	while temp4 < temp1
		DrawSpriteXY(0, object.xpos, temp0)
		temp0 += 0x100000
		temp4++
	loop

	if temp1 == 0
		DrawSprite(0)
	end if
end event


event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-8, -8, 16, 16, 222, 239)

	AddEditorVariable("size")
	SetActiveVariable("size")
	AddEnumVariable("4 Nodes", 0)
	AddEnumVariable("8 Nodes", 1)
	AddEnumVariable("16 Nodes", 2)
	AddEnumVariable("32 Nodes", 3)
end event
