From 6c3853fd0d70d8e5d4f3e05f6c79cb5382219bc5 Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 31 Dec 2012 11:46:36 +0000 Subject: [PATCH] Expose an additional flight plan leg data to Nasal. --- src/Scripting/NasalPositioned.cxx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Scripting/NasalPositioned.cxx b/src/Scripting/NasalPositioned.cxx index 66bfb5826..252342516 100644 --- a/src/Scripting/NasalPositioned.cxx +++ b/src/Scripting/NasalPositioned.cxx @@ -2204,6 +2204,26 @@ static naRef f_leg_path(naContext c, naRef me, int argc, naRef* args) return result; } +static naRef f_leg_courseAndDistanceFrom(naContext c, naRef me, int argc, naRef* args) +{ + FlightPlan::Leg* leg = fpLegGhost(me); + if (!leg) { + naRuntimeError(c, "leg.courseAndDistanceFrom called on non-flightplan-leg object"); + } + + SGGeod pos; + geodFromArgs(args, 0, argc, pos); + + double courseDeg; + double distanceM; + boost::tie(courseDeg, distanceM) = leg->waypoint()->courseAndDistanceFrom(pos); + + naRef result = naNewVector(c); + naVec_append(result, naNum(courseDeg)); + naVec_append(result, naNum(distanceM * SG_METER_TO_NM)); + return result; +} + static naRef f_waypoint_navaid(naContext c, naRef me, int argc, naRef* args) { flightgear::Waypt* w = wayptGhost(me); @@ -2409,6 +2429,7 @@ naRef initNasalPositioned(naRef globals, naContext c, naRef gcSave) hashset(c, fpLegPrototype, "setSpeed", naNewFunc(c, naNewCCode(c, f_leg_setSpeed))); hashset(c, fpLegPrototype, "setAltitude", naNewFunc(c, naNewCCode(c, f_leg_setAltitude))); hashset(c, fpLegPrototype, "path", naNewFunc(c, naNewCCode(c, f_leg_path))); + hashset(c, fpLegPrototype, "courseAndDistanceFrom", naNewFunc(c, naNewCCode(c, f_leg_courseAndDistanceFrom))); for(int i=0; funcs[i].name; i++) { hashset(c, globals, funcs[i].name,