do

local CBFP_oldXSA0202 = XSA0202

XSA0202 = Class(CBFP_oldXSA0202) {

    # The speed adjustment calculations in the original script didn't take into account the fuel supply of the unit.
    # Bug report and fix by Kaskouy, rewritten by Brute51. [168]

    Weapons = {
        ShleoAAGun01 = Class(CBFP_oldXSA0202.Weapons.ShleoAAGun01) {},
        ShleoAAGun02 = Class(CBFP_oldXSA0202.Weapons.ShleoAAGun02) {},
        Bomb = Class(CBFP_oldXSA0202.Weapons.Bomb) {
                
            IdleState = State (CBFP_oldXSA0202.Weapons.Bomb.IdleState) {
                OnGotTarget = function(self)
                    CBFP_oldXSA0202.Weapons.Bomb.IdleState.OnGotTarget(self)
                    local speedMulti = 0.67 * self.unit:GetSpeedModifier()   # [168]
                    self.unit:SetSpeedMult(speedMulti)
                end,                
            },
        
            OnGotTarget = function(self)
                CBFP_oldXSA0202.Weapons.Bomb.OnGotTarget(self)
                local speedMulti = 0.67 * self.unit:GetSpeedModifier()   # [168]
                self.unit:SetSpeedMult(speedMulti)
            end,
        
            OnLostTarget = function(self)
                CBFP_oldXSA0202.Weapons.Bomb.OnLostTarget(self)
                local speedMulti = self.unit:GetSpeedModifier()   # [168]
                self.unit:SetSpeedMult(speedMulti)
            end,  	
        },
    },

    GetSpeedModifier = function(self)
        # this returns 1 when the plane has fuel or 0.25 when it doesn't have fuel. The movement speed penalty for
        # running out of fuel is 75% so planes with no fuel fly at 25% of max speed. [168]
        if self:GetFuelRatio() == 0 then
            return 0.25
        end
        return 1
    end,
}

TypeClass = XSA0202

end