ObjectData = 
{
	MotionModel = 
	{
		DefaultAnimation = [[normal]],
		Motions = 
		{
			motion2 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\ginseng\ginseng.anim]],
						Name = [[ginseng_toolbar]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[toolbar]],
			},
			motion1 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\ginseng\ginseng.anim]],
						Name = [[ginseng]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[normal]],
			},
		},
	},
	Extensions = 
	{
		PhysicsExtension = 
		{
		},
		PositionExtension = 
		{
		},
		FlyingExtension = 
		{
			speed = 10.000000,
			flip_when_collide = false,
		},
		EdibleExtension = 
		{
			Eaters =
			{
				"whale",
			},
		},
	},
}

-- Begin Scripting --

help_text_header = [[Ginseng]]
help_text = [[A luminous little fellow.]]

function OnInit()	

	this:EnablePhysics( false )	

	light = World_CreateLight( this:GetPosition(), Colour( 255,200,100 ), 45, 20 )
	front_halo = this:CreateEffect( "Ginseng/ginseng_front_halo" )
	back_halo = this:CreateEffect( "Ginseng/ginseng_back_halo" )
	
	REFLECTOR_HASH = World_HashString("reflector")
	MARSHOMECH_HASH = World_HashString("marshomech")
	EXPLODING_MARSHMALLOW_HASH = World_HashString("giant_marshmallow_exploding")
	EETS_HAPPY_HASH = World_HashString("eets_happy")
	EETS_SCARED_HASH = World_HashString("eets_scared")
	
end

function UpdateEffects()
	if not front_halo or not front_halo:IsValid() then

		--assert( not back_halo or not back_halo:IsValid() )
		
		current_position = this:GetPosition()

		front_halo = this:CreateEffect( "ginseng/ginseng_front_halo" )
		back_halo = this:CreateEffect( "ginseng/ginseng_back_halo" )
		
		return
	end
end

function Update()

	Profile_Start("ginseng")

	UpdateEffects()

	if not light then
		Profile_Stop("ginseng")
		return
	end
	
	World_MoveLight( light, this:GetPosition() )
	
	--detect collisions
	for report in this:GetCollisionReports() do
		local obj = World_GetObjectByID( report.id_2 )
		if obj ~= nil then
			local objectHash = obj:GetBlueprintHash()

			if objectHash ~= REFLECTOR_HASH then
				World_CreateEffect("ginseng/ginseng_explode", this:GetPosition() )

				-- Makes Eets angrier.
				if (objectHash == EETS_HAPPY_HASH) or (objectHash == EETS_SCARED_HASH) then
					World_ChangeEmotion( 2, 300 )
				elseif (objectHash == EXPLODING_MARSHMALLOW_HASH) then
					obj:CallFunction("BlowMeUp")
				end
				
				if objectHash ~= MARSHOMECH_HASH then
					local we = obj:GetWalkingExtension()
					if we and we:GetState() ~= WalkingExtension.WES_Falling and objectHash ~= MARSHOMECH_HASH then
						we:Reset()
					end
					
					local norm = obj:GetPosition() - this:GetPosition()
					if norm:LengthSqr() == 0 then
						norm = Vector2( 0, -1 )
					else
						norm:Normalize()
					end
					
					obj:ForcePosition( obj:GetPosition() )
					obj:ApplyImpulse(Vector2(0, World_GetGravity().y * -1000))
					obj:ApplyImpulse( norm * 5000 )
	
				end
				
				this:KillMe()
				Profile_Stop("ginseng")
				return
				
			end
		end
	end
	
	Profile_Stop("ginseng")

end

function OnDestroy()

	if light then
		World_RemoveLight(light)
		light = nil
	end
	
end
