#****************************************************************************
#**
#**  File     : /cdimage/lua/modules/Hawkeyeprojectiles.lua
#**  Author(s): Lt_Hawkeye
#**
#**  Summary  :
#**
#**  Copyright © 2005 Gas Powered Games, Inc.  All rights reserved.
#****************************************************************************
#------------------------------------------------------------------------
#  Lt_hawkeye's Custom Projectiles
#------------------------------------------------------------------------
local Projectile = import('/lua/sim/projectile.lua').Projectile
local DefaultProjectileFile = import('/lua/sim/defaultprojectiles.lua')
local EmitterProjectile = DefaultProjectileFile.EmitterProjectile
local OnWaterEntryEmitterProjectile = DefaultProjectileFile.OnWaterEntryEmitterProjectile
local SingleBeamProjectile = DefaultProjectileFile.SingleBeamProjectile
local SinglePolyTrailProjectile = DefaultProjectileFile.SinglePolyTrailProjectile
local MultiPolyTrailProjectile = DefaultProjectileFile.MultiPolyTrailProjectile
local SingleCompositeEmitterProjectile = DefaultProjectileFile.SingleCompositeEmitterProjectile
local MultiCompositeEmitterProjectile = DefaultProjectileFile.MultiCompositeEmitterProjectile
local Explosion = import('/lua/defaultexplosions.lua')
local EffectTemplate = import('/lua/EffectTemplates.lua')
local HawkeyeEffectTemplate = import('/mods/HawksmodFA/lua/HawkeyeEffectTemplates.lua')
local DepthCharge = import('/lua/defaultantiprojectile.lua').DepthCharge
local util = import('/lua/utilities.lua')


RailGun01Projectile = Class(MultiPolyTrailProjectile) {
    PolyTrails = {
		'/mods/HawksmodFA/effects/emitters/railgun_polytrail_04_emit.bp',
		'/mods/HawksmodFA/effects/emitters/railgun_polytrail_05_emit.bp',
		'/effects/emitters/default_polytrail_03_emit.bp',
	},
	PolyTrailOffset = {0,0,0},  
	FxTrails = EffectTemplate.CDisintegratorFxTrails01,  
	
    # Hit Effects
    FxImpactUnit = EffectTemplate.CDisintegratorHitUnit01,
    FxImpactAirUnit = EffectTemplate.CDisintegratorHitAirUnit01,
    FxImpactProp = EffectTemplate.CDisintegratorHitUnit01,
    FxImpactLand = EffectTemplate.CDisintegratorHitLand01,
    FxImpactUnderWater = {},
   
}

MiniRocketProjectile = Class(SingleBeamProjectile) {
    DestroyOnImpact = false,
    FxTrails = EffectTemplate.TMissileExhaust02,
    FxTrailOffset = -1,
    BeamName = '/effects/emitters/missile_munition_exhaust_beam_01_emit.bp',

    FxImpactUnit = EffectTemplate.TMissileHit01,
    FxImpactLand = EffectTemplate.TMissileHit01,
    FxImpactProp = EffectTemplate.TMissileHit01,
    FxImpactUnderWater = {},

    OnImpact = function(self, targetType, targetEntity)
        local army = self:GetArmy()
        SingleBeamProjectile.OnImpact(self, targetType, targetEntity)
    end,

    CreateImpactEffects = function( self, army, EffectTable, EffectScale )
        local emit = nil
        for k, v in EffectTable do
            emit = CreateEmitterAtEntity(self,army,v)
            if emit and EffectScale != 1 then
                emit:ScaleEmitter(EffectScale or 1)
            end
        end
    end,
}

