| 1 |
##################################################################################### |
| 2 |
# This script activates and controls the crater model and effects # |
| 3 |
# # |
| 4 |
# Author Vivian Meazza May 2011 # |
| 5 |
##################################################################################### |
| 6 |
|
| 7 |
|
| 8 |
var crater_init = func() { |
| 9 |
|
| 10 |
# =============================== Listeners =============================== |
| 11 |
# |
| 12 |
|
| 13 |
setlistener("/sim/armament/weapons/bomb", func(n) { |
| 14 |
var node = props.globals.getNode(n.getValue(), 1); |
| 15 |
var solid = node.getNode("material/solid").getValue(); |
| 16 |
var mat_name = node.getNode("material/name").getValue(); |
| 17 |
var name = node.getNode("name").getValue(); |
| 18 |
|
| 19 |
print ("mat_name ", mat_name, " ", solid); |
| 20 |
|
| 21 |
var impact = geo.Coord.new().set_latlon( |
| 22 |
node.getNode("impact/latitude-deg").getValue(), |
| 23 |
node.getNode("impact/longitude-deg").getValue(), |
| 24 |
node.getNode("impact/elevation-m").getValue()); |
| 25 |
|
| 26 |
if (solid){ |
| 27 |
var time = props.globals.getNode("sim/time/elapsed-sec", 1).getValue(); |
| 28 |
var duration = 300; |
| 29 |
|
| 30 |
var explosion = geo.put_model("Models/Geometry/Crater/explosion.xml", impact, |
| 31 |
node.getNode("impact/heading-deg").getValue(), |
| 32 |
0, |
| 33 |
0); |
| 34 |
|
| 35 |
explosion.getNode("start-time",1).setDoubleValue(time); |
| 36 |
explosion.getNode("duration-sec",1).setDoubleValue(duration); |
| 37 |
settimer(func {explosion.remove()}, 5); |
| 38 |
|
| 39 |
settimer(func { |
| 40 |
var model = geo.put_model("Models/Geometry/Crater/crater.xml", impact, |
| 41 |
node.getNode("impact/heading-deg").getValue(), |
| 42 |
0, |
| 43 |
0); |
| 44 |
|
| 45 |
var smoke = geo.put_model("Models/Geometry/Crater/crater-smoke.xml", impact, |
| 46 |
node.getNode("impact/heading-deg").getValue(), |
| 47 |
0, |
| 48 |
0); |
| 49 |
|
| 50 |
smoke.getNode("start-time",1).setDoubleValue(time); |
| 51 |
smoke.getNode("duration-sec",1).setDoubleValue(duration); |
| 52 |
settimer(func {smoke.remove()}, duration); |
| 53 |
}, 2); |
| 54 |
|
| 55 |
var distance = geo.aircraft_position().distance_to(impact) / 1000; |
| 56 |
screen.log.write(sprintf("bomb impact: %.3f km", distance, 1, 0.9, 0.9)); |
| 57 |
|
| 58 |
vol = 0.3/math.sqrt(distance) ; |
| 59 |
|
| 60 |
fgcommand("play-audio-sample", props.Node.new( |
| 61 |
{ |
| 62 |
path : getprop("/sim/fg-root") ~ "/Models/Geometry/Crater", |
| 63 |
file : "explosion.wav", |
| 64 |
volume : vol,} |
| 65 |
)); # end fgcommand |
| 66 |
|
| 67 |
} else { |
| 68 |
|
| 69 |
var spray = geo.put_model("Models/Geometry/Crater/spray-effect.xml", impact, |
| 70 |
node.getNode("impact/heading-deg").getValue(), |
| 71 |
0, |
| 72 |
0); |
| 73 |
|
| 74 |
settimer(func {spray.remove()}, 3); |
| 75 |
|
| 76 |
settimer(func { |
| 77 |
|
| 78 |
var splash = geo.put_model("Models/Geometry/Crater/splash-effect.xml", |
| 79 |
node.getNode("impact/latitude-deg").getValue(), |
| 80 |
node.getNode("impact/longitude-deg").getValue(), |
| 81 |
node.getNode("impact/elevation-m").getValue()+ 0.25, |
| 82 |
node.getNode("impact/heading-deg").getValue(), |
| 83 |
0, |
| 84 |
0); |
| 85 |
|
| 86 |
settimer(func {splash.remove()}, 8); |
| 87 |
}, 2); |
| 88 |
|
| 89 |
}# endif |
| 90 |
|
| 91 |
|
| 92 |
}); # end func |
| 93 |
|
| 94 |
} # end listener |
| 95 |
|
| 96 |
# Fire it up |
| 97 |
|
| 98 |
setlistener("sim/signals/fdm-initialized", crater_init); |
| 99 |
|
| 100 |
# end |