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

//-------Aliases-------//
private alias 53 : TYPE_GASBREAKBLOCK

// Function declarations
reserve function GasBreakBlock_DebugDraw
reserve function GasBreakBlock_DebugSpawn

// Static Values
private value GasBreakBlock_value37 = 0;

// Tables
public table GasBreakBlock_table44
	-0xC0000, -0xC0000, -0x40000, -0xC0000, 0x40000, -0xC0000, 0xC0000, -0xC0000, -0xC0000, -0x40000, -0x40000, -0x40000, 0x40000, -0x40000, 0xC0000, -0x40000
	-0xC0000, 0x40000, -0x40000, 0x40000, 0x40000, 0x40000, 0xC0000, 0x40000, -0xC0000, 0xC0000, -0x40000, 0xC0000, 0x40000, 0xC0000, 0xC0000, 0xC0000
	
end table

public table GasBreakBlock_table45
	-0x40000, -0x40000, -0x20000, -0x40000, 0x20000, -0x40000, 0x40000, -0x40000, -0x3C000, -0x20000, -0x1C000, -0x20000, 0x1C000, -0x20000, 0x3C000, -0x20000
	-0x38000, 0x20000, -0x18000, 0x20000, 0x18000, 0x20000, 0x38000, 0x20000, -0x34000, 0x40000, -0x14000, 0x40000, 0x14000, 0x40000, 0x34000, 0x40000
	
end table

public table GasBreakBlock_table43
	2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5
end table

private table GasBreakBlock_table0
	6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9
end table

function GasBreakBlock_DebugDraw
	temp0 = object[0].value17
	temp0 -= GasBreakBlock_value37
	DrawSprite(temp0)
end function


function GasBreakBlock_DebugSpawn
	temp0 = object[0].value17
	temp0 -= GasBreakBlock_value37
	CreateTempObject(TypeName[Gas Break Block], temp0, object.xpos, object.ypos)
	object[tempObjectPos].frame = temp0
	object[tempObjectPos].drawOrder = 4
end function


event ObjectMain
	switch object.state
	case 0
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -32, 24, 32, 64, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			BoxCollisionTest(C_BOX, object.entityPos, -16, 16, 16, 48, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if object[currentPlayer].animation == ANI_JUMPING
				if object.state == 0
					temp0 = object[currentPlayer].yvel
					BoxCollisionTest(C_BOX, object.entityPos, -16, -16, 16, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
					object[currentPlayer].yvel = temp0
					if checkResult == 1
						object[currentPlayer].gravity = GRAVITY_AIR
						temp0 = 0
						temp1 = 0
						while temp0 < 16
							CreateTempObject(TypeName[Gas Break Block], 0, object.xpos, object.ypos)
							GetTableValue(object[tempObjectPos].frame, temp0, GasBreakBlock_table43)
							GetTableValue(temp2, temp1, GasBreakBlock_table44)
							GetTableValue(object[tempObjectPos].xvel, temp1, GasBreakBlock_table45)
							temp1++
							GetTableValue(temp3, temp1, GasBreakBlock_table44)
							GetTableValue(object[tempObjectPos].yvel, temp1, GasBreakBlock_table45)
							temp1++
							object[tempObjectPos].xpos += temp2
							object[tempObjectPos].ypos += temp3
							object[tempObjectPos].state = 2
							object[tempObjectPos].drawOrder = 5
							temp0++
						loop
						object.state++
						if object.priority != PRIORITY_XBOUNDS_DESTROY
							object.priority = PRIORITY_ACTIVE
						end if
						PlaySfx(SfxName[Block Break], 0)
					end if
				end if
			else
				BoxCollisionTest(C_BOX, object.entityPos, -16, -16, 16, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			end if
		next
		break
	case 1
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -32, 24, 32, 64, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			BoxCollisionTest(C_BOX, object.entityPos, -16, 16, 16, 48, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if object[currentPlayer].state != PlayerObject_Blank
				BoxCollisionTest(C_TOUCH, object.entityPos, -8, -4, 8, 4, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				if checkResult == 1
					object[currentPlayer].state = PlayerObject_Blank
					object[currentPlayer].animation = ANI_JUMPING
					object[currentPlayer].animationSpeed = 240
					object[currentPlayer].value5 = 240
					object[currentPlayer].xpos = object.xpos
					object[currentPlayer].ypos = object.ypos
					if object.propertyValue == 0
						object[currentPlayer].xvel = 0
						object[currentPlayer].yvel = -0x80000
						object[currentPlayer].gravity = GRAVITY_AIR
					else
						object[currentPlayer].xvel = 0x80000
						object[currentPlayer].yvel = 0
					end if
					object[currentPlayer].speed = object[currentPlayer].xvel
					PlaySfx(SfxName[Rolling], 0)
				end if
			end if
		next
		if object.outOfBounds == 1
			if object.priority != PRIORITY_XBOUNDS_DESTROY
				object.priority = PRIORITY_ACTIVE_BOUNDS
				object.state = 0
			end if
		end if
		break
	case 2
		object.xpos += object.xvel
		object.ypos += object.yvel
		object.yvel += 0x1800
		if object.outOfBounds == 1
			object.type = TypeName[Blank Object]
		end if
		break
	end switch
end event


event ObjectDraw
	if object.state != 1
		DrawSprite(object.frame)
	end if
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone07")
	if checkResult == 1
		LoadSpriteSheet("OOZ/Objects.gif")
		SpriteFrame(-16, -16, 32, 32, 69, 141)
		SpriteFrame(-16, -16, 32, 32, 69, 174)
		SpriteFrame(-4, -4, 8, 8, 69, 141)
		SpriteFrame(-4, -4, 8, 8, 77, 141)
		SpriteFrame(-4, -4, 8, 8, 85, 141)
		SpriteFrame(-4, -4, 8, 8, 93, 141)
		SpriteFrame(-4, -4, 8, 8, 69, 141)
		SpriteFrame(-4, -4, 8, 8, 69, 141)
		SpriteFrame(-4, -4, 8, 8, 69, 141)
		SpriteFrame(-4, -4, 8, 8, 69, 141)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-16, -16, 32, 32, 991, 843)
		SpriteFrame(-16, -16, 32, 32, 991, 876)
		SpriteFrame(-4, -4, 8, 8, 991, 843)
		SpriteFrame(-4, -4, 8, 8, 999, 843)
		SpriteFrame(-4, -4, 8, 8, 1007, 843)
		SpriteFrame(-4, -4, 8, 8, 1015, 843)
		SpriteFrame(-4, -4, 8, 8, 991, 843)
		SpriteFrame(-4, -4, 8, 8, 991, 843)
		SpriteFrame(-4, -4, 8, 8, 991, 843)
		SpriteFrame(-4, -4, 8, 8, 991, 843)
	end if
	foreach (TypeName[Gas Break Block], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].propertyValue &= 1
		object[arrayPos0].frame = object[arrayPos0].propertyValue
		object[arrayPos0].drawOrder = 4
	next
	temp0 = 0
	GasBreakBlock_value37 = DebugMode_ObjCount
	while temp0 < 2
		SetTableValue(TypeName[Gas Break Block], DebugMode_ObjCount, DebugMode_TypesTable)
		SetTableValue(GasBreakBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
		SetTableValue(GasBreakBlock_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
