// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Breakoff Pillar Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 48 : TYPE_BREAKOFFPILLAR

// Function declarations
reserve function BreakoffPillar_DebugDraw
reserve function BreakoffPillar_DebugSpawn

// Static Values

// Tables
public table BreakoffPillar_table41
	0, 0x10000, -0x10000, 0x10000, 0, -0x10000, 0, 0x10000
end table


function BreakoffPillar_DebugDraw
	DrawSprite(0)
	DrawSprite(1)
	DrawSprite(2)
end function


function BreakoffPillar_DebugSpawn
	CreateTempObject(TypeName[Breakoff Pillar], 0, object.xpos, object.ypos)
	object[tempObjectPos].frame = 2
end function


event ObjectMain
	switch object.state
	case 0
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -128, -256, 128, 256, currentPlayer, -1, -1, 1, 1)
			if checkResult == 1
				object.priority = PRIORITY_ACTIVE
				object.value2 = 8
				object.state = 1
			end if
		next
		break
	case 1
		object.value2--
		if object.value2 >= 0
			GetTableValue(object.value1, object.value2, BreakoffPillar_table41)
		else
			object.state = 2
		end if
		break
	case 2
		object.value0 += object.yvel
		object.yvel += 0x3800
		temp0 = object.ypos
		object.ypos += object.value0
		temp1 = object.ypos
		ObjectTileCollision(CSIDE_FLOOR, 0, 65, 0)
		if checkResult == 1
			object.state = 3
			object.frame++
		end if
		temp1 -= object.ypos
		object.ypos = temp0
		object.value0 -= temp1
		break
	case 3
		break
	end switch
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_BOX, object.entityPos, -16, -32, 16, 32, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		temp0 = object.ypos
		object.ypos += object.value0
		BoxCollisionTest(C_BOX, object.entityPos, -16, 32, 16, 65, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		if checkResult == 4
			if object[currentPlayer].gravity == GRAVITY_GROUND
				CallFunction(PlayerObject_Kill)
			end if
		end if
		object.ypos = temp0
	next
	temp0 = object.ixpos
	temp0 -= screen.cameraX
	Abs(temp0)
	temp0 -= 184
	if temp0 >= screen.xcenter
		object.value0 = 0
		object.value1 = 0
		object.yvel = 0
		object.value2 = 0
		object.frame = 2
		object.state = 0
		object.priority = PRIORITY_ACTIVE_BOUNDS
	end if
end event


event ObjectDraw
	DrawSprite(0)
	DrawSprite(1)
	temp0 = object.xpos
	temp0 += object.value1
	temp1 = object.ypos
	temp1 += object.value0
	DrawSpriteXY(object.frame, temp0, temp1)
end event


event ObjectStartup
	LoadSpriteSheet("ARZ/Objects.gif")
	SpriteFrame(-28, -32, 56, 56, 59, 42)
	SpriteFrame(-16, 24, 32, 8, 140, 80)
	SpriteFrame(-16, 32, 32, 37, 173, 38)
	SpriteFrame(-16, 32, 32, 41, 140, 38)
	SetTableValue(TypeName[Breakoff Pillar], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(BreakoffPillar_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(BreakoffPillar_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
	foreach (TypeName[Breakoff Pillar], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].frame = 2
	next
end event

event RSDKDraw
	DrawSprite(0)
end event

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