rwr.nas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. print("*** LOADING rwr.nas ... ***");
  2. var lineWidth = 3;
  3. RWRCanvas = {
  4. new: func (_ident, root, center, diameter) {
  5. var rwr = {parents: [RWRCanvas]};
  6. rwr.max_icons = 12;
  7. var radius = diameter/2;
  8. rwr.inner_radius = radius*0.30;
  9. rwr.outer_radius = radius*0.75;
  10. rwr.circle_radius_big = radius*0.5;
  11. rwr.circle_radius_small = radius*0.125;
  12. var tick_long = radius*0.25;
  13. var tick_short = tick_long*0.5;
  14. var font = int(0.08*diameter);
  15. var colorG = [0.3,1,0.3];
  16. var colorLG = [0,0.5,0];
  17. rwr.fadeTime = 7;#seconds
  18. rwr.rootCenter = root.createChild("group")
  19. .setTranslation(center[0],center[1]);
  20. var rootOffset = root.createChild("group")
  21. .setTranslation(center[0]-diameter/2,center[1]-diameter/2);
  22. # root.createChild("path")
  23. # .moveTo(0, diameter/2)
  24. # .arcSmallCW(diameter/2, diameter/2, 0, diameter, 0)
  25. # .arcSmallCW(diameter/2, diameter/2, 0, -diameter, 0)
  26. # .setStrokeLineWidth(lineWidth)
  27. # .setColor(1, 1, 1);
  28. rootOffset.createChild("path")
  29. .moveTo(diameter/2-rwr.circle_radius_small, diameter/2)
  30. .arcSmallCW(rwr.circle_radius_small, rwr.circle_radius_small, 0, rwr.circle_radius_small*2, 0)
  31. .arcSmallCW(rwr.circle_radius_small, rwr.circle_radius_small, 0, -rwr.circle_radius_small*2, 0)
  32. .setStrokeLineWidth(lineWidth)
  33. .setColor(colorLG);
  34. rootOffset.createChild("path")
  35. .moveTo(diameter/2-rwr.circle_radius_big, diameter/2)
  36. .arcSmallCW(rwr.circle_radius_big, rwr.circle_radius_big, 0, rwr.circle_radius_big*2, 0)
  37. .arcSmallCW(rwr.circle_radius_big, rwr.circle_radius_big, 0, -rwr.circle_radius_big*2, 0)
  38. .setStrokeLineWidth(lineWidth)
  39. .setColor(colorLG);
  40. rootOffset.createChild("path")
  41. .moveTo(diameter/2-rwr.circle_radius_small/2, diameter/2)
  42. .lineTo(diameter/2+rwr.circle_radius_small/2, diameter/2)
  43. .moveTo(diameter/2, diameter/2-rwr.circle_radius_small/2)
  44. .lineTo(diameter/2, diameter/2+rwr.circle_radius_small/2)
  45. .setStrokeLineWidth(lineWidth)
  46. .setColor(colorLG);
  47. rootOffset.createChild("path")
  48. .moveTo(0,diameter*0.5)
  49. .horiz(tick_long)
  50. .moveTo(diameter,diameter*0.5)
  51. .horiz(-tick_long)
  52. .moveTo(diameter*0.5,0)
  53. .vert(tick_long)
  54. .moveTo(diameter*0.5,diameter)
  55. .vert(-tick_long)
  56. .setStrokeLineWidth(lineWidth)
  57. .setColor(colorLG);
  58. rwr.rootCenter.createChild("path")
  59. .moveTo(radius*math.cos(30*D2R),radius*math.sin(-30*D2R))
  60. .lineTo((radius-tick_short)*math.cos(30*D2R),(radius-tick_short)*math.sin(-30*D2R))
  61. .moveTo(radius*math.cos(60*D2R),radius*math.sin(-60*D2R))
  62. .lineTo((radius-tick_short)*math.cos(60*D2R),(radius-tick_short)*math.sin(-60*D2R))
  63. .moveTo(radius*math.cos(30*D2R),radius*math.sin(30*D2R))
  64. .lineTo((radius-tick_short)*math.cos(30*D2R),(radius-tick_short)*math.sin(30*D2R))
  65. .moveTo(radius*math.cos(60*D2R),radius*math.sin(60*D2R))
  66. .lineTo((radius-tick_short)*math.cos(60*D2R),(radius-tick_short)*math.sin(60*D2R))
  67. .moveTo(-radius*math.cos(30*D2R),radius*math.sin(-30*D2R))
  68. .lineTo(-(radius-tick_short)*math.cos(30*D2R),(radius-tick_short)*math.sin(-30*D2R))
  69. .moveTo(-radius*math.cos(60*D2R),radius*math.sin(-60*D2R))
  70. .lineTo(-(radius-tick_short)*math.cos(60*D2R),(radius-tick_short)*math.sin(-60*D2R))
  71. .moveTo(-radius*math.cos(30*D2R),radius*math.sin(30*D2R))
  72. .lineTo(-(radius-tick_short)*math.cos(30*D2R),(radius-tick_short)*math.sin(30*D2R))
  73. .moveTo(-radius*math.cos(60*D2R),radius*math.sin(60*D2R))
  74. .lineTo(-(radius-tick_short)*math.cos(60*D2R),(radius-tick_short)*math.sin(60*D2R))
  75. .setStrokeLineWidth(lineWidth)
  76. .setColor(colorLG);
  77. rwr.texts = setsize([],rwr.max_icons);
  78. for (var i = 0;i<rwr.max_icons;i+=1) {
  79. rwr.texts[i] = rwr.rootCenter.createChild("text")
  80. .setText("00")
  81. .setAlignment("center-center")
  82. .setColor(colorG)
  83. .setFontSize(font, 1.0)
  84. .hide();
  85. }
  86. rwr.symbol_hat = setsize([],rwr.max_icons);
  87. for (var i = 0;i<rwr.max_icons;i+=1) {
  88. rwr.symbol_hat[i] = rwr.rootCenter.createChild("path")
  89. .moveTo(0,-font)
  90. .lineTo(font*0.7,-font*0.5)
  91. .moveTo(0,-font)
  92. .lineTo(-font*0.7,-font*0.5)
  93. .setStrokeLineWidth(lineWidth)
  94. .setColor(colorG)
  95. .hide();
  96. }
  97. # me.symbol_16_SAM = setsize([],max_icons);
  98. # for (var i = 0;i<max_icons;i+=1) {
  99. # me.symbol_16_SAM[i] = me.rootCenter.createChild("path")
  100. # .moveTo(-11, 7)
  101. # .lineTo(-9, -7)
  102. # .moveTo(-9, -7)
  103. # .lineTo(-9, -4)
  104. # .moveTo(-9, -8)
  105. # .lineTo(-11, -4)
  106. # .setStrokeLineWidth(lineWidth)
  107. # .setColor(1,0,0)
  108. # .hide();
  109. # }
  110. rwr.symbol_launch = setsize([],rwr.max_icons);
  111. for (var i = 0;i<rwr.max_icons;i+=1) {
  112. rwr.symbol_launch[i] = rwr.rootCenter.createChild("path")
  113. .moveTo(font*1.2, 0)
  114. .arcSmallCW(font*1.2, font*1.2, 0, -font*2.4, 0)
  115. .arcSmallCW(font*1.2, font*1.2, 0, font*2.4, 0)
  116. .setStrokeLineWidth(lineWidth)
  117. .setColor(colorG)
  118. .hide();
  119. }
  120. rwr.symbol_new = setsize([],rwr.max_icons);
  121. for (var i = 0;i<rwr.max_icons;i+=1) {
  122. rwr.symbol_new[i] = rwr.rootCenter.createChild("path")
  123. .moveTo(font*1.2, 0)
  124. .arcSmallCCW(font*1.2, font*1.2, 0, -font*2.4, 0)
  125. .setStrokeLineWidth(lineWidth)
  126. .setColor(colorG)
  127. .hide();
  128. }
  129. # rwr.symbol_16_lethal = setsize([],max_icons);
  130. # for (var i = 0;i<max_icons;i+=1) {
  131. # rwr.symbol_16_lethal[i] = rwr.rootCenter.createChild("path")
  132. # .moveTo(10, 10)
  133. # .lineTo(10, -10)
  134. # .lineTo(-10,-10)
  135. # .lineTo(-10,10)
  136. # .lineTo(10, 10)
  137. # .setStrokeLineWidth(lineWidth)
  138. # .setColor(1,0,0)
  139. # .hide();
  140. # }
  141. rwr.symbol_priority = rwr.rootCenter.createChild("path")
  142. .moveTo(0, font*1.2)
  143. .lineTo(font*1.2, 0)
  144. .lineTo(0,-font*1.2)
  145. .lineTo(-font*1.2,0)
  146. .lineTo(0, font*1.2)
  147. .setStrokeLineWidth(lineWidth)
  148. .setColor(colorG)
  149. .hide();
  150. # rwr.symbol_16_air = setsize([],max_icons);
  151. # for (var i = 0;i<max_icons;i+=1) {
  152. # rwr.symbol_16_air[i] = rwr.rootCenter.createChild("path")
  153. # .moveTo(15, 0)
  154. # .lineTo(0,-15)
  155. # .lineTo(-15,0)
  156. # .setStrokeLineWidth(lineWidth)
  157. # .setColor(1,0,0)
  158. # .hide();
  159. # }
  160. # Threat list ID:
  161. #REVISION: 2022/02/12
  162. #OPRF Fleet
  163. rwr.AIRCRAFT_WARTHOG = "10";
  164. rwr.AIRCRAFT_TOMCAT = "14";
  165. rwr.AIRCRAFT_EAGLE = "15";
  166. rwr.AIRCRAFT_FALCON = "16";
  167. rwr.AIRCRAFT_FISHBED = "21";
  168. rwr.AIRCRAFT_FLANKER = "27";
  169. rwr.AIRCRAFT_FULCRUM = "29";
  170. rwr.AIRCRAFT_VIGGEN = "37";
  171. rwr.AIRCRAFT_BLACKBIRD = "71";
  172. rwr.AIRCRAFT_JAGUAR = "JA";
  173. rwr.AIRCRAFT_MIRAGE = "M2";
  174. rwr.AIRCRAFT_SEARCH = "S";
  175. rwr.ASSET_AAA = "A";
  176. rwr.ASSET_VOLGA = "2";
  177. rwr.ASSET_BUK = "11";
  178. rwr.ASSET_GARGOYLE = "20"; # Other namings for tracking and radar: BB, CS.
  179. rwr.ASSET_PAC2 = "P";
  180. rwr.ASSET_FRIGATE = "SH";
  181. rwr.SCENARIO_OPPONENT = "28";
  182. #MISC
  183. rwr.AIRCRAFT_FAGOT = "MG";
  184. rwr.AIRCRAFT_FOXBAT = "FB";
  185. rwr.AIRCRAFT_FLOGGER = "23";
  186. rwr.AIRCRAFT_FULLBACK = "34";
  187. rwr.AIRCRAFT_PAKFA = "57";
  188. rwr.AIRCRAFT_TYPHOON = "EF";
  189. rwr.AIRCRAFT_HORNET = "18";
  190. rwr.AIRCRAFT_FLAGON = "SU";
  191. rwr.AIRCRAFT_PHANTOM = "F4";
  192. rwr.AIRCRAFT_SKYHAWK = "A4";
  193. rwr.AIRCRAFT_TIGER = "F5";
  194. rwr.AIRCRAFT_TONKA = "TO";
  195. rwr.AIRCRAFT_AARDVARK = "F1";
  196. rwr.AIRCRAFT_RAFALE = "RF";
  197. rwr.AIRCRAFT_HARRIER = "HA";
  198. rwr.AIRCRAFT_HARRIERII = "AV";
  199. rwr.AIRCRAFT_GINA = "91";
  200. rwr.AIRCRAFT_MB339 = "M3";
  201. rwr.AIRCRAFT_ALPHAJET = "AJ";
  202. rwr.AIRCRAFT_INTRUDER = "A6";
  203. rwr.AIRCRAFT_FROGFOOT = "25";
  204. rwr.AIRCRAFT_NIGHTHAWK = "17";
  205. rwr.AIRCRAFT_RAPTOR = "22";
  206. rwr.AIRCRAFT_JSF = "35";
  207. rwr.AIRCRAFT_GRIPEN = "39";
  208. rwr.AIRCRAFT_MITTEN = "Y1";
  209. rwr.AIRCRAFT_ALCA = "LC";
  210. rwr.AIRCRAFT_SPRETNDRD = "ET";
  211. rwr.AIRCRAFT_MIRAGEF1 = "M1";
  212. rwr.AIRCRAFT_UNKNOWN = "U";
  213. rwr.AIRCRAFT_UFO = "UK";
  214. rwr.ASSET_AI = "AI";
  215. rwr.lookupType = {
  216. # OPRF fleet and related aircrafts:
  217. "f-14b": rwr.AIRCRAFT_TOMCAT,
  218. "F-14D": rwr.AIRCRAFT_TOMCAT,
  219. "F-15C": rwr.AIRCRAFT_EAGLE,
  220. "F-15D": rwr.AIRCRAFT_EAGLE,
  221. "F-16": rwr.AIRCRAFT_FALCON,
  222. "JA37-Viggen": rwr.AIRCRAFT_VIGGEN,
  223. "AJ37-Viggen": rwr.AIRCRAFT_VIGGEN,
  224. "AJS37-Viggen": rwr.AIRCRAFT_VIGGEN,
  225. "JA37Di-Viggen": rwr.AIRCRAFT_VIGGEN,
  226. "m2000-5": rwr.AIRCRAFT_MIRAGE,
  227. "m2000-5B": rwr.AIRCRAFT_MIRAGE,
  228. "MiG-21bis": rwr.AIRCRAFT_FISHBED,
  229. "MiG-21MF-75": rwr.AIRCRAFT_FISHBED,
  230. "MiG-29": rwr.AIRCRAFT_FULCRUM,
  231. "SU-27": rwr.AIRCRAFT_FLANKER,
  232. "EC-137R": rwr.AIRCRAFT_SEARCH,
  233. "RC-137R": rwr.AIRCRAFT_SEARCH,
  234. "E-8R": rwr.AIRCRAFT_SEARCH,
  235. "EC-137D": rwr.AIRCRAFT_SEARCH,
  236. "gci": rwr.AIRCRAFT_SEARCH,
  237. "Blackbird-SR71A": rwr.AIRCRAFT_BLACKBIRD,
  238. "Blackbird-SR71A-BigTail": rwr.AIRCRAFT_BLACKBIRD,
  239. "Blackbird-SR71B": rwr.AIRCRAFT_BLACKBIRD,
  240. "A-10": rwr.AIRCRAFT_WARTHOG,
  241. "A-10-model": rwr.AIRCRAFT_WARTHOG,
  242. "Typhoon": rwr.AIRCRAFT_TYPHOON,
  243. "ZSU-23-4M": rwr.ASSET_AAA,
  244. "S-75": rwr.ASSET_VOLGA,
  245. "buk-m2": rwr.ASSET_BUK,
  246. "s-300": rwr.ASSET_GARGOYLE,
  247. "MIM104D": rwr.ASSET_PAC2,
  248. "missile_frigate": rwr.ASSET_FRIGATE,
  249. "frigate": rwr.ASSET_FRIGATE,
  250. "fleet": rwr.ASSET_FRIGATE,
  251. "Mig-28": rwr.SCENARIO_OPPONENT,
  252. "Jaguar-GR1": rwr.AIRCRAFT_JAGUAR,
  253. # Other threatening aircrafts (FGAddon, FGUK, etc.):
  254. "AI": rwr.ASSET_AI,
  255. "SU-37": rwr.AIRCRAFT_FLANKER,
  256. "J-11A": rwr.AIRCRAFT_FLANKER,
  257. "daVinci_SU-34": rwr.AIRCRAFT_FULLBACK,
  258. "Su-34": rwr.AIRCRAFT_FULLBACK,
  259. "T-50": rwr.AIRCRAFT_PAKFA,
  260. "MiG-21Bison": rwr.AIRCRAFT_FISHBED,
  261. "Mig-29": rwr.AIRCRAFT_FULCRUM,
  262. "EF2000": rwr.AIRCRAFT_TYPHOON,
  263. "F-15C_Eagle": rwr.AIRCRAFT_EAGLE,
  264. "F-15J_ADTW": rwr.AIRCRAFT_EAGLE,
  265. "F-15DJ_ADTW": rwr.AIRCRAFT_EAGLE,
  266. "f16": rwr.AIRCRAFT_FALCON,
  267. "F-16CJ": rwr.AIRCRAFT_FALCON,
  268. "FA-18C_Hornet": rwr.AIRCRAFT_HORNET,
  269. "FA-18D_Hornet": rwr.AIRCRAFT_HORNET,
  270. "f18": rwr.AIRCRAFT_HORNET,
  271. "F-111C": rwr.AIRCRAFT_AARDVARK,
  272. "A-10-modelB": rwr.AIRCRAFT_WARTHOG,
  273. "Su-15": rwr.AIRCRAFT_FLAGON,
  274. "jaguar": rwr.AIRCRAFT_JAGUAR,
  275. "Jaguar-GR3": rwr.AIRCRAFT_JAGUAR,
  276. "E3B": rwr.AIRCRAFT_SEARCH,
  277. "E-2C-Hawkeye": rwr.AIRCRAFT_SEARCH,
  278. "onox-awacs": rwr.AIRCRAFT_SEARCH,
  279. "u-2s": rwr.AIRCRAFT_SEARCH,
  280. "U-2S-model": rwr.AIRCRAFT_SEARCH,
  281. "F-4S": rwr.AIRCRAFT_PHANTOM,
  282. "F-4EJ_ADTW": rwr.AIRCRAFT_PHANTOM,
  283. "FGR2-Phantom": rwr.AIRCRAFT_PHANTOM,
  284. "F4J": rwr.AIRCRAFT_PHANTOM,
  285. "F-4D": rwr.AIRCRAFT_PHANTOM,
  286. "F-4E": rwr.AIRCRAFT_PHANTOM,
  287. "F-4N": rwr.AIRCRAFT_PHANTOM,
  288. "a4f": rwr.AIRCRAFT_SKYHAWK,
  289. "A-4K": rwr.AIRCRAFT_SKYHAWK,
  290. "F-5E": rwr.AIRCRAFT_TIGER,
  291. "F-5E-TigerII": rwr.AIRCRAFT_TIGER,
  292. "F-5ENinja": rwr.AIRCRAFT_TIGER,
  293. "f-20A": rwr.AIRCRAFT_TIGER,
  294. "f-20C": rwr.AIRCRAFT_TIGER,
  295. "f-20prototype": rwr.AIRCRAFT_TIGER,
  296. "f-20bmw": rwr.AIRCRAFT_TIGER,
  297. "f-20-dutchdemo": rwr.AIRCRAFT_TIGER,
  298. "Tornado-GR4a": rwr.AIRCRAFT_TONKA,
  299. "Tornado-IDS": rwr.AIRCRAFT_TONKA,
  300. "Tornado-F3": rwr.AIRCRAFT_TONKA,
  301. "Tornado-ADV": rwr.AIRCRAFT_TONKA,
  302. "brsq": rwr.AIRCRAFT_RAFALE,
  303. "Harrier-GR1": rwr.AIRCRAFT_HARRIER,
  304. "Harrier-GR3": rwr.AIRCRAFT_HARRIER,
  305. "Harrier-GR5": rwr.AIRCRAFT_HARRIER,
  306. "Harrier-GR9": rwr.AIRCRAFT_HARRIER,
  307. "AV-8B": rwr.AIRCRAFT_HARRIERII,
  308. "G91-R1B": rwr.AIRCRAFT_GINA,
  309. "G91": rwr.AIRCRAFT_GINA,
  310. "g91": rwr.AIRCRAFT_GINA,
  311. "mb339": rwr.AIRCRAFT_MB339,
  312. "mb339pan": rwr.AIRCRAFT_MB339,
  313. "alphajet": rwr.AIRCRAFT_ALPHAJET,
  314. "MiG-15bis": rwr.AIRCRAFT_FAGOT,
  315. "MiG-23ML": rwr.AIRCRAFT_FLOGGER,
  316. "MiG-23MLD": rwr.AIRCRAFT_FLOGGER,
  317. "Su-25": rwr.AIRCRAFT_FROGFOOT,
  318. "MiG-25": rwr.AIRCRAFT_FOXBAT,
  319. "A-6E-model": rwr.AIRCRAFT_INTRUDER,
  320. "A-6E": rwr.AIRCRAFT_INTRUDER,
  321. "F-117": rwr.AIRCRAFT_NIGHTHAWK,
  322. "F-22-Raptor": rwr.AIRCRAFT_RAPTOR,
  323. "F-35A": rwr.AIRCRAFT_JSF,
  324. "F-35B": rwr.AIRCRAFT_JSF,
  325. "F-35C": rwr.AIRCRAFT_JSF,
  326. "daVinci_F-35A": rwr.AIRCRAFT_JSF,
  327. "daVinci_F-35B": rwr.AIRCRAFT_JSF,
  328. "JAS-39C_Gripen": rwr.AIRCRAFT_GRIPEN,
  329. "gripen": rwr.AIRCRAFT_GRIPEN,
  330. "Yak-130": rwr.AIRCRAFT_MITTEN,
  331. "L-159": rwr.AIRCRAFT_ALCA,
  332. "super-etendard": rwr.AIRCRAFT_SPRETNDRD,
  333. "Mirage_F1-model": rwr.AIRCRAFT_MIRAGEF1,
  334. "USS-NORMANDY": rwr.ASSET_FRIGATE,
  335. "USS-LakeChamplain": rwr.ASSET_FRIGATE,
  336. "USS-OliverPerry": rwr.ASSET_FRIGATE,
  337. "USS-SanAntonio": rwr.ASSET_FRIGATE,
  338. "mp-nimitz": rwr.ASSET_FRIGATE,
  339. "mp-eisenhower": rwr.ASSET_FRIGATE,
  340. "mp-vinson": rwr.ASSET_FRIGATE,
  341. "mp-clemenceau": rwr.ASSET_FRIGATE,
  342. "ufo": rwr.AIRCRAFT_UFO,
  343. "bluebird-osg": rwr.AIRCRAFT_UFO,
  344. "Vostok-1": rwr.AIRCRAFT_UFO,
  345. "V-1": rwr.AIRCRAFT_UFO,
  346. "SpaceShuttle": rwr.AIRCRAFT_UFO,
  347. "F-23C_BlackWidow-II": rwr.AIRCRAFT_UFO,
  348. };
  349. rwr.shownList = [];
  350. #
  351. # recipient that will be registered on the global transmitter and connect this
  352. # subsystem to allow subsystem notifications to be received
  353. rwr.recipient = emesary.Recipient.new(_ident);
  354. rwr.recipient.parent_obj = rwr;
  355. rwr.recipient.Receive = func(notification)
  356. {
  357. if (notification.NotificationType == "FrameNotification")
  358. {
  359. #
  360. # Link16 wingmen only visible when no other threats. So check the size of this list
  361. # first and if populated use it.
  362. if (notification["rwrList"] != nil and size(notification.rwrList)>0)
  363. me.parent_obj.update(notification.rwrList, "normal");
  364. else if (notification["rwrList16"] != nil)
  365. me.parent_obj.update(notification.rwrList16, "link16");
  366. return emesary.Transmitter.ReceiptStatus_OK;
  367. }
  368. return emesary.Transmitter.ReceiptStatus_NotProcessed;
  369. };
  370. emesary.GlobalTransmitter.Register(rwr.recipient);
  371. return rwr;
  372. },
  373. update: func (list, type) {
  374. #printf("list %d", size(list));
  375. me.elapsed = getprop("sim/time/elapsed-sec");
  376. var sorter = func(a, b) {
  377. if(a[1] > b[1]){
  378. return -1; # A should before b in the returned vector
  379. }elsif(a[1] == b[1]){
  380. return 0; # A is equivalent to b
  381. }else{
  382. return 1; # A should after b in the returned vector
  383. }
  384. }
  385. me.sortedlist = sort(list, sorter);
  386. me.newList = [];
  387. me.i = 0;
  388. me.prio = 0;
  389. me.newsound = 0;
  390. me.unk = 0;
  391. foreach(me.contact; me.sortedlist) {
  392. me.typ=me.lookupType[me.contact[0].get_model()];
  393. if (me.i > me.max_icons-1) {
  394. break;
  395. }
  396. if (me.typ == nil) {
  397. if (me.contact[0].propNode.getName() != "multiplayer") {
  398. # AI planes are allowed to be unknowns
  399. me.typ = me.AIRCRAFT_UNKNOWN;
  400. me.unk = 1;
  401. } else {
  402. continue;
  403. }
  404. }
  405. #print("show "~me.i~" "~me.typ~" "~contact[0].get_model()~" "~contact[1]);
  406. me.threat = me.contact[1];#print(me.threat);
  407. if (me.threat > 0.5 and me.typ != me.AIRCRAFT_UNKNOWN and me.typ != me.ASSET_AI) {
  408. me.threat = me.inner_radius;# inner circle
  409. } elsif (me.threat > 0) {
  410. me.threat = me.outer_radius;# outer circle
  411. } else {
  412. continue;
  413. }
  414. if (me.contact[0].get_range() > 170) {
  415. continue;
  416. }
  417. me.dev = -geo.normdeg180(me.contact[0].get_bearing()-getprop("orientation/heading-deg"))+90;
  418. me.x = math.cos(me.dev*D2R)*me.threat;
  419. me.y = -math.sin(me.dev*D2R)*me.threat;
  420. me.texts[me.i].setTranslation(me.x,me.y);
  421. me.texts[me.i].setText(me.typ);
  422. me.texts[me.i].show();
  423. if (me.prio == 0 and me.typ != me.ASSET_AI and me.typ != me.AIRCRAFT_UNKNOWN) {#
  424. me.symbol_priority.setTranslation(me.x,me.y);
  425. me.symbol_priority.show();
  426. me.prio = 1;
  427. }
  428. if (!(me.typ == me.ASSET_GARGOYLE or me.typ == me.ASSET_BUK or me.typ == me.ASSET_PAC2 or me.typ == me.ASSET_FRIGATE) and me.contact[0].get_Speed()>60) {
  429. #air-borne
  430. me.symbol_hat[me.i].setTranslation(me.x,me.y);
  431. me.symbol_hat[me.i].show();
  432. } else {
  433. me.symbol_hat[me.i].hide();
  434. }
  435. if (me.contact[0].get_Callsign()==getprop("sound/rwr-launch") and 10*(me.elapsed-int(me.elapsed))>5) {#blink 2Hz
  436. me.symbol_launch[me.i].setTranslation(me.x,me.y);
  437. me.symbol_launch[me.i].show();
  438. } else {
  439. me.symbol_launch[me.i].hide();
  440. }
  441. me.popupNew = me.elapsed;
  442. foreach(me.old; me.shownList) {
  443. if(me.old[0].getUnique()==me.contact[0].getUnique()) {
  444. me.popupNew = me.old[1];
  445. break;
  446. }
  447. }
  448. if (me.popupNew == me.elapsed) {
  449. me.newsound = 1;
  450. }
  451. if (me.popupNew > me.elapsed-me.fadeTime) {
  452. me.symbol_new[me.i].setTranslation(me.x,me.y);
  453. me.symbol_new[me.i].show();
  454. me.symbol_new[me.i].update();
  455. } else {
  456. me.symbol_new[me.i].hide();
  457. }
  458. #printf("display %s %d",contact[0].get_Callsign(), me.threat);
  459. append(me.newList, [me.contact[0],me.popupNew]);
  460. me.i += 1;
  461. }
  462. me.shownList = me.newList;
  463. if (me.newsound == 1) setprop("sound/rwr-new", !getprop("sound/rwr-new"));
  464. for (;me.i<me.max_icons;me.i+=1) {
  465. me.texts[me.i].hide();
  466. me.symbol_hat[me.i].hide();
  467. me.symbol_new[me.i].hide();
  468. me.symbol_launch[me.i].hide();
  469. }
  470. if (me.prio == 0) {
  471. me.symbol_priority.hide();
  472. }
  473. setprop("sound/rwr-pri", me.prio);
  474. setprop("sound/rwr-unk", me.unk);
  475. },
  476. };
  477. var rwr = nil;
  478. var cv = nil;
  479. # var main_init_listener = setlistener("sim/signals/fdm-initialized", func {
  480. # if (getprop("sim/signals/fdm-initialized") == 1) {
  481. # var diam = 256;
  482. # cv = canvas.new({
  483. # "name": "Rwr",
  484. # "size": [diam,diam],
  485. # "view": [diam,diam],
  486. # "mipmapping": 1
  487. # });
  488. # # # cv.addPlacement({"node": "bkg", "texture":"rwr-bkg.png"});
  489. # cv.setColorBackground(0, 0.20, 0);
  490. # var root = cv.createGroup();
  491. # rwr = RWRCanvas.new(root, [diam/2,diam/2],diam);
  492. # removelistener(main_init_listener);
  493. # }
  494. # }, 0, 0);
  495. var openDialog = func(){
  496. return;
  497. var diam = 256;
  498. cv = canvas.new({
  499. "name": "Rwr",
  500. "size": [diam,diam],
  501. "view": [diam,diam],
  502. "mipmapping": 1
  503. });
  504. cv.setColorBackground(0, 0.20, 0);
  505. var root = cv.createGroup();
  506. rwr = RWRCanvas.new(root, [diam/2,diam/2],diam);
  507. var window = canvas.Window.new([256,256],"Rwr");
  508. window.setCanvas(cv);
  509. }
  510. var setGroup = func (root) {
  511. root.createChild("path").horiz(768).vert(576).horiz(-768).vert(-576).setColorFill(0,0,0).setColor(0,0,0);
  512. rwr = RWRCanvas.new("RWRCanvas",root, [768/2,576/2],576);
  513. };