
//ENT.Base = "base_entity"
ENT.Type = "anim"

ENT.PrintName		= "grenade"
ENT.Author			= "LeErOy NeWmAn"
ENT.Contact			= ""
ENT.Purpose			= nil
ENT.Instructions	= nil


/*---------------------------------------------------------
   Name: OnRemove
   Desc: Called just before entity is deleted
---------------------------------------------------------*/
function ENT:OnRemove()
end

function ENT:PhysicsUpdate()
end

function ENT:PhysicsCollide(data,phys)

	local Ent = data.HitEntity

	if data.Speed > 100 then
		self.Entity:EmitSound(Sound("physics/metal/metal_grenade_impact_hard"..math.random(1,3)..".wav"))
		if (Ent:IsPlayer() || Ent:IsNPC() || Ent:GetClass() == "prop_ragdoll") then 
			local dmginfo = DamageInfo()
			dmginfo:SetDamage( (data.Speed / 100) )
			dmginfo:SetDamagePosition( data.HitPos )
			if (Ent:Health() - (data.Speed / 100)) > 0 then
				dmginfo:SetDamageType( DMG_CRUSH )
			else
				dmginfo:SetDamageType( DMG_GENERIC  )
			end
			dmginfo:SetAttacker( self.GrenadeOwner )
			Ent:TakeDamageInfo( dmginfo )
			Ent:EmitSound("physics/flesh/flesh_impact_hard" .. math.random(1, 6) .. ".wav", 100, math.Rand(90, 120))
		end
	elseif data.Speed < 100 and data.Speed > 50 then
		self.Entity:EmitSound(Sound("physics/metal/metal_grenade_impact_soft"..math.random(1,3)..".wav"))
	end
	
	local impulse = -data.Speed * data.HitNormal * 0.005 + (data.OurOldVelocity * -.005)
	phys:ApplyForceCenter(impulse)
end
