| 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/RP-3-60", 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 (name, " mat_name ", mat_name); |
| 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 |
|
| 27 |
var distance = geo.aircraft_position().distance_to(impact) / 1000; |
| 28 |
screen.log.write(sprintf("RP-3-60 impact: %.3f km", distance, 1, 0.9, 0.9)); |
| 29 |
|
| 30 |
if (!solid){ |
| 31 |
var spray = geo.put_model("Models/Geometry/Crater/spray-effect.xml", impact, |
| 32 |
node.getNode("impact/heading-deg").getValue(), |
| 33 |
0, |
| 34 |
0); |
| 35 |
|
| 36 |
settimer(func {spray.remove()}, 3); |
| 37 |
|
| 38 |
settimer(func { |
| 39 |
|
| 40 |
var splash = geo.put_model("Models/Geometry/Crater/splash-effect.xml", |
| 41 |
node.getNode("impact/latitude-deg").getValue(), |
| 42 |
node.getNode("impact/longitude-deg").getValue(), |
| 43 |
node.getNode("impact/elevation-m").getValue()+ 0.25, |
| 44 |
node.getNode("impact/heading-deg").getValue(), |
| 45 |
0, |
| 46 |
0); |
| 47 |
|
| 48 |
settimer(func {splash.remove()}, 8); |
| 49 |
}, 2); |
| 50 |
|
| 51 |
} else { |
| 52 |
|
| 53 |
var time = props.globals.getNode("sim/time/elapsed-sec", 1).getValue(); |
| 54 |
var duration = 300; |
| 55 |
|
| 56 |
var explosion = geo.put_model("Models/Geometry/Crater/explosion.xml", impact, |
| 57 |
node.getNode("impact/heading-deg").getValue(), |
| 58 |
0, |
| 59 |
0); |
| 60 |
|
| 61 |
explosion.getNode("start-time",1).setDoubleValue(time); |
| 62 |
explosion.getNode("duration-sec",1).setDoubleValue(duration); |
| 63 |
settimer(func {explosion.remove()}, 5); |
| 64 |
settimer(func { |
| 65 |
var model = geo.put_model("Models/Geometry/RP-3/crater.xml", impact, |
| 66 |
node.getNode("impact/heading-deg").getValue(), |
| 67 |
0, |
| 68 |
0); |
| 69 |
|
| 70 |
var smoke = geo.put_model("Models/Geometry/Crater/crater-smoke.xml", impact, |
| 71 |
node.getNode("impact/heading-deg").getValue(), |
| 72 |
0, |
| 73 |
0); |
| 74 |
|
| 75 |
smoke.getNode("start-time",1).setDoubleValue(time); |
| 76 |
smoke.getNode("duration-sec",1).setDoubleValue(duration); |
| 77 |
settimer(func {smoke.remove()}, duration); |
| 78 |
}, 2); |
| 79 |
|
| 80 |
vol = 0.3/math.sqrt(distance) ; |
| 81 |
|
| 82 |
fgcommand("play-audio-sample", props.Node.new({ |
| 83 |
path : getprop("/sim/fg-root") ~ "/Models/Geometry/RP-3", |
| 84 |
file : "explosion.wav", |
| 85 |
volume : vol, |
| 86 |
|
| 87 |
})); # end fgcommand |
| 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 |