From 252501a0cae17e30220904df1ee62f7190a06161 Mon Sep 17 00:00:00 2001 From: Jonathan Redpath Date: Mon, 16 May 2022 21:09:36 +0100 Subject: [PATCH] Flightplan stringing: if the last waypoint of a SID is found en-route, then we delete all preceeding points according to the manual --- Nasal/FMGC/flightplan-delegates.nas | 21 ++++++++++++++++++++- Nasal/FMGC/flightplan.nas | 7 +++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Nasal/FMGC/flightplan-delegates.nas b/Nasal/FMGC/flightplan-delegates.nas index 4938c00b..fff9b3d5 100644 --- a/Nasal/FMGC/flightplan-delegates.nas +++ b/Nasal/FMGC/flightplan-delegates.nas @@ -55,7 +55,26 @@ var A320RouteManagerDelegate = { # and we have a SID var sid = me.flightplan.sid; logprint(LOG_INFO, 'routing via SID ' ~ sid.id); - me.flightplan.insertWaypoints(sid.route(me.flightplan.departure_runway, me.flightplan.sid_trans), 1); + + var wps = sid.route(me.flightplan.departure_runway, me.flightplan.sid_trans); + var lastWP = wps[-1]; + var foundIdx = -999; + + for (var wptIdx = 0; wptIdx < me.flightplan.getPlanSize(); wptIdx = wptIdx + 1) { + if (me.flightplan.getWP(wptIdx).id == lastWP.id) { + foundIdx = wptIdx; + break; + } + } + + if (foundIdx != -999) { + while (foundIdx > 0) { + me.flightplan.deleteWP(1); + foundIdx -= 1; + } + } + + me.flightplan.insertWaypoints(wps, 1); for (var wpIdx = 0; wpIdx < me.flightplan.getPlanSize(); wpIdx = wpIdx + 1) { if (me.flightplan.getWP(wpIdx).wp_type == "vectors" and (me.flightplan.getWP(wpIdx + 1) == nil or me.flightplan.getWP(wpIdx + 1).wp_type != "discontinuity")) { diff --git a/Nasal/FMGC/flightplan.nas b/Nasal/FMGC/flightplan.nas index f8d39444..da218879 100644 --- a/Nasal/FMGC/flightplan.nas +++ b/Nasal/FMGC/flightplan.nas @@ -403,17 +403,16 @@ var flightPlanController = { deleteWP: func(index, n, a = 0) { # a = 1, means adding a waypoint via deleting intermediate var wp = me.flightplans[n].getWP(index); if ((left(wp.wp_name, 4) != FMGCInternal.depApt and left(wp.wp_name, 4) != FMGCInternal.arrApt) and me.flightplans[n].getPlanSize() > 2) { - - if (me.flightplans[n].getWP(index).id != "DISCONTINUITY" and a == 0) { # if it is a discont, don't make a new one + if (wp.id != "DISCONTINUITY" and a == 0) { # if it is a discont, don't make a new one me.flightplans[n].deleteWP(index); fmgc.windController.deleteWind(n, index); - if (me.flightplans[n].getWP(index) != nil) { + if (me.flightplans[n].getWP(index) != nil) { # This refers to the next one after the one we deleted if (me.flightplans[n].getWP(index).id != "DISCONTINUITY") { # else, if the next one isn't a discont, add one me.addDiscontinuity(index, n); } } } else { - if (me.flightplans[n].getWP(index).id == "DISCONTINUITY" and index > 0 and (me.flightplans[n].getWP(index - 1).id == "PPOS" or find(me.flightplans[n].getWP(index - 1).id, "VECTORS"))) { + if (wp.id == "DISCONTINUITY" and index > 0 and (me.flightplans[n].getWP(index - 1).id == "PPOS" or find("VECTORS", me.flightplans[n].getWP(index - 1).id) != -1)) { return 1; } else { me.flightplans[n].deleteWP(index);