local CBFP_oldXEA0306 = XEA0306

XEA0306 = Class(CBFP_oldXEA0306) {

    # added by brute51 - bug fix for flak ignoring continental shields [122]
    # This fix is about making the continental and its cargo invulnerable so long it's shield is protecting it.

    ShieldIsOn = true,  # used to keep track of shield status

    OnTransportAttach = function(self, attachBone, unit)
        CBFP_oldXEA0306.OnTransportAttach(self, attachBone, unit)
        unit:SetCanTakeDamage(not ShieldIsOn) # making transported unit invulnerable if transport is too
    end,

    OnTransportDetach = function(self, attachBone, unit)
        unit:SetCanTakeDamage(true) # Units dropped by the transport shouldnt be invulnerable
        CBFP_oldXEA0306.OnTransportDetach(self, attachBone, unit)
    end,

    OnShieldIsUp = function (self)
        CBFP_oldXEA0306.OnShieldIsUp(self)
        self:ShieldStatusChanged(true)
    end,

    OnShieldIsDown = function (self)
        self:ShieldStatusChanged(false)
        CBFP_oldXEA0306.OnShieldIsDown(self)
    end,

    ShieldStatusChanged = function( self, ShieldIsOnline )
        self.ShieldIsOn = ShieldIsOnline
        self:SetCanTakeDamage(not ShieldIsOnline) # turn invulnerability on when our shield is on
        local cargo = self:GetCargo()
        for k, v in cargo do
            v:SetCanTakeDamage(not ShieldIsOnline)
        end
    end,

    OnKilled = function(self, instigator, type, overkillRatio)
        if self.GetCargo then
            local cargo = self:GetCargo() # added by brute51  all carried units should be vulnerable again
            for k, v in cargo do
                v:SetCanTakeDamage(true) 
            end
        end
        CBFP_oldXEA0306.OnKilled(self, instigator, type, overkillRatio)
    end,
}

TypeClass = XEA0306