MiniRocket02Projectile = Class(SingleBeamProjectile) {
    DestroyOnImpact = false,
    FxTrails = EffectTemplate.TMissileExhaust02,
    FxTrailOffset = -1,
    BeamName = '/effects/emitters/missile_munition_exhaust_beam_01_emit.bp',

    # Hit Effects
    FxImpactUnit = EffectTemplate.CMissileLOAHit01,
    FxImpactLand = EffectTemplate.CMissileLOAHit01,
    FxImpactProp = EffectTemplate.CMissileLOAHit01,
    FxImpactNone = EffectTemplate.CMissileLOAHit01,
    FxImpactUnderWater = {},
    
    CreateImpactEffects = function( self, army, EffectTable, EffectScale )
        local emit = nil
        for k, v in EffectTable do
            emit = CreateEmitterAtEntity(self,army,v)
            if emit and EffectScale != 1 then
                emit:ScaleEmitter(EffectScale or 1)
            end
        end
    end,
    
    OnExitWater = function(self)
		EmitterProjectile.OnExitWater(self)
		local army = self:GetArmy()
		for k, v in self.FxExitWaterEmitter do
			CreateEmitterAtBone(self,-2,army,v)
		end
    end,
}

#***********************************************
#                 SeaDragon Projectiles
#***********************************************

SeaDragonShell = Class(SinglePolyTrailProjectile) {

    PolyTrail = '/effects/emitters/default_polytrail_01_emit.bp',

    # Hit Effects
    FxImpactUnit = EffectTemplate.CMolecularResonanceHitUnit01,
    FxUnitHitScale = 2,
    FxImpactProp = EffectTemplate.CMolecularResonanceHitUnit01,
    FxPropHitScale = 2,    
    FxImpactLand = EffectTemplate.CMolecularResonanceHitUnit01,
    FxLandHitScale = 2,
    FxImpactUnderWater = {},
    DestroyOnImpact = false,

    OnCreate = function(self)
        SinglePolyTrailProjectile.OnCreate(self)
        self.Impacted = false
    end,

    DelayedDestroyThread = function(self)
        WaitSeconds( 0.3 )
        self.CreateImpactEffects( self, self:GetArmy(), self.FxImpactUnit, self.FxUnitHitScale )
        self:Destroy()
    end,

    OnImpact = function(self, TargetType, TargetEntity)
        if self.Impacted == false then
            self.Impacted = true
            if TargetType == 'Terrain' then
                SinglePolyTrailProjectile.OnImpact(self, TargetType, TargetEntity)
                self:ForkThread( self.DelayedDestroyThread )
            else
                SinglePolyTrailProjectile.OnImpact(self, TargetType, TargetEntity)
                self:Destroy()
            end
        end
    end,
}
XCannonProjectile = Class(MultiPolyTrailProjectile) {
    PolyTrails = {
        HawkeyeEffectTemplate.XCannonPolyTrail,
        '/effects/emitters/default_polytrail_01_emit.bp',
    },
    PolyTrailOffset = {0,0}, 

    FxTrails = HawkeyeEffectTemplate.XCannonFXTrail01,
    #PolyTrail = EffectTemplate.CHvyProtonCannonPolyTrail,
    FxImpactUnit = HawkeyeEffectTemplate.XCannonHitUnit,
    FxImpactProp = HawkeyeEffectTemplate.XCannonHitUnit,
    FxImpactLand = EffectTemplate.CHvyProtonCannonHitLand,
    FxImpactUnderWater = EffectTemplate.CHvyProtonCannonHit01,
    FxImpactWater = EffectTemplate.CHvyProtonCannonHit01,
    FxTrailOffset = 0,
}
#------------------------------------------------------------
#				Bismark Projectiles
#-----------------------------------------------------------
ZCannon01Projectile = Class(MultiPolyTrailProjectile) {
	FxImpactTrajectoryAligned = false,
    PolyTrails = HawkeyeEffectTemplate.ZCannonPolytrail01,
    PolyTrailOffset = {0,0,0},
    FxTrails = HawkeyeEffectTemplate.ZCannonFxtrail01,

    # Hit Effects
    FxImpactUnit = HawkeyeEffectTemplate.ZCannonHit01,
    FxImpactProp = HawkeyeEffectTemplate.ZCannonHit01,
    FxImpactLand = HawkeyeEffectTemplate.ZCannonHit01,
    FxLandHitScale = 1.5,
    FxPropHitScale = 1.5,
    FxUnitHitScale = 1.5,
    FxImpactUnderWater = {},
    FxSplatScale = 9,

    OnImpact = function(self, targetType, targetEntity)
        local army = self:GetArmy()
        if targetType == 'Terrain' then
            CreateDecal( self:GetPosition(), util.GetRandomFloat(0,2*math.pi), 'nuke_scorch_001_normals', '', 'Alpha Normals', self.FxSplatScale, self.FxSplatScale, 150, 50, army )
            CreateDecal( self:GetPosition(), util.GetRandomFloat(0,2*math.pi), 'nuke_scorch_002_albedo', '', 'Albedo', self.FxSplatScale * 2, self.FxSplatScale * 2, 150, 50, army )
            self:ShakeCamera(20, 1, 0, 1)
        end
        local pos = self:GetPosition()
        DamageArea(self, pos, self.DamageData.DamageRadius, 1, 'Force', true)
        DamageArea(self, pos, self.DamageData.DamageRadius, 1, 'Force', true)
        EmitterProjectile.OnImpact(self, targetType, targetEntity)
    end,
}

