local PLUGIN = PLUGIN

AddCSLuaFile()

ENT.Base              = "tacrp_proj_base"
ENT.PrintName         = "40mm HEAT"
ENT.Spawnable         = false

ENT.Model             = "models/weapons/tacint/grenade_40mm.mdl"

ENT.IsRocket          = false -- projectile has a booster and will not drop.

ENT.InstantFuse       = false -- projectile is armed immediately after firing.
ENT.RemoteFuse        = false -- allow this projectile to be triggered by remote detonator.
ENT.ImpactFuse        = true  -- projectile explodes on impact.

ENT.ExplodeOnDamage   = false -- projectile explodes when it takes damage.
ENT.ExplodeUnderwater = true

ENT.Delay             = 0

ENT.ExplodeSounds     = {
  "^TacRP/weapons/grenade/frag_explode-1.wav",
  "^TacRP/weapons/grenade/frag_explode-2.wav",
  "^TacRP/weapons/grenade/frag_explode-3.wav",
}

ENT.AudioLoop         = "TacRP/weapons/rpg7/rocket_flight-1.wav"

ENT.SmokeTrail        = true

function ENT:Detonate()
  if self:WaterLevel() > 0 then
    self:Remove()
    return
  end
  local attacker = self.Attacker or self:GetOwner() or self

  util.BlastDamage(self, attacker, self:GetPos(), 150, 25 * PLUGIN.ConVars["mult_damage_explosive"]:GetFloat())

  self:EmitSound(table.Random(self.ExplodeSounds), 75)

  local cloud = ents.Create("TacRP_fire_cloud")

  if not IsValid(cloud) then return end

  local ang = self:GetAngles()

  ang:RotateAroundAxis(ang:Right(), 90)

  cloud:SetPos(self:GetPos())
  cloud:SetAngles(ang)
  cloud:SetOwner(attacker)
  cloud:Spawn()

  cloud:SetMoveType(MOVETYPE_NONE)

  self:Remove()
end
