<PropertyList>

  <path>FDAP.ac</path>

  <animation>
    <type>select</type>
    <object-name>AP.fdoff.lit</object-name>
    <condition>
      <property>autopilot/locks/passive-mode</property>
      <greater-than>
        <property>/systems/electrical/ac-volts</property>
        <value>90</value>
      </greater-than>
    </condition>
  </animation>

  <animation>
    <type>select</type>
    <object-name>AP.hdg.lit</object-name>
    <condition>
      <equals>
        <property>autopilot/locks/heading</property>
        <value>dg-heading-hold</value>
      </equals>
    </condition>
  </animation>

  <animation>
    <type>select</type>
    <object-name>AP.nav.lit</object-name>
    <condition>
      <or>
        <equals>
          <property>autopilot/locks/heading</property>
          <value>nav1-hold</value>
        </equals>
        <equals>
          <property>autopilot/locks/heading</property>
          <value>nav2-hold</value>
        </equals>
        <equals>
          <property>autopilot/locks/heading</property>
          <value>gps-hold</value>
        </equals>
      </or>
    </condition>
  </animation>

  <animation>
    <type>select</type>
    <object-name>AP.apr.lit</object-name>
    <condition>
      <or>
        <equals>
          <property>autopilot/locks/altitude</property>
          <value>gs1-hold</value>
        </equals>
        <property>autopilot/settings/gs-arm</property>
      </or>
    </condition>
  </animation>

  <animation>
    <type>select</type>
    <object-name>AP.bc.lit</object-name>
    <condition>
      <property>instrumentation/nav/back-course-btn</property>
    </condition>
  </animation>

  <animation>
    <type>select</type>
    <object-name>AP.nav1.lit</object-name>
    <condition>
      <and>
        <equals>
          <property alias="../../../../../selected-nav"/>
          <value>0</value>
        </equals>
        <greater-than>
          <property>/systems/electrical/ac-volts</property>
          <value>90</value>
        </greater-than>
      </and>
    </condition>
  </animation>

  <animation>
    <type>select</type>
    <object-name>AP.nav2.lit</object-name>
    <condition>
      <and>
        <equals>
          <property alias="../../../../../selected-nav"/>
          <value>1</value>
        </equals>
        <greater-than>
          <property>/systems/electrical/ac-volts</property>
          <value>90</value>
        </greater-than>
      </and>
    </condition>
  </animation>

  <animation>
    <type>select</type>
    <object-name>AP.alt.lit</object-name>
    <condition>
      <equals>
        <property>autopilot/locks/altitude</property>
        <value>altitude-hold</value>
      </equals>
    </condition>
  </animation>

  <animation>
    <type>select</type>
    <object-name>AP.altsel.cap</object-name>
    <condition>
      <and>
        <equals>
          <property>autopilot/locks/altitude</property>
          <value>altitude-hold</value>
        </equals>
        <greater-than-equals>
          <expression>
            <abs>
              <difference>
                <property>autopilot/settings/target-altitude-ft</property>
                <property>instrumentation/altimeter/indicated-altitude-ft</property>
              </difference>
            </abs>
          </expression>
          <value type="double">100.0</value>
        </greater-than-equals>
      </and>
    </condition>
  </animation>

  <animation>
    <type>select</type>
    <object-name>AP.altsel.hld</object-name>
    <condition>
      <and>
        <equals>
          <property>autopilot/locks/altitude</property>
          <value>altitude-hold</value>
        </equals>
        <less-than-equals>
          <expression>
            <abs>
              <difference>
                <property>autopilot/settings/target-altitude-ft</property>
                <property>instrumentation/altimeter/indicated-altitude-ft</property>
              </difference>
            </abs>
          </expression>
          <value type="double">100.0</value>
        </less-than-equals>
      </and>
    </condition>
  </animation>

  <animation>
    <type>select</type>
    <object-name>AP.vnav.lit</object-name>
    <condition>
      <equals>
        <property>autopilot/locks/altitude</property>
        <value>vnav</value>
      </equals>
    </condition>
  </animation>

  <animation>
    <type>select</type>
    <object-name>AP.vs.lit</object-name>
    <condition>
      <equals>
        <property>autopilot/locks/altitude</property>
        <value>vertical-speed-hold</value>
      </equals>
    </condition>
  </animation>

  <animation>
    <type>select</type>
    <object-name>AP.ias.cap</object-name>
    <condition>
      <equals>
        <property>autopilot/locks/speed</property>
        <value>speed-with-throttle</value>
      </equals>
    </condition>
  </animation>

  <animation>
    <type>select</type>
    <object-name>AP.ias.hld</object-name>
    <condition>
      <equals>
        <property>autopilot/locks/speed</property>
        <value>speed-with-throttle</value>
      </equals>
    </condition>
  </animation>

  <!-- hotspots -->

  <animation>
    <type>pick</type>
    <object-name>AP.hdg</object-name>
    <action>
      <button>0</button>
      <binding>
        <command>nasal</command>
        <script>
          if (getprop ("autopilot/locks/heading") == "dg-heading-hold")
            setprop ("autopilot/locks/heading", "wing-leveler");
          else setprop ("autopilot/locks/heading", "dg-heading-hold");
        </script>
      </binding>
    </action>
  </animation>

  <animation>
    <type>pick</type>
    <object-name>AP.nav</object-name>
    <action>
      <button>0</button>
      <binding>
        <command>nasal</command>
        <!-- State transitions: NAV to GPS to wing leveler to NAV selected by
             the pilot's HSI -->
        <script>
          var current_value = getprop ("autopilot/locks/heading");
          if (current_value == "nav1-hold"
           or current_value == "nav2-hold") {
            setprop ("/autopilot/locks/heading", "gps-hold");
          }
          elsif (current_value == "gps-hold") {
            setprop ("/autopilot/locks/heading", "wing-leveler");
          }
          elsif (current_value == "wing-leveler") {
            var selected_nav = getprop ("/instrumentation/hsi[0]/selected-nav");
            setprop ("/autopilot/locks/heading", "nav" ~ (selected_nav + 1) ~ "-hold");
          }
        </script>
      </binding>
    </action>
  </animation>

  <animation>
    <type>pick</type>
    <object-name>AP.apr</object-name>
    <action>
      <button>0</button>
      <binding>
        <command>nasal</command>
        <script>
          if (getprop ("autopilot/locks/altitude") == "gs1-hold") {
            setprop("autopilot/locks/heading","wing-leveler");
            setprop("autopilot/locks/altitude","pitch-hold");
          }
          else {
            setprop("autopilot/locks/heading","nav1-hold");
            if (getprop ("instrumentation/nav[0]/gs-in-range")) {
              setprop("autopilot/locks/altitude", "gs1-hold");
              setprop("autopilot/settings/gs-arm", "false");
            }
            else {
              setprop("autopilot/locks/altitude", "altitude-hold");
              setprop("autopilot/settings/gs-arm", "true");
            }
          }
        </script>
      </binding>
    </action>
  </animation>

  <animation>
    <type>pick</type>
    <object-name>AP.bc</object-name>
    <action>
      <button>0</button>
      <binding>
        <command>property-toggle</command>
        <property>instrumentation/nav/back-course-btn</property>
      </binding>
    </action>
  </animation>

  <animation>
    <type>pick</type>
    <object-name>AP.nav-hsi</object-name>
    <action>
      <button>0</button>
      <binding>
        <command>property-toggle</command>
        <property alias="../../../../selected-nav"/>
        <!-- This triggers a Nasal listener in citation2.nas to drive the HSI
             from the selected nav radio. -->
      </binding>
      <binding>
        <command>nasal</command>
        <!--
            If autopilot is engaged in NAV mode, set it to follow the VOR beacon
            selected on the pilot's HSI, in case it has just changed.  If this
            script is triggered by toggling the copilot's HSI, it has no effect
            since the pilot's selected nav has not changed.
        -->
        <script>
          var current_mode = getprop ("/autopilot/locks/heading");
          if (current_mode == "nav1-hold"
           or current_mode == "nav2-hold") {
             var selected = getprop ("/instrumentation/hsi[0]/selected-nav");
             if (selected == 0) {
               setprop ("/autopilot/locks/heading", "nav1-hold");
             }
             elsif (selected == 1) {
               setprop ("/autopilot/locks/heading", "nav2-hold");
             }
          }
        </script>
      </binding>
    </action>
  </animation>

  <animation>
    <type>pick</type>
    <object-name>AP.alt</object-name>
    <action>
      <button>0</button>
      <binding>
        <command>nasal</command>
        <script>
          if (getprop ("autopilot/locks/altitude") == "altitude-hold")
            setprop ("autopilot/locks/altitude", "pitch-hold");
          else setprop ("autopilot/locks/altitude", "altitude-hold");
        </script>
      </binding>
    </action>
  </animation>

  <animation>
    <type>pick</type>
    <object-name>AP.vs</object-name>
    <action>
      <button>0</button>
      <binding>
        <command>nasal</command>
        <script>
          if (getprop ("autopilot/locks/altitude") == "vertical-speed-hold")
            setprop ("autopilot/locks/altitude", "pitch-hold");
          else setprop ("autopilot/locks/altitude", "vertical-speed-hold");
        </script>
      </binding>
    </action>
  </animation>

  <animation>
    <type>pick</type>
    <object-name>AP.ias</object-name>
    <action>
      <button>0</button>
      <binding>
        <command>property-cycle</command>
        <property>/autopilot/locks/speed</property>
        <value type="string">speed-with-throttle</value>
        <!-- value type="string">speed-with-pitch-trim</value--> <!-- not supported -->
        <value type="string"/>
      </binding>
    </action>
  </animation>

  <animation>
    <type>pick</type>
    <object-name>AP.fdoff</object-name>
    <action>
      <button>0</button>
      <binding>
        <command>property-toggle</command>
        <property>/autopilot/locks/passive-mode</property>
      </binding>
    </action>
  </animation>

</PropertyList>
