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

//-------Aliases-------//
private alias 58 : TYPE_TURRETPLATFORM

// Function declarations
reserve function TurretPlatform_Function121
reserve function TurretPlatform_DebugDraw
reserve function TurretPlatform_DebugSpawn

// Static Values
public value TurretPlatform_value47 = 0;

// Tables

function TurretPlatform_Function121
	object[arrayPos0].value0 = 0
	object[arrayPos0].animationTimer = 0
	object[arrayPos0].frame = 0
	object[arrayPos0].state = 0
	object[arrayPos0].priority = PRIORITY_ACTIVE
end function


function TurretPlatform_DebugDraw
	DrawSprite(0)
end function


function TurretPlatform_DebugSpawn
	temp0 = object[0].value17
	temp0 -= TurretPlatform_value47
	temp0 *= 48
	temp0 &= 240
	CreateTempObject(TypeName[Turret Platform], temp0, object.xpos, object.ypos)
	arrayPos0 = object[tempObjectPos].entityPos
	CallFunction(TurretPlatform_Function121)
end function


event ObjectMain
	switch object.state
	case 0
		temp0 = oscillation
		temp0 &= 240
		if temp0 == object.propertyValue
			object.priority = PRIORITY_ACTIVE
			object.value0 = 160
			object.animationTimer = 6
			object.state = 1
		end if
		break
	case 1
		object.animationTimer++
		object.frame = object.animationTimer
		object.frame /= 6
		if object.frame == 4
			object.state = 2
		end if
		break
	case 2
		object.value0--
		if object.value0 == 0
			object.state = 3
		end if
		break
	case 3
		object.animationTimer--
		object.frame = object.animationTimer
		object.frame /= 6
		if object.animationTimer == 0
			object.state = 0
		end if
		break
	end switch
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		if object.frame >= 3
			BoxCollisionTest(C_PLATFORM, object.entityPos, -32, -24, 32, 0, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		end if
	next
	if object.outOfBounds == 1
		arrayPos0 = object.entityPos
		CallFunction(TurretPlatform_Function121)
	end if
end event


event ObjectDraw
	DrawSprite(object.frame)
end event


event ObjectStartup
	LoadSpriteSheet("SCZ/Objects.gif")
	SpriteFrame(-24, -24, 48, 16, 130, 92)
	SpriteFrame(-24, -24, 48, 16, 130, 109)
	SpriteFrame(-24, -24, 48, 16, 130, 126)
	SpriteFrame(-28, -24, 56, 21, 130, 143)
	SpriteFrame(-32, -24, 64, 24, 130, 165)
	foreach (TypeName[Turret Platform], arrayPos0, ALL_ENTITIES)
		CallFunction(TurretPlatform_Function121)
	next
	temp0 = 0
	TurretPlatform_value47 = DebugMode_ObjCount
	while temp0 < 6
		SetTableValue(TypeName[Turret Platform], DebugMode_ObjCount, DebugMode_TypesTable)
		SetTableValue(TurretPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
		SetTableValue(TurretPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
		DebugMode_ObjCount++
		temp0++
	loop
end event

event RSDKDraw
	DrawSprite(0)
end event

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