| 1 |
<?xml version="1.0"?> |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
<PropertyList> |
| 10 |
<load><![CDATA[ |
| 11 |
var self = cmdarg(); |
| 12 |
printlog("info", "loading ballon at ", self.getPath() ); |
| 13 |
|
| 14 |
self.getNode("controls/flight/lateral-mode",1).setValue("yaw"); |
| 15 |
var windh = props.globals.getNode("environment/wind-from-heading-deg",1); |
| 16 |
var winds = props.globals.getNode("environment/wind-speed-kt",1); |
| 17 |
var speed = self.getNode("controls/flight/target-spd",1); |
| 18 |
var head = self.getNode("controls/flight/target-hdg",1); |
| 19 |
var running = self.getNode("engines/engine[0]/running",1); |
| 20 |
var flame_on_time = 10.0 + 10.0*rand(); |
| 21 |
var flame_off_time = 30.0 + 10.0*rand(); |
| 22 |
var position = nil; |
| 23 |
|
| 24 |
# this init sequence needs to be done on init (duh?) and after the fdm |
| 25 |
# has been initialized _and_ after the listener on fdm-initialized in |
| 26 |
# Nasal/balloons.nas has finished his job. See note below. |
| 27 |
var init = func { |
| 28 |
printlog("debug", self.getPath(), " initializing" ); |
| 29 |
running.setBoolValue(0); # start with engine (flame) off |
| 30 |
position = geo.aircraft_position(); |
| 31 |
position.apply_course_distance( |
| 32 |
props.globals.getNode("orientation/heading-deg", 1).getValue()-10.0+20*rand(), |
| 33 |
800 + 400*rand()); |
| 34 |
var elevation = geo.elevation( position.lat(), position.lon() ) * globals.M2FT; |
| 35 |
position.set_alt( elevation != nil ? elevation : 0.0 ); |
| 36 |
self.getNode("controls/flight/target-alt", 1 ).setValue( position.alt() ); |
| 37 |
|
| 38 |
self.getNode("position/latitude-deg",1).setDoubleValue( position.lat() ); |
| 39 |
self.getNode("position/longitude-deg",1).setDoubleValue( position.lon() ); |
| 40 |
self.getNode("position/altitude-ft", 1 ).setValue( position.alt() ); |
| 41 |
} |
| 42 |
|
| 43 |
init(); |
| 44 |
|
| 45 |
var initListener = setlistener( "/sim/signals/reinit", func(n) { |
| 46 |
var b = n.getValue(); |
| 47 |
if( b == nil or b == 0 ) return; |
| 48 |
# hide balloon deep under the surface after reset |
| 49 |
self.getNode("position/altitude-ft", 1 ).setValue( -9999.0 ); |
| 50 |
}); |
| 51 |
|
| 52 |
# note: there is a listener on fdm-initialized Nasal/balloons.nas which shall |
| 53 |
# allways be triggered before us. This should be guaranteed by being registered |
| 54 |
# before this balloon loads. |
| 55 |
var fdmInitListener = setlistener( "/sim/signals/fdm-initialized", init ); |
| 56 |
|
| 57 |
var loopid = 0; |
| 58 |
|
| 59 |
var flameLoop = func(id) { |
| 60 |
id == loopid or return; |
| 61 |
var b = running.getValue(); |
| 62 |
running.setBoolValue( b == 0 ); |
| 63 |
if( b == 0 ) { |
| 64 |
#if the flame is on, set target altitude |
| 65 |
position.set_lat( self.getNode("position/latitude-deg",1).getValue() ); |
| 66 |
position.set_lon( self.getNode("position/longitude-deg",1).getValue() ); |
| 67 |
var elevation = geo.elevation( position.lat(), position.lon() ) * globals.M2FT; |
| 68 |
position.set_alt( elevation != nil ? elevation : 0.0 ); |
| 69 |
self.getNode("controls/flight/target-alt", 1 ).setValue( position.alt() + 1500 + 1000*rand()); |
| 70 |
} |
| 71 |
settimer( func { flameLoop(id) }, b ? flame_off_time : flame_on_time ); |
| 72 |
} |
| 73 |
|
| 74 |
var loop = func(id) { |
| 75 |
id == loopid or return; |
| 76 |
speed.setValue(winds.getValue()); |
| 77 |
head.setValue(geo.normdeg(windh.getValue() + 180.0)); |
| 78 |
settimer(func { loop(id) }, 10.0 ); |
| 79 |
} |
| 80 |
|
| 81 |
settimer( func { |
| 82 |
flameLoop(loopid); |
| 83 |
settimer(func { loop(loopid) }, 0.5); |
| 84 |
}, 5.0 + 20.0*rand() ); |
| 85 |
]]></load> |
| 86 |
<unload><![CDATA[ |
| 87 |
printlog("info", "unloading balloon"); |
| 88 |
loopid += 1; |
| 89 |
removelistener( initListener ); |
| 90 |
removelistener( fdmInitListener ); |
| 91 |
]]></unload> |
| 92 |
</PropertyList> |