##############################################################################
#                                  pylons                                    #
#                                                                            #
# BARANGER Emmanuel (Helijah) 01/2025 - 08/2025                              #
##############################################################################

var updatepylons = func {

  # sim/model/show-tiptanks
  var tipt = getprop("sim/multiplay/generic/bool[1]");
  if ( tipt == 1 ) {
    setprop("sim/weight[0]/selected", getprop("sim/weight[0]/opt[1]/name"));
    setprop("sim/weight[0]/weight-lb", getprop("sim/weight[0]/opt[1]/lbs"));

    setprop("sim/weight[1]/selected", getprop("sim/weight[1]/opt[1]/name"));
    setprop("sim/weight[1]/weight-lb", getprop("sim/weight[1]/opt[1]/lbs"));

    var run = getprop("controls/engines/engine[0]/cutoff");
    if ( run == 0 ) {                                     # engine on
      setprop("consumables/fuel/tank[1]/selected", 1);
      setprop("consumables/fuel/tank[2]/selected", 1);
    } elsif ( run == 1 ) {                                # engine off
      setprop("consumables/fuel/tank[1]/level-lbs", 335);
      setprop("consumables/fuel/tank[2]/level-lbs", 335);
    }
  } else {
    setprop("sim/weight[0]/selected", getprop("sim/weight[0]/opt[0]/name"));
    setprop("sim/weight[0]/weight-lb", getprop("sim/weight[0]/opt[0]/lbs"));

    setprop("sim/weight[1]/selected", getprop("sim/weight[1]/opt[0]/name"));
    setprop("sim/weight[1]/weight-lb", getprop("sim/weight[1]/opt[0]/lbs"));

    var run = getprop("controls/engines/engine[0]/cutoff");
    if ( run == 1 ) {                                     # engine on
      setprop("consumables/fuel/tank[1]/level-lbs", 0);
      setprop("consumables/fuel/tank[2]/level-lbs", 0);
    }
  }

  # sim/model/show-GA/A AIM-9M
  var sGAA = getprop("sim/multiplay/generic/bool[7]");
  if ( sGAA == 1 ) {
    var tir = getprop("controls/armament/trigger3");
    if ( tir == 0 ) {
      setprop("sim/weight[4]/selected", getprop("sim/weight[4]/opt[1]/name"));
      setprop("sim/weight[4]/weight-lb", getprop("sim/weight[4]/opt[1]/lbs"));
    }

    var tir = getprop("controls/armament/trigger3");
    if ( tir == 0 ) {
      setprop("sim/weight[5]/selected", getprop("sim/weight[5]/opt[1]/name"));
      setprop("sim/weight[5]/weight-lb", getprop("sim/weight[5]/opt[1]/lbs"));
    }
  } else {
    setprop("sim/weight[4]/selected", getprop("sim/weight[4]/opt[0]/name"));
    setprop("sim/weight[4]/weight-lb", getprop("sim/weight[4]/opt[0]/lbs"));

    setprop("sim/weight[5]/selected", getprop("sim/weight[5]/opt[0]/name"));
    setprop("sim/weight[5]/weight-lb", getprop("sim/weight[5]/opt[0]/lbs"));
  }

  # sim/model/show-tanks
  var shtk = getprop("sim/multiplay/generic/bool[3]");
  if ( shtk == 1 ) {
    setprop("sim/weight[2]/selected", getprop("sim/weight[2]/opt[1]/name"));
    setprop("sim/weight[2]/weight-lb", getprop("sim/weight[2]/opt[1]/lbs"));

    setprop("sim/weight[3]/selected", getprop("sim/weight[3]/opt[1]/name"));
    setprop("sim/weight[3]/weight-lb", getprop("sim/weight[3]/opt[1]/lbs"));

    var run = getprop("controls/engines/engine[0]/cutoff");
    if ( run == 0 ) {                                     # engine on
      setprop("consumables/fuel/tank[3]/selected", 1);
      setprop("consumables/fuel/tank[4]/selected", 1);
    } elsif ( run == 1 ) {                                # engine off
      setprop("consumables/fuel/tank[3]/level-lbs", 335);
      setprop("consumables/fuel/tank[4]/level-lbs", 335);
    }
  } else {
    setprop("sim/weight[2]/selected", getprop("sim/weight[2]/opt[0]/name"));
    setprop("sim/weight[2]/weight-lb", getprop("sim/weight[2]/opt[0]/lbs"));

    setprop("sim/weight[3]/selected", getprop("sim/weight[3]/opt[0]/name"));
    setprop("sim/weight[3]/weight-lb", getprop("sim/weight[3]/opt[0]/lbs"));

    var run = getprop("controls/engines/engine[0]/cutoff");
    if ( run == 1 ) {                                     # engine off
      setprop("consumables/fuel/tank[3]/level-lbs", 0);
      setprop("consumables/fuel/tank[4]/level-lbs", 0);
    }
  }

  # sim/model/show-smoketanks
  var smkt = getprop("sim/multiplay/generic/bool[2]");
  if ( smkt == 1 ) {
    setprop("sim/weight[6]/selected", getprop("sim/weight[6]/opt[1]/name"));
    setprop("sim/weight[6]/weight-lb", getprop("sim/weight[6]/opt[1]/lbs"));

    setprop("sim/weight[7]/selected", getprop("sim/weight[7]/opt[1]/name"));
    setprop("sim/weight[7]/weight-lb", getprop("sim/weight[7]/opt[1]/lbs"));
  }

  # sim/model/show-GA/G MK 82
  var sGAG = getprop("sim/multiplay/generic/bool[6]");
  if ( sGAG == 1 ) {
    var tir = getprop("controls/armament/trigger1");
    if ( tir == 0 ) {
      setprop("sim/weight[6]/selected", getprop("sim/weight[6]/opt[2]/name"));
      setprop("sim/weight[6]/weight-lb", getprop("sim/weight[6]/opt[2]/lbs"));
    }

    var tir = getprop("controls/armament/trigger2");
    if ( tir == 0 ) {
      setprop("sim/weight[7]/selected", getprop("sim/weight[7]/opt[2]/name"));
      setprop("sim/weight[7]/weight-lb", getprop("sim/weight[7]/opt[2]/lbs"));
    }
  }

  # sim/model/show-gunpod
  var sGunPod = getprop("sim/multiplay/generic/bool[23]");
  if ( sGunPod == 1 ) {
    setprop("sim/weight[6]/selected", getprop("sim/weight[6]/opt[3]/name"));
    setprop("sim/weight[6]/weight-lb", getprop("sim/weight[6]/opt[3]/lbs"));

    setprop("sim/weight[7]/selected", getprop("sim/weight[7]/opt[3]/name"));
    setprop("sim/weight[7]/weight-lb", getprop("sim/weight[7]/opt[3]/lbs"));
  }

  if ( smkt == 0 and sGAG == 0 and sGunPod == 0 ) {
    setprop("sim/weight[6]/selected", getprop("sim/weight[6]/opt[0]/name"));
    setprop("sim/weight[6]/weight-lb", getprop("sim/weight[6]/opt[0]/lbs"));

    setprop("sim/weight[7]/selected", getprop("sim/weight[7]/opt[0]/name"));
    setprop("sim/weight[7]/weight-lb", getprop("sim/weight[7]/opt[0]/lbs"));
  }

}

updatepylons();
