do

local CBFP_oldUEL0001 = UEL0001

UEL0001 = Class(CBFP_oldUEL0001) {    


#### Brute51 Pod Fix part 1/2 ---------------------------------
# In this fix I'm seperating 'Left pod' from the left should pod (first upgrade) and the 'Right pod' from the 
# right shoulder pod (second upgrade). This way if a pod is destroyed I dont have to reset the other pod so now it
# can continue to do what it was doing.
# When a pod is destroyed this removes either the 2nd upgrade if we had 2 pods, or the first if we had 1 pod.
####
    NotifyOfPodDeath = function(self, pod)

        if self.HasLeftPod and self.HasRightPod then
            # we have 2 pods and one dies

            # So we need to go back to 1 enhancement icon being lit insted of
            # both. If I make the left one dark then the right one turns dark aswell.
            # Bypassing the ACUs createenhancement function because that destroys both pods
            TWalkingLandUnit.CreateEnhancement(self, 'RightPodRemove') # darkens both pod enhancement icons
            TWalkingLandUnit.CreateEnhancement(self, 'LeftPod') # makes the correct enhancement icon light up again

        else
            # we have 1 pod and it dies

            # since we have just 1 pod only the left enhancement icon is lit. 
            self:CreateEnhancement('LeftPodRemove')
        end

        self:RequestRefreshUI()

        if pod == 'LeftPod' then
            self.HasLeftPod = false
        else
            self.HasRightPod = false
        end

# end Pod Fix 1/2 ---------------------------------------
    end,

    CreateEnhancement = function(self, enh)
        local bp = self:GetBlueprint().Enhancements[enh]
        if not bp then return end


#### Brute51 Pod Fix part 2/2 ---------------------------------
# Here we're adding pods when a pod upgrade is done. The pod is added to either Leftpod or Rightpod, depending on
# which variable isnt used yet. This means it could happen Leftpod is used for the 2nd pod.
####

        if enh == 'LeftPod' or enh == 'RightPod' then

            # making sure we have up to date information
            if not self.LeftPod or self.LeftPod:IsDead() then
                self.HasLeftPod = false
            end
            if not self.RightPod or self.RightPod:IsDead() then
                self.HasRightPod = false
            end

            # when we're enhancing to the 2nd pod enhancement ( = right pod) but the first pod is destroyed then 
            # change to 1st pod ( = left pod)
            if enh == 'RightPod' and not self.HasLeftPod and not self.HasRightPod then
                TWalkingLandUnit.CreateEnhancement(self, 'RightPodRemove')  # no pod enhancement icons lit
                enh = 'LeftPod'
            end

            TWalkingLandUnit.CreateEnhancement(self, enh)

            if not self.HasLeftPod then
                local location = self:GetPosition('AttachSpecial02')
                local pod = CreateUnitHPR('UEA0001', self:GetArmy(), location[1], location[2], location[3], 0, 0, 0)
                pod:SetCreator(self)
                pod:SetParent(self, 'LeftPod')
                self.Trash:Add(pod)
                self.LeftPod = pod
                self.HasLeftPod = true
            else
                local location = self:GetPosition('AttachSpecial01')
                local pod = CreateUnitHPR('UEA0001', self:GetArmy(), location[1], location[2], location[3], 0, 0, 0)
                pod:SetCreator(self)
                pod:SetParent(self, 'RightPod')
                self.Trash:Add(pod)
                self.RightPod = pod
                self.HasRightPod = true
            end

        # for removing the pod upgrades
        elseif enh == 'RightPodRemove' or enh == 'LeftPodRemove' then

            # this is only run when the ACU has only 1 pod enhancement or when we're dumping an enhancement for
            # another one. In both cases it's ok if we destroy both living pods.

            TWalkingLandUnit.CreateEnhancement(self, enh)

            if self.RightPod and not self.RightPod:IsDead() then
                self.RightPod:Kill()
                self.HasRightPod = false
            end
            if self.LeftPod and not self.LeftPod:IsDead() then
                self.LeftPod:Kill()
                self.HasLeftPod = false
            end


# end Pod Fix 2/2 ---------------------------------------


        elseif enh =='DamageStablization' then
            # added by brute51 - fix for bug SCU regen upgrade doesnt stack with veteran bonus [140]
            TWalkingLandUnit.CreateEnhancement(self, enh)
            local bpRegenRate = bp.NewRegenRate or 0
            if not Buffs['UefACURegenerateBonus'] then
               BuffBlueprint {
                    Name = 'UefACURegenerateBonus',
                    DisplayName = 'UefACURegenerateBonus',
                    BuffType = 'ACUREGENERATEBONUS',
                    Stacks = 'ALWAYS',
                    Duration = -1,
                    Affects = {
                        Regen = {
                            Add = bpRegenRate,
                            Mult = 1.0,
                        },
                    },
                } 
            end
            if Buff.HasBuff( self, 'UefACURegenerateBonus' ) then
                Buff.RemoveBuff( self, 'UefACURegenerateBonus' )
            end  
            Buff.ApplyBuff(self, 'UefACURegenerateBonus')
        elseif enh =='DamageStablizationRemove' then
            # added by brute51 - fix for bug SCU regen upgrade doesnt stack with veteran bonus [140]
            TWalkingLandUnit.CreateEnhancement(self, enh)
            if Buff.HasBuff( self, 'UefACURegenerateBonus' ) then
                Buff.RemoveBuff( self, 'UefACURegenerateBonus' )
            end  

        else
            CBFP_oldUEL0001.CreateEnhancement(self, enh)
        end
    end,
}

TypeClass = UEL0001

end