#****************************************************************************
#**
#**  Author(s): Exavier Macbeth
#**
#**  Summary  :  This is a blank slate file for creating defaultcollisionbeams.lua files
#**
#**  Copyright © 2005 Gas Powered Games, Inc.  All rights reserved.
#****************************************************************************

local CollisionBeam = import('/lua/sim/CollisionBeam.lua').CollisionBeam
local EffectTemplate = import('/lua/EffectTemplates.lua')
local Util = import('/lua/utilities.lua')

#-----------------------------
#   Base class that defines supreme commander specific defaults
#-----------------------------
SCCollisionBeam = Class(CollisionBeam) {
    FxImpactUnit = EffectTemplate.DefaultProjectileLandUnitImpact,
    FxImpactLand = {},#EffectTemplate.DefaultProjectileLandImpact,
    FxImpactWater = EffectTemplate.DefaultProjectileWaterImpact,
    FxImpactUnderWater = EffectTemplate.DefaultProjectileUnderWaterImpact,
    FxImpactAirUnit = EffectTemplate.DefaultProjectileAirUnitImpact,
    FxImpactProp = {},
    FxImpactShield = {},    
    FxImpactNone = {},
}

#-----------------------------
#   Start Your Code Here
#-----------------------------
BLaserCollisionBeam = Class(SCCollisionBeam) {

    TerrainImpactType = 'LargeBeam01',
    TerrainImpactScale = 2,
    FxBeamStartPoint = EffectTemplate.CMicrowaveLaserMuzzle01,
	FxBeamStartPointScale = 4,
    FxBeam = {'/mods/IMBA_Mod_V4/effects/emitters/blaser_beam_01_emit.bp'},
    FxBeamEndPoint = EffectTemplate.CMicrowaveLaserEndPoint01,
	FxBeamEndPointScale =  2,
    SplatTexture = 'czar_mark01_albedo',
    ScorchSplatDropTime = 0.25,

    OnImpact = function(self, impactType, targetEntity)
        if impactType == 'Terrain' then
            if self.Scorching == nil then
                self.Scorching = self:ForkThread( self.ScorchThread )   
            end
        elseif not impactType == 'Unit' then
            KillThread(self.Scorching)
            self.Scorching = nil
        end
        CollisionBeam.OnImpact(self, impactType, targetEntity)
    end,

    OnDisable = function( self )
        CollisionBeam.OnDisable(self)
        KillThread(self.Scorching)
        self.Scorching = nil   
    end,

    ScorchThread = function(self)
        local army = self:GetArmy()
        local size = 2 + (Random() * 1.5) 
        local CurrentPosition = self:GetPosition(1)
        local LastPosition = Vector(0,0,0)
        local skipCount = 1
        while true do
            if Util.GetDistanceBetweenTwoVectors( CurrentPosition, LastPosition ) > 0.25 or skipCount > 100 then
                CreateSplat( CurrentPosition, Util.GetRandomFloat(0,2*math.pi), self.SplatTexture, size, size, 100, 100, army )
                LastPosition = CurrentPosition
                skipCount = 1
            else
                skipCount = skipCount + self.ScorchSplatDropTime
            end
                
            WaitSeconds( self.ScorchSplatDropTime )
            size = 2 + (Random() * 1.5)
            CurrentPosition = self:GetPosition(1)
        end
    end,
}

QuantumBeamGeneratorCollisionBeam = Class(SCCollisionBeam) {
    TerrainImpactType = 'LargeBeam02',
    TerrainImpactScale = 1,
        
    FxBeam = {'/mods/IMBA_Mod_V4/effects/emitters/quantum_generator_beam_01_emit.bp'},
    FxBeamEndPoint = {
		'/mods/IMBA_Mod_V4/effects/emitters/quantum_generator_end_01_emit.bp',
        '/mods/IMBA_Mod_V4/effects/emitters/quantum_generator_end_03_emit.bp',
        '/mods/IMBA_Mod_V4/effects/emitters/quantum_generator_end_04_emit.bp',
        '/mods/IMBA_Mod_V4/effects/emitters/quantum_generator_end_05_emit.bp',
        '/mods/IMBA_Mod_V4/effects/emitters/quantum_generator_end_06_emit.bp',
	},
		FxBeamEndPointScale =  0.5,
    FxBeamStartPoint = {
		'/mods/IMBA_Mod_V4/effects/emitters/quantum_generator_01_emit.bp',
        '/mods/IMBA_Mod_V4/effects/emitters/quantum_generator_02_emit.bp',
   
		--'/effects/emitters/microwave_laser_end_01_emit.bp',
		--'/effects/emitters/microwave_laser_end_02_emit.bp',
		--'/effects/emitters/microwave_laser_end_03_emit.bp',
		--'/effects/emitters/microwave_laser_end_04_emit.bp',
		--'/effects/emitters/microwave_laser_end_05_emit.bp',
		--'/effects/emitters/microwave_laser_end_06_emit.bp',
    },
	 
	FxBeamStartPointScale = 1,
    
    SplatTexture = 'czar_mark01_albedo',
    ScorchSplatDropTime = 0.5,

    OnImpact = function(self, impactType, targetEntity)
        if impactType == 'Terrain' then
            if self.Scorching == nil then
                self.Scorching = self:ForkThread( self.ScorchThread )   
            end
        elseif not impactType == 'Unit' then
            KillThread(self.Scorching)
            self.Scorching = nil
        end
        CollisionBeam.OnImpact(self, impactType, targetEntity)
    end,

    OnDisable = function( self )
        CollisionBeam.OnDisable(self)
        KillThread(self.Scorching)
        self.Scorching = nil   
    end,

    ScorchThread = function(self)
        local army = self:GetArmy()
        local size = 3.5 + (Random() * 3.5) 
        local CurrentPosition = self:GetPosition(1)
        local LastPosition = Vector(0,0,0)
        local skipCount = 1
        while true do
            if Util.GetDistanceBetweenTwoVectors( CurrentPosition, LastPosition ) > 0.25 or skipCount > 100 then
                CreateSplat( CurrentPosition, Util.GetRandomFloat(0,2*math.pi), self.SplatTexture, size, size, 250, 250, army )
                LastPosition = CurrentPosition
                skipCount = 1
            else
                skipCount = skipCount + self.ScorchSplatDropTime
            end
                
            WaitSeconds( self.ScorchSplatDropTime )
            size = 3.2 + (Random() * 3.5)
            CurrentPosition = self:GetPosition(1)
        end
    end,    
}