fuel.nas 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # simple fuelsystem
  2. # this will use fuel from external tanks first.
  3. # while refueling all tanks are selected
  4. # Adapted from Eurofighter Typhoon code, by Aster
  5. props.globals.initNode("systems/refuel/refueling", 0, "BOOL");
  6. props.globals.initNode("systems/refuel/refueling_grnd", 0, "BOOL");
  7. var fueltanks = props.globals.getNode("consumables/fuel").getChildren("tank");
  8. var engine = props.globals.getNode("controls/engines").getChildren("engine");
  9. var fueltanks = props.globals.getNode("consumables/fuel").getChildren("tank");
  10. var wow = getprop ("/gear/gear[0]/wow");
  11. var parked = getprop("controls/gear/brake-parking");
  12. var refueling_grnd = props.globals.getNode("systems/refuel/refueling_grnd");
  13. var refueling = props.globals.getNode("systems/refuel/refueling");
  14. setlistener("systems/refuel/contact", func(n) {
  15. if (n.getValue() == 1) {
  16. refueling.setValue(1);
  17. foreach(f; fueltanks) {
  18. f.getNode("selected", 1).setBoolValue(1);
  19. }
  20. } else {
  21. refueling.setValue(0);
  22. }
  23. },1);
  24. # accessible from menu:
  25. var fillup = func {
  26. if (wow and parked) {
  27. foreach(f; fueltanks) {
  28. var cap = f.getNode("capacity-gal_us");
  29. var level = f.getNode("level-gal_us");
  30. if (cap.getValue() > level.getValue()) {
  31. refueling_grnd.setValue(1);
  32. f.getNode("selected", 1).setBoolValue(1);
  33. interpolate(f.getNode("level-gal_us"), cap.getValue(), 20);
  34. }
  35. }
  36. settimer( func refueling_grnd.setValue(0), 20);
  37. }
  38. }
  39. var fuelTanks = func {
  40. if (refueling.getValue() == 0 and refueling_grnd.getValue() == 0) {
  41. var levelDropStbd = getprop("consumables/fuel/tank[11]/level-gal_us");
  42. if(levelDropStbd == nil) { levelDropStbd = 0; }
  43. var levelDropPort = getprop("consumables/fuel/tank[9]/level-gal_us");
  44. if(levelDropPort == nil) { levelDropPort = 0; }
  45. var levelDropCentr = getprop("consumables/fuel/tank[10]/level-gal_us");
  46. if(levelDropCentr == nil) { levelDropCentr = 0; }
  47. var wingtanks = getprop("sim/weight[0]/weight-lb") + getprop("sim/weight[8]/weight-lb");
  48. var centertank = getprop("sim/weight[4]/weight-lb");
  49. if (getprop("sim/freeze/fuel")) { return registerTimer(fuelTanks); }
  50. if (getprop("systems/refuel/contact")) {return registerTimer(fuelTanks); }
  51. # first zero all tanks
  52. foreach(f; fueltanks) {
  53. if (f.getNode("selected", 1).getBoolValue()){
  54. f.getNode("selected", 1).setBoolValue(0);
  55. }
  56. }
  57. # centreline
  58. if (levelDropCentr > 0) {
  59. setprop("consumables/fuel/tank[10]/selected", 1);
  60. # wingtanks
  61. } elsif (levelDropStbd > 0 and levelDropPort > 0) {
  62. setprop("consumables/fuel/tank[9]/selected", 1);
  63. setprop("consumables/fuel/tank[11]/selected", 1);
  64. # internal: not ordered yet
  65. } else {
  66. foreach(f; fueltanks) {
  67. if (f.getNode("level-lbs").getValue() > 0.01) {
  68. f.getNode("selected", 0).setBoolValue(1);
  69. }
  70. }
  71. }
  72. }
  73. settimer(fuelTanks, 0.3);
  74. }
  75. setlistener("/sim/signals/fdm-initialized", fuelTanks);