Crash and stress damage system: Difference between revisions

Jump to navigation Jump to search
m
Correct some minor things, mainly indentation
(Updated to work with 3.5+ failure system, its quite stable, have used it in the JA37 for almost a year now.)
m (Correct some minor things, mainly indentation)
Line 1: Line 1:
Inspired by the crash system in the [[Mikoyan-Gurevich_MiG-15|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.
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 aircrafts Nasal folder as crash-and-stress.nas file:
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.input.simCrashed.setBoolValue(TRUE);
    me._explodeBegin("Aircraft hit "~hitStr~".");
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",
weight:    "fdm/jsbsim/inertia/weight-lbs",
fuel:      "fdm/jsbsim/propulsion/total-fuel-lbs",
fuel:      "fdm/jsbsim/propulsion/total-fuel-lbs",
simTime:    "fdm/jsbsim/simulation/sim-time-sec",
simTime:    "fdm/jsbsim/simulation/sim-time-sec",
vgFps:      "fdm/jsbsim/velocities/vg-fps",
vgFps:      "fdm/jsbsim/velocities/vg-fps",
downFps:    "velocities/down-relground-fps",
downFps:    "velocities/down-relground-fps",
Nz:        "fdm/jsbsim/accelerations/Nz",
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",
weight:    "yasim/gross-weight-lbs",
fuel:      "consumables/fuel/total-fuel-lbs",
fuel:      "consumables/fuel/total-fuel-lbs",
simTime:    "sim/time/elapsed-sec",
simTime:    "sim/time/elapsed-sec",
vgFps:      "velocities/groundspeed-kt",
vgFps:      "velocities/groundspeed-kt",
Nz:        "accelerations/n-z-cg-fps_sec",
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">
  <aircraft-explode>
<?xml version="1.0" encoding="UTF-8"?>
  <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>
<PropertyList>
      <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>


       
<fx>


  <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>
  <aircraft-explode>
  <name>aircraft-water-crash</name>
    <name>aircraft-explode</name>
  <path>Aircraft/JA37/Sounds/aircraft-water-crash.wav</path>
    <path>Aircraft/JA37/Sounds/aircraft-explode.wav</path>
  <mode>once</mode>
    <mode>once</mode>
  <condition>
    <condition>
  <equals>
      <equals>
  <property>damage/sounds/water-crash-on</property>
        <property>damage/sounds/explode-on</property>
  <value>1</value>
        <value>1</value>
  </equals>
      </equals>
  </condition>
    </condition>
      <position>
    <position>
        <x>0.01</x>
      <x>0.01</x>
        <y>0.01</y>
      <y>0.01</y>
        <z>0.01</z>
      <z>0.01</z>
      </position>    
    </position>
  <volume>
    <volume>
  <factor>1</factor>
      <factor>3</factor>
  </volume>
      <max>3</max>
  </aircraft-water-crash>
    </volume>
  </aircraft-explode>


  <aircraft-crack>
  <aircraft-detach>
  <name>aircraft-crack</name>
    <name>aircraft-detach</name>
  <path>Aircraft/JA37/Sounds/aircraft-crack.wav</path>
    <path>Aircraft/JA37/Sounds/aircraft-wings-detach.wav</path>
  <mode>once</mode>
    <mode>once</mode>
  <condition>
    <condition>
  <property>sim/current-view/internal</property>
      <equals>
  <equals>
        <property>damage/sounds/detach-on</property>
  <property>damage/sounds/crack-on</property>
        <value>1</value>
  <value>1</value>
      </equals>
  </equals>
    </condition>
  </condition>
    <position>
      <position>
      <x>0.01</x>
        <x>0.01</x>
      <y>0.01</y>
        <y>0.01</y>
      <z>0.01</z>
        <z>0.01</z>
    </position>       
      </position>       
    <volume>
  <volume>
      <factor>1</factor>
  <property>damage/sounds/crack-volume</property>
    </volume>
  <factor>1</factor>
  </aircraft-detach>
  </volume>
  </aircraft-crack>


  <aircraft-creaking>
  <aircraft-crash>
  <name>aircraft-creaking</name>
    <name>aircraft-impact</name>
  <path>Aircraft/JA37/Sounds/aircraft-creaking.wav</path>
    <path>Sounds/aircraft-crash.wav</path>
  <mode>looped</mode>
    <mode>once</mode>
  <condition>
    <condition>
    <property>sim/current-view/internal</property>
      <equals>
  <equals>
        <property>damage/sounds/crash-on</property>
  <property>damage/sounds/creaking-on</property>
        <value>1</value>
  <value>1</value>
      </equals>
  </equals>
    </condition>
  </condition>
    <position>
      <position>
      <x>0.01</x>
        <x>0.01</x>
      <y>0.01</y>
        <y>0.01</y>
      <z>0.01</z>
        <z>0.01</z>
    </position>     
      </position>       
    <volume>
  <volume>
      <factor>1</factor>
  <property>damage/sounds/creaking-volume</property>
    </volume>
  <factor>1</factor>
  </aircraft-crash>
  </volume>
 
  </aircraft-creaking>
  <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 jsbsim specific, the corresponding yasim signal is:
Notice that the last signal is JSBSim specific, the corresponding YASim signal is:


<syntaxhighlight lan="nasal">
<syntaxhighlight lan="nasal">

Navigation menu