<?xml version="1.0" encoding="ISO-8859-1"?>

<PropertyList>

  <nasal>
    <load>
      <![CDATA[

      #makes the propellors spin in the AI version of the aircraft
      var nodeName = cmdarg().getPath();

      print("Loading Sukhoi Su 33 ", nodeName);

      ##checks whether it has been initialized already; if so, just return
      if ( bombable.check_overall_initialized (nodeName) ) {
        return;
      }

      ############################################
      #Bombable INITIALIZER
      var object_init = func() {

        # Datas of this object are under: cmdarg().getPath()
        var thisNodeName = cmdarg().getPath();
        var thisNode     = props.globals.getNode(thisNodeName);
        # Add some useful nodes

        ########################################################################
        ########################################################################
        # INITIALIZE BOMBABLE
        #
        # Initialize constants and main routines for maintaining altitude
        # relative to ground-level, relocating after file/reset, and
        # creating bombable/shootable objects.
        #
        # These routines are found in FG/nasal/bombable.nas
        #
        ########################################################################
        # INITIALIZE BOMBABLE Object
        # This object will be slurped in the object's node as a child
        # node named "bombable".
        # All distances are specified in meters.
        # All altitudes are relative to current ground level at the object's
        # location
        #

        thisNodeName = cmdarg().getPath();

        var bombableObject = {

          objectNodeName : thisNodeName,
          objectNode     : props.globals.getNode(thisNodeName),

          # time, in seconds, between the updates that
          # keep the object at its AGL. Tradeoff is high-speed updates look more
          # realistic but slow down the framerate/cause jerkiness.  Faster-moving
          # objects will need more frequent updates to look realistic.
          # update time faster than about 1/3 seems to have a noticeable effect
          # on frame rate
          updateTime_s   : 1/3,

          #########################################
          # ALTITUDE DEFINITIONS
          #
          altitudes : {
            # altitude correction to add to your aircraft or ship that is needed to put wheels on
            # ground (or, for a ship, make it float in the water at the correct level).  For most
            # objects this is 0 but some models need a small correction to place them exactly at
            # ground level
            wheelsOnGroundAGL_m : 1 ,

            # minimum altitude above ground level this object is allowed to fly
            minimumAGL_m        : 100,

            # maximum altitude AGL this object is allowed to fly, ie, operational ceiling
            maximumAGL_m        : 13715,

            # altitude AGL when crashed.  Ships will sink to this level, aircraft or vehicles will
            # sink into the ground as landing gear collapses or tires deflate. Should be negative,
            # even just -0.001.
            crashedAGL_m        : 0.6,
          },
          #
          #########################################
          # VELOCITIES DEFINITIONS
          #
          velocities : {
            # max % to reduce speed, per step, when damaged
            maxSpeedReduce_percent                       : 0.5,

            # minimum speed to reduce to when damaged.  Ground vehicles and ships might stop completely
            # when damaged but aircraft will need a minimum speed so they keep moving until they hit the
            # ground.
            minSpeed_kt                                  : 130,

            # cruising speed, typical/optimal cruising speed, V C for aircraft
            cruiseSpeed_kt                               : 1000,

            # typical/optimal speed when aggressively attacking or evading, in
            # level flight for aircraft
            attackSpeed_kt                               : 1100,

            # Maximum possible speed under dive or downhill conditions, V NE for aircraft
            maxSpeed_kt                                  : 1240,

            # max rate to sink or fly downwards when damaged, in meters/second
            damagedAltitudeChangeMaxRate_meterspersecond : 30,
          },
          #
          #########################################
          # EVASION DEFINITIONS
          #
          # The evasion system makes the AI aircraft dodge when they come under
          # fire.
          evasions : {
            # max time to delay/wait between dodges
            dodgeDelayMax_sec             : 200,

            # minimum time to delay/wait between dodges
            dodgeDelayMin_sec             : 100,

            # Max amount to turn when dodging
            dodgeMax_deg                  : 1,

            # minimum amount to turn when dodging
            dodgeMin_deg                  : 1,

            # you can figure this out by rolling the corresponding FG aircraft and
            # timing a 180 or 360 deg roll
            rollRateMax_degpersec         : 20,

            # Preference for right turns vs. left when dodging.  90% means 90% right
            # turns, 50% means 50% right turns.
            dodgeROverLPreference_percent : 50,

            # Aircraft will begin to move up or down
            dodgeAltMin_m                 : -20,

            # Max & Min are relative to current alt
            dodgeAltMax_m                 : 20,
          },
          #
          #########################################
          # ATTACK DEFINITIONS
          #
          # The attack system makes the AI aircraft turn and fly towards
          # other aircraft
          # The B17 won't actually turn and attack but it has a rear-ward facing gun that will shoot
          attacks : {
            # max distance to turn & attack main aircraft
            maxDistance_m            : 700,

            # min distance to turn & attack main aircraft, ie, fly away this far before turning
            # to attack again
            minDistance_m             : 1,

            #when within minDistance_m, the aircraft will continue to turn towards the main aircraft
            # and attack *if* if the angle is less than this amount from dead ahead
            continueAttackAngle_deg   : 20,

            # will attack the main aircraft unless this amount higher than it or more
            altitudeHigherCutoff_m    : 700,

            # will attack the main aircraft unless this amount lower than it or more
            altitudeLowerCutoff_m     : 700,

            # when turning on attack, roll to this angle min
            rollMin_deg               : 0,

            # when turning on attack, roll to this angle max
            rollMax_deg               : 0,

            # you can figure this out by rolling the corresponding FG aircraft and
            # timing a 180 or 360 deg roll
            rollRateMax_degpersec     : 20,

            # How powerful the aircraft is when climbing during an attack; 4000 would
            # be typical for, say a Zero--scale accordingly for others; higher is stronger
            climbPower                 : 0,

            # How powerful the aircraft is when diving during and attack; 6000 typical of
            # a Zero--could be much more than climbPower if the aircraft is a weak climber but a strong diver
            divePower                  : 0,

            # check for need to attack/correct course this often
            attackCheckTime_sec        : 10,

            # once engaged with enemy, check/update course this frequently
            attackCheckTimeEngaged_sec : 1,

            # maximum percentage damage one hit from the aircraft's main weapon/machine guns will do to an opponent
            maxDamage_percent          : 7,

            # maximum distance at which the aircrafts main weapon/maching guns will be able to damage an opponent
            maxDamageDistance_m        : 700,

            # direction the aircraft's main weapon is aimed.
            # 0,0 = straight ahead, 90,0=directly right, 0,90=directly up, 0,180=directly back, etc.
            weaponAngle_deg            : { heading: 180, elevation: 0 },

            # Offset of the weapon from the main aircraft center
            weaponOffset_m             : {x:-8, y:0, z:0},
          },
          #
          #########################################
          # WEAPONS DEFINITIONS
          #
          # The weapons system makes the AI aircraft fire on the main aircraft
          # You can define any number of weapons--just enclose each in curly brackets
          # and separate with commas (,).
          # Let's try 2 guns for the B17.  This could be improved/tweak for historical accuracy.
          # vs framerate.  It might be worthwhile to try 4, as FR isn't too bad with 2.
          # The B17 actually had 13 guns in different positions:
          # http://wiki.flightgear.org/Boeing_B-17_Flying_Fortress
          weapons : {
            # internal name - this can be any name you want; must be a valid nasal variable name
            cannon : {

              # name presented to users, ie in on-screen messages
              name                : "GSh-30-1",

              # maximum percentage damage one hit from the aircraft's main weapon/machine guns will do to an opponent
              # Based on observation from within FG, a good F6F pass can easily do 18% damage to most aircraft
              maxDamage_percent   : 18,

              # maximum distance at which the aircrafts main weapon/maching guns will be able to damage an opponent.
              Making this large is very expensive for FG's framerate and the chance of a hit at great than 100 meters,
              vanishingly small.  So set it carefully.
              maxDamageDistance_m : 1500,

              # direction the aircraft's main weapon is aimed.
              weaponAngle_deg     : { heading: 0, elevation: 0 },

              # 0,0 = straight ahead, 90,0=directly right, 0,90=directly up, 0,180=directly back, etc.
              # Offset of the weapon from the main aircraft center
              weaponOffset_m      : {x:-3, y:3, z:0},

              # Visual size of the weapon's projectile, in meters, at start & end of its path
              weaponSize_m        : {start:.1, end:.1},
            },
          },
          #
          #########################################
          # DIMENSION DEFINITIONS
          #
          # All dimensions are in meters
          # These dimensions must reach outside the actual model, ie,
          # slightly too large is better than slightly too small
          # Some models (like ships) have wake or other models and these
          # dimensions must be larger than those so if we go out to this
          # distance we will reach 'ground' and not 'model'
          #
          dimensions : {
            # width of your object, ie, for aircraft, wingspan
            width_m             : 14.70,

            # length of your object, ie, for aircraft, distance nose to tail
            length_m            : 21.19,

            # height of your object, ie, for aircraft ground to highest point when sitting on runway,
            height_m            : 5.93,

            # typically 1/2 the longest dimension of the object. Hits within this distance of the
            damageRadius_m      : 10.595,

            # center of object have some possibility of damage
            # typically the radius of the fuselage or cockpit or other most
            # vital area at the center of the object.  Always smaller than damageRadius_m
            vitalDamageRadius_m : 6,
          },
          #
          #########################################
          # VULNERABILITIES DEFINITIONS
          #
          vulnerabilities : {
            # Vulnerability to damage from armament, 1=normal M1 tank; higher to make objects easier to kill
            # and lower to make them  more difficult.  This  is a multiplier, so 5 means 5X easier to kill
            # than an M1, 1/5 means 5X harder to kill.
            damageVulnerability               : 20,

            # Chance that a small-caliber machine-gun round will damage the engine.
            engineDamageVulnerability_percent : 4,

            # Vulnerability to catching on fire. 100% means even the slightest impact will
            # set it on fire; 20% means quite difficult to set on fire; 0% means set on fire
            # only when completely damaged; -1% means never set on fire.
            fireVulnerability_percent         : 10,

            # Amount of damage to add, per second, when on fire.  100% = completely damaged.
            fireDamageRate_percentpersecond   : 0.2,

            # Once a fire starts, for this many seconds there is a chance to put out the fire;
            # fires lasting longer than this won't be put out until the object burns out.
            fireExtinguishMaxTime_seconds     : 180,

            # Chance of the crew putting out the fire within the MaxTime above.
            fireExtinguishSuccess_percentage  : 60,

            # mass of the object in KG, but give at least a 2-10X bonus to anything carrying flammables or high explosives.
            explosiveMass_kg                  : 47772,
          },
          #
          #########################################
          # LIVERY DEFINITIONS
          #
          # Path to livery files to use at different damage levels.
          # Path is relative to the AI aircraft's directory.
          # The object will start with the first livery listed and
          # change to succeeding liveries as the damage
          # level increases. The final livery should indicate full damage/
          # object destroyed.
          #
          # If you don't want to specify any special liveries simply set
          # damageLivery : nil and the object's normal livery will be used.
          #
          damageLiveries : {
            damageLivery : [  ]
          },
        };

        #########################################
        # INITIALIZE ROUTINES
        #
        # OVERALL INITIALIZER: Needed to make all the others work
        bombable.initialize ( bombableObject );
        #
        # LOCATION: Relocate object to maintain its position after file/reset
        # (best not used for airplanes)
        # bombable.location_init ( thisNodeName );
        #
        # GROUND: Keep object at altitude relative to ground level
        bombable.ground_init ( thisNodeName );
        #
        # BOMBABLE: Make the object bombable/damageable
        var bombableListenerid = bombable.bombable_init ( thisNodeName );
        #
        # ATTACK: Make the object attack the main aircraft
        #bombable.attack_init ( thisNodeName );
        # Attack turned off for B-17s--they don't attack, they simply fly formation & shoot back
        #
        # WEAPONS: Make the object shoot the main aircraft
        bombable.weapons_init ( thisNodeName );
        #
        # SMOKE/CONTRAIL: Start a flare, contrail, smoke trail, or exhaust
        # trail for the object.
        # Smoke types available: flare, jetcontrail, pistonexhaust, smoketrail,
        # damagedengine
        bombable.startSmoke("pistonexhaust", thisNodeName );
        #
        # END INITIALIZE BOMBABLE
        ########################################################################
        ########################################################################
      }

      object_init();
      ]]>
    </load>
    <unload>
      <![CDATA[
        print("Unload Sukhoi Su 33.");
        var nodeName= cmdarg().getPath();
        print("Unload object "~ nodeName );
        bombable.de_overall_initialize( nodeName );
        bombable.initialize_del( nodeName );
        bombable.ground_del( nodeName );
        # bombable.location_del (nodeName);
        bombable.bombable_del( nodeName );
        # bombable.attack_del( nodeName );
        bombable.weapons_del (nodeName);
        #  </unload>
      ]]>
    </unload>
  </nasal>

</PropertyList>