#------------------------------------------------------------------------
#  Cybran Dumb MISSILE PROJECTILES
#------------------------------------------------------------------------
DumbRocketProjectile = Class(SingleCompositeEmitterProjectile) {
    FxTrails = {'/effects/emitters/missile_cruise_munition_trail_01_emit.bp',},
    FxTrailScale = 0.25,
#	PolyTrail = EffectTemplate.CCorsairMissilePolyTrail01,    
    BeamName = '/effects/emitters/missile_exhaust_fire_beam_01_emit.bp',
    FxImpactUnit = EffectTemplate.CCorsairMissileUnitHit01,
    FxImpactProp = EffectTemplate.CCorsairMissileHit01,
    FxImpactLand = EffectTemplate.CCorsairMissileLandHit01,
    FxImpactUnderWater = {},
}

DumbRocketProjectile02 = Class(MultiPolyTrailProjectile) {
    FxTrails = {},
#    FxTrailScale = 0.25,
	PolyTrail = EffectTemplate.TGaussCannonPolyTrail,    
#    BeamName = '/effects/emitters/missile_exhaust_fire_beam_01_emit.bp',
    FxImpactUnit = EffectTemplate.CCorsairMissileUnitHit01,
    FxImpactProp = EffectTemplate.CCorsairMissileHit01,
    FxImpactLand = EffectTemplate.CCorsairMissileLandHit01,
    FxImpactUnderWater = {},
}
#------------------------------------------------------------------------
#
#  Scorp Laser
#
#------------------------------------------------------------------------

