2007-03-24 20:56:40 +00:00
|
|
|
# Code to process XML-based tutorials. See $FG_ROOT/Docs/README.tutorials
|
2007-03-21 17:31:26 +00:00
|
|
|
# ---------------------------------------------------------------------------------------
|
2006-02-22 17:03:42 +00:00
|
|
|
|
|
|
|
|
2012-07-14 19:20:21 +00:00
|
|
|
var step_interval = 0; # time between tutorial steps (default is set below)
|
|
|
|
var exit_interval = 0; # time between fulfillment of a step and the start of the next step (default is set below)
|
2007-03-19 23:46:50 +00:00
|
|
|
|
2007-03-21 17:31:26 +00:00
|
|
|
var loop_id = 0;
|
2007-03-30 20:24:26 +00:00
|
|
|
var tutorialN = nil;
|
|
|
|
var steps = [];
|
2007-03-19 23:46:50 +00:00
|
|
|
var current_step = nil;
|
2007-03-30 20:24:26 +00:00
|
|
|
var is_first_step = nil;
|
2007-03-19 23:46:50 +00:00
|
|
|
var num_errors = nil;
|
2007-03-30 20:24:26 +00:00
|
|
|
var step_start_time = nil;
|
|
|
|
var step_iter_count = 0; # number or step loop iterations
|
|
|
|
var last_step_time = nil; # for set_targets() eta calculation
|
2007-03-19 23:46:50 +00:00
|
|
|
var audio_dir = nil;
|
|
|
|
|
2014-01-01 23:17:39 +00:00
|
|
|
# Screen display. On bottom of screen, with no auto-scroll.
|
|
|
|
var display = screen.window.new(nil, 30, 5, 0);
|
|
|
|
display.sticky = 0; # don't turn on; makes scrolling up messages jump left and right
|
|
|
|
|
2007-03-30 20:24:26 +00:00
|
|
|
# property nodes (to be initialized with listener)
|
|
|
|
var markerN = nil;
|
|
|
|
var headingN = nil;
|
|
|
|
var slipN = nil;
|
|
|
|
var time_elapsedN = nil;
|
|
|
|
var last_messageN = nil;
|
|
|
|
var step_countN = nil;
|
|
|
|
var step_timeN = nil;
|
|
|
|
|
2011-06-05 19:37:58 +00:00
|
|
|
_setlistener("/nasal/tutorial/loaded", func {
|
2007-03-30 20:24:26 +00:00
|
|
|
markerN = props.globals.getNode("/sim/model/marker", 1);
|
|
|
|
headingN = props.globals.getNode("/orientation/heading-deg", 1);
|
|
|
|
slipN = props.globals.getNode("/orientation/side-slip-deg", 1);
|
|
|
|
time_elapsedN = props.globals.getNode("/sim/time/elapsed-sec", 1);
|
|
|
|
last_messageN = props.globals.getNode("/sim/tutorials/last-message", 1);
|
|
|
|
step_countN = props.globals.getNode("/sim/tutorials/step-count", 1);
|
|
|
|
step_timeN = props.globals.getNode("/sim/tutorials/step-time", 1);
|
2007-10-15 21:55:23 +00:00
|
|
|
setlistener("/sim/crashed", stopTutorial);
|
2007-03-30 20:24:26 +00:00
|
|
|
});
|
|
|
|
|
2007-03-19 23:46:50 +00:00
|
|
|
var startTutorial = func {
|
2007-03-24 13:39:01 +00:00
|
|
|
var name = getprop("/sim/tutorials/current-tutorial");
|
2007-03-19 23:46:50 +00:00
|
|
|
if (name == nil) {
|
|
|
|
screen.log.write("No tutorial selected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-30 20:24:26 +00:00
|
|
|
tutorialN = nil;
|
2007-03-24 13:39:01 +00:00
|
|
|
foreach (var c; props.globals.getNode("/sim/tutorials").getChildren("tutorial")) {
|
2007-03-20 17:32:28 +00:00
|
|
|
if (c.getNode("name").getValue() == name) {
|
2007-03-30 20:24:26 +00:00
|
|
|
tutorialN = c;
|
2007-03-19 23:46:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-30 20:24:26 +00:00
|
|
|
if (tutorialN == nil) {
|
2007-03-19 23:46:50 +00:00
|
|
|
screen.log.write('Unable to find tutorial "' ~ name ~ '"');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-21 17:31:26 +00:00
|
|
|
stopTutorial();
|
|
|
|
screen.log.write('Loading tutorial "' ~ name ~ '" ...');
|
2007-03-22 17:08:05 +00:00
|
|
|
view.point.save();
|
2007-03-20 16:22:26 +00:00
|
|
|
init_nasal();
|
2007-03-22 17:08:05 +00:00
|
|
|
|
2007-03-30 20:24:26 +00:00
|
|
|
current_step = 0;
|
|
|
|
is_first_step = 1;
|
|
|
|
num_errors = 0;
|
|
|
|
last_step_time = time_elapsedN.getValue();
|
|
|
|
steps = tutorialN.getChildren("step");
|
2007-03-22 17:08:05 +00:00
|
|
|
|
2012-07-14 19:20:21 +00:00
|
|
|
step_interval = read_int(tutorialN, "step-time", 5); # time between tutorial steps
|
|
|
|
exit_interval = read_int(tutorialN, "exit-time", 1); # time between fulfillment of steps
|
2007-03-30 20:24:26 +00:00
|
|
|
run_nasal(tutorialN);
|
|
|
|
set_models(tutorialN.getNode("models"));
|
|
|
|
|
|
|
|
var dir = tutorialN.getNode("audio-dir");
|
|
|
|
if (dir != nil)
|
2014-01-01 23:17:39 +00:00
|
|
|
audio_dir = getprop("/sim/fg-root") ~ "/" ~ dir.getValue();
|
2007-03-30 20:24:26 +00:00
|
|
|
else
|
2007-03-19 23:46:50 +00:00
|
|
|
audio_dir = "";
|
|
|
|
|
2007-03-30 20:24:26 +00:00
|
|
|
var presets = tutorialN.getChild("presets");
|
2007-03-19 23:46:50 +00:00
|
|
|
if (presets != nil) {
|
|
|
|
props.copy(presets, props.globals.getNode("/sim/presets"));
|
2007-11-20 17:02:13 +00:00
|
|
|
fgcommand("presets-commit");
|
2007-03-19 23:46:50 +00:00
|
|
|
|
|
|
|
if (getprop("/sim/presets/on-ground")) {
|
|
|
|
var eng = props.globals.getNode("/controls/engines");
|
|
|
|
if (eng != nil) {
|
|
|
|
foreach (var c; eng.getChildren("engine")) {
|
|
|
|
c.getNode("magnetos", 1).setIntValue(3);
|
|
|
|
c.getNode("throttle", 1).setDoubleValue(0.5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-30 20:24:26 +00:00
|
|
|
var timeofday = tutorialN.getChild("timeofday");
|
|
|
|
if (timeofday != nil)
|
2007-03-21 17:31:26 +00:00
|
|
|
fgcommand("timeofday", props.Node.new({ "timeofday" : timeofday.getValue() }));
|
2007-03-19 23:46:50 +00:00
|
|
|
|
2007-03-30 20:24:26 +00:00
|
|
|
# <init>
|
|
|
|
do_group(tutorialN.getNode("init"));
|
2007-03-24 13:39:01 +00:00
|
|
|
is_running(1); # needs to be after "presets-commit"
|
2014-01-12 19:52:30 +00:00
|
|
|
display.clear();
|
2014-01-01 23:17:39 +00:00
|
|
|
display.show();
|
2007-03-24 13:39:01 +00:00
|
|
|
|
2007-03-19 23:46:50 +00:00
|
|
|
# Pick up any weather conditions/scenarios set
|
|
|
|
setprop("/environment/rebuild-layers", getprop("/environment/rebuild-layers") + 1);
|
2007-03-30 20:24:26 +00:00
|
|
|
settimer(func { step_tutorial(loop_id += 1) }, step_interval);
|
2007-03-19 23:46:50 +00:00
|
|
|
}
|
2006-02-22 17:03:42 +00:00
|
|
|
|
|
|
|
|
2007-03-20 16:22:26 +00:00
|
|
|
|
2007-03-19 23:46:50 +00:00
|
|
|
var stopTutorial = func {
|
2007-03-21 17:31:26 +00:00
|
|
|
loop_id += 1;
|
2007-03-22 17:08:05 +00:00
|
|
|
if (is_running()) {
|
2007-03-30 20:24:26 +00:00
|
|
|
var end = tutorialN.getNode("end");
|
2007-03-22 17:08:05 +00:00
|
|
|
set_properties(end);
|
|
|
|
run_nasal(end);
|
2007-03-30 20:24:26 +00:00
|
|
|
set_view(end) or view.point.restore();
|
2014-01-12 19:52:30 +00:00
|
|
|
say("Tutorial finished.");
|
2014-01-01 23:17:39 +00:00
|
|
|
settimer(func() { if (!is_running()) { display.close(); } }, 10);
|
2007-03-22 17:08:05 +00:00
|
|
|
}
|
|
|
|
set_marker();
|
2007-03-19 23:46:50 +00:00
|
|
|
is_running(0);
|
2006-02-22 17:03:42 +00:00
|
|
|
}
|
|
|
|
|
2007-03-21 17:31:26 +00:00
|
|
|
|
2006-02-22 17:03:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
# - Gets the current step node from the tutorial
|
|
|
|
# - If this is the first time the step is entered, it displays the instruction message
|
|
|
|
# - Otherwise, it
|
|
|
|
# - Checks if the exit conditions have been met. If so, it increments the step counter.
|
|
|
|
# - Checks for any error conditions, in which case it displays a message to the screen and
|
|
|
|
# increments an error counter
|
|
|
|
# - Otherwise display the instructions for the step.
|
|
|
|
#
|
2007-03-24 20:56:40 +00:00
|
|
|
var step_tutorial = func(id) {
|
2012-07-14 19:20:21 +00:00
|
|
|
|
|
|
|
# Check to ensure that this is the currently running tutorial.
|
2007-03-21 17:31:26 +00:00
|
|
|
id == loop_id or return;
|
2014-01-01 23:17:39 +00:00
|
|
|
|
2012-07-14 19:20:21 +00:00
|
|
|
var continue_after = func(n, w) {
|
|
|
|
settimer(func { step_tutorial(id) }, w);
|
2007-03-30 20:24:26 +00:00
|
|
|
}
|
2007-03-19 23:46:50 +00:00
|
|
|
|
2007-03-30 20:24:26 +00:00
|
|
|
# <end>
|
2007-03-21 17:31:26 +00:00
|
|
|
if (current_step >= size(steps)) {
|
2007-03-30 20:24:26 +00:00
|
|
|
var end = tutorialN.getNode("end");
|
2007-03-21 17:31:26 +00:00
|
|
|
stopTutorial();
|
2007-03-19 23:46:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-21 17:31:26 +00:00
|
|
|
var step = steps[current_step];
|
2007-03-22 17:08:05 +00:00
|
|
|
set_marker(step);
|
2007-03-30 20:24:26 +00:00
|
|
|
set_targets(tutorialN.getNode("targets"));
|
2007-03-19 23:46:50 +00:00
|
|
|
|
2007-03-30 20:24:26 +00:00
|
|
|
# <step>
|
|
|
|
if (is_first_step) {
|
|
|
|
is_first_step = 0;
|
|
|
|
step_start_time = time_elapsedN.getValue();
|
|
|
|
step_timeN.setDoubleValue(0);
|
|
|
|
step_countN.setIntValue(step_iter_count = 0);
|
2007-03-19 23:46:50 +00:00
|
|
|
|
2007-03-30 20:24:26 +00:00
|
|
|
do_group(step, "Tutorial step " ~ current_step);
|
2014-01-01 23:17:39 +00:00
|
|
|
|
2012-07-14 19:20:21 +00:00
|
|
|
# A <wait> tag affects only the initial entry to the step
|
|
|
|
var w = read_int(step, "wait", step_interval);
|
|
|
|
return continue_after(step, w);
|
2007-03-30 20:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
step_countN.setIntValue(step_iter_count += 1);
|
|
|
|
step_timeN.setDoubleValue(time_elapsedN.getValue() - step_start_time);
|
|
|
|
|
|
|
|
# <abort>
|
|
|
|
var abort = step.getNode("abort");
|
|
|
|
if (abort != nil) {
|
|
|
|
if (props.condition(abort.getNode("condition"))) {
|
|
|
|
do_group(abort);
|
|
|
|
current_step += 1;
|
|
|
|
is_first_step = 1;
|
|
|
|
return continue_after(abort, exit_interval);
|
|
|
|
}
|
2007-03-19 23:46:50 +00:00
|
|
|
}
|
|
|
|
|
2007-03-30 20:24:26 +00:00
|
|
|
# <error>
|
2007-03-21 17:31:26 +00:00
|
|
|
foreach (var error; shuffle(step.getChildren("error"))) {
|
|
|
|
if (props.condition(error.getNode("condition"))) {
|
2007-03-19 23:46:50 +00:00
|
|
|
num_errors += 1;
|
2007-03-30 20:24:26 +00:00
|
|
|
do_group(error);
|
|
|
|
return continue_after(error, step_interval);
|
2007-03-19 23:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-30 20:24:26 +00:00
|
|
|
# <exit>
|
2007-03-21 17:31:26 +00:00
|
|
|
var exit = step.getNode("exit");
|
|
|
|
if (exit != nil) {
|
2007-03-30 20:24:26 +00:00
|
|
|
if (!props.condition(exit.getNode("condition")))
|
2011-06-02 17:11:05 +00:00
|
|
|
{
|
|
|
|
if (time_elapsedN.getValue() - step_start_time > 15.0)
|
|
|
|
{
|
|
|
|
# What's going on? Repeat last message.
|
|
|
|
last_messageN.setValue("");
|
2011-06-04 10:18:11 +00:00
|
|
|
step_start_time = time_elapsedN.getValue();
|
|
|
|
do_group(step, "Tutorial step " ~ current_step);
|
2011-06-02 17:11:05 +00:00
|
|
|
}
|
2012-07-14 19:27:31 +00:00
|
|
|
return continue_after(exit, step_interval);
|
2011-06-02 17:11:05 +00:00
|
|
|
}
|
2007-03-30 20:24:26 +00:00
|
|
|
|
|
|
|
do_group(exit);
|
2007-03-19 23:46:50 +00:00
|
|
|
}
|
|
|
|
|
2007-03-21 17:31:26 +00:00
|
|
|
# success!
|
2007-03-21 00:21:51 +00:00
|
|
|
current_step += 1;
|
2007-03-30 20:24:26 +00:00
|
|
|
is_first_step = 1;
|
|
|
|
return continue_after(tutorialN, exit_interval);
|
2006-02-22 17:03:42 +00:00
|
|
|
}
|
|
|
|
|
2007-03-19 23:46:50 +00:00
|
|
|
|
2007-03-30 20:24:26 +00:00
|
|
|
##
|
|
|
|
# Do the stuff that's shared by <init>, <step>, <error>, <exit>, and <abort>.
|
|
|
|
# <end> doesn't use it.
|
|
|
|
#
|
|
|
|
var do_group = func(node, default_msg = nil) {
|
|
|
|
say_message(node, default_msg);
|
|
|
|
set_view(node);
|
|
|
|
set_properties(node);
|
|
|
|
run_nasal(node);
|
|
|
|
}
|
|
|
|
|
2012-07-14 19:20:21 +00:00
|
|
|
var read_int = func(node, child, default) {
|
2007-03-30 20:24:26 +00:00
|
|
|
var c = node.getNode(child);
|
|
|
|
if (c == nil)
|
|
|
|
return default;
|
2012-07-14 19:20:21 +00:00
|
|
|
c = int(c.getValue());
|
2007-03-30 20:24:26 +00:00
|
|
|
return c != nil ? c : default;
|
2007-03-24 13:39:01 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 16:22:26 +00:00
|
|
|
|
2007-03-30 20:24:26 +00:00
|
|
|
##
|
2007-03-22 17:08:05 +00:00
|
|
|
# scan all <set> blocks and set their <property> to <value> or
|
|
|
|
# the value of a property that <property n="1"> points to
|
2006-02-22 17:03:42 +00:00
|
|
|
# <set>
|
2007-03-19 23:46:50 +00:00
|
|
|
# <property>/foo/bar</property>
|
|
|
|
# <value>woof</value>
|
2006-02-22 17:03:42 +00:00
|
|
|
# </set>
|
|
|
|
#
|
2007-03-19 23:46:50 +00:00
|
|
|
var set_properties = func(node) {
|
|
|
|
node != nil or return;
|
|
|
|
foreach (var c; node.getChildren("set")) {
|
2007-03-22 17:08:05 +00:00
|
|
|
var dest = c.getChild("property", 0);
|
|
|
|
var src = c.getChild("property", 1);
|
|
|
|
var val = c.getChild("value");
|
|
|
|
|
|
|
|
dest != nil or die("<set> without <property>");
|
|
|
|
if (val != nil) {
|
|
|
|
setprop(dest.getValue(), val.getValue());
|
|
|
|
} elsif (src != nil) {
|
|
|
|
src = getprop(src.getValue());
|
|
|
|
src != nil or die("<property n=\"1\"> doesn't refer to defined property");
|
|
|
|
setprop(dest.getValue(), src);
|
|
|
|
} else {
|
|
|
|
die("<set> without <value> or <property n=\"1\">");
|
2007-03-19 23:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-22 17:03:42 +00:00
|
|
|
}
|
|
|
|
|
2007-03-19 23:46:50 +00:00
|
|
|
|
2007-03-30 20:24:26 +00:00
|
|
|
##
|
|
|
|
# For each <target><*><longitude-deg|latitude-deg> calculate and update
|
|
|
|
# /sim/tutorials/targets/*/...
|
|
|
|
# heading-deg ... absolute heading to target (0 -> North)
|
|
|
|
# direction-deg ... relative angle to target (0 -> ahead, 90 -> to the right)
|
|
|
|
# distance-m ... distance in meters
|
|
|
|
# eta-min ... estimated time of arrival (assuming aircraft flies in
|
|
|
|
# in current speed towards target)
|
|
|
|
#
|
2007-03-21 00:21:51 +00:00
|
|
|
var set_targets = func(node) {
|
|
|
|
node != nil or return;
|
|
|
|
|
2007-03-30 20:24:26 +00:00
|
|
|
var time = time_elapsedN.getValue();
|
2007-03-24 13:39:01 +00:00
|
|
|
var dest = props.globals.getNode("/sim/tutorials/targets", 1);
|
2007-03-21 00:21:51 +00:00
|
|
|
var aircraft = geo.aircraft_position();
|
2007-03-30 20:24:26 +00:00
|
|
|
var hdg = headingN.getValue() + slipN.getValue();
|
2007-03-22 22:10:55 +00:00
|
|
|
|
2007-03-22 17:08:05 +00:00
|
|
|
foreach (var t; node.getChildren()) {
|
2007-03-21 00:21:51 +00:00
|
|
|
var lon = t.getNode("longitude-deg");
|
|
|
|
var lat = t.getNode("latitude-deg");
|
2007-03-30 20:24:26 +00:00
|
|
|
if (lon == nil or lat == nil)
|
2007-03-22 22:10:55 +00:00
|
|
|
die("target coords undefined");
|
2007-03-30 20:24:26 +00:00
|
|
|
|
2009-01-15 00:39:51 +00:00
|
|
|
var target = geo.Coord.new().set_latlon(lat.getValue(), lon.getValue());
|
2007-03-22 22:10:55 +00:00
|
|
|
var dist = aircraft.distance_to(target);
|
2007-03-23 10:58:15 +00:00
|
|
|
var course = aircraft.course_to(target);
|
|
|
|
var angle = geo.normdeg(course - hdg);
|
2007-03-30 20:24:26 +00:00
|
|
|
if (angle >= 180)
|
2007-03-21 00:21:51 +00:00
|
|
|
angle -= 360;
|
|
|
|
|
2007-03-22 17:08:05 +00:00
|
|
|
var d = dest.getChild(t.getName(), t.getIndex(), 1);
|
2007-03-23 10:58:15 +00:00
|
|
|
d.getNode("heading-deg", 1).setDoubleValue(course);
|
2007-03-21 00:21:51 +00:00
|
|
|
d.getNode("direction-deg", 1).setDoubleValue(angle);
|
2007-03-22 22:10:55 +00:00
|
|
|
var distN = d.getNode("distance-m", 1);
|
|
|
|
var lastdist = distN.getValue();
|
|
|
|
distN.setDoubleValue(dist);
|
|
|
|
if (lastdist != nil) {
|
2007-03-30 20:24:26 +00:00
|
|
|
var speed = (lastdist - dist) / (time - last_step_time) + 0.00001; # m/s
|
2007-03-22 22:10:55 +00:00
|
|
|
d.getNode("eta-min", 1).setDoubleValue(dist / (speed * 60));
|
|
|
|
}
|
2007-03-21 00:21:51 +00:00
|
|
|
}
|
2007-03-30 20:24:26 +00:00
|
|
|
last_step_time = time;
|
2007-03-21 00:21:51 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 16:22:26 +00:00
|
|
|
|
2007-03-20 17:32:28 +00:00
|
|
|
var models = [];
|
|
|
|
var set_models = func(node) {
|
|
|
|
node != nil or return;
|
2007-03-21 00:21:51 +00:00
|
|
|
|
2007-03-20 17:32:28 +00:00
|
|
|
var manager = props.globals.getNode("/models", 1);
|
|
|
|
foreach (var src; node.getChildren("model")) {
|
|
|
|
var i = 0;
|
2007-03-30 20:24:26 +00:00
|
|
|
for (; 1; i += 1)
|
|
|
|
if (manager.getChild("model", i, 0) == nil)
|
2007-03-20 17:32:28 +00:00
|
|
|
break;
|
2007-03-30 20:24:26 +00:00
|
|
|
|
2007-03-20 17:32:28 +00:00
|
|
|
var dest = manager.getChild("model", i, 1);
|
|
|
|
props.copy(src, dest);
|
2007-03-21 00:21:51 +00:00
|
|
|
dest.getNode("load", 1); # makes the modelmgr load the model
|
2007-03-20 17:32:28 +00:00
|
|
|
dest.removeChildren("load");
|
|
|
|
append(models, dest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var remove_models = func {
|
2007-03-30 20:24:26 +00:00
|
|
|
foreach (var m; models)
|
2007-03-20 17:32:28 +00:00
|
|
|
m.getParent().removeChild(m.getName(), m.getIndex());
|
2007-03-30 20:24:26 +00:00
|
|
|
|
2007-03-20 17:32:28 +00:00
|
|
|
models = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-21 17:31:26 +00:00
|
|
|
var set_view = func(node = nil) {
|
|
|
|
node != nil or return;
|
2007-03-22 17:08:05 +00:00
|
|
|
var v = node.getChild("view");
|
|
|
|
if (v != nil) {
|
2011-06-02 22:39:05 +00:00
|
|
|
# when changing view direction, switch to view 0 (captain's view),
|
|
|
|
# unless another view is explicitly specified
|
|
|
|
v.initNode("view-number", 0, "INT", 0);
|
2007-03-22 17:08:05 +00:00
|
|
|
view.point.move(v);
|
|
|
|
return 1;
|
2007-03-21 17:31:26 +00:00
|
|
|
}
|
2007-03-22 17:08:05 +00:00
|
|
|
return 0;
|
2007-03-21 17:31:26 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 17:32:28 +00:00
|
|
|
|
2007-03-22 17:08:05 +00:00
|
|
|
var set_marker = func(node = nil) {
|
2007-03-23 10:58:15 +00:00
|
|
|
if (node != nil) {
|
|
|
|
var loc = node.getNode("marker");
|
|
|
|
if (loc != nil) {
|
|
|
|
var s = loc.getNode("scale");
|
2007-03-30 20:24:26 +00:00
|
|
|
markerN.setValues({
|
2007-03-24 18:10:33 +00:00
|
|
|
"x/value": loc.getNode("x-m", 1).getValue(),
|
|
|
|
"y/value": loc.getNode("y-m", 1).getValue(),
|
|
|
|
"z/value": loc.getNode("z-m", 1).getValue(),
|
2007-03-23 10:58:15 +00:00
|
|
|
"scale/value": s != nil ? s.getValue() : 1,
|
|
|
|
"arrow-enabled": 1,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2007-03-19 23:46:50 +00:00
|
|
|
}
|
2007-03-30 20:24:26 +00:00
|
|
|
markerN.getNode("arrow-enabled", 1).setBoolValue(0);
|
2006-02-22 17:03:42 +00:00
|
|
|
}
|
|
|
|
|
2007-03-19 23:46:50 +00:00
|
|
|
|
2006-02-24 11:03:22 +00:00
|
|
|
# Set and return running state. Disable/enable stop menu.
|
|
|
|
#
|
2007-03-19 23:46:50 +00:00
|
|
|
var is_running = func(which = nil) {
|
2007-03-24 13:39:01 +00:00
|
|
|
var prop = "/sim/tutorials/running";
|
2007-03-19 23:46:50 +00:00
|
|
|
if (which != nil) {
|
|
|
|
setprop(prop, which);
|
|
|
|
}
|
|
|
|
return getprop(prop);
|
2006-02-24 11:03:22 +00:00
|
|
|
}
|
|
|
|
|
2007-03-19 23:46:50 +00:00
|
|
|
|
2006-02-22 17:03:42 +00:00
|
|
|
# Output the message and optional sound recording.
|
|
|
|
#
|
2007-03-20 16:22:26 +00:00
|
|
|
var lastmsgcount = 0;
|
2007-03-21 00:21:51 +00:00
|
|
|
var say_message = func(node, default = nil) {
|
|
|
|
var msg = default;
|
|
|
|
var audio = nil;
|
|
|
|
|
|
|
|
if (node != nil) {
|
|
|
|
|
|
|
|
var m = node.getChildren("message");
|
2007-03-30 20:24:26 +00:00
|
|
|
if (size(m))
|
2007-03-21 00:21:51 +00:00
|
|
|
msg = m[rand() * size(m)].getValue();
|
|
|
|
|
|
|
|
var a = node.getChildren("audio");
|
2007-03-30 20:24:26 +00:00
|
|
|
if (size(a))
|
2007-03-21 17:31:26 +00:00
|
|
|
audio = a[rand() * size(a)].getValue();
|
2007-03-21 00:21:51 +00:00
|
|
|
}
|
|
|
|
|
2014-01-01 23:17:39 +00:00
|
|
|
if (msg != last_messageN.getValue()) {
|
|
|
|
# Messages are only displayed if they change
|
2007-03-21 00:21:51 +00:00
|
|
|
if (audio != nil) {
|
2014-01-01 23:17:39 +00:00
|
|
|
var prop = { path : audio_dir, file : audio, volume : 1.0 };
|
2007-05-15 14:40:58 +00:00
|
|
|
fgcommand("play-audio-sample", props.Node.new(prop));
|
2007-03-19 23:46:50 +00:00
|
|
|
}
|
|
|
|
|
2014-01-01 23:17:39 +00:00
|
|
|
if (msg != nil) {
|
|
|
|
display.write(msg, 1, 1, 1);
|
2007-03-30 20:24:26 +00:00
|
|
|
last_messageN.setValue(msg);
|
2014-01-01 23:17:39 +00:00
|
|
|
}
|
2007-03-19 23:46:50 +00:00
|
|
|
}
|
2006-02-22 17:03:42 +00:00
|
|
|
}
|
2007-03-19 23:46:50 +00:00
|
|
|
|
|
|
|
|
2007-03-21 17:31:26 +00:00
|
|
|
var shuffle = func(vec) {
|
|
|
|
var s = size(vec);
|
|
|
|
forindex (var i; vec) {
|
|
|
|
var j = rand() * s;
|
2007-03-24 13:39:01 +00:00
|
|
|
if (i != j) {
|
|
|
|
var swap = vec[j];
|
|
|
|
vec[j] = vec[i];
|
|
|
|
vec[i] = swap;
|
|
|
|
}
|
2007-03-21 17:31:26 +00:00
|
|
|
}
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
2007-03-20 16:22:26 +00:00
|
|
|
|
2007-03-19 23:46:50 +00:00
|
|
|
var run_nasal = func(node) {
|
|
|
|
node != nil or return;
|
|
|
|
foreach (var n; node.getChildren("nasal")) {
|
2007-03-30 20:24:26 +00:00
|
|
|
if (n.getNode("module") == nil)
|
2007-03-20 16:22:26 +00:00
|
|
|
n.getNode("module", 1).setValue("__tutorial");
|
2007-03-30 20:24:26 +00:00
|
|
|
|
2007-03-19 23:46:50 +00:00
|
|
|
fgcommand("nasal", n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-21 17:31:26 +00:00
|
|
|
var say = func(what, who = "copilot", delay = 0) {
|
2014-01-01 23:17:39 +00:00
|
|
|
settimer(func { display.write(what, 1, 1, 1) }, delay);
|
2007-03-21 17:31:26 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 16:22:26 +00:00
|
|
|
|
2007-03-21 17:31:26 +00:00
|
|
|
# Set up namespace "__tutorial" for embedded Nasal.
|
2007-03-20 16:22:26 +00:00
|
|
|
#
|
|
|
|
var init_nasal = func {
|
|
|
|
globals.__tutorial = {
|
2007-06-22 18:49:38 +00:00
|
|
|
say : say, # just exporting tutorial.say as __tutorial.say
|
2007-03-30 20:24:26 +00:00
|
|
|
next : func(n = 1) { current_step += n; is_first_step = 1; },
|
2007-03-21 17:31:26 +00:00
|
|
|
previous : func(n = 1) {
|
|
|
|
current_step -= n;
|
2007-03-30 20:24:26 +00:00
|
|
|
is_first_step = 1;
|
|
|
|
if (current_step < 0)
|
2007-03-21 17:31:26 +00:00
|
|
|
current_step = 0;
|
2007-03-20 16:22:26 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var dialog = func {
|
|
|
|
fgcommand("dialog-show", props.Node.new({ "dialog-name" : "marker-adjust" }));
|
|
|
|
}
|
2007-03-19 23:46:50 +00:00
|
|
|
|
|
|
|
|
2007-03-24 23:28:41 +00:00
|
|
|
##
|
|
|
|
# Tutorial loader for development purposes.
|
|
|
|
# Usage: tutorial.load("Aircraft/bo105/Tutorials/foo.xml", 1)
|
|
|
|
# Loads this file to tutorial slot #1 (/sim/tutorials/tutorial[1])
|
|
|
|
#
|
|
|
|
var load = func(file, index = 0) {
|
|
|
|
props.globals.getNode("/sim/tutorials", 1).removeChild("tutorial", index);
|
2010-08-15 10:27:15 +00:00
|
|
|
io.read_properties(file, "/sim/tutorials/tutorial[" ~ index ~ "]/");
|
2007-03-24 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|