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

//-------Aliases-------//
private alias 58 : TYPE_EARTHQUAKE


// Static Values

// Tables
public table Earthquake_table49
	-192, -256, 192, 256, -192, -320, 192, 320, -192, -448, 192, 448, -384, -256, 384, 128
	-448, -448, 448, 448, -448, -448, 448, 448
end table

public table Earthquake_table51
	-192, -640, 0x412, 256, 0, 0, 0, 0, 0, 0, 0, 0, -384, -896, 600, 128
	-448, -0x540, 672, 448, -448, -0x460, 672, 448
end table

public table Earthquake_table50
	-448, -640, 0x512, 256, 0, 0, 0, 0, 0, 0, 0, 0, -640, -896, 856, 128
	-704, -0x540, 928, 448, -704, -0x460, 928, 448
end table

public table Earthquake_table46
	1, 1, 1, 2, 3, 4
end table

public table Earthquake_table48
	-0xE00000, -0x1400000, 0, -0x2B40000, 0, -0x3000000, 0, -0x3500000
end table

public table Earthquake_table47
	0, 0, 0x6800000, 0x11800000
end table


event ObjectMain	
	BoxCollisionTest(C_TOUCH, object.entityPos, object.value7, object.value8, object.value9, object.value10, 0, 0, 0, 0, 0)
	if checkResult == 1
		if HTZSetup_value33 == 0
			HTZSetup_value33 = 2
			HTZSetup_value34 = object.value0
			HTZSetup_value37 = object.value1
			HTZSetup_value35 = object.value2
			HTZSetup_value38 = object.propertyValue
			hParallax[20].scrollPos = object.value16
		end if
	end if
	BoxCollisionTest(C_TOUCH, object.entityPos, object.value3, object.value4, object.value5, object.value6, 0, 0, 0, 0, 0)
	if checkResult == 1
		if HTZSetup_value33 == 0
			HTZSetup_value33 = 1
			HTZSetup_value34 = object.value0
			HTZSetup_value37 = object.value1
			HTZSetup_value35 = object.value2
			hParallax[20].scrollPos = object.value16
		end if
	end if
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		temp0 = object.value12
		temp0 -= object.value15
		temp1 = object.value14
		temp1 -= object.value15
		if object.propertyValue == 3
			temp2 = object[currentPlayer].xpos
			temp2 -= object.xpos
			temp2 += 0x1800000
			if temp2 > 0
				temp2 >>= 18
				temp0 += temp2
			end if
			temp0++
			if object[currentPlayer].value42 == 0
				if object[currentPlayer].gravity == GRAVITY_AIR
					if object[currentPlayer].xvel > 0
						temp2 = object[currentPlayer].xvel
						temp2 >>= 2
						object[currentPlayer].ypos += temp2
						object[currentPlayer].ypos += 0x20000
					end if
				end if
			end if
		end if
		BoxCollisionTest(C_BOX, object.entityPos, object.value11, temp0, object.value13, temp1, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		switch checkResult
		case 1
			temp0 = HTZSetup_value36
			temp0 -= object.value15
			temp0 <<= 16
			object[currentPlayer].ypos -= temp0
		case 2
		case 3
			if object.propertyValue == 2
				CallFunction(PlayerObject_FireHit)
			end if
			if object.propertyValue == 4
				CallFunction(PlayerObject_FireHit)
			end if
			if object.propertyValue == 5
				CallFunction(PlayerObject_FireHit)
			end if
			break
		case 4
			if object[currentPlayer].gravity == GRAVITY_GROUND
				CallFunction(PlayerObject_Kill)
			end if
			break
		end switch
	next
	foreach (TypeName[Lose Ring], arrayPos0, ACTIVE_ENTITIES)
		if object[arrayPos0].yvel >= 0
			temp0 = object.value12
			temp0 -= object.value15
			temp1 = object.value14
			temp1 -= object.value15
			if object.propertyValue == 3
				temp2 = object[arrayPos0].xpos
				temp2 -= object.xpos
				temp2 += 0x1800000
				if temp2 > 0
					temp2 >>= 18
					temp0 += temp2
				end if
				temp0++
			end if
			temp2 = object[arrayPos0].yvel
			BoxCollisionTest(C_PLATFORM, object.entityPos, object.value11, temp0, object.value13, temp1, arrayPos0, -8, -8, 8, 8)
			if checkResult == 1
				object[arrayPos0].yvel = temp2
				temp2 >>= 2
				object[arrayPos0].yvel -= temp2
				FlipSign(object[arrayPos0].yvel)
				if object[arrayPos0].yvel > -0x10000
					object[arrayPos0].yvel = -0x10000
				end if
				object[arrayPos0].gravity = GRAVITY_AIR
			end if
		end if
	next
	object.value15 = HTZSetup_value36
end event


event ObjectStartup
	foreach (TypeName[Earthquake], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].priority = PRIORITY_ACTIVE
		GetTableValue(object[arrayPos0].value0, object[arrayPos0].propertyValue, Earthquake_table46)
		temp0 = object[arrayPos0].value0
		temp0--
		GetTableValue(object[arrayPos0].value16, temp0, Earthquake_table47)
		temp0 <<= 1
		GetTableValue(object[arrayPos0].value1, temp0, Earthquake_table48)
		temp0++
		GetTableValue(object[arrayPos0].value2, temp0, Earthquake_table48)
		temp0 = object[arrayPos0].propertyValue
		temp0 <<= 2
		GetTableValue(object[arrayPos0].value11, temp0, Earthquake_table49)
		GetTableValue(object[arrayPos0].value3, temp0, Earthquake_table50)
		GetTableValue(object[arrayPos0].value7, temp0, Earthquake_table51)
		temp0++
		GetTableValue(object[arrayPos0].value12, temp0, Earthquake_table49)
		GetTableValue(object[arrayPos0].value4, temp0, Earthquake_table50)
		GetTableValue(object[arrayPos0].value8, temp0, Earthquake_table51)
		temp0++
		GetTableValue(object[arrayPos0].value13, temp0, Earthquake_table49)
		GetTableValue(object[arrayPos0].value5, temp0, Earthquake_table50)
		GetTableValue(object[arrayPos0].value9, temp0, Earthquake_table51)
		temp0++
		GetTableValue(object[arrayPos0].value14, temp0, Earthquake_table49)
		GetTableValue(object[arrayPos0].value6, temp0, Earthquake_table50)
		GetTableValue(object[arrayPos0].value10, temp0, Earthquake_table51)
		if options.vsMode == 1
			ResetObjectEntity(arrayPos0, TypeName[Blank Object], 0, 0, 0)
		end if
	next
end event

event RSDKDraw
	DrawSprite(0)
end event

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