2017-10-10 14:25:37 +08:00
|
|
|
|
|
|
|
var mission_objects = [];
|
|
|
|
var mission_started = 0;
|
|
|
|
var mission_node = props.getNode("/sim/mission/data", 1);
|
|
|
|
var mission_root = "";
|
|
|
|
|
|
|
|
var hasmember = view.hasmember;
|
|
|
|
|
2017-10-22 07:25:52 +08:00
|
|
|
var preferences_load = func() {
|
2017-10-20 05:24:56 +08:00
|
|
|
foreach (var a; directory(mission_root)) {
|
|
|
|
if (a == "preferences.xml") {
|
|
|
|
io.read_properties(mission_root ~ "/preferences.xml", props.getNode(""));
|
|
|
|
break;
|
2017-10-10 15:35:13 +08:00
|
|
|
}
|
|
|
|
}
|
2017-10-10 14:25:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var start_mission = func(name) {
|
2017-10-20 05:24:56 +08:00
|
|
|
if (mission_started) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-10 14:25:37 +08:00
|
|
|
|
2017-10-20 05:24:56 +08:00
|
|
|
# FIXME - FIX ResourceLoader in FG Source
|
2017-10-10 15:35:13 +08:00
|
|
|
mission_root = resolvepath("/Aircraft/Missions/" ~ name);
|
|
|
|
if (mission_root == "") {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-22 07:25:52 +08:00
|
|
|
# save mission root for repositioning (will reset addon)
|
|
|
|
setprop("/sim/mission/current_mission/path", mission_root);
|
2017-10-10 14:25:37 +08:00
|
|
|
|
|
|
|
mission_node.removeAllChildren();
|
|
|
|
io.read_properties(mission_root ~ "/mission.xml", mission_node);
|
|
|
|
|
2017-10-22 07:25:52 +08:00
|
|
|
# set flightgear main state (location, weather)
|
2017-10-10 14:25:37 +08:00
|
|
|
var presets = mission_node.getChild("presets");
|
2017-10-22 07:25:52 +08:00
|
|
|
if (presets != nil) {
|
|
|
|
props.copy(presets, props.getNode("/sim/presets"));
|
|
|
|
fgcommand("reposition");
|
|
|
|
}
|
2017-10-10 14:25:37 +08:00
|
|
|
|
|
|
|
var timeofday = mission_node.getChild("timeofday");
|
2017-10-10 15:35:13 +08:00
|
|
|
if (timeofday != nil) {
|
2017-10-10 14:25:37 +08:00
|
|
|
fgcommand("timeofday", props.Node.new({ "timeofday" : timeofday.getValue() }));
|
2017-10-10 15:35:13 +08:00
|
|
|
}
|
2017-10-10 14:25:37 +08:00
|
|
|
|
2017-10-22 07:25:52 +08:00
|
|
|
# wait for simulator restart & proceed
|
2017-10-10 14:25:37 +08:00
|
|
|
settimer (func _start_mission(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
var _start_mission = func {
|
2017-10-22 07:25:52 +08:00
|
|
|
# wait for splash screen closing
|
2017-10-10 14:25:37 +08:00
|
|
|
if (splash_screen()) {
|
|
|
|
settimer(func _start_mission(), 2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-22 07:25:52 +08:00
|
|
|
# reload data
|
|
|
|
mission_root = getprop("/sim/mission/current_mission/path");
|
|
|
|
print("mission root: " ~ mission_root);
|
2017-10-10 14:25:37 +08:00
|
|
|
|
2017-10-22 07:25:52 +08:00
|
|
|
mission_node.removeAllChildren();
|
|
|
|
io.read_properties(mission_root ~ "/mission.xml", mission_node);
|
2017-10-10 14:25:37 +08:00
|
|
|
|
2017-10-22 07:25:52 +08:00
|
|
|
preferences_load();
|
|
|
|
extensions_load();
|
|
|
|
extensions_models_init();
|
2017-10-10 14:25:37 +08:00
|
|
|
|
|
|
|
mission_started = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
var stop_mission = func {
|
2017-10-20 05:24:56 +08:00
|
|
|
if (!mission_started) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-10 14:25:37 +08:00
|
|
|
|
2017-10-20 05:24:56 +08:00
|
|
|
foreach(var obj; mission_objects) {
|
|
|
|
obj.del();
|
|
|
|
}
|
2017-10-10 14:25:37 +08:00
|
|
|
setsize(mission_objects, 0);
|
|
|
|
|
2017-10-22 07:25:52 +08:00
|
|
|
extensions_clear();
|
2017-10-10 14:25:37 +08:00
|
|
|
delete(globals, "__mission");
|
|
|
|
|
|
|
|
mission_started = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var activate_object = func(name, start = 1) {
|
2017-10-20 05:24:56 +08:00
|
|
|
if (name == nil) {
|
2017-10-10 14:25:37 +08:00
|
|
|
return;
|
2017-10-20 05:24:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach(var obj; mission_objects) {
|
2017-10-10 14:25:37 +08:00
|
|
|
if (obj.name == name) {
|
2017-10-20 05:24:56 +08:00
|
|
|
if (start) {
|
2017-10-10 14:25:37 +08:00
|
|
|
obj.start();
|
2017-10-20 05:24:56 +08:00
|
|
|
} else {
|
2017-10-10 14:25:37 +08:00
|
|
|
obj.stop();
|
2017-10-20 05:24:56 +08:00
|
|
|
}
|
2017-10-10 14:25:37 +08:00
|
|
|
}
|
2017-10-20 05:24:56 +08:00
|
|
|
}
|
2017-10-10 14:25:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var activate_object_group = func(group, start = 1) {
|
2017-10-20 06:52:35 +08:00
|
|
|
foreach(var ref; group.getChildren("object-reference")) {
|
2017-10-10 14:25:37 +08:00
|
|
|
activate_object(ref.getValue(), start);
|
2017-10-20 06:52:35 +08:00
|
|
|
}
|
2017-10-10 14:25:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var get_coord = func(n) {
|
|
|
|
geo.Coord.new().set_latlon (
|
|
|
|
var lat = n.getValue("latitude-deg") or 0,
|
|
|
|
var lon = n.getValue("longitude-deg") or 0,
|
|
|
|
(n.getValue("altitude-m") or 0) + (geo.elevation(lat, lon) or 0) * get(n, "altitude-is-AGL", 1)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var put_model = func(path, coord, heading = 0, pitch = 0, roll = 0) {
|
|
|
|
var models = props.getNode("/models");
|
|
|
|
var model = nil;
|
|
|
|
|
2017-10-20 05:24:56 +08:00
|
|
|
for (var i = 0; 1; i += 1) {
|
2017-10-10 14:25:37 +08:00
|
|
|
if (models.getChild("model", i, 0) == nil) {
|
|
|
|
model = models.getChild("model", i, 1);
|
|
|
|
break;
|
|
|
|
}
|
2017-10-20 05:24:56 +08:00
|
|
|
}
|
2017-10-10 14:25:37 +08:00
|
|
|
|
|
|
|
var model_path = model.getPath();
|
|
|
|
|
|
|
|
model.setValues({
|
|
|
|
"path" : path,
|
|
|
|
"latitude-deg" : coord.lat(),
|
|
|
|
"latitude-deg-prop" : model_path ~ "/latitude-deg",
|
|
|
|
"longitude-deg" : coord.lon(),
|
|
|
|
"longitude-deg-prop" : model_path ~ "/longitude-deg",
|
|
|
|
"elevation-ft" : coord.alt() * M2FT,
|
|
|
|
"elevation-ft-prop" : model_path ~ "/elevation-ft",
|
|
|
|
"heading-deg" : heading,
|
|
|
|
"heading-deg-prop" : model_path ~ "/heading-deg",
|
|
|
|
"pitch-deg" : pitch,
|
|
|
|
"pitch-deg-prop" : model_path ~ "/pitch-deg",
|
|
|
|
"roll-deg" : roll,
|
|
|
|
"roll-deg-prop" : model_path ~ "/roll-deg",
|
|
|
|
});
|
|
|
|
|
|
|
|
model.getNode("load", 1).remove();
|
|
|
|
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
|
|
|
var model = {
|
|
|
|
new: func (path, coord, heading = 0, pitch = 0, roll = 0) {
|
|
|
|
var m = {
|
|
|
|
parents: [model],
|
|
|
|
model: put_model(path, coord, heading, pitch, roll)
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
var get = func(node, path, default = nil) {
|
2017-10-20 05:24:56 +08:00
|
|
|
if ( (var value = node.getValue(path)) == nil) {
|
2017-10-10 14:25:37 +08:00
|
|
|
default;
|
2017-10-20 05:24:56 +08:00
|
|
|
} else {
|
|
|
|
value;
|
|
|
|
}
|
2017-10-10 14:25:37 +08:00
|
|
|
}
|
|
|
|
|
2017-10-20 06:52:35 +08:00
|
|
|
var file_found = func(filename) {
|
|
|
|
return call(io.readfile, [filename], nil, nil, var err=[]);
|
|
|
|
}
|
|
|
|
|
2017-10-10 14:25:37 +08:00
|
|
|
var play_sound = func (file) {
|
2017-10-20 06:52:35 +08:00
|
|
|
|
|
|
|
var filepath = mission_root ~ "/Sounds/";
|
|
|
|
if (!file_found(filepath ~ "/" ~ file)) {
|
|
|
|
filepath = getprop("/sim/mission/root_path") ~ "/Missions/Generic/Sounds";
|
|
|
|
}
|
|
|
|
|
2017-10-10 14:25:37 +08:00
|
|
|
var sound = {
|
2017-10-20 06:52:35 +08:00
|
|
|
path : filepath,
|
2017-10-10 14:25:37 +08:00
|
|
|
file : file,
|
|
|
|
volume : 1
|
|
|
|
};
|
|
|
|
fgcommand("play-audio-sample", props.Node.new(sound));
|
|
|
|
}
|
|
|
|
|
2017-10-20 06:52:35 +08:00
|
|
|
var speak = func (text) {
|
|
|
|
setprop("/sim/sound/voices/atc", text);
|
|
|
|
}
|
|
|
|
|
2017-10-10 15:35:13 +08:00
|
|
|
print("Mission loaded");
|