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

//-------Aliases-------//
private alias 48 : TYPE_SPIRALPATH


// Static Values

// Tables
public table SpiralPath_table45
	6, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7
end table

public table SpiralPath_table44
	32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32
	32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 31, 31
	31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 30, 30, 30
	30, 30, 30, 30, 30, 30, 29, 29, 29, 29, 29, 28, 28, 28, 28, 27
	27, 27, 27, 26, 26, 26, 25, 25, 25, 24, 24, 24, 23, 23, 22, 22
	21, 21, 20, 20, 19, 18, 18, 17, 16, 16, 15, 14, 14, 13, 12, 12
	11, 10, 10, 9, 8, 8, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1
	0, -1, -2, -2, -3, -4, -4, -5, -6, -7, -7, -8, -9, -9, -10, -10
	-11, -11, -12, -12, -13, -14, -14, -15, -15, -16, -16, -17, -17, -18, -18, -19
	-19, -19, -20, -21, -21, -22, -22, -23, -23, -24, -24, -25, -25, -26, -26, -27
	-27, -28, -28, -28, -29, -29, -30, -30, -30, -31, -31, -31, -32, -32, -32, -33
	-33, -33, -33, -34, -34, -34, -35, -35, -35, -35, -35, -35, -35, -35, -36, -36
	-36, -36, -36, -36, -36, -36, -36, -37, -37, -37, -37, -37, -37, -37, -37, -37
	-37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37
	-37, -37, -37, -37, -36, -36, -36, -36, -36, -36, -36, -35, -35, -35, -35, -35
	-35, -35, -35, -34, -34, -34, -33, -33, -33, -33, -32, -32, -32, -31, -31, -31
	-30, -30, -30, -29, -29, -28, -28, -28, -27, -27, -26, -26, -25, -25, -24, -24
	-23, -23, -22, -22, -21, -21, -20, -19, -19, -18, -18, -17, -16, -16, -15, -14
	-14, -13, -12, -11, -11, -10, -9, -8, -7, -7, -6, -5, -4, -3, -2, -1
	0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 10, 11, 12, 13
	13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21
	21, 22, 22, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 26
	27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29
	29, 30, 30, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 31
	31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32
	32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32
end table


event ObjectMain
	object.priority = PRIORITY_ACTIVE
	temp2 = 0
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		temp0 = object[currentPlayer].xpos
		temp0 -= object.xpos
		GetBit(temp3, object.value1, temp2)
		if temp3 == 0
			if object[currentPlayer].value42 == 0
				BoxCollisionTest(C_TOUCH, object.entityPos, -192, 8, 192, 64, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				if checkResult == 1
					SetBit(object.value1, temp2, 1)
					object[currentPlayer].yvel = 0
				end if
			end if
		else
			temp0 += 0xD00000
			temp1 = object[currentPlayer].xvel
			Abs(temp1)
			CheckLower(temp1, 0x60000)
			temp3 = checkResult
			CheckLower(object[currentPlayer].yvel, -0x40000)
			temp3 |= checkResult
			CheckLower(temp0, 0)
			temp3 |= checkResult
			CheckGreater(temp0, 0x19FFFFF)
			temp3 |= checkResult
			if temp3 == 1
				SetBit(object.value1, temp2, 0)
				if object[currentPlayer].value42 == 1
					if object[currentPlayer].yvel >= 0
						if object[currentPlayer].state != PlayerObject_HandleFlyCarry
							if object[currentPlayer].animation != ANI_SKIDDING
								object[currentPlayer].animation = ANI_TWIRL
								object[currentPlayer].angle = 0
							end if
						end if
					end if
				end if
			else
				object[currentPlayer].yvel = 0
				temp0 >>= 16
				GetTableValue(object[currentPlayer].ypos, temp0, SpiralPath_table44)
				object[currentPlayer].ypos -= object[currentPlayer].collisionBottom
				object[currentPlayer].ypos += 19
				object[currentPlayer].ypos <<= 16
				object[currentPlayer].ypos += object.ypos
				if object[currentPlayer].state == PlayerObject_HandleGround
					if object[currentPlayer].gravity == GRAVITY_AIR
						object[currentPlayer].prevAnimation = ANI_TWIRL
						object[currentPlayer].animation = ANI_TWIRL
						object[currentPlayer].animationSpeed = 0
						object[currentPlayer].direction = FLIP_NONE
						temp1 = object.xpos
						temp1 -= 0xC40000
						temp0 = object[currentPlayer].xpos
						temp0 -= temp1
						temp0 >>= 21
						temp0 %= 12
						if object[currentPlayer].speed > 0
							object[currentPlayer].frame = temp0
							object[currentPlayer].rotation = 0
						else
							GetTableValue(object[currentPlayer].frame, temp0, SpiralPath_table45)
							object[currentPlayer].rotation = 256
						end if
					end if
				end if
				object[currentPlayer].gravity = GRAVITY_GROUND
			end if
		end if
		temp2++
	next
	if object.outOfBounds == 1
		object.priority = PRIORITY_ACTIVE_BOUNDS
		temp0 = 0
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -192, 8, 192, 64, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			temp0 |= checkResult
		next
		if temp0 == 0
			object.value1 = 0
		end if
	end if
end event

event RSDKDraw
	DrawSprite(0)
end event

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