######################################################################
#                    Helijah 07/2024                                 #
#                    Updated 06/2025                                 #
######################################################################

var loop = func {

  # var doors  = getprop("sim/model/door-positions/water/position-norm");
  var doors  = getprop("sim/multiplay/generic/float[8]");
  var empty0 = getprop("/ai/submodels/submodel[0]/count");
  var empty1 = getprop("/ai/submodels/submodel[1]/count");
  var empty2 = getprop("/ai/submodels/submodel[2]/count");
  var empty3 = getprop("/ai/submodels/submodel[3]/count");

  if ((doors == 1) and ((empty0 > 0) or (empty1 > 0) or (empty2 > 0) or (empty3 > 0))) {
    # setprop("/sim/model/water-release",1);
    setprop("/sim/multiplay/generic/int[10]",1);
  } else {
    # setprop("/sim/model/water-release",0);
    setprop("/sim/multiplay/generic/int[10]",0);
  }

  setprop("/sim/weight[0]/weight-lb", getprop("/ai/submodels/submodel[0]/count"));
  setprop("/sim/weight[1]/weight-lb", getprop("/ai/submodels/submodel[1]/count"));
  setprop("/sim/weight[2]/weight-lb", getprop("/ai/submodels/submodel[2]/count"));
  setprop("/sim/weight[3]/weight-lb", getprop("/ai/submodels/submodel[3]/count"));

}

var update_loop = func {
  loop();
  settimer(update_loop, 0);
}
setlistener("/sim/signals/fdm-initialized", update_loop);
