radar.nas 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # =======================
  2. # Multiplayer Quirks
  3. # =======================
  4. var RadarStandby = props.globals.getNode("instrumentation/radar/radar-standby");
  5. MPjoin = func(n) {
  6. #print(n.getValue(), " added");
  7. setprop("instrumentation/radar",n.getValue(),"radar/y-shift",0);
  8. setprop("instrumentation/radar",n.getValue(),"radar/x-shift",0);
  9. setprop("instrumentation/radar",n.getValue(),"radar/rotation",0);
  10. setprop("instrumentation/radar",n.getValue(),"radar/in-range",0);
  11. setprop("instrumentation/radar",n.getValue(),"radar/h-offset",180);
  12. setprop("instrumentation/radar",n.getValue(),"joined",1);
  13. }
  14. MPleave= func(n) {
  15. #print(n.getValue(), " removed");
  16. setprop("instrumentation/radar",n.getValue(),"radar/in-range",0);
  17. setprop("instrumentation/radar",n.getValue(),"joined",0);
  18. }
  19. #need to copy the properties so that we never try to access a non-existent property in XML
  20. MPradarProperties = func {
  21. var Estado = RadarStandby.getValue();
  22. if ( Estado != 1 ) {
  23. targetList = props.globals.getNode("ai/models/").getChildren("multiplayer");
  24. foreach (d; props.globals.getNode("ai/models/").getChildren("aircraft")) {
  25. append(targetList,d);
  26. }
  27. foreach (m; targetList) {
  28. var string = "instrumentation/radar/ai/models/"~m.getName()~"["~m.getIndex()~"]/";
  29. if (getprop(string,"joined")==1 or m.getName()=="aircraft") {
  30. factor = getprop("instrumentation/radar/range-factor"); ## if (factor == nil) { factor=0.001888};
  31. setprop(string,"radar/y-shift",m.getNode("radar/y-shift").getValue() * factor);
  32. setprop(string,"radar/x-shift",m.getNode("radar/x-shift").getValue() * factor);
  33. setprop(string,"radar/rotation",m.getNode("radar/rotation").getValue());
  34. setprop(string,"radar/h-offset",m.getNode("radar/h-offset").getValue());
  35. if (getprop("instrumentation/radar/selected")==2){
  36. if (getprop(string~"radar/x-shift") < -0.04 or
  37. getprop(string~"radar/x-shift") > 0.04) {
  38. setprop(string,"radar/in-range",0);
  39. } else {
  40. setprop(string,"radar/in-range",m.getNode("radar/in-range").getValue());
  41. }
  42. } else {
  43. setprop(string,"radar/in-range",m.getNode("radar/in-range").getValue());
  44. }
  45. }
  46. }
  47. # this is a good place to deal with the range scaling factors
  48. if (getprop("instrumentation/radar/selected")==2) {
  49. if (getprop("instrumentation/radar/range")==10) {
  50. setprop("instrumentation/radar/range",10);
  51. setprop("instrumentation/radar/range-factor",0.00648);
  52. }
  53. elsif (getprop("instrumentation/radar/range")==20) {
  54. setprop("instrumentation/radar/range-factor",0.00324);
  55. }
  56. else { #40
  57. setprop("instrumentation/radar/range-factor",0.00162);
  58. }
  59. }
  60. elsif(getprop("instrumentation/radar/selected")==3 or getprop("instrumentation/radar/selected")==4) {
  61. if (getprop("instrumentation/radar/range")==40) {
  62. setprop("instrumentation/radar/range",40);
  63. setprop("instrumentation/radar/range-factor",0.00162);
  64. }
  65. elsif (getprop("instrumentation/radar/range")==20) {
  66. setprop("instrumentation/radar/range-factor",0.00324);
  67. }
  68. else { #10
  69. setprop("instrumentation/radar/range-factor",0.00648);
  70. }
  71. }
  72. } # from Estado
  73. settimer(MPradarProperties,1.0);
  74. }
  75. # ===================
  76. # Boresight Detecting
  77. # ===================
  78. locking=0;
  79. found=-1;
  80. boreSightLock = func {
  81. var Estado = RadarStandby.getValue();
  82. if ( Estado != 1 ) {
  83. if(getprop("instrumentation/radar/selected") == 1){
  84. targetList= props.globals.getNode("ai/models/").getChildren("multiplayer");
  85. foreach (d; props.globals.getNode("ai/models/").getChildren("aircraft")) {
  86. append(targetList,d);
  87. }
  88. foreach (m; targetList) {
  89. var string = "instrumentation/radar/ai/models/"~m.getName()~"["~m.getIndex()~"]";
  90. var string1 = "ai/models/"~m.getName()~"["~m.getIndex()~"]";
  91. if (getprop(string1~"radar/in-range")) {
  92. hOffset = getprop(string1~"radar/h-offset");
  93. vOffset = getprop(string1~"radar/v-offset");
  94. #really should be a cone, but is a square pyramid to avoid trigonemetry
  95. if(hOffset < 3 and hOffset > -3 and vOffset < 3 and vOffset > -3) {
  96. if (locking == 11){
  97. setprop(string~"radar/boreLock",2);
  98. setprop("instrumentation/radar/lock",2);
  99. # setprop("sim[0]/hud/current-color",1);
  100. locking -= 1;
  101. }
  102. elsif (locking ==1 or locking ==3 or locking ==5 or locking ==7 or locking ==9 ) {
  103. setprop("instrumentation/radar/lock",1);
  104. setprop(string1~"radar/boreLock",1);
  105. }
  106. else {
  107. setprop("instrumentation/radar/lock",0);
  108. setprop(string~"radar/boreLock",1);
  109. }
  110. if (found != m.getIndex()) {
  111. found=m.getIndex();
  112. locking=0;
  113. }
  114. else {
  115. locking += 1;
  116. }
  117. settimer(boreSightLock, 0.2);
  118. return;
  119. }
  120. }
  121. }
  122. setprop(string~"radar/boreLock",0);
  123. locking=0;
  124. # setprop("sim[0]/hud/current-color",0);
  125. } # from getprop
  126. } # from Estado
  127. locking=0;
  128. # setprop("sim[0]/hud/current-color",0);
  129. found =-1;
  130. setprop("instrumentation/radar/lock",0);
  131. settimer(boreSightLock, 0.2);
  132. }
  133. setlistener("ai/models/model-added", MPjoin);
  134. setlistener("ai/models/model-removed", MPleave);
  135. settimer(MPradarProperties,1.0);
  136. settimer(boreSightLock, 1.0);