2021-02-11 22:46:04 +00:00
|
|
|
# See: http://wiki.flightgear.org/MapStructure
|
|
|
|
# Class things:
|
2021-02-21 22:01:20 +00:00
|
|
|
|
2021-02-24 22:00:46 +00:00
|
|
|
## Airbus Terrain on ND by InuYaksa*2021
|
|
|
|
## EGPWS device - Applicable to: MSN 0112
|
|
|
|
## Ident.: DSC-31-45-00009586.0012001 / 22 MAY 12
|
|
|
|
## Ident.: DSC-31-45-00009586.0009001 / 08 AUG 13
|
|
|
|
|
2021-02-21 22:01:20 +00:00
|
|
|
## inspired from work on 787-family - thanks a lots
|
2021-02-24 22:00:46 +00:00
|
|
|
## and a great help from legoboyvdlp
|
2021-02-21 22:01:20 +00:00
|
|
|
|
2021-02-11 22:46:04 +00:00
|
|
|
var name = 'TERRAIN';
|
|
|
|
var parents = [DotSym];
|
|
|
|
var __self__ = caller(0)[0];
|
|
|
|
DotSym.makeinstance( name, __self__ );
|
|
|
|
|
|
|
|
var element_type = "group";
|
|
|
|
|
2021-02-18 23:17:21 +00:00
|
|
|
var terrain_minalt = props.globals.initNode("/instrumentation/efis[0]/nd/terrain-on-nd/min-altitude", 0,"INT");
|
|
|
|
var terrain_maxalt = props.globals.initNode("/instrumentation/efis[0]/nd/terrain-on-nd/max-altitude", -9999,"INT");
|
2021-02-28 21:22:36 +00:00
|
|
|
var terrain_maxcol = props.globals.initNode("/instrumentation/efis[0]/nd/terrain-on-nd/max-color", 0,"INT"); # 0= grn, 1= yel, 2= red
|
2021-02-18 23:17:21 +00:00
|
|
|
|
2021-02-24 22:00:46 +00:00
|
|
|
var terrain_alert = props.globals.getNode("/instrumentation/mk-viii/outputs/alert-mode");
|
2021-02-14 20:02:32 +00:00
|
|
|
|
2021-02-16 23:30:26 +00:00
|
|
|
var tile_list = [
|
2021-02-24 22:00:46 +00:00
|
|
|
nil,"tile_gl.png","tile_gh.png","tile_al.png","tile_ah.png","tile_rh.png", # 0-5 low alt - imho real ND displays as amber-ish color than yellow one
|
2021-02-21 15:59:17 +00:00
|
|
|
"tile_gl.png","tile_gh.png","tile_gh.png","tile_gs.png", # 6-9 hi alt
|
2021-02-24 22:00:46 +00:00
|
|
|
"tile_ml.png","tile_cl.png", # 10 magenta - 11 cyan-ish/blue (water)
|
|
|
|
"tile_as.png","tile_rs.png" # 12-13 alert - solid colors
|
2021-02-16 23:30:26 +00:00
|
|
|
];
|
2021-02-12 23:38:43 +00:00
|
|
|
|
2021-02-15 22:12:07 +00:00
|
|
|
var is_terrain = 0;
|
2021-02-12 23:38:43 +00:00
|
|
|
|
|
|
|
var get_elevation = func (lat, lon) {
|
|
|
|
var info = geodinfo(lat, lon);
|
|
|
|
var elevation = 0;
|
2021-02-15 22:12:07 +00:00
|
|
|
if (info != nil) {
|
|
|
|
elevation = int(info[0] * 3.2808399);
|
|
|
|
me.is_terrain = (info[1] == nil) ? 1 : info[1].solid;
|
|
|
|
}
|
2021-02-12 23:38:43 +00:00
|
|
|
else { elevation = nil; }
|
|
|
|
return elevation;
|
|
|
|
}
|
|
|
|
|
2021-02-15 22:12:07 +00:00
|
|
|
var updateTerrain = func {
|
|
|
|
|
|
|
|
if (me.reference == nil) return;
|
2021-02-11 22:46:04 +00:00
|
|
|
|
|
|
|
if(me.fetching) return;
|
2021-02-12 23:38:43 +00:00
|
|
|
|
2021-02-11 22:46:04 +00:00
|
|
|
me.fetching = 1;
|
2021-02-14 20:02:32 +00:00
|
|
|
|
|
|
|
if (me.request_clear == 1) {
|
|
|
|
me.request_clear = 0;
|
|
|
|
me.clear();
|
2021-02-16 23:30:26 +00:00
|
|
|
me.group.setVisible(1);
|
2021-02-14 20:02:32 +00:00
|
|
|
}
|
2021-02-11 22:46:04 +00:00
|
|
|
|
2021-02-12 23:38:43 +00:00
|
|
|
var RAD2DEG = 57.2957795;
|
|
|
|
var DEG2RAD = 0.016774532925;
|
2021-02-11 22:46:04 +00:00
|
|
|
|
2021-02-15 22:12:07 +00:00
|
|
|
var pos_lat = me.reference.lat();
|
|
|
|
var pos_lon = me.reference.lon();
|
2021-02-12 23:38:43 +00:00
|
|
|
|
2021-02-16 23:30:26 +00:00
|
|
|
var heading = me.refheading;
|
|
|
|
var altitudeft = me.refaltitudeft;
|
|
|
|
var lowaltft = me.reflowaltft;
|
|
|
|
var basealtft = me.basealtitudeft;
|
2021-02-18 23:17:21 +00:00
|
|
|
var alert_level = me.terrain_alert.getValue();
|
2021-02-11 22:46:04 +00:00
|
|
|
|
2021-02-12 23:38:43 +00:00
|
|
|
var side = (math.mod(me.radar_beacon,2)==0) ? "L" : "R";
|
|
|
|
var a = int(me.radar_beacon/2);
|
2021-02-16 23:30:26 +00:00
|
|
|
var col = a + 0.5;
|
2021-02-12 23:38:43 +00:00
|
|
|
|
2021-02-12 23:39:38 +00:00
|
|
|
if (side == "R") {
|
2021-02-16 23:30:26 +00:00
|
|
|
col = -col;
|
2021-02-12 23:38:43 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 20:02:32 +00:00
|
|
|
var trn = me.terrlayer[side ~ a];
|
2021-02-12 23:38:43 +00:00
|
|
|
|
2021-02-14 20:02:32 +00:00
|
|
|
var len = size(trn);
|
|
|
|
var range = me.range;
|
2021-02-11 22:46:04 +00:00
|
|
|
|
2021-02-14 20:02:32 +00:00
|
|
|
var tiles = me.tile_list;
|
2021-02-13 10:21:29 +00:00
|
|
|
|
2021-02-21 22:01:20 +00:00
|
|
|
#var proj_lon = pos_lon + ((col * (range/30) * math.sin(DEG2RAD * (heading - 90))) / 40);
|
|
|
|
#var proj_lat = pos_lat + ((col * (range/30) * math.cos(DEG2RAD * (heading - 90))) / 40);
|
|
|
|
|
|
|
|
# if me.tileradiusw == 20
|
|
|
|
var range_20f = range / 18.75;
|
|
|
|
var heading_sin = math.sin(DEG2RAD * heading);
|
|
|
|
var heading_cos = math.cos(DEG2RAD * heading);
|
|
|
|
|
|
|
|
var proj_lon = pos_lon + ((col * range_20f * math.sin(DEG2RAD * (heading - 90))) / 60);
|
|
|
|
var proj_lat = pos_lat + ((col * range_20f * math.cos(DEG2RAD * (heading - 90))) / 60);
|
2021-02-12 23:38:43 +00:00
|
|
|
|
2021-02-14 20:02:32 +00:00
|
|
|
var elevft = [];
|
2021-02-12 23:38:43 +00:00
|
|
|
|
2021-02-16 23:30:26 +00:00
|
|
|
me.radar_cleared = 0;
|
|
|
|
|
2021-02-14 20:02:32 +00:00
|
|
|
for (var row = 0; row < len; row += 1) {
|
2021-02-12 23:38:43 +00:00
|
|
|
|
2021-02-14 20:02:32 +00:00
|
|
|
if (trn[row] == nil) {
|
|
|
|
append(elevft,-1);
|
|
|
|
continue;
|
|
|
|
}
|
2021-02-13 22:57:09 +00:00
|
|
|
|
2021-02-21 22:01:20 +00:00
|
|
|
var point_lon = proj_lon + ((row * range_20f / 60) * heading_sin);
|
|
|
|
var point_lat = proj_lat + ((row * range_20f / 60) * heading_cos);
|
2021-02-14 20:02:32 +00:00
|
|
|
|
|
|
|
var elev = me.get_elevation(point_lat, point_lon);
|
|
|
|
var grad = 0; #black
|
2021-02-21 15:59:17 +00:00
|
|
|
if (elev != nil) {
|
|
|
|
if (elev>me.max_altitude) me.max_altitude = elev;
|
|
|
|
if (me.is_terrain) {
|
|
|
|
if (elev<me.min_altitude) me.min_altitude = elev;
|
2021-02-16 23:30:26 +00:00
|
|
|
if (elev < basealtft) grad = 0; # < 400 near runway use blank
|
2021-02-15 22:12:07 +00:00
|
|
|
else {
|
|
|
|
var diff = elev - altitudeft;
|
|
|
|
if (diff>=0) {
|
|
|
|
grad = int(diff/1000) + 3;
|
|
|
|
if (grad>5) grad = 5;
|
2021-02-18 23:17:21 +00:00
|
|
|
if (alert_level > 0 and a < 6 and grad > 3) {
|
|
|
|
if (alert_level == 1 and (grad == 3 or grad == 4)) grad = 12; # solid yellow
|
|
|
|
else if (alert_level == 2 and grad == 5) grad = 13; # solid red
|
|
|
|
}
|
2021-02-15 22:12:07 +00:00
|
|
|
} else {
|
2021-02-16 23:30:26 +00:00
|
|
|
if (me.hialtmode == 0) {
|
|
|
|
if (diff>=lowaltft) grad = 3; # lite yellow
|
|
|
|
else {
|
2021-02-17 23:03:33 +00:00
|
|
|
grad = int(diff/1000) + 2;
|
2021-02-16 23:30:26 +00:00
|
|
|
if (grad<0) grad = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (diff>=lowaltft) grad = 3; # lite yellow
|
|
|
|
else {
|
|
|
|
if (me.bands_range > 0 and elev > me.bands_minalt) {
|
2021-02-21 15:59:17 +00:00
|
|
|
grad = 9 - int((me.bands_maxalt - elev) / me.bands_range);
|
|
|
|
if (grad>9) grad = 9; # solid green
|
|
|
|
else if (grad<6) grad = 6; #light green
|
2021-02-16 23:30:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-13 10:21:29 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-15 22:12:07 +00:00
|
|
|
} else {
|
2021-02-21 15:59:17 +00:00
|
|
|
grad = 11; #water/cyan
|
2021-02-12 23:38:43 +00:00
|
|
|
}
|
2021-02-14 20:02:32 +00:00
|
|
|
append(elevft,grad); # 0-5
|
|
|
|
} else {
|
2021-02-16 23:30:26 +00:00
|
|
|
append(elevft,0); # no data - black (magenta)
|
2021-02-12 23:38:43 +00:00
|
|
|
}
|
2021-02-14 20:02:32 +00:00
|
|
|
|
|
|
|
}
|
2021-02-12 23:38:43 +00:00
|
|
|
|
2021-02-21 15:59:17 +00:00
|
|
|
if (me.min_altitude > me.max_altitude) me.min_altitude = me.max_altitude; # occurs on sea areas
|
|
|
|
|
2021-02-14 20:02:32 +00:00
|
|
|
for (var r=0; r < len; r+=1) {
|
|
|
|
var imgx = elevft[r];
|
|
|
|
if (imgx == -1) continue;
|
|
|
|
if (imgx < 1) trn[r].hide();
|
|
|
|
else trn[r].setFile(me.imgpath ~ me.tile_list[imgx]).show();
|
|
|
|
}
|
2021-02-12 23:38:43 +00:00
|
|
|
|
|
|
|
me.radar_beacon += 1;
|
2021-02-14 20:02:32 +00:00
|
|
|
if (me.radar_beacon >= (me.tileradiusw*2)) {
|
|
|
|
me.restart_beacon();
|
2021-02-11 22:46:04 +00:00
|
|
|
}
|
2021-02-16 23:30:26 +00:00
|
|
|
|
2021-02-11 22:46:04 +00:00
|
|
|
me.fetching = 0;
|
|
|
|
};
|
|
|
|
|
2021-02-14 20:02:32 +00:00
|
|
|
var update_altitudes = func {
|
2021-02-18 23:17:21 +00:00
|
|
|
|
2021-02-14 20:02:32 +00:00
|
|
|
me.terrain_minalt.setValue(me.min_altitude);
|
|
|
|
me.terrain_maxalt.setValue(me.max_altitude);
|
2021-02-16 23:30:26 +00:00
|
|
|
|
2021-02-28 21:22:36 +00:00
|
|
|
var altdif = me.max_altitude - me.refaltitudeft;
|
|
|
|
if (altdif <= 0) {
|
|
|
|
if (altdif >= me.reflowaltft) me.terrain_maxcol.setValue(1);
|
|
|
|
else me.terrain_maxcol.setValue(0);
|
|
|
|
} else {
|
|
|
|
if (altdif>2000) me.terrain_maxcol.setValue(2);
|
|
|
|
else me.terrain_maxcol.setValue(1);
|
|
|
|
}
|
|
|
|
|
2021-02-21 15:59:17 +00:00
|
|
|
if (me.avg_minalt == 9999) {
|
|
|
|
me.avg_minalt = me.min_altitude;
|
|
|
|
me.avg_maxalt = me.max_altitude;
|
|
|
|
} else {
|
|
|
|
#if (me.min_altitude < me.avg_minalt) me.avg_minalt = me.min_altitude;else
|
|
|
|
me.avg_minalt = math.round((me.avg_minalt * 2 + me.min_altitude) / 3);
|
|
|
|
#if (me.max_altitude > me.avg_maxalt) me.avg_maxalt = me.max_altitude;else
|
|
|
|
me.avg_maxalt = math.round((me.avg_maxalt * 2 + me.max_altitude) / 3);
|
|
|
|
}
|
|
|
|
|
2021-03-01 20:42:28 +00:00
|
|
|
me.avg_peakalt = me.avg_maxalt - me.avg_minalt;
|
|
|
|
|
2021-02-18 23:17:21 +00:00
|
|
|
if (me.onground == 0 and (me.max_altitude + 250) < me.refaltitudeft) { # 250 ft tollerance
|
2021-02-17 23:03:33 +00:00
|
|
|
me.hialtmode = 1;
|
2021-02-28 21:22:36 +00:00
|
|
|
var range = math.min(2400,(me.avg_maxalt - me.avg_minalt)) - 400;
|
|
|
|
if (range < 1900) { # min elev number
|
2021-02-21 15:59:17 +00:00
|
|
|
me.bands_range = 0;
|
2021-02-22 20:18:22 +00:00
|
|
|
} else {
|
2021-02-28 21:22:36 +00:00
|
|
|
me.bands_range = int(range / 4);
|
2021-02-21 15:59:17 +00:00
|
|
|
me.bands_maxalt = me.avg_maxalt;
|
2021-02-28 21:22:36 +00:00
|
|
|
me.bands_minalt = math.max( me.avg_maxalt - range, me.avg_minalt + 400 );
|
2021-02-21 15:59:17 +00:00
|
|
|
}
|
2021-02-16 23:30:26 +00:00
|
|
|
} else {
|
|
|
|
me.hialtmode = 0;
|
2021-02-21 15:59:17 +00:00
|
|
|
#me.avg_minalt = 9999;
|
2021-02-16 23:30:26 +00:00
|
|
|
}
|
2021-02-18 23:17:21 +00:00
|
|
|
|
|
|
|
me.min_altitude = 9999;
|
|
|
|
me.max_altitude = -9999;
|
2021-02-16 23:30:26 +00:00
|
|
|
|
2021-02-14 20:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var restart_beacon = func {
|
|
|
|
me.radar_beacon = 0;
|
|
|
|
me.radar_cycle += 1;
|
2021-02-16 23:30:26 +00:00
|
|
|
me.reference = nil;
|
2021-02-14 20:02:32 +00:00
|
|
|
};
|
|
|
|
|
2021-02-11 22:46:04 +00:00
|
|
|
var init = func {
|
2021-02-12 23:38:43 +00:00
|
|
|
#print('TERRAIN init');
|
2021-02-21 22:01:20 +00:00
|
|
|
me.tile = 33;
|
2021-02-11 22:46:04 +00:00
|
|
|
me.fetching = 0;
|
|
|
|
me.fetchRad = me.model.fetchRad; # Radius of radar layer to fetch
|
|
|
|
me.range = me.model.rangeNm; # Range of Navigation Display
|
|
|
|
me.viewport_radius = me.getOption('viewport_radius', 670);
|
2021-02-17 23:03:33 +00:00
|
|
|
me.imgpath = get_local_path('res/terrainv2/');
|
2021-02-14 20:02:32 +00:00
|
|
|
me.radar_beacon = 0;
|
|
|
|
me.radar_cycle = 0;
|
|
|
|
me.radar_cleared = 1;
|
2021-02-21 22:01:20 +00:00
|
|
|
me.request_clear = 0;
|
2021-02-14 20:02:32 +00:00
|
|
|
me.min_altitude = 9999;
|
|
|
|
me.max_altitude = -9999;
|
2021-02-21 15:59:17 +00:00
|
|
|
me.avg_minalt = 9999;
|
|
|
|
me.avg_maxalt = -9999;
|
2021-03-01 20:42:28 +00:00
|
|
|
me.avg_peakalt = 0;
|
2021-02-28 21:22:36 +00:00
|
|
|
me.maxalt_col = 0; # 0 = grn, 1 = yel, 2 = red
|
2021-02-16 23:30:26 +00:00
|
|
|
me.bands_minalt = 0;
|
|
|
|
me.bands_maxalt = 0;
|
|
|
|
me.bands_range = 0;
|
2021-02-15 22:12:07 +00:00
|
|
|
me.basealtitudeft = nil;
|
|
|
|
me.reference = nil;
|
2021-02-15 22:59:00 +00:00
|
|
|
me.onfailure = 0;
|
2021-02-16 23:30:26 +00:00
|
|
|
me.hialtmode = 0; # high aircraft relative altitude mode
|
2021-02-17 23:03:33 +00:00
|
|
|
me.checkarrival = 0;
|
|
|
|
me.onground = 1;
|
2021-02-11 22:46:04 +00:00
|
|
|
|
|
|
|
var tile = me.tile;
|
|
|
|
|
|
|
|
var gx = int(me.viewport_radius / tile);
|
|
|
|
me.tileradius = gx;
|
|
|
|
|
2021-02-21 22:01:20 +00:00
|
|
|
var limx = int((512/tile)+0.5); # display width is smaller than height
|
2021-02-14 20:02:32 +00:00
|
|
|
me.tileradiusw = limx;
|
|
|
|
|
|
|
|
me.terrlayer = {};
|
2021-02-11 22:46:04 +00:00
|
|
|
|
2021-02-14 20:02:32 +00:00
|
|
|
var centx = 0;
|
2021-02-12 23:38:43 +00:00
|
|
|
var centy = -me.viewport_radius;
|
2021-02-11 22:46:04 +00:00
|
|
|
|
2021-02-13 22:00:50 +00:00
|
|
|
var group = me.group.createChild("group").set("z-index", -100); #me.element
|
|
|
|
|
2021-02-14 20:02:32 +00:00
|
|
|
for (var c=0; c<limx; c+=1) {
|
2021-02-11 22:46:04 +00:00
|
|
|
var hh = c * tile;
|
2021-02-12 23:38:43 +00:00
|
|
|
var mx = (c == 0) ? gx : int(math.sqrt(gx*gx-c*c) + 0.5);
|
2021-02-13 22:57:09 +00:00
|
|
|
var my = int(c*4/gx);
|
2021-02-12 23:38:43 +00:00
|
|
|
var py = centy + (gx-1) * tile;
|
2021-02-11 22:46:04 +00:00
|
|
|
var pxr = centx+(c*tile);
|
|
|
|
var pxl = centx-(c*tile)-tile;
|
|
|
|
var grplx = [];
|
|
|
|
var grprx = [];
|
|
|
|
for (var r=0; r<mx; r+=1) {
|
2021-02-13 22:57:09 +00:00
|
|
|
if (r<my) {
|
|
|
|
append(grplx , nil); #skip
|
|
|
|
append(grprx , nil);
|
|
|
|
} else {
|
|
|
|
append(grplx , group.createChild("image").setSize(tile,tile).setTranslation(pxl,py).hide());
|
|
|
|
append(grprx , group.createChild("image").setSize(tile,tile).setTranslation(pxr,py).hide());
|
|
|
|
}
|
2021-02-11 22:46:04 +00:00
|
|
|
py-=tile;
|
|
|
|
}
|
|
|
|
me.terrlayer["L" ~ c] = grplx;
|
|
|
|
me.terrlayer["R" ~ c] = grprx;
|
|
|
|
}
|
2021-02-14 20:02:32 +00:00
|
|
|
|
2021-02-17 23:03:33 +00:00
|
|
|
setlistener("/instrumentation/mk-viii/inputs/discretes/ta-tcf-inhibit", func{ # detect GPWS switch status
|
|
|
|
me.onfailure = getprop("/instrumentation/mk-viii/inputs/discretes/ta-tcf-inhibit");
|
2021-02-24 22:00:46 +00:00
|
|
|
},1,0);
|
2021-02-15 22:59:00 +00:00
|
|
|
|
2021-02-11 22:46:04 +00:00
|
|
|
};
|
|
|
|
|
2021-02-13 10:21:29 +00:00
|
|
|
var clear = func {
|
|
|
|
|
2021-02-14 20:02:32 +00:00
|
|
|
if (me.radar_cleared == 0) {
|
|
|
|
me.radar_cleared = 1;
|
|
|
|
for (var c=0; c<me.tileradiusw; c+=1 ) {
|
|
|
|
var rowL = me.terrlayer["L" ~ c];
|
2021-02-13 10:21:29 +00:00
|
|
|
var rowR = me.terrlayer["R" ~ c];
|
|
|
|
var len = size(rowL);
|
|
|
|
for (var r=0; r<len; r+=1) {
|
2021-02-13 22:57:09 +00:00
|
|
|
if (rowL[r] != nil) {
|
|
|
|
rowL[r].hide();
|
|
|
|
rowR[r].hide();
|
|
|
|
}
|
2021-02-14 20:02:32 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-13 10:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-02-11 22:46:04 +00:00
|
|
|
var draw = func {
|
2021-02-14 22:11:52 +00:00
|
|
|
|
|
|
|
if(me.fetching) return;
|
2021-02-15 22:12:07 +00:00
|
|
|
|
2021-02-21 15:59:17 +00:00
|
|
|
if (pts.Sim.pause.getBoolValue()) return;
|
|
|
|
|
2021-02-15 22:59:00 +00:00
|
|
|
if (me.onfailure == 1) {
|
|
|
|
me.clear();
|
|
|
|
me.restart_beacon();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-21 15:59:17 +00:00
|
|
|
if (me.layer.display_changed == 1) {
|
|
|
|
me.layer.display_changed = 0;
|
|
|
|
me.clear();
|
2021-02-28 21:22:36 +00:00
|
|
|
me.min_altitude = 9999;
|
|
|
|
me.max_altitude = -9999;
|
|
|
|
terrain_maxalt.setValue(-9999);
|
2021-02-21 15:59:17 +00:00
|
|
|
me.reference = nil;
|
|
|
|
}
|
|
|
|
|
2021-02-16 23:30:26 +00:00
|
|
|
if (me.reference == nil) { # update aircraft reference
|
2021-02-15 22:12:07 +00:00
|
|
|
|
|
|
|
var ref = geo.aircraft_position();
|
|
|
|
me.reference = ref;
|
|
|
|
if (ref != nil) {
|
2021-02-21 15:59:17 +00:00
|
|
|
|
2021-02-16 23:30:26 +00:00
|
|
|
me.refheading = getprop("orientation/heading-magnetic-deg");
|
2021-02-15 22:12:07 +00:00
|
|
|
|
2021-02-28 21:22:36 +00:00
|
|
|
var refalt = int(getprop("/position/altitude-ft")); #int(ref.alt() * 3.2808399);
|
2021-02-17 23:03:33 +00:00
|
|
|
me.refaltitudeft = refalt;
|
2021-02-28 21:22:36 +00:00
|
|
|
me.groundaltft = int(getprop("/position/ground-elev-ft"));
|
2021-02-16 23:30:26 +00:00
|
|
|
me.reflowaltft = (pts.Gear.position[1].getValue()) ? -250 : -500;
|
2021-02-28 21:22:36 +00:00
|
|
|
me.onground = pts.Gear.wow[0].getValue();
|
2021-02-18 23:17:21 +00:00
|
|
|
|
|
|
|
if (me.min_altitude != 9999) me.update_altitudes();
|
2021-02-28 21:22:36 +00:00
|
|
|
|
2021-03-01 20:42:28 +00:00
|
|
|
var vspeed30s = int(getprop("velocities/vertical-speed-fps") * 30);
|
|
|
|
if (vspeed30s<-500) me.refaltitudeft = math.max(me.avg_minalt , me.refaltitudeft + vspeed30s);
|
|
|
|
|
2021-02-28 21:22:36 +00:00
|
|
|
if (me.basealtitudeft == nil) { # first basealt set
|
|
|
|
me.basealtitudeft = me.groundaltft + 400;
|
|
|
|
me.checkarrival = 1;
|
|
|
|
print("set REFALT [init]: "~me.basealtitudeft);
|
|
|
|
#} else if (fmgc.FMGCInternal.phase < 2) { # starting at phase < 2
|
|
|
|
# nothing to do
|
2021-02-21 15:59:17 +00:00
|
|
|
} else if (fmgc.FMGCInternal.phase == 5) {
|
|
|
|
if (me.checkarrival == 1) {
|
|
|
|
me.checkarrival = 0;
|
|
|
|
me.basealtitudeft = nil;
|
|
|
|
if (fmgc.FMGCInternal.arrApt != nil) {
|
|
|
|
var airport = airportinfo(fmgc.FMGCInternal.arrApt);
|
|
|
|
if (airport != nil) me.basealtitudeft = 400 + int(airport.elevation * M2FT);
|
|
|
|
print("set REFALT [arrApt]: "~me.basealtitudeft);
|
|
|
|
}
|
|
|
|
if (me.basealtitudeft == nil) {
|
|
|
|
me.basealtitudeft = 400 + me.avg_minalt; # that's fun
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (fmgc.FMGCInternal.phase == 6) {
|
|
|
|
if (me.checkarrival == 0) {
|
2021-02-21 22:01:20 +00:00
|
|
|
me.checkarrival = 1;
|
2021-02-21 15:59:17 +00:00
|
|
|
#me.basealtitudeft = 0;
|
|
|
|
}
|
|
|
|
} else if (fmgc.FMGCInternal.phase == 7) {
|
|
|
|
if (me.checkarrival == 0) {
|
2021-02-21 22:01:20 +00:00
|
|
|
me.checkarrival = 1;
|
2021-02-28 21:22:36 +00:00
|
|
|
me.basealtitudeft = me.groundaltft + 400;
|
2021-02-21 15:59:17 +00:00
|
|
|
print("set REFALT [done]: "~me.basealtitudeft);
|
|
|
|
}
|
2021-02-28 21:22:36 +00:00
|
|
|
} else if (fmgc.FMGCInternal.phase == 2) {
|
2021-03-01 20:42:28 +00:00
|
|
|
var expdaltft = me.groundaltft;
|
|
|
|
expdaltft += (me.avg_peakalt>400) ? 400 : 160;
|
2021-02-28 21:22:36 +00:00
|
|
|
if (me.basealtitudeft > expdaltft) {
|
|
|
|
me.basealtitudeft = expdaltft;
|
|
|
|
print("set REFALT [blwbase]: "~me.basealtitudeft);
|
|
|
|
}
|
2021-03-01 20:42:28 +00:00
|
|
|
} else if (fmgc.FMGCInternal.phase >= 2) {
|
|
|
|
var flatalt = (me.avg_peakalt>400) ? 400 : 160;
|
|
|
|
me.basealtitudeft = math.avg(me.basealtitudeft,flatalt + me.groundaltft,int(flatalt + me.avg_minalt));
|
2021-02-28 21:22:36 +00:00
|
|
|
#if (me.basealtitudeft > me.avg_maxalt) {
|
|
|
|
# if (me.avg_maxalt < 1000) me.basealtitudeft = 0; # 1000ft min elev number
|
|
|
|
# else me.basealtitudeft = int(400 + me.avg_minalt);
|
|
|
|
# print("set REFALT [blwmin]: "~me.basealtitudeft);
|
|
|
|
#}
|
|
|
|
#else if (me.basealtitudeft == 0 and me.avg_maxalt >= 1000) { # 1000ft min elev number
|
|
|
|
# me.basealtitudeft = int(400 + me.avg_minalt);
|
|
|
|
# print("set REFALT [abvmin]: "~me.basealtitudeft);
|
|
|
|
#}
|
2021-02-17 23:03:33 +00:00
|
|
|
}
|
2021-02-16 23:30:26 +00:00
|
|
|
|
2021-02-15 22:12:07 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 23:03:33 +00:00
|
|
|
} else {
|
|
|
|
|
2021-02-16 23:30:26 +00:00
|
|
|
var range = me.layer.map.getRange(); # Range of Navigation Display
|
|
|
|
var update_size = (range != me.range);
|
|
|
|
me.range = range;
|
2021-02-13 22:00:50 +00:00
|
|
|
|
2021-02-21 15:59:17 +00:00
|
|
|
if (update_size) {
|
2021-02-16 23:30:26 +00:00
|
|
|
me.request_clear = 1;
|
|
|
|
}
|
2021-02-11 22:46:04 +00:00
|
|
|
|
2021-02-16 23:30:26 +00:00
|
|
|
me.updateTerrain(); # left
|
2021-02-17 23:03:33 +00:00
|
|
|
me.updateTerrain(); # right
|
2021-02-16 23:30:26 +00:00
|
|
|
|
|
|
|
}
|
2021-02-12 23:38:43 +00:00
|
|
|
|
2021-02-24 22:00:46 +00:00
|
|
|
};
|