; Fltdir.txt by Art Rutty, 72550,2533
; A Keyboard program to control the FS4 Auto-pilot.
; Incorporating Charlie Gulick's T&AMOD and
; inspired by his Flypal program.

keywatch:
if key("0")then
        gosub altlock
        endif
if key("\")then
        gosub climb100
        endif
if key("/")then
        gosub dive100
        endif
if key("a")then
        gosub aglread
        endif
if key("t")then
        gosub trimread
        endif
if key("6")then
        gosub tasread
        endif
if key("e")then
        gosub headhold
        endif
if key("w")then
        gosub turnleft
        endif
if key("r")then
        gosub turnright
        endif
if key("`")then
        gosub adftog
        endif
if key("j")then
        gosub jack
        endif
if key("8")then
        gosub magvar
        endif
if key("9")then
        gosub vor1tog
        endif
goto keywatch

altlock:
movevar(altit_lock_var,altmsl)
setvar(a,1)
z := z ^ a
movevar(altit_lock,z)
if varmask(altit_lock,1)
gosub lockon
goto end
endif

print "Altitude hold off!"
wait(1)
print ""
setvar(altit_lock,0)
end:
return

lockon:
if altitude(0,0)
endif
printvar(result,"Altitude hold at: ")
wait(2)
print""
return

climb100:
setvar(a,0)
climb1002:
addvar(a,100)
addvar(altit_lock_var,30)
addvar(altit_lock,1)
printvar(a,"Climbing ")
wait(2)
if key("'")then
        print "Locking on new altitude"
        return
        endif
goto climb1002

dive100:
setvar(a,0)
dive1002:
addvar(a,100)
addvar(altit_lock_var,-30)
addvar(altit_lock,1)
printvar(a,"Decending ")
wait(2)
if key("'")then
        print "Locking on new altitude"
        return
        endif
goto dive1002

tasread:
if airspeed(0,0)
endif
printvar(result,"True Airspeed: ")
if key("6")then
        print ""
        return
        endif
goto tasread

aglread:
if altagl(0,0)
endif
printvar(result,"AGL: ")
if key("a")then
        print ""
        return
        endif
goto aglread

trimread:
printvar(elvtrm_ind,"Trim: "
if key("t")then
        print ""
        return
        endif
goto trimread

headhold:
setvar(nav1_lock,0)
setvar(a,1)
x := x ^ a
movevar(heading_lock,x)

if heading(0,0)
endif
z := result
z := z + v
setvar(c,182)
z := z * c
movevar(head_lock_var,z)

if varmask(heading_lock,1)then
if altagl(0,25)
print "Heading Hold On. . . Don't FORGET to tune in Magnetic Variation!"
return
endif
print "Heading Hold On. . ."
return
endif

setvar(f,0)
movevar(heading_lock,f)
print "Heading Hold Off"
wait(1)
print ""
return


adftog:
setvar(h,1)
adf_flag := adf_flag ^ h
print "Now press <esc> . . ."
wait(1)
print ""
return

jack:
if altagl(0,100)
setvar(j,254)
plane_height := plane_height + j
if altagl(0,0)
endif
printvar(result,"Plane height: ")
endif
return

turnleft:
setvar(a,0)
turnleft2:
addvar(a,-1)
printvar(a,"Turning left ")
addvar(head_lock_var,-182)
if key("x")then
        print "Locking on new course"
        return
        endif
goto turnleft2

turnright:
setvar(a,0)
turnright2:
addvar(a,1)
printvar(a,"Turning right: ")
addvar(head_lock_var,182)
if key("x")then
        print "Locking on new course"
        return
        endif
goto turnright2

magvar:
setvar(p,1)
setvar(n,-1)
magvar2:
print "Press: 9 for positive var. . . 7 for negative var. . . 8 to stop or end"
wait(1)
if key("9")then
        gosub pos
        endif
if key("7")then
        gosub neg
        endif
if key("8")then
        print ""
        return
        endif
printvar(v,"Magnetic Variation: ")
wait(1)
goto magvar2

pos:
        v := v + p
        printvar(v,"Magnetic Variation: ")
if key("8")then
        return
        endif
goto pos

neg:
        v := v + n
        printvar(v,"Magnetic Variation: ")
if key("8")then
        return
        endif
goto neg

vor1tog:
setvar(heading_lock,0)
setvar(a,1)
y := y ^ a
movevar(nav1_lock,y)
if varmask(nav1_lock,1)then
        print "Vor1 Lock ON"
        wait(1)
        return
endif
        print "Vor1 Lock Off"
        wait(1)
        print ""
return


