#****************************************************************************
#**
#**  File     :  /UAL0302/UAL0302.*
#**  Author(s):  Optimus Prime
#**
#**  Summary  :  Aeon Super Heavy Assault Tank
#**
#****************************************************************************

local ALandUnit = import('/lua/aeonunits.lua').ALandUnit
local ADFCannonQuantumWeapon = import('/lua/aeonweapons.lua').ADFCannonQuantumWeapon
local WeaponsFile = import('/lua/terranweapons.lua')
local TDFGaussCannonWeapon = WeaponsFile.TDFGaussCannonWeapon
local AIFMortarWeapon = import('/lua/aeonweapons.lua').AIFMortarWeapon
local EffectTemplate = import('/lua/EffectTemplates.lua')
local utilities = import('/lua/Utilities.lua')
local EffectUtil = import('/lua/EffectUtilities.lua')
local AIFMissileTacticalSerpentineWeapon = import('/lua/aeonweapons.lua').AIFMissileTacticalSerpentineWeapon

UAL0302 = Class(ALandUnit) {

    Weapons = {
        MainGun = Class(TDFGaussCannonWeapon) {},
        MissileRack1 = Class(AIFMissileTacticalSerpentineWeapon) {},
        MissileRack2 = Class(AIFMissileTacticalSerpentineWeapon) {},
        MissileRack3 = Class(AIFMissileTacticalSerpentineWeapon) {},
        MissileRack4 = Class(AIFMissileTacticalSerpentineWeapon) {},
        MissileRack5 = Class(AIFMissileTacticalSerpentineWeapon) {},
        MissileRack6 = Class(AIFMissileTacticalSerpentineWeapon) {},
    },
    
    
    OnStopBeingBuilt = function(self,builder,layer)
        ALandUnit.OnStopBeingBuilt(self,builder,layer)
        self:SetMaintenanceConsumptionActive()
        local layer = self:GetCurrentLayer()
        # If created with F2 on land, then play the transform anim.
        if(layer == 'Land') then
            self:CreateUnitAmbientEffect(layer)
        elseif (layer == 'Seabed') then
        end
        self.WeaponsEnabled = true
    end,
    
    
    
    AmbientExhaustBones = {
		'ExhastBig1',
		'ExhastBig2',
    },
    
    AmbientExhaustBones2 = {
		'Exhaust3',
		'Exhaust4',
    },
    	
    
    AmbientLandExhaustEffects = {
		'/effects/emitters/hydrocarbon_smoke_01_emit.bp',			
	},
	
	
	CreateUnitAmbientEffect = function(self, layer)
	    if( self.AmbientEffectThread != nil ) then
	       self.AmbientEffectThread:Destroy()
        end	 
        if self.AmbientExhaustEffectsBag then
            EffectUtil.CleanupEffectBag(self,'AmbientExhaustEffectsBag')
        end        
        
        self.AmbientEffectThread = nil
        self.AmbientExhaustEffectsBag = {} 
	    if layer == 'Land' then
	        self.AmbientEffectThread = self:ForkThread(self.UnitLandAmbientEffectThread)        
	    end          
	end, 
	
	UnitLandAmbientEffectThread = function(self)
		while not self:IsDead() do
            local army = self:GetArmy()			
			
			for kE, vE in self.AmbientLandExhaustEffects do
				for kB, vB in self.AmbientExhaustBones do
					table.insert( self.AmbientExhaustEffectsBag, CreateAttachedEmitter(self, vB, army, vE ):ScaleEmitter(0.3):OffsetEmitter(0,0,0))
				end
			end
			WaitSeconds(2)
			EffectUtil.CleanupEffectBag(self,'AmbientExhaustEffectsBag')
			WaitSeconds(utilities.GetRandomFloat(1,3))
			for kE, vE in self.AmbientLandExhaustEffects do
				for kB, vB in self.AmbientExhaustBones2 do
					table.insert( self.AmbientExhaustEffectsBag, CreateAttachedEmitter(self, vB, army, vE ):ScaleEmitter(0.2):OffsetEmitter(0,0,0))
				end
			end
			WaitSeconds(3)	
			EffectUtil.CleanupEffectBag(self,'AmbientExhaustEffectsBag')	
			WaitSeconds(utilities.GetRandomFloat(5,15))
		end		
	end,    

	OnKilled = function(self, inst, type, okr)
        self.Trash:Destroy()
        self.Trash = TrashBag()
        if self.AmbientExhaustEffectsBag then
            EffectUtil.CleanupEffectBag(self,'AmbientExhaustEffectsBag')
        end
        ALandUnit.OnKilled(self, inst, type, okr)
    end,
	    
}
TypeClass = UAL0302