FMGC: Fix waypoint advance logic and F-PLN bug

This commit is contained in:
Joshua Davidson 2019-02-21 12:13:46 -07:00
parent ceb8a6fcdb
commit cfff08578d
3 changed files with 56 additions and 12 deletions

View file

@ -697,7 +697,11 @@ var ap_various = func {
setprop("/it-autoflight/internal/lnav-advance-nm", turn_dist);
if (getprop("/FMGC/flightplan[2]/current-leg-dist") <= turn_dist) {
currentWP[2] = currentWP[2] + 1;
if (currentWP[2] < 1) {
currentWP[2] = 1;
} else if (num_out[2].getValue() > 2) { # The Airbus doesn't display anything past the previous waypoint after advancing
flightplan.advanceDelete(2);
}
}
}
}

View file

@ -7,6 +7,7 @@
var TMPY = 5;
var MAIN = 6;
var debug = 0; # Set to 1 to check inner functionality
var insertReturn = nil;
var active_out = [nil, nil, props.globals.getNode("/FMGC/flightplan[2]/active")];
var num_out = [props.globals.getNode("/FMGC/flightplan[0]/num"), props.globals.getNode("/FMGC/flightplan[1]/num"), props.globals.getNode("/FMGC/flightplan[2]/num")];
var TMPYActive = [props.globals.getNode("/FMGC/internal/tmpy-active[0]"), props.globals.getNode("/FMGC/internal/tmpy-active[1]")];
@ -80,7 +81,9 @@ var FPLNText = {
}
},
getSubText: func(i) {
if (TMPYActive[i].getBoolValue()) {
if (me.index == 0) {
return "";
} else if (TMPYActive[i].getBoolValue()) {
if (fmgc.arrivalAirportI[i] == me.index) {
return "DEST";
} else {
@ -101,7 +104,7 @@ var FPLNText = {
}
var scratchpad = getprop("/MCDU[" ~ me.computer.mcdu ~ "]/scratchpad");
if (scratchpad == "CLR") {
if (fmgc.flightplan.deleteWP(me.index, me.computer.mcdu) != 0) {
if (fmgc.flightplan.deleteWP(me.index, me.computer.mcdu, 0) != 0) {
notAllowed(me.computer.mcdu);
} else {
setprop("/MCDU[" ~ me.computer.mcdu ~ "]/scratchpad-msg", 0);
@ -109,19 +112,28 @@ var FPLNText = {
}
} else {
if (size(scratchpad) == 5) {
if (fmgc.flightplan.insertFix(scratchpad, me.index, me.computer.mcdu) != 0) {
var insertReturn = fmgc.flightplan.insertFix(scratchpad, me.index, me.computer.mcdu);
if (insertReturn == 2) {
notAllowed(me.computer.mcdu);
} else if (insertReturn == 1) {
notInDataBase(me.computer.mcdu);
} else {
setprop("/MCDU[" ~ me.computer.mcdu ~ "]/scratchpad", "");
}
} else if (size(scratchpad) == 4) {
if (fmgc.flightplan.insertArpt(scratchpad, me.index, me.computer.mcdu) != 0) {
var insertReturn = fmgc.flightplan.insertArpt(scratchpad, me.index, me.computer.mcdu);
if (insertReturn == 2) {
notAllowed(me.computer.mcdu);
} else if (insertReturn == 1) {
notInDataBase(me.computer.mcdu);
} else {
setprop("/MCDU[" ~ me.computer.mcdu ~ "]/scratchpad", "");
}
} else if (size(scratchpad) == 3) {
if (fmgc.flightplan.insertNavaid(scratchpad, me.index, me.computer.mcdu) != 0) {
var insertReturn = fmgc.flightplan.insertNavaid(scratchpad, me.index, me.computer.mcdu);
if (insertReturn == 2) {
notAllowed(me.computer.mcdu);
} else if (insertReturn == 1) {
notInDataBase(me.computer.mcdu);
} else {
setprop("/MCDU[" ~ me.computer.mcdu ~ "]/scratchpad", "");

View file

@ -100,6 +100,17 @@ var flightplan = {
}
me.checkWPOutputs(n);
},
advanceDelete: func(n) {
if (num_out[n].getValue() > 2) {
if (TMPYActive[0].getBoolValue() and wpID[0][0] == wpID[n][0]) {
me.deleteWP(0, 0);
}
if (TMPYActive[1].getBoolValue() and wpID[1][0] == wpID[n][0]) {
me.deleteWP(0, 1);
}
me.deleteWP(0, n, 1);
}
},
updateARPT: func(dep, arr, n) {
if (n == 2) { # Which flightplan?
me.reset2();
@ -123,9 +134,12 @@ var flightplan = {
me.checkWPOutputs(n);
},
# return 1 will cause NOT IN DATABASE, return 2 will cause NOT ALLOWED
insertFix: func(wp, i, n) {
var pos = findFixesByID(wp);
if (pos != nil and size(pos) > 0) {
if (i == 0) {
return 2;
} else if (pos != nil and size(pos) > 0) {
fp[n].insertWP(createWPFrom(pos[0]), i);
me.checkWPOutputs(n);
return 0;
@ -135,7 +149,9 @@ var flightplan = {
},
insertArpt: func(wp, i, n) {
var pos = findAirportsByICAO(wp);
if (pos != nil and size(pos) > 0) {
if (i == 0) {
return 2;
} else if (pos != nil and size(pos) > 0) {
fp[n].insertWP(createWPFrom(pos[0]), i);
me.checkWPOutputs(n);
return 0;
@ -145,7 +161,9 @@ var flightplan = {
},
insertNavaid: func(nav, i, n) {
var pos = findNavaidsByID(nav);
if (pos != nil and size(pos) > 0) {
if (i == 0) {
return 2;
} else if (pos != nil and size(pos) > 0) {
fp[n].insertWP(createWPFrom(pos[0]), i);
me.checkWPOutputs(n);
return 0;
@ -161,16 +179,26 @@ var flightplan = {
fp[n].insertWP(createWP(geo.aircraft_position(), "T/P"), 0);
me.checkWPOutputs(n);
},
deleteWP: func(i, n) {
deleteWP: func(i, n, t) {
var wp = wpID[n][i].getValue();
if (fp[n].getPlanSize() > 2 and wp != FMGCdep.getValue() and wp != FMGCarr.getValue() and wp != "T/P" and wp != "PPOS") {
if (t == 1) {
fp[n].deleteWP(i);
me.outputProps(); # Make sure everything is updated before we update the MCDUs.
me.updateMCDUDriver(n);
canvas_nd.A3XXRouteDriver.triggerSignal("fp-removed");
return 0;
} else {
return 1;
if (i == 0) {
return 2;
} else if (fp[n].getPlanSize() > 2 and wp != FMGCdep.getValue() and wp != FMGCarr.getValue() and wp != "T/P" and wp != "PPOS") {
fp[n].deleteWP(i);
me.outputProps(); # Make sure everything is updated before we update the MCDUs.
me.updateMCDUDriver(n);
canvas_nd.A3XXRouteDriver.triggerSignal("fp-removed");
return 0;
} else {
return 2;
}
}
},
checkWPOutputs: func(n) {