// ----------------------------------
// RSDK Project: Sonic 2
// Script Description: Ground Flame Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// ========================
// Aliases
// ========================

private alias object.value0 : object.timer

// Path ID Aliases
private alias 0 : PATH_A


// ========================
// Tables
// ========================

private table GroundFlame_aniTable
	4, 5, 2, 3, 0, 1, 0, 1, 2, 3, 4, 5, 6
end table

private table GroundFlame_hitboxes
	0, 0, -8, -8, -15, -15
end table


// ========================
// Events
// ========================

event ObjectUpdate
	ObjectTileGrip(CSIDE_FLOOR, 0, 9, PATH_A)
	if checkResult == false
		object.type = TypeName[Blank Object]
	end if

	temp0 = object.animationTimer
	temp0 /= 6
	GetTableValue(object.frame, temp0, GroundFlame_aniTable)
	
	object.animationTimer++
	if object.animationTimer == 10
		if object.timer > 0
			CreateTempObject(TypeName[Ground Flame], 0, object.xpos, object.ypos)
			if object.direction == FLIP_NONE
				object[tempObjectPos].xpos -= 0xE0000
			else
				object[tempObjectPos].xpos += 0xE0000
			end if
			object[tempObjectPos].timer = object.timer
			object[tempObjectPos].timer--
			object[tempObjectPos].direction = object.direction
		end if
	end if

	if object.frame == 6
		object.type = TypeName[Blank Object]
	else
		GetTableValue(temp0, object.frame, GroundFlame_hitboxes)
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -8, temp0, 8, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			if checkResult == true
				CallFunction(Player_FireHit)
			end if
		next
	end if

	if object.outOfBounds == true
		object.type = TypeName[Blank Object]
	end if
end event


event ObjectDraw
	DrawSprite(object.frame)
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone05")
	if checkResult == true
		LoadSpriteSheet("HTZ/Objects.gif")
		SpriteFrame(-8, -15, 16, 31, 1, 1)
		SpriteFrame(-8, -15, 16, 31, 18, 1)
		SpriteFrame(-8, -8, 16, 24, 35, 1)
		SpriteFrame(-8, -8, 16, 24, 35, 26)
		SpriteFrame(-8, 0, 16, 16, 1, 33)
		SpriteFrame(-8, 0, 16, 16, 18, 33)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		
		// These sprites have different offsets than their HTZ versions
		SpriteFrame(-8, -19, 16, 31, 869, 68)
		SpriteFrame(-8, -19, 16, 31, 886, 68)
		SpriteFrame(-8, -12, 16, 24, 973, 21)
		SpriteFrame(-8, -12, 16, 24, 990, 21)
		SpriteFrame(-8, -4, 16, 16, 835, 71)
		SpriteFrame(-8, -4, 16, 16, 852, 71)
	end if
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	CheckCurrentStageFolder("Zone05")
	if checkResult == true
		LoadSpriteSheet("HTZ/Objects.gif")
		SpriteFrame(-8, -15, 16, 31, 1, 1)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-8, -19, 16, 31, 869, 68)
	end if
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
