From ada64f22b76c964279c459167a51fddc22d03ac7 Mon Sep 17 00:00:00 2001 From: Inuyaksa Date: Sun, 11 Apr 2021 23:19:25 +0200 Subject: [PATCH] TERR - more consistent green areas display --- .../Instruments/ND/canvas/map/TERRAIN.symbol | 109 ++++++++++-------- 1 file changed, 61 insertions(+), 48 deletions(-) diff --git a/Models/Instruments/ND/canvas/map/TERRAIN.symbol b/Models/Instruments/ND/canvas/map/TERRAIN.symbol index f55dba20..9a652d4b 100644 --- a/Models/Instruments/ND/canvas/map/TERRAIN.symbol +++ b/Models/Instruments/ND/canvas/map/TERRAIN.symbol @@ -96,6 +96,9 @@ var updateTerrain = func { me.radar_cleared = 0; + var altmin = 9999; + var altmax = -9999; + for (var row = 0; row < len; row += 1) { if (trn[row] == nil) { @@ -111,17 +114,17 @@ var updateTerrain = func { var elev = me.get_elevation(point_lat, point_lon); var grad = 0; #black if (elev != nil) { - if (elev>me.max_altitude) me.max_altitude = elev; + if (elev>altmax) altmax = elev; if (me.is_terrain) { - if (elev=0) { grad = int(diff/1000) + 3; if (grad>5) grad = 5; - if (alert_level > 0 and a < 6 and grad > 3) { - if (alert_level == 1 and (grad == 3 or grad == 4)) grad = 12; # solid yellow + if (alert_level > 0 and a <= 6) { + if (alert_level == 1 and grad != 5) grad = 12; # solid yellow else if (alert_level == 2 and grad == 5) grad = 13; # solid red } } else { @@ -135,9 +138,13 @@ var updateTerrain = func { if (diff>=lowaltft) grad = 3; # lite yellow else { if (me.bands_range > 0 and elev > me.bands_minalt) { - 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 + if (elev >= me.green_altitude) grad = 9; # solid green + else { + grad = 8 - int((me.bands_maxalt - elev) / me.bands_range); # 9 - + #if (grad>9) grad = 9; # solid green + if (grad>8) grad = 8; # high green + else if (grad<6) grad = 6; #light green + } } } } @@ -153,8 +160,6 @@ var updateTerrain = func { } - if (me.min_altitude > me.max_altitude) me.min_altitude = me.max_altitude; # occurs on sea areas - for (var r=0; r < len; r+=1) { var imgx = elevft[r]; if (imgx == -1) continue; @@ -162,6 +167,20 @@ var updateTerrain = func { else trn[r].setFile(me.imgpath ~ me.tile_list[imgx]).show(); } + if (altmax != -9999) { + + if (altmin > altmax) altmin = altmax; # occurs on sea areas + + if (me.max_altitude == -9999) { + me.min_altitude = altmin; + me.max_altitude = altmax; + } else { + if (altminme.max_altitude) me.max_altitude = altmax; + } + + } + me.radar_beacon += 1; if (me.radar_beacon >= (me.tileradiusw*2)) { me.restart_beacon(); @@ -172,48 +191,49 @@ var updateTerrain = func { var update_altitudes = func { - me.terrain_minalt.setValue(me.min_altitude); - me.terrain_maxalt.setValue(me.max_altitude); + var maxalt = int(me.max_altitude); + me.terrain_minalt.setValue(int(me.min_altitude)); + me.terrain_maxalt.setValue(maxalt); - var altdif = me.max_altitude - me.refaltitudeft; + if (me.avg_maxalt == -9999) { + me.avg_minalt = int(me.min_altitude); + me.avg_maxalt = maxalt; + } else { + me.avg_minalt = math.avg(me.avg_minalt,me.min_altitude); + me.avg_maxalt = math.avg(me.avg_maxalt,maxalt); + } + + var altdif = maxalt - 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); + if (altdif>=2000) me.terrain_maxcol.setValue(2); else me.terrain_maxcol.setValue(1); } - if (me.avg_maxalt == -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); - } + me.avg_diffalt = me.avg_maxalt - me.avg_minalt; - me.avg_peakalt = me.avg_maxalt - me.avg_minalt; - - if (me.onground == 0 and (me.max_altitude + 250) < me.refaltitudeft) { # 250 ft tollerance + if (me.onground == 0 and (maxalt + 200) < me.refaltitudeft) { # 200 ft tollerance me.hialtmode = 1; - var mxrange = math.max(2400,int(me.avg_peakalt*0.25)); - var range = math.min(mxrange,(me.avg_maxalt - me.avg_minalt)) - 250; - if (range < 360) { # min elev number - me.bands_range = 0; - } else { - me.bands_range = int(range / 4); + var mxrange = math.max(1600,int((me.avg_maxalt - me.basealtitudeft) * 0.3)); + var range = math.min(mxrange,me.avg_diffalt); + if (range < 160) { # min elev number + me.bands_range = 0; + } else { me.bands_maxalt = me.avg_maxalt; - me.bands_minalt = math.max( me.avg_maxalt - range, me.avg_minalt + 400 ); + me.bands_minalt = math.max( me.avg_maxalt - range, me.avg_minalt + me.basealtitudeft ); + me.bands_range = int( (me.bands_maxalt - me.bands_minalt) / 4); } + me.green_altitude = math.max(maxalt - 1200, me.avg_maxalt - me.bands_range); } else { me.hialtmode = 0; #me.avg_minalt = 9999; } me.min_altitude = 9999; - me.max_altitude = -9999; + me.max_altitude = -9999; + me.avg_maxalt = -9999; } @@ -239,9 +259,10 @@ var init = func { me.request_clear = 0; me.min_altitude = 9999; me.max_altitude = -9999; + me.green_altitude = 0; # max altitude for solid green (peak color) me.avg_minalt = 9999; me.avg_maxalt = -9999; - me.avg_peakalt = nil; + me.avg_diffalt = nil; me.maxalt_col = 0; # 0 = grn, 1 = yel, 2 = red me.bands_minalt = 0; me.bands_maxalt = 0; @@ -335,9 +356,10 @@ var draw = func { if (me.layer.display_hidden == 1) { me.layer.display_hidden = 0; me.clear(); + me.terrain_maxalt.setValue(-9999); me.min_altitude = 9999; me.max_altitude = -9999; - me.terrain_maxalt.setValue(-9999); + me.avg_maxalt = -9999; me.reference = nil; } @@ -355,9 +377,9 @@ var draw = func { me.reflowaltft = (pts.Gear.position[1].getValue()) ? -250 : -500; me.onground = pts.Gear.wow[0].getValue(); - if (me.min_altitude != 9999) me.update_altitudes(); + if (me.max_altitude != -9999) me.update_altitudes(); - var flatalt = (me.avg_peakalt == nil or me.avg_peakalt>499) ? 400 : 140; + var flatalt = (me.avg_diffalt == nil or me.avg_diffalt>499) ? 400 : 180; var vspeed30s = int(getprop("velocities/vertical-speed-fps") * 30); if (vspeed30s<-500) me.refaltitudeft = math.max(me.avg_minalt , me.refaltitudeft + vspeed30s); @@ -404,19 +426,10 @@ var draw = func { print("set REFALT [blwbase]: "~me.basealtitudeft); } } else if (fmgc.FMGCInternal.phase >= 2) { - me.basealtitudeft = math.avg(me.basealtitudeft,flatalt + me.groundaltft,int(flatalt + me.avg_minalt)); - #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); - #} + if (me.avg_minalt != 9999) me.basealtitudeft = int(math.avg(me.basealtitudeft,flatalt + me.avg_minalt)); } - } + } } else {