2010-04-12 20:51:46 +00:00
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
########################################################
|
2010-04-12 20:51:46 +00:00
|
|
|
# routines to set up, transform and manage local weather
|
2011-07-03 21:39:01 +00:00
|
|
|
# Thorsten Renk, June 2011
|
2010-06-04 21:05:32 +00:00
|
|
|
# thermal model by Patrice Poly, April 2010
|
|
|
|
########################################################
|
|
|
|
|
|
|
|
# function purpose
|
|
|
|
#
|
|
|
|
# calc_geo to compute the latitude to meter conversion
|
|
|
|
# calc_d_sq to compute a distance square in local Cartesian approximation
|
2010-08-03 06:18:14 +00:00
|
|
|
# effect_volume_loop to check if the aircraft has entered an effect volume
|
2010-10-26 19:40:33 +00:00
|
|
|
# assemble_effect_array to store the size of the effect volume array
|
2010-08-03 06:18:14 +00:00
|
|
|
# add_vectors to add two vectors in polar coordinates
|
|
|
|
# wind_altitude_interpolation to interpolate aloft winds in altitude
|
|
|
|
# wind_interpolation to interpolate aloft winds in altitude and position
|
2011-01-05 12:36:10 +00:00
|
|
|
# get_slowdown_fraction to compute the effect of boundary layer wind slowdown
|
2010-06-04 21:05:32 +00:00
|
|
|
# interpolation_loop to continuously interpolate weather parameters between stations
|
|
|
|
# thermal_lift_start to start the detailed thermal model
|
2010-10-26 19:40:33 +00:00
|
|
|
# thermal_lift_loop to manage the detailed thermal lift model
|
|
|
|
# thermal_lift_stop to end the detailed thermal lift model
|
|
|
|
# wave_lift_start to start the detailed wave lift model
|
|
|
|
# wave_lift_loop to manage the detailed wave lift model
|
|
|
|
# wave_lift_stop to end the detailed wave lift model
|
2010-06-04 21:05:32 +00:00
|
|
|
# effect_volume_start to manage parameters when an effect volume is entered
|
|
|
|
# effect_volume_stop to manage parameters when an effect volume is left
|
|
|
|
# ts_factor (helper function for thermal lift model)
|
|
|
|
# tl_factor (helper function for thermal lift model)
|
|
|
|
# calcLift_max to calculate the maximal available thermal lift for given altitude
|
|
|
|
# calcLift to calculate the thermal lift at aircraft position
|
2010-10-26 19:40:33 +00:00
|
|
|
# calcWaveLift to calculate wave lift at aircraft position
|
2010-06-04 21:05:32 +00:00
|
|
|
# create_cloud_vec to place a single cloud into an array to be written later
|
|
|
|
# clear_all to remove all clouds, effect volumes and weather stations and stop loops
|
2010-06-15 18:54:44 +00:00
|
|
|
# create_detailed_cumulus_cloud to place multiple cloudlets into a box based on a size parameter
|
|
|
|
# create_cumulonimbus_cloud to place multiple cloudlets into a box
|
2011-07-03 21:39:01 +00:00
|
|
|
# create_cumulonimbus_cloud_rain to place multiple cloudlets into a box and add a rain layer beneath
|
2012-04-26 10:03:51 +00:00
|
|
|
# create_cumosys (wrapper to place a convective cloud system based on terrain coverage)
|
2010-06-04 21:05:32 +00:00
|
|
|
# cumulus_loop to place 25 Cumulus clouds each frame
|
|
|
|
# create_cumulus to place a convective cloud system based on terrain coverage
|
2010-10-26 19:40:33 +00:00
|
|
|
# recreate_cumulus to respawn convective clouds as part of the convective dynamics algorithm
|
2010-08-03 06:18:14 +00:00
|
|
|
# cumulus_exclusion_layer to create a layer with 'holes' left for thunderstorm placement
|
2010-06-04 21:05:32 +00:00
|
|
|
# create_rise_clouds to create a barrier cloud system
|
|
|
|
# create_streak to create a cloud streak
|
2010-08-03 06:18:14 +00:00
|
|
|
# create_hollow_layer to create a cloud layer in a hollow cylinder (better for performance)
|
|
|
|
# create_cloudbox to create a sophisticated cumulus cloud with different textures (experimental)
|
|
|
|
# terrain_presampling_start to initialize terrain presampling
|
|
|
|
# terrain_presampling_loop to sample 25 terrain points per frame
|
|
|
|
# terrain_presampling to sample terrain elevation at a random point within specified area
|
|
|
|
# terrain_presampling_analysis to analyze terrain presampling results
|
2010-10-26 19:40:33 +00:00
|
|
|
# wave_detection_loop to detect if and where wave lift should be placed (currently unfinished)
|
2010-08-03 06:18:14 +00:00
|
|
|
# get_convective_altitude to determine the altitude at which a Cumulus cloud is placed
|
|
|
|
# manage presampling to take proper action when a presampling call has been finished
|
|
|
|
# set_wind_model_flag to convert the wind model string into an integer flag
|
2010-10-26 19:40:33 +00:00
|
|
|
# set_texture_mix to determine the texture mix between smooth and rough cloud appearance
|
2010-06-04 21:05:32 +00:00
|
|
|
# create_effect_volume to create an effect volume
|
|
|
|
# set_weather_station to specify a weather station for interpolation
|
2011-06-13 19:57:21 +00:00
|
|
|
# set_atmosphere_ipoint to specify an interpolation point for visibility, haze and shading in the atmosphere
|
2010-08-03 06:18:14 +00:00
|
|
|
# set_wind_ipoint to set an aloft wind interpolation point
|
2011-03-19 13:03:28 +00:00
|
|
|
# set_wind_ipoint_metar to set a wind interpolation point from available ground METAR info where aloft is modelled
|
2010-08-03 06:18:14 +00:00
|
|
|
# showDialog to pop up a dialog window
|
2010-10-26 19:40:33 +00:00
|
|
|
# readFlags to read configuration flags from the property tree into Nasal variables at startup
|
2010-06-04 21:05:32 +00:00
|
|
|
# streak_wrapper wrapper to execute streak from menu
|
|
|
|
# convection wrapper wrapper to execute convective clouds from menu
|
|
|
|
# barrier wrapper wrapper to execute barrier clouds from menu
|
|
|
|
# single_cloud_wrapper wrapper to create single cloud from menu
|
|
|
|
# layer wrapper wrapper to create layer from menu
|
2010-08-03 06:18:14 +00:00
|
|
|
# box wrapper wrapper to create a cloudbox (experimental)
|
2010-10-26 19:40:33 +00:00
|
|
|
# set_aloft wrapper wrapper to create aloft winds from menu
|
2010-06-04 21:05:32 +00:00
|
|
|
# set_tile to call a weather tile creation from menu
|
|
|
|
# startup to prepare the package at startup
|
2010-10-26 19:40:33 +00:00
|
|
|
# test to serve as a testbed for new functions
|
|
|
|
|
|
|
|
# object purpose
|
|
|
|
|
|
|
|
# weatherStation to store info about weather conditions
|
2011-06-13 19:57:21 +00:00
|
|
|
# atmopshereIpoint to store info about haze and light propagation in the atmosphere
|
2011-03-19 13:03:28 +00:00
|
|
|
# windIpoint to store an interpolation point of the windfield
|
2010-10-26 19:40:33 +00:00
|
|
|
# effectVolume to store effect volume info and provide methods to move and time-evolve effect volumes
|
|
|
|
# thermalLift to store thermal info and provide methods to move and time-evolve a thermal
|
|
|
|
# waveLift to store wave info
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
###################################
|
|
|
|
# geospatial helper functions
|
|
|
|
###################################
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
var calc_geo = func(clat) {
|
|
|
|
|
|
|
|
lon_to_m = math.cos(clat*math.pi/180.0) * lat_to_m;
|
|
|
|
m_to_lon = 1.0/lon_to_m;
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
weather_dynamics.lon_to_m = lon_to_m;
|
|
|
|
weather_dynamics.m_to_lon = m_to_lon;
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
var calc_d_sq = func (lat1, lon1, lat2, lon2) {
|
|
|
|
|
|
|
|
var x = (lat1 - lat2) * lat_to_m;
|
|
|
|
var y = (lon1 - lon2) * lon_to_m;
|
|
|
|
|
|
|
|
return (x*x + y*y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
###################################
|
|
|
|
# effect volume management loop
|
|
|
|
###################################
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
var effect_volume_loop = func (index, n_active) {
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
|
|
|
|
if (local_weather_running_flag == 0) {return;}
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
var n = 25;
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
var esize = n_effectVolumeArray;
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
var viewpos = geo.aircraft_position();
|
|
|
|
var active_counter = n_active;
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
var i_max = index + n;
|
2010-06-04 21:05:32 +00:00
|
|
|
if (i_max > esize) {i_max = esize;}
|
|
|
|
|
|
|
|
for (var i = index; i < i_max; i = i+1)
|
|
|
|
{
|
2010-10-26 19:40:33 +00:00
|
|
|
var e = effectVolumeArray[i];
|
|
|
|
|
|
|
|
var flag = 0; # default assumption is that we're not in the volume
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var ealt_min = e.alt_low * ft_to_m;
|
|
|
|
var ealt_max = e.alt_high * ft_to_m;
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
if ((viewpos.alt() > ealt_min) and (viewpos.alt() < ealt_max)) # we are in the correct alt range
|
|
|
|
{
|
2010-06-04 21:05:32 +00:00
|
|
|
# so we load geometry next
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
var geometry = e.geometry;
|
|
|
|
var elat = e.lat;
|
|
|
|
var elon = e.lon;
|
|
|
|
var rx = e.r1;
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
if (geometry == 1) # we have a cylinder
|
|
|
|
{
|
2010-06-04 21:05:32 +00:00
|
|
|
var d_sq = calc_d_sq(viewpos.lat(), viewpos.lon(), elat, elon);
|
|
|
|
if (d_sq < (rx*rx)) {flag =1;}
|
2010-04-12 20:51:46 +00:00
|
|
|
}
|
2010-06-04 21:05:32 +00:00
|
|
|
else if (geometry == 2) # we have an elliptic shape
|
2010-04-12 20:51:46 +00:00
|
|
|
{
|
2010-06-04 21:05:32 +00:00
|
|
|
# get orientation
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
var ry = e.r2;
|
|
|
|
var phi = e.phi;
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
phi = phi * math.pi/180.0;
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
# first get unrotated coordinates
|
2010-06-04 21:05:32 +00:00
|
|
|
var xx = (viewpos.lon() - elon) * lon_to_m;
|
|
|
|
var yy = (viewpos.lat() - elat) * lat_to_m;
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
# then rotate to align with the shape
|
|
|
|
var x = xx * math.cos(phi) - yy * math.sin(phi);
|
|
|
|
var y = yy * math.cos(phi) + xx * math.sin(phi);
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
# then check elliptic condition
|
|
|
|
if ((x*x)/(rx*rx) + (y*y)/(ry*ry) <1) {flag = 1;}
|
|
|
|
}
|
2010-06-04 21:05:32 +00:00
|
|
|
else if (geometry == 3) # we have a rectangular shape
|
2010-04-12 20:51:46 +00:00
|
|
|
{
|
2010-06-04 21:05:32 +00:00
|
|
|
# get orientation
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
var ry = e.r2;
|
|
|
|
var phi = e.phi;
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
phi = phi * math.pi/180.0;
|
2010-04-12 20:51:46 +00:00
|
|
|
# first get unrotated coordinates
|
2010-06-04 21:05:32 +00:00
|
|
|
var xx = (viewpos.lon() - elon) * lon_to_m;
|
|
|
|
var yy = (viewpos.lat() - elat) * lat_to_m;
|
2010-04-12 20:51:46 +00:00
|
|
|
# then rotate to align with the shape
|
|
|
|
var x = xx * math.cos(phi) - yy * math.sin(phi);
|
|
|
|
var y = yy * math.cos(phi) + xx * math.sin(phi);
|
|
|
|
# then check rectangle condition
|
|
|
|
if ((x>-rx) and (x<rx) and (y>-ry) and (y<ry)) {flag = 1;}
|
|
|
|
}
|
2010-06-04 21:05:32 +00:00
|
|
|
} # end if altitude
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
# if flag ==1 at this point, we are inside the effect volume
|
|
|
|
# but we only need to take action on entering and leaving, so we check also active_flag
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
# if (flag==1) {print("Inside volume");}
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var active_flag = e.active_flag;
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
if ((flag==1) and (active_flag ==0)) # we just entered the node
|
|
|
|
{
|
2010-10-26 19:40:33 +00:00
|
|
|
#print("Entered volume");
|
|
|
|
e.active_flag = 1;
|
2010-04-12 20:51:46 +00:00
|
|
|
effect_volume_start(e);
|
|
|
|
}
|
2010-06-04 21:05:32 +00:00
|
|
|
else if ((flag==0) and (active_flag ==1)) # we left an active node
|
2010-04-12 20:51:46 +00:00
|
|
|
{
|
|
|
|
#print("Left volume!");
|
2010-10-26 19:40:33 +00:00
|
|
|
e.active_flag = 0;
|
2010-04-12 20:51:46 +00:00
|
|
|
effect_volume_stop(e);
|
|
|
|
}
|
2010-06-04 21:05:32 +00:00
|
|
|
if (flag==1) {active_counter = active_counter + 1;} # we still count the active volumes
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
} # end foreach
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
# at this point, all active effect counters should have been set to zero if we're outside all volumes
|
|
|
|
# however there seem to be rare configurations of overlapping volumes for which this doesn't happen
|
|
|
|
# therefore we zero them for redundancy here so that the interpolation loop can take over
|
|
|
|
# and set the properties correctly for outside
|
|
|
|
|
|
|
|
|
|
|
|
if (i == esize) # we check the number of actives and reset all counters
|
|
|
|
{
|
|
|
|
if (active_counter == 0)
|
|
|
|
{
|
|
|
|
var vNode = props.globals.getNode("local-weather/effect-volumes", 1);
|
|
|
|
vNode.getChild("number-active-vis").setValue(0);
|
|
|
|
vNode.getChild("number-active-snow").setValue(0);
|
|
|
|
vNode.getChild("number-active-rain").setValue(0);
|
|
|
|
vNode.getChild("number-active-lift").setValue(0);
|
2010-06-15 18:54:44 +00:00
|
|
|
vNode.getChild("number-active-turb").setValue(0);
|
2010-10-26 19:40:33 +00:00
|
|
|
vNode.getChild("number-active-sat").setValue(0);
|
2010-06-04 21:05:32 +00:00
|
|
|
}
|
|
|
|
#print("n_active: ", active_counter);
|
|
|
|
active_counter = 0; i = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
# and we repeat the loop as long as the control flag is set
|
|
|
|
|
|
|
|
|
|
|
|
if (getprop(lw~"effect-loop-flag") ==1) {settimer( func {effect_volume_loop(i, active_counter); },0);}
|
2010-04-12 20:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
###################################
|
|
|
|
# assemble effect volume array
|
|
|
|
###################################
|
|
|
|
|
|
|
|
|
|
|
|
var assemble_effect_array = func {
|
|
|
|
|
|
|
|
n_effectVolumeArray = size(effectVolumeArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# vector addition
|
|
|
|
###################################
|
|
|
|
|
|
|
|
var add_vectors = func (phi1, r1, phi2, r2) {
|
|
|
|
|
|
|
|
phi1 = phi1 * math.pi/180.0;
|
|
|
|
phi2 = phi2 * math.pi/180.0;
|
|
|
|
|
|
|
|
var x1 = r1 * math.sin(phi1);
|
|
|
|
var x2 = r2 * math.sin(phi2);
|
|
|
|
|
|
|
|
var y1 = r1 * math.cos(phi1);
|
|
|
|
var y2 = r2 * math.cos(phi2);
|
|
|
|
|
|
|
|
var x = x1+x2;
|
|
|
|
var y = y1+y2;
|
|
|
|
|
|
|
|
var phi = math.atan2(x,y) * 180.0/math.pi;
|
|
|
|
var r = math.sqrt(x*x + y*y);
|
|
|
|
|
|
|
|
var vec = [];
|
|
|
|
|
|
|
|
append(vec, phi);
|
|
|
|
append(vec,r);
|
|
|
|
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# windfield altitude interpolation
|
|
|
|
###################################
|
|
|
|
|
|
|
|
|
|
|
|
var wind_altitude_interpolation = func (altitude, w) {
|
|
|
|
|
|
|
|
if (altitude < wind_altitude_array[0]) {var alt_wind = wind_altitude_array[0];}
|
|
|
|
else if (altitude > wind_altitude_array[8]) {var alt_wind = 0.99* wind_altitude_array[8];}
|
2011-03-19 13:03:28 +00:00
|
|
|
else {var alt_wind = altitude;}
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
for (var i = 0; i<9; i=i+1)
|
|
|
|
{if (alt_wind < wind_altitude_array[i]) {break;}}
|
|
|
|
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
#var altNodeMin = w.getChild("altitude",i-1);
|
|
|
|
#var altNodeMax = w.getChild("altitude",i);
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
#var vmin = altNodeMin.getNode("windspeed-kt").getValue();
|
|
|
|
#var vmax = altNodeMax.getNode("windspeed-kt").getValue();
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
var vmin = w.alt[i-1].v;
|
|
|
|
var vmax = w.alt[i].v;
|
|
|
|
|
|
|
|
#var dir_min = altNodeMin.getNode("wind-from-heading-deg").getValue();
|
|
|
|
#var dir_max = altNodeMax.getNode("wind-from-heading-deg").getValue();
|
|
|
|
|
|
|
|
var dir_min = w.alt[i-1].d;
|
|
|
|
var dir_max = w.alt[i].d;
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
var f = (alt_wind - wind_altitude_array[i-1])/(wind_altitude_array[i] - wind_altitude_array[i-1]);
|
|
|
|
|
|
|
|
var res = add_vectors(dir_min, (1-f) * vmin, dir_max, f * vmax);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
|
|
|
|
###################################
|
|
|
|
# windfield spatial interpolation
|
|
|
|
###################################
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
var wind_interpolation = func (lat, lon, alt) {
|
|
|
|
|
|
|
|
var sum_norm = 0;
|
|
|
|
var sum_wind = [0,0];
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
var wsize = size(windIpointArray);
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
for (var i = 0; i < wsize; i=i+1) {
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
|
|
|
|
var w = windIpointArray[i];
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
var wpos = geo.Coord.new();
|
2011-03-19 13:03:28 +00:00
|
|
|
wpos.set_latlon(w.lat,w.lon,1000.0);
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
var ppos = geo.Coord.new();
|
|
|
|
ppos.set_latlon(lat,lon,1000.0);
|
|
|
|
|
|
|
|
var d = ppos.distance_to(wpos);
|
|
|
|
if (d <100.0) {d = 100.0;} # to prevent singularity at zero
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
sum_norm = sum_norm + (1./d) * w.weight;
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
var res = wind_altitude_interpolation(alt,w);
|
2011-03-19 13:03:28 +00:00
|
|
|
|
|
|
|
sum_wind = add_vectors(sum_wind[0], sum_wind[1], res[0], (res[1]/d) * w.weight);
|
|
|
|
|
|
|
|
# gradually fade in the interpolation weight of newly added points to
|
|
|
|
# avoid sudden jumps
|
|
|
|
|
|
|
|
if (w.weight < 1.0) {w.weight = w.weight + 0.02;}
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sum_wind[1] = sum_wind[1] /sum_norm;
|
|
|
|
|
|
|
|
return sum_wind;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-05 12:36:10 +00:00
|
|
|
###################################
|
|
|
|
# boundary layer computations
|
|
|
|
###################################
|
|
|
|
|
|
|
|
|
|
|
|
var get_slowdown_fraction = func {
|
|
|
|
|
|
|
|
var tile_index = getprop(lw~"tiles/tile[4]/tile-index");
|
|
|
|
var altitude_agl = getprop("/position/altitude-agl-ft");
|
|
|
|
var altitude = getprop("/position/altitude-ft");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (presampling_flag == 0)
|
|
|
|
{
|
|
|
|
var base_layer_thickness = 600.0;
|
|
|
|
var f_slow = 1.0/3.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var alt_median = alt_50_array[tile_index - 1];
|
|
|
|
var alt_difference = alt_median - (altitude - altitude_agl);
|
|
|
|
var base_layer_thickness = 150.0;
|
|
|
|
|
|
|
|
# get the boundary layer size dependent on terrain altitude above terrain median
|
|
|
|
|
|
|
|
if (alt_difference > 0.0) # we're low and the boundary layer grows
|
|
|
|
{var boundary_alt = base_layer_thickness + 0.3 * alt_difference;}
|
|
|
|
else # the boundary layer shrinks
|
|
|
|
{var boundary_alt = base_layer_thickness + 0.1 * alt_difference;}
|
|
|
|
|
|
|
|
if (boundary_alt < 50.0){boundary_alt = 50.0;}
|
|
|
|
if (boundary_alt > 3000.0) {boundary_alt = 3000.0;}
|
|
|
|
|
|
|
|
# get the boundary effect as a function of bounday layer size
|
|
|
|
|
|
|
|
var f_slow = 1.0 - (0.2 + 0.17 * math.ln(boundary_alt/base_layer_thickness));
|
|
|
|
}
|
|
|
|
|
2011-04-19 20:55:25 +00:00
|
|
|
if (debug_output_flag == 1)
|
|
|
|
{
|
2012-01-03 19:21:34 +00:00
|
|
|
#print("Boundary layer thickness: ",base_layer_thickness);
|
|
|
|
#print("Boundary layer slowdown: ", f_slow);
|
2011-04-19 20:55:25 +00:00
|
|
|
}
|
2011-01-05 12:36:10 +00:00
|
|
|
return f_slow;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
###################################
|
|
|
|
# interpolation management loop
|
|
|
|
###################################
|
|
|
|
|
|
|
|
var interpolation_loop = func {
|
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
if (local_weather_running_flag == 0) {return;}
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
var viewpos = geo.aircraft_position();
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
#var vis_before = getprop(lwi~"visibility-m");
|
|
|
|
var vis_before = interpolated_conditions.visibility_m;
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2011-05-14 13:15:20 +00:00
|
|
|
# if applicable, do some work for fps sampling
|
|
|
|
|
|
|
|
if (fps_control_flag == 1)
|
|
|
|
{
|
|
|
|
fps_samples = fps_samples +1;
|
|
|
|
fps_sum = fps_sum + getprop("/sim/frame-rate");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
# determine at which distance we no longer keep an interpolation point, needs to be larger for METAR since points are more scarce
|
|
|
|
|
|
|
|
if (metar_flag == 1)
|
|
|
|
{var distance_to_unload = 250000.0;}
|
|
|
|
else
|
|
|
|
{var distance_to_unload = 120000.0;}
|
|
|
|
|
|
|
|
# if we can set environment without a reset, the loop can run a bit faster for smoother interpolation
|
|
|
|
# so determine the suitable timing
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
|
|
|
|
var interpolation_loop_time = 0.1;
|
|
|
|
var vlimit = 1.01;
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
# get an inverse distance weighted average from all defined weather stations
|
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
var sum_alt = 0.0;
|
|
|
|
var sum_vis = 0.0;
|
|
|
|
var sum_T = 0.0;
|
|
|
|
var sum_p = 0.0;
|
|
|
|
var sum_D = 0.0;
|
|
|
|
var sum_norm = 0.0;
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
var n_stations = size(weatherStationArray);
|
|
|
|
|
|
|
|
for (var i = 0; i < n_stations; i=i+1) {
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2012-11-20 13:11:21 +00:00
|
|
|
var s = weatherStationArray[i];
|
2011-01-05 12:36:10 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
var stpos = geo.Coord.new();
|
2010-10-26 19:40:33 +00:00
|
|
|
stpos.set_latlon(s.lat,s.lon,0.0);
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
var d = viewpos.distance_to(stpos);
|
|
|
|
if (d <100.0) {d = 100.0;} # to prevent singularity at zero
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
sum_norm = sum_norm + 1./d * s.weight;
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
sum_alt = sum_alt + (s.alt/d) * s.weight;
|
2010-10-26 19:40:33 +00:00
|
|
|
sum_vis = sum_vis + (s.vis/d) * s.weight;
|
|
|
|
sum_T = sum_T + (s.T/d) * s.weight;
|
|
|
|
sum_D = sum_D + (s.D/d) * s.weight;
|
|
|
|
sum_p = sum_p + (s.p/d) * s.weight;
|
|
|
|
|
|
|
|
# gradually fade in the interpolation weight of newly added stations to
|
|
|
|
# avoid sudden jumps
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
if (s.weight < 1.0) {s.weight = s.weight + 0.02;}
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
# automatically delete stations out of range
|
|
|
|
# take care not to unload if weird values appear for a moment
|
2011-01-05 12:36:10 +00:00
|
|
|
# never unload if only one station left
|
2011-03-19 13:03:28 +00:00
|
|
|
if ((d > distance_to_unload) and (d < (distance_to_unload + 20000.0)) and (n_stations > 1))
|
2010-10-26 19:40:33 +00:00
|
|
|
{
|
|
|
|
if (debug_output_flag == 1)
|
|
|
|
{print("Distance to weather station ", d, " m, unloading ...", i);}
|
|
|
|
weatherStationArray = weather_tile_management.delete_from_vector(weatherStationArray,i);
|
|
|
|
i = i-1; n_stations = n_stations -1;
|
|
|
|
}
|
2010-04-12 20:51:46 +00:00
|
|
|
}
|
|
|
|
|
2011-04-19 20:55:25 +00:00
|
|
|
setprop(lwi~"station-number", i+1);
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
var ialt = sum_alt/sum_norm;
|
2010-04-12 20:51:46 +00:00
|
|
|
var vis = sum_vis/sum_norm;
|
|
|
|
var p = sum_p/sum_norm;
|
2012-01-03 19:21:34 +00:00
|
|
|
var D = sum_D/sum_norm + temperature_offset;
|
|
|
|
var T = sum_T/sum_norm + temperature_offset;
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2012-11-20 13:11:21 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
# get an inverse distance weighted average from all defined atmospheric condition points
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
sum_norm = 0.0;
|
|
|
|
var sum_vis_aloft = 0.0;
|
|
|
|
var sum_vis_alt1 = 0.0;
|
|
|
|
var sum_vis_ovcst = 0.0;
|
|
|
|
var sum_ovcst = 0.0;
|
|
|
|
var sum_ovcst_alt_low = 0.0;
|
|
|
|
var sum_ovcst_alt_high = 0.0;
|
|
|
|
var sum_scatt = 0.0;
|
|
|
|
var sum_scatt_alt_low = 0.0;
|
|
|
|
var sum_scatt_alt_high = 0.0;
|
|
|
|
|
|
|
|
var n_iPoints = size(atmosphereIpointArray);
|
|
|
|
|
|
|
|
for (var i = 0; i < n_iPoints; i=i+1) {
|
|
|
|
|
2012-11-20 13:11:21 +00:00
|
|
|
var a = atmosphereIpointArray[i];
|
2011-06-13 19:57:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
var apos = geo.Coord.new();
|
|
|
|
apos.set_latlon(a.lat,a.lon,0.0);
|
|
|
|
|
|
|
|
var d = viewpos.distance_to(apos);
|
|
|
|
if (d <100.0) {d = 100.0;} # to prevent singularity at zero
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
sum_norm = sum_norm + 1./d * a.weight;
|
|
|
|
sum_vis_aloft = sum_vis_aloft + (a.vis_aloft/d) * a.weight;
|
|
|
|
sum_vis_alt1 = sum_vis_alt1 + (a.vis_alt1/d) * a.weight;
|
|
|
|
sum_vis_ovcst = sum_vis_ovcst + (a.vis_ovcst/d) * a.weight;
|
|
|
|
sum_ovcst = sum_ovcst + (a.ovcst/d) * a.weight;
|
|
|
|
sum_ovcst_alt_low = sum_ovcst_alt_low + (a.ovcst_alt_low/d) * a.weight;
|
|
|
|
sum_ovcst_alt_high = sum_ovcst_alt_high + (a.ovcst_alt_high/d) * a.weight;
|
|
|
|
sum_scatt = sum_scatt + (a.scatt/d) * a.weight;
|
|
|
|
sum_scatt_alt_low = sum_scatt_alt_low + (a.scatt_alt_low/d) * a.weight;
|
|
|
|
sum_scatt_alt_high = sum_scatt_alt_high + (a.scatt_alt_high/d) * a.weight;
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
# gradually fade in the interpolation weight of newly added stations to
|
|
|
|
# avoid sudden jumps
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
if (a.weight < 1.0) {a.weight = a.weight + 0.02;}
|
|
|
|
|
|
|
|
# automatically delete stations out of range
|
|
|
|
# take care not to unload if weird values appear for a moment
|
|
|
|
# never unload if only one station left
|
|
|
|
if ((d > distance_to_unload) and (d < (distance_to_unload + 20000.0)) and (n_iPoints > 1))
|
|
|
|
{
|
|
|
|
if (debug_output_flag == 1)
|
|
|
|
{print("Distance to atmosphere interpolation point ", d, " m, unloading ...", i);}
|
|
|
|
atmosphereIpointArray = weather_tile_management.delete_from_vector(atmosphereIpointArray,i);
|
|
|
|
i = i-1; n_iPoints = n_iPoints -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setprop(lwi~"atmosphere-ipoint-number", i+1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var vis_aloft = sum_vis_aloft/sum_norm;
|
|
|
|
var vis_alt1 = sum_vis_alt1/sum_norm;
|
|
|
|
var vis_ovcst = sum_vis_ovcst/sum_norm;
|
|
|
|
var ovcst_max = sum_ovcst/sum_norm;
|
|
|
|
var ovcst_alt_low = sum_ovcst_alt_low/sum_norm;
|
|
|
|
var ovcst_alt_high = sum_ovcst_alt_high/sum_norm;
|
|
|
|
var scatt_max = sum_scatt/sum_norm;
|
|
|
|
var scatt_alt_low = sum_scatt_alt_low/sum_norm;
|
|
|
|
var scatt_alt_high = sum_scatt_alt_high/sum_norm;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# altitude model for visibility - increase above the lowest inversion layer to simulate ground haze
|
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
vis = vis * ground_haze_factor;
|
2011-06-13 19:57:21 +00:00
|
|
|
|
|
|
|
var altitude = getprop("position/altitude-ft");
|
2012-11-20 13:11:21 +00:00
|
|
|
# var current_mean_terrain_elevation = ialt;
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
var alt1 = vis_alt1;
|
2011-03-19 13:03:28 +00:00
|
|
|
var alt2 = alt1 + 1500.0;
|
|
|
|
|
2012-11-20 13:11:21 +00:00
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
setprop("/environment/ground-visibility-m",vis);
|
|
|
|
setprop("/environment/ground-haze-thickness-m",alt2 * ft_to_m);
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
# compute the visibility gradients
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2011-09-23 21:25:15 +00:00
|
|
|
if (realistic_visibility_flag == 1)
|
|
|
|
{
|
|
|
|
vis_aloft = vis_aloft * 2.0;
|
|
|
|
vis_ovcst = vis_ovcst * 3.0;
|
|
|
|
}
|
|
|
|
|
2013-03-01 07:40:05 +00:00
|
|
|
var inc1 = 0.0 * (vis_aloft - vis)/(vis_alt1 - ialt);
|
2011-06-13 19:57:21 +00:00
|
|
|
var inc2 = 0.9 * (vis_aloft - vis)/1500.0;
|
|
|
|
var inc3 = (vis_ovcst - vis_aloft)/(ovcst_alt_high - vis_alt1+1500);
|
|
|
|
var inc4 = 0.5;
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
|
|
|
|
if (realistic_visibility_flag == 1)
|
2011-09-23 21:25:15 +00:00
|
|
|
{inc4 = inc4 * 3.0;}
|
2011-09-23 21:22:19 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
# compute the visibility
|
|
|
|
|
|
|
|
if (altitude < alt1)
|
|
|
|
{vis = vis + inc1 * altitude;}
|
|
|
|
else if (altitude < alt2)
|
|
|
|
{
|
|
|
|
vis = vis + inc1 * alt1 + inc2 * (altitude - alt1);
|
|
|
|
}
|
|
|
|
else if (altitude < ovcst_alt_high)
|
|
|
|
{
|
|
|
|
vis = vis + inc1 * alt1 + inc2 * (alt2-alt1) + inc3 * (altitude - alt2);
|
|
|
|
}
|
|
|
|
else if (altitude > ovcst_alt_high)
|
|
|
|
{
|
|
|
|
vis = vis + inc1 * alt1 + inc2 * (alt2-alt1) + inc3 * (ovcst_alt_high - alt2) + inc4 * (altitude - ovcst_alt_high);
|
|
|
|
}
|
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
# limit visibility (otherwise memory consumption may be very bad...)
|
2011-09-23 21:22:19 +00:00
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
if (vis > max_vis_range)
|
|
|
|
{vis = max_vis_range;}
|
2011-09-23 21:22:19 +00:00
|
|
|
|
2013-03-01 07:40:05 +00:00
|
|
|
|
2011-09-23 21:25:15 +00:00
|
|
|
# determine scattering shader parameters if scattering shader is on
|
2011-06-13 19:57:21 +00:00
|
|
|
|
2011-09-23 21:25:15 +00:00
|
|
|
if (scattering_shader_flag == 1)
|
2011-06-13 19:57:21 +00:00
|
|
|
{
|
2012-04-26 10:03:51 +00:00
|
|
|
|
|
|
|
# values to be used with new exposure filter
|
|
|
|
var rayleigh = 0.0003;
|
|
|
|
var mie = 0.005;
|
2011-09-23 21:25:15 +00:00
|
|
|
var density = 0.3;
|
|
|
|
|
2012-04-26 10:03:51 +00:00
|
|
|
var vis_factor = (vis - 30000.0)/90000.0;
|
|
|
|
if (vis_factor < 0.0) {vis_factor = 0.0;}
|
|
|
|
if (vis_factor > 1.0) {vis_factor = 1.0;}
|
2012-06-11 08:47:00 +00:00
|
|
|
|
2012-04-26 10:03:51 +00:00
|
|
|
|
|
|
|
if (altitude < 36000.0)
|
2011-09-23 21:25:15 +00:00
|
|
|
{
|
2012-04-26 10:03:51 +00:00
|
|
|
rayleigh = 0.0003 - 0.0001 * vis_factor;
|
|
|
|
mie = 0.005 - vis_factor * 0.002;
|
2011-09-23 21:25:15 +00:00
|
|
|
}
|
|
|
|
else if (altitude < 85000.0)
|
|
|
|
{
|
2012-04-26 10:03:51 +00:00
|
|
|
rayleigh = (0.0003 - 0.0001 * vis_factor) - (altitude-36000.0)/49000.0 * 0.0001;
|
|
|
|
mie = 0.005 - vis_factor * 0.002 - (altitude-36000.0)/49000.0 * 0.002;
|
2011-09-23 21:25:15 +00:00
|
|
|
}
|
|
|
|
else
|
2012-04-26 10:03:51 +00:00
|
|
|
{rayleigh = 0.0002 - 0.0001 * vis_factor; mie = 0.003 - vis_factor * 0.002;}
|
|
|
|
|
|
|
|
# now the pollution factor
|
|
|
|
|
|
|
|
if (altitude < alt1)
|
|
|
|
{
|
|
|
|
rayleigh = rayleigh +0.0003 * air_pollution_norm + 0.0004 * air_pollution_norm * (1.0 - (altitude/alt1) * (altitude/alt1));
|
|
|
|
density = density + 0.05 * air_pollution_norm + 0.05 * air_pollution_norm * (1.0 - (altitude/alt1) * (altitude/alt1));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rayleigh = rayleigh + 0.0003 * air_pollution_norm;
|
|
|
|
density = density + 0.05 * air_pollution_norm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
}
|
2011-09-23 21:25:15 +00:00
|
|
|
|
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
# compute the horizon shading
|
|
|
|
|
|
|
|
if (altitude < scatt_alt_low)
|
|
|
|
{
|
|
|
|
var scatt = scatt_max;
|
|
|
|
}
|
|
|
|
else if (altitude < scatt_alt_high)
|
|
|
|
{
|
|
|
|
var scatt = scatt_max + (0.95 - scatt_max) * (altitude - scatt_alt_low)/(scatt_alt_high-scatt_alt_low);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{var scatt = 0.95;}
|
2011-06-13 19:57:21 +00:00
|
|
|
|
|
|
|
|
2012-11-20 13:11:21 +00:00
|
|
|
# compute the cloud layer self shading correction
|
|
|
|
|
|
|
|
var sun_angle = 1.57079632675 - getprop("/sim/time/sun-angle-rad");
|
2013-04-09 06:52:19 +00:00
|
|
|
var cloud_layer_shading = 1.0 - (0.8*(1.0 - scatt_max) * math.pow(math.cos(sun_angle),100.0));
|
2012-11-20 13:11:21 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
# compute the overcast haze
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
if (altitude < ovcst_alt_low)
|
|
|
|
{
|
|
|
|
var ovcst = ovcst_max;
|
|
|
|
}
|
|
|
|
else if (altitude < ovcst_alt_high)
|
|
|
|
{
|
|
|
|
var ovcst = ovcst_max - ovcst_max * (altitude - ovcst_alt_low)/(ovcst_alt_high-ovcst_alt_low);
|
2011-06-13 19:57:21 +00:00
|
|
|
}
|
2012-01-03 19:21:34 +00:00
|
|
|
else
|
|
|
|
{var ovcst = 0.0;}
|
|
|
|
|
|
|
|
|
2016-04-08 07:49:55 +00:00
|
|
|
# compute heating and cooling of various terrain and object types
|
|
|
|
|
|
|
|
var time = getprop("sim/time/utc/day-seconds");
|
|
|
|
time = time + getprop("sim/time/local-offset");
|
|
|
|
|
|
|
|
# low thermal inertia follows the Sun more or less directly
|
|
|
|
# high thermal inertia takes some time to reach full heat
|
|
|
|
|
|
|
|
var t_factor1 = 0.5 * (1.0-math.cos((time * sec_to_rad)));
|
|
|
|
var t_factor2 = 0.5 * (1.0-math.cos((time * sec_to_rad)-0.4));
|
|
|
|
var t_factor3 = 0.5 * (1.0-math.cos((time * sec_to_rad)-0.9));
|
|
|
|
|
|
|
|
var amp = scatt_max;
|
|
|
|
|
|
|
|
setprop("/environment/surface/delta-T-soil", amp * (-5.0 + 10.0 * t_factor2));
|
|
|
|
setprop("/environment/surface/delta-T-vegetation", amp * (-5.0 + 10.0 * t_factor1));
|
|
|
|
setprop("/environment/surface/delta-T-rock", amp * (-7.0 + 14.0 * t_factor1));
|
|
|
|
setprop("/environment/surface/delta-T-water", amp * (-1.0 + 2.0* t_factor3));
|
|
|
|
setprop("/environment/surface/delta-T-structure", amp * 10.0* t_factor1);
|
|
|
|
setprop("/environment/surface/delta-T-cloud", amp * (-2.0 + 2.0* t_factor3));
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
# compute base turbulence
|
|
|
|
|
|
|
|
var base_turbulence = 0.0;
|
|
|
|
|
|
|
|
if (altitude < alt1)
|
|
|
|
{
|
|
|
|
base_turbulence = lowest_layer_turbulence;
|
|
|
|
}
|
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
# limit relative changes of the visibility, will make for gradual transitions
|
2011-03-19 13:03:28 +00:00
|
|
|
|
|
|
|
if (vis/vis_before > vlimit)
|
|
|
|
{vis = vlimit * vis_before;}
|
|
|
|
else if (vis/vis_before < (2.0-vlimit))
|
|
|
|
{vis = (2.0-vlimit) * vis_before;}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
# write all properties into the weather interpolation record
|
2011-03-19 13:03:28 +00:00
|
|
|
|
|
|
|
setprop(lwi~"mean-terrain-altitude-ft",ialt);
|
2012-11-20 13:11:21 +00:00
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
|
|
|
|
if (vis > 0.0) interpolated_conditions.visibility_m = vis;
|
|
|
|
interpolated_conditions.temperature_degc = T;
|
|
|
|
interpolated_conditions.dewpoint_degc = D;
|
|
|
|
if (p>10.0) interpolated_conditions.pressure_sea_level_inhg = p;
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2011-09-23 21:25:15 +00:00
|
|
|
|
|
|
|
if (scattering_shader_flag == 1)
|
|
|
|
{
|
|
|
|
local_weather.setSkydomeShader(rayleigh, mie, density);
|
2012-11-20 13:11:21 +00:00
|
|
|
setprop("/environment/cloud-self-shading", cloud_layer_shading);
|
2011-09-23 21:25:15 +00:00
|
|
|
}
|
2012-01-03 19:21:34 +00:00
|
|
|
|
|
|
|
local_weather.setScattering(scatt);
|
|
|
|
local_weather.setOvercast(ovcst);
|
2012-04-26 10:03:51 +00:00
|
|
|
|
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
# now check if an effect volume writes the property and set only if not
|
2013-03-01 07:40:05 +00:00
|
|
|
# but set visibility if interpolated is smaller than effect-specified
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2012-11-20 13:11:21 +00:00
|
|
|
var flag = getprop("local-weather/effect-volumes/number-active-vis");
|
2011-05-14 13:15:20 +00:00
|
|
|
|
2011-07-03 21:39:01 +00:00
|
|
|
if ((flag ==0) and (vis > 0.0) and (getprop(lw~"lift-loop-flag") == 0) and (compat_layer.smooth_visibility_loop_flag == 0))
|
2010-04-12 20:51:46 +00:00
|
|
|
{
|
2010-08-03 06:18:14 +00:00
|
|
|
compat_layer.setVisibility(vis);
|
2010-04-12 20:51:46 +00:00
|
|
|
}
|
2013-06-26 09:33:07 +00:00
|
|
|
else if ((getprop("/local-weather/current/visibility-m") > vis) and (compat_layer.smooth_visibility_loop_flag == 0))
|
2013-03-01 07:40:05 +00:00
|
|
|
{
|
|
|
|
compat_layer.setVisibility(vis);
|
|
|
|
}
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2011-05-14 13:15:20 +00:00
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
|
2011-05-14 13:15:20 +00:00
|
|
|
flag = getprop("local-weather/effect-volumes/number-active-lift");
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
if (flag ==0)
|
|
|
|
{
|
2012-06-11 08:47:00 +00:00
|
|
|
#setprop(lw~"current/thermal-lift",0.0);
|
2010-06-04 21:05:32 +00:00
|
|
|
}
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
# no need to check for these, as they are not modelled in effect volumes
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
compat_layer.setTemperature(T);
|
|
|
|
compat_layer.setDewpoint(D);
|
2012-06-11 08:47:00 +00:00
|
|
|
if (p>0.0) {compat_layer.setPressure(p);}
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
|
2015-12-21 11:49:23 +00:00
|
|
|
# determine whether low haze is icy and whether we see scattering
|
|
|
|
|
|
|
|
var ice_hex_sheet = 0.0;
|
|
|
|
var ice_hex_column = 0.0;
|
|
|
|
|
|
|
|
if (T < -5.0)
|
|
|
|
{
|
|
|
|
ice_hex_column = (-T - 5.0) /10.0;
|
|
|
|
ice_hex_sheet = (-T - 10.0 + (T-D)) /20.0;
|
|
|
|
|
|
|
|
|
|
|
|
var sheet_bias = (T-D)/ 20;
|
|
|
|
if (sheet_bias > 1.0) {sheet_bias = 1.0;}
|
|
|
|
ice_hex_column = ice_hex_column * sheet_bias;
|
|
|
|
|
|
|
|
if (ice_hex_sheet > 1.0) {ice_hex_sheet = 1.0;}
|
|
|
|
if (ice_hex_column > 1.0) {ice_hex_column = 1.0;}
|
|
|
|
}
|
|
|
|
#print("Col: ",ice_hex_column);
|
|
|
|
#print("Sheet: ", ice_hex_sheet);
|
|
|
|
|
|
|
|
setprop("/environment/scattering-phenomena/ice-hexagonal-column-factor", ice_hex_column);
|
|
|
|
setprop("/environment/scattering-phenomena/ice-hexagonal-sheet-factor", ice_hex_sheet);
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
# now determine the local wind
|
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
|
2011-05-14 13:15:20 +00:00
|
|
|
var tile_index = getprop(lw~"tiles/tile[4]/tile-index");
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
if (wind_model_flag ==1) # constant
|
|
|
|
{
|
|
|
|
var winddir = weather_dynamics.tile_wind_direction[0];
|
|
|
|
var windspeed = weather_dynamics.tile_wind_speed[0];
|
2012-01-03 19:21:34 +00:00
|
|
|
|
|
|
|
wind.cloudlayer = [winddir,windspeed];
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
}
|
|
|
|
else if (wind_model_flag ==2) # constant in tile
|
|
|
|
{
|
|
|
|
var winddir = weather_dynamics.tile_wind_direction[tile_index-1];
|
|
|
|
var windspeed = weather_dynamics.tile_wind_speed[tile_index-1];
|
2012-01-03 19:21:34 +00:00
|
|
|
|
|
|
|
wind.cloudlayer = [winddir, windspeed];
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
}
|
|
|
|
else if (wind_model_flag ==3) # aloft interpolated, constant in tiles
|
|
|
|
{
|
2011-03-19 13:03:28 +00:00
|
|
|
var w = windIpointArray[0];
|
2010-08-03 06:18:14 +00:00
|
|
|
var res = wind_altitude_interpolation(altitude,w);
|
|
|
|
var winddir = res[0];
|
|
|
|
var windspeed = res[1];
|
2012-01-03 19:21:34 +00:00
|
|
|
|
|
|
|
wind.cloudlayer = wind_altitude_interpolation(0.0,w);
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
}
|
|
|
|
else if (wind_model_flag == 5) # aloft waypoint interpolated
|
|
|
|
{
|
2011-03-19 13:03:28 +00:00
|
|
|
var res = wind_interpolation(viewpos.lat(), viewpos.lon(), altitude);
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
var winddir = res[0];
|
|
|
|
var windspeed = res[1];
|
2012-01-03 19:21:34 +00:00
|
|
|
|
|
|
|
wind.cloudlayer = wind_interpolation(viewpos.lat(), viewpos.lon(), 0.0);
|
2010-08-03 06:18:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
wind.surface = [wind.cloudlayer[0], wind.cloudlayer[1] * get_slowdown_fraction()];
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
# now do the boundary layer computations
|
|
|
|
|
|
|
|
var altitude_agl = getprop("/position/altitude-agl-ft");
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
if (altitude_agl < 50.0)
|
|
|
|
{
|
|
|
|
base_turbulence = base_turbulence * altitude_agl/50.0;
|
|
|
|
}
|
|
|
|
|
2010-09-10 06:52:21 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (presampling_flag == 0)
|
2010-08-03 06:18:14 +00:00
|
|
|
{
|
|
|
|
var boundary_alt = 600.0;
|
|
|
|
var windspeed_ground = windspeed/3.0;
|
2011-03-19 13:03:28 +00:00
|
|
|
|
|
|
|
var f_min = 2.0/3.0;
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
if (altitude_agl < boundary_alt)
|
2010-09-10 06:52:21 +00:00
|
|
|
{var windspeed_current = windspeed_ground + 2.0 * windspeed_ground * (altitude_agl/boundary_alt);}
|
2010-08-03 06:18:14 +00:00
|
|
|
else
|
|
|
|
{var windspeed_current = windspeed;}
|
|
|
|
}
|
2010-09-10 06:52:21 +00:00
|
|
|
else
|
2010-08-03 06:18:14 +00:00
|
|
|
{
|
|
|
|
var alt_median = alt_50_array[tile_index - 1];
|
|
|
|
var alt_difference = alt_median - (altitude - altitude_agl);
|
|
|
|
var base_layer_thickness = 150.0;
|
|
|
|
|
|
|
|
# get the boundary layer size dependent on terrain altitude above terrain median
|
|
|
|
|
|
|
|
if (alt_difference > 0.0) # we're low and the boundary layer grows
|
|
|
|
{var boundary_alt = base_layer_thickness + 0.3 * alt_difference;}
|
|
|
|
else # the boundary layer shrinks
|
|
|
|
{var boundary_alt = base_layer_thickness + 0.1 * alt_difference;}
|
|
|
|
|
|
|
|
if (boundary_alt < 50.0){boundary_alt = 50.0;}
|
|
|
|
if (boundary_alt > 3000.0) {boundary_alt = 3000.0;}
|
|
|
|
|
|
|
|
# get the boundary effect as a function of bounday layer size
|
|
|
|
|
|
|
|
var f_min = 0.2 + 0.17 * math.ln(boundary_alt/base_layer_thickness);
|
|
|
|
|
|
|
|
|
|
|
|
if (altitude_agl < boundary_alt)
|
|
|
|
{
|
|
|
|
var windspeed_current = (1-f_min) * windspeed + f_min * windspeed * (altitude_agl/boundary_alt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{var windspeed_current = windspeed;}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
var windspeed_ground = (1.0-f_min) * windspeed;
|
|
|
|
|
|
|
|
|
|
|
|
# set the wind hash before gusts, it represents mean wind
|
|
|
|
|
|
|
|
wind.current = [winddir,windspeed_current];
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
# determine gusts and turbulence in the bounday layer
|
|
|
|
|
|
|
|
var gust_frequency = getprop(lw~"tmp/gust-frequency-hz");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (gust_frequency > 0.0)
|
|
|
|
{
|
|
|
|
var gust_relative_strength = getprop(lw~"tmp/gust-relative-strength");
|
|
|
|
var gust_angvar = getprop(lw~"tmp/gust-angular-variation-deg");
|
|
|
|
|
2015-01-14 08:04:42 +00:00
|
|
|
# if we have variability in the direction of the wind, the winds will
|
|
|
|
# drift by the Markov chain code below to adjust to a new winddir as computed
|
|
|
|
# above - however if the wind is not variable but still gusty, this won't happen
|
|
|
|
# so we have to take care of it explicitly
|
|
|
|
|
|
|
|
if (gust_angvar > 0.0)
|
|
|
|
{var winddir_last = interpolated_conditions.wind_from_heading_deg;}
|
|
|
|
else
|
|
|
|
{var winddir_last = winddir;}
|
2012-06-11 08:47:00 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
var alt_scaling_factor = 1.2 * windspeed / 10.0;
|
|
|
|
if (alt_scaling_factor < 1.0) {alt_scaling_factor = 1.0;}
|
|
|
|
|
|
|
|
# expected mean number of gusts in time interval (should be < 1)
|
2015-11-16 15:41:57 +00:00
|
|
|
var p_gust = gust_frequency * interpolation_loop_time;
|
|
|
|
|
|
|
|
# real time series show a ~10-30 second modulation as well
|
|
|
|
var p_squall = gust_frequency * 0.1 * interpolation_loop_time;
|
|
|
|
var squall_scale = getprop("/local-weather/tmp/squall-scaling-norm");
|
|
|
|
|
|
|
|
if (rand() < p_squall)
|
|
|
|
{
|
|
|
|
squall_scale = rand();
|
|
|
|
# prefer large changes
|
|
|
|
if ((squall_scale > 0.3) and (squall_scale < 0.7))
|
|
|
|
{squall_scale = rand();}
|
|
|
|
|
|
|
|
setprop("/local-weather/tmp/squall-scaling-norm", squall_scale);
|
|
|
|
}
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2011-05-14 13:15:20 +00:00
|
|
|
winddir_change = 0.0;
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
if (rand() < p_gust) # we change the offsets for windspeed and direction
|
|
|
|
{
|
|
|
|
var alt_fact = 1.0 - altitude_agl/(boundary_alt * alt_scaling_factor);
|
|
|
|
if (alt_fact < 0.0) {alt_fact = 0.0};
|
2015-11-16 15:41:57 +00:00
|
|
|
|
|
|
|
var random_factor = 0.3 * rand() + 0.7 * squall_scale;
|
|
|
|
|
|
|
|
windspeed_multiplier = (1.0 + (random_factor * gust_relative_strength * alt_fact));
|
2011-05-14 13:15:20 +00:00
|
|
|
winddir_change = alt_fact * (1.0 - 2.0 * rand()) * gust_angvar;
|
|
|
|
winddir_change = winddir_change * 0.2; # Markov chain parameter, max. change per frame is 1/5
|
|
|
|
|
|
|
|
# if the Markov chain reaches the boundary, reflect
|
|
|
|
|
|
|
|
#print("Winddir: ", winddir, " winddir_last: ", winddir_last, " winddir_change: ", winddir_change);
|
|
|
|
if (weather_tile_management.relangle(winddir_last + winddir_change, winddir) > gust_angvar)
|
|
|
|
{winddir_change = -winddir_change;}
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
}
|
|
|
|
windspeed_current = windspeed_current * windspeed_multiplier;
|
2011-05-14 13:15:20 +00:00
|
|
|
winddir = winddir_last + winddir_change;
|
2011-03-19 13:03:28 +00:00
|
|
|
}
|
|
|
|
|
2015-11-16 15:41:57 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
compat_layer.setWindSmoothly(winddir, windspeed_current);
|
|
|
|
|
2015-01-14 08:04:42 +00:00
|
|
|
# set the interpolated conditions to the wind including gust
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
interpolated_conditions.wind_from_heading_deg = winddir;
|
|
|
|
interpolated_conditions.windspeed_kt = windspeed_current;
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
# hack to get access to the water shader
|
|
|
|
|
|
|
|
setprop("/environment/config/boundary/entry[0]/wind-from-heading-deg",winddir);
|
|
|
|
setprop("/environment/config/boundary/entry[0]/wind-speed-kt",windspeed_ground);
|
|
|
|
|
|
|
|
# end hack
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# set turbulence
|
|
|
|
flag = getprop("local-weather/effect-volumes/number-active-turb");
|
|
|
|
|
|
|
|
var wind_enhancement_factor = windspeed_current/15.0;
|
|
|
|
if (wind_enhancement_factor > 1.5) {wind_enhancement_factor = 1.5;}
|
|
|
|
|
2019-05-20 07:13:55 +00:00
|
|
|
var volcanic_turbulence = getprop("/environment/volcanoes/turbulence");
|
|
|
|
|
|
|
|
var total_turbulence = base_turbulence * wind_enhancement_factor + volcanic_turbulence;
|
|
|
|
if (total_turbulence > 1.0) {total_turbulence = 1.0;}
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
if ((flag ==0))
|
2019-05-20 07:13:55 +00:00
|
|
|
{compat_layer.setTurbulence(total_turbulence);}
|
2012-06-11 08:47:00 +00:00
|
|
|
|
2012-04-26 10:03:51 +00:00
|
|
|
# set scattering on the ground - this doesn't affect fog but is diffuse and specular light reduction
|
|
|
|
# so it is stronger than normal scattering
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
var scatt_ground = (scatt_max - 0.4)/0.6;
|
2012-04-26 10:03:51 +00:00
|
|
|
if (scatt_ground < 0.0) {scatt_ground = 0.0;}
|
|
|
|
|
|
|
|
setprop("/environment/surface/scattering", scatt_ground);
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
if (getprop(lw~"interpolation-loop-flag") ==1) {settimer(interpolation_loop, 0.0);}
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
###################################
|
|
|
|
# thermal lift loop startup
|
|
|
|
###################################
|
|
|
|
|
|
|
|
var thermal_lift_start = func (ev) {
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
|
|
|
|
# if another lift loop is already running, do nothing
|
|
|
|
if (getprop(lw~"lift-loop-flag") == 1) {return;}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
# copy the properties from effect volume to the lift object
|
|
|
|
|
|
|
|
l = thermalLift.new(ev.lat, ev.lon, ev.radius, ev.height, ev.cn, ev.sh, ev.max_lift, ev.f_lift_radius);
|
|
|
|
|
|
|
|
l.index = ev.index;
|
|
|
|
|
|
|
|
if (dynamics_flag == 1)
|
|
|
|
{
|
|
|
|
l.timestamp = weather_dynamics.time_lw;
|
|
|
|
if (dynamical_convection_flag == 1)
|
|
|
|
{
|
|
|
|
l.flt = ev.flt;
|
|
|
|
l.evolution_timestamp = ev.evolution_timestamp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thermal = l;
|
|
|
|
|
|
|
|
if (debug_output_flag == 1)
|
|
|
|
{
|
|
|
|
print("Entering thermal lift...");
|
|
|
|
print("strength: ", thermal.max_lift, " radius: ", thermal.radius);
|
|
|
|
if (dynamical_convection_flag ==1)
|
|
|
|
{print("fractional lifetime: ", thermal.flt);}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# and start the lift loop, unless another one is already running
|
|
|
|
# so we block overlapping calls
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
|
|
|
|
setprop(lw~"lift-loop-flag",1);
|
|
|
|
settimer(thermal_lift_loop,0);
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
###################################
|
|
|
|
# thermal lift loop
|
|
|
|
###################################
|
|
|
|
|
|
|
|
var thermal_lift_loop = func {
|
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
if (local_weather_running_flag == 0) {return;}
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
var apos = geo.aircraft_position();
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var tlat = thermal.lat;
|
|
|
|
var tlon = thermal.lon;
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
var tpos = geo.Coord.new();
|
|
|
|
tpos.set_latlon(tlat,tlon,0.0);
|
|
|
|
|
|
|
|
var d = apos.distance_to(tpos);
|
|
|
|
var alt = getprop("position/altitude-ft");
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (dynamical_convection_flag == 1)
|
|
|
|
{var flt = thermal.flt;}
|
|
|
|
else
|
|
|
|
{var flt = 0.5;}
|
|
|
|
|
|
|
|
var lift = calcLift(d, alt, thermal.radius, thermal.height, thermal.cn, thermal.sh, thermal.max_lift, thermal.f_lift_radius, flt);
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (getprop(lw~"wave-loop-flag") ==1)
|
|
|
|
{
|
|
|
|
lift = lift + getprop(lw~"current/wave-lift");
|
|
|
|
}
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2011-05-14 13:15:20 +00:00
|
|
|
# compute a reduction in visibility when entering the cloudbase
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
#var vis = getprop(lw~"interpolation/visibility-m");
|
|
|
|
|
|
|
|
var vis = interpolated_conditions.visibility_m;
|
2011-05-14 13:15:20 +00:00
|
|
|
|
|
|
|
if (alt > 0.9 * thermal.height)
|
|
|
|
{
|
|
|
|
var visibility_reduction = math.pow((alt - 0.9 * thermal.height)/(0.2 * thermal.height),0.1);
|
|
|
|
visibility_reduction = visibility_reduction * (1.0 - math.pow(d/(0.8*thermal.radius),14));
|
|
|
|
|
|
|
|
if (visibility_reduction > 1.0) {visibility_reduction = 1.0;} # this shouldn't ever happen
|
|
|
|
if (visibility_reduction < 0.0) {visibility_reduction = 0.0;}
|
|
|
|
vis = vis * (1.0 - 0.98 * visibility_reduction);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setprop(lw~"current/visibility-m",vis);
|
|
|
|
compat_layer.setVisibility(vis);
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
setprop(lw~"current/thermal-lift",lift);
|
|
|
|
compat_layer.setLift(lift);
|
|
|
|
|
|
|
|
# if dynamics is on, move the thermal and occasionally compute altitude and age
|
|
|
|
|
|
|
|
if (dynamics_flag == 1)
|
|
|
|
{
|
|
|
|
thermal.move();
|
|
|
|
|
|
|
|
if ((rand() < 0.01) and (presampling_flag == 1)) # check every 100 frames
|
|
|
|
{
|
|
|
|
if (dynamical_convection_flag == 1)
|
|
|
|
{
|
|
|
|
thermal.correct_altitude_and_age();
|
|
|
|
if (thermal.flt > 1.1)
|
|
|
|
{thermal_lift_stop();}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
thermal.correct_altitude();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (getprop(lw~"lift-loop-flag") ==1) {settimer(thermal_lift_loop, 0);}
|
|
|
|
}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
###################################
|
2010-10-26 19:40:33 +00:00
|
|
|
# thermal lift loop stop
|
2010-06-04 21:05:32 +00:00
|
|
|
###################################
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var thermal_lift_stop = func {
|
|
|
|
|
|
|
|
setprop(lw~"lift-loop-flag",0);
|
|
|
|
setprop(lw~"current/thermal-lift",0.0);
|
|
|
|
compat_layer.setLift(0.0);
|
|
|
|
|
|
|
|
if (debug_output_flag == 1)
|
|
|
|
{
|
|
|
|
print("Leaving thermal lift...");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
###################################
|
|
|
|
# wave lift loop startup
|
|
|
|
###################################
|
|
|
|
|
|
|
|
var wave_lift_start = func (ev) {
|
|
|
|
|
|
|
|
# copy the properties from effect volume to the wave object
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
w = waveLift.new (ev.lat, ev.lon, ev.r1, ev.r2, ev.phi, ev.height, ev.max_lift);
|
|
|
|
w.index = ev.index;
|
|
|
|
wave = w;
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
# and start the lift loop, unless another one is already running
|
|
|
|
# so we block overlapping calls
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (getprop(lw~"wave-loop-flag") == 0)
|
|
|
|
{setprop(lw~"wave-loop-flag",1); settimer(wave_lift_loop,0);}
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
###################################
|
2010-10-26 19:40:33 +00:00
|
|
|
# wave lift loop
|
2010-06-04 21:05:32 +00:00
|
|
|
###################################
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var wave_lift_loop = func {
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
if (local_weather_running_flag == 0) {return;}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var lat = getprop("position/latitude-deg");
|
|
|
|
var lon = getprop("position/longitude-deg");
|
|
|
|
var alt = getprop("position/altitude-ft");
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var phi = wave.phi * math.pi/180.0;
|
|
|
|
|
|
|
|
var xx = (lon - wave.lon) * lon_to_m;
|
|
|
|
var yy = (lat - wave.lat) * lat_to_m;
|
|
|
|
|
|
|
|
var x = xx * math.cos(phi) - yy * math.sin(phi);
|
|
|
|
var y = yy * math.cos(phi) + xx * math.sin(phi);
|
|
|
|
|
|
|
|
var lift = calcWaveLift(x,y,alt);
|
|
|
|
|
|
|
|
# check if we are in a thermal, if so set wave lift and let the thermal lift loop add that
|
|
|
|
|
|
|
|
if (getprop(lw~"lift-loop-flag") ==1)
|
|
|
|
{
|
|
|
|
setprop(lw~"current/wave-lift",lift);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setprop(lw~"current/thermal-lift",lift);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getprop(lw~"wave-loop-flag") ==1) {settimer(wave_lift_loop, 0);}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# wave lift loop stop
|
|
|
|
###################################
|
|
|
|
|
|
|
|
var wave_lift_stop = func {
|
|
|
|
|
|
|
|
setprop(lw~"wave-loop-flag",0);
|
2010-06-04 21:05:32 +00:00
|
|
|
setprop(lw~"current/thermal-lift",0.0);
|
|
|
|
}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
####################################
|
|
|
|
# action taken when in effect volume
|
|
|
|
####################################
|
|
|
|
|
|
|
|
var effect_volume_start = func (ev) {
|
|
|
|
|
|
|
|
var cNode = props.globals.getNode(lw~"current");
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
if (ev.vis_flag ==1)
|
2010-04-12 20:51:46 +00:00
|
|
|
{
|
|
|
|
# first store the current setting in case we need to restore on leaving
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var vis = ev.vis;
|
|
|
|
ev.vis_r = cNode.getNode("visibility-m").getValue();
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
# then set the new value in current and execute change
|
|
|
|
cNode.getNode("visibility-m").setValue(vis);
|
2011-07-03 21:39:01 +00:00
|
|
|
#compat_layer.setVisibility(vis);
|
2013-04-09 06:41:27 +00:00
|
|
|
print(vis);
|
2011-07-03 21:39:01 +00:00
|
|
|
compat_layer.setVisibilitySmoothly(vis);
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
# then count the number of active volumes on entry (we need that to determine
|
|
|
|
# what to do on exit)
|
2010-10-26 19:40:33 +00:00
|
|
|
ev.n_entry_vis = getprop(lw~"effect-volumes/number-active-vis");
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
# and add to the counter
|
|
|
|
setprop(lw~"effect-volumes/number-active-vis",getprop(lw~"effect-volumes/number-active-vis")+1);
|
|
|
|
}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (ev.rain_flag == 1)
|
2010-04-12 20:51:46 +00:00
|
|
|
{
|
2010-10-26 19:40:33 +00:00
|
|
|
var rain = ev.rain;
|
2013-03-01 07:40:05 +00:00
|
|
|
#print("Setting rain to:", rain);
|
2010-10-26 19:40:33 +00:00
|
|
|
ev.rain_r = cNode.getNode("rain-norm").getValue();
|
2010-04-12 20:51:46 +00:00
|
|
|
cNode.getNode("rain-norm").setValue(rain);
|
2010-08-03 06:18:14 +00:00
|
|
|
compat_layer.setRain(rain);
|
2010-10-26 19:40:33 +00:00
|
|
|
ev.n_entry_rain = getprop(lw~"effect-volumes/number-active-rain");
|
2010-04-12 20:51:46 +00:00
|
|
|
setprop(lw~"effect-volumes/number-active-rain",getprop(lw~"effect-volumes/number-active-rain")+1);
|
|
|
|
}
|
2010-10-26 19:40:33 +00:00
|
|
|
if (ev.snow_flag == 1)
|
2010-04-12 20:51:46 +00:00
|
|
|
{
|
2010-10-26 19:40:33 +00:00
|
|
|
var snow = ev.snow;
|
|
|
|
ev.snow_r = cNode.getNode("snow-norm").getValue();
|
2010-04-12 20:51:46 +00:00
|
|
|
cNode.getNode("snow-norm").setValue(snow);
|
2010-08-03 06:18:14 +00:00
|
|
|
compat_layer.setSnow(snow);
|
2010-10-26 19:40:33 +00:00
|
|
|
ev.n_entry_snow = getprop(lw~"effect-volumes/number-active-snow");
|
2010-04-12 20:51:46 +00:00
|
|
|
setprop(lw~"effect-volumes/number-active-snow",getprop(lw~"effect-volumes/number-active-snow")+1);
|
|
|
|
}
|
2010-10-26 19:40:33 +00:00
|
|
|
if (ev.turb_flag == 1)
|
2010-06-15 18:54:44 +00:00
|
|
|
{
|
2010-10-26 19:40:33 +00:00
|
|
|
var turbulence = ev.turb;
|
|
|
|
ev.turb_r = cNode.getNode("turbulence").getValue();
|
2010-06-15 18:54:44 +00:00
|
|
|
cNode.getNode("turbulence").setValue(turbulence);
|
2010-08-03 06:18:14 +00:00
|
|
|
compat_layer.setTurbulence(turbulence);
|
2010-10-26 19:40:33 +00:00
|
|
|
ev.n_entry_turb = getprop(lw~"effect-volumes/number-active-turb");
|
2010-06-15 18:54:44 +00:00
|
|
|
setprop(lw~"effect-volumes/number-active-turb",getprop(lw~"effect-volumes/number-active-turb")+1);
|
|
|
|
}
|
2010-10-26 19:40:33 +00:00
|
|
|
if (ev.sat_flag == 1)
|
|
|
|
{
|
|
|
|
var saturation = ev.sat;
|
|
|
|
ev.sat_r = getprop("/rendering/scene/saturation");
|
2011-07-03 21:39:01 +00:00
|
|
|
compat_layer.setLightSmoothly(saturation);
|
2010-10-26 19:40:33 +00:00
|
|
|
ev.n_entry_sat = getprop(lw~"effect-volumes/number-active-sat");
|
|
|
|
setprop(lw~"effect-volumes/number-active-sat",getprop(lw~"effect-volumes/number-active-sat")+1);
|
|
|
|
}
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (ev.lift_flag == 1)
|
2010-04-12 20:51:46 +00:00
|
|
|
{
|
2010-10-26 19:40:33 +00:00
|
|
|
var lift = ev.lift;
|
|
|
|
ev.lift_r = cNode.getNode("thermal-lift").getValue();
|
2010-04-12 20:51:46 +00:00
|
|
|
cNode.getNode("thermal-lift").setValue(lift);
|
2010-10-26 19:40:33 +00:00
|
|
|
compat_layer.setLift(lift);
|
|
|
|
ev.n_entry_lift = getprop(lw~"effect-volumes/number-active-lift");
|
2010-04-12 20:51:46 +00:00
|
|
|
setprop(lw~"effect-volumes/number-active-lift",getprop(lw~"effect-volumes/number-active-lift")+1);
|
|
|
|
}
|
2010-10-26 19:40:33 +00:00
|
|
|
else if (ev.lift_flag == 2)
|
2010-06-04 21:05:32 +00:00
|
|
|
{
|
2010-10-26 19:40:33 +00:00
|
|
|
ev.lift_r = cNode.getNode("thermal-lift").getValue();
|
|
|
|
ev.n_entry_lift = getprop(lw~"effect-volumes/number-active-lift");
|
2010-06-04 21:05:32 +00:00
|
|
|
setprop(lw~"effect-volumes/number-active-lift",getprop(lw~"effect-volumes/number-active-lift")+1);
|
|
|
|
thermal_lift_start(ev);
|
|
|
|
}
|
2010-10-26 19:40:33 +00:00
|
|
|
else if (ev.lift_flag == 3)
|
|
|
|
{
|
|
|
|
ev.lift_r = cNode.getNode("thermal-lift").getValue();
|
|
|
|
ev.n_entry_lift = getprop(lw~"effect-volumes/number-active-lift");
|
|
|
|
setprop(lw~"effect-volumes/number-active-lift",getprop(lw~"effect-volumes/number-active-lift")+1);
|
|
|
|
wave_lift_start(ev);
|
|
|
|
}
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var effect_volume_stop = func (ev) {
|
|
|
|
|
|
|
|
var cNode = props.globals.getNode(lw~"current");
|
|
|
|
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (ev.vis_flag == 1)
|
2010-04-12 20:51:46 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
var n_active = getprop(lw~"effect-volumes/number-active-vis");
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var n_entry = ev.n_entry_vis;
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
# if no other nodes affecting property are active, restore to outside
|
|
|
|
# else restore settings as they have been when entering the volume when the number
|
|
|
|
# of active volumes is the same as on entry (i.e. volumes are nested), otherwise
|
|
|
|
# leave property at current because new definitions are already active and should not
|
|
|
|
# be cancelled
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
if (n_active ==1){var vis = interpolated_conditions.visibility_m;}
|
|
|
|
else if ((n_active -1) == n_entry)
|
2010-10-26 19:40:33 +00:00
|
|
|
{var vis = ev.vis_r;}
|
2010-04-12 20:51:46 +00:00
|
|
|
else {var vis = cNode.getNode("visibility-m").getValue();}
|
|
|
|
cNode.getNode("visibility-m").setValue(vis);
|
2011-07-03 21:39:01 +00:00
|
|
|
compat_layer.setVisibilitySmoothly(vis);
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
# and subtract from the counter
|
|
|
|
setprop(lw~"effect-volumes/number-active-vis",getprop(lw~"effect-volumes/number-active-vis")-1);
|
|
|
|
}
|
2010-10-26 19:40:33 +00:00
|
|
|
if (ev.rain_flag == 1)
|
2010-04-12 20:51:46 +00:00
|
|
|
{
|
|
|
|
var n_active = getprop(lw~"effect-volumes/number-active-rain");
|
2010-10-26 19:40:33 +00:00
|
|
|
var n_entry = ev.n_entry_rain;
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
if (n_active ==1){var rain = interpolated_conditions.rain_norm;}
|
|
|
|
else if ((n_active -1) == n_entry)
|
2010-10-26 19:40:33 +00:00
|
|
|
{var rain = ev.rain_r;}
|
2010-04-12 20:51:46 +00:00
|
|
|
else {var rain = cNode.getNode("rain-norm").getValue();}
|
|
|
|
cNode.getNode("rain-norm").setValue(rain);
|
2010-08-03 06:18:14 +00:00
|
|
|
compat_layer.setRain(rain);
|
2010-04-12 20:51:46 +00:00
|
|
|
setprop(lw~"effect-volumes/number-active-rain",getprop(lw~"effect-volumes/number-active-rain")-1);
|
|
|
|
}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (ev.snow_flag == 1)
|
2010-04-12 20:51:46 +00:00
|
|
|
{
|
|
|
|
var n_active = getprop(lw~"effect-volumes/number-active-snow");
|
2010-10-26 19:40:33 +00:00
|
|
|
var n_entry = ev.n_entry_snow;
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
if (n_active ==1){var snow = interpolated_conditions.snow_norm;}
|
2010-10-26 19:40:33 +00:00
|
|
|
else if ((n_active -1) == n_entry)
|
|
|
|
{var snow = ev.snow_r;}
|
2010-04-12 20:51:46 +00:00
|
|
|
else {var snow = cNode.getNode("snow-norm").getValue();}
|
|
|
|
cNode.getNode("snow-norm").setValue(snow);
|
2010-08-03 06:18:14 +00:00
|
|
|
compat_layer.setSnow(snow);
|
2010-04-12 20:51:46 +00:00
|
|
|
setprop(lw~"effect-volumes/number-active-snow",getprop(lw~"effect-volumes/number-active-snow")-1);
|
|
|
|
}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (ev.turb_flag == 1)
|
2010-06-15 18:54:44 +00:00
|
|
|
{
|
|
|
|
var n_active = getprop(lw~"effect-volumes/number-active-turb");
|
2010-10-26 19:40:33 +00:00
|
|
|
var n_entry = ev.n_entry_turb;
|
2012-06-11 08:47:00 +00:00
|
|
|
if (n_active ==1){var turbulence = interpolated_conditions.turbulence;}
|
2010-10-26 19:40:33 +00:00
|
|
|
else if ((n_active -1) == n_entry)
|
|
|
|
{var turbulence = ev.turb_r;}
|
2010-06-15 18:54:44 +00:00
|
|
|
else {var turbulence = cNode.getNode("turbulence").getValue();}
|
|
|
|
cNode.getNode("turbulence").setValue(turbulence);
|
2010-08-03 06:18:14 +00:00
|
|
|
compat_layer.setTurbulence(turbulence);
|
2010-06-15 18:54:44 +00:00
|
|
|
setprop(lw~"effect-volumes/number-active-turb",getprop(lw~"effect-volumes/number-active-turb")-1);
|
|
|
|
}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (ev.sat_flag == 1)
|
|
|
|
{
|
|
|
|
var n_active = getprop(lw~"effect-volumes/number-active-sat");
|
|
|
|
var n_entry = ev.n_entry_sat;
|
|
|
|
if (n_active ==1){var saturation = 1.0;}
|
|
|
|
else if ((n_active -1) == n_entry)
|
|
|
|
{var saturation = ev.sat_r;}
|
|
|
|
else {var saturation = getprop("/rendering/scene/saturation");}
|
2011-07-03 21:39:01 +00:00
|
|
|
compat_layer.setLightSmoothly(saturation);
|
2010-10-26 19:40:33 +00:00
|
|
|
setprop(lw~"effect-volumes/number-active-sat",getprop(lw~"effect-volumes/number-active-sat")-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ev.lift_flag == 1)
|
2010-04-12 20:51:46 +00:00
|
|
|
{
|
|
|
|
var n_active = getprop(lw~"effect-volumes/number-active-lift");
|
2010-10-26 19:40:33 +00:00
|
|
|
var n_entry = ev.n_entry_lift;
|
2012-06-11 08:47:00 +00:00
|
|
|
if (n_active ==1){var lift = interpolated_conditions.thermal_lift;}
|
2010-10-26 19:40:33 +00:00
|
|
|
else if ((n_active -1) == n_entry)
|
|
|
|
{var lift = ev.lift_r;}
|
2010-04-12 20:51:46 +00:00
|
|
|
else {var lift = cNode.getNode("thermal-lift").getValue();}
|
|
|
|
cNode.getNode("thermal-lift").setValue(lift);
|
2010-10-26 19:40:33 +00:00
|
|
|
compat_layer.setLift(lift);
|
2010-06-04 21:05:32 +00:00
|
|
|
setprop(lw~"effect-volumes/number-active-lift",getprop(lw~"effect-volumes/number-active-lift")-1);
|
|
|
|
}
|
2010-10-26 19:40:33 +00:00
|
|
|
else if (ev.lift_flag == 2)
|
2010-06-04 21:05:32 +00:00
|
|
|
{
|
|
|
|
thermal_lift_stop();
|
2010-04-12 20:51:46 +00:00
|
|
|
setprop(lw~"effect-volumes/number-active-lift",getprop(lw~"effect-volumes/number-active-lift")-1);
|
|
|
|
}
|
2010-10-26 19:40:33 +00:00
|
|
|
else if (ev.lift_flag == 3)
|
2010-06-04 21:05:32 +00:00
|
|
|
{
|
2010-10-26 19:40:33 +00:00
|
|
|
wave_lift_stop();
|
|
|
|
setprop(lw~"effect-volumes/number-active-lift",getprop(lw~"effect-volumes/number-active-lift")-1);
|
2010-06-04 21:05:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
#########################################
|
|
|
|
# compute thermal lift in detailed model
|
|
|
|
#########################################
|
|
|
|
|
|
|
|
var ts_factor = func (t, alt, height) {
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var t1 = 0.1; # fractional time at which lift is fully developed
|
|
|
|
var t2 = 0.9; # fractional time at which lift starts to decay
|
|
|
|
var t3 = 1.0; # fractional time at which lift is gone
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
# no time dependence modelled yet
|
2010-10-26 19:40:33 +00:00
|
|
|
# return 1.0;
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var t_a = t - (alt/height) * t1 - t1;
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
if (t_a<0) {return 0.0;}
|
|
|
|
else if (t_a<t1) {return 0.5 + 0.5 * math.cos((1.0-t_a/t1)* math.pi);}
|
2010-10-26 19:40:33 +00:00
|
|
|
else if (t_a < t2) {return 1.0;}
|
|
|
|
else {return 0.5 - 0.5 * math.cos((1.0-(t2-t_a)/(t3-t2))*math.pi);}
|
2010-06-04 21:05:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var tl_factor = func (t, alt, height) {
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var t1 = 0.1; # fractional time at which lift is fully developed
|
|
|
|
var t2 = 0.9; # fractional time at which lift starts to decay
|
|
|
|
var t3 = 1.0; # fractional time at which lift is gone
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
# no time dependence modelled yet
|
2010-10-26 19:40:33 +00:00
|
|
|
# return 1.0;
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
var t_a = t - (alt/height) * t1;
|
|
|
|
|
|
|
|
if (t_a<0) {return 0.0;}
|
|
|
|
else if (t_a<t1) {return 0.5 + 0.5 * math.cos((1.0-t_a/t1)* math.pi);}
|
2010-10-26 19:40:33 +00:00
|
|
|
else if (t_a < t2) {return 1.0;}
|
|
|
|
else {return 0.5 - 0.5 * math.cos((1.0-(t2-t_a)/(t3-t2))*math.pi);}
|
2010-06-04 21:05:32 +00:00
|
|
|
}
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
var calcLift_max = func (alt, max_lift, height) {
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
alt_agl = getprop("/position/altitude-agl-ft");
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
# no lift below ground
|
2010-10-26 19:40:33 +00:00
|
|
|
if (alt_agl < 0.0) {return 0.0;}
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
# lift ramps up to full within 200 m
|
2010-10-26 19:40:33 +00:00
|
|
|
else if (alt_agl < 200.0*m_to_ft)
|
|
|
|
{return max_lift * 0.5 * (1.0 + math.cos((1.0-alt_agl/(200.0*m_to_ft))*math.pi));}
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
# constant max. lift in main body
|
2010-10-26 19:40:33 +00:00
|
|
|
else if ((alt_agl > 200.0*m_to_ft) and (alt < height))
|
2010-06-04 21:05:32 +00:00
|
|
|
{return max_lift;}
|
|
|
|
|
|
|
|
# decreasing lift from cloudbase to 10% above base
|
|
|
|
else if ((alt > height ) and (alt < height*1.1))
|
2010-10-26 19:40:33 +00:00
|
|
|
{return max_lift * 0.5 * (1.0 - math.cos((1.0-10.0*(alt-height)/height)*math.pi));}
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
# no lift available above
|
|
|
|
else {return 0.0;}
|
2010-04-12 20:51:46 +00:00
|
|
|
}
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
var calcLift = func (d, alt, R, height, cn, sh, max_lift, f_lift_radius, t) {
|
|
|
|
|
|
|
|
# radius of slice at given altitude
|
|
|
|
var r_total = (cn + alt/height*(1.0-cn)) * (R - R * (1.0- sh ) * (1.0 - ((2.0*alt/height)-1.0)*((2.0*alt/height)-1.0)));
|
|
|
|
|
|
|
|
|
|
|
|
# print("r_total: ", r_total, "d: ",d);
|
|
|
|
# print("alt: ", alt, "height: ",height);
|
|
|
|
|
|
|
|
# no lift if we're outside the radius or above the thermal
|
|
|
|
if ((d > r_total) or (alt > 1.1*height)) { return 0.0; }
|
|
|
|
|
|
|
|
# fraction of radius providing lift
|
|
|
|
var r_lift = f_lift_radius * r_total;
|
|
|
|
|
|
|
|
# print("r_lift: ", r_lift);
|
|
|
|
|
|
|
|
# if we are in the sink portion, get the max. sink for this time and altitude and adjust for actual position
|
|
|
|
if ((d < r_total ) and (d > r_lift))
|
|
|
|
{
|
|
|
|
var s_max = 0.5 * calcLift_max(alt, max_lift, height) * ts_factor(t, alt, height);
|
|
|
|
# print("s_max: ", s_max);
|
|
|
|
return s_max * math.sin(math.pi * (1.0 + (d-r_lift) * (1.0/(r_total - r_lift))));
|
|
|
|
}
|
|
|
|
# else we are in the lift portion, get the max. lift for this time and altitude and adjust for actual position
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var l_max = calcLift_max(alt, max_lift, height) * tl_factor(t, alt, height);
|
|
|
|
# print("l_max: ", l_max);
|
|
|
|
return l_max * math.cos(math.pi * (d/(2.0 * r_lift)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
#########################################
|
|
|
|
# compute wave lift in detailed model
|
|
|
|
#########################################
|
|
|
|
|
|
|
|
var calcWaveLift = func (x,y, alt) {
|
|
|
|
|
|
|
|
var lift = wave.max_lift * math.cos((y/wave.y) * 1.5 * math.pi);
|
|
|
|
|
|
|
|
if (abs(x)/wave.x > 0.9)
|
|
|
|
{
|
|
|
|
lift = lift * (abs(x) - 0.9 * wave.x)/(0.1 * wave.x);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lift = lift * 2.71828 * math.exp(-alt/wave.height) * alt/wave.height;
|
|
|
|
|
|
|
|
var alt_agl = getprop("/position/altitude-agl-ft");
|
|
|
|
|
|
|
|
if (alt_agl < 1000.0)
|
|
|
|
{
|
|
|
|
lift = lift * (alt_agl/1000.0) * (alt_agl/1000.0);
|
|
|
|
}
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
return lift;
|
|
|
|
}
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# place a single cloud into a vector to be processed
|
2010-08-03 06:18:14 +00:00
|
|
|
# separately
|
2010-06-04 21:05:32 +00:00
|
|
|
###########################################################
|
|
|
|
|
2012-11-20 13:11:21 +00:00
|
|
|
var create_cloud_vec = func(path, lat, lon, alt, heading) {
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
if (path == "new") # we have to switch to new cloud generating routines
|
|
|
|
{
|
|
|
|
local_weather.cloudAssembly.lat = lat;
|
2012-11-20 13:11:21 +00:00
|
|
|
local_weather.cloudAssembly.lon = lon;
|
2011-09-23 21:22:19 +00:00
|
|
|
local_weather.cloudAssembly.alt = alt;
|
2012-04-26 10:03:51 +00:00
|
|
|
local_weather.cloudAssembly.top_shade = top_shade;
|
2014-11-16 10:28:09 +00:00
|
|
|
local_weather.cloudAssembly.alpha_factor = alpha_factor;
|
2011-09-23 21:22:19 +00:00
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
#print(lat," ",long, " ", alt);
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
if (dynamics_flag == 1)
|
|
|
|
{
|
|
|
|
local_weather.cloudAssembly.mean_alt = cloud_mean_altitude;
|
|
|
|
local_weather.cloudAssembly.flt = cloud_fractional_lifetime;
|
|
|
|
local_weather.cloudAssembly.evolution_timestamp = cloud_evolution_timestamp;
|
2012-01-03 19:21:34 +00:00
|
|
|
local_weather.cloudAssembly.rel_alt = cloudAssembly.alt - cloud_mean_altitude;
|
2011-09-23 21:22:19 +00:00
|
|
|
}
|
2012-01-03 19:21:34 +00:00
|
|
|
|
|
|
|
append(cloudAssemblyArray,cloudAssembly);
|
2011-09-23 21:22:19 +00:00
|
|
|
|
2012-11-20 13:11:21 +00:00
|
|
|
# at this point we insert tracers for the depth buffer
|
|
|
|
|
|
|
|
#if (local_weather.cloudAssembly.tracer_flag == 1)
|
|
|
|
# {
|
|
|
|
# tracerAssembly = local_weather.cloud.new("Tracer", "default");
|
|
|
|
# tracerAssembly.texture_sheet = "/Models/Weather/nimbus_sheet1.rgb";
|
|
|
|
# tracerAssembly.n_sprites = 1;
|
|
|
|
# tracerAssembly.bottom_shade = 0.0;
|
|
|
|
# tracerAssembly.top_shade = 0.0;
|
|
|
|
# tracerAssembly.num_tex_x = 1;
|
|
|
|
# tracerAssembly.num_tex_y = 1;
|
|
|
|
# tracerAssembly.lat = lat;
|
|
|
|
# tracerAssembly.lon = lon;
|
|
|
|
# tracerAssembly.alt = alt + local_weather.cloudAssembly.min_height *0.35 * m_to_ft ;
|
|
|
|
# tracerAssembly.min_width = local_weather.cloudAssembly.min_width * 0.35;
|
|
|
|
# tracerAssembly.max_width = local_weather.cloudAssembly.max_width * 0.35;
|
|
|
|
# tracerAssembly.min_height = local_weather.cloudAssembly.min_height * 0.35;
|
|
|
|
# tracerAssembly.max_height = local_weather.cloudAssembly.max_height * 0.35;
|
|
|
|
# tracerAssembly.min_cloud_width = local_weather.cloudAssembly.min_cloud_width * 0.35;
|
|
|
|
# tracerAssembly.min_cloud_height = local_weather.cloudAssembly.min_cloud_height * 0.35;
|
|
|
|
# tracerAssembly.z_scale = local_weather.cloudAssembly.z_scale;
|
|
|
|
# append(cloudAssemblyArray,tracerAssembly);
|
|
|
|
# }
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
append(clouds_path,path);
|
|
|
|
append(clouds_lat,lat);
|
2012-11-20 13:11:21 +00:00
|
|
|
append(clouds_lon,lon);
|
2010-06-04 21:05:32 +00:00
|
|
|
append(clouds_alt,alt);
|
|
|
|
append(clouds_orientation,heading);
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
# globals (needed for Cumulus clouds) should be set if needed by the main cloud generating call
|
|
|
|
|
|
|
|
if (dynamics_flag ==1)
|
|
|
|
{
|
|
|
|
append(clouds_mean_alt, cloud_mean_altitude);
|
|
|
|
append(clouds_flt, cloud_fractional_lifetime);
|
|
|
|
append(clouds_evolution_timestamp,cloud_evolution_timestamp);
|
|
|
|
}
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
}
|
2010-04-12 20:51:46 +00:00
|
|
|
###########################################################
|
|
|
|
# clear all clouds and effects
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var clear_all = func {
|
|
|
|
|
|
|
|
# clear the clouds and models
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
var cloudNode = props.globals.getNode(lw~"clouds", 1);
|
|
|
|
cloudNode.removeChildren("tile");
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
var modelNode = props.globals.getNode("models", 1).getChildren("model");
|
|
|
|
|
|
|
|
foreach (var m; modelNode)
|
|
|
|
{
|
2010-08-03 06:18:14 +00:00
|
|
|
var l = m.getNode("tile-index",1).getValue();
|
|
|
|
if (l != nil)
|
2010-04-12 20:51:46 +00:00
|
|
|
{
|
|
|
|
m.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
# remove the hard-coded clouds
|
|
|
|
|
|
|
|
foreach (c; weather_tile_management.cloudArray)
|
|
|
|
{
|
|
|
|
c.remove();
|
|
|
|
}
|
|
|
|
setsize(weather_tile_management.cloudArray,0);
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
# reset pressure continuity
|
|
|
|
|
|
|
|
weather_tiles.last_pressure = 0.0;
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
# stop all loops
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
setprop(lw~"effect-loop-flag",0);
|
|
|
|
setprop(lw~"interpolation-loop-flag",0);
|
2010-06-04 21:05:32 +00:00
|
|
|
setprop(lw~"tile-loop-flag",0);
|
|
|
|
setprop(lw~"lift-loop-flag",0);
|
2010-10-26 19:40:33 +00:00
|
|
|
setprop(lw~"wave-loop-flag",0);
|
2010-08-03 06:18:14 +00:00
|
|
|
setprop(lw~"dynamics-loop-flag",0);
|
|
|
|
setprop(lw~"timing-loop-flag",0);
|
2010-09-10 06:52:21 +00:00
|
|
|
setprop(lw~"buffer-loop-flag",0);
|
|
|
|
setprop(lw~"housekeeping-loop-flag",0);
|
2010-10-26 19:40:33 +00:00
|
|
|
setprop(lw~"convective-loop-flag",0);
|
2014-03-10 08:29:14 +00:00
|
|
|
setprop(lw~"shadow-loop-flag",0);
|
2015-08-11 13:28:32 +00:00
|
|
|
setprop(lw~"thunderstorm-loop-flag",0);
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
weather_dynamics.convective_loop_kill_flag = 1; # long-running loop needs a different scheme to end
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
# also remove rain, snow, haze and light effects
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
compat_layer.setRain(0.0);
|
|
|
|
compat_layer.setSnow(0.0);
|
2011-03-19 13:03:28 +00:00
|
|
|
compat_layer.setLight(1.0);
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
# set placement indices to zero
|
|
|
|
|
|
|
|
setprop(lw~"clouds/placement-index",0);
|
|
|
|
setprop(lw~"clouds/model-placement-index",0);
|
|
|
|
setprop(lw~"effect-volumes/effect-placement-index",0);
|
2010-08-03 06:18:14 +00:00
|
|
|
setprop(lw~"effect-volumes/number",0);
|
2013-01-10 11:21:14 +00:00
|
|
|
setprop(lw~"effect-volumes/number-active-rain",0);
|
|
|
|
setprop(lw~"effect-volumes/number-active-snow",0);
|
|
|
|
setprop(lw~"effect-volumes/number-active-vis",0);
|
|
|
|
setprop(lw~"effect-volumes/number-active-turb",0);
|
|
|
|
setprop(lw~"effect-volumes/number-active-lift",0);
|
|
|
|
setprop(lw~"effect-volumes/number-active-sat",0);
|
2010-06-04 21:05:32 +00:00
|
|
|
setprop(lw~"tiles/tile-counter",0);
|
|
|
|
|
2010-09-10 06:52:21 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
# remove any quadtrees and arrays
|
|
|
|
|
|
|
|
settimer ( func { setsize(weather_dynamics.cloudQuadtrees,0);},0.1); # to avoid error generation in this frame
|
|
|
|
setsize(effectVolumeArray,0);
|
|
|
|
n_effectVolumeArray = 0;
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2014-02-17 08:21:26 +00:00
|
|
|
# remove any impostors
|
|
|
|
|
|
|
|
weather_tile_management.remove_impostors();
|
2012-03-08 22:20:39 +00:00
|
|
|
|
2014-03-10 08:29:14 +00:00
|
|
|
# clear out the visual shadows
|
|
|
|
|
|
|
|
for (var i = 0; i<cloudShadowArraySize; i=i+1)
|
|
|
|
{
|
|
|
|
setprop("/local-weather/cloud-shadows/cloudpos-x["~i~"]",0.0);
|
|
|
|
setprop("/local-weather/cloud-shadows/cloudpos-y["~i~"]",0.0);
|
|
|
|
}
|
|
|
|
|
2012-03-08 22:20:39 +00:00
|
|
|
# clear any wxradar echos
|
|
|
|
|
|
|
|
if (wxradar_support_flag ==1)
|
|
|
|
{props.globals.getNode("/instrumentation/wxradar", 1).removeChildren("storm");}
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
# if we have used METAR, we may no longer want to do so
|
|
|
|
|
|
|
|
metar_flag = 0;
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2010-09-10 06:52:21 +00:00
|
|
|
settimer ( func {
|
|
|
|
setsize(weather_tile_management.modelArrays,0);
|
|
|
|
setsize(weather_dynamics.tile_wind_direction,0);
|
|
|
|
setsize(weather_dynamics.tile_wind_speed,0);
|
|
|
|
setsize(weather_tile_management.cloudBufferArray,0);
|
|
|
|
setsize(weather_tile_management.cloudSceneryArray,0);
|
2010-10-26 19:40:33 +00:00
|
|
|
setsize(alt_20_array,0);
|
|
|
|
setsize(alt_50_array,0);
|
2011-09-23 21:22:19 +00:00
|
|
|
setsize(alt_min_array,0);
|
|
|
|
setsize(alt_mean_array,0);
|
2014-03-10 08:29:14 +00:00
|
|
|
setsize(weather_dynamics.cloudShadowArray,0);
|
2015-08-11 13:28:32 +00:00
|
|
|
setsize(local_weather.thunderstormArray,0);
|
2014-03-10 08:29:14 +00:00
|
|
|
setsize(weather_dynamics.cloudShadowCandidateArray,0);
|
2010-10-26 19:40:33 +00:00
|
|
|
setsize(weather_dynamics.tile_convective_altitude,0);
|
|
|
|
setsize(weather_dynamics.tile_convective_strength,0);
|
|
|
|
setsize(weatherStationArray,0);
|
2011-03-19 13:03:28 +00:00
|
|
|
setsize(windIpointArray,0);
|
2011-06-13 19:57:21 +00:00
|
|
|
setsize(atmosphereIpointArray,0);
|
2010-09-10 06:52:21 +00:00
|
|
|
setprop(lw~"clouds/buffer-count",0);
|
|
|
|
setprop(lw~"clouds/cloud-scenery-count",0);
|
2010-10-26 19:40:33 +00:00
|
|
|
weather_tile_management.n_cloudSceneryArray = 0;
|
2011-06-13 19:57:21 +00:00
|
|
|
compat_layer.setScattering(0.8);
|
|
|
|
compat_layer.setOvercast(0.0);
|
2010-10-26 19:40:33 +00:00
|
|
|
setprop(lwi~"ipoint-number",0);
|
2011-06-13 19:57:21 +00:00
|
|
|
setprop(lwi~"atmosphere-ipoint-number", 0);
|
2013-03-01 07:40:05 +00:00
|
|
|
},0);
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
setprop(lw~"tmp/presampling-status", "idle");
|
|
|
|
|
2011-05-14 13:15:20 +00:00
|
|
|
# reset the random store
|
|
|
|
|
|
|
|
weather_tiles.rnd_store = rand();
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
# default 3d clouds layer wrapping back on, just in case
|
|
|
|
|
|
|
|
setprop("/sim/rendering/clouds3d-wrap",1);
|
|
|
|
|
2014-10-22 08:00:19 +00:00
|
|
|
# hand precipitation control back to automatic
|
|
|
|
|
|
|
|
props.globals.getNode("/environment/precipitation-control/detailed-precipitation").setBoolValue("false");
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
# indicate that we are no longer running
|
|
|
|
|
2011-05-14 13:15:20 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
local_weather_running_flag = 0;
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
}
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
###########################################################
|
2010-06-15 18:54:44 +00:00
|
|
|
# detailed Cumulus clouds created from multiple cloudlets
|
2010-06-04 21:05:32 +00:00
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var create_detailed_cumulus_cloud = func (lat, lon, alt, size) {
|
|
|
|
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
# various distribution biases
|
2010-09-10 06:52:21 +00:00
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
var edge_bias = convective_texture_mix;
|
2011-07-03 21:39:01 +00:00
|
|
|
size = size + convective_size_bias;
|
2012-06-11 08:47:00 +00:00
|
|
|
height_bias = 1.0;
|
|
|
|
if (edge_bias > 0.0) {height_bias = height_bias + 15.0 *edge_bias + 20.0 * rand() * edge_bias;}
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
#height_bias = 6.0;
|
2011-09-23 21:22:19 +00:00
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
if (size > 2.0)
|
|
|
|
{
|
|
|
|
if (rand() > (size - 2.0))
|
|
|
|
{create_cumulonimbus_cloud(lat, lon, alt, size); }
|
|
|
|
else
|
|
|
|
{create_cumulonimbus_cloud_rain(lat, lon, alt, size, 0.1 + 0.2* rand());}
|
|
|
|
return;
|
|
|
|
}
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
else if (size>1.5)
|
|
|
|
{
|
|
|
|
var type = "Congestus";
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
var height = 400;
|
|
|
|
var n = 3;
|
|
|
|
var x = 700.0;
|
|
|
|
var y = 200.0;
|
|
|
|
var edge = 0.2;
|
|
|
|
|
|
|
|
var alpha = rand() * 180.0;
|
|
|
|
edge = edge + edge_bias;
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
create_streak(type,lat,lon, alt+ 0.3* (height )-offset_map["Congestus"], height,n,0.0,edge,x,1,0.0,0.0,y,alpha,1.0);
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
var type = "Cu (volume)";
|
|
|
|
var height = 400;
|
2012-06-11 08:47:00 +00:00
|
|
|
var n = 10 + int(height_bias);
|
2011-09-23 21:22:19 +00:00
|
|
|
var x = 1400.0;
|
|
|
|
var y = 400.0;
|
|
|
|
var edge = 0.2;
|
|
|
|
|
|
|
|
edge = edge + edge_bias;
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
create_streak(type,lat,lon, alt+ 0.5* (height * height_bias )-offset_map["Cumulus"], height * height_bias ,n,0.0,edge,x,1,0.0,0.0,y,alpha,1.0);
|
2011-09-23 21:22:19 +00:00
|
|
|
|
|
|
|
var btype = "Congestus bottom";
|
|
|
|
var n_b = 6;
|
2012-06-11 08:47:00 +00:00
|
|
|
height_bias = 1.0;
|
2018-08-30 06:28:33 +00:00
|
|
|
var top_shade_store = local_weather.top_shade;
|
|
|
|
if (top_shade_store > 0.6) {local_weather.top_shade = 0.6;}
|
2012-06-11 08:47:00 +00:00
|
|
|
create_streak(btype,lat,lon, alt -offset_map["Congestus"] -900.0, 100.0,n_b,0.0,edge,0.3*x,1,0.0,0.0,0.3*y,alpha,1.0);
|
2018-08-30 06:28:33 +00:00
|
|
|
local_weather.top_shade = top_shade_store;
|
2011-09-23 21:22:19 +00:00
|
|
|
|
2014-03-10 08:29:14 +00:00
|
|
|
if (local_weather.cloud_shadow_flag == 1)
|
|
|
|
{
|
|
|
|
var cs = local_weather.cloudShadow.new(lat, lon, 0.9 * (1.5 * x)/5000.0 , 0.9);
|
|
|
|
cs.index = getprop(lw~"tiles/tile-counter");
|
|
|
|
append(cloudShadowCandidateArray,cs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
}
|
|
|
|
else if (size>1.1)
|
|
|
|
{
|
|
|
|
var type = "Cumulus (cloudlet)";
|
|
|
|
var btype = "Cumulus bottom";
|
|
|
|
var height = 200;
|
2012-06-11 08:47:00 +00:00
|
|
|
var n = 6 + int(height_bias);
|
2011-09-23 21:22:19 +00:00
|
|
|
var n_b = 2;
|
|
|
|
var x = 900.0;
|
|
|
|
var y = 200.0;
|
|
|
|
var edge = 0.2;
|
|
|
|
|
|
|
|
var alpha = rand() * 180.0;
|
|
|
|
edge = edge + edge_bias;
|
2012-06-11 08:47:00 +00:00
|
|
|
create_streak(type,lat,lon, alt+ 0.5* (height* height_bias )-offset_map["Cumulus"], height * height_bias,n,0.0,edge,x,1,0.0,0.0,y,alpha,1.0);
|
2011-09-23 21:22:19 +00:00
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
height_bias = 1.0;
|
2018-08-30 06:28:33 +00:00
|
|
|
var top_shade_store = local_weather.top_shade;
|
|
|
|
if (top_shade_store > 0.6) {local_weather.top_shade = 0.6;}
|
2012-01-03 19:21:34 +00:00
|
|
|
create_streak(btype,lat,lon, alt -offset_map["Cumulus"] - 200.0, 100.0,n_b,0.0,edge,0.3*x,1,0.0,0.0,0.3*y,alpha,1.0);
|
2018-08-30 06:28:33 +00:00
|
|
|
local_weather.top_shade = top_shade_store;
|
2011-09-23 21:22:19 +00:00
|
|
|
|
2014-03-10 08:29:14 +00:00
|
|
|
if (local_weather.cloud_shadow_flag == 1)
|
|
|
|
{
|
|
|
|
var cs = local_weather.cloudShadow.new(lat, lon, 0.9 * (1.5 * x)/5000.0 , 0.8);
|
|
|
|
cs.index = getprop(lw~"tiles/tile-counter");
|
|
|
|
append(cloudShadowCandidateArray,cs);
|
|
|
|
}
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
}
|
|
|
|
else if (size>0.8)
|
|
|
|
{
|
|
|
|
var type = "Cumulus (cloudlet)";
|
|
|
|
var height = 150;
|
2012-06-11 08:47:00 +00:00
|
|
|
var n = 4 + int(height_bias);
|
2011-09-23 21:22:19 +00:00
|
|
|
var x = 300.0;
|
|
|
|
var y = 300.0;
|
|
|
|
var edge = 0.3;
|
|
|
|
|
|
|
|
var alpha = rand() * 180.0;
|
|
|
|
edge = edge + edge_bias;
|
2012-06-11 08:47:00 +00:00
|
|
|
create_streak(type,lat,lon, alt+ 0.5* (height * height_bias )-offset_map["Cumulus"], height * height_bias,n,0.0,edge,x,1,0.0,0.0,y,alpha,1.0);
|
2011-09-23 21:22:19 +00:00
|
|
|
|
|
|
|
n = 2;
|
|
|
|
x = 700.0;
|
|
|
|
y = 200.0;
|
|
|
|
edge = 1.0;
|
2012-06-11 08:47:00 +00:00
|
|
|
create_streak(type,lat,lon, alt+ 0.5* (height*height_bias )-offset_map["Cumulus"], height * height_bias,n,0.0,edge,x,1,0.0,0.0,y,alpha,1.0);
|
2014-04-17 09:39:53 +00:00
|
|
|
|
|
|
|
if (local_weather.cloud_shadow_flag == 1)
|
|
|
|
{
|
|
|
|
var cs = local_weather.cloudShadow.new(lat, lon, 0.9 * (1.5 * x)/5000.0 , 0.7);
|
|
|
|
cs.index = getprop(lw~"tiles/tile-counter");
|
|
|
|
append(cloudShadowCandidateArray,cs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (size>0.4)
|
|
|
|
{
|
|
|
|
var type = "Cumulus (cloudlet)";
|
|
|
|
var height = 100;
|
2012-06-11 08:47:00 +00:00
|
|
|
var n = 2 + int(height_bias * 0.5);
|
2011-09-23 21:22:19 +00:00
|
|
|
var x = 600.0;
|
|
|
|
var y = 100.0;
|
|
|
|
var edge = 1.0;
|
|
|
|
|
|
|
|
var alpha = rand() * 180.0;
|
|
|
|
edge = edge + edge_bias;
|
2012-06-11 08:47:00 +00:00
|
|
|
create_streak(type,lat,lon, alt+ 0.5* (height * height_bias)-offset_map["Cumulus"], height * height_bias,n,0.0,edge,x,1,0.0,0.0,y,alpha,1.0);
|
2014-04-17 09:39:53 +00:00
|
|
|
|
|
|
|
if (local_weather.cloud_shadow_flag == 1)
|
|
|
|
{
|
|
|
|
var cs = local_weather.cloudShadow.new(lat, lon, 0.9 * (1.0 * x)/5000.0 , 0.6);
|
|
|
|
cs.index = getprop(lw~"tiles/tile-counter");
|
|
|
|
append(cloudShadowCandidateArray,cs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var type = "Cumulus (whisp)";
|
|
|
|
var height = 100;
|
|
|
|
var n = 1;
|
|
|
|
var x = 100.0;
|
|
|
|
var y = 100.0;
|
|
|
|
var edge = 1.0;
|
|
|
|
|
|
|
|
var alpha = rand() * 180.0;
|
|
|
|
edge = edge + edge_bias;
|
2012-01-03 19:21:34 +00:00
|
|
|
create_streak(type,lat,lon, alt+ 0.3* (height )-offset_map["Cumulus"], height,n,0.0,edge,x,1,0.0,0.0,y,alpha,1.0);
|
2011-09-23 21:22:19 +00:00
|
|
|
}
|
2010-06-04 21:05:32 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
###########################################################
|
|
|
|
# detailed small Cumulonimbus clouds created from multiple cloudlets
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var create_cumulonimbus_cloud = func(lat, lon, alt, size) {
|
|
|
|
|
2011-07-03 21:39:01 +00:00
|
|
|
|
2013-03-01 07:40:05 +00:00
|
|
|
create_cloudbox("Cb_box", lat, lon, alt, 2500.0,2000.0, 1000.0,10, 0.2, 0.1, 1.0, 1, 0.8, 0.1, 6);
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2013-03-01 07:40:05 +00:00
|
|
|
#create_cloudbox = func (type, blat, blon, balt, dx,dy,dz,n, f_core, r_core, h_core, n_core, f_bottom, h_bottom, n_bottom)
|
2010-06-15 18:54:44 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 21:39:01 +00:00
|
|
|
###########################################################
|
|
|
|
# detailed small Cumulonimbus and rain created from multiple cloudlets
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var create_cumulonimbus_cloud_rain = func(lat, lon, alt, size, rain) {
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
|
2013-03-01 07:40:05 +00:00
|
|
|
create_cloudbox("Cb_box", lat, lon, alt, 2500.0,2000.0, 1000.0,10, 0.2, 0.1, 1.0, 1, 0.8, 0.1, 6);
|
2012-06-11 08:47:00 +00:00
|
|
|
|
2011-07-03 21:39:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
# place a rain texture
|
|
|
|
|
|
|
|
var path = "Models/Weather/rain2.xml";
|
|
|
|
if (thread_flag == 1)
|
|
|
|
{create_cloud_vec(path, lat, lon, alt, 0.0);}
|
|
|
|
else
|
|
|
|
{compat_layer.create_cloud(path, lat, lon, alt, 0.0);}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# and some rain underneath
|
|
|
|
|
|
|
|
create_effect_volume(1, lat, lon, 2000.0, 2000.0, 0.0, 0.0, alt+1000.0, 8000.0 + 8000.0 * rand(), rain, -1, -1, -1 ,1,-1 );
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
###########################################################
|
|
|
|
# wrappers for convective cloud system to distribute
|
|
|
|
# call across several frames if needed
|
2010-04-12 20:51:46 +00:00
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var create_cumosys = func (blat, blon, balt, nc, size) {
|
|
|
|
|
2012-11-20 13:11:21 +00:00
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
# realistic Cumulus has somewhat larger models, so compensate to get the same coverage
|
2010-10-26 19:40:33 +00:00
|
|
|
if (detailed_clouds_flag == 1)
|
2010-06-15 18:54:44 +00:00
|
|
|
{nc = int(0.7 * nc);}
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2011-05-14 13:15:20 +00:00
|
|
|
nc = int(nc / cumulus_efficiency_factor);
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (thread_flag == 1)
|
2010-06-04 21:05:32 +00:00
|
|
|
{setprop(lw~"tmp/convective-status", "computing");
|
|
|
|
cumulus_loop(blat, blon, balt, nc, size);}
|
|
|
|
|
|
|
|
else
|
|
|
|
{create_cumulus(blat, blon, balt, nc, size);
|
2010-10-26 19:40:33 +00:00
|
|
|
if (debug_output_flag == 1)
|
|
|
|
{print("Convective system done!");}
|
|
|
|
}
|
2010-06-04 21:05:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var cumulus_loop = func (blat, blon, balt, nc, size) {
|
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
if (local_weather_running_flag == 0) {return;}
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
if (local_weather.features.fast_geodinfo == 0)
|
|
|
|
{var n = int(25/cumulus_efficiency_factor);}
|
|
|
|
else
|
|
|
|
{var n = int(200/cumulus_efficiency_factor);}
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
if (nc < 0)
|
|
|
|
{
|
2010-10-26 19:40:33 +00:00
|
|
|
if (debug_output_flag == 1)
|
|
|
|
{print("Convective system done!");}
|
2010-08-03 06:18:14 +00:00
|
|
|
setprop(lw~"tmp/convective-status", "idle");
|
|
|
|
assemble_effect_array();
|
2011-07-03 21:39:01 +00:00
|
|
|
convective_size_bias = 0.0;
|
2012-06-11 08:47:00 +00:00
|
|
|
height_bias = 1.0;
|
2010-08-03 06:18:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
create_cumulus(blat, blon, balt, n, size);
|
|
|
|
|
|
|
|
settimer( func {cumulus_loop(blat, blon, balt, nc-n, size) },0);
|
|
|
|
}
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# place a convective cloud system
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var create_cumulus = func (blat, blon, balt, nc, size) {
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
var path = "Models/Weather/blank.ac";
|
|
|
|
var i = 0;
|
|
|
|
var p = 0.0;
|
|
|
|
var rn = 0.0;
|
|
|
|
var place_lift_flag = 0;
|
2010-06-04 21:05:32 +00:00
|
|
|
var strength = 0.0;
|
2010-10-26 19:40:33 +00:00
|
|
|
var detail_flag = detailed_clouds_flag;
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
var alpha = getprop(lw~"tmp/tile-orientation-deg") * math.pi/180.0; # the tile orientation
|
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
var tile_index = getprop(lw~"tiles/tile-counter");
|
2015-01-02 07:12:44 +00:00
|
|
|
var alt_base = balt;
|
|
|
|
if (presampling_flag==1) {alt_base = alt_20_array[tile_index -1];}
|
|
|
|
|
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
|
2014-03-10 08:29:14 +00:00
|
|
|
#var sec_to_rad = 2.0 * math.pi/86400; # conversion factor for sinusoidal dependence on daytime
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
calc_geo(blat);
|
|
|
|
|
|
|
|
# get the local time of the day in seconds
|
|
|
|
|
|
|
|
var t = getprop("sim/time/utc/day-seconds");
|
|
|
|
t = t + getprop("sim/time/local-offset");
|
|
|
|
|
|
|
|
# print("t is now:", t);
|
|
|
|
|
|
|
|
# and make a simple sinusoidal model of thermal strength
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
# daily variation in number of thermals, peaks at noon
|
|
|
|
var t_factor1 = 0.5 * (1.0-math.cos((t * sec_to_rad)));
|
|
|
|
|
|
|
|
# daily variation in strength of thermals, peaks around 15:30
|
|
|
|
var t_factor2 = 0.5 * (1.0-math.cos((t * sec_to_rad)-0.9));
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
# number of possible thermals equals overall strength times daily variation times geographic variation
|
|
|
|
# this is a proxy for solar thermal energy
|
|
|
|
|
|
|
|
nc = t_factor1 * nc * math.cos(blat/180.0*math.pi);
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
# var thermal_conditions = getprop(lw~"config/thermal-properties");
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
while (i < nc) {
|
|
|
|
|
|
|
|
p = 0.0;
|
|
|
|
place_lift_flag = 0;
|
2010-06-04 21:05:32 +00:00
|
|
|
strength = 0.0;
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
# pick a trial position inside the tile and rotate by tile orientation angle
|
2010-04-12 20:51:46 +00:00
|
|
|
var x = (2.0 * rand() - 1.0) * size;
|
|
|
|
var y = (2.0 * rand() - 1.0) * size;
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
var lat = blat + (y * math.cos(alpha) - x * math.sin(alpha)) * m_to_lat;
|
|
|
|
var lon = blon + (x * math.cos(alpha) + y * math.sin(alpha)) * m_to_lon;
|
|
|
|
|
|
|
|
# now check ground cover type on chosen spot
|
2010-04-12 20:51:46 +00:00
|
|
|
var info = geodinfo(lat, lon);
|
|
|
|
|
|
|
|
if (info != nil) {
|
2010-06-15 18:54:44 +00:00
|
|
|
var elevation = info[0] * m_to_ft;
|
2010-04-12 20:51:46 +00:00
|
|
|
if (info[1] != nil){
|
|
|
|
var landcover = info[1].names[0];
|
|
|
|
if (contains(landcover_map,landcover)) {p = p + landcover_map[landcover];}
|
|
|
|
else {print(p, " ", info[1].names[0]);}
|
|
|
|
}}
|
2012-01-03 19:21:34 +00:00
|
|
|
else {
|
|
|
|
# to avoid gaps, we create default clouds
|
|
|
|
|
|
|
|
p = p + 0.1;
|
|
|
|
var elevation = alt_base;
|
|
|
|
# continue;
|
|
|
|
}
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
|
|
|
|
# apply some optional corrections, biases clouds towards higher elevations
|
|
|
|
|
|
|
|
var terrain_altitude_factor = 1.0;
|
2011-09-23 21:22:19 +00:00
|
|
|
var terrain_strength_factor = 1.0;
|
2011-06-13 19:57:21 +00:00
|
|
|
|
|
|
|
if (detailed_terrain_interaction_flag == 1)
|
|
|
|
{
|
2011-09-23 21:22:19 +00:00
|
|
|
|
|
|
|
terrain_altitude_factor = get_terrain_altitude_factor(tile_index, balt, elevation);
|
|
|
|
terrain_strength_factor = get_terrain_strength_factor(terrain_altitude_factor);
|
2011-06-13 19:57:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
# then decide if the thermal energy at the spot generates an updraft and a cloud
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
if (rand() < (p * cumulus_efficiency_factor * terrain_altitude_factor)) # we decide to place a cloud at this spot
|
2010-04-12 20:51:46 +00:00
|
|
|
{
|
2011-09-23 21:22:19 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
# check if we have a terrain elevation analysis available and can use a
|
|
|
|
# detailed placement altitude correction
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (presampling_flag == 1)
|
2010-06-15 18:54:44 +00:00
|
|
|
{
|
2011-09-23 21:22:19 +00:00
|
|
|
|
|
|
|
if (detailed_terrain_interaction_flag == 1)
|
|
|
|
{
|
|
|
|
var grad = get_terrain_gradient(lat, lon, elevation, alpha, 1000.0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{var grad = 0.0;}
|
|
|
|
|
|
|
|
|
|
|
|
var place_alt = get_convective_altitude(balt, elevation, getprop(lw~"tiles/tile-counter"), grad);
|
2010-06-15 18:54:44 +00:00
|
|
|
}
|
|
|
|
else {var place_alt = balt;}
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
# no cloud placement into the ground
|
|
|
|
if (place_alt < elevation) {continue;}
|
|
|
|
|
|
|
|
# if we're in a lee, we may not want to place the cloud
|
|
|
|
|
|
|
|
if (detailed_terrain_interaction_flag == 1)
|
|
|
|
{
|
2013-02-11 12:29:15 +00:00
|
|
|
var p_lee_suppression = get_lee_bias(grad, tile_index);
|
2011-09-23 21:22:19 +00:00
|
|
|
if (rand() > p_lee_suppression) {continue;}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
# now decide on the strength of the thermal at the spot and on cloud size
|
|
|
|
|
|
|
|
var rn = rand();
|
|
|
|
strength = (1.5 * rn + (2.0 * p * terrain_strength_factor)) * t_factor2;
|
2012-06-11 08:47:00 +00:00
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
# the terrain effect cannot create Cb development, so we have to curb
|
|
|
|
# the strength if it would not have been Cb otherwise
|
|
|
|
|
|
|
|
if (strength > 2.0)
|
|
|
|
{
|
|
|
|
if (((1.5 * rn + (2.0 * p)) * t_factor2) < 2.0)
|
|
|
|
{strength = 1.7 + rand() * 0.2;}
|
|
|
|
}
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
if (strength > 1.0) {place_lift_flag = 1;}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
cloud_mean_altitude = place_alt;
|
|
|
|
cloud_fractional_lifetime = rand();
|
|
|
|
cloud_evolution_timestamp = weather_dynamics.time_lw;
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (generate_thermal_lift_flag != 3) # no clouds if we produce blue thermals
|
2010-06-04 21:05:32 +00:00
|
|
|
{
|
2012-06-11 08:47:00 +00:00
|
|
|
create_detailed_cumulus_cloud(lat, lon, place_alt, strength);
|
2010-06-04 21:05:32 +00:00
|
|
|
}
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
# now see if we need to create a thermal - first check the flag
|
2010-10-26 19:40:33 +00:00
|
|
|
if (generate_thermal_lift_flag == 1) # thermal by constant
|
2010-04-12 20:51:46 +00:00
|
|
|
{
|
|
|
|
# now check if convection is strong
|
|
|
|
if (place_lift_flag == 1)
|
2010-06-04 21:05:32 +00:00
|
|
|
{
|
2010-06-15 18:54:44 +00:00
|
|
|
var lift = 3.0 + 10.0 * (strength -1.0);
|
2010-06-04 21:05:32 +00:00
|
|
|
var radius = 500 + 500 * rand();
|
2010-06-15 18:54:44 +00:00
|
|
|
#print("Lift: ", lift * ft_to_m - 1.0);
|
2010-10-26 19:40:33 +00:00
|
|
|
create_effect_volume(1, lat, lon, radius, radius, 0.0, 0.0, place_alt+500.0, -1, -1, -1, -1, lift, 1,-1);
|
2010-04-12 20:51:46 +00:00
|
|
|
} # end if place_lift_flag
|
|
|
|
} # end if generate-thermal-lift-flag
|
2010-10-26 19:40:33 +00:00
|
|
|
else if ((generate_thermal_lift_flag == 2) or (generate_thermal_lift_flag == 3)) # thermal by function
|
2010-06-04 21:05:32 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (place_lift_flag == 1)
|
|
|
|
{
|
2010-06-15 18:54:44 +00:00
|
|
|
var lift = (3.0 + 10.0 * (strength -1.0))/thermal_conditions;
|
|
|
|
var radius = (500 + 500 * rand())*thermal_conditions;
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
create_effect_volume(1, lat, lon, 1.1*radius, 1.1*radius, 0.0, 0.0, place_alt*1.15, -1, -1, -1, lift*0.03, lift, -2,-1);
|
2010-06-04 21:05:32 +00:00
|
|
|
} # end if place_lift_flag
|
|
|
|
|
|
|
|
} # end if generate-thermal-lift-flag
|
|
|
|
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
} # end if rand < p
|
|
|
|
i = i + 1;
|
|
|
|
} # end while
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#################################################################
|
|
|
|
# respawn convective clouds to compensate for decay
|
|
|
|
# the difference being that new clouds get zero fractional
|
|
|
|
# lifetime and are placed based on terrain with a different weight
|
|
|
|
##################################################################
|
|
|
|
|
|
|
|
var recreate_cumulus = func (blat, blon, balt, alpha, nc, size, tile_index) {
|
|
|
|
|
|
|
|
var path = "Models/Weather/blank.ac";
|
|
|
|
var i = 0;
|
|
|
|
var p = 0.0;
|
|
|
|
var rn = 0.0;
|
|
|
|
var place_lift_flag = 0;
|
|
|
|
var strength = 0.0;
|
|
|
|
var detail_flag = detailed_clouds_flag;
|
|
|
|
|
|
|
|
alpha = alpha * math.pi/180.0; # the tile orientation
|
|
|
|
|
|
|
|
|
|
|
|
# current aircraft position
|
|
|
|
|
|
|
|
var alat = getprop("position/latitude-deg");
|
|
|
|
var alon = getprop("position/longitude-deg");
|
|
|
|
|
|
|
|
# get the local time of the day in seconds
|
|
|
|
|
|
|
|
var t = getprop("sim/time/utc/day-seconds");
|
|
|
|
t = t + getprop("sim/time/local-offset");
|
|
|
|
|
|
|
|
|
|
|
|
# and make a simple sinusoidal model of thermal strength
|
|
|
|
|
|
|
|
# daily variation in number of thermals, peaks at noon
|
|
|
|
var t_factor1 = 0.5 * (1.0-math.cos((t * sec_to_rad)));
|
|
|
|
|
|
|
|
# daily variation in strength of thermals, peaks around 15:30
|
|
|
|
var t_factor2 = 0.5 * (1.0-math.cos((t * sec_to_rad)-0.9));
|
|
|
|
|
|
|
|
|
|
|
|
# number of possible thermals equals overall strength times daily variation times geographic variation
|
|
|
|
# this is a proxy for solar thermal energy
|
|
|
|
|
|
|
|
nc = t_factor1 * nc * math.cos(blat/180.0*math.pi);
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
# var thermal_conditions = getprop(lw~"config/thermal-properties");
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
var alt_base = alt_20_array[tile_index -1];
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
while (i < nc) {
|
|
|
|
|
|
|
|
p = 0.0;
|
|
|
|
place_lift_flag = 0;
|
|
|
|
strength = 0.0;
|
|
|
|
|
|
|
|
# pick a trial position inside the tile and rotate by tile orientation angle
|
|
|
|
var x = (2.0 * rand() - 1.0) * size;
|
|
|
|
var y = (2.0 * rand() - 1.0) * size;
|
|
|
|
|
|
|
|
var lat = blat + (y * math.cos(alpha) - x * math.sin(alpha)) * m_to_lat;
|
|
|
|
var lon = blon + (x * math.cos(alpha) + y * math.sin(alpha)) * m_to_lon;
|
|
|
|
|
|
|
|
# check if the cloud would be spawned in visual range, if not don't bother
|
|
|
|
var d_sq = calc_d_sq(alat, alon, lat, lon);
|
|
|
|
|
|
|
|
if (math.sqrt(d_sq) > weather_tile_management.cloud_view_distance)
|
|
|
|
{i = i+1; continue;}
|
|
|
|
|
|
|
|
# now check ground cover type on chosen spot
|
|
|
|
var info = geodinfo(lat, lon);
|
|
|
|
|
|
|
|
if (info != nil) {
|
|
|
|
var elevation = info[0] * m_to_ft;
|
|
|
|
if (info[1] != nil){
|
|
|
|
var landcover = info[1].names[0];
|
|
|
|
if (contains(landcover_map,landcover)) {p = p + landcover_map[landcover];}
|
|
|
|
else {print(p, " ", info[1].names[0]);}
|
|
|
|
}}
|
2012-01-03 19:21:34 +00:00
|
|
|
else {
|
|
|
|
# to avoid gaps, we create default clouds
|
|
|
|
|
|
|
|
p = p + 0.1;
|
|
|
|
var elevation = alt_base;
|
|
|
|
# continue;
|
|
|
|
}
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
|
|
|
|
# apply some optional corrections, biases clouds towards higher elevations
|
|
|
|
|
|
|
|
var terrain_altitude_factor = 1.0;
|
|
|
|
var terrain_strength_factor = 1.0;
|
|
|
|
|
|
|
|
if (detailed_terrain_interaction_flag == 1)
|
|
|
|
{
|
|
|
|
terrain_altitude_factor = get_terrain_altitude_factor(tile_index, balt, elevation);
|
|
|
|
terrain_strength_factor = get_terrain_strength_factor(terrain_altitude_factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
# check if to place a cloud with weight sqrt(p), the lifetime gets another sqrt(p) factor
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
if (rand() > math.sqrt(p * cumulus_efficiency_factor * terrain_altitude_factor))
|
2010-10-26 19:40:33 +00:00
|
|
|
{i=i+1; continue;}
|
|
|
|
|
|
|
|
|
|
|
|
# then calculate the strength of the updraft
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
strength = (1.5 * rand() + (2.0 * p * terrain_strength_factor)) * t_factor2; # the strength of thermal activity at the spot
|
2010-10-26 19:40:33 +00:00
|
|
|
if (strength > 1.0)
|
|
|
|
{
|
|
|
|
path = select_cloud_model("Cumulus","large"); place_lift_flag = 1;
|
|
|
|
}
|
|
|
|
else {path = select_cloud_model("Cumulus","small");}
|
|
|
|
|
|
|
|
if (presampling_flag == 1)
|
|
|
|
{
|
2011-09-23 21:22:19 +00:00
|
|
|
var place_alt = get_convective_altitude(balt, elevation, tile_index,0.0);
|
2010-10-26 19:40:33 +00:00
|
|
|
}
|
|
|
|
else {var place_alt = balt;}
|
2011-09-23 21:22:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
# no cloud placement into the ground
|
|
|
|
if (place_alt < elevation) {continue;}
|
|
|
|
|
|
|
|
# if we're in a lee, we may not want to place the cloud
|
|
|
|
|
|
|
|
if (detailed_terrain_interaction_flag == 1)
|
|
|
|
{
|
2013-02-11 12:29:15 +00:00
|
|
|
var p_lee_suppression = get_lee_bias(grad, tile_index);
|
2011-09-23 21:22:19 +00:00
|
|
|
if (rand() > math.sqrt(p_lee_suppression)) {continue;}
|
|
|
|
}
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
cloud_mean_altitude = place_alt;
|
|
|
|
cloud_fractional_lifetime = 0.0;
|
|
|
|
cloud_evolution_timestamp = weather_dynamics.time_lw;
|
|
|
|
|
|
|
|
compat_layer.cloud_mean_altitude = place_alt;
|
|
|
|
compat_layer.cloud_flt = cloud_fractional_lifetime;
|
|
|
|
compat_layer.cloud_evolution_timestamp = cloud_evolution_timestamp;
|
|
|
|
|
|
|
|
if (generate_thermal_lift_flag != 3) # no clouds if we produce blue thermals
|
|
|
|
{
|
|
|
|
if (thread_flag == 1)
|
|
|
|
{
|
|
|
|
thread_flag = 0; # create clouds immediately
|
|
|
|
if (detail_flag == 0){compat_layer.create_cloud(path,lat,lon, place_alt, 0.0);}
|
|
|
|
else {create_detailed_cumulus_cloud(lat, lon, place_alt, strength);}
|
|
|
|
thread_flag = 1; # and restore threading
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (detail_flag == 0){compat_layer.create_cloud(path, lat, lon, place_alt, 0.0);}
|
|
|
|
else {create_detailed_cumulus_cloud(lat, lon, place_alt, strength);}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (generate_thermal_lift_flag == 1) # thermal by constant
|
|
|
|
{
|
|
|
|
if (place_lift_flag == 1)
|
|
|
|
{
|
|
|
|
var lift = 3.0 + 10.0 * (strength -1.0);
|
|
|
|
var radius = 500 + 500 * rand();
|
|
|
|
create_effect_volume(1, lat, lon, radius, radius, 0.0, 0.0, place_alt+500.0, -1, -1, -1, -1, lift, 1,-1);
|
|
|
|
} # end if place_lift_flag
|
|
|
|
} # end if generate-thermal-lift-flag
|
|
|
|
else if ((generate_thermal_lift_flag == 2) or (generate_thermal_lift_flag == 3)) # thermal by function
|
|
|
|
{
|
|
|
|
if (place_lift_flag == 1)
|
|
|
|
{
|
|
|
|
var lift = (3.0 + 10.0 * (strength -1.0))/thermal_conditions;
|
|
|
|
var radius = (500 + 500 * rand())*thermal_conditions;
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
create_effect_volume(1, lat, lon, 1.1*radius, 1.1*radius, 0.0, 0.0, place_alt*1.15, -1, -1, -1, lift*0.03, lift, -2,-1);
|
2010-10-26 19:40:33 +00:00
|
|
|
} # end if place_lift_flag
|
|
|
|
|
|
|
|
} # end if generate-thermal-lift-flag
|
|
|
|
|
|
|
|
|
|
|
|
i = i + 1;
|
|
|
|
} # end while
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# place a barrier cloud system
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var create_rise_clouds = func (blat, blon, balt, nc, size, winddir, dist) {
|
|
|
|
|
|
|
|
var path = "Models/Weather/blank.ac";
|
|
|
|
var i = 0;
|
|
|
|
var p = 0.0;
|
|
|
|
var rn = 0.0;
|
|
|
|
var nsample = 10;
|
|
|
|
var counter = 0;
|
|
|
|
var dir = (winddir + 180.0) * math.pi/180.0;
|
|
|
|
var step = dist/nsample;
|
|
|
|
|
|
|
|
calc_geo(blat);
|
|
|
|
|
|
|
|
while (i < nc) {
|
|
|
|
|
|
|
|
counter = counter + 1;
|
|
|
|
p = 0.0;
|
|
|
|
|
|
|
|
var x = (2.0 * rand() - 1.0) * size;
|
|
|
|
var y = (2.0 * rand() - 1.0) * size;
|
|
|
|
|
|
|
|
var lat = blat + y * m_to_lat;
|
|
|
|
var lon = blon + x * m_to_lon;
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var elevation = compat_layer.get_elevation(lat, lon);
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
#print("elevation: ", elevation, "balt: ", balt);
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if ((elevation < balt) and (elevation != -1.0))
|
2010-04-12 20:51:46 +00:00
|
|
|
{
|
|
|
|
for (var j = 0; j<nsample; j=j+1)
|
|
|
|
{
|
|
|
|
d = j * step;
|
|
|
|
x = d * math.sin(dir);
|
|
|
|
y = d * math.cos(dir);
|
|
|
|
var tlat = lat + y * m_to_lat;
|
|
|
|
var tlon = lon + x * m_to_lon;
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
#print("x: ", x, "y: ", y);
|
|
|
|
|
|
|
|
var elevation1 = compat_layer.get_elevation(tlat,tlon);
|
|
|
|
#print("elevation1: ", elevation1, "balt: ", balt);
|
|
|
|
|
|
|
|
if (elevation1 > balt)
|
2010-08-03 06:18:14 +00:00
|
|
|
{
|
|
|
|
p = 1.0 - j * (1.0/nsample);
|
2010-10-26 19:40:33 +00:00
|
|
|
#p = 1.0;
|
2010-08-03 06:18:14 +00:00
|
|
|
break;
|
2010-04-12 20:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (counter > 500) {print("Cannot place clouds - exiting..."); i = nc;}
|
|
|
|
if (rand() < p)
|
2010-10-26 19:40:33 +00:00
|
|
|
{
|
|
|
|
path = select_cloud_model("Stratus (structured)","large");
|
2010-08-03 06:18:14 +00:00
|
|
|
compat_layer.create_cloud(path, lat, lon, balt, 0.0);
|
2010-10-26 19:40:33 +00:00
|
|
|
counter = 0;
|
|
|
|
i = i+1;
|
|
|
|
}
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
} # end while
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# place a cloud streak
|
|
|
|
###########################################################
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
var create_streak = func (type, blat, blong, balt, alt_var, nx, xoffset, edgex, x_var, ny, yoffset, edgey, y_var, direction, tri) {
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
var flag = 0;
|
|
|
|
var path = "Models/Weather/blank.ac";
|
|
|
|
calc_geo(blat);
|
|
|
|
var dir = direction * math.pi/180.0;
|
|
|
|
|
|
|
|
var ymin = -0.5 * ny * yoffset;
|
|
|
|
var xmin = -0.5 * nx * xoffset;
|
|
|
|
var xinc = xoffset * (tri-1.0) /ny;
|
|
|
|
|
|
|
|
var jlow = int(nx*edgex);
|
|
|
|
var ilow = int(ny*edgey);
|
|
|
|
|
|
|
|
|
|
|
|
for (var i=0; i<ny; i=i+1)
|
|
|
|
{
|
2010-08-03 06:18:14 +00:00
|
|
|
var y = ymin + i * yoffset;
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
for (var j=0; j<nx; j=j+1)
|
|
|
|
{
|
2010-08-03 06:18:14 +00:00
|
|
|
var y0 = y + y_var * 2.0 * (rand() -0.5);
|
|
|
|
var x = xmin + j * (xoffset + i * xinc) + x_var * 2.0 * (rand() -0.5);
|
|
|
|
var lat = blat + m_to_lat * (y0 * math.cos(dir) - x * math.sin(dir));
|
|
|
|
var long = blong + m_to_lon * (x * math.cos(dir) + y0 * math.sin(dir));
|
|
|
|
|
|
|
|
var alt = balt + alt_var * 2 * (rand() - 0.5);
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
flag = 0;
|
|
|
|
var rn = 6.0 * rand();
|
|
|
|
|
|
|
|
if (((j<jlow) or (j>(nx-jlow-1))) and ((i<ilow) or (i>(ny-ilow-1)))) # select a small or no cloud
|
|
|
|
{
|
|
|
|
if (rn > 2.0) {flag = 1;} else {path = select_cloud_model(type,"small");}
|
|
|
|
}
|
|
|
|
if ((j<jlow) or (j>(nx-jlow-1)) or (i<ilow) or (i>(ny-ilow-1)))
|
|
|
|
{
|
|
|
|
if (rn > 5.0) {flag = 1;} else {path = select_cloud_model(type,"small");}
|
|
|
|
}
|
|
|
|
else { # select a large cloud
|
|
|
|
if (rn > 5.0) {flag = 1;} else {path = select_cloud_model(type,"large");}
|
|
|
|
}
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (flag==0){
|
2010-10-26 19:40:33 +00:00
|
|
|
if (thread_flag == 1)
|
2010-08-03 06:18:14 +00:00
|
|
|
{create_cloud_vec(path, lat, long, alt, 0.0);}
|
2010-06-04 21:05:32 +00:00
|
|
|
else
|
2010-08-03 06:18:14 +00:00
|
|
|
{compat_layer.create_cloud(path, lat, long, alt, 0.0);}
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
2010-04-12 20:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
###########################################################
|
|
|
|
# place a cloud layer with a gap in the middle
|
|
|
|
# (useful to reduce cloud count in large thunderstorms)
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var create_hollow_layer = func (type, blat, blon, balt, bthick, rx, ry, phi, density, edge, gap_fraction) {
|
|
|
|
|
|
|
|
|
|
|
|
var i = 0;
|
|
|
|
var area = math.pi * rx * ry;
|
|
|
|
var n = int(area/80000000.0 * 100 * density);
|
|
|
|
var path = "Models/Weather/blank.ac";
|
|
|
|
|
|
|
|
phi = phi * math.pi/180.0;
|
|
|
|
|
|
|
|
if (contains(cloud_vertical_size_map, type))
|
|
|
|
{var alt_offset = cloud_vertical_size_map[type]/2.0 * m_to_ft;}
|
|
|
|
else {var alt_offset = 0.0;}
|
|
|
|
|
|
|
|
while(i<n)
|
|
|
|
{
|
|
|
|
var x = rx * (2.0 * rand() - 1.0);
|
|
|
|
var y = ry * (2.0 * rand() - 1.0);
|
|
|
|
var alt = balt + bthick * rand() + 0.8 * alt_offset;
|
|
|
|
var res = (x*x)/(rx*rx) + (y*y)/(ry*ry);
|
|
|
|
|
|
|
|
|
|
|
|
if ((res < 1.0) and (res > (gap_fraction * gap_fraction)))
|
|
|
|
{
|
|
|
|
var lat = blat + m_to_lat * (y * math.cos(phi) - x * math.sin(phi));
|
|
|
|
var lon = blon + m_to_lon * (x * math.cos(phi) + y * math.sin(phi));
|
|
|
|
if (res > ((1.0 - edge) * (1.0- edge)))
|
|
|
|
{
|
|
|
|
if (rand() > 0.4) {
|
|
|
|
path = select_cloud_model(type,"small");
|
|
|
|
compat_layer.create_cloud(path, lat, lon, alt, 0.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
path = select_cloud_model(type,"large");
|
2010-10-26 19:40:33 +00:00
|
|
|
if (thread_flag == 1)
|
2010-08-03 06:18:14 +00:00
|
|
|
{create_cloud_vec(path, lat, lon, alt, 0.0);}
|
|
|
|
else
|
|
|
|
{compat_layer.create_cloud(path, lat, lon, alt, 0.0);}
|
|
|
|
}
|
|
|
|
i = i + 1;
|
|
|
|
}
|
|
|
|
else # we are in the central gap region
|
|
|
|
{
|
|
|
|
i = i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
###########################################################
|
|
|
|
# place a cloud box
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
var create_cloudbox = func (type, blat, blon, balt, dx,dy,dz,n, f_core, r_core, h_core, n_core, f_bottom, h_bottom, n_bottom) {
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
var phi = 0;
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
# first get core coordinates
|
|
|
|
|
|
|
|
var core_dx = dx * f_core;
|
|
|
|
var core_dy = dy * f_core;
|
|
|
|
var core_dz = dz * h_core;
|
|
|
|
|
|
|
|
var core_x_offset = (1.0 * rand() - 0.5) * ((dx - core_dx) * r_core);
|
|
|
|
var core_y_offset = (1.0 * rand() - 0.5) * ((dy - core_dy) * r_core);
|
|
|
|
|
|
|
|
# get the bottom geometry
|
|
|
|
|
|
|
|
var bottom_dx = dx * f_bottom;
|
|
|
|
var bottom_dy = dy * f_bottom;
|
|
|
|
var bottom_dz = dz * h_bottom;
|
|
|
|
|
|
|
|
var bottom_offset = 400.0; # in practice, need a small shift
|
|
|
|
|
|
|
|
# fill the main body of the box
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
for (var i=0; i<n; i=i+1)
|
|
|
|
{
|
|
|
|
|
|
|
|
var x = 0.5 * dx * (2.0 * rand() - 1.0);
|
2010-08-03 06:18:14 +00:00
|
|
|
var y = 0.5 * dy * (2.0 * rand() - 1.0);
|
|
|
|
|
|
|
|
# veto in core region
|
|
|
|
if ((x > core_x_offset - 0.5 * core_dx) and (x < core_x_offset + 0.5 * core_dx))
|
|
|
|
{
|
|
|
|
if ((y > core_y_offset - 0.5 * core_dy) and (y < core_y_offset + 0.5 * core_dy))
|
|
|
|
{
|
|
|
|
i = i -1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var alt = balt + bottom_dz + bottom_offset + dz * rand();
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
var lat = blat + m_to_lat * (y * math.cos(phi) - x * math.sin(phi));
|
|
|
|
var lon = blon + m_to_lon * (x * math.cos(phi) + y * math.sin(phi));
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
var path = select_cloud_model(type,"standard");
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
|
|
|
|
create_cloud_vec(path, lat, lon, alt, 0.0);
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
# fill the core region
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
for (var i=0; i<n_core; i=i+1)
|
|
|
|
{
|
|
|
|
var x = 0.5 * core_dx * (2.0 * rand() - 1.0);
|
|
|
|
var y = 0.5 * core_dy * (2.0 * rand() - 1.0);
|
|
|
|
var alt = balt + bottom_dz + bottom_offset + core_dz * rand();
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
var lat = blat + m_to_lat * (y * math.cos(phi) - x * math.sin(phi));
|
|
|
|
var lon = blon + m_to_lon * (x * math.cos(phi) + y * math.sin(phi));
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
var path = select_cloud_model(type,"core");
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (thread_flag == 1)
|
2010-08-03 06:18:14 +00:00
|
|
|
{create_cloud_vec(path, lat, lon, alt, 0.0);}
|
|
|
|
else
|
|
|
|
{compat_layer.create_cloud(path, lat, lon, alt, 0.0);}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# fill the bottom region
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
for (var i=0; i<n_bottom; i=i+1)
|
2010-06-04 21:05:32 +00:00
|
|
|
{
|
2010-08-03 06:18:14 +00:00
|
|
|
var x = 0.5 * bottom_dx * (2.0 * rand() - 1.0);
|
|
|
|
var y = 0.5 * bottom_dy * (2.0 * rand() - 1.0);
|
|
|
|
var alt = balt + bottom_dz * rand();
|
|
|
|
|
|
|
|
|
|
|
|
var lat = blat + m_to_lat * (y * math.cos(phi) - x * math.sin(phi));
|
|
|
|
var lon = blon + m_to_lon * (x * math.cos(phi) + y * math.sin(phi));
|
|
|
|
|
|
|
|
var path = select_cloud_model(type,"bottom");
|
|
|
|
|
2018-08-30 06:28:33 +00:00
|
|
|
var top_shade_store = local_weather.top_shade;
|
|
|
|
if (top_shade_store > 0.6) {local_weather.top_shade = 0.6;}
|
2010-10-26 19:40:33 +00:00
|
|
|
if (thread_flag == 1)
|
2010-08-03 06:18:14 +00:00
|
|
|
{create_cloud_vec(path, lat, lon, alt, 0.0);}
|
|
|
|
else
|
|
|
|
{compat_layer.create_cloud(path, lat, lon, alt, 0.0);}
|
2018-08-30 06:28:33 +00:00
|
|
|
local_weather.top_shade = top_shade_store;
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
}
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
###########################################################
|
|
|
|
# terrain presampling initialization
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var terrain_presampling_start = func (blat, blon, nc, size, alpha) {
|
|
|
|
|
2011-04-19 20:55:25 +00:00
|
|
|
# terrain presampling start is always used the first time, and initializes
|
|
|
|
# the hard-coded routine if that is available since the hard-coded routine cannot
|
|
|
|
# be yet read out on startup
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
# initialize the result vector
|
|
|
|
|
2012-03-08 22:20:39 +00:00
|
|
|
setsize(terrain_n,40);
|
|
|
|
for(var j=0;j<40;j=j+1){terrain_n[j]=0;}
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
if (thread_flag == 1)
|
|
|
|
{
|
|
|
|
var status = getprop(lw~"tmp/presampling-status");
|
|
|
|
if (status != "idle") # we try a second later
|
|
|
|
{
|
|
|
|
settimer( func {terrain_presampling_start(blat, blon, nc, size, alpha);},1.00);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setprop(lw~"tmp/presampling-status", "sampling");
|
|
|
|
terrain_presampling_loop (blat, blon, nc, size, alpha);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
terrain_presampling(blat, blon, nc, size, alpha);
|
|
|
|
terrain_presampling_analysis();
|
|
|
|
setprop(lw~"tmp/presampling-status", "finished");
|
|
|
|
}
|
2011-04-19 20:55:25 +00:00
|
|
|
|
2012-03-08 22:20:39 +00:00
|
|
|
if (compat_layer.features.terrain_presampling == 1)
|
2011-04-19 20:55:25 +00:00
|
|
|
{
|
|
|
|
print("Starting hard-coded terrain presampling");
|
2012-03-08 22:20:39 +00:00
|
|
|
setprop("/environment/terrain/area[0]/enabled",1);
|
2011-04-19 20:55:25 +00:00
|
|
|
setprop(lw~"tmp/presampling-status", "sampling");
|
2012-01-13 14:50:36 +00:00
|
|
|
setprop("/environment/terrain/area[0]/enabled", 1 );
|
2011-04-19 20:55:25 +00:00
|
|
|
setprop("/environment/terrain/area[0]/input/latitude-deg", blat );
|
|
|
|
setprop("/environment/terrain/area[0]/input/longitude-deg", blon );
|
|
|
|
setprop("/environment/terrain/area[0]/input/use-aircraft-position",1);
|
|
|
|
setprop("/environment/terrain/area[0]/input/radius-m",45000.0);
|
|
|
|
|
|
|
|
setprop("/environment/terrain/area[0]/output/valid", 0 );
|
|
|
|
|
|
|
|
}
|
2010-06-15 18:54:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# terrain presampling loop
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var terrain_presampling_loop = func (blat, blon, nc, size, alpha) {
|
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
if ((local_weather_running_flag == 0) and (local_weather_startup_flag == 0)) {return;}
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2010-09-10 06:52:21 +00:00
|
|
|
|
2012-11-20 13:11:21 +00:00
|
|
|
var n = 25;
|
|
|
|
var n_out = 25;
|
2011-09-23 21:22:19 +00:00
|
|
|
if (local_weather.features.fast_geodinfo == 0)
|
2012-11-20 13:11:21 +00:00
|
|
|
{
|
2011-09-23 21:22:19 +00:00
|
|
|
# dynamically drop accuracy if framerate is low
|
2010-09-10 06:52:21 +00:00
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
var dt = getprop("/sim/time/delta-sec");
|
2010-09-10 06:52:21 +00:00
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
if (dt > 0.2) # we have below 20 fps
|
|
|
|
{n = 5;}
|
|
|
|
else if (dt > 0.1) # we have below 10 fps
|
|
|
|
{n = 10;}
|
|
|
|
else if (dt > 0.05) # we have below 5 fps
|
|
|
|
{n = 15;}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n = 250; n_out = 250;
|
|
|
|
}
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
if (nc <= 0) # we're done and may analyze the result
|
|
|
|
{
|
|
|
|
terrain_presampling_analysis();
|
2010-10-26 19:40:33 +00:00
|
|
|
if (debug_output_flag == 1)
|
|
|
|
{print("Presampling done!");}
|
2010-06-15 18:54:44 +00:00
|
|
|
setprop(lw~"tmp/presampling-status", "finished");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
terrain_presampling(blat, blon, n, size, alpha);
|
|
|
|
|
2010-09-10 06:52:21 +00:00
|
|
|
settimer( func {terrain_presampling_loop(blat, blon, nc-n_out, size, alpha) },0);
|
2010-06-15 18:54:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# terrain presampling routine
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var terrain_presampling = func (blat, blon, ntries, size, alpha) {
|
|
|
|
|
|
|
|
var phi = alpha * math.pi/180.0;
|
|
|
|
var elevation = 0.0;
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
var lat_vec = [];
|
|
|
|
var lon_vec = [];
|
2010-09-10 06:52:21 +00:00
|
|
|
var lat_lon_vec = [];
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
for (var i=0; i<ntries; i=i+1)
|
|
|
|
{
|
|
|
|
var x = (2.0 * rand() - 1.0) * size;
|
|
|
|
var y = (2.0 * rand() - 1.0) * size;
|
2010-09-10 06:52:21 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
append(lat_vec, blat + (y * math.cos(phi) - x * math.sin(phi)) * m_to_lat);
|
|
|
|
append(lon_vec, blon + (x * math.cos(phi) + y * math.sin(phi)) * m_to_lon);
|
2010-08-03 06:18:14 +00:00
|
|
|
}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
var elevation_vec = compat_layer.get_elevation_array(lat_vec, lon_vec);
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2012-11-20 13:11:21 +00:00
|
|
|
for (var i=0; i<ntries;i=i+1)
|
2010-08-03 06:18:14 +00:00
|
|
|
{
|
2012-11-20 13:11:21 +00:00
|
|
|
for(var j=0;j<30;j=j+1)
|
2010-06-15 18:54:44 +00:00
|
|
|
{
|
2010-08-03 06:18:14 +00:00
|
|
|
if ((elevation_vec[i] != -1.0) and (elevation_vec[i] < 500.0 * (j+1)))
|
2010-06-15 18:54:44 +00:00
|
|
|
{terrain_n[j] = terrain_n[j]+1; break;}
|
|
|
|
}
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# terrain presampling analysis
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var terrain_presampling_analysis = func {
|
|
|
|
|
2011-04-19 20:55:25 +00:00
|
|
|
if ((compat_layer.features.terrain_presampling_active == 0) or (getprop(lw~"tiles/tile-counter") == 0))
|
|
|
|
{
|
|
|
|
var sum = 0;
|
|
|
|
var alt_mean = 0;
|
|
|
|
var alt_med = 0;
|
|
|
|
var alt_20 = 0;
|
|
|
|
var alt_min = 0;
|
|
|
|
var alt_low_min = 0;
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
|
2012-03-08 22:20:39 +00:00
|
|
|
for (var i=0; i<40;i=i+1)
|
2011-04-19 20:55:25 +00:00
|
|
|
{sum = sum + terrain_n[i];}
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2011-04-19 20:55:25 +00:00
|
|
|
var n_tot = sum;
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2011-04-19 20:55:25 +00:00
|
|
|
sum = 0;
|
2012-03-08 22:20:39 +00:00
|
|
|
for (var i=0; i<40;i=i+1)
|
2011-04-19 20:55:25 +00:00
|
|
|
{
|
|
|
|
sum = sum + terrain_n[i];
|
|
|
|
if (sum > int(0.5 *n_tot)) {alt_med = i * 500.0; break;}
|
|
|
|
}
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2011-04-19 20:55:25 +00:00
|
|
|
sum = 0;
|
2012-03-08 22:20:39 +00:00
|
|
|
for (var i=0; i<40;i=i+1)
|
2011-04-19 20:55:25 +00:00
|
|
|
{
|
|
|
|
sum = sum + terrain_n[i];
|
|
|
|
if (sum > int(0.3 *n_tot)) {alt_20 = i * 500.0; break;}
|
|
|
|
}
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
|
2012-03-08 22:20:39 +00:00
|
|
|
for (var i=0; i<40;i=i+1) {alt_mean = alt_mean + terrain_n[i] * i * 500.0;}
|
2011-04-19 20:55:25 +00:00
|
|
|
alt_mean = alt_mean/n_tot;
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2012-03-08 22:20:39 +00:00
|
|
|
for (var i=0; i<40;i=i+1) {if (terrain_n[i] > 0) {alt_min = i * 500.0; break;}}
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2011-04-19 20:55:25 +00:00
|
|
|
var n_max = 0;
|
|
|
|
sum = 0;
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2012-03-08 22:20:39 +00:00
|
|
|
for (var i=0; i<39;i=i+1)
|
2011-04-19 20:55:25 +00:00
|
|
|
{
|
|
|
|
sum = sum + terrain_n[i];
|
|
|
|
if (terrain_n[i] > n_max) {n_max = terrain_n[i];}
|
|
|
|
if ((n_max > terrain_n[i+1]) and (sum > int(0.3*n_tot)))
|
|
|
|
{alt_low_min = i * 500; break;}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2010-06-15 18:54:44 +00:00
|
|
|
{
|
2012-11-20 13:11:21 +00:00
|
|
|
# print("Hard-coded sampling...");
|
2011-04-19 20:55:25 +00:00
|
|
|
var n_tot = getprop("/environment/terrain/area[0]/input/max-samples");
|
|
|
|
var alt_mean = getprop("/environment/terrain/area[0]/output/alt-mean-ft");
|
|
|
|
var alt_med = getprop("/environment/terrain/area[0]/output/alt-median-ft");
|
|
|
|
var alt_min = getprop("/environment/terrain/area[0]/output/alt-min-ft");
|
|
|
|
var alt_20 = getprop("/environment/terrain/area[0]/output/alt-offset-ft");
|
2010-06-15 18:54:44 +00:00
|
|
|
}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (debug_output_flag == 1)
|
|
|
|
{print("Terrain presampling analysis results:");
|
|
|
|
print("total: ",n_tot," mean: ",alt_mean," median: ",alt_med," min: ",alt_min, " alt_20: ", alt_20);}
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2011-04-19 20:55:25 +00:00
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
setprop(lw~"tmp/tile-alt-offset-ft",alt_20);
|
|
|
|
setprop(lw~"tmp/tile-alt-median-ft",alt_med);
|
|
|
|
setprop(lw~"tmp/tile-alt-min-ft",alt_min);
|
2011-06-13 19:57:21 +00:00
|
|
|
setprop(lw~"tmp/tile-alt-mean-ft",alt_mean);
|
2011-04-19 20:55:25 +00:00
|
|
|
setprop(lw~"tmp/tile-alt-layered-ft",0.5 * (alt_min + alt_20));
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
append(alt_50_array, alt_med);
|
2012-11-20 13:11:21 +00:00
|
|
|
append(alt_20_array, alt_20);
|
2011-09-23 21:22:19 +00:00
|
|
|
append(alt_min_array, alt_min);
|
|
|
|
append(alt_mean_array, alt_mean);
|
2012-03-08 22:20:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
current_mean_alt = 0.5 * (current_mean_alt + alt_20);
|
|
|
|
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# wave conditions search
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var wave_detection_loop = func (blat, blon, nx, alpha) {
|
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
if (local_weather_running_flag == 0) {return;}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var phi = alpha * math.pi/180.0;
|
|
|
|
var elevation = 0.0;
|
|
|
|
var ny = 20;
|
|
|
|
|
|
|
|
|
|
|
|
for (var i=0; i<ny; i=i+1)
|
|
|
|
{
|
|
|
|
var x = 5000.0;
|
|
|
|
var y = -20000.0 + i * 2000.0;
|
|
|
|
|
|
|
|
var lat = blat + (y * math.cos(phi) - x * math.sin(phi)) * m_to_lat;
|
|
|
|
var lon = blon + (x * math.cos(phi) + y * math.sin(phi)) * m_to_lon;
|
|
|
|
|
|
|
|
elevation = compat_layer.get_elevation(lat, lon);
|
|
|
|
|
|
|
|
print(elevation);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
###########################################################
|
|
|
|
# detailed altitude determination for convective calls
|
|
|
|
# clouds follow the terrain to some degree, but not excessively so
|
|
|
|
###########################################################
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
var get_convective_altitude = func (balt, elevation, tile_index, grad) {
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var alt_offset = alt_20_array[tile_index - 1];
|
|
|
|
var alt_median = alt_50_array[tile_index - 1];
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
# get the maximal shift
|
|
|
|
var alt_variation = alt_median - alt_offset;
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
# always get some amount of leeway
|
|
|
|
if (alt_variation < 500.0) {alt_variation = 500.0;}
|
|
|
|
|
|
|
|
# get the correction to the maximal shift by detailed terrain
|
|
|
|
|
|
|
|
if (detailed_terrain_interaction_flag == 1)
|
|
|
|
{
|
|
|
|
var gradfact = get_gradient_factor(grad);
|
|
|
|
|
|
|
|
if ((local_weather.wind_model_flag == 1) or (local_weather.wind_model_flag == 3))
|
|
|
|
{
|
|
|
|
var windspeed = tile_wind_speed[0];
|
|
|
|
}
|
|
|
|
else if ((local_weather.wind_model_flag ==2) or (local_weather.wind_model_flag == 4) or (local_weather.wind_model_flag == 5))
|
|
|
|
{
|
|
|
|
var windspeed = tile_wind_speed[tile_index-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
var gradfact = ((gradfact - 1.0) * windspeed) + 1.0;
|
|
|
|
#print("gradfact: ", gradfact);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var gradfact = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
var alt_variation = alt_variation * gradfact;
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
# get the difference between offset and foot point
|
|
|
|
var alt_diff = elevation - alt_offset;
|
|
|
|
|
|
|
|
# now get the elevation-induced shift
|
|
|
|
|
|
|
|
var fraction = alt_diff / alt_variation;
|
|
|
|
|
|
|
|
if (fraction > 1.0) {fraction = 1.0;} # no placement above maximum shift
|
|
|
|
if (fraction < 0.0) {fraction = 0.0;} # no downward shift
|
|
|
|
|
|
|
|
# get the cloud base
|
|
|
|
|
|
|
|
var cloudbase = balt - alt_offset;
|
|
|
|
|
|
|
|
var alt_above_terrain = balt - elevation;
|
|
|
|
|
|
|
|
# the shift strength is weakened if the layer is high above base elevation
|
|
|
|
# the reference altitude is 1000 ft, anything higher has less sensitivity to terrain
|
|
|
|
|
|
|
|
var shift_strength = 1000.0/alt_above_terrain;
|
|
|
|
|
|
|
|
if (shift_strength > 1.0) {shift_strength = 1.0;} # no enhancement for very low layers
|
2010-10-26 19:40:33 +00:00
|
|
|
if (shift_strength < 0.0) {shift_strength = 1.0;} # this shouldn't happen, but just in case...
|
|
|
|
|
|
|
|
if (alt_diff > alt_variation) {alt_diff = alt_variation;} # maximal shift is given by alt_variation
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
# print("balt: ", balt, " new alt: ", balt + shift_strength * alt_diff * fraction);
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
return balt + shift_strength * alt_diff * fraction;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# detailed terrain gradient determination in wind direction
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
|
|
|
|
var get_terrain_gradient = func (lat, lon, elevation1, phi, dist) {
|
|
|
|
|
|
|
|
|
|
|
|
# get the first elevation
|
|
|
|
# var elevation1 = compat_layer.get_elevation(lat,lon);
|
|
|
|
|
|
|
|
# look <dist> upwind to learn about the history of the cloud
|
|
|
|
var elevation2 = compat_layer.get_elevation(lat+weather_tiles.get_lat(0.0,dist,phi), lon+weather_tiles.get_lon(0.0,dist,phi));
|
|
|
|
|
|
|
|
return (elevation2 - elevation1)/(dist * m_to_ft);
|
|
|
|
}
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# enhancement of the placement altitude due to terrain
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var get_gradient_factor = func (grad) {
|
|
|
|
|
|
|
|
if (grad > 0.0)
|
|
|
|
{return 1.0;}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1.0 -2.0 * grad;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# suppression of placement in lee terrain
|
|
|
|
###########################################################
|
|
|
|
|
2013-02-11 12:29:15 +00:00
|
|
|
var get_lee_bias = func (grad, tile_index) {
|
2011-09-23 21:22:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
if ((local_weather.wind_model_flag == 1) or (local_weather.wind_model_flag == 3))
|
|
|
|
{
|
|
|
|
var windspeed = tile_wind_speed[0];
|
|
|
|
}
|
|
|
|
else if ((local_weather.wind_model_flag ==2) or (local_weather.wind_model_flag == 4) or (local_weather.wind_model_flag == 5))
|
|
|
|
{
|
|
|
|
var windspeed = tile_wind_speed[tile_index-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (grad < 0.0)
|
|
|
|
{return 1.0;}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var lee_bias = 1.0 - (grad * 0.2 * windspeed);
|
|
|
|
}
|
|
|
|
if (lee_bias < 0.2) {lee_bias = 0.2;}
|
|
|
|
|
|
|
|
return lee_bias;
|
|
|
|
}
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# enhancement of Cumulus in above average altitude
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
|
|
|
|
var get_terrain_altitude_factor = func (tile_index, balt, elevation) {
|
|
|
|
|
|
|
|
|
|
|
|
var alt_mean = alt_mean_array[tile_index -1];
|
|
|
|
var alt_base = alt_20_array[tile_index -1];
|
|
|
|
|
|
|
|
var alt_layer = balt - alt_base;
|
|
|
|
var alt_above_terrain = balt - elevation;
|
|
|
|
var alt_above_mean = balt - alt_mean;
|
|
|
|
|
|
|
|
# the cloud may still be above terrain even if the layer altitude is negative, but we want to avoid neg. factors here
|
|
|
|
|
|
|
|
if (alt_above_terrain < 0.0) {alt_above_terrain = 0.0;}
|
|
|
|
|
|
|
|
var norm_alt_diff = (alt_above_mean - alt_above_terrain)/alt_layer;
|
|
|
|
|
|
|
|
if (norm_alt_diff > 0.0)
|
|
|
|
{
|
|
|
|
var terrain_altitude_factor = 1.0 + 2.0 * norm_alt_diff;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var terrain_altitude_factor = 1.0/(1.0 - 5.0 * norm_alt_diff);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (terrain_altitude_factor > 3.0) {terrain_altitude_factor = 3.0;}
|
|
|
|
if (terrain_altitude_factor < 0.1) {terrain_altitude_factor = 0.1;}
|
|
|
|
|
|
|
|
return terrain_altitude_factor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var get_terrain_strength_factor = func (terrain_altitude_factor) {
|
|
|
|
|
|
|
|
return 1.0+ (0.5 * (terrain_altitude_factor-1.0));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
###########################################################
|
|
|
|
# terrain presampling listener dispatcher
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var manage_presampling = func {
|
|
|
|
|
2011-04-19 20:55:25 +00:00
|
|
|
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
var status = getprop(lw~"tmp/presampling-status");
|
|
|
|
|
2011-04-19 20:55:25 +00:00
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
# we only take action when the analysis is done
|
|
|
|
if (status != "finished") {return;}
|
|
|
|
|
|
|
|
if (getprop(lw~"tiles/tile-counter") == 0) # we deal with a tile setup call from the menu
|
|
|
|
{
|
|
|
|
set_tile();
|
|
|
|
}
|
|
|
|
else # the tile setup call came from weather_tile_management
|
|
|
|
{
|
|
|
|
var lat = getprop(lw~"tiles/tmp/latitude-deg");
|
|
|
|
var lon = getprop(lw~"tiles/tmp/longitude-deg");
|
|
|
|
var code = getprop(lw~"tiles/tmp/code");
|
2010-08-03 06:18:14 +00:00
|
|
|
var dir_index = getprop(lw~"tiles/tmp/dir-index");
|
|
|
|
|
|
|
|
weather_tile_management.generate_tile(code, lat, lon, dir_index);
|
2010-06-15 18:54:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# set status to idle again
|
|
|
|
|
|
|
|
setprop(lw~"tmp/presampling-status", "idle");
|
|
|
|
|
2011-04-19 20:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# hardcoded terrain presampling listener dispatcher
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var manage_hardcoded_presampling = func {
|
|
|
|
|
|
|
|
var status = getprop("/environment/terrain/area[0]/enabled");
|
|
|
|
|
|
|
|
print("Hard-coded terrain presampling status: ", status);
|
|
|
|
|
|
|
|
# no action unless the sampler has finished
|
|
|
|
if (status ==0) {return;}
|
|
|
|
|
|
|
|
# no action if the sampler hasn't been started
|
|
|
|
|
|
|
|
if (getprop(lw~"tmp/presampling-status") != "sampling") {return;}
|
|
|
|
|
|
|
|
terrain_presampling_analysis();
|
|
|
|
if (debug_output_flag == 1)
|
|
|
|
{print("Presampling done!");}
|
|
|
|
setprop(lw~"tmp/presampling-status", "finished");
|
|
|
|
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
###########################################################
|
|
|
|
# set wind model flag
|
|
|
|
###########################################################
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
var set_wind_model_flag = func {
|
|
|
|
|
|
|
|
var wind_model = getprop(lw~"config/wind-model");
|
|
|
|
|
|
|
|
if (wind_model == "constant") {wind_model_flag = 1;}
|
|
|
|
else if (wind_model == "constant in tile") {wind_model_flag =2;}
|
|
|
|
else if (wind_model == "aloft interpolated") {wind_model_flag =3; }
|
|
|
|
else if (wind_model == "airmass interpolated") {wind_model_flag =4;}
|
|
|
|
else if (wind_model == "aloft waypoints") {wind_model_flag =5;}
|
|
|
|
else {print("Wind model not implemented!"); wind_model_flag =1;}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-09-10 06:52:21 +00:00
|
|
|
###########################################################
|
|
|
|
# set texture mix for convective clouds
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var set_texture_mix = func {
|
|
|
|
|
|
|
|
var thermal_properties = getprop(lw~"config/thermal-properties");
|
2012-06-11 08:47:00 +00:00
|
|
|
thermal_conditions = thermal_properties;
|
2010-09-10 06:52:21 +00:00
|
|
|
|
|
|
|
convective_texture_mix = -(thermal_properties - 1.0) * 0.4;
|
|
|
|
|
|
|
|
if (convective_texture_mix < -0.2) {convective_texture_mix = -0.2;}
|
|
|
|
if (convective_texture_mix > 0.2) {convective_texture_mix = 0.2;}
|
2012-06-11 08:47:00 +00:00
|
|
|
|
|
|
|
lowest_layer_turbulence = 0.7 - thermal_properties;
|
|
|
|
if (lowest_layer_turbulence < 0.0) {lowest_layer_turbulence = 0.0;}
|
2010-09-10 06:52:21 +00:00
|
|
|
}
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
###########################################################
|
|
|
|
# create an effect volume
|
|
|
|
###########################################################
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var create_effect_volume = func (geometry, lat, lon, r1, r2, phi, alt_low, alt_high, vis, rain, snow, turb, lift, lift_flag, sat) {
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var ev = effectVolume.new (geometry, lat, lon, r1, r2, phi, alt_low, alt_high, vis, rain, snow, turb, lift, lift_flag, sat);
|
|
|
|
ev.index = getprop(lw~"tiles/tile-counter");
|
|
|
|
ev.active_flag = 0;
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (vis < 0.0) {ev.vis_flag = 0;} else {ev.vis_flag = 1;}
|
|
|
|
if (rain < 0.0) {ev.rain_flag = 0;} else {ev.rain_flag = 1;}
|
|
|
|
if (snow < 0.0) {ev.snow_flag = 0;} else {ev.snow_flag = 1;}
|
|
|
|
if (turb < 0.0) {ev.turb_flag = 0;} else {ev.turb_flag = 1;}
|
|
|
|
if (lift_flag == 0.0) {ev.lift_flag = 0;} else {ev.lift_flag = 1;}
|
|
|
|
if (sat < 0.0) {ev.sat_flag = 0;} else {ev.sat_flag = 1;}
|
|
|
|
if (sat > 1.0) {sat = 1.0;}
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
if (lift_flag == -2) # we create a thermal by function
|
|
|
|
{
|
2010-10-26 19:40:33 +00:00
|
|
|
ev.lift_flag = 2;
|
|
|
|
ev.radius = 0.8 * r1;
|
|
|
|
ev.height = alt_high * 0.87;
|
|
|
|
ev.cn = 0.7 + rand() * 0.2;
|
|
|
|
ev.sh = 0.7 + rand() * 0.2;
|
|
|
|
ev.max_lift = lift;
|
|
|
|
ev.f_lift_radius = 0.7 + rand() * 0.2;
|
|
|
|
if (dynamics_flag == 1) # globals set by the convective system
|
|
|
|
{
|
|
|
|
ev.flt = cloud_fractional_lifetime;
|
|
|
|
ev.evolution_timestamp = cloud_evolution_timestamp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lift_flag == -3) # we create a wave lift
|
|
|
|
{
|
|
|
|
ev.lift_flag = 3;
|
|
|
|
ev.height = 10000.0; # scale height in ft
|
|
|
|
ev.max_lift = lift;
|
|
|
|
ev.index = 0; # static objects are assigned tile id zero
|
2010-06-04 21:05:32 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
# set a timestamp if needed
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (dynamics_flag == 1)
|
2010-08-03 06:18:14 +00:00
|
|
|
{
|
2010-10-26 19:40:33 +00:00
|
|
|
ev.timestamp = weather_dynamics.time_lw;
|
2010-08-03 06:18:14 +00:00
|
|
|
}
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
# and add to the counter
|
|
|
|
setprop(lw~"effect-volumes/number",getprop(lw~"effect-volumes/number")+1);
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
append(effectVolumeArray,ev);
|
2010-04-12 20:51:46 +00:00
|
|
|
}
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
###########################################################
|
2010-08-03 06:18:14 +00:00
|
|
|
# set a weather station for interpolation
|
2010-06-04 21:05:32 +00:00
|
|
|
###########################################################
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
var set_weather_station = func (lat, lon, alt, vis, T, D, p) {
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
var s = weatherStation.new (lat, lon, alt, vis, T, D, p);
|
2010-10-26 19:40:33 +00:00
|
|
|
s.index = getprop(lw~"tiles/tile-counter");
|
2011-03-19 13:03:28 +00:00
|
|
|
s.weight = 0.02;
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
# set a timestamp if needed
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (dynamics_flag == 1)
|
2010-06-04 21:05:32 +00:00
|
|
|
{
|
2010-10-26 19:40:33 +00:00
|
|
|
s.timestamp = weather_dynamics.time_lw;
|
2010-06-04 21:05:32 +00:00
|
|
|
}
|
2010-10-26 19:40:33 +00:00
|
|
|
append(weatherStationArray,s);
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
###########################################################
|
|
|
|
# set an atmosphere condition point for interpolation
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var set_atmosphere_ipoint = func (lat, lon, vis_aloft, vis_alt1, vis_ovcst, ovcst,ovcst_alt_low, ovcst_alt_high, scatt, scatt_alt_low, scatt_alt_high) {
|
|
|
|
|
|
|
|
var a = atmosphereIpoint.new (lat, lon, vis_aloft, vis_alt1, vis_ovcst, ovcst, ovcst_alt_low, ovcst_alt_high, scatt, scatt_alt_low, scatt_alt_high);
|
|
|
|
a.index = getprop(lw~"tiles/tile-counter");
|
|
|
|
a.weight = 0.02;
|
|
|
|
|
|
|
|
# set a timestamp if needed
|
|
|
|
|
|
|
|
if (dynamics_flag == 1)
|
|
|
|
{
|
|
|
|
a.timestamp = weather_dynamics.time_lw;
|
|
|
|
}
|
|
|
|
append(atmosphereIpointArray,a);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
###########################################################
|
2010-08-03 06:18:14 +00:00
|
|
|
# set a wind interpolation point
|
2010-04-12 20:51:46 +00:00
|
|
|
###########################################################
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
var set_wind_ipoint = func (lat, lon, d0, v0, d1, v1, d2, v2, d3, v3, d4, v4, d5, v5, d6, v6, d7, v7, d8, v8) {
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
var w = windIpoint.new(lat, lon, d0, v0, d1, v1, d2, v2, d3, v3, d4, v4, d5, v5, d6, v6, d7, v7, d8, v8);
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
append(windIpointArray, w);
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# set a wind interpolation point from ground METAR data
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var set_wind_ipoint_metar = func (lat, lon, d0, v0) {
|
|
|
|
|
|
|
|
# insert a plausible pattern of aloft winds based on ground info
|
|
|
|
|
|
|
|
|
|
|
|
# direction of Coriolis deflection depends on hemisphere
|
|
|
|
if (lat >0.0) {var dsign = -1.0;} else {var dsign = 1.0;}
|
|
|
|
|
|
|
|
|
2011-05-14 13:15:20 +00:00
|
|
|
var v1 = v0 * (1.0 + rand() * 0.1);
|
|
|
|
var d1 = d0 + dsign * 2.0 * rand();
|
2011-03-19 13:03:28 +00:00
|
|
|
|
|
|
|
var v2 = v0 * (1.2 + rand() * 0.2);
|
|
|
|
var d2 = d0 + dsign * (3.0 * rand() + 2.0);
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
var v3 = v0 * (1.3 + rand() * 0.4) + 5.0;
|
2014-11-16 10:28:09 +00:00
|
|
|
var d3 = d0 + dsign * (3.0 * rand() + 4.0);
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
var v4 = v0 * (1.7 + rand() * 0.5) + 10.0;
|
2014-11-16 10:28:09 +00:00
|
|
|
var d4 = d0 + dsign * (4.0 * rand() + 8.0);
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
var v5 = v0 * (1.7 + rand() * 0.5) + 20.0;
|
2014-11-16 10:28:09 +00:00
|
|
|
var d5 = d0 + dsign * (4.0 * rand() + 10.0);
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
var v6 = v0 * (1.7 + rand() * 0.5) + 40.0;
|
2014-11-16 10:28:09 +00:00
|
|
|
var d6 = d0 + dsign * (4.0 * rand() + 12.0);
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
var v7 = v0 * (2.0 + rand() * 0.7) + 50.0;
|
2014-11-16 10:28:09 +00:00
|
|
|
var d7 = d0 + dsign * (4.0 * rand() + 13.0);
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
var v8 = v0 * (2.0 + rand() * 0.7) + 55.0;;
|
2014-11-16 10:28:09 +00:00
|
|
|
var d8 = d0 + dsign * (5.0 * rand() + 14.0);
|
2011-03-19 13:03:28 +00:00
|
|
|
|
|
|
|
var w = windIpoint.new(lat, lon, d0, v0, d1, v1, d2, v2, d3, v3, d4, v4, d5, v5, d6, v6, d7, v7, d8, v8);
|
|
|
|
|
|
|
|
append(windIpointArray, w);
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
###########################################################
|
|
|
|
# helper to show additional dialogs
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var showDialog = func (name) {
|
|
|
|
|
|
|
|
fgcommand("dialog-show", props.Node.new({"dialog-name":name}));
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# helper to transfer configuration flags in menu to Nasal
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var readFlags = func {
|
|
|
|
|
|
|
|
# thermal lift must be 1 for constant thermals (obsolete), 2 for thermals by model (menu default)
|
|
|
|
# and 3 for blue thermals (set internally inside the tile only)
|
|
|
|
|
|
|
|
if (getprop(lw~"config/generate-thermal-lift-flag") ==1) {generate_thermal_lift_flag = 2;}
|
|
|
|
else {generate_thermal_lift_flag = 0};
|
|
|
|
|
|
|
|
thread_flag = getprop(lw~"config/thread-flag");
|
2012-01-03 19:21:34 +00:00
|
|
|
# dynamics_flag = getprop(lw~"config/dynamics-flag");
|
2011-05-14 13:15:20 +00:00
|
|
|
presampling_flag = getprop(lw~"config/presampling-flag");
|
2010-10-26 19:40:33 +00:00
|
|
|
detailed_clouds_flag = getprop(lw~"config/detailed-clouds-flag");
|
|
|
|
dynamical_convection_flag = getprop(lw~"config/dynamical-convection-flag");
|
|
|
|
debug_output_flag = getprop(lw~"config/debug-output-flag");
|
2011-05-14 13:15:20 +00:00
|
|
|
fps_control_flag = getprop(lw~"config/fps-control-flag");
|
2011-09-23 21:22:19 +00:00
|
|
|
realistic_visibility_flag = getprop(lw~"config/realistic-visibility-flag");
|
|
|
|
detailed_terrain_interaction_flag = getprop(lw~"config/detailed-terrain-interaction-flag");
|
2012-03-08 22:20:39 +00:00
|
|
|
scattering_shader_flag = getprop("/sim/rendering/shaders/skydome");
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2012-12-13 10:15:21 +00:00
|
|
|
# also initialize menu entries
|
|
|
|
|
|
|
|
air_pollution_norm = getprop("/environment/air-pollution-norm");
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
}
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
###########################################################
|
|
|
|
# wrappers to call functions from the local weather menu bar
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
var streak_wrapper = func {
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
thread_flag = 0;
|
|
|
|
dynamics_flag = 0;
|
|
|
|
presampling_flag = 0;
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
var array = [];
|
|
|
|
append(weather_tile_management.modelArrays,array);
|
|
|
|
setprop(lw~"tiles/tile-counter",getprop(lw~"tiles/tile-counter")+1);
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
var lat = getprop("position/latitude-deg");
|
|
|
|
var lon = getprop("position/longitude-deg");
|
|
|
|
var type = getprop("/local-weather/tmp/cloud-type");
|
|
|
|
var alt = getprop("/local-weather/tmp/alt");
|
|
|
|
var nx = getprop("/local-weather/tmp/nx");
|
|
|
|
var xoffset = getprop("/local-weather/tmp/xoffset");
|
|
|
|
var xedge = getprop("/local-weather/tmp/xedge");
|
|
|
|
var ny = getprop("/local-weather/tmp/ny");
|
|
|
|
var yoffset = getprop("/local-weather/tmp/yoffset");
|
|
|
|
var yedge = getprop("/local-weather/tmp/yedge");
|
|
|
|
var dir = getprop("/local-weather/tmp/dir");
|
|
|
|
var tri = getprop("/local-weather/tmp/tri");
|
|
|
|
var rnd_alt = getprop("/local-weather/tmp/rnd-alt");
|
|
|
|
var rnd_pos_x = getprop("/local-weather/tmp/rnd-pos-x");
|
|
|
|
var rnd_pos_y = getprop("/local-weather/tmp/rnd-pos-y");
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
create_streak(type,lat,lon,alt,rnd_alt,nx,xoffset,xedge,rnd_pos_x,ny,yoffset,yedge,rnd_pos_y,dir,tri);
|
2010-04-12 20:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var convection_wrapper = func {
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
thread_flag = 0;
|
|
|
|
dynamics_flag = 0;
|
|
|
|
presampling_flag = 0;
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
var array = [];
|
|
|
|
append(weather_tile_management.modelArrays,array);
|
|
|
|
setprop(lw~"tiles/tile-counter",getprop(lw~"tiles/tile-counter")+1);
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
var lat = getprop("position/latitude-deg");
|
|
|
|
var lon = getprop("position/longitude-deg");
|
|
|
|
var alt = getprop("/local-weather/tmp/conv-alt");
|
|
|
|
var size = getprop("/local-weather/tmp/conv-size");
|
|
|
|
var strength = getprop("/local-weather/tmp/conv-strength");
|
|
|
|
|
|
|
|
var n = int(10 * size * size * strength);
|
|
|
|
create_cumosys(lat,lon,alt,n, size*1000.0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var barrier_wrapper = func {
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
thread_flag = 0;
|
|
|
|
dynamics_flag = 0;
|
|
|
|
presampling_flag = 0;
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
var array = [];
|
|
|
|
append(weather_tile_management.modelArrays,array);
|
|
|
|
setprop(lw~"tiles/tile-counter",getprop(lw~"tiles/tile-counter")+1);
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
var lat = getprop("position/latitude-deg");
|
|
|
|
var lon = getprop("position/longitude-deg");
|
|
|
|
var alt = getprop("/local-weather/tmp/bar-alt");
|
|
|
|
var n = getprop("/local-weather/tmp/bar-n");
|
|
|
|
var dir = getprop("/local-weather/tmp/bar-dir");
|
|
|
|
var dist = getprop("/local-weather/tmp/bar-dist") * 1000.0;
|
|
|
|
var size = getprop("/local-weather/tmp/bar-size") * 1000.0;
|
|
|
|
|
|
|
|
create_rise_clouds(lat, lon, alt, n, size, dir, dist);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var single_cloud_wrapper = func {
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
thread_flag = 0;
|
|
|
|
dynamics_flag = 0;
|
|
|
|
presampling_flag = 0;
|
|
|
|
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
var array = [];
|
|
|
|
append(weather_tile_management.modelArrays,array);
|
|
|
|
setprop(lw~"tiles/tile-counter",getprop(lw~"tiles/tile-counter")+1);
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
var type = getprop("/local-weather/tmp/scloud-type");
|
|
|
|
var subtype = getprop("/local-weather/tmp/scloud-subtype");
|
|
|
|
var lat = getprop("/local-weather/tmp/scloud-lat");
|
|
|
|
var lon = getprop("/local-weather/tmp/scloud-lon");
|
|
|
|
var alt = getprop("/local-weather/tmp/scloud-alt");
|
|
|
|
var heading = getprop("/local-weather/tmp/scloud-dir");
|
|
|
|
|
|
|
|
var path = select_cloud_model(type,subtype);
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
compat_layer.create_cloud(path, lat, lon, alt, heading);
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var layer_wrapper = func {
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
thread_flag = 0;
|
|
|
|
dynamics_flag = 0;
|
|
|
|
presampling_flag = 0;
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
var array = [];
|
|
|
|
append(weather_tile_management.modelArrays,array);
|
|
|
|
setprop(lw~"tiles/tile-counter",getprop(lw~"tiles/tile-counter")+1);
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
var lat = getprop("position/latitude-deg");
|
|
|
|
var lon = getprop("position/longitude-deg");
|
|
|
|
var type = getprop(lw~"tmp/layer-type");
|
|
|
|
var rx = getprop(lw~"tmp/layer-rx") * 1000.0;
|
|
|
|
var ry = getprop(lw~"tmp/layer-ry") * 1000.0;
|
|
|
|
var phi = getprop(lw~"tmp/layer-phi");
|
|
|
|
var alt = getprop(lw~"tmp/layer-alt");
|
|
|
|
var thick = getprop(lw~"tmp/layer-thickness");
|
|
|
|
var density = getprop(lw~"tmp/layer-density");
|
|
|
|
var edge = getprop(lw~"tmp/layer-edge");
|
|
|
|
var rain_flag = getprop(lw~"tmp/layer-rain-flag");
|
|
|
|
var rain_density = getprop(lw~"tmp/layer-rain-density");
|
|
|
|
|
|
|
|
create_layer(type, lat, lon, alt, thick, rx, ry, phi, density, edge, rain_flag, rain_density);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
var box_wrapper = func {
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
thread_flag = 0;
|
|
|
|
dynamics_flag = 0;
|
|
|
|
presampling_flag = 0;
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
setprop(lw~"tiles/tile-counter",getprop(lw~"tiles/tile-counter")+1);
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
var lat = getprop("position/latitude-deg");
|
|
|
|
var lon = getprop("position/longitude-deg");
|
|
|
|
var alt = getprop("position/altitude-ft");
|
|
|
|
var x = getprop(lw~"tmp/box-x-m");
|
|
|
|
var y = getprop(lw~"tmp/box-y-m");
|
|
|
|
var z = getprop(lw~"tmp/box-alt-ft");
|
|
|
|
var n = getprop(lw~"tmp/box-n");
|
2010-08-03 06:18:14 +00:00
|
|
|
var f_core = getprop(lw~"tmp/box-core-fraction");
|
|
|
|
var r_core = getprop(lw~"tmp/box-core-offset");
|
|
|
|
var h_core = getprop(lw~"tmp/box-core-height");
|
|
|
|
var n_core = getprop(lw~"tmp/box-core-n");
|
|
|
|
var f_bottom = getprop(lw~"tmp/box-bottom-fraction");
|
|
|
|
var h_bottom = getprop(lw~"tmp/box-bottom-thickness");
|
|
|
|
var n_bottom = getprop(lw~"tmp/box-bottom-n");
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
var type = "Box_test";
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
create_cloudbox(type, lat, lon, alt, x,y,z,n, f_core, r_core, h_core, n_core, f_bottom, h_bottom, n_bottom);
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
var set_aloft_wrapper = func {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var lat = getprop(lw~"tmp/ipoint-latitude-deg");
|
|
|
|
var lon = getprop(lw~"tmp/ipoint-longitude-deg");
|
|
|
|
|
|
|
|
var d0 = getprop(lw~"tmp/FL0-wind-from-heading-deg");
|
|
|
|
var v0 = getprop(lw~"tmp/FL0-windspeed-kt");
|
|
|
|
|
|
|
|
var d1 = getprop(lw~"tmp/FL50-wind-from-heading-deg");
|
|
|
|
var v1 = getprop(lw~"tmp/FL50-windspeed-kt");
|
|
|
|
|
|
|
|
var d2 = getprop(lw~"tmp/FL100-wind-from-heading-deg");
|
|
|
|
var v2 = getprop(lw~"tmp/FL100-windspeed-kt");
|
|
|
|
|
|
|
|
var d3 = getprop(lw~"tmp/FL180-wind-from-heading-deg");
|
|
|
|
var v3 = getprop(lw~"tmp/FL180-windspeed-kt");
|
|
|
|
|
|
|
|
var d4 = getprop(lw~"tmp/FL240-wind-from-heading-deg");
|
|
|
|
var v4 = getprop(lw~"tmp/FL240-windspeed-kt");
|
|
|
|
|
|
|
|
var d5 = getprop(lw~"tmp/FL300-wind-from-heading-deg");
|
|
|
|
var v5 = getprop(lw~"tmp/FL300-windspeed-kt");
|
|
|
|
|
|
|
|
var d6 = getprop(lw~"tmp/FL340-wind-from-heading-deg");
|
|
|
|
var v6 = getprop(lw~"tmp/FL340-windspeed-kt");
|
|
|
|
|
|
|
|
var d7 = getprop(lw~"tmp/FL390-wind-from-heading-deg");
|
|
|
|
var v7 = getprop(lw~"tmp/FL390-windspeed-kt");
|
|
|
|
|
|
|
|
var d8 = getprop(lw~"tmp/FL450-wind-from-heading-deg");
|
|
|
|
var v8 = getprop(lw~"tmp/FL450-windspeed-kt");
|
|
|
|
|
|
|
|
set_wind_ipoint(lat, lon, d0, v0, d1, v1, d2, v2, d3, v3, d4, v4, d5, v5, d6, v6, d7, v7, d8, v8);
|
|
|
|
|
|
|
|
if (wind_model_flag == 5)
|
|
|
|
{setprop(lwi~"ipoint-number", getprop(lwi~"ipoint-number") + 1);}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
####################################
|
|
|
|
# tile setup call wrapper
|
|
|
|
####################################
|
|
|
|
|
|
|
|
var set_tile = func {
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
# check if another instance of local weather is running already
|
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
if (local_weather_running_flag == 1)
|
|
|
|
{
|
|
|
|
setprop("/sim/messages/pilot", "Local weather: Local weather is already running, use Clear/End before restarting. Aborting...");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
local_weather_startup_flag = 1;
|
|
|
|
|
2018-09-01 06:46:33 +00:00
|
|
|
# randomize high ice scattering properties
|
|
|
|
|
|
|
|
setprop("/environment/scattering-phenomena/ring-factor", rand());
|
|
|
|
setprop("/environment/scattering-phenomena/rainbow-factor", rand());
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
var type = getprop("/local-weather/tmp/tile-type");
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
# set tile center coordinates to current position
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
var lat = getprop("position/latitude-deg");
|
|
|
|
var lon = getprop("position/longitude-deg");
|
|
|
|
|
|
|
|
setprop(lw~"tiles/tmp/latitude-deg",lat);
|
|
|
|
setprop(lw~"tiles/tmp/longitude-deg",lon);
|
2010-09-10 06:52:21 +00:00
|
|
|
setprop(lw~"tiles/tmp/dir-index",4);
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
readFlags();
|
|
|
|
|
|
|
|
# check consistency of flags
|
|
|
|
|
|
|
|
if (dynamical_convection_flag == 1)
|
|
|
|
{
|
|
|
|
if (dynamics_flag == 0)
|
|
|
|
{
|
|
|
|
print("Dynamical convection needs weather dynamics to run! Aborting...");
|
|
|
|
setprop("/sim/messages/pilot", "Local weather: dynamical convection needs weather dynamics to run! Aborting...");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (presampling_flag == 0)
|
|
|
|
{
|
|
|
|
print("Dynamical convection needs terrain presampling to run! Aborting...");
|
|
|
|
setprop("/sim/messages/pilot", "Local weather: dynamical convection needs terrain presampling to run! Aborting...");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
if (detailed_terrain_interaction_flag == 1)
|
|
|
|
{
|
|
|
|
if (presampling_flag == 0)
|
|
|
|
{
|
|
|
|
print("Terrain effect needs terrain presampling to run! Aborting...");
|
|
|
|
setprop("/sim/messages/pilot", "Local weather: terrain effect needs terrain presampling to run! Aborting...");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2011-01-05 12:36:10 +00:00
|
|
|
# if we can do so, we switch global weather and METAR parsing in environment off at this point
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
if (compat_layer.features.can_disable_environment ==1)
|
|
|
|
{
|
|
|
|
props.globals.getNode("/environment/config/enabled").setBoolValue(0);
|
2011-01-05 12:36:10 +00:00
|
|
|
props.globals.getNode("/environment/params/metar-updates-environment").setBoolValue(0);
|
2010-10-26 19:40:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
# switch off normal 3d clouds
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
local_weather.setDefaultCloudsOff();
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2014-02-17 08:21:26 +00:00
|
|
|
# read max. visibility range and set far camera clipping
|
|
|
|
|
|
|
|
max_vis_range = math.exp(getprop(lw~"config/aux-max-vis-range-m"));
|
|
|
|
setprop(lw~"config/max-vis-range-m",max_vis_range);
|
|
|
|
if (max_vis_range>120000.0){setprop("/sim/rendering/camera-group/zfar",max_vis_range);}
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
# now see if we need to presample the terrain
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if ((presampling_flag == 1) and (getprop(lw~"tmp/presampling-status") == "idle"))
|
2010-06-15 18:54:44 +00:00
|
|
|
{
|
2010-08-03 06:18:14 +00:00
|
|
|
terrain_presampling_start(lat, lon, 1000, 40000, getprop(lw~"tmp/tile-orientation-deg"));
|
2010-06-15 18:54:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
# indicate that we're up and running
|
|
|
|
|
|
|
|
local_weather_startup_flag = 0;
|
|
|
|
local_weather_running_flag = 1;
|
|
|
|
|
2011-01-05 12:36:10 +00:00
|
|
|
# see if we use METAR for weather setup
|
|
|
|
|
|
|
|
if ((getprop("/environment/metar/valid") == 1) and (getprop(lw~"tmp/tile-management") == "METAR"))
|
|
|
|
{
|
|
|
|
type = "METAR";
|
|
|
|
metar_flag = 1;
|
|
|
|
|
|
|
|
setprop(lw~"METAR/station-id","METAR");
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2011-01-05 12:36:10 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else if ((getprop("/environment/metar/valid") == 0) and (getprop(lw~"tmp/tile-management") == "METAR"))
|
|
|
|
{
|
|
|
|
print("No METAR available, aborting...");
|
|
|
|
setprop("/sim/messages/pilot", "Local weather: No METAR available! Aborting...");
|
|
|
|
return;
|
|
|
|
}
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
# see if we need to create an aloft wind interpolation structure
|
|
|
|
|
2013-02-11 12:29:15 +00:00
|
|
|
set_wind_model_flag();
|
|
|
|
|
2013-03-01 07:40:05 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
if ((wind_model_flag == 3) or ((wind_model_flag ==5) and (getprop(lwi~"ipoint-number") == 0)))
|
2011-03-19 13:03:28 +00:00
|
|
|
{
|
|
|
|
if (metar_flag != 1)
|
|
|
|
{set_aloft_wrapper();}
|
|
|
|
}
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
# prepare the first tile wind field
|
|
|
|
|
2011-01-05 12:36:10 +00:00
|
|
|
if (metar_flag == 1) # the winds from current METAR are used
|
2010-08-03 06:18:14 +00:00
|
|
|
{
|
2011-03-19 13:03:28 +00:00
|
|
|
|
|
|
|
# METAR reports ground winds, we want to set aloft, so we need to compute the local boundary layer
|
|
|
|
# need to set the tile index for this
|
|
|
|
setprop(lw~"tiles/tile[4]/tile-index",1);
|
|
|
|
|
|
|
|
var boundary_correction = 1.0/get_slowdown_fraction();
|
|
|
|
var metar_base_wind_deg = getprop("environment/metar/base-wind-dir-deg");
|
|
|
|
var metar_base_wind_speed = boundary_correction * getprop("environment/metar/base-wind-speed-kt");
|
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
# set the wind hash for the new scheme
|
|
|
|
|
|
|
|
wind.cloudlayer = [metar_base_wind_deg,metar_base_wind_speed];
|
|
|
|
wind.surface = [metar_base_wind_deg,metar_base_wind_speed/boundary_correction];
|
|
|
|
wind.current = wind.surface;
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2011-01-05 12:36:10 +00:00
|
|
|
if ((wind_model_flag == 1) or (wind_model_flag == 2))
|
|
|
|
{
|
2011-03-19 13:03:28 +00:00
|
|
|
append(weather_dynamics.tile_wind_direction, metar_base_wind_deg);
|
|
|
|
append(weather_dynamics.tile_wind_speed, metar_base_wind_speed);
|
|
|
|
setprop(lw~"tmp/tile-orientation-deg",metar_base_wind_deg);
|
|
|
|
}
|
|
|
|
else if (wind_model_flag == 5)
|
|
|
|
{
|
|
|
|
var station_lat = getprop("/environment/metar/station-latitude-deg");
|
|
|
|
var station_lon = getprop("/environment/metar/station-longitude-deg");
|
|
|
|
|
|
|
|
set_wind_ipoint_metar(station_lat, station_lon, metar_base_wind_deg, metar_base_wind_speed);
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
var res = wind_interpolation(lat,lon,0.0);
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2015-01-02 07:12:44 +00:00
|
|
|
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
append(weather_dynamics.tile_wind_direction,res[0]);
|
|
|
|
append(weather_dynamics.tile_wind_speed,res[1]);
|
|
|
|
setprop(lw~"tmp/tile-orientation-deg", weather_dynamics.tile_wind_direction[0]);
|
2015-01-02 07:12:44 +00:00
|
|
|
|
|
|
|
# in case of gusty winds, these need to be re-initialized to the base wind
|
|
|
|
# from METAR rather than the menu
|
|
|
|
interpolated_conditions.wind_from_heading_deg = metar_base_wind_deg;
|
|
|
|
interpolated_conditions.windspeed_kt = metar_base_wind_speed;
|
2011-01-05 12:36:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print("Wind model currently not supported with live data!");
|
|
|
|
setprop("/sim/messages/pilot", "Local weather: Wind model currently not supported with live data! Aborting...");
|
|
|
|
return;
|
|
|
|
}
|
2010-08-03 06:18:14 +00:00
|
|
|
}
|
2011-01-05 12:36:10 +00:00
|
|
|
else
|
2010-08-03 06:18:14 +00:00
|
|
|
{
|
2012-01-03 19:21:34 +00:00
|
|
|
setprop(lw~"tiles/tile[4]/tile-index",1);
|
|
|
|
var boundary_correction = get_slowdown_fraction();
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-01-05 12:36:10 +00:00
|
|
|
if (wind_model_flag == 5) # it needs to be interpolated
|
|
|
|
{
|
|
|
|
var res = wind_interpolation(lat,lon,0.0);
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-01-05 12:36:10 +00:00
|
|
|
append(weather_dynamics.tile_wind_direction,res[0]);
|
|
|
|
append(weather_dynamics.tile_wind_speed,res[1]);
|
2012-01-03 19:21:34 +00:00
|
|
|
|
|
|
|
# set the wind hash for the new scheme
|
|
|
|
|
|
|
|
wind.surface = [res[0],res[1] * boundary_correction];
|
|
|
|
wind.cloudlayer = res;
|
|
|
|
wind.current = wind.surface;
|
|
|
|
|
|
|
|
|
2011-01-05 12:36:10 +00:00
|
|
|
}
|
|
|
|
else if (wind_model_flag == 3) # it comes from a different menu
|
|
|
|
{
|
|
|
|
append(weather_dynamics.tile_wind_direction, getprop(lw~"tmp/FL0-wind-from-heading-deg"));
|
|
|
|
append(weather_dynamics.tile_wind_speed, getprop(lw~"tmp/FL0-windspeed-kt"));
|
2012-01-03 19:21:34 +00:00
|
|
|
|
|
|
|
# set the wind hash for the new scheme
|
|
|
|
wind.cloudlayer = [getprop(lw~"tmp/FL0-wind-from-heading-deg"),getprop(lw~"tmp/FL0-windspeed-kt") ];
|
|
|
|
wind.surface = [wind.cloudlayer[0],wind.cloudlayer[1] * boundary_correction];
|
|
|
|
wind.current = wind.surface;
|
|
|
|
|
2011-01-05 12:36:10 +00:00
|
|
|
}
|
|
|
|
else # it comes from the standard menu
|
|
|
|
{
|
|
|
|
append(weather_dynamics.tile_wind_direction, getprop(lw~"tmp/tile-orientation-deg"));
|
|
|
|
append(weather_dynamics.tile_wind_speed, getprop(lw~"tmp/windspeed-kt"));
|
2012-01-03 19:21:34 +00:00
|
|
|
|
|
|
|
# set the wind hash for the new scheme
|
|
|
|
wind.cloudlayer = [getprop(lw~"tmp/tile-orientation-deg"),getprop(lw~"tmp/windspeed-kt")];
|
|
|
|
wind.surface = [wind.cloudlayer[0],wind.cloudlayer[1] * boundary_correction];
|
|
|
|
wind.current = wind.surface;
|
|
|
|
|
2011-01-05 12:36:10 +00:00
|
|
|
}
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-01-05 12:36:10 +00:00
|
|
|
# when the aloft wind menu is used, the lowest winds should be taken from there
|
|
|
|
# so we need to overwrite the setting from the tile generating menu in this case
|
|
|
|
# otherwise the wrong orientation is built
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
|
2011-01-05 12:36:10 +00:00
|
|
|
if (wind_model_flag ==3)
|
|
|
|
{
|
|
|
|
setprop(lw~"tmp/tile-orientation-deg", getprop(lw~"tmp/FL0-wind-from-heading-deg"));
|
|
|
|
}
|
|
|
|
else if (wind_model_flag == 5)
|
|
|
|
{
|
|
|
|
setprop(lw~"tmp/tile-orientation-deg", weather_dynamics.tile_wind_direction[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
# create all the neighbouring tile coordinate sets
|
|
|
|
|
|
|
|
weather_tile_management.create_neighbours(lat,lon,getprop(lw~"tmp/tile-orientation-deg"));
|
|
|
|
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
setprop(lw~"tiles/tile-counter",getprop(lw~"tiles/tile-counter")+1);
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
# see if we need to generate a quadtree structure for clouds
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (dynamics_flag ==1)
|
2010-08-03 06:18:14 +00:00
|
|
|
{
|
|
|
|
var quadtree = [];
|
|
|
|
weather_dynamics.generate_quadtree_structure(0, quadtree);
|
|
|
|
append(weather_dynamics.cloudQuadtrees,quadtree);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
if (type == "High-pressure-core")
|
|
|
|
{weather_tiles.set_high_pressure_core_tile();}
|
|
|
|
else if (type == "High-pressure")
|
|
|
|
{weather_tiles.set_high_pressure_tile();}
|
|
|
|
else if (type == "High-pressure-border")
|
|
|
|
{weather_tiles.set_high_pressure_border_tile();}
|
|
|
|
else if (type == "Low-pressure-border")
|
|
|
|
{weather_tiles.set_low_pressure_border_tile();}
|
|
|
|
else if (type == "Low-pressure")
|
|
|
|
{weather_tiles.set_low_pressure_tile();}
|
|
|
|
else if (type == "Low-pressure-core")
|
|
|
|
{weather_tiles.set_low_pressure_core_tile();}
|
2010-06-15 18:54:44 +00:00
|
|
|
else if (type == "Cold-sector")
|
|
|
|
{weather_tiles.set_cold_sector_tile();}
|
2010-08-03 06:18:14 +00:00
|
|
|
else if (type == "Warm-sector")
|
|
|
|
{weather_tiles.set_warm_sector_tile();}
|
2010-06-15 18:54:44 +00:00
|
|
|
else if (type == "Tropical")
|
|
|
|
{weather_tiles.set_tropical_weather_tile();}
|
|
|
|
else if (type == "Coldfront")
|
|
|
|
{weather_tiles.set_coldfront_tile();}
|
2010-08-03 06:18:14 +00:00
|
|
|
else if (type == "Warmfront")
|
2010-06-15 18:54:44 +00:00
|
|
|
{weather_tiles.set_warmfront1_tile();}
|
|
|
|
else if (type == "Warmfront-2")
|
|
|
|
{weather_tiles.set_warmfront2_tile();}
|
|
|
|
else if (type == "Warmfront-3")
|
|
|
|
{weather_tiles.set_warmfront3_tile();}
|
|
|
|
else if (type == "Warmfront-4")
|
|
|
|
{weather_tiles.set_warmfront4_tile();}
|
2012-01-03 19:21:34 +00:00
|
|
|
else if (type == "Thunderstorms")
|
|
|
|
{weather_tiles.set_thunderstorms_tile();}
|
2010-06-15 18:54:44 +00:00
|
|
|
else if (type == "METAR")
|
|
|
|
{weather_tiles.set_METAR_tile();}
|
2010-06-04 21:05:32 +00:00
|
|
|
else if (type == "Altocumulus sky")
|
|
|
|
{weather_tiles.set_altocumulus_tile();setprop(lw~"tiles/code","altocumulus_sky");}
|
|
|
|
else if (type == "Broken layers")
|
|
|
|
{weather_tiles.set_broken_layers_tile();setprop(lw~"tiles/code","broken_layers");}
|
|
|
|
else if (type == "Cold front")
|
|
|
|
{weather_tiles.set_coldfront_tile();setprop(lw~"tiles/code","coldfront");}
|
|
|
|
else if (type == "Cirrus sky")
|
|
|
|
{weather_tiles.set_cirrus_sky_tile();setprop(lw~"tiles/code","cirrus_sky");}
|
|
|
|
else if (type == "Fair weather")
|
|
|
|
{setprop(lw~"tiles/code","cumulus_sky");weather_tiles.set_fair_weather_tile();}
|
|
|
|
else if (type == "Glider's sky")
|
|
|
|
{setprop(lw~"tiles/code","gliders_sky");weather_tiles.set_gliders_sky_tile();}
|
|
|
|
else if (type == "Blue thermals")
|
|
|
|
{setprop(lw~"tiles/code","blue_thermals");weather_tiles.set_blue_thermals_tile();}
|
|
|
|
else if (type == "Incoming rainfront")
|
|
|
|
{weather_tiles.set_rainfront_tile();setprop(lw~"tiles/code","rainfront");}
|
|
|
|
else if (type == "8/8 stratus sky")
|
|
|
|
{weather_tiles.set_overcast_stratus_tile();setprop(lw~"tiles/code","overcast_stratus");}
|
|
|
|
else if (type == "Test tile")
|
|
|
|
{weather_tiles.set_4_8_stratus_tile();setprop(lw~"tiles/code","test");}
|
|
|
|
else if (type == "Summer rain")
|
|
|
|
{weather_tiles.set_summer_rain_tile();setprop(lw~"tiles/code","summer_rain");}
|
|
|
|
else
|
|
|
|
{print("Tile not implemented.");setprop(lw~"tiles/tile-counter",getprop(lw~"tiles/tile-counter")-1);return();}
|
|
|
|
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
# mark tile as active
|
|
|
|
|
|
|
|
append(weather_tile_management.active_tile_list,1);
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
# start tile management loop if needed
|
|
|
|
|
|
|
|
if (getprop(lw~"tmp/tile-management") != "single tile") {
|
|
|
|
if (getprop(lw~"tile-loop-flag") == 0)
|
2010-06-15 18:54:44 +00:00
|
|
|
{
|
|
|
|
setprop(lw~"tiles/tile[4]/code",getprop(lw~"tiles/code"));
|
|
|
|
setprop(lw~"tile-loop-flag",1);
|
|
|
|
weather_tile_management.tile_management_loop();}
|
2010-06-04 21:05:32 +00:00
|
|
|
}
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
# start the interpolation loop
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
if (getprop(lw~"interpolation-loop-flag") == 0)
|
|
|
|
{setprop(lw~"interpolation-loop-flag",1); local_weather.interpolation_loop();}
|
|
|
|
|
|
|
|
# start the effect volume loop
|
|
|
|
|
|
|
|
if (getprop(lw~"effect-loop-flag") == 0)
|
|
|
|
{setprop(lw~"effect-loop-flag",1); local_weather.effect_volume_loop(0,0);}
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
# start weather dynamics loops if needed
|
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
if (getprop(lw~"timing-loop-flag") == 0)
|
|
|
|
{setprop(lw~"timing-loop-flag",1); local_weather.timing_loop();}
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
if (dynamics_flag ==1)
|
2010-08-03 06:18:14 +00:00
|
|
|
{
|
2012-01-03 19:21:34 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
if (getprop(lw~"dynamics-loop-flag") == 0)
|
|
|
|
{
|
|
|
|
setprop(lw~"dynamics-loop-flag",1);
|
2012-06-11 08:47:00 +00:00
|
|
|
# weather_dynamics.quadtree_loop();
|
2010-10-26 19:40:33 +00:00
|
|
|
weather_dynamics.weather_dynamics_loop(0,0);
|
|
|
|
}
|
|
|
|
if ((getprop(lw~"convective-loop-flag") == 0) and (getprop(lw~"config/dynamical-convection-flag") ==1))
|
|
|
|
{
|
|
|
|
setprop(lw~"convective-loop-flag",1);
|
|
|
|
weather_dynamics.convective_loop();
|
2010-08-03 06:18:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-09-10 06:52:21 +00:00
|
|
|
# and start the buffer loop and housekeeping loop if needed
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
if (buffer_flag == 1)
|
2010-09-10 06:52:21 +00:00
|
|
|
{
|
|
|
|
if (getprop(lw~"buffer-loop-flag") == 0)
|
|
|
|
{
|
2012-06-11 08:47:00 +00:00
|
|
|
# setprop(lw~"buffer-loop-flag",1); weather_tile_management.buffer_loop(0);
|
2011-09-23 21:22:19 +00:00
|
|
|
setprop(lw~"housekeeping-loop-flag",1); weather_tile_management.housekeeping_loop(0,0);
|
2010-09-10 06:52:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-26 10:03:51 +00:00
|
|
|
# start the sea color loop
|
|
|
|
local_weather.init_sea_colors();
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2012-11-20 13:11:21 +00:00
|
|
|
# start the mask loop
|
|
|
|
#local_weather.init_mask();
|
|
|
|
|
2014-02-17 08:21:26 +00:00
|
|
|
# create impostors - this should only happen when sufficiently high in air
|
|
|
|
weather_tile_management.create_impostors();
|
2012-11-20 13:11:21 +00:00
|
|
|
|
2014-03-10 08:29:14 +00:00
|
|
|
# start the cloud shadow loop
|
|
|
|
|
2014-04-17 09:39:53 +00:00
|
|
|
local_weather.cloud_shadow_flag = getprop("/local-weather/config/generate-cloud-shadows");
|
2014-03-10 08:29:14 +00:00
|
|
|
|
|
|
|
if (local_weather.cloud_shadow_flag == 1)
|
|
|
|
{
|
|
|
|
setprop(lw~"shadow-loop-flag",1);
|
|
|
|
weather_tile_management.shadow_management_loop(0);
|
|
|
|
}
|
|
|
|
|
2015-11-16 15:41:57 +00:00
|
|
|
#weather_tile_management.watchdog_loop();
|
2010-09-10 06:52:21 +00:00
|
|
|
|
2015-08-11 13:28:32 +00:00
|
|
|
# start thunderstorm management
|
|
|
|
|
|
|
|
setprop(lw~"thunderstorm-loop-flag",1);
|
|
|
|
|
2015-08-12 08:31:05 +00:00
|
|
|
local_weather.place_model_controlled("lightning", "Models/Weather/lightning_combined.xml", lat, lon, 0.0, 0.0, 0.0, 0.0);
|
2015-08-11 13:28:32 +00:00
|
|
|
|
|
|
|
local_weather.thunderstorm_management_loop();
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#################################################
|
|
|
|
# Anything that needs to run at startup goes here
|
|
|
|
#################################################
|
|
|
|
|
|
|
|
var startup = func {
|
|
|
|
print("Loading local weather routines...");
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
# get local Cartesian geometry
|
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
var lat = getprop("position/latitude-deg");
|
|
|
|
var lon = getprop("position/longitude-deg");
|
|
|
|
calc_geo(lat);
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
# copy weather properties at startup to local weather
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
|
|
|
|
interpolated_conditions.visibility_m = getprop(ec~"boundary/entry[0]/visibility-m");
|
|
|
|
interpolated_conditions.pressure_sea_level_inhg = getprop(ec~"boundary/entry[0]/pressure-sea-level-inhg");
|
|
|
|
interpolated_conditions.temperature_degc = getprop(ec~"boundary/entry[0]/temperature-degc");
|
|
|
|
interpolated_conditions.dewpoint_degc = getprop(ec~"boundary/entry[0]/dewpoint-degc");
|
|
|
|
interpolated_conditions.wind_from_heading_deg = getprop(ec~"boundary/entry[0]/wind-from-heading-deg");
|
|
|
|
interpolated_conditions.wind_speed_kt = getprop(ec~"boundary/entry[0]/wind-speed-kt");
|
|
|
|
interpolated_conditions.turbulence = getprop(ec~"boundary/entry[0]/turbulence/magnitude-norm");
|
|
|
|
interpolated_conditions.rain_norm = 0.0;
|
|
|
|
interpolated_conditions.snow_norm = 0.0;
|
|
|
|
interpolated_conditions.thermal_lift = 0.0;
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
# before interpolation starts, these are also initially current
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
setprop(lw~"current/visibility-m",interpolated_conditions.visibility_m);
|
|
|
|
setprop(lw~"current/rain-norm",0.0);
|
|
|
|
setprop(lw~"current/snow-norm",0.0);
|
|
|
|
setprop(lw~"current/thermal-lift", 0.0);
|
|
|
|
setprop(lw~"current/turbulence",interpolated_conditions.turbulence);
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
# create default properties for METAR system, should be overwritten by real-weather-fetch
|
|
|
|
|
|
|
|
setprop(lw~"METAR/latitude-deg",lat);
|
|
|
|
setprop(lw~"METAR/longitude-deg",lon);
|
|
|
|
setprop(lw~"METAR/altitude-ft",0.0);
|
|
|
|
setprop(lw~"METAR/wind-direction-deg",0.0);
|
|
|
|
setprop(lw~"METAR/wind-strength-kt",10.0);
|
|
|
|
setprop(lw~"METAR/visibility-m",17000.0);
|
|
|
|
setprop(lw~"METAR/rain-norm",0.0);
|
|
|
|
setprop(lw~"METAR/snow-norm",0.0);
|
|
|
|
setprop(lw~"METAR/temperature-degc",10.0);
|
|
|
|
setprop(lw~"METAR/dewpoint-degc",7.0);
|
|
|
|
setprop(lw~"METAR/pressure-inhg",29.92);
|
|
|
|
setprop(lw~"METAR/thunderstorm-flag",0);
|
|
|
|
setprop(lw~"METAR/layer[0]/cover-oct",4);
|
|
|
|
setprop(lw~"METAR/layer[0]/alt-agl-ft", 3000.0);
|
|
|
|
setprop(lw~"METAR/layer[1]/cover-oct",0);
|
|
|
|
setprop(lw~"METAR/layer[1]/alt-agl-ft", 20000.0);
|
|
|
|
setprop(lw~"METAR/layer[2]/cover-oct",0);
|
|
|
|
setprop(lw~"METAR/layer[2]/alt-agl-ft", 20000.0);
|
|
|
|
setprop(lw~"METAR/layer[3]/cover-oct",0);
|
|
|
|
setprop(lw~"METAR/layer[3]/alt-agl-ft", 20000.0);
|
|
|
|
setprop(lw~"METAR/available-flag",1);
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2011-05-14 13:15:20 +00:00
|
|
|
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-05-14 13:15:20 +00:00
|
|
|
# set listeners
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
setlistener(lw~"tmp/thread-status", func {var s = size(clouds_path); compat_layer.create_cloud_array(s, clouds_path, clouds_lat, clouds_lon, clouds_alt, clouds_orientation); });
|
|
|
|
setlistener(lw~"tmp/convective-status", func {var s = size(clouds_path); compat_layer.create_cloud_array(s, clouds_path, clouds_lat, clouds_lon, clouds_alt, clouds_orientation); });
|
2010-06-04 21:05:32 +00:00
|
|
|
setlistener(lw~"tmp/effect-thread-status", func {var s = size(effects_geo); effect_placement_loop(s); });
|
2010-06-15 18:54:44 +00:00
|
|
|
setlistener(lw~"tmp/presampling-status", func {manage_presampling(); });
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2013-03-01 07:40:05 +00:00
|
|
|
#setlistener(lw~"config/wind-model", func {set_wind_model_flag();});
|
2010-09-10 06:52:21 +00:00
|
|
|
setlistener(lw~"config/thermal-properties", func {set_texture_mix();});
|
|
|
|
|
2015-11-25 19:46:51 +00:00
|
|
|
setlistener(lw~"config/clouds-in-dynamics-loop", func(n) {weather_dynamics.max_clouds_in_loop = int(n.getValue());});
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2015-11-25 19:46:51 +00:00
|
|
|
setlistener(lw~"config/clouds-visible-range-m", func(n) {weather_tile_management.cloud_view_distance = n.getValue();});
|
|
|
|
setlistener(lw~"config/distance-to-load-tile-m", func(n) {setprop(lw~"config/distance-to-remove-tile-m",n.getValue() + 500.0);});
|
2011-05-14 13:15:20 +00:00
|
|
|
|
2015-11-25 19:46:51 +00:00
|
|
|
setlistener(lw~"config/fps-control-flag", func(n) {fps_control_flag = n.getValue();});
|
|
|
|
setlistener(lw~"config/target-framerate", func(n) {target_framerate = n.getValue();});
|
2011-05-14 13:15:20 +00:00
|
|
|
|
2015-11-25 19:46:51 +00:00
|
|
|
setlistener(lw~"config/small-scale-persistence", func(n) {weather_tiles.small_scale_persistence = n.getValue();});
|
|
|
|
setlistener(lw~"config/ground-haze-factor", func(n) {ground_haze_factor = n.getValue();});
|
|
|
|
setlistener(lw~"config/aux-max-vis-range-m", func(n) {
|
|
|
|
max_vis_range = math.exp(n.getValue());
|
2014-01-30 09:08:35 +00:00
|
|
|
setprop(lw~"config/max-vis-range-m",max_vis_range);
|
|
|
|
if (max_vis_range>120000.0){setprop("/sim/rendering/camera-group/zfar",max_vis_range);}
|
|
|
|
});
|
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
|
2015-11-25 19:46:51 +00:00
|
|
|
setlistener(lw~"config/temperature-offset-degc", func(n) {temperature_offset = n.getValue();});
|
2011-05-14 13:15:20 +00:00
|
|
|
|
2015-11-25 19:46:51 +00:00
|
|
|
setlistener("/environment/air-pollution-norm", func(n) {air_pollution_norm = n.getValue() ;});
|
2012-04-26 10:03:51 +00:00
|
|
|
|
2015-11-25 19:46:51 +00:00
|
|
|
setlistener("/sim/rendering/shaders/skydome", func(n) {scattering_shader_flag = n.getValue() ; if (scattering_shader_flag ==1) {setprop("/sim/rendering/minimum-sky-visibility",0.0);} else {setprop("/sim/rendering/minimum-sky-visibility",1000.0);} });
|
2010-04-12 20:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#####################################################
|
|
|
|
# Standard test call (for development and debug only)
|
|
|
|
#####################################################
|
|
|
|
|
|
|
|
var test = func {
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
var lat = getprop("position/latitude-deg");
|
|
|
|
var lon = getprop("position/longitude-deg");
|
2012-03-08 22:20:39 +00:00
|
|
|
var alt = getprop("position/altitude-ft");
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
# thread_flag = 0;
|
|
|
|
# dynamics_flag = 0;
|
|
|
|
# presampling_flag = 0;
|
2011-09-23 21:22:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
#if (compat_layer.features.can_disable_environment ==1)
|
|
|
|
# {
|
|
|
|
# props.globals.getNode("/environment/config/enabled").setBoolValue(0);
|
|
|
|
# props.globals.getNode("/environment/params/metar-updates-environment").setBoolValue(0);
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
#compat_layer.setDefaultCloudsOff();
|
|
|
|
|
|
|
|
#var array = [];
|
|
|
|
#append(weather_tile_management.modelArrays,array);
|
|
|
|
#setprop(lw~"tiles/tile-counter",getprop(lw~"tiles/tile-counter")+1);
|
|
|
|
|
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
#var pos = geo.aircraft_position();
|
2010-09-10 06:52:21 +00:00
|
|
|
|
2012-11-20 13:11:21 +00:00
|
|
|
debug.dump(geodinfo(lat, lon));
|
2011-09-23 21:22:19 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
|
2013-04-09 06:52:19 +00:00
|
|
|
#var info = {};
|
|
|
|
|
|
|
|
#for (var i = 0; i< 100000; i=i+1)
|
|
|
|
# {
|
|
|
|
# info = geodinfo(lat, lon);
|
2012-11-20 13:11:21 +00:00
|
|
|
# }
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
}
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
#################################################################
|
|
|
|
# object classes
|
|
|
|
#################################################################
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var weatherStation = {
|
2011-03-19 13:03:28 +00:00
|
|
|
new: func (lat, lon, alt, vis, T, D, p) {
|
2010-10-26 19:40:33 +00:00
|
|
|
var s = { parents: [weatherStation] };
|
|
|
|
s.lat = lat;
|
|
|
|
s.lon = lon;
|
2011-03-19 13:03:28 +00:00
|
|
|
s.alt = alt;
|
2010-10-26 19:40:33 +00:00
|
|
|
s.vis = vis;
|
|
|
|
s.T = T;
|
|
|
|
s.D = D;
|
|
|
|
s.p = p;
|
2011-06-13 19:57:21 +00:00
|
|
|
s.scattering = 0.8;
|
2010-10-26 19:40:33 +00:00
|
|
|
return s;
|
|
|
|
},
|
|
|
|
move: func {
|
|
|
|
var windfield = weather_dynamics.get_windfield(me.index);
|
|
|
|
var dt = weather_dynamics.time_lw - me.timestamp;
|
|
|
|
me.lat = me.lat + windfield[1] * dt * local_weather.m_to_lat;
|
|
|
|
me.lon = me.lon + windfield[0] * dt * local_weather.m_to_lon;
|
|
|
|
me.timestamp = weather_dynamics.time_lw;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
var atmosphereIpoint = {
|
|
|
|
new: func (lat, lon, vis_aloft, vis_alt1, vis_ovcst, ovcst, ovcst_alt_low, ovcst_alt_high, scatt, scatt_alt_low, scatt_alt_high){
|
|
|
|
var a = { parents: [atmosphereIpoint] };
|
|
|
|
a.lat = lat;
|
|
|
|
a.lon = lon;
|
|
|
|
a.vis_aloft = vis_aloft;
|
|
|
|
a.vis_alt1 = vis_alt1;
|
|
|
|
a.vis_ovcst = vis_ovcst;
|
|
|
|
a.ovcst = ovcst;
|
|
|
|
a.ovcst_alt_low = ovcst_alt_low;
|
|
|
|
a.ovcst_alt_high = ovcst_alt_high;
|
|
|
|
a.scatt = scatt;
|
|
|
|
a.scatt_alt_low = scatt_alt_low;
|
|
|
|
a.scatt_alt_high = scatt_alt_high;
|
|
|
|
return a;
|
|
|
|
},
|
|
|
|
move: func {
|
|
|
|
var windfield = weather_dynamics.get_windfield(me.index);
|
|
|
|
var dt = weather_dynamics.time_lw - me.timestamp;
|
|
|
|
me.lat = me.lat + windfield[1] * dt * local_weather.m_to_lat;
|
|
|
|
me.lon = me.lon + windfield[0] * dt * local_weather.m_to_lon;
|
|
|
|
me.timestamp = weather_dynamics.time_lw;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
var windIpoint = {
|
|
|
|
new: func (lat, lon, d0, v0, d1, v1, d2, v2, d3, v3, d4, v4, d5, v5, d6, v6, d7, v7, d8, v8) {
|
|
|
|
var w = { parents: [windIpoint] };
|
|
|
|
w.lat = lat;
|
|
|
|
w.lon = lon;
|
|
|
|
|
|
|
|
altvec = [];
|
|
|
|
|
|
|
|
var wv = windVec.new(d0, v0);
|
|
|
|
append(altvec,wv);
|
|
|
|
|
|
|
|
wv = windVec.new(d1, v1);
|
|
|
|
append(altvec, wv);
|
|
|
|
|
|
|
|
wv = windVec.new(d2, v2);
|
|
|
|
append(altvec, wv);
|
|
|
|
|
|
|
|
wv = windVec.new(d3, v3);
|
|
|
|
append(altvec, wv);
|
|
|
|
|
|
|
|
wv = windVec.new(d4, v4);
|
|
|
|
append(altvec, wv);
|
|
|
|
|
|
|
|
wv = windVec.new(d5, v5);
|
|
|
|
append(altvec, wv);
|
|
|
|
|
|
|
|
wv = windVec.new(d6, v6);
|
|
|
|
append(altvec, wv);
|
|
|
|
|
|
|
|
wv = windVec.new(d7, v7);
|
|
|
|
append(altvec, wv);
|
|
|
|
|
|
|
|
wv = windVec.new(d8, v8);
|
|
|
|
append(altvec, wv);
|
|
|
|
|
|
|
|
w.alt = altvec;
|
|
|
|
|
|
|
|
w.weight = 0.02;
|
|
|
|
return w;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
var windVec = {
|
|
|
|
new: func (d, v) {
|
|
|
|
var wv = { parents: [windVec] };
|
|
|
|
wv.d = d;
|
|
|
|
wv.v = v;
|
|
|
|
return wv;
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var effectVolume = {
|
|
|
|
new: func (geometry, lat, lon, r1, r2, phi, alt_low, alt_high, vis, rain, snow, turb, lift, lift_flag, sat) {
|
|
|
|
var e = { parents: [effectVolume] };
|
|
|
|
e.geometry = geometry;
|
|
|
|
e.lat = lat;
|
|
|
|
e.lon = lon;
|
|
|
|
e.r1 = r1;
|
|
|
|
e.r2 = r2;
|
|
|
|
e.phi = phi;
|
|
|
|
e.alt_low = alt_low;
|
|
|
|
e.alt_high = alt_high;
|
|
|
|
e.vis = vis;
|
|
|
|
e.rain = rain;
|
|
|
|
e.snow = snow;
|
|
|
|
e.turb = turb;
|
|
|
|
e.lift = lift;
|
|
|
|
e.lift_flag = lift_flag;
|
|
|
|
e.sat = sat;
|
|
|
|
return e;
|
|
|
|
},
|
|
|
|
move: func {
|
|
|
|
var windfield = weather_dynamics.get_windfield(me.index);
|
|
|
|
var dt = weather_dynamics.time_lw - me.timestamp;
|
|
|
|
me.lat = me.lat + windfield[1] * dt * local_weather.m_to_lat;
|
|
|
|
me.lon = me.lon + windfield[0] * dt * local_weather.m_to_lon;
|
|
|
|
me.timestamp = weather_dynamics.time_lw;
|
|
|
|
},
|
|
|
|
correct_altitude: func {
|
|
|
|
var convective_alt = weather_dynamics.tile_convective_altitude[me.index-1] + alt_20_array[me.index-1];
|
|
|
|
var elevation = compat_layer.get_elevation(me.lat, me.lon);
|
2011-09-23 21:22:19 +00:00
|
|
|
me.alt_high = local_weather.get_convective_altitude(convective_alt, elevation, me.index,0.0) *1.15;
|
2010-10-26 19:40:33 +00:00
|
|
|
me.height = me.alt_high * 0.87;
|
|
|
|
},
|
|
|
|
correct_altitude_and_age: func {
|
|
|
|
var convective_alt = weather_dynamics.tile_convective_altitude[me.index-1] + local_weather.alt_20_array[me.index-1];
|
|
|
|
var elevation = -1.0; var p_cover = 0.2;
|
|
|
|
var info = geodinfo(me.lat, me.lon);
|
|
|
|
if (info != nil)
|
|
|
|
{
|
|
|
|
elevation = info[0] * local_weather.m_to_ft;
|
|
|
|
if (info[1] != nil)
|
|
|
|
{
|
|
|
|
var landcover = info[1].names[0];
|
|
|
|
if (contains(landcover_map,landcover)) {p_cover = landcover_map[landcover];}
|
|
|
|
else {p_cover = 0.2;}
|
|
|
|
}
|
|
|
|
}
|
2011-09-23 21:22:19 +00:00
|
|
|
me.alt_high = get_convective_altitude(convective_alt, elevation, me.index,0.0) * 1.15;
|
2010-10-26 19:40:33 +00:00
|
|
|
me.height = me.alt_high * 0.87;
|
|
|
|
var current_lifetime = math.sqrt(p_cover)/math.sqrt(0.35) * weather_dynamics.cloud_convective_lifetime_s;
|
|
|
|
var fractional_increase = (weather_dynamics.time_lw - me.evolution_timestamp)/current_lifetime;
|
|
|
|
me.flt = me.flt + fractional_increase;
|
|
|
|
me.evolution_timestamp = weather_dynamics.time_lw;
|
|
|
|
},
|
|
|
|
get_distance: func {
|
|
|
|
var lat = getprop("position/latitude-deg");
|
|
|
|
var lon = getprop("position/longitude-deg");
|
|
|
|
return math.sqrt(calc_d_sq(lat, lon, me.lat, me.lon));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var thermalLift = {
|
|
|
|
new: func (lat, lon, radius, height, cn, sh, max_lift, f_lift_radius) {
|
|
|
|
var l = { parents: [thermalLift] };
|
|
|
|
l.lat = lat;
|
|
|
|
l.lon = lon;
|
|
|
|
l.radius = radius;
|
|
|
|
l.height = height;
|
|
|
|
l.cn = cn;
|
|
|
|
l.sh = sh;
|
|
|
|
l.max_lift = max_lift;
|
|
|
|
l.f_lift_radius = f_lift_radius;
|
|
|
|
return l;
|
|
|
|
},
|
|
|
|
move: func {
|
|
|
|
var windfield = weather_dynamics.get_windfield(me.index);
|
|
|
|
var dt = weather_dynamics.time_lw - me.timestamp;
|
|
|
|
me.lat = me.lat + windfield[1] * dt * local_weather.m_to_lat;
|
|
|
|
me.lon = me.lon + windfield[0] * dt * local_weather.m_to_lon;
|
|
|
|
me.timestamp = weather_dynamics.time_lw;
|
|
|
|
},
|
|
|
|
correct_altitude: func {
|
|
|
|
var convective_alt = weather_dynamics.tile_convective_altitude[me.index-1] + alt_20_array[me.index-1];
|
|
|
|
var elevation = compat_layer.get_elevation(me.lat, me.lon);
|
2011-09-23 21:22:19 +00:00
|
|
|
me.height = local_weather.get_convective_altitude(convective_alt, elevation, me.index,0.0);
|
2010-10-26 19:40:33 +00:00
|
|
|
},
|
|
|
|
correct_altitude_and_age: func {
|
|
|
|
var convective_alt = weather_dynamics.tile_convective_altitude[me.index-1] + local_weather.alt_20_array[me.index-1];
|
|
|
|
var elevation = -1.0; var p_cover = 0.2;
|
|
|
|
var info = geodinfo(me.lat, me.lon);
|
|
|
|
if (info != nil)
|
|
|
|
{
|
|
|
|
elevation = info[0] * local_weather.m_to_ft;
|
|
|
|
if (info[1] != nil)
|
|
|
|
{
|
|
|
|
var landcover = info[1].names[0];
|
|
|
|
if (contains(landcover_map,landcover)) {p_cover = landcover_map[landcover];}
|
|
|
|
else {p_cover = 0.2;}
|
|
|
|
}
|
|
|
|
}
|
2011-09-23 21:22:19 +00:00
|
|
|
me.height = get_convective_altitude(convective_alt, elevation, me.index,0.0);
|
2010-10-26 19:40:33 +00:00
|
|
|
var current_lifetime = math.sqrt(p_cover)/math.sqrt(0.35) * weather_dynamics.cloud_convective_lifetime_s;
|
|
|
|
var fractional_increase = (weather_dynamics.time_lw - me.evolution_timestamp)/current_lifetime;
|
|
|
|
me.flt = me.flt + fractional_increase;
|
|
|
|
me.evolution_timestamp = weather_dynamics.time_lw;
|
|
|
|
},
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
};
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
var waveLift = {
|
|
|
|
new: func (lat, lon, x, y, phi, height, max_lift) {
|
|
|
|
var w = { parents: [waveLift] };
|
|
|
|
w.lat = lat;
|
|
|
|
w.lon = lon;
|
|
|
|
w.x = x;
|
|
|
|
w.y = y;
|
|
|
|
w.phi = phi;
|
|
|
|
w.height = height;
|
|
|
|
w.max_lift = max_lift;
|
|
|
|
w.phi = getprop(lw~"tmp/tile-orientation-deg");
|
|
|
|
return w;
|
|
|
|
},
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
};
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#################################################################
|
|
|
|
# global variable, property creation and the startup listener
|
|
|
|
#################################################################
|
|
|
|
|
|
|
|
var rad_E = 6378138.12; # earth radius
|
|
|
|
var lat_to_m = 110952.0; # latitude degrees to meters
|
|
|
|
var m_to_lat = 9.01290648208234e-06; # meters to latitude degrees
|
|
|
|
var ft_to_m = 0.30480;
|
|
|
|
var m_to_ft = 1.0/ft_to_m;
|
2014-03-10 08:29:14 +00:00
|
|
|
var sec_to_rad = 2.0 * math.pi/86400;
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
var lon_to_m = 0.0; # needs to be calculated dynamically
|
|
|
|
var m_to_lon = 0.0; # we do this on startup
|
|
|
|
|
|
|
|
# some common abbreviations
|
|
|
|
|
|
|
|
var lw = "/local-weather/";
|
|
|
|
var lwi = "/local-weather/interpolation/";
|
|
|
|
var ec = "/environment/config/";
|
|
|
|
|
|
|
|
# a hash map of the strength for convection associated with terrain types
|
|
|
|
|
2018-09-17 08:39:35 +00:00
|
|
|
var landcover_map = {BuiltUpCover: 0.35, Town: 0.35, Freeway:0.35, BarrenCover:0.3, HerbTundraCover: 0.25, GrassCover: 0.2, CropGrassCover: 0.2, EvergreenBroadCover: 0.2, EvergreenNeedleCover: 0.2, Sand: 0.25, Grass: 0.2, Grassland: 0.2, Ocean: 0.01, Marsh: 0.05, Lake: 0.01, ShrubCover: 0.15, Shrub: 0.15, Landmass: 0.2, CropWoodCover: 0.15, MixedForestCover: 0.15, DryCropPastureCover: 0.25, MixedCropPastureCover: 0.2, MixedCrop: 0.2, ComplexCrop: 0.2, IrrCropPastureCover: 0.15, DeciduousBroadCover: 0.1, DeciduousNeedleCover: 0.1, Bog: 0.05, Littoral: 0.05, pa_taxiway : 0.35, pa_tiedown: 0.35, pc_taxiway: 0.35, pc_tiedown: 0.35, Glacier: 0.03, SnowCover: 0.04, DryLake: 0.3, IntermittentStream: 0.2, DryCrop: 0.2, Lava: 0.3, GolfCourse: 0.2, Rock: 0.3, Construction: 0.35, PackIce: 0.04, NaturalCrop: 0.2, Default: 0.2};
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
# a hash map of average vertical cloud model sizes
|
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
var cloud_vertical_size_map = {Altocumulus: 700.0, Cumulus: 600.0, Congestus: 2000.0, Nimbus: 1000.0, Stratus: 800.0, Stratus_structured: 600.0, Stratus_thin: 400.0, Cirrocumulus: 200.0, Cb_box: 2000.0};
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
# a hash map of offsets for the new cloud rendering system
|
|
|
|
|
|
|
|
var offset_map = {Nimbus: 2800.0, Stratus: 2000.0, Stratus_thin: 2500.0, Cirrostratus: 4500.0, Stratus_structured: 1800.0, Stratus_alt: 600.0, Cumulus: 200.0, Congestus: 600.0 };
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
# the array of aloft wind interpolation altitudes
|
|
|
|
|
|
|
|
var wind_altitude_array = [0.0, 5000.0, 10000.0, 18000.0, 24000.0, 30000.0, 34000.0, 39000.0, 45000.0];
|
2010-06-04 21:05:32 +00:00
|
|
|
|
|
|
|
# storage arrays for cloud generation
|
|
|
|
|
2010-06-15 18:54:44 +00:00
|
|
|
var clouds_path = [];
|
|
|
|
var clouds_lat = [];
|
|
|
|
var clouds_lon = [];
|
|
|
|
var clouds_alt = [];
|
|
|
|
var clouds_orientation = [];
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# storage array for assembled clouds
|
|
|
|
|
|
|
|
var cloudAssemblyArray = [];
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
# additional info needed for dynamical clouds: the base altitude around which cloudlets are distributed
|
|
|
|
# and the fractional lifetime
|
|
|
|
|
|
|
|
var clouds_mean_alt = [];
|
|
|
|
var clouds_flt = [];
|
|
|
|
var clouds_evolution_timestamp = [];
|
2010-08-03 06:18:14 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
# storage arrays for terrain presampling and results by tile
|
2010-06-15 18:54:44 +00:00
|
|
|
|
|
|
|
var terrain_n = [];
|
2010-08-03 06:18:14 +00:00
|
|
|
var alt_50_array = [];
|
2010-09-10 06:52:21 +00:00
|
|
|
var alt_20_array = [];
|
2011-09-23 21:22:19 +00:00
|
|
|
var alt_min_array = [];
|
|
|
|
var alt_mean_array = [];
|
2010-08-03 06:18:14 +00:00
|
|
|
|
|
|
|
# array of currently existing effect volumes
|
|
|
|
|
|
|
|
var effectVolumeArray = [];
|
|
|
|
var n_effectVolumeArray = 0;
|
|
|
|
|
2012-06-11 08:47:00 +00:00
|
|
|
# global weather hashes
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
var thermal = {};
|
|
|
|
var wave = {};
|
2012-06-11 08:47:00 +00:00
|
|
|
var interpolated_conditions = {};
|
|
|
|
var current_conditions = {};
|
2012-11-20 13:11:21 +00:00
|
|
|
var tracerAssembly = {};
|
2012-06-11 08:47:00 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
# the wind hash stores the current winds
|
|
|
|
|
|
|
|
var wind = {surface: [0.0,0.0] , cloudlayer: [0.0,0.0], current: [0.0,0.0]};
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2011-09-23 21:22:19 +00:00
|
|
|
|
|
|
|
|
2011-06-13 19:57:21 +00:00
|
|
|
# arrays of currently existing weather stations, wind interpolation and atmospheric condition points
|
2010-10-26 19:40:33 +00:00
|
|
|
|
|
|
|
var weatherStationArray = [];
|
2011-03-19 13:03:28 +00:00
|
|
|
var windIpointArray = [];
|
2011-06-13 19:57:21 +00:00
|
|
|
var atmosphereIpointArray = [];
|
2011-03-19 13:03:28 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
# a flag for the wind model (so we don't have to do string comparisons all the time)
|
|
|
|
# 1: constant 2: constant in tile 3: aloft interpolated 4: airmass interpolated
|
|
|
|
|
|
|
|
var wind_model_flag = 1;
|
|
|
|
|
2011-05-14 13:15:20 +00:00
|
|
|
# globals governing properties of the Cumulus system
|
2010-09-10 06:52:21 +00:00
|
|
|
|
|
|
|
var convective_texture_mix = 0.0;
|
2012-06-11 08:47:00 +00:00
|
|
|
var height_bias = 1.0;
|
2011-07-03 21:39:01 +00:00
|
|
|
var convective_size_bias = 0.0;
|
2011-05-14 13:15:20 +00:00
|
|
|
var cumulus_efficiency_factor = 1.0;
|
2010-10-26 19:40:33 +00:00
|
|
|
var cloud_mean_altitude = 0.0;
|
2012-06-11 08:47:00 +00:00
|
|
|
var thermal_conditions = getprop(lw~"config/thermal-properties");
|
|
|
|
var lowest_layer_turbulence = 0.6 - thermal_conditions;
|
|
|
|
if (lowest_layer_turbulence < 0.0) {lowest_layer_turbulence = 0.0;}
|
2010-10-26 19:40:33 +00:00
|
|
|
|
2012-04-26 10:03:51 +00:00
|
|
|
# global keeping track of lighting
|
|
|
|
|
|
|
|
var top_shade = 1.0;
|
|
|
|
|
2014-11-16 10:28:09 +00:00
|
|
|
# global cloud transparency
|
|
|
|
|
|
|
|
var alpha_factor = 1.0;
|
|
|
|
|
2013-04-09 06:41:27 +00:00
|
|
|
# global cloud size scale;
|
|
|
|
|
|
|
|
var cloud_size_scale = 1.0;
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
# globals keeping track of the lifetime when building a Cumulus from individual cloudlets
|
|
|
|
|
|
|
|
var cloud_fractional_lifetime = 0.0;
|
|
|
|
var cloud_evolution_timestamp = 0.0;
|
|
|
|
|
2011-03-19 13:03:28 +00:00
|
|
|
# globals propagating gust information inside the interpolation loop
|
|
|
|
|
|
|
|
var windspeed_multiplier = 1.0;
|
|
|
|
var winddir_change = 0.0;
|
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
# global flags mirroring property tree menu settings
|
|
|
|
|
|
|
|
var generate_thermal_lift_flag = 0;
|
|
|
|
var thread_flag = 1;
|
|
|
|
var dynamics_flag = 1;
|
|
|
|
var presampling_flag = 1;
|
|
|
|
var detailed_clouds_flag = 1;
|
|
|
|
var dynamical_convection_flag = 1;
|
|
|
|
var debug_output_flag = 1;
|
2011-01-05 12:36:10 +00:00
|
|
|
var metar_flag = 0;
|
2011-03-19 13:03:28 +00:00
|
|
|
var local_weather_running_flag = 0;
|
2011-06-13 19:57:21 +00:00
|
|
|
var local_weather_startup_flag = 0;
|
|
|
|
var fps_control_flag = 0;
|
2011-09-23 21:22:19 +00:00
|
|
|
var buffer_flag = 1;
|
|
|
|
var detailed_terrain_interaction_flag = 1;
|
2011-09-23 21:25:15 +00:00
|
|
|
var hardcoded_clouds_flag = 1;
|
2011-09-23 21:22:19 +00:00
|
|
|
var realistic_visibility_flag = 0;
|
2011-09-23 21:25:15 +00:00
|
|
|
var scattering_shader_flag = 0;
|
2012-03-08 22:20:39 +00:00
|
|
|
var wxradar_support_flag = 1;
|
2011-05-14 13:15:20 +00:00
|
|
|
|
2012-01-03 19:21:34 +00:00
|
|
|
var ground_haze_factor = 1.0;
|
2014-01-30 09:08:35 +00:00
|
|
|
var max_vis_range = math.exp(getprop(lw~"config/aux-max-vis-range-m"));
|
2012-01-03 19:21:34 +00:00
|
|
|
var temperature_offset = 0.0;
|
2012-03-08 22:20:39 +00:00
|
|
|
var current_mean_alt = 0.0;
|
2012-04-26 10:03:51 +00:00
|
|
|
var air_pollution_norm = 0.0;
|
2012-01-03 19:21:34 +00:00
|
|
|
|
2011-05-14 13:15:20 +00:00
|
|
|
# globals for framerate controlled cloud management
|
|
|
|
|
|
|
|
var fps_average = 0.0;
|
|
|
|
var fps_samples = 0;
|
|
|
|
var fps_sum = 0.0;
|
|
|
|
var target_framerate = 25.0;
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
# set all sorts of default properties for the menu
|
|
|
|
|
2011-07-03 21:39:01 +00:00
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
setprop(lw~"tmp/scloud-lat",getprop("position/latitude-deg"));
|
|
|
|
setprop(lw~"tmp/scloud-lon",getprop("position/longitude-deg"));
|
2010-06-15 18:54:44 +00:00
|
|
|
setprop(lw~"tmp/tile-alt-median-ft",0.0);
|
|
|
|
setprop(lw~"tmp/tile-alt-min-ft",0.0);
|
2010-06-04 21:05:32 +00:00
|
|
|
setprop(lw~"tmp/last-reading-pos-del",0);
|
|
|
|
setprop(lw~"tmp/last-reading-pos-mod",0);
|
|
|
|
setprop(lw~"tmp/thread-status", "idle");
|
|
|
|
setprop(lw~"tmp/convective-status", "idle");
|
2010-06-15 18:54:44 +00:00
|
|
|
setprop(lw~"tmp/presampling-status", "idle");
|
2010-09-10 06:52:21 +00:00
|
|
|
setprop(lw~"tmp/buffer-status", "idle");
|
|
|
|
setprop(lw~"tmp/buffer-tile-index", 0);
|
2010-08-03 06:18:14 +00:00
|
|
|
setprop(lw~"tmp/ipoint-latitude-deg",getprop("position/latitude-deg"));
|
|
|
|
setprop(lw~"tmp/ipoint-longitude-deg",getprop("position/longitude-deg"));
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
# set the default loop flags to loops inactive
|
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
setprop(lw~"effect-loop-flag",0);
|
|
|
|
setprop(lw~"interpolation-loop-flag",0);
|
2010-06-04 21:05:32 +00:00
|
|
|
setprop(lw~"tile-loop-flag",0);
|
|
|
|
setprop(lw~"lift-loop-flag",0);
|
2010-10-26 19:40:33 +00:00
|
|
|
setprop(lw~"wave-loop-flag",0);
|
2010-09-10 06:52:21 +00:00
|
|
|
setprop(lw~"buffer-loop-flag",0);
|
|
|
|
setprop(lw~"housekeeping-loop-flag",0);
|
2010-10-26 19:40:33 +00:00
|
|
|
setprop(lw~"convective-loop-flag",0);
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
# create other management properties
|
2010-04-12 20:51:46 +00:00
|
|
|
|
2010-10-26 19:40:33 +00:00
|
|
|
#setprop(lw~"clouds/cloud-number",0);
|
2010-06-04 21:05:32 +00:00
|
|
|
setprop(lw~"clouds/placement-index",0);
|
|
|
|
setprop(lw~"clouds/model-placement-index",0);
|
|
|
|
setprop(lw~"effect-volumes/effect-placement-index",0);
|
2010-04-12 20:51:46 +00:00
|
|
|
|
|
|
|
# create properties for effect volume management
|
|
|
|
|
|
|
|
setprop(lw~"effect-volumes/number",0);
|
|
|
|
setprop(lw~"effect-volumes/number-active-vis",0);
|
|
|
|
setprop(lw~"effect-volumes/number-active-rain",0);
|
|
|
|
setprop(lw~"effect-volumes/number-active-snow",0);
|
|
|
|
setprop(lw~"effect-volumes/number-active-turb",0);
|
|
|
|
setprop(lw~"effect-volumes/number-active-lift",0);
|
2010-10-26 19:40:33 +00:00
|
|
|
setprop(lw~"effect-volumes/number-active-sat",0);
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2012-01-05 08:47:26 +00:00
|
|
|
# setprop(lw~"config/max-vis-range-m", 120000.0);
|
2012-01-03 19:21:34 +00:00
|
|
|
setprop(lw~"config/temperature-offset-degc", 0.0);
|
2010-06-15 18:54:44 +00:00
|
|
|
|
2013-04-09 06:41:27 +00:00
|
|
|
setprop("/sim/rendering/eye-altitude-m", getprop("/position/altitude-ft") * ft_to_m);
|
2012-03-08 22:20:39 +00:00
|
|
|
|
2010-06-04 21:05:32 +00:00
|
|
|
# create properties for tile management
|
|
|
|
|
|
|
|
setprop(lw~"tiles/tile-counter",0);
|
|
|
|
|
2010-08-03 06:18:14 +00:00
|
|
|
# create properties for wind
|
|
|
|
|
|
|
|
setprop(lwi~"ipoint-number",0);
|
|
|
|
|
2011-06-13 20:27:44 +00:00
|
|
|
var updateMenu = func {
|
|
|
|
var isEnabled = getprop("/nasal/local_weather/enabled");
|
|
|
|
gui.menuEnable("local_weather", isEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
_setlistener("/nasal/local_weather/enabled", updateMenu);
|
2010-06-04 21:05:32 +00:00
|
|
|
|
2010-04-12 20:51:46 +00:00
|
|
|
|