2,733
edits
(Updated to work with 3.5+ failure system, its quite stable, have used it in the JA37 for almost a year now.) |
Red Leader (talk | contribs) m (Correct some minor things, mainly indentation) |
||
Line 1: | Line 1: | ||
Inspired by the crash system in the [[ | Inspired by the crash system in the [[MiG-15]] by Slavutinsky Victor, this system is meant to become generic and usable for all aircraft by adding just a few lines. For now you have to add a file with code though. | ||
== Features so far== | == Features so far == | ||
* Impact, crash and explosion detection. | * Impact, crash and explosion detection. | ||
* Tied into the new 3.5+ failure manager. | * Tied into the new 3.5+ failure manager. | ||
Line 7: | Line 7: | ||
* Sounds. | * Sounds. | ||
== Planned features== | == Planned features == | ||
Feel free to suggest some in the forum topic linked to at the end of this article. | Feel free to suggest some in the forum topic linked to at the end of this article. | ||
== How to install the current system on an aircraft == | == How to install the current system on an aircraft == | ||
Copy this code into your | Copy this code into your aircraft's Nasal folder as <code>crash-and-stress.nas</code> file: | ||
<syntaxhighlight lang="nasal"> | <syntaxhighlight lang="nasal"> | ||
# | # | ||
Line 289: | Line 289: | ||
var lon = me.input.lon.getValue(); | var lon = me.input.lon.getValue(); | ||
var info = geodinfo(lat, lon); | var info = geodinfo(lat, lon); | ||
var solid = info == nil?TRUE:(info[1] == nil?TRUE:info[1].solid); | var solid = info == nil ? TRUE : (info[1] == nil ? TRUE : info[1].solid); | ||
var speed = me._calcGroundSpeed(); | var speed = me._calcGroundSpeed(); | ||
Line 295: | Line 295: | ||
var failure_modes = FailureMgr._failmgr.failure_modes; | var failure_modes = FailureMgr._failmgr.failure_modes; | ||
var mode_list = keys(failure_modes); | var mode_list = keys(failure_modes); | ||
var probability = speed / 200.0;# 200kt will fail everything, 0kt will fail nothing. | var probability = speed / 200.0; # 200kt will fail everything, 0kt will fail nothing. | ||
var hitStr = "something"; | var hitStr = "something"; | ||
if(info != nil and info[1] != nil) { | if(info != nil and info[1] != nil) { | ||
hitStr = info[1].names == nil?"something":info[1].names[0]; | hitStr = info[1].names == nil ? "something" : info[1].names[0]; | ||
foreach(infoStr; info[1].names) { | foreach(infoStr; info[1].names) { | ||
if(find('_', infoStr) == -1) { | if(find('_', infoStr) == -1) { | ||
Line 310: | Line 310: | ||
if(probability > 1.0 and me.fdm.input.fuel.getValue() > 2500) { | if(probability > 1.0 and me.fdm.input.fuel.getValue() > 2500) { | ||
# 200kt+ and fuel in tanks will explode the aircraft on impact. | # 200kt+ and fuel in tanks will explode the aircraft on impact. | ||
me.input.simCrashed.setBoolValue(TRUE); | |||
me._explodeBegin("Aircraft hit " ~ hitStr ~ "."); | |||
return; | return; | ||
} | } | ||
Line 321: | Line 321: | ||
} | } | ||
var str = "Aircraft hit "~hitStr~"."; | var str = "Aircraft hit " ~ hitStr ~ "."; | ||
me._output(str); | me._output(str); | ||
} elsif (solid == TRUE) { | } elsif (solid == TRUE) { | ||
Line 372: | Line 372: | ||
}, | }, | ||
_stressDamage: func (str) { | _stressDamage: func (str) { | ||
me._output("Aircraft damaged: Wings broke off, due to "~str~" G forces."); | me._output("Aircraft damaged: Wings broke off, due to " ~ str ~ " G forces."); | ||
me.input.detachOn.setBoolValue(TRUE); | me.input.detachOn.setBoolValue(TRUE); | ||
Line 401: | Line 401: | ||
var lon = me.input.lon.getValue(); | var lon = me.input.lon.getValue(); | ||
var info = geodinfo(lat, lon); | var info = geodinfo(lat, lon); | ||
var solid = info==nil?TRUE:(info[1] == nil?TRUE:info[1].solid); | var solid = info == nil ? TRUE : (info[1] == nil ? TRUE : info[1].solid); | ||
if(solid == FALSE) { | if(solid == FALSE) { | ||
me._impactDamage(); | me._impactDamage(); | ||
Line 409: | Line 409: | ||
_testStress: func () { | _testStress: func () { | ||
if (me._isRunning() == TRUE and me.wingsAttached == TRUE) { | if (me._isRunning() == TRUE and me.wingsAttached == TRUE) { | ||
var gForce = me.fdm.input.Nz.getValue() == nil?1:me.fdm.input.Nz.getValue(); | var gForce = me.fdm.input.Nz.getValue() == nil ? 1 : me.fdm.input.Nz.getValue(); | ||
var weight = me.fdm.input.weight.getValue(); | var weight = me.fdm.input.weight.getValue(); | ||
var wingload = gForce * weight; | var wingload = gForce * weight; | ||
Line 499: | Line 499: | ||
parents: [fdmProperties], | parents: [fdmProperties], | ||
input: { | input: { | ||
weight: "fdm/jsbsim/inertia/weight-lbs", | |||
fuel: "fdm/jsbsim/propulsion/total-fuel-lbs", | |||
simTime: "fdm/jsbsim/simulation/sim-time-sec", | |||
vgFps: "fdm/jsbsim/velocities/vg-fps", | |||
downFps: "velocities/down-relground-fps", | |||
Nz: "fdm/jsbsim/accelerations/Nz", | |||
}, | }, | ||
wingsFailureID: "fdm/jsbsim/structural/wings", | wingsFailureID: "fdm/jsbsim/structural/wings", | ||
Line 512: | Line 512: | ||
parents: [fdmProperties], | parents: [fdmProperties], | ||
input: { | input: { | ||
weight: "yasim/gross-weight-lbs", | |||
fuel: "consumables/fuel/total-fuel-lbs", | |||
simTime: "sim/time/elapsed-sec", | |||
vgFps: "velocities/groundspeed-kt", | |||
Nz: "accelerations/n-z-cg-fps_sec", | |||
}, | }, | ||
convert: func () { | convert: func () { | ||
Line 577: | Line 577: | ||
Notice that you should edit the line underneath '''# example use''' to fit your aircraft requirements. | Notice that you should edit the line underneath '''# example use''' to fit your aircraft requirements. | ||
In your -set.xml file under nasal tags add | In your [[aircraft-set.xml]] file under nasal tags add | ||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
Line 588: | Line 588: | ||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
<?xml version="1.0" encoding="UTF-8"?> | |||
<PropertyList> | |||
<fx> | |||
<!-- ... --> | |||
<aircraft-explode> | |||
<name>aircraft-explode</name> | |||
<path>Aircraft/JA37/Sounds/aircraft-explode.wav</path> | |||
<mode>once</mode> | |||
<condition> | |||
<equals> | |||
<property>damage/sounds/explode-on</property> | |||
<value>1</value> | |||
</equals> | |||
</condition> | |||
<position> | |||
<x>0.01</x> | |||
<y>0.01</y> | |||
<z>0.01</z> | |||
</position> | |||
<volume> | |||
<factor>3</factor> | |||
<max>3</max> | |||
</volume> | |||
</aircraft-explode> | |||
<aircraft-detach> | |||
<name>aircraft-detach</name> | |||
<path>Aircraft/JA37/Sounds/aircraft-wings-detach.wav</path> | |||
<mode>once</mode> | |||
<condition> | |||
<equals> | |||
<property>damage/sounds/detach-on</property> | |||
<value>1</value> | |||
</equals> | |||
</condition> | |||
<position> | |||
<x>0.01</x> | |||
<y>0.01</y> | |||
<z>0.01</z> | |||
</position> | |||
<volume> | |||
<factor>1</factor> | |||
</volume> | |||
</aircraft-detach> | |||
<aircraft-crash> | |||
<name>aircraft-impact</name> | |||
<path>Sounds/aircraft-crash.wav</path> | |||
<mode>once</mode> | |||
<condition> | |||
<equals> | |||
<property>damage/sounds/crash-on</property> | |||
<value>1</value> | |||
</equals> | |||
</condition> | |||
<position> | |||
<x>0.01</x> | |||
<y>0.01</y> | |||
<z>0.01</z> | |||
</position> | |||
<volume> | |||
<factor>1</factor> | |||
</volume> | |||
</aircraft-crash> | |||
<aircraft-water-crash> | |||
<name>aircraft-water-crash</name> | |||
<path>Aircraft/JA37/Sounds/aircraft-water-crash.wav</path> | |||
<mode>once</mode> | |||
<condition> | |||
<equals> | |||
<property>damage/sounds/water-crash-on</property> | |||
<value>1</value> | |||
</equals> | |||
</condition> | |||
<position> | |||
<x>0.01</x> | |||
<y>0.01</y> | |||
<z>0.01</z> | |||
</position> | |||
<volume> | |||
<factor>1</factor> | |||
</volume> | |||
</aircraft-water-crash> | |||
<aircraft-crack> | |||
<name>aircraft-crack</name> | |||
<path>Aircraft/JA37/Sounds/aircraft-crack.wav</path> | |||
<mode>once</mode> | |||
<condition> | |||
<property>sim/current-view/internal</property> | |||
<equals> | |||
<property>damage/sounds/crack-on</property> | |||
<value>1</value> | |||
</equals> | |||
</condition> | |||
<position> | |||
<x>0.01</x> | |||
<y>0.01</y> | |||
<z>0.01</z> | |||
</position> | |||
<volume> | |||
<property>damage/sounds/crack-volume</property> | |||
<factor>1</factor> | |||
</volume> | |||
</aircraft-crack> | |||
<aircraft-creaking> | |||
<name>aircraft-creaking</name> | |||
<path>Aircraft/JA37/Sounds/aircraft-creaking.wav</path> | |||
<mode>looped</mode> | |||
<condition> | |||
<property>sim/current-view/internal</property> | |||
<equals> | |||
<property>damage/sounds/creaking-on</property> | |||
<value>1</value> | |||
</equals> | |||
</condition> | |||
<position> | |||
<x>0.01</x> | |||
<y>0.01</y> | |||
<z>0.01</z> | |||
</position> | |||
<volume> | |||
<property>damage/sounds/creaking-volume</property> | |||
<factor>1</factor> | |||
</volume> | |||
</aircraft-creaking> | |||
<!-- ... --> | |||
</fx> | |||
</PropertyList> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 755: | Line 767: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Notice that the last signal is | Notice that the last signal is JSBSim specific, the corresponding YASim signal is: | ||
<syntaxhighlight lan="nasal"> | <syntaxhighlight lan="nasal"> |