diff --git a/Nasal/FMGC/flightplan.nas b/Nasal/FMGC/flightplan.nas index f551c999..3aa74bfb 100644 --- a/Nasal/FMGC/flightplan.nas +++ b/Nasal/FMGC/flightplan.nas @@ -180,14 +180,34 @@ var flightPlanController = { } }, - insertPPOS: func(n) { - me.flightplans[n].insertWP(createWP(geo.aircraft_position(), "PPOS"), 0); - }, - insertTP: func(n) { me.flightplans[n].insertWP(createWP(geo.aircraft_position(), "T-P"), 1); }, + childWPBearingDistance: func(wpt, bearing, dist, name, typeStr = "") { + var coordinates = greatCircleMove(wpt.lat, wpt.lon, bearing, dist); + if (typeStr != "") { + return createWP(coordinates, name); + } else { + return createWP(coordinates, name, typeStr); + } + }, + + insertNOSTAR: func(n) { + var wptStore = me.flightplans[n].getWP(me.arrivalIndex[n]); + if (wptStore.wp_type == "runway") { + if (me.flightplans[n].getWP(me.arrivalIndex[n] - 1).id == "CF") { # check if we have NO STAR already loaded + me.deleteWP(me.arrivalIndex[n] - 1, n, 1); + } + var hdg = me.flightplans[n].destination_runway.heading + 180; + if (hdg > 360) { + hdg = hdg - 360; + } + me.flightplans[n].insertWP(me.childWPBearingDistance(wptStore, hdg, 5, "CF", "star"), me.arrivalIndex[n]); + } + me.flightPlanChanged(n); + }, + directTo: func(waypointGhost, plan) { if (me.flightplans[plan].indexOfWP(waypointGhost) == -1) { me.insertTP(plan); diff --git a/Nasal/MCDU/ARRIVAL.nas b/Nasal/MCDU/ARRIVAL.nas index 64f6bcd3..0dc9c184 100644 --- a/Nasal/MCDU/ARRIVAL.nas +++ b/Nasal/MCDU/ARRIVAL.nas @@ -22,6 +22,7 @@ var arrivalPage = { R4: [nil, nil, "ack"], R5: [nil, nil, "ack"], R6: [nil, nil, "ack"], + apprIsRwyFlag: nil, arrAirport: nil, runways: nil, selectedApproach: nil, @@ -123,7 +124,23 @@ var arrivalPage = { me._setupPageWithData(); }, updateActiveApproach: func() { - if (me.selectedApproach != nil) { + if (me.apprIsRwyFlag) { + if (!fmgc.flightPlanController.temporaryFlag[me.computer]) { + if (fmgc.flightPlanController.flightplans[2].destination_runway != nil) { + me.L1 = [fmgc.flightPlanController.flightplans[2].destination_runway.id, " APPR", "grn"]; + } elsif (fmgc.flightPlanController.flightplans[me.computer].destination_runway != nil) { + me.L1 = [fmgc.flightPlanController.flightplans[me.computer].destination_runway.id, " APPR", "yel"]; + } else { + me.L1 = ["---", " APPR", "wht"]; + } + } else { + if (fmgc.flightPlanController.flightplans[me.computer].destination_runway != nil) { + me.L1 = [fmgc.flightPlanController.flightplans[me.computer].destination_runway.id, " APPR", "yel"]; + } else { + me.L1 = ["---", " APPR", "wht"]; + } + } + } elsif (me.selectedApproach != nil) { if (fmgc.flightPlanController.flightplans[2].approach != nil) { if (fmgc.flightPlanController.flightplans[2].approach == me.selectedApproach) { me.L1 = [fmgc.flightPlanController.flightplans[2].approach.id, " APPR", "grn"]; @@ -143,17 +160,23 @@ var arrivalPage = { canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); }, updateActiveSTARs: func() { - if (me.selectedSTAR != nil) { + if (me.selectedSTAR == " NO STAR") { + if (!fmgc.flightPlanController.temporaryFlag[me.computer]) { + me.C1 = ["NONE", "STAR", "grn"]; + } else { + me.C1 = ["NONE", "STAR", "yel"]; + } + } elsif (me.selectedSTAR != nil) { if (fmgc.flightPlanController.flightplans[2].star != nil) { if (fmgc.flightPlanController.flightplans[2].star == me.selectedSTAR) { - me.C1 = [fmgc.flightPlanController.flightplans[2].star.id, "SID", "grn"]; + me.C1 = [fmgc.flightPlanController.flightplans[2].star.id, "STAR", "grn"]; } elsif (fmgc.flightPlanController.flightplans[me.computer].star != nil) { - me.C1 = [fmgc.flightPlanController.flightplans[me.computer].star.id, "SID", "yel"]; + me.C1 = [fmgc.flightPlanController.flightplans[me.computer].star.id, "STAR", "yel"]; } else { me.C1 = ["------- ", "STAR", "wht"]; } } elsif (fmgc.flightPlanController.flightplans[me.computer].star.id != nil) { - me.C1 = [fmgc.flightPlanController.flightplans[me.computer].star.id, "SID", "yel"]; + me.C1 = [fmgc.flightPlanController.flightplans[me.computer].star.id, "STAR", "yel"]; } else { me.C1 = ["------- ", "STAR", "wht"]; } @@ -174,7 +197,7 @@ var arrivalPage = { me.R1 = ["-------", "TRANS ", "wht"]; } } elsif (fmgc.flightPlanController.flightplans[me.computer].star_trans != nil) { - me.C1 = [fmgc.flightPlanController.flightplans[me.computer].star_trans.id, "SID", "yel"]; + me.C1 = [fmgc.flightPlanController.flightplans[me.computer].star_trans.id, "STAR", "yel"]; } else { me.R1 = ["-------", "TRANS ", "wht"]; } @@ -187,57 +210,113 @@ var arrivalPage = { canvas_mcdu.pageSwitch[me.computer].setBoolValue(0); }, updateApproaches: func() { + me.apprIsRwyFlag = 0; if (me.arrAirport == nil) { me.arrAirport = findAirportsByICAO(left(me.id, 4)); } me._approaches = me.arrAirport[0].getApproachList(); me.approaches = sort(me._approaches,func(a,b) cmp(a,b)); - - if (size(me.approaches) >= 1) { - me.L3 = [" " ~ me.approaches[0 + me.scrollApproach], " APPR", "blu"]; - me.C3 = [math.round(me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[0 + me.scrollApproach]).runways[0]].length) ~ "M", "AVAILABLE ", "blu"]; - me.R3 = ["CRS" ~ math.round(me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[0 + me.scrollApproach]).runways[0]].heading), nil, "blu"]; - if (me.approaches[0 + me.scrollApproach] != me.selectedApproach) { - me.arrowsMatrix[0][2] = 1; - me.arrowsColour[0][2] = "blu"; - } else { - me.arrowsMatrix[0][2] = 0; - me.arrowsColour[0][2] = "ack"; - } + if (me.approaches == nil or size(me.approaches) == 0) { + me.apprIsRwyFlag = 1; + me._approaches = me.arrAirport[0].runways; + me.approaches = sort(keys(me._approaches),func(a,b) cmp(a,b)); } - if (size(me.approaches) >= 2) { - me.L4 = [" " ~ me.approaches[1 + me.scrollApproach], nil, "blu"]; - if (me.arrAirport[0].getIAP(me.approaches[0 + me.scrollApproach]).radio == "ILS") { - me.C4 = [math.round(me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[1 + me.scrollApproach]).runways[0]].length) ~ "M", me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[0 + me.scrollApproach]).runways[0]].ils.id ~ "/" ~ sprintf("%7.2f", me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[0 + me.scrollApproach]).runways[0]].ils_frequency_mhz), "blu"]; - } else { - me.C4 = [math.round(me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[1 + me.scrollApproach]).runways[0]].length) ~ "M", nil, "blu"]; + if (!me.apprIsRwyFlag) { + if (size(me.approaches) >= 1) { + me.L3 = [" " ~ me.approaches[0 + me.scrollApproach], " APPR", "blu"]; + me.C3 = [math.round(me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[0 + me.scrollApproach]).runways[0]].length) ~ "M", "AVAILABLE ", "blu"]; + me.R3 = ["CRS" ~ math.round(me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[0 + me.scrollApproach]).runways[0]].heading), nil, "blu"]; + if (me.approaches[0 + me.scrollApproach] != me.selectedApproach) { + me.arrowsMatrix[0][2] = 1; + me.arrowsColour[0][2] = "blu"; + } else { + me.arrowsMatrix[0][2] = 0; + me.arrowsColour[0][2] = "ack"; + } } - me.R4 = ["CRS" ~ math.round(me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[1 + me.scrollApproach]).runways[0]].heading), nil, "blu"]; - if (me.approaches[1 + me.scrollApproach] != me.selectedApproach) { - me.arrowsMatrix[0][3] = 1; - me.arrowsColour[0][3] = "blu"; - } else { - me.arrowsMatrix[0][3] = 0; - me.arrowsColour[0][3] = "ack"; + if (size(me.approaches) >= 2) { + me.L4 = [" " ~ me.approaches[1 + me.scrollApproach], nil, "blu"]; + if (me.arrAirport[0].getIAP(me.approaches[0 + me.scrollApproach]).radio == "ILS") { + me.C4 = [math.round(me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[1 + me.scrollApproach]).runways[0]].length) ~ "M", me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[0 + me.scrollApproach]).runways[0]].ils.id ~ "/" ~ sprintf("%7.2f", me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[0 + me.scrollApproach]).runways[0]].ils_frequency_mhz), "blu"]; + } else { + me.C4 = [math.round(me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[1 + me.scrollApproach]).runways[0]].length) ~ "M", nil, "blu"]; + } + me.R4 = ["CRS" ~ math.round(me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[1 + me.scrollApproach]).runways[0]].heading), nil, "blu"]; + if (me.approaches[1 + me.scrollApproach] != me.selectedApproach) { + me.arrowsMatrix[0][3] = 1; + me.arrowsColour[0][3] = "blu"; + } else { + me.arrowsMatrix[0][3] = 0; + me.arrowsColour[0][3] = "ack"; + } } - } - if (size(me.approaches) >= 3) { - me.L5 = [" " ~ me.approaches[2 + me.scrollApproach], nil, "blu"]; - if (me.arrAirport[0].getIAP(me.approaches[1 + me.scrollApproach]).radio == "ILS") { - me.C5 = [math.round(me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[2 + me.scrollApproach]).runways[0]].length) ~ "M", me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[1 + me.scrollApproach]).runways[0]].ils.id ~ "/" ~ sprintf("%7.2f", me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[1 + me.scrollApproach]).runways[0]].ils_frequency_mhz), "blu"]; - } else { - me.C5 = [math.round(me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[2 + me.scrollApproach]).runways[0]].length) ~ "M", nil, "blu"]; + if (size(me.approaches) >= 3) { + me.L5 = [" " ~ me.approaches[2 + me.scrollApproach], nil, "blu"]; + if (me.arrAirport[0].getIAP(me.approaches[1 + me.scrollApproach]).radio == "ILS") { + me.C5 = [math.round(me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[2 + me.scrollApproach]).runways[0]].length) ~ "M", me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[1 + me.scrollApproach]).runways[0]].ils.id ~ "/" ~ sprintf("%7.2f", me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[1 + me.scrollApproach]).runways[0]].ils_frequency_mhz), "blu"]; + } else { + me.C5 = [math.round(me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[2 + me.scrollApproach]).runways[0]].length) ~ "M", nil, "blu"]; + } + me.R5 = ["CRS" ~ math.round(me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[2 + me.scrollApproach]).runways[0]].heading), nil, "blu"]; + if (me.arrAirport[0].getIAP(me.approaches[2 + me.scrollApproach]).radio == "ILS") { + me.C6[1] = me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[2 + me.scrollApproach]).runways[0]].ils.id ~ "/" ~ sprintf("%7.2f", me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[2 + me.scrollApproach]).runways[0]].ils_frequency_mhz); + } + if (me.approaches[2 + me.scrollApproach] != me.selectedApproach) { + me.arrowsMatrix[0][4] = 1; + me.arrowsColour[0][4] = "blu"; + } else { + me.arrowsMatrix[0][3] = 0; + me.arrowsColour[0][3] = "ack"; + } } - me.R5 = ["CRS" ~ math.round(me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[2 + me.scrollApproach]).runways[0]].heading), nil, "blu"]; - if (me.arrAirport[0].getIAP(me.approaches[2 + me.scrollApproach]).radio == "ILS") { - me.C6[1] = me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[2 + me.scrollApproach]).runways[0]].ils.id ~ "/" ~ sprintf("%7.2f", me.arrAirport[0].runways[me.arrAirport[0].getIAP(me.approaches[2 + me.scrollApproach]).runways[0]].ils_frequency_mhz); + } else { + # show runways, not IAPS if no approaches. Not realistic but people with no navigraph keep complaining + if (size(me.approaches) >= 1) { + me.L3 = [" " ~ me._approaches[me.approaches[0 + me.scrollApproach]].id, " RWY", "blu"]; + me.C3 = [math.round(me._approaches[me.approaches[0 + me.scrollApproach]].length) ~ "M", "AVAILABLE ", "blu"]; + me.R3 = ["CRS" ~ math.round(me._approaches[me.approaches[0 + me.scrollApproach]].heading), nil, "blu"]; + if (me.approaches[0 + me.scrollApproach] != me.selectedApproach) { + me.arrowsMatrix[0][2] = 1; + me.arrowsColour[0][2] = "blu"; + } else { + me.arrowsMatrix[0][2] = 0; + me.arrowsColour[0][2] = "ack"; + } } - if (me.approaches[2 + me.scrollApproach] != me.selectedApproach) { - me.arrowsMatrix[0][4] = 1; - me.arrowsColour[0][4] = "blu"; - } else { - me.arrowsMatrix[0][3] = 0; - me.arrowsColour[0][3] = "ack"; + if (size(me.approaches) >= 2) { + me.L4 = [" " ~ me._approaches[me.approaches[1 + me.scrollApproach]].id, nil, "blu"]; + if (me._approaches[me.approaches[0 + me.scrollApproach]].ils != nil) { + me.C4 = [math.round(me._approaches[me.approaches[1 + me.scrollApproach]].length) ~ "M", me._approaches[me.approaches[0 + me.scrollApproach]].ils.id ~ "/" ~ sprintf("%7.2f", me._approaches[me.approaches[0 + me.scrollApproach]].ils_frequency_mhz), "blu"]; + } else { + me.C4 = [math.round(me._approaches[me.approaches[1 + me.scrollApproach]].length) ~ "M", nil, "blu"]; + } + me.R4 = ["CRS" ~ math.round(me._approaches[me.approaches[1 + me.scrollApproach]].heading), nil, "blu"]; + if (me.approaches[1 + me.scrollApproach] != me.selectedApproach) { + me.arrowsMatrix[0][3] = 1; + me.arrowsColour[0][3] = "blu"; + } else { + me.arrowsMatrix[0][3] = 0; + me.arrowsColour[0][3] = "ack"; + } + } + if (size(me.approaches) >= 3) { + me.L5 = [" " ~ me._approaches[me.approaches[2 + me.scrollApproach]].id, nil, "blu"]; + if (me._approaches[me.approaches[1 + me.scrollApproach]].ils != nil) { + me.C5 = [math.round(me._approaches[me.approaches[2 + me.scrollApproach]].length) ~ "M", me._approaches[me.approaches[1 + me.scrollApproach]].ils.id ~ "/" ~ sprintf("%7.2f", me._approaches[me.approaches[1 + me.scrollApproach]].ils_frequency_mhz), "blu"]; + } else { + me.C5 = [math.round(me._approaches[me.approaches[2 + me.scrollApproach]].length) ~ "M", nil, "blu"]; + } + me.R5 = ["CRS" ~ math.round(me._approaches[me.approaches[2 + me.scrollApproach]].heading), nil, "blu"]; + if (me._approaches[me.approaches[2 + me.scrollApproach]].ils != nil) { + me.C6[1] = me._approaches[me.approaches[1 + me.scrollApproach]].ils.id ~ "/" ~ sprintf("%7.2f", me._approaches[me.approaches[1 + me.scrollApproach]].ils_frequency_mhz); + } + if (me.approaches[2 + me.scrollApproach] != me.selectedApproach) { + me.arrowsMatrix[0][4] = 1; + me.arrowsColour[0][4] = "blu"; + } else { + me.arrowsMatrix[0][4] = 0; + me.arrowsColour[0][4] = "ack"; + } } } @@ -257,6 +336,11 @@ var arrivalPage = { } me.stars = sort(me._stars,func(a,b) cmp(a,b)); + if (me.stars == nil) { + me.stars = [" NO STAR"]; + } else { + append(me.stars, " NO STAR"); + } if (size(me.stars) >= 1) { me.L2 = [" " ~ me.stars[0 + me.scrollStars], "STARS", "blu"]; @@ -415,7 +499,7 @@ var arrivalPage = { me.scrollStars = 0; } me.updateSTARs(); - if (me.selectedSTAR == nil) { + if (me.selectedSTAR == nil or me.selectedSTAR != " NO STAR") { me.clearTransitions(); } else { me.updateTransitions(); @@ -440,7 +524,7 @@ var arrivalPage = { me.scrollStars = size(me.stars) - 4; } me.updateSTARs(); - if (me.selectedSTAR == nil) { + if (me.selectedSTAR == nil or me.selectedSTAR != " NO STAR") { me.clearTransitions(); } else { me.updateTransitions(); @@ -459,12 +543,17 @@ var arrivalPage = { }, arrPushbuttonLeft: func(index) { if (me.activePage == 0) { - if (size(me.approaches) >= (index - 1) and index != 2) { + if (size(me.approaches) >= (index - 2) and index != 2) { if (!dirToFlag) { - me.selectedApproach = me.arrAirport[0].getIAP(me.approaches[index - 3 + me.scrollApproach]); me.makeTmpy(); - fmgc.flightPlanController.flightplans[me.computer].destination_runway = me.arrAirport[0].runways[me.selectedApproach.runways[0]]; - fmgc.flightPlanController.flightplans[me.computer].approach = me.selectedApproach; + if (!me.apprIsRwyFlag) { + me.selectedApproach = me.arrAirport[0].getIAP(me.approaches[index - 3 + me.scrollApproach]); + fmgc.flightPlanController.flightplans[me.computer].destination_runway = me.arrAirport[0].runways[me.selectedApproach.runways[0]]; + fmgc.flightPlanController.flightplans[me.computer].approach = me.selectedApproach; + } else { + me.selectedApproach = me.arrAirport[0].runways[index - 3 + me.scrollApproach]; + fmgc.flightPlanController.flightplans[me.computer].destination_runway = me.arrAirport[0].runway(me.approaches[index - 3 + me.scrollApproach]); + } setprop("FMGC/internal/baro", 99999); setprop("FMGC/internal/radio", 99999); setprop("FMGC/internal/radio-no", 0); @@ -480,15 +569,26 @@ var arrivalPage = { notAllowed(me.computer); } } else { - if (size(me.stars) >= (index - 1)) { + if (size(me.stars) >= (index - 2)) { if (!dirToFlag) { me.selectedSTAR = me.stars[index - 2 + me.scrollStars]; me.makeTmpy(); - fmgc.flightPlanController.flightplans[me.computer].star = me.arrAirport[0].getStar(me.selectedSTAR); + if (me.selectedSTAR != " NO STAR") { + fmgc.flightPlanController.flightplans[me.computer].star = me.arrAirport[0].getStar(me.selectedSTAR); + } else { + fmgc.flightPlanController.flightplans[me.computer].star = nil; + if (fmgc.flightPlanController.flightplans[me.computer].approach == nil) { + fmgc.flightPlanController.insertNOSTAR(me.computer); + } + } me.updateActiveSTARs(); me.updateSTARs(); - me.hasPressNoTrans = 0; - me.updateTransitions(); + if (me.selectedSTAR != " NO STAR") { + me.hasPressNoTrans = 0; + me.updateTransitions(); + } else { + me.hasPressNoTrans = 1; + } me.updateActiveTransitions(); fmgc.flightPlanController.flightPlanChanged(me.computer); } else { diff --git a/Nasal/MCDU/MCDU.nas b/Nasal/MCDU/MCDU.nas index 28c8f1f3..497ada85 100644 --- a/Nasal/MCDU/MCDU.nas +++ b/Nasal/MCDU/MCDU.nas @@ -448,6 +448,7 @@ var rskbutton = func(btn, i) { } canvas_mcdu.myArrival[i] = nil; canvas_mcdu.myArrival[i] = arrivalPage.new(canvas_mcdu.myLatRev[i].title[2], i); + canvas_mcdu.myArrival[i]._setupPageWithData(); setprop("MCDU[" ~ i ~ "]/page", "ARRIVAL"); } else { notAllowed(i);