defineProperty("AI", globalProperty("sim/operation/prefs/ai_flies_aircraft"))
defineProperty("AP", globalProperty("sim/cockpit2/autopilot/flight_director_mode"))
defineProperty("AT", globalProperty("sim/cockpit2/autopilot/autothrottle_enabled"))
defineProperty("VNAV", globalProperty("sim/cockpit2/autopilot/fms_vnav"))
defineProperty("L_N2_speed",globalProperty("sim/cockpit2/engine/indicators/N2_percent[0]")) 
defineProperty("R_N2_speed",globalProperty("sim/cockpit2/engine/indicators/N2_percent[1]"))
defineProperty("L_fadec",globalProperty("sim/cockpit2/engine/actuators/fadec_on[0]"))
defineProperty("R_fadec",globalProperty("sim/cockpit2/engine/actuators/fadec_on[1]"))
defineProperty("N1_Limit0",globalProperty("sim/cockpit2/engine/actuators/N1_target_bug[0]"))
defineProperty("N1_Limit1",globalProperty("sim/cockpit2/engine/actuators/N1_target_bug[1]"))
defineProperty("ThrotMax",globalProperty("sim/aircraft/engine/acf_throtmax_FWD"))
defineProperty("Fuel0",globalProperty("sim/cockpit2/fuel/fuel_quantity[0]"))
defineProperty("Fuel1",globalProperty("sim/cockpit2/fuel/fuel_quantity[1]"))
defineProperty("alt",globalProperty("sim/cockpit2/autopilot/altitude_readout_preselector"))


function update()

if get(AT) < 0 then
logInfo("sim/cockpit2/autopilot/autothrottle_enabled set to -1. Setting back to 0")
set(AT, 0)
end

if get(AT) > 0 or get(AI) > 0 then
set(L_fadec, 1)
set(R_fadec, 1)
set(ThrotMax, 1.0)
else
set(L_fadec, 0)
set(R_fadec, 0)
set(ThrotMax, 1.2)
end

if get(VNAV) == 1 then
-- Limit throttle during VNAV by fuel load and altitude - otherwise, the plane climbs like a rocket at light loads
fuel = get(Fuel0) + get(Fuel1)
alt_mod = get(alt) / 2500
limit = fuel / 382.2858 + 75 + alt_mod
if limit > 110 then 
limit = 110 
end
set (N1_Limit0,limit)
set (N1_Limit1,limit)
else
set (N1_Limit0,110)
set (N1_Limit1,110)
end

end
