ObjectData = 
{
	MotionModel = 
	{
		DefaultAnimation = [[normal]],
		Motions = 
		{
			motion3 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\Choco Pump\choco_pump_toolbar.anim]],
						Name = [[choco_pump_toolbar]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[toolbar]],
			},
			motion2 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\Choco Pump\choco_pump_idle.anim]],
						Name = [[choco_pump_standing_still]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[normal]],
			},
			motion1 = 
			{
				Animations = 
				{
					anim1 = 
					{
						Path = [[DATA:Animations\Choco Pump\choco_pump_firing.anim]],
						Name = [[choco_pump_firing]],
						MinFreq = 1.000000,
						MaxFreq = 1.000000,
					},
				},
				Name = [[fire]],
			},
		},
	},
	Extensions = 
	{
		FlippableExtension = 
		{
		},
		PhysicsExtension = 
		{
			mass = 100.000000,
		},
		LevelEditorExtension = 
		{
			flippable = true,
		},
		ClickableExtension = 
		{
			arrow_offset_x = 0,
			arrow_offset_y = -20,
		},
		PositionExtension = 
		{
		},
		CanBeAttachedExtension = 
		{
		},
	},
}

-- Begin Scripting --

help_text_header = "$00611"
help_text = "$00612"

function OnInit()

	this:EnablePhysics( false )

	CANNON_FORCE = -15000
	isReloaded = true
	
	CHOCOCHIPSTAT_HASH = "choco_shots"
end 

function Update()

	Profile_Start("choco_pump")

	local motion_model = this:GetMotionModel()
	
	if motion_model:GetCurrentMotionName() == "fire"
		and motion_model:GetCurrentMotion():GetCurrentAnim():GetCurrentFrameIndex() == 1 then
		
			this:CreateEffect( "sneezy sow/fire" )
			Sound_CreateSound("Firing Sound", false, 0, this:GetPosition() )

			World_Alert(this:GetPosition(), 400)
			--World_Scare(this:GetPosition(), 100, 100)

			local pos = this:GetPosition()
			local facing = this:GetFacing()
			local perpfacing = facing:PerpDot()
			if this:GetFlipped() then
				pos = pos + facing  * -50 + perpfacing * -10
			else
				pos = pos + facing  * -50 + perpfacing * 10
			end

			local obj = World_CreateObject( "chocolate_chip", pos )
			obj:ApplyImpulse( facing * CANNON_FORCE )
			
			World_IncrementStat(CHOCOCHIPSTAT_HASH)

			isReloaded = false
			recharge = 0
	end
	
	Profile_Stop("choco_pump")
	
end



function OnClick1()

	if( this:GetMotionModel():GetCurrentMotionName() ~= "fire" ) then
		this:SetMotion("fire")
		
		-- Sets the frame to the point before firing.
		this:GetMotionModel():GetCurrentMotion():GetCurrentAnim():SetCurrentFrameIndex(1)
	end
	
end
