aar.nas 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # Properties under /consumables/fuel/tank[n]:
  2. # + level-gal_us - Current fuel load. Can be set by user code.
  3. # + level-lbs - OUTPUT ONLY property, do not try to set
  4. # + selected - boolean indicating tank selection.
  5. # + density-ppg - Fuel density, in lbs/gallon.
  6. # + capacity-gal_us - Tank capacity
  7. #
  8. # Properties under /engines/engine[n]:
  9. # + fuel-consumed-lbs - Output from the FDM, zeroed by this script
  10. # + out-of-fuel - boolean, set by this code.
  11. # ==================================== timer stuff ===========================================
  12. # set the update period
  13. UPDATE_PERIOD = 0.3;
  14. # set the timer for the selected function
  15. registerTimer = func {
  16. settimer(arg[0], UPDATE_PERIOD);
  17. } # end function
  18. # =============================== end timer stuff ===========================================
  19. initialized = 0;
  20. enabled = 0;
  21. print ("running aar");
  22. # print (" enabled " , enabled, " initialized ", initialized);
  23. updateTanker = func {
  24. # print ("tanker update running ");
  25. #if (!initialized ) {
  26. #print("calling initialize");
  27. #initialize();}
  28. Refueling = props.globals.getNode("/systems/refuel/contact");
  29. AllAircraft = props.globals.getNode("ai/models").getChildren("aircraft");
  30. AllMultiplayer = props.globals.getNode("ai/models").getChildren("multiplayer");
  31. Aircraft = props.globals.getNode("ai/models/aircraft");
  32. # select all tankers which are in contact. For now we assume that it must be in
  33. # contact with us.
  34. selectedTankers = [];
  35. if ( enabled ) { # check that AI Models are enabled, otherwise don't bother
  36. foreach(a; AllAircraft) {
  37. contact_node = a.getNode("refuel/contact");
  38. id_node = a.getNode("id");
  39. tanker_node = a.getNode("tanker");
  40. contact = contact_node.getValue();
  41. id = id_node.getValue();
  42. tanker = tanker_node.getValue();
  43. # print ("contact ", contact , " tanker " , tanker );
  44. if (tanker and contact) {
  45. append(selectedTankers, a);
  46. }
  47. }
  48. foreach(m; AllMultiplayer) {
  49. contact_node = m.getNode("refuel/contact");
  50. id_node = m.getNode("id");
  51. tanker_node = m.getNode("tanker");
  52. contact = contact_node.getValue();
  53. id = id_node.getValue();
  54. tanker = tanker_node.getValue();
  55. # print (" mp contact ", contact , " tanker " , tanker );
  56. if (tanker and contact) {
  57. append(selectedTankers, m);
  58. }
  59. }
  60. }
  61. # print ("tankers ", size(selectedTankers) );
  62. if ( size(selectedTankers) >= 1 ){
  63. Refueling.setBoolValue(1);
  64. } else {
  65. Refueling.setBoolValue(0);
  66. }
  67. registerTimer(updateTanker);
  68. }
  69. # Initalize: Make sure all needed properties are present and accounted
  70. # for, and that they have sane default values.
  71. initialize = func {
  72. AI_Enabled = props.globals.getNode("sim/ai/enabled");
  73. Refueling = props.globals.getNode("/systems/refuel/contact",1);
  74. Refueling.setBoolValue(0);
  75. enabled = AI_Enabled.getValue();
  76. initialized = 1;
  77. }
  78. initDoubleProp = func {
  79. node = arg[0]; prop = arg[1]; val = arg[2];
  80. if(node.getNode(prop) != nil) {
  81. val = num(node.getNode(prop).getValue());
  82. }
  83. node.getNode(prop, 1).setDoubleValue(val);
  84. }
  85. # Fire it up
  86. if (!initialized) {initialize();}
  87. registerTimer(updateTanker);