+static naRef f_flightplan_pathGeod(naContext c, naRef me, int argc, naRef* args)
+{
+ FlightPlan* fp = flightplanGhost(me);
+ if (!fp) {
+ naRuntimeError(c, "flightplan.clone called on non-flightplan object");
+ }
+
+ if ((argc < 1) || !naIsNum(args[0])) {
+ naRuntimeError(c, "bad argument to flightplan.pathGeod");
+ }
+
+ if ((argc > 1) && !naIsNum(args[1])) {
+ naRuntimeError(c, "bad argument to flightplan.pathGeod");
+ }
+
+ int index = (int) args[0].num;
+ double offset = (argc > 1) ? args[1].num : 0.0;
+ naRef result = naNewHash(c);
+ SGGeod g = fp->pointAlongRoute(index, offset);
+ hashset(c, result, "lat", naNum(g.getLatitudeDeg()));
+ hashset(c, result, "lon", naNum(g.getLongitudeDeg()));
+ return result;
+}
+
+static naRef f_flightplan_finish(naContext c, naRef me, int argc, naRef* args)
+{
+ FlightPlan* fp = flightplanGhost(me);
+ if (!fp) {
+ naRuntimeError(c, "flightplan.finish called on non-flightplan object");
+ }
+
+ fp->finish();
+ return naNil();
+}
+
+static naRef f_flightplan_indexOfWp(naContext c, naRef me, int argc, naRef* args)
+{
+ FlightPlan* fp = flightplanGhost(me);
+ if (!fp) {
+ naRuntimeError(c, "flightplan.indexOfWP called on non-flightplan object");
+ }
+
+ FGPositioned* positioned = positionedGhost(args[0]);
+ if (positioned) {
+ return naNum(fp->findWayptIndex(positioned));
+ }
+
+ SGGeod pos;
+ int argOffset = geodFromArgs(args, 0, argc, pos);
+ if (argOffset > 0) {
+ return naNum(fp->findWayptIndex(pos));
+ }
+
+ return naNum(-1);
+}
+