ObjectData = 
{
	MotionModel = 
	{
		DefaultAnimation = [[Happy]],
		Motions = 
		{
			motion4 = 
			{
				Animations = 
				{
					anim4 = 
					{
						Path = [[DATA:Animations\Eets\eets_emote_angry_5.anim]],
						Name = [[eets_emote_angry_5]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
					anim1 = 
					{
						Path = [[DATA:Animations\Eets\eets_emote_angry_2.anim]],
						Name = [[eets_emote_angry_2]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
					anim3 = 
					{
						Path = [[DATA:Animations\Eets\eets_emote_angry_4.anim]],
						Name = [[eets_emote_angry_4]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
					anim2 = 
					{
						Path = [[DATA:Animations\Eets\eets_emote_angry_3.anim]],
						Name = [[eets_emote_angry_3]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[Angry]],
			},
			motion1 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\Eets\eets_emote_happy.anim]],
						Name = [[eets_emote_happy]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[Happy]],
			},
			motion5 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\Eets\eets_emote_angry_first.anim]],
						Name = [[eets_emote_angry_first]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[AngryTransition]],
			},
			motion3 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\Eets\eets_emote_scared_first.anim]],
						Name = [[eets_emote_scared_first]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[ScaredTransition]],
			},
			motion2 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\Eets\eets_emote_scared_2.anim]],
						Name = [[eets_emote_scared_2]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
					anim2 = 
					{
						Path = [[DATA:Animations\Eets\eets_emote_scared_3.anim]],
						Name = [[eets_emote_scared_3]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[Scared]],
			},
		},
	},
	Extensions = 
	{
	},
}-- Begin Scripting --

--[[help_text_header = [[Eets Head]]
help_text = 
[[\nJust bobbing around,
this will show you if
Eets is feeling happy,
angry, or scared.]]]]

distortion_table = 
{		
	eets_emote_angry_2 =
	{
		{ 7, 7, 20, 40 },
		{ 15, 15, 20, 40 },
	},
	eets_emote_angry_3 =
	{
		{ 7, 7, 20, 40 },
		{ 15, 15, 20, 40 },
	},
	eets_emote_angry_4 =
	{
		{ 28, 28, 20, 40 },
	},
	eets_emote_angry_5 =
	{
		{ 57, 57, 20, 40 },
	},
	eets_emote_scared_2 =
	{
		{ 10, 10, 20, 40 },
		{ 16, 16, 20, 40 },
		{ 37, 37, 20, 40 },
		{ 60, 60, 20, 40 },
		{ 157, 157, 20, 40 },
	},
	eets_emote_scared_3 =
	{
		{ 78, 78, 20, 40 },
	}
}

prev_name = ""

function Update()

	Profile_Start("emotimeter_eets")
	
	-- Stop anim when paused
	if World_IsPaused() then
		  local this_anim = this:GetMotionModel():GetCurrentMotion():GetCurrentAnim()
		  if( (frame_index == nil) or (not World_AnimationsEqual(last_anim, this_anim)) ) then -- if frame_index is nil or if last_anim is not this_anim
				frame_index = this_anim:GetCurrentFrameIndex()
				last_anim = this_anim
		  else
				this_anim:SetCurrentFrameIndex( frame_index )
		  end
	else
		frame_index = nil
		last_anim = nil
	end
  
    local anim_name = this:GetMotionModel():GetCurrentMotion():GetCurrentAnimName()
	if( prev_name ~= anim_name ) then
		prev_name = anim_name
		local anim = this:GetMotionModel():GetCurrentMotion():GetCurrentAnim()
		AddDistortions( anim, anim_name)
	end
	
	Profile_Stop("emotimeter_eets")
	
end

function AddDistortions( anim, anim_name )

	local local_table = distortion_table[ anim_name ]
	if local_table == nil then
		return nil
	end

	anim:ClearDistortions()
	--search in subtree
	for i in local_table do
		anim:AddDistortion(local_table[i][1], local_table[i][2], math.random(local_table[i][3], local_table[i][4]))
	end

	--not found
	return nil
	
end




