WP Database: add initial; limits entries to 20
This commit is contained in:
parent
886a13cd79
commit
68fd0ba416
4 changed files with 161 additions and 32 deletions
|
@ -4000,6 +4000,7 @@
|
|||
<file>Aircraft/A320-family/Nasal/FMGC/FCU.nas</file>
|
||||
</fcu>
|
||||
<fmgc>
|
||||
<file>Aircraft/A320-family/Nasal/FMGC/flightplan-waypoints.nas</file>
|
||||
<file>Aircraft/A320-family/Nasal/FMGC/flightplan.nas</file>
|
||||
<file>Aircraft/A320-family/Nasal/FMGC/FMGC.nas</file>
|
||||
<file>Aircraft/A320-family/Nasal/FMGC/FMGC-b.nas</file>
|
||||
|
|
119
Nasal/FMGC/flightplan-waypoints.nas
Normal file
119
Nasal/FMGC/flightplan-waypoints.nas
Normal file
|
@ -0,0 +1,119 @@
|
|||
# A3XX FMGC Waypoint database
|
||||
# Copyright (c) 2020 Josh Davidson (Octal450) and Jonathan Redpath (legoboyvdlp)
|
||||
|
||||
var WaypointDatabase = {
|
||||
waypointsVec: [],
|
||||
# addWP - adds pilot waypoint to waypoints vector
|
||||
# arg: wpObj - passed pilot waypoint object
|
||||
# return:
|
||||
# 0 - not allowed
|
||||
# 2 - accepted
|
||||
# 4 - database full
|
||||
addWP: func(wpObj) {
|
||||
# validate ghost
|
||||
if (wpObj.wpGhost == nil) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
# check size of database
|
||||
if (me.getCount() >= 20) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
if (wpObj.index >= me.getSize()) {
|
||||
# add to end, since index doesn't exist
|
||||
append(me.waypointsVec, wpObj.wpGhost);
|
||||
return 2;
|
||||
} elsif (me.waypointsVec[wpObj.index] == nil) {
|
||||
# add at passed index
|
||||
me.waypointsVec[wpObj.index] = wpObj.wpGhost;
|
||||
} else {
|
||||
# fall back to end
|
||||
logprint(4, "pilotWaypoint constructor claims index " ~ wpObj.index ~ " is nil, but it isn't!");
|
||||
append(me.waypointsVec, wpObj.wpGhost);
|
||||
return 2;
|
||||
}
|
||||
},
|
||||
# delete - empties waypoints vector
|
||||
delete: func() {
|
||||
me.waypointsVec = [];
|
||||
},
|
||||
# deleteAtIndex - delete at specific index. Set to nil, so it still exists in vector
|
||||
deleteAtIndex: func(index) {
|
||||
if (index < 0 or index >= me.getSize() or index >= 20) {
|
||||
return;
|
||||
}
|
||||
me.waypointsVec[index] = nil;
|
||||
},
|
||||
# getNilIndex - find the first nil
|
||||
# post 2020.1 use dedicated function vecindex()
|
||||
getNilIndex: func() {
|
||||
for (var i = 0; i < me.getSize(); i = i + 1) {
|
||||
if (me.waypointsVec[i] == nil) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
},
|
||||
# getCount - return size, neglecting "nil"
|
||||
getCount: func() {
|
||||
var count = 0;
|
||||
for (var i = 0; i < me.getSize(); i = i + 1) {
|
||||
if (me.waypointsVec[i] == nil) {
|
||||
continue;
|
||||
}
|
||||
count += 1;
|
||||
}
|
||||
return count;
|
||||
},
|
||||
# getSize - return maximum size of vector
|
||||
getSize: func() {
|
||||
return size(me.waypointsVec);
|
||||
},
|
||||
#
|
||||
getWP: func(text) {
|
||||
for (var i = 0; i < me.getSize(); i = i + 1) {
|
||||
if (me.waypointsVec[i] == nil) {
|
||||
continue;
|
||||
}
|
||||
if (text == me.waypointsVec[i].wpGhost.wp_name) {
|
||||
return me.waypointsVec[i].wpGhost;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
},
|
||||
};
|
||||
|
||||
var pilotWaypoint = {
|
||||
new: func(positioned, typeStr, wpGhostType = "") {
|
||||
var pilotWp = { parents:[pilotWaypoint] };
|
||||
|
||||
# Figure out what the first index is we can use
|
||||
var nilIndex = WaypointDatabase.getNilIndex();
|
||||
var position = nil;
|
||||
|
||||
if (nilIndex == -1) {
|
||||
position = WaypointDatabase.getSize() + 1;
|
||||
} else {
|
||||
position = nilIndex + 1
|
||||
}
|
||||
|
||||
pilotWp.setId(typeStr ~ sprintf("%s", position));
|
||||
pilotWp.index = position - 1;
|
||||
|
||||
# set ghost to created waypoint
|
||||
if (wpGhostType != "") {
|
||||
pilotWp.wpGhost = createWP(positioned, pilotWp.id, wpGhostType);
|
||||
} else {
|
||||
pilotWp.wpGhost = createWP(positioned, pilotWp.id);
|
||||
}
|
||||
|
||||
return pilotWp;
|
||||
},
|
||||
setId: func(id) {
|
||||
if (typeof(id) == "scalar") { me.id = id; }
|
||||
},
|
||||
getId: func() {
|
||||
if (me.id != nil) { return id; }
|
||||
},
|
||||
};
|
|
@ -232,13 +232,9 @@ var flightPlanController = {
|
|||
# name: name of waypoint to be created
|
||||
# typeStr: optional argument to be passed to createWP, must be one of "sid", "star" "approach" "missed" or "pseudo"
|
||||
|
||||
childWPBearingDistance: func(wpt, bearing, dist, name, typeStr = "") {
|
||||
childWPBearingDistance: func(wpt, bearing, dist) {
|
||||
var coordinates = greatCircleMove(wpt.lat, wpt.lon, num(bearing), num(dist));
|
||||
if (typeStr != "") {
|
||||
return createWP(coordinates, name, typeStr);
|
||||
} else {
|
||||
return createWP(coordinates, name);
|
||||
}
|
||||
return coordinates;
|
||||
},
|
||||
|
||||
# insertNOSID - create default SID and add to flightplan
|
||||
|
@ -254,7 +250,7 @@ var flightPlanController = {
|
|||
}
|
||||
|
||||
# fudge the altitude since we cannot create a hdgtoAlt from nasal. Assume 600 feet per mile - 2.5 miles
|
||||
me.flightplans[n].insertWP(me.childWPBearingDistance(wptStore, me.flightplans[n].departure_runway.heading, 2.5, "1500", "sid"), 1);
|
||||
me.flightplans[n].insertWP(createWP(me.childWPBearingDistance(wptStore, me.flightplans[n].departure_runway.heading, 2.5), "1500", "sid"), 1);
|
||||
}
|
||||
me.flightPlanChanged(n);
|
||||
},
|
||||
|
@ -274,7 +270,7 @@ var flightPlanController = {
|
|||
if (hdg > 360) {
|
||||
hdg = hdg - 360;
|
||||
}
|
||||
me.flightplans[n].insertWP(me.childWPBearingDistance(wptStore, hdg, 5, "CF", "star"), me.arrivalIndex[n]);
|
||||
me.flightplans[n].insertWP(createWP(me.childWPBearingDistance(wptStore, hdg, 5), "CF", "star"), me.arrivalIndex[n]);
|
||||
}
|
||||
me.flightPlanChanged(n);
|
||||
},
|
||||
|
@ -458,21 +454,15 @@ var flightPlanController = {
|
|||
if (latDecimal > 90 or latDecimal < -90 or lonDecimal > 180 or lonDecimal < -180) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
var myWpLatLon = createWP(latDecimal, lonDecimal, "LL" ~ index);
|
||||
if (me.flightplans[plan].indexOfWP(myWpLatLon) == -1) {
|
||||
me.flightplans[plan].insertWP(myWpLatLon, index);
|
||||
me.addDiscontinuity(index + 1, plan);
|
||||
me.flightPlanChanged(plan);
|
||||
return 2;
|
||||
} else {
|
||||
var numToDel = me.flightplans[plan].indexOfWP(myWpLatLon) - index;
|
||||
while (numToDel > 0) {
|
||||
me.deleteWP(index, plan, 1);
|
||||
numToDel -= 1;
|
||||
}
|
||||
return 2;
|
||||
var waypoint = pilotWaypoint.new({lat: latDecimal, lon: lonDecimal}, "LL");
|
||||
var addDb = WaypointDatabase.addWP(waypoint);
|
||||
if (addDb != 2) {
|
||||
return addDb;
|
||||
}
|
||||
me.flightplans[plan].insertWP(waypoint.wpGhost, index);
|
||||
me.addDiscontinuity(index + 1, plan);
|
||||
me.flightPlanChanged(plan);
|
||||
return 2;
|
||||
},
|
||||
|
||||
insertNavaid: func(text, index, plan, override = 0, overrideIndex = -1) {
|
||||
|
@ -568,7 +558,7 @@ var flightPlanController = {
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (size(wpGhostContainer) == 0 or override) {
|
||||
if (size(wpGhostContainer) == 1 or override) {
|
||||
if (!override) {
|
||||
wpGhost = wpGhostContainer[0];
|
||||
} else {
|
||||
|
@ -584,8 +574,7 @@ var flightPlanController = {
|
|||
}
|
||||
|
||||
var localMagvar = magvar(wpGhost.lat, wpGhost.lon);
|
||||
me.insertPlaceBearingDistance(wpGhost, textSplit[1] + localMagvar, textSplit[2], index, plan);
|
||||
return 2;
|
||||
return me.insertPlaceBearingDistance(wpGhost, textSplit[1] + localMagvar, textSplit[2], index, plan);
|
||||
},
|
||||
|
||||
|
||||
|
@ -597,12 +586,18 @@ var flightPlanController = {
|
|||
# plan: plan to insert to
|
||||
|
||||
insertPlaceBearingDistance: func(wp, bearing, distance, index, plan) {
|
||||
me.flightplans[plan].insertWP(me.childWPBearingDistance(wp, bearing, distance, "PBD" ~ index), index);
|
||||
var waypoint = pilotWaypoint.new(me.childWPBearingDistance(wp, bearing, distance), "PBD");
|
||||
var addDb = WaypointDatabase.addWP(waypoint);
|
||||
if (addDb != 2) {
|
||||
return addDb;
|
||||
}
|
||||
me.flightplans[plan].insertWP(waypoint.wpGhost, index);
|
||||
me.addDiscontinuity(index + 1, plan);
|
||||
me.flightPlanChanged(plan);
|
||||
return 2;
|
||||
},
|
||||
|
||||
scratchpad: func(text, index, plan) { # return 0 not in database, 1 not allowed, 2 success, 3 = not allowed due to dir to
|
||||
scratchpad: func(text, index, plan) { # return 0 not in database, 1 not allowed, 2 success, 3 = not allowed due to dir to, 4 = database full
|
||||
if (mcdu.dirToFlag) {
|
||||
return 3;
|
||||
}
|
||||
|
@ -618,6 +613,8 @@ var flightPlanController = {
|
|||
var thePlan = plan;
|
||||
}
|
||||
|
||||
# check waypoints database here
|
||||
|
||||
if (size(split("/", text)) == 3) {
|
||||
return me.getWPforPBD(text, index, thePlan);
|
||||
} elsif (text == "CLR") {
|
||||
|
|
|
@ -410,6 +410,8 @@ var fplnPage = { # this one is only created once, and then updated - remember th
|
|||
notInDataBase(me.computer);
|
||||
} elsif (returny == 1) {
|
||||
notAllowed(me.computer);
|
||||
} elsif (returny == 4) {
|
||||
databaseFull(me.computer);
|
||||
} else {
|
||||
setprop("MCDU[" ~ me.computer ~ "]/scratchpad-msg", "");
|
||||
setprop("MCDU[" ~ me.computer ~ "]/scratchpad", "");
|
||||
|
@ -445,15 +447,25 @@ var fplnPage = { # this one is only created once, and then updated - remember th
|
|||
};
|
||||
|
||||
var notInDataBase = func(i) {
|
||||
if (getprop("MCDU[" ~ i ~ "]/scratchpad-msg") == 1) {
|
||||
setprop("MCDU[" ~ i ~ "]/last-scratchpad", "NOT IN DATABASE");
|
||||
} else {
|
||||
setprop("MCDU[" ~ i ~ "]/last-scratchpad", getprop("MCDU[" ~ i ~ "]/scratchpad"));
|
||||
}
|
||||
if (getprop("MCDU[" ~ i ~ "]/scratchpad-msg") == 1) {
|
||||
setprop("MCDU[" ~ i ~ "]/last-scratchpad", "NOT IN DATABASE");
|
||||
} else {
|
||||
setprop("MCDU[" ~ i ~ "]/last-scratchpad", getprop("MCDU[" ~ i ~ "]/scratchpad"));
|
||||
}
|
||||
setprop("MCDU[" ~ i ~ "]/scratchpad-msg", 1);
|
||||
setprop("MCDU[" ~ i ~ "]/scratchpad", "NOT IN DATABASE");
|
||||
}
|
||||
|
||||
var databaseFull = func(i) {
|
||||
if (getprop("MCDU[" ~ i ~ "]/scratchpad-msg") == 1) {
|
||||
setprop("MCDU[" ~ i ~ "]/last-scratchpad", "LIST OF 20 IN USE");
|
||||
} else {
|
||||
setprop("MCDU[" ~ i ~ "]/last-scratchpad", getprop("MCDU[" ~ i ~ "]/scratchpad"));
|
||||
}
|
||||
setprop("MCDU[" ~ i ~ "]/scratchpad-msg", 1);
|
||||
setprop("MCDU[" ~ i ~ "]/scratchpad", "LIST OF 20 IN USE");
|
||||
}
|
||||
|
||||
var decimalToShortString = func(dms, type) {
|
||||
var degrees = split(".", sprintf(dms))[0];
|
||||
if (type == "lat") {
|
||||
|
|
Loading…
Reference in a new issue