ObjectData = 
{
	MotionModel = 
	{
		DefaultAnimation = [[normal]],
		Motions = 
		{
			motion2 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\ginseng light\ginseng_light_toolbar.anim]],
						Name = [[ginseng_light_toolbar]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[toolbar]],
			},
			motion1 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\ginseng light\ginseng_light_idle.anim]],
						Name = [[ginseng_light_idle]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[normal]],
			},
		},
	},
	Extensions = 
	{
		PositionExtension = 
		{
			foreground = false,
			background = true,
		},
		PhysicsExtension = 
		{
		},
		LevelEditorExtension = 
		{
			trash_icon_offset = {-41,26},
		},
	},
}

-- Begin Scripting --

help_text_header = "$00637"
help_text = "$00638"

function OnInit()	

	GINSENG_TOLERANCE_SQR = 40*40
	this:EnablePhysics( false )
	light = nil
	switchedOn = false
	
	GINSENG_HASH = World_HashString("ginseng")
	
	
end

function Update()

	Profile_Start("ginseng_light")

	--check if any ginsengs are flying nearby
	for object in World_GetObjects() do
		local hashName = object:GetBlueprintHash()
	
		if (hashName == GINSENG_HASH and object:IsVisible() ) then
			local pos = object:GetPosition()
			local difference = pos - this:GetPosition()
			
			if difference:LengthSqr() < GINSENG_TOLERANCE_SQR then
				if not light then
					light = World_CreateLight( this:GetPosition(), Colour( 200,255,255 ), 150, 100 )
					World_SetLightAttenuation( light, 150, 120, 0.0 )
					back_effect = World_CreateEffect("ginseng light/blue_back_halo", this:GetPosition() )
					front_effect = World_CreateEffect("ginseng light/blue_front_halo", this:GetPosition() )
					World_IncrementStat("ginseng_shots")
				else
					World_RemoveLight(light)
					back_effect:Stop(false)
					front_effect:Stop(false)
					light = nil
				end

				World_CreateEffect("ginseng/ginseng_explode", this:GetPosition() )

				-- Kill the object if it is a Ginseng.
				if hashName == GINSENG_HASH then
					object:KillMe()
				end
			end
		end
	end
	
	Profile_Stop("ginseng_light")
end

function OnDestroy()

	if light then
		World_RemoveLight(light)
	end
	
end

