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

//-------Aliases-------//
private alias 69 : TYPE_EGGMANHAMMER

// Function declarations
reserve function EggmanHammer_Function152

// Static Values

// Tables
public table EggmanHammer_table44
	-0x280000, -0x80000, 0x180000, 0x380000
end table


function EggmanHammer_Function152
	object.ypos = object.value1
	Sin256(temp0, object.value2)
	temp0 <<= 10
	object.ypos += temp0
	object.value2 += 2
	object.value2 &= 255
	object[-1].xpos = object.xpos
	object[-1].ypos = object.ypos
	object[-1].direction = object.direction
end function


event ObjectMain
	switch object.state
	case 0
		object.value1 += 0x10000
		object.value3--
		if object.value3 == 0
			object.state++
		end if
		CallFunction(EggmanHammer_Function152)
		break
	case 1
		object.animationTimer = 0
		if object.direction == FLIP_NONE
			if object.xpos > object.value4
				object.xpos -= object.value7
			else
				object.state++
			end if
		else
			if object.xpos < object.value5
				object.xpos += object.value7
			else
				object.state = 2
			end if
		end if
		CallFunction(EggmanHammer_Function152)
		break
	case 2
		CallFunction(EggmanHammer_Function152)
		if object.value2 == 192
			object.state = 3
		end if
		break
	case 3
		object.animationTimer++
		switch object.animationTimer
		case 1
			object.frame = 4
			PlaySfx(SfxName[Crusher], 0)
			break
		case 7
			object.frame = 5
			arrayPos0 = object.entityPos
			if object.direction == FLIP_NONE
				arrayPos0 += 4
			else
				arrayPos0 += 5
			end if
			object[arrayPos0].state = 2
			object[arrayPos0].value3 = 32
			object[arrayPos0].value8 = -0x10000
			arrayPos1 = object[+1].entityPos
			arrayPos1 += object.value11
			object.value11++
			object.value11 %= 3
			object[arrayPos1].type = TypeName[Eggman Arrow]
			object[arrayPos1].xpos = object[arrayPos0].xpos
			Rand(temp0, 4)
			GetTableValue(object[arrayPos1].ypos, temp0, EggmanHammer_table44)
			object[arrayPos0].value9 = object[arrayPos1].ypos
			object[arrayPos1].ypos += object[arrayPos0].ypos
			if object.direction == FLIP_NONE
				object[arrayPos1].value0 = object[+5].xpos
				object[arrayPos1].value0 -= 0x280000
				object[arrayPos1].xpos += 0x100000
			else
				object[arrayPos1].value0 = object[+4].xpos
				object[arrayPos1].value0 += 0x280000
				object[arrayPos1].xpos -= 0x100000
			end if
			object[arrayPos1].direction = object.direction
			object[arrayPos1].drawOrder = 2
			object[arrayPos1].value1 = object[+1].entityPos
			object[arrayPos1].value1 += object.value11
			object[arrayPos1].yvel = 0
			object[arrayPos1].frame = 0
			object[arrayPos1].animation = 0
			object[arrayPos1].animationTimer = 0
			object[arrayPos1].xvel = object.value12
			object[arrayPos1].state = 0
			break
		case 13
			foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
				if object.direction == FLIP_NONE
					BoxCollisionTest(C_TOUCH, object.entityPos, -88, -24, -56, 24, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				else
					BoxCollisionTest(C_TOUCH, object.entityPos, 56, -24, 88, 24, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				end if
				if checkResult == 1
					CallFunction(PlayerObject_Hit)
				end if
			next
			break
		case 22
			object.frame = 4
			break
		case 29
			object.frame = 3
			break
		case 32
			object.direction ^= FLIP_X
			object.state = 1
			break
		end switch
		CallFunction(EggmanHammer_Function152)
		break
	case 4
		break
	case 5
		object.value13 += object.xvel
		object.value14 += object.yvel
		object.yvel += 0x3800
		break
	end switch
	object.value10++
	object.value10 &= 3
	object.value9 = object.value10
	object.value9 >>= 1
end event


event ObjectDraw
	DrawSpriteFX(2, FX_FLIP, object.xpos, object.ypos)
	if object.value8 != 1
		DrawSpriteFX(object.value9, FX_FLIP, object.xpos, object.ypos)
	end if
	if object.animation != 1
		temp0 = object.xpos
		if object.direction == FLIP_NONE
			temp0 -= 0x280000
		else
			temp0 += 0x280000
		end if
		temp0 += object.value13
		temp1 = object.ypos
		temp1 += 0x40000
		temp1 += object.value14
		DrawSpriteFX(object.frame, FX_ROTATE, temp0, temp1)
	end if
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone03")
	if checkResult == 1
		LoadSpriteSheet("ARZ/Objects.gif")
		SpriteFrame(-15, 24, 46, 16, 78, 183)
		SpriteFrame(-16, 24, 48, 8, 207, 162)
		SpriteFrame(-44, -28, 76, 52, 1, 147)
		SpriteFrame(-50, -49, 54, 53, 1, 202)
		SpriteFrame(-49, -43, 49, 55, 56, 200)
		SpriteFrame(-48, -24, 48, 48, 106, 207)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-15, 24, 46, 16, 299, 5)
		SpriteFrame(-16, 24, 48, 8, 299, 22)
		SpriteFrame(-44, -28, 76, 52, 222, 5)
		SpriteFrame(-50, -49, 54, 53, 255, 58)
		SpriteFrame(-49, -43, 49, 55, 310, 56)
		SpriteFrame(-48, -24, 48, 48, 348, 1)
	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
