From df0fa8887104d07f4a7f800e7a80fcfe92605c43 Mon Sep 17 00:00:00 2001 From: legoboyvdlp R Date: Mon, 15 Jun 2020 16:29:05 +0100 Subject: [PATCH] Set constraints on FPLNt push --- Nasal/MCDU/F-PLN.nas | 92 ++++++++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 28 deletions(-) diff --git a/Nasal/MCDU/F-PLN.nas b/Nasal/MCDU/F-PLN.nas index f48a2af8..90adf249 100644 --- a/Nasal/MCDU/F-PLN.nas +++ b/Nasal/MCDU/F-PLN.nas @@ -156,33 +156,73 @@ var fplnItem = { setprop("MCDU[" ~ me.computer ~ "]/page", "LATREV"); }, pushButtonRight: func() { - if (canvas_mcdu.myVertRev[me.computer] != nil) { - canvas_mcdu.myVertRev[me.computer].del(); - } - canvas_mcdu.myVertRev[me.computer] = nil; - - if (fmgc.flightPlanController.temporaryFlag[me.computer]) { - if (me.index == fmgc.flightPlanController.arrivalIndex[me.computer]) { - canvas_mcdu.myVertRev[me.computer] = vertRev.new(1, left(me.wp.wp_name, 4), me.index, me.computer, me.wp, me.plan); - } elsif (left(me.wp.wp_name, 4) == fmgc.flightPlanController.flightplans[me.computer].departure.id) { - canvas_mcdu.myVertRev[me.computer] = vertRev.new(0, left(me.wp.wp_name, 4), me.index, me.computer, me.wp, me.plan); - } elsif (me.index == (fmgc.flightPlanController.currentToWptIndex.getValue() - 1)) { - canvas_mcdu.myVertRev[me.computer] = vertRev.new(3, me.wp.wp_name, me.index, me.computer, me.wp, me.plan); + if (size(mcdu_scratchpad.scratchpads[me.computer].scratchpad) == 0) { + if (canvas_mcdu.myVertRev[me.computer] != nil) { + canvas_mcdu.myVertRev[me.computer].del(); + } + canvas_mcdu.myVertRev[me.computer] = nil; + + if (fmgc.flightPlanController.temporaryFlag[me.computer]) { + if (me.index == fmgc.flightPlanController.arrivalIndex[me.computer]) { + canvas_mcdu.myVertRev[me.computer] = vertRev.new(1, left(me.wp.wp_name, 4), me.index, me.computer, me.wp, me.plan); + } if (left(me.wp.wp_name, 4) == fmgc.flightPlanController.flightplans[me.computer].departure.id) { + canvas_mcdu.myVertRev[me.computer] = vertRev.new(0, left(me.wp.wp_name, 4), me.index, me.computer, me.wp, me.plan); + } elsif (me.index == (fmgc.flightPlanController.currentToWptIndex.getValue() - 1)) { + canvas_mcdu.myVertRev[me.computer] = vertRev.new(3, me.wp.wp_name, me.index, me.computer, me.wp, me.plan); + } else { + canvas_mcdu.myVertRev[me.computer] = vertRev.new(2, me.wp.wp_name, me.index, me.computer, me.wp, me.plan); + } } else { - canvas_mcdu.myVertRev[me.computer] = vertRev.new(2, me.wp.wp_name, me.index, me.computer, me.wp, me.plan); + if (me.index == fmgc.flightPlanController.arrivalIndex[2]) { + canvas_mcdu.myVertRev[me.computer] = vertRev.new(1, left(me.wp.wp_name, 4), me.index, me.computer, me.wp, me.plan); + } elsif (left(me.wp.wp_name, 4) == fmgc.flightPlanController.flightplans[2].departure.id) { + canvas_mcdu.myVertRev[me.computer] = vertRev.new(0, left(me.wp.wp_name, 4), me.index, me.computer, me.wp, me.plan); + } elsif (me.index == (fmgc.flightPlanController.currentToWptIndex.getValue() - 1)) { + canvas_mcdu.myVertRev[me.computer] = vertRev.new(3, me.wp.wp_name, me.index, me.computer, me.wp, me.plan); + } else { + canvas_mcdu.myVertRev[me.computer] = vertRev.new(2, me.wp.wp_name, me.index, me.computer, me.wp, me.plan); + } + } + setprop("MCDU[" ~ me.computer ~ "]/page", "VERTREV"); + } elsif (me.index != 0) { # todo - only apply to climb, descent, or missed waypoints + var scratchpadStore = mcdu_scratchpad.scratchpads[me.computer].scratchpad; + + if (scratchpadStore == "CLR") { + me.wp.setSpeed("delete"); + me.wp.setAltitude("delete"); + mcdu_scratchpad.scratchpads[me.computer].empty(); + } elsif (find("/", scratchpadStore) != -1) { + var scratchpadSplit = split("/", scratchpadStore); + + if (size(scratchpadSplit[0]) == 0) { + if (num(scratchpadSplit[1]) != nil and (size(scratchpadSplit[1]) == 4 or size(scratchpadSplit[1]) == 5) and scratchpadSplit[1] >= 0 and scratchpadSplit[1] <= 39000) { + me.wp.setAltitude(math.round(scratchpadSplit[1], 10), "at"); + mcdu_scratchpad.scratchpads[me.computer].empty(); + } else { + mcdu_message(me.computer, "FORMAT ERROR"); + } + } else { + if (num(scratchpadSplit[0]) != nil and size(scratchpadSplit[0]) == 3 and scratchpadSplit[0] >= 100 and scratchpadSplit[0] <= 350 and + num(scratchpadSplit[1]) != nil and (size(scratchpadSplit[1]) == 4 or size(scratchpadSplit[1]) == 5) and scratchpadSplit[1] >= 0 and scratchpadSplit[1] <= 39000) { + me.wp.setSpeed(scratchpadSplit[0], "at"); + me.wp.setAltitude(math.round(scratchpadSplit[1], 10), "at"); + mcdu_scratchpad.scratchpads[me.computer].empty(); + } elsif (num(scratchpadSplit[0]) != nil and size(scratchpadSplit[0]) == 3 and scratchpadSplit[0] >= 100 and scratchpadSplit[0] <= 350 and size(scratchpadSplit[1]) == 0) { + me.wp.setSpeed(scratchpadSplit[0], "at"); + mcdu_scratchpad.scratchpads[me.computer].empty(); + } else { + mcdu_message(me.computer, "FORMAT ERROR"); + } + } + } elsif (num(scratchpadStore) != nil and size(scratchpadStore) == 3 and scratchpadStore >= 100 and scratchpadStore <= 350) { + me.wp.setSpeed(scratchpadStore, "at"); + mcdu_scratchpad.scratchpads[me.computer].empty(); + } else { + mcdu_message(me.computer, "FORMAT ERROR"); } } else { - if (me.index == fmgc.flightPlanController.arrivalIndex[2]) { - canvas_mcdu.myVertRev[me.computer] = vertRev.new(1, left(me.wp.wp_name, 4), me.index, me.computer, me.wp, me.plan); - } elsif (left(me.wp.wp_name, 4) == fmgc.flightPlanController.flightplans[2].departure.id) { - canvas_mcdu.myVertRev[me.computer] = vertRev.new(0, left(me.wp.wp_name, 4), me.index, me.computer, me.wp, me.plan); - } elsif (me.index == (fmgc.flightPlanController.currentToWptIndex.getValue() - 1)) { - canvas_mcdu.myVertRev[me.computer] = vertRev.new(3, me.wp.wp_name, me.index, me.computer, me.wp, me.plan); - } else { - canvas_mcdu.myVertRev[me.computer] = vertRev.new(2, me.wp.wp_name, me.index, me.computer, me.wp, me.plan); - } + mcdu_message(me.computer, "NOT ALLOWED"); } - setprop("MCDU[" ~ me.computer ~ "]/page", "VERTREV"); }, }; @@ -446,11 +486,7 @@ var fplnPage = { # this one is only created once, and then updated - remember th } } else { if (size(me.outputList) >= index) { - if (size(mcdu_scratchpad.scratchpads[me.computer].scratchpad) > 0) { - mcdu_message(me.computer, "NOT ALLOWED"); - } else { - me.outputList[index - 1].pushButtonRight(); - } + me.outputList[index - 1].pushButtonRight(); } else { mcdu_message(me.computer, "NOT ALLOWED"); }