123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- var splash_vec_loop = func(){
- var airspeed = getprop("/velocities/airspeed-kt");
- airspeed = airspeed + getprop("/engines/engine/rpm")*0.0191;
- var splash_x = -0.71 - 0.0071 * airspeed;
- var splash_y = 0.0;
- var splash_z = 0.71 + 0.0071 * airspeed;
- setprop("/environment/aircraft-effects/splash-vector-x", splash_x);
- setprop("/environment/aircraft-effects/splash-vector-y", splash_y);
- setprop("/environment/aircraft-effects/splash-vector-z", splash_z);
- settimer(func(){
- splash_vec_loop();
- }, 0.05);
- }
- settimer(func(){
- splash_vec_loop();
- }, 3);
- ##########################################
- # Click Sounds
- ##########################################
- var click = func (name, timeout=0.1, delay=0) {
- var sound_prop = "/sim/model/AvroVulcanB2/sound/click-" ~ name;
- settimer(func {
- # Play the sound
- setprop(sound_prop, 1);
- # Reset the property after 0.2 seconds so that the sound can be
- # played again.
- settimer(func {
- setprop(sound_prop, 0);
- }, timeout);
- }, delay);
- };
- ##########################################
- # Thunder Sound
- ##########################################
- var speed_of_sound = func (t, re) {
- # Compute speed of sound in m/s
- #
- # t = temperature in Celsius
- # re = amount of water vapor in the air
- # Compute virtual temperature using mixing ratio (amount of water vapor)
- # Ratio of gas constants of dry air and water vapor: 287.058 / 461.5 = 0.622
- var T = 273.15 + t;
- var v_T = T * (1 + re/0.622)/(1 + re);
- # Compute speed of sound using adiabatic index, gas constant of air,
- # and virtual temperature in Kelvin.
- return math.sqrt(1.4 * 287.058 * v_T);
- };
- var thunder = func (name) {
- var thunderCalls = 0;
- var lightning_pos_x = getprop("/environment/lightning/lightning-pos-x");
- var lightning_pos_y = getprop("/environment/lightning/lightning-pos-y");
- var lightning_distance = math.sqrt(math.pow(lightning_pos_x, 2) + math.pow(lightning_pos_y, 2));
- # On the ground, thunder can be heard up to 16 km. Increase this value
- # a bit because the aircraft is usually in the air.
- if (lightning_distance > 20000)
- return;
- var t = getprop("/environment/temperature-degc");
- var re = getprop("/environment/relative-humidity") / 100;
- var delay_seconds = lightning_distance / speed_of_sound(t, re);
- # Maximum volume at 5000 meter
- var lightning_distance_norm = std.min(1.0, 1 / math.pow(lightning_distance / 5000.0, 2));
- settimer(func {
- var thunder1 = getprop("/sim/model/AvroVulcanB2/sound/click-thunder1");
- var thunder2 = getprop("/sim/model/AvroVulcanB2/sound/click-thunder2");
- var thunder3 = getprop("/sim/model/AvroVulcanB2/sound/click-thunder3");
- if (!thunder1) {
- thunderCalls = 1;
- setprop("/sim/model/AvroVulcanB2/sound/lightning/dist1", lightning_distance_norm);
- }
- else if (!thunder2) {
- thunderCalls = 2;
- setprop("/sim/model/AvroVulcanB2/sound/lightning/dist2", lightning_distance_norm);
- }
- else if (!thunder3) {
- thunderCalls = 3;
- setprop("/sim/model/AvroVulcanB2/sound/lightning/dist3", lightning_distance_norm);
- }
- else
- return;
- # Play the sound (sound files are about 9 seconds)
- click("thunder" ~ thunderCalls, 9.0, 0);
- }, delay_seconds);
- };
- # Listening for lightning strikes
- setlistener("/environment/lightning/lightning-pos-y", thunder);
|