Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.40 KB | None | 0 0
  1. _vehicle = _this select 0;
  2.  
  3. private ["_crew"];
  4. _crew = player;
  5.  
  6. sleep 1;
  7.  
  8. disableSerialization;
  9.  
  10. if(getNumber(configFile >> "CfgVehicles" >> typeOf _vehicle >> "has_rwr") == 0) exitWith {};
  11.  
  12. //INIT
  13. private ["_type","_threats","_lastScan","_RWRopen","_MaxTargets","_scanInterval","_oldThreats"];
  14. _type = 0;
  15. _threats = [];
  16. _lastScan = [];
  17. _oldThreats = [];
  18. _RWRopen = false;
  19.  
  20.  
  21. // CUSTOMIZABLE PARAMETERS
  22. _maxTargets = 6; /* RWR maximum number of targets on-screen - 6 Primary 6 Secondary at a time, depending on its priority */
  23. _scanInterval0 = 0.5; //RWR scan interval in seconds
  24. _scanInterval = 0.5;
  25.  
  26. //INCOMING MISSILE EVENT HANDLER
  27. rwr_fireSource = objNull;
  28. private ["_incomingeh"];
  29. _incomingeh = _vehicle addEventHandler ["IncomingMissile", {rwr_fireSource = _this select 2}];
  30.  
  31. //DEFINE
  32. #define CTRL(A) ((uiNamespace getVariable "ACE_RWR_RU") displayCtrl A)
  33.  
  34. #define IDCRWRBASE 22000
  35. #define __IDC [22000,22001,22002,22003,22004,22005,22006,22007,22008,22009,22010,22011,22012,22013,22014,22015,22016,22017,22018,22019,22020,22021,22022,22023,22024,22025,22026,22027,22028,22029,22030,22031,22032,22033,22034,22035]
  36. #define __IDC_DIR [22000,22001,22002,22003,22004,22005,22006,22007,22008,22009,22010,22011,22012,22013,22014,22015,22028,22029,22030,22031]
  37.  
  38. #define SR5RWR_display_width 0.22
  39. #define SR5RWR_display_height 0.2934
  40.  
  41. // Primary threat direction array
  42. #define __PRIDIR [[IDCRWRBASE + 0,IDCRWRBASE + 1],[IDCRWRBASE + 2,IDCRWRBASE + 3],[IDCRWRBASE + 4,IDCRWRBASE + 5],[IDCRWRBASE + 6,IDCRWRBASE + 7],[IDCRWRBASE + 28,IDCRWRBASE + 29]]
  43. // Secondary threat direction array
  44. #define __SECDIR [[IDCRWRBASE + 8,IDCRWRBASE + 9],[IDCRWRBASE + 10,IDCRWRBASE + 11],[IDCRWRBASE + 12,IDCRWRBASE + 13],[IDCRWRBASE + 14,IDCRWRBASE + 15],[IDCRWRBASE + 30,IDCRWRBASE + 31]]
  45. // Primary threat types array
  46. #define __PRITYP [IDCRWRBASE + 16,IDCRWRBASE + 17,IDCRWRBASE + 18,IDCRWRBASE + 19,IDCRWRBASE + 20,IDCRWRBASE + 21]
  47. // Secondary threat type array
  48. #define __SECTYP [IDCRWRBASE + 22,IDCRWRBASE + 23,IDCRWRBASE + 24,IDCRWRBASE + 25,IDCRWRBASE + 26,IDCRWRBASE + 27]
  49. // Signal strength
  50. #define __SIGNAL IDCRWRBASE + 32
  51. // Launch
  52. #define __LAUNCH IDCRWRBASE + 33
  53. // Signal up
  54. #define __SIGNAL_UP IDCRWRBASE + 34
  55. // Signal down
  56. #define __SIGNAL_DOWN IDCRWRBASE + 35
  57. #define LSWTIME 4
  58.  
  59. #include "functions.hpp"
  60.  
  61. //BEGIN MAIN LOOP
  62. private ["_maxTargets","_threat","_invisibleThreats"];
  63. private ["_LOSorigin","_LOSend","_LOSh","_LOSdist","_LOSvector","_LOS","_posH","_posT","_viewAngleH","_viewAngleT"];
  64. private ["_AX","_AY","_AZ","_BX","_BY","_BZ","_HX","_HY","_HZ","_TX","_TY","_TZ"];
  65. private ["_dir_index","_type_index"];
  66. private ["_LWTIME"];
  67. private "_launcher";
  68.  
  69. _LWTIME = 0;
  70.  
  71. uiNamespace setVariable ["ACE_RWR_STATUS", true];
  72.  
  73. while { (_crew == driver _vehicle || {_crew == gunner _vehicle} || {_crew == commander _vehicle}) && {alive _vehicle} && (uiNamespace getVariable "ACE_RWR_STATUS")} do {
  74. //GATHER ALL NEARBY CARS AND TANKS
  75. private _nearStuff = vehicles select {_vehicle distance _x < ((getNumber (configFile >> "cfgVehicles" >> typeOf _x >> "rangerwrold")) * 0.8)};
  76. _nearStuff deleteAt (_nearStuff find _vehicle);
  77.  
  78. //SET NUMBER OF TARGETS
  79. _maxTargets = if (count _nearStuff < 6) then {count _nearStuff} else {6};
  80. if (count _nearStuff > 0) then {
  81. //ACQUIRE THREATS AND BUILD ARRAY
  82. for "_y" from 0 to (_maxTargets - 1) do {
  83. _threat = _nearStuff select _y;
  84. if (getNumber(configFile >> "CfgVehicles" >> typeOf _threat >> "radarType") == 4 && {_threat != _vehicle} && {({alive _x} count crew _threat > 0)} && {!(_threat in _threats)} && {!(_threat isKindOf "ParachuteBase")}) then {
  85. _threats set [count _threats, _threat];
  86. };
  87. };
  88.  
  89. //CHECK FOR RADIO VISIBILITY
  90. _invisibleThreats = [];
  91. for "_y" from 0 to (count _threats - 1) do {
  92. _threat = _threats select _y;
  93. _LOSorigin = getPosASL _vehicle;
  94. _LOSorigin set [2, (_LOSorigin select 2) + 0 ];
  95. _LOSend = getPosASL _threat;
  96. _LOSdist = _vehicle distance _threat;
  97. _posH = _vehicle worldToModel [_LOSend select 0, _LOSend select 1, (_LOSend select 2) + 0];
  98. _LOSvector = [(_posH select 0) / _LOSdist, (_posH select 1) / _LOSdist, (_posH select 2) / _LOSdist];
  99. _LOS = true;
  100. for [{_j = 20}, {(_j < (_LOSdist - 10)) && _LOS}, {_j = _j + 20}] do {
  101. _posH = [(_LOSorigin select 0) + (_LOSvector select 0) * _j, (_LOSorigin select 1) + (_LOSvector select 1) * _j, (_LOSorigin select 2) + (_LOSvector select 2) * _j];
  102. _posT = [_posH select 0, _posH select 1, getTerrainHeightASL [_posH select 0, _posH select 1]];
  103.  
  104. _AX = _LOSorigin select 0; _AY = _LOSorigin select 1; _AZ = _LOSorigin select 2;
  105. _HX = _posH select 0; _HY = _posH select 1; _HZ = _posH select 2;
  106. _TX = _posT select 0; _TY = _posT select 1; _TZ = _posT select 2;
  107.  
  108. _LOSdistH = (getPos _vehicle) distance _posH;
  109. _LOSdistT = (getPos _vehicle) distance _posT;
  110.  
  111. //TRACE_4("",_posH,_posT,_AZ,_TZ);
  112. _tt = if (_AZ - _HZ == 0) then {0.0001} else {_AZ - _HZ};
  113. _viewAngleH = atan(_LOSdistH / _tt);
  114. if (_viewAngleH < 0) then { _viewAngleH = 360 + _viewAngleH };
  115. _tt = if (_AZ - _TZ == 0) then {0.0001} else {_AZ - _TZ};
  116. _viewAngleT = atan(_LOSdistT / _tt);
  117. if (_viewAngleT < 0) then { _viewAngleT = 360 + _viewAngleT };
  118.  
  119. if (_viewAngleH < _viewAngleT) then { _LOS = false };
  120. };
  121. if (!_LOS && {!(_threat in _invisibleThreats)}) then { _invisibleThreats set [count _invisibleThreats, _threat] };
  122. };
  123.  
  124. if ((count (_threats - _invisibleThreats) > 0) && {({alive _x} count crew _threat > 0)}) then {
  125. if !(_RWRopen) then {
  126. 135737 cutRsc ["ACE_RWR_RU","PLAIN"];
  127. _RWRopen = true;
  128. // INITIATE RWR15
  129. call clearAllControls;
  130. };
  131.  
  132. for "_y" from 0 to (count _threats - 1) do {
  133. _threat = _threats select _y;
  134.  
  135. // PRIORITIY TYPES
  136. /* On Primary threat:
  137. - Big direction indicator lamps light up
  138. - Small direction indicator lamps light up
  139. - Big type indicator lamp lights up
  140. - Small type indicator lamp lights up
  141.  
  142. On Secondary threat:
  143. - Small direction indicator lamps light up
  144. - Small type indicator lamp lights up
  145.  
  146. Maximum 6 primary threats can be displayed
  147. N, 3, X, H, F, C = All Big type indicator lamps light up && All Small type indicator lamps light up
  148.  
  149. Maximum 6 secondary threats can be displayed
  150. All small type indicator lamps light up */
  151.  
  152. /* Aircraft is always a primary threat! */
  153. _type = if (_threat isKindOf "Plane") then { "PRIMARY" } else { "SECONDARY" };
  154.  
  155. /* If there is only one threat available, it becomes the primary threat - even if it is a secondary class threat */
  156. if (count _threats == 1) then { _type = "PRIMARY" };
  157. /* Once there is a primary class threat detected, priority switches back again */
  158. //if (_type == "PRIMARY") then { _vehicle setVariable [QGVAR(primary_threat),_threat]; };
  159.  
  160. // GET DIRECTION TOWARDS OWN AIRCRAFT
  161. if (_threat in _threats && {!(_threat in _invisibleThreats)}) then {
  162. //GET VECTOR POSITIONS
  163. _p1 = getPos _vehicle;
  164. _p2 = getPos _threat;
  165. _AX = _p1 select 0;
  166. _BX = _p2 select 0;
  167. _AY = _p1 select 1;
  168. _BY = _p2 select 1;
  169.  
  170. _dir = (_BX - _AX) atan2 (_BY - _AY); // 180 to -180 degree
  171. // RELATIVE TO VEHICLE
  172. _dir = _dir - getDir _vehicle;
  173. if (_dir < 0) then { _dir = 360 + _dir; };
  174. if (_dir > 180) then { _dir = _dir - 360; };
  175. _dir = round _dir;
  176.  
  177. // GET DIRECTION
  178. switch (true) do {
  179. // LEFT
  180. // 10
  181. case (_dir < 0 && {_dir >= -10}) : { _dir_index = [[0,0]]; };
  182. // 10 + 30
  183. case (_dir < -10 && {_dir > -30}) : { _dir_index = [[0,0],[1,0]]; };
  184. // 30
  185. case (_dir == -30) : { _dir_index = [[1,0]]; };
  186. // 30 + 50
  187. case (_dir < -30 && {_dir > -50}) : { _dir_index = [[1,0],[2,0]]; };
  188. // 50
  189. case (_dir == -50) : { _dir_index = [[2,0]]; };
  190. // 50 + 90
  191. case (_dir < -50 && {_dir > -90}) : { _dir_index = [[2,0],[3,0]]; };
  192. // 90
  193. case (_dir == -90) : { _dir_index = [[3,0]]; };
  194. // > 90
  195. case (_dir < -90) : { _dir_index = [[4,0]]; };
  196.  
  197. // RIGHT
  198. // 10
  199. case (_dir > 0 && {_dir <= 10}) : { _dir_index = [[0,1]]; };
  200. // 10 + 30
  201. case (_dir > 10 && {_dir < 30}) : { _dir_index = [[0,1],[1,1]]; };
  202. // 30
  203. case (_dir == 30) : { _dir_index = [[1,1]]; };
  204. // 30 + 50
  205. case (_dir > 30 && {_dir < 50}) : { _dir_index = [[1,1],[2,1]]; };
  206. // 50
  207. case (_dir == 50) : { _dir_index = [[2,1]]; };
  208. // 50 + 90
  209. case (_dir > 50 && {_dir < 90}) : { _dir_index = [[2,1],[3,1]]; };
  210. // 90
  211. case (_dir == 90) : { _dir_index = [[3,1]]; };
  212. // > 90
  213. case (_dir > 90) : { _dir_index = [[4,1]];};
  214. };
  215.  
  216. //DISPLAY THREAT ON RWR UI
  217. _type_index = 0;/*getNumber(configFile >> "CfgVehicles" >> typeOf _threat >> "threat_img_spo");*/
  218.  
  219. //NEW THREAT
  220. if !(_threat in _lastScan) then {
  221. _lastScan set [count _lastScan, _threat];
  222. };
  223. // THREAT TYPE DISPLAY
  224. if(_threat isKindOf "Tank")then{
  225. _type_index = 3;
  226. };
  227. if(_threat isKindOf "Air")then{
  228. _type_index = 0;
  229. };
  230. if(_threat isKindOf "min_rf_sa_22")then{
  231. _type_index = 3;
  232. };
  233. if(_threat isKindOf "min_rf_sa_22_desert")then{
  234. _type_index = 3;
  235. };
  236. [_type,_type_index,true] call showThreatTypes;
  237.  
  238. // THREAT DIRECTION DISPLAY
  239. [_type,_dir_index,true] call showThreatDirection;
  240.  
  241. // SIGNAL STRENGTH PRIMARY
  242. [_type,_threat,_vehicle] call displaySignalStrength;
  243.  
  244. // SIGNAL LOCK WARNING
  245. [_type,_threat,_vehicle] call displayLockWarning;
  246.  
  247. /*// RHS MI-24 RWR
  248. if(_vehicle isKindOf "RHS_Mi24_base")then{
  249. [_type,_vehicle,_threat,_dir] call displayMiRwr;
  250. };*/
  251.  
  252.  
  253. //LAUNCH
  254. if (_threat == rwr_fireSource) then {
  255. _launched = _vehicle getVariable ["LaunchWarning",false];
  256. if (!_launched) then {
  257. _vehicle setVariable ["LaunchWarning",true];
  258. [_vehicle] call displayLaunchWarning;
  259. rwr_fireSource = objNull;
  260. };
  261. } else {
  262. _vehicle setVariable ["LaunchWarning",false];
  263. };
  264. sleep _scanInterval0;
  265. } else {
  266. //THREAT IS ACTIVE BUT OUT OF RANGE
  267. if (_threat in _lastScan) then {_lastScan = _lastScan - [_threat] };
  268. if (_threat == rwr_fireSource) then { rwr_fireSource = objNull };
  269. if (_RWRopen && {count (_threats - _invisibleThreats) <= 0}) then {
  270. 135737 cutRsc ["Default","PLAIN"];
  271. _vehicle setVariable ["LaunchWarning",false];
  272. _RWRopen = false;
  273. };
  274. // RESET
  275. [_type,_type_index,false] call showThreatTypes;
  276. }; //END IF (_vehicle distance _threat > (getNumber (configFile >> "cfgVehicles" >> typeOf _threat >> "rangerwrold")))
  277. }; //END for (threats)
  278. } else {
  279. //NO THREATS
  280. _lastScan = [];
  281. 135737 cutRsc ["Default","PLAIN"];
  282. _RWRopen = false;
  283. _vehicle setVariable ["LaunchWarning",false];
  284. rwr_fireSource = objNull;
  285. }; //END if (count _threats > 0)
  286. }else {
  287. //NO THREATS
  288. _lastScan = [];
  289. 135737 cutRsc ["Default","PLAIN"];
  290. _RWRopen = false;
  291. _vehicle setVariable ["LaunchWarning",false];
  292. rwr_fireSource = objNull;
  293. }; //END if (count _nearStuff > 0)
  294. sleep _scanInterval;
  295. //CLEANING
  296. _rmthreats = [];
  297. for "_y" from 0 to (count _threats - 1) do {
  298. _threat = _threats select _y;
  299. if (damage _threat > 0.9 && {_threat in _threats}) then { //THREAT DESTROYED
  300. _rmthreats set [count _rmthreats, _threat];
  301. };
  302. if (_threat distance _vehicle > ((getNumber (configFile >> "cfgVehicles" >> typeOf _threat >> "rangerwrold")) * 0.8)) then { //THREAT OUT OF RANGE
  303. _rmthreats set [count _rmthreats, _threat];
  304. };
  305. };
  306. if (count _rmthreats > 0) then {
  307. _threats = _threats - _rmthreats;
  308. _oldThreats = _oldThreats - _rmthreats;
  309. _lastScan = _lastScan - _rmthreats;
  310. _threats = _threats - [objNull];
  311. _oldThreats = _oldThreats - [objNull];
  312. _lastScan = _lastScan - [objNull];
  313. };
  314. if ((_RWRopen) && (time - _LWTIME >= LSWTIME)) then {
  315. _LWTIME = time;
  316. playSound ["ACE_RWR15_TRACK",true];
  317. };
  318. }; //END While Main Loop
  319.  
  320. 135737 cutRsc ["Default","PLAIN"];
  321. _vehicle setVariable ["LaunchWarning", false];
  322. _vehicle removeEventHandler ["IncomingMissile", _incomingeh];
  323. //[_crew, 1, ["ACE_SelfActions", "spo_15"]] call ace_interact_menu_fnc_removeActionFromObject;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement