<!DOCTYPE flight_plan SYSTEM "flight_plan.dtd">

<!--flight_plan alt="120" ground_alt="0" lat0="42.644957" lon0="9.015701" max_dist_from_home="200000" name="Corsica" security_height="70"-->
<flight_plan alt="80" ground_alt="0" lat0="43.771918" lon0="7.499057" max_dist_from_home="200000" name="Corsica" security_height="70" qfu="130">
  <waypoints>
    <waypoint name="HOME"         lat="42.644957" lon="9.015701"/>
    <waypoint name="STDBY_MENTON" lat="43.77"	    lon="7.5"/>
    <waypoint name="STDBY_LOZARI" lat="42.6444"   lon="9.016"/>
    <waypoint name="MENTON"       lat="43.770726" lon="7.500866"/>
    <waypoint name="TMA_NICE"     lat="43.540596" lon="7.830192"/>
    <waypoint name="TMA_CALVI"    lat="42.815734" lon="8.789095"/>
    <waypoint name="LOZARI"       lat="42.645772" lon="9.014937"/>
    <waypoint alt="30.0" name="AF" lat="42.640243" lon="9.011551"/>
    <waypoint alt="0.0"  name="TD" lat="42.640735" lon="9.014385"/>
    <waypoint name="_BASELEG" x="168.8" y="-13.8"/>
    <waypoint name="CLIMB"        lat="43.769542" lon="7.501300"/>
  </waypoints>

  <includes>
    <include name="ZRT" procedure="corsica_sectors.xml"/>
  </includes>

  <exceptions>
    <exception cond="Or(! InsideZRT(GetPosX(), GetPosY()), GetPosAlt() > GetAltRef() + 300)" deroute="Kill"/>
  </exceptions>
  <blocks>
    <block name="Wait GPS">
      <set value="1" var="kill_throttle"/>
      <while cond="!GpsFixValid()"/>
    </block>
    <block name="Holding point">
      <set value="1" var="kill_throttle"/>
      <attitude roll="0" throttle="0" vmode="throttle"/>
    </block>
    <block name="Takeoff" strip_button="Takeoff (wp CLIMB)" strip_icon="takeoff.png">
      <exception cond="GetPosAlt() > GetAltRef()+25" deroute="Standby Menton"/>
      <set value="0" var="kill_throttle"/>
      <set value="0" var="autopilot_flight_time"/>
      <go throttle="1.0" vmode="throttle" wp="CLIMB" pitch="15"/>
    </block>
    <block name="Standby Menton" strip_button="Standby Menton" strip_icon="home.png">
      <circle radius="nav_radius" wp="STDBY_MENTON"/>
    </block>
    <block name="Mission to Corsica" strip_button="Mission to Corsica" strip_icon="path.png">
      <go wp="TMA_NICE" from="MENTON" hmode="route"/>
      <go wp="TMA_CALVI" from="TMA_NICE" hmode="route"/>
      <go wp="LOZARI" from="TMA_CALVI" hmode="route"/>
      <deroute block="Standby Lozari"/>
    </block>
    <block name="Standby Lozari" strip_button="Standby Lozari" strip_icon="home.png">
      <circle radius="nav_radius" wp="STDBY_LOZARI" until="stage_time>300"/>
      <circle radius="nav_radius" wp="STDBY_LOZARI" alt="30"/>
    </block>

    <block name="Land Right AF-TD" strip_button="Land right (wp AF-TD)" strip_icon="land-right.png">
      <set value="DEFAULT_CIRCLE_RADIUS" var="nav_radius"/>
      <deroute block="land"/>
    </block>
    <block name="Land Left AF-TD" strip_button="Land left (wp AF-TD)" strip_icon="land-left.png">
      <set value="-DEFAULT_CIRCLE_RADIUS" var="nav_radius"/>
      <deroute block="land"/>
    </block>
    <block name="land">
      <call fun="nav_compute_baseleg(WP_AF, WP_TD, WP__BASELEG, nav_radius)"/>
      <circle radius="nav_radius" until="NavCircleCount() > 0.5" wp="_BASELEG"/>
      <circle radius="nav_radius" until="And(NavQdrCloseTo(DegOfRad(baseleg_out_qdr)-10), 10 > fabs(GetPosAlt() - WaypointAlt(WP__BASELEG)))" wp="_BASELEG"/>
    </block>
    <block name="final">
      <exception cond="GetAltRef() + 10 > GetPosAlt()" deroute="flare"/>
      <go from="AF" hmode="route" vmode="glide" wp="TD"/>
    </block>
    <block name="flare">
      <go approaching_time="0" from="AF" hmode="route" throttle="0.0" vmode="throttle" wp="TD"/>
      <attitude roll="0.0" throttle="0.0" until="FALSE" vmode="throttle"/>
    </block>
    <block name="Kill">
      <exception cond="And(InsideZRT(GetPosX(), GetPosY()), GetAltRef() + 300 > GetPosAlt())" deroute="Resume Mission"/>
      <attitude roll="0" vmode="throttle" throttle="0.2"/>
    </block>
    <block name="Resume Mission">
      <deroute block="Mission to Corsica"/>
    </block>
    <block name="Back to Menton">
      <go wp="TMA_CALVI" from="LOZARI" hmode="route"/>
      <go wp="TMA_NICE" from="TMA_CALVI" hmode="route"/>
      <go wp="MENTON" from="TMA_NICE" hmode="route"/>
      <deroute block="Standby Menton"/>
    </block>
  </blocks>
</flight_plan>
