<?xml version="1.0"?>

<PropertyList>

    <name>Engine Failure</name>

    <description>Engine failure is very rare in flight simulators, but a risk in real life.


The tutorial starts with you cruising at 3000 ft near Hilo. A total engine failure will occur, with no possibility of restart - black smoke, chunks of metal pushed out of the cowling.

Glide the aircraft to the nearest airport and make a successful emergency landing. You must manage your altitude and fly a normal pattern from "abeam the numbers". Don't deploy flaps until you have the runway "made".

The Cessna 172 glides at a ratio of 9:1 at a best glide speed of 65 kts IAS. The glide ratio assumes no flaps and a "windmilling" propeller. If you fly any faster or slower, or have flaps deployed, the glide rate will be worse.

PHTO (Hilo) is within glide distance. Try to land at PHTO.
  </description>
  
    <nasal>
        <script>
            c172p.repair_damage();
            electrical.reset_battery_and_circuit_breakers();
            c172p.click("engine-repair", 6.0);
            c172p.dialog_battery_reload();
            setprop("/engines/active-engine/oil-level", sim/model/c172p/engine_flag_0 ? 7 : 8);
            setprop("/engines/active-engine/carb_ice", 0.0);
            setprop("/fdm/jsbsim/engine/damage-level", 0.0);
        </script>
    </nasal>

    <timeofday>dusk</timeofday>
    <presets>
        <airport-id>PHTO</airport-id>
        <on-ground>0</on-ground>
        <altitude-ft>3000</altitude-ft>
        <latitude-deg>19.76209725536232</latitude-deg>
        <longitude-deg>-155.017574109008</longitude-deg>
        <heading-deg>270</heading-deg>
        <airspeed-kt>105.0</airspeed-kt>
        <glideslope-deg>3.5</glideslope-deg>
        <offset-azimuth-deg>0</offset-azimuth-deg>
        <offset-distance-nm>0</offset-distance-nm>
        <ndb-id>0</ndb-id>
        <vor-id>0</vor-id>
        <fix>0</fix>
    </presets>

    <step>
        <set>
            <property>/sim/model/c172p/securing/chock</property>
            <value>false</value>
        </set>
        <set>
            <property>/sim/model/c172p/securing/cowl-plugs-visible</property>
            <value>false</value>
        </set>
        <set>
            <property>/sim/model/c172p/securing/tiedownL-visible</property>
            <value>false</value>
        </set>
        <set>
            <property>/sim/model/c172p/securing/tiedownR-visible</property>
            <value>false</value>
        </set>
        <set>
            <property>/sim/model/c172p/securing/tiedownT-visible</property>
            <value>false</value>
        </set>
        <set>
            <property>/sim/model/c172p/securing/pitot-cover-visible</property>
            <value>false</value>
        </set>
        <set>
            <property>/controls/flight/flaps</property>
            <value>0.0</value>
        <set>
            <property>/controls/switches/master-bat</property>
            <value>true</value>
        </set>
        <set>
            <property>/controls/switches/master-alt</property>
            <value>true</value>
        </set>
        </set>
        <set>
            <property>/controls/switches/magnetos</property>
            <value>3</value>
        </set>
        <set>
            <property>/controls/engines/current-engine/throttle</property>
            <value>0.2</value>
        </set>
        <set>
            <property>/instrumentation/adf/frequencies/selected-khz</property>
            <value>367</value>
        </set>
        <set>
            <property>/environment/weather-scenario</property>
            <value>Fair weather</value>
        </set>
        <set>
            <property>instrumentation/altimeter/setting-inhg</property>
            <value>29.95</value>
        </set>
        <set>
            <property>/sim/model/c172p/cockpit/control-lock-placed</property>
            <value>false</value>
        </set>
        <set>
            <property>/sim/model/c172p/cockpit/control-lock-visible</property>
            <value>false</value>
        </set>
        <nasal>
            <script>
                setprop("/controls/engines/current-engine/mixture", 1.0);
                setprop("/controls/switches/starter", 1);
            </script>
        </nasal>
        <message></message>
        <view>
            <heading-offset-deg>0.0</heading-offset-deg>
            <pitch-offset-deg>-12</pitch-offset-deg>
            <roll-offset-deg>0.0</roll-offset-deg>
            <x-offset-m>-0.21</x-offset-m>
            <y-offset-m>0.19</y-offset-m>
            <field-of-view>73.6</field-of-view>
        </view>
    </step>

    <step>
        <nasal>
            <script>
                var listeners = std.Vector.new();

                listeners.append(setlistener("/engines/active-engine/running", func (node) {
                    if (node.getBoolValue()) {
                        setprop("/controls/switches/starter", 0);
                        foreach (var listener; listeners.vector) {
                            removelistener(listener);
                        }
                        listeners.clear();
                    }
                }, 1, 0));
            </script>
        </nasal>
        <set>
            <property>/controls/engines/current-engine/throttle</property>
            <value>0.6</value>
        </set>
        <message>We're happily cruising along, enjoying an evenings flight.</message>
        <wait>15</wait>
    </step>

    <step>
        <message>Engine failure! Engine failure! Trim for a best glide speed of 65 knots.</message>
        <set>
            <property>/controls/switches/starter</property>
            <value>false</value>
        </set>
        <set>
            <property>/controls/engines/engine/faults/left-magneto-serviceable</property>
            <value>false</value>
        </set>
        <set>
            <property>/controls/engines/engine/faults/right-magneto-serviceable</property>
            <value>false</value>
        </set>
        <set>
            <property>/controls/engines/engine/faults/spark-plugs-serviceable</property>
            <value>false</value>
        </set>
        <set>
            <property>/controls/switches/magnetos</property>
            <value>0</value>
        </set>
    </step>

    <step>
        <message>Now look around and choose an airport, or emergency landing site. Stay at 65 knots.</message>
        <set>
            <property>/engines/active-engine/running</property>
            <value>false</value>
        </set>

        <error>
            <message>You are too slow. You need to fly at 65 knots IAS for maximum glide.</message>
            <condition>
                <less-than>
                    <property>/instrumentation/airspeed-indicator/indicated-speed-kt</property>
                    <value>62</value>
                </less-than>
            </condition>
        </error>
        <error>
            <message>You are too fast. You need to fly at 65 knots IAS for maximum glide.</message>
            <condition>
                <greater-than>
                    <property>/instrumentation/airspeed-indicator/indicated-speed-kt</property>
                    <value>69</value>
                </greater-than>
            </condition>
        </error>
        <error>
            <message>Engine failure is currently simulated by switching off the magnetos.
        Please switch them off again to continue the tutorial.</message>
            <condition>
                <greater-than>
                    <property>/controls/switches/magnetos</property>
                    <value>0</value>
                </greater-than>
            </condition>
        </error>
    </step>

    <step>
        <message>Start maneuvering towards your chosen emergency landing spot,
      keeping your speed at 65 knots IAS.</message>
        <set>
            <property>/engines/active-engine/running</property>
            <value>false</value>
        </set>

        <error>
            <message>You are too slow. You need to fly at 65 knots IAS for maximum glide.</message>
            <condition>
                <less-than>
                    <property>/instrumentation/airspeed-indicator/indicated-speed-kt</property>
                    <value>62</value>
                </less-than>
            </condition>
        </error>
        <error>
            <message>You are too fast. You need to fly at 65 knots IAS for maximum glide.</message>
            <condition>
                <greater-than>
                    <property>/instrumentation/airspeed-indicator/indicated-speed-kt</property>
                    <value>69</value>
                </greater-than>
            </condition>
        </error>
        <error>
            <message>Engine failure is currently simulated by switching off the magnetos.
        Please switch them off again to continue the tutorial.</message>
            <condition>
                <greater-than>
                    <property>/controls/switches/magnetos</property>
                    <value>0</value>
                </greater-than>
            </condition>
        </error>
    </step>

    <step>
        <message>At this point we would radio an emergency/mayday.
      Remember - Aviate, Navigate, Communicate - in that order.</message>
        <set>
            <property>/engines/active-engine/running</property>
            <value>false</value>
        </set>

        <error>
            <message>You are too slow. You need to fly at 65 knots IAS for maximum glide.</message>
            <condition>
                <less-than>
                    <property>/instrumentation/airspeed-indicator/indicated-speed-kt</property>
                    <value>62</value>
                </less-than>
            </condition>
        </error>
        <error>
            <message>You are too fast. You need to fly at 65 knots IAS for maximum glide.</message>
            <condition>
                <greater-than>
                    <property>/instrumentation/airspeed-indicator/indicated-speed-kt</property>
                    <value>69</value>
                </greater-than>
            </condition>
        </error>
        <error>
            <message>Engine failure is currently simulated by switching off the magnetos.
        Please switch them off again to continue the tutorial.</message>
            <condition>
                <greater-than>
                    <property>/controls/switches/magnetos</property>
                    <value>0</value>
                </greater-than>
            </condition>
        </error>
    </step>

    <step>
        <message>Continue flying towards your emergency landing spot.
      If we had the spare capacity, we might attempt to restart the engine at this point.</message>

        <error>
            <message>Engine failure is currently simulated by switching off the magnetos.
        Please switch them off again to continue the tutorial.</message>
            <condition>
                <greater-than>
                    <property>/controls/switches/magnetos</property>
                    <value>0</value>
                </greater-than>
            </condition>
        </error>
    </step>

    <step>
        <message>Stay a 65 knots for maximum glide. Only use flaps once the runway is "made".</message>

        <error>
            <message>Engine failure is currently simulated by switching off the magnetos.
        Please switch them off again to continue the tutorial.</message>
            <condition>
                <greater-than>
                    <property>/controls/switches/magnetos</property>
                    <value>0</value>
                </greater-than>
            </condition>
        </error>

        <exit>
            <condition>
                <less-than>
                    <property>/instrumentation/airspeed-indicator/indicated-speed-kt</property>
                    <value>10</value>
                </less-than>
            </condition>
        </exit>
    </step>

    <step>
        <message>Assuming the aircraft is upright and you landed on a runway,
      you walked away from a total engine failure - well done!</message>
    </step>

</PropertyList>