ScorpPulseLaser = Class(MultiPolyTrailProjectile) {
    PolyTrails = {
		'/mods/HawksmodFA/effects/emitters/scorp_disintegrator_polytrail_02_emit.bp',
		'/mods/HawksmodFA/effects/emitters/scorp_disintegrator_polytrail_03_emit.bp',
		'/effects/emitters/default_polytrail_03_emit.bp',
	},
	PolyTrailOffset = {0,0,0},    

    # Hit Effects
    FxImpactUnit = EffectTemplate.CHvyDisintegratorHitUnit01,
    FxImpactProp = EffectTemplate.CHvyDisintegratorHitUnit01,
    FxImpactLand = EffectTemplate.CHvyDisintegratorHitLand01,
    FxLandHitScale = 0.5,
    FxPropHitScale = 0.5,
    FxUnitHitScale = 0.5,
    FxImpactUnderWater = {},
    FxTrails = {},
    FxTrailOffset = 0,
}
#--------------------------------------------------------
#				Acolyte Missile
#-------------------------------------------------------
AcolyteMissileprojectile = Class(SinglePolyTrailProjectile) {
    PolyTrail = '/effects/emitters/serpentine_missile_trail_emit.bp',
    FxTrails = {'/effects/emitters/saint_munition_01_emit.bp'},
    FxTrailScale = 0.5,

    FxImpactUnit = EffectTemplate.AMissileHit01,
    FxUnitHitScale = 3,
    FxImpactProp = EffectTemplate.AMissileHit01,
    FXPropHitScale = 3,
    FxImpactNone = EffectTemplate.AMissileHit01,
    FxNoneHitScale = 3,
    FxImpactLand = EffectTemplate.AMissileHit01,
    FXLandHitScale = 3,
    FxImpactProjectile = EffectTemplate.ASaintImpact01,
    FxImpactUnderWater = {},

}
#------------------------------------------------------------
#				Bismark Projectiles
#-----------------------------------------------------------
SonicWaveProjectile = Class(MultiPolyTrailProjectile) {
	FxImpactTrajectoryAligned = false,
    PolyTrails = HawkeyeEffectTemplate.WaveCannonPolytrail01,
    PolyTrailOffset = {0,0,0},
    FxTrails = HawkeyeEffectTemplate.WaveCannonFxtrail01,

    # Hit Effects
    FxImpactUnit = EffectTemplate.AGravitonBolterHit01,
    FxImpactProp = EffectTemplate.AGravitonBolterHit01,
    FxImpactLand = EffectTemplate.AGravitonBolterHit01,
    FxLandHitScale = 1.5,
    FxPropHitScale = 1.5,
    FxUnitHitScale = 1.5,
    FxImpactUnderWater = {},

}
#------------------------------------------------------------
#				Seraphim Lambda Projectiles
#-----------------------------------------------------------
EyeBlast01Projectile = Class(EmitterProjectile) {
	FxImpactTrajectoryAligned = false,
    FxTrails = EffectTemplate.SDFExperimentalPhasonProjFXTrails01,
    FxImpactUnit = HawkeyeEffectTemplate.SDFExperimentalPhasonProjHitUnit,
    FxImpactProp = HawkeyeEffectTemplate.SDFExperimentalPhasonProjHit01,
    FxImpactLand = HawkeyeEffectTemplate.SDFExperimentalPhasonProjHit01,
    FxImpactWater = HawkeyeEffectTemplate.SDFExperimentalPhasonProjHit01,
}

#------------------------------------------------------------------------
#  CYBRAN SUB LAUNCHED TORPEDO
#------------------------------------------------------------------------
AssaultTorpedoSubProjectile = Class(EmitterProjectile) {
    FxTrails = {'/effects/emitters/torpedo_underwater_wake_02_emit.bp',},

    # Hit Effects
    FxImpactUnit = EffectTemplate.CTorpedoUnitHit01,
    FxImpactProp = EffectTemplate.CTorpedoUnitHit01,
    FxImpactUnderWater = EffectTemplate.CTorpedoUnitHit01,    
    FxImpactLand = EffectTemplate.CTorpedoUnitHit01,
    FxLandHitScale = 4,
    FxPropHitScale = 4,
    FxUnitHitScale = 4,
    FxNoneHitScale = 4,
    FxImpactNone = {},
}

ShadowCannonProjectile = Class(MultiPolyTrailProjectile) {
    PolyTrails = {
		'/effects/emitters/electron_bolter_trail_01_emit.bp',
		'/mods/HawksmodFA/effects/emitters/shadowcannon_polytrail_01_emit.bp',
	},
    PolyTrailOffset = {0,0}, 

    FxTrails = HawkeyeEffectTemplate.ShadowCannonFXTrail01,
    #PolyTrail = EffectTemplate.CHvyProtonCannonPolyTrail,
    FxImpactUnit = EffectTemplate.CHvyProtonCannonHitUnit,
    FxImpactProp = EffectTemplate.CHvyProtonCannonHitUnit,
    FxImpactLand = EffectTemplate.CHvyProtonCannonHitLand,
    FxImpactUnderWater = EffectTemplate.CHvyProtonCannonHit01,
    FxImpactWater = EffectTemplate.CHvyProtonCannonHit01,
    FxLandHitScale = 0.5,
    FxPropHitScale = 0.5,
    FxUnitHitScale = 0.5,
    FxNoneHitScale = 0.5,
    FxTrailOffset = 0,
}

