--[[#######################################################################
#  File	 :  /hook/lua/CybranModUnits.lua
#  Author(s):  GPG Devs
#  Summary  :  Default definitions of Cybran units
#  -----------------------------
#  Modif.by :  AsdrubaelVect
#  Rev.Date :  5 septembre 2009
#  -----------------------------
#  Revis.by :  Manimal
#  Rev.Date :  14 décembre 2009
#  -----------------------------
#  Copyright © 2005 Gas Powered Games, Inc.  All rights reserved.
#######################################################################]]--


#--------------------------------------------------------------------------
# CYBRAN DEFAULT UNITS
#--------------------------------------------------------------------------
local DefaultUnitsFile = import('defaultunits.lua')
local AirFactoryUnit = DefaultUnitsFile.AirFactoryUnit
local AirStagingPlatformUnit = DefaultUnitsFile.AirStagingPlatformUnit
local AirUnit = DefaultUnitsFile.AirUnit
local ConcreteStructureUnit = DefaultUnitsFile.ConcreteStructureUnit
local ConstructionUnit = DefaultUnitsFile.ConstructionUnit
local EnergyStorageUnit = DefaultUnitsFile.EnergyStorageUnit
local LandFactoryUnit = DefaultUnitsFile.LandFactoryUnit
local SeaFactoryUnit = DefaultUnitsFile.SeaFactoryUnit
local SeaUnit = DefaultUnitsFile.SeaUnit
local ShieldLandUnit = DefaultUnitsFile.ShieldLandUnit
local ShieldStructureUnit = DefaultUnitsFile.ShieldStructureUnit
local StructureUnit = DefaultUnitsFile.StructureUnit
local QuantumGateUnit = DefaultUnitsFile.QuantumGateUnit
local RadarJammerUnit = DefaultUnitsFile.RadarJammerUnit

local Util = import('utilities.lua')
local EffectTemplate = import('/lua/EffectTemplates.lua')
local EffectUtil = import('EffectUtilities.lua')
local CreateCybranBuildBeams = EffectUtil.CreateCybranBuildBeams


# MODIF DE MANIMAL
local HoverLandUnit = DefaultUnitsFile.HoverLandUnit
local TransportBeaconUnit = DefaultUnitsFile.TransportBeaconUnit
local LandUnit = DefaultUnitsFile.LandUnit
local SubUnit = DefaultUnitsFile.SubUnit
local WalkingLandUnit = DefaultUnitsFile.WalkingLandUnit
local WallStructureUnit = DefaultUnitsFile.WallStructureUnit


# AJOUT DE MANIMAL
local PortalFactoryUnit = DefaultUnitsFile.PortalFactoryUnit
local HeroWalkingLandUnit = DefaultUnitsFile.HeroWalkingLandUnit


#-------------------------------------------------------------
#  PORTAL FACTORY STRUCTURES
#-------------------------------------------------------------

--CPortalFactoryUnit = Class(AirFactoryUnit) {
CPortalFactoryUnit = Class( PortalFactoryUnit ) {

    CreateBuildEffects = function( self, unitBeingBuilt, order )
        if not unitBeingBuilt then return end
        WaitSeconds( 0.1 )
        EffectUtil.CreateCybranFactoryBuildEffects( self, unitBeingBuilt, self:GetBlueprint().General.BuildBones, self.BuildEffectsBag )
    end,
    
    StartBuildFx = function(self, unitBeingBuilt)
        if not unitBeingBuilt then return end
    end,
    
    StopBuildFx = function(self)
    end,
    
    OnPaused = function(self)
        PortalFactoryUnit.OnPaused(self)    --AirFactoryUnit.OnPaused(self)
    end,
    
    OnUnpaused = function(self)
        PortalFactoryUnit.OnUnpaused(self)    --AirFactoryUnit.OnUnpaused(self)
        if self:GetNumBuildOrders(categories.ALLUNITS) > 0 and not self:IsUnitState('Upgrading') then
        end
    end,

    OnStartBuild = function(self, unitBeingBuilt, order )
        PortalFactoryUnit.OnStartBuild(self, unitBeingBuilt, order )    --AirFactoryUnit.OnStartBuild(self, unitBeingBuilt, order )
        if order != 'Upgrade' then
        end
    end,
   
    OnStopBuild = function(self, unitBuilding)
        PortalFactoryUnit.OnStopBuild(self, unitBuilding)    --AirFactoryUnit.OnStopBuild(self, unitBuilding)
    end,

    OnFailedToBuild = function(self)
        PortalFactoryUnit.OnFailedToBuild(self)    --AirFactoryUnit.OnFailedToBuild(self)
    end,

    OnStartBeingBuilt = function(self, builder, layer)
        PortalFactoryUnit.OnStartBeingBuilt(self, builder, layer)
    end,

    OnCreate = function(self)
        PortalFactoryUnit.OnCreate(self)
    end,


}   



#-------------------------------------------------------------
#  HERO WALKING LAND UNITS
#-------------------------------------------------------------

CHeroWalkingLandUnit = Class( HeroWalkingLandUnit ) {}




#-------------------------------------------------------------
#  AIR UNITS
#-------------------------------------------------------------
CAirUnit = Class(DefaultUnitsFile.AirUnit) {}


#-------------------------------------------------------------
#  AIR FACTORY STRUCTURES
#-------------------------------------------------------------
CAirFactoryUnit = Class(AirFactoryUnit) {

    CreateBuildEffects = function( self, unitBeingBuilt, order )
        if not unitBeingBuilt then return end
        WaitSeconds( 0.1 )
        EffectUtil.CreateCybranFactoryBuildEffects( self, unitBeingBuilt, self:GetBlueprint().General.BuildBones, self.BuildEffectsBag )
    end,
    
    StartBuildFx = function(self, unitBeingBuilt)
        if not unitBeingBuilt then return end
        
        # Start build process
        if not self.BuildAnimManip then
            self.BuildAnimManip = CreateAnimator(self)
            self.BuildAnimManip:PlayAnim(self:GetBlueprint().Display.AnimationBuild, true):SetRate(0)
            self.Trash:Add(self.BuildAnimManip)
        end
        self.BuildAnimManip:SetRate(1)
    end,
    
    StopBuildFx = function(self)
        if self.BuildAnimManip then
            self.BuildAnimManip:SetRate(0)
        end
    end,
    
    OnPaused = function(self)
        AirFactoryUnit.OnPaused(self)
        self:StopArmsMoving()
    end,
    
    OnUnpaused = function(self)
        AirFactoryUnit.OnUnpaused(self)
        if self:GetNumBuildOrders(categories.ALLUNITS) > 0 and not self:IsUnitState('Upgrading') then
            self:StartArmsMoving()
        end
    end,

    OnStartBuild = function(self, unitBeingBuilt, order )
        AirFactoryUnit.OnStartBuild(self, unitBeingBuilt, order )
        if order != 'Upgrade' then
            self:StartArmsMoving()
        end
    end,
   
    OnStopBuild = function(self, unitBuilding)
        AirFactoryUnit.OnStopBuild(self, unitBuilding)
        self:StopArmsMoving()
    end,

    OnFailedToBuild = function(self)
        AirFactoryUnit.OnFailedToBuild(self)
        self:StopArmsMoving()
    end,

}

