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

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

private alias object.value0 : object.timer
private alias object.value8 : object.exploding

// States
private alias 0  : WFZEGGMANDISPENSER_ENTER
private alias 1  : WFZEGGMANDISPENSER_DISPENSE
private alias 2  : WFZEGGMANDISPENSER_IDLE
private alias 14 : WFZEGGMANDISPENSER_DESTROYED


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

event ObjectUpdate
	switch object.state
	case WFZEGGMANDISPENSER_ENTER
		object.ypos += 0x4000

		object.timer++
		if object.timer >= 92
			object.timer = 0
			object.drawOrder = 4
			object.state = WFZEGGMANDISPENSER_DISPENSE
		end if
		break

	case WFZEGGMANDISPENSER_DISPENSE
		object.timer++
		switch object.timer
		case 10
			object[+2].type = TypeName[Eggman Platform]
			break

		case 138
			object[+3].type = TypeName[Eggman Platform]
			break

		case 266
			object[+4].type = TypeName[Eggman Platform]
			object.state = WFZEGGMANDISPENSER_IDLE
			break
			
		end switch
		break

	case WFZEGGMANDISPENSER_IDLE
		break

	case WFZEGGMANDISPENSER_DESTROYED
		object.timer++
		if object.timer >= 180
			object.timer = 0
			object.type = TypeName[Blank Object]
		end if
		break
		
	end switch

	if object.exploding == true
		temp0 = oscillation
		temp0 &= 7
		if temp0 == 0
			Rand(temp0, 96)
			temp0 -= 48
			temp0 <<= 16
			temp0 += object.xpos

			Rand(temp1, 48)
			temp1 -= 24
			temp1 <<= 16
			temp1 += object.ypos

			CreateTempObject(TypeName[Explosion], 0, temp0, temp1)
			object[tempObjectPos].drawOrder = 5
			PlaySfx(SfxName[Explosion], false)
		end if
	end if
end event


event ObjectDraw
	DrawSprite(object.frame)
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone11")
	if checkResult == true
		LoadSpriteSheet("SCZ/Objects.gif")
		SpriteFrame(-32, -8, 64, 16, 311, 82)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-32, -8, 64, 16, 513, 163)
	end if
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	CheckCurrentStageFolder("Zone11")
	if checkResult == true
		LoadSpriteSheet("SCZ/Objects.gif")
		SpriteFrame(-32, -8, 64, 16, 311, 82)
	else
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-32, -8, 64, 16, 513, 163)
	end if
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