HellFireMissileProjectile = Class(SingleCompositeEmitterProjectile) {
    FxTrails = {'/effects/emitters/missile_cruise_munition_trail_01_emit.bp',},
    FxTrailScale = 0.25,
#	PolyTrail = EffectTemplate.CCorsairMissilePolyTrail01,    
    BeamName = '/effects/emitters/missile_exhaust_fire_beam_01_emit.bp',
    FxImpactUnit = EffectTemplate.TNapalmHvyCarpetBombHitLand01,
    FxImpactProp = EffectTemplate.TNapalmHvyCarpetBombHitLand01,
    FxImpactLand = EffectTemplate.TNapalmHvyCarpetBombHitLand01,
    FxImpactWater = EffectTemplate.TNapalmHvyCarpetBombHitWater01,
    FxImpactUnderWater = {},
}

ACUShadowCannonProjectile = Class(MultiPolyTrailProjectile) {
    PolyTrails = {
		'/effects/emitters/electron_bolter_trail_01_emit.bp',
		'/mods/HawksmodFA/effects/emitters/shadowcannon_polytrail_01_emit.bp',
	},
    PolyTrailOffset = {0,0}, 

    FxTrails = HawkeyeEffectTemplate.ShadowCannonFXTrail01,
    #PolyTrail = EffectTemplate.CHvyProtonCannonPolyTrail,
    FxImpactUnit = HawkeyeEffectTemplate.ACUShadowCannonHit01,
    FxImpactProp = HawkeyeEffectTemplate.ACUShadowCannonHit01,
    FxImpactLand = HawkeyeEffectTemplate.ACUShadowCannonHit01,
    FxImpactUnderWater = HawkeyeEffectTemplate.ACUShadowCannonHit01,
    FxImpactWater = HawkeyeEffectTemplate.ACUShadowCannonHit01,
    FxLandHitScale = 0.7,
    FxPropHitScale = 0.7,
    FxUnitHitScale = 0.7,
    FxNoneHitScale = 0.7,
    FxTrailOffset = 0,
}

#------------------------------------------------------------------------
#  TERRAN Heavy GAUSS CANNON PROJECTILES
#------------------------------------------------------------------------
HawkGaussCannonProjectile = Class(MultiPolyTrailProjectile) {
    FxTrails = {},
    PolyTrails = EffectTemplate.TGaussCannonPolyTrail,
    PolyTrailOffset = {0,0},
    FxImpactUnit = EffectTemplate.TMissileHit01,
    FxImpactProp = EffectTemplate.TMissileHit01,
    FxImpactLand = EffectTemplate.TMissileHit01,
    FxTrailOffset = 0,
    FxImpactUnderWater = {},
}

#------------------------------------------------------------------------
#  AEON ARTILLERY PROJECTILES
#------------------------------------------------------------------------
WraithProjectile = Class(SinglePolyTrailProjectile) {
	FxImpactLand = HawkeyeEffectTemplate.WraithCannonHit01,
    FxImpactNone = HawkeyeEffectTemplate.WraithCannonHit01,
	FxImpactProp = HawkeyeEffectTemplate.WraithCannonHit01,    
    FxImpactUnit = HawkeyeEffectTemplate.WraithCannonHit01,    
    FxImpactUnderWater = {},
    FxImpactProjectile = {},
    FxLandHitScale = 0.7,
    FxPropHitScale = 0.7,
    FxUnitHitScale = 0.7,
    FxNoneHitScale = 0.7,
    PolyTrail = HawkeyeEffectTemplate.WraithPolytrail01,
    FxTrails = HawkeyeEffectTemplate.WraithMunition01,
}