Advertisement
Gamenator

Pook incoming.sqf attempt to fix

Nov 18th, 2023
1,298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 11.89 KB | None | 0 0
  1. /************************************************************
  2.  
  3. RWR and spoofing script: Based on Franze's Su-17/22 RWR script!
  4.  
  5. Updated by HCPOOKIE to work with:
  6.  - POOK_EF2000
  7.  - POOK Soviet AF
  8.  - VME_PLA Vehicles
  9.  - Fuller's USAF mod
  10.  - Other mods can employ this script as well.
  11.  
  12. Please credit appropriately.
  13.  
  14. ///////////////////////////////////
  15. * This is the POOK_SovAF version!!!
  16. ///////////////////////////////////
  17.  
  18. USAGE:
  19.  - Action-based script to attempt to spoof incoming missiles
  20. `
  21.  - Relies on two other functions which must be loaded on INIT:
  22. EF2K_pitchbank = compile preprocessFileLineNumbers "\mod\scripts\fsetpitch.sqf";
  23. EF2K_getpb = compile preprocessFileLineNumbers "\mod\scripts\frotate.sqf";
  24.  
  25.  - Checks for certain jammer pods on plane; if none, checks
  26.    if plane is of certain types that contain on-board jamming
  27.    equipment; if neither, revert to default action
  28.  
  29.  - Reads missile attributes to determine if the following
  30.    POOK_SAM pack values are present, and modify behavior
  31.    accordingly (see POOK_SAM pack documentation for more info):
  32.    - POOK_HOJ
  33.    - POOK_Band
  34.    - POOK_HOP
  35.  
  36.  - Missiles have chance to burn-through jamming, making results
  37.    semi-random.  Pilots should plan to adjust flight to dodge
  38.    missiles, and employ standard countermeasures while jamming.
  39.  
  40.  - Script also provides RWR notification to pilot and animates
  41.    on-board RWR cockpit indicators if so equipped.
  42.  
  43.  - Pilot also receives vehicle chat notifications regardless
  44.    if the plane has an animated RWR system.
  45.  
  46. ************************************************************/
  47.  
  48. private ["_v","_amm","_aTyp","_shooter","_theta","_p","_pMsl","_rng",
  49. "_ico","_msl","_dev","_VXmis","_VYmis","_HOJ","_HOP","_B",
  50. "_pbvar","_pitch","_bank","_typ","_ECM","_I","_Ip","_Q","_icT"];
  51.  
  52. _v = _this select 0; // incomingMissile EH: unit: Object - Object the event handler is assigned to
  53. _amm = _this select 1; // incomingMissile EH: ammo: String - Ammo type that was fired on the unit
  54. _shooter = _this select 2; // incomingMissile EH: whoFired: Object - Object that fired the weapon
  55. _theta = 0;
  56. _ECM = false;
  57. _p = getpos _v;
  58. _msl = nearestobject [_shooter,_amm]; // EH select 2, EH select 1
  59. _pMsl = getpos _msl;
  60. _rng = _pMsl distance _p;
  61.  
  62. /*********** RWR alarm sound and master caution lamps *********************************************************/
  63. _v animate ['missile_launch_ind',0];
  64. _v animate ['master_caution_ind',0];
  65.  
  66.  
  67. /*********** Check for pod and/or plane class that contains internal jamming systems Pook_SOV_BB**************************/
  68. _I = [_v] call pook_SOV_FNC_tCheck;
  69. _Ip = [_v] call pook_SOV_FNC_pCheck;
  70.  
  71. // if either checks are TRUE then full ECM can activate
  72. if ((_I) || (_Ip)) then {
  73.     _ECM = true;
  74. };
  75.  
  76. /*********** Get pook_SAM missile data values if present *****************************************************/
  77. _aTyp = toUpper (_amm);
  78. _HOJ = [(configFile >> "cfgAmmo" >> _aTyp),"pook_HOJ",2] call BIS_fnc_returnConfigEntry;
  79. _B = [(configFile >> "cfgAmmo" >> _aTyp),"pook_Band",2] call BIS_fnc_returnConfigEntry;
  80. _HOP = [(configFile >> "cfgAmmo" >> _aTyp),"pook_HOP",2] call BIS_fnc_returnConfigEntry;
  81.  
  82. /*********** JAMMING OFFSET *******************************
  83.  
  84. _dev = Baseline offset value.
  85. Determines amount of missile deflection during jam loop
  86.  
  87. Larger = more deviation
  88.  
  89. Also used to calculate missile burn-through rate, as
  90. a product of "distance * _chance".
  91.  
  92. 0.0005 base value for vanilla and undocumented missiles
  93.  
  94. **********************************************************/
  95.  
  96. switch (_B) do {
  97. /*
  98. 0.00035 = extreme wiggle in path
  99. 0.000275 = median spoofing
  100.  
  101.     case "C":{_dev = 0.0005;}; // SA2; (also MIM23 search)
  102.     case "J":{_dev = 0.00025;}; // SA19
  103.     case "X":{_dev = 0.000275;}; // typical
  104.     case "G":{_dev = 0.0001;}; // MIM104, SA15
  105. */
  106.     case "C":{if (_ECM) then {_dev = 0.000325;} else {_dev = 0.0003;};}; // SA2; (also MIM23 search)
  107.     case "J":{if (_ECM) then {_dev = 0.0003125;} else {_dev = 0.000275;};}; // SA8, SA19
  108.     case "X":{if (_ECM) then {_dev = 0.0003;} else {_dev = 0.00025;};}; // typical: SA3,SA10,SA11,SA17,SA20,SA21,SA22,NAS,MIM23
  109.     case "G":{if (_ECM) then {_dev = 0.000125;} else {_dev = 0.0001;};}; // MIM104, SA15
  110.  
  111. // following are search radars, and not directly involved in jamming actions
  112.     case "A":{_dev = 0.0001;}; // SA2 search; SA3 search
  113.     case "H":{_dev = 0.0001;}; // SA11/SA17 search
  114.     case "S":{_dev = 0.0001;}; // SA-22 search
  115.     case "E":{_dev = 0.0001;}; // SA-19 search
  116.     case "L":{_dev = 0.0001;}; // SA-21 search
  117.  
  118.     case "I":{_dev = 0.00001;}; // Infra-red (IR)
  119.  
  120.     default {_dev = 0.0005;}; // undocumented missiles (vanilla, etc)
  121. };
  122.  
  123. /** animate RWR "TYPE" warning light (Russian type) ************************************************************/
  124. /**
  125. if (_shooter isKindOf "Air") then {
  126.     _v setobjecttexture [87,"\fza_su17\su17_rwrlights.paa"];
  127. };
  128. if (_shooter isKindOf "Land" and _rng > 20000) then {
  129.     _v setobjecttexture [90,"\fza_su17\su17_rwrlights.paa"];
  130. };
  131. if (_shooter isKindOf "Land" and _rng > 10000 and _rng < 20000) then {
  132.     _v setobjecttexture [91,"\fza_su17\su17_rwrlights.paa"];
  133. };
  134. if (_shooter isKindOf "Land" and _rng < 10000) then {
  135.     _v setobjecttexture [92,"\fza_su17\su17_rwrlights.paa"];
  136. };
  137. **/
  138.  
  139. /** animate RWR "TYPE" warning light (NATO type) ***************************************************************/
  140. _icT = [_aTyp] call pook_SOV_FNC_aTyp;
  141. //_typ = ([_aTyp] call pook_SOV_FNC_aTyp) select 1;
  142. _ico = _icT select 0;
  143. _typ = _icT select 1;
  144.  
  145. while {(alive _msl)} do {
  146. private ["_pP","_pM","_rng","_qd","_reldir","_oc","_ocF","_ocN","_highlow"];
  147.  
  148. _pP = getpos _v;
  149. _pM = getpos _msl;
  150. _rng = _pM distance _pP;
  151.  
  152. };
  153.  
  154. private["_highlow","_pP","_pM"];
  155. /** missile HEIGHT check - is it "high" or "low" ***************************************************************/
  156. if (_pP select 2 > _pM select 2) then {
  157.     _highlow = "Low";
  158. } else {
  159.     _highlow = "High";
  160. };
  161.  
  162.  
  163.  
  164. /** calculate incoming DIRECTION  ***************************************************************/
  165. _reldir = ((_pM select 0) - (_pP select 0)) atan2 ((_pM select 1) - (_pP select 1));
  166. if (_reldir < 0) then {
  167.     _reldir = _reldir + 360;
  168. };
  169.  
  170. _Theta = [_reldir,_v] call pook_SOV_FNC_Theta;
  171. _oc = _Theta select 0;
  172. _ocF = _Theta select 1;
  173. _ocN = _Theta select 2;
  174. _qd = _Theta select 3;
  175.  
  176.  
  177. _v vehiclechat format ["%4 Missile %1 OClock %2 %3 Meters",_oc,_highlow,_rng,_typ];
  178.  
  179. /** animate RWR warn flash *************************************************************
  180.  
  181. _v setObjectTexture [_qd,"\pook_EF2000\data\cockpit\mfd3_ca.paa"]; // red on
  182. sleep 0.25;
  183. _v setObjectTexture [_qd,""]; // red off
  184. sleep 0.25;
  185. _v setObjectTexture [_qd,"\pook_EF2000\data\cockpit\mfd3_ca.paa"]; // red on
  186. sleep 0.25;
  187. _v setObjectTexture [_qd,""]; // red off
  188. sleep 0.25;
  189. _v setObjectTexture [_qd,"\pook_EF2000\data\cockpit\mfd3_ca.paa"]; // red on
  190. sleep 0.25;
  191. _v setObjectTexture [_qd,""]; // red off
  192.  
  193. **/
  194. /** RWR incoming ident *************************************************************
  195. if (_rng > 1500) then {
  196.     if (_rng > 5000) then {
  197.         _v setObjectTexture [_ocF, _ico]; // far
  198.     } else {
  199.         _v setObjectTexture [_ocN, _ico]; // near
  200.     };
  201. } else {
  202.     _v setObjectTexture [35, _ico]; // close
  203. };
  204.  
  205. **/
  206. /** "has passed" check - cancel ECM if true ***************************************************************/
  207. private ["_ps"];
  208. _ps = _msl distance _v;
  209. sleep 1;
  210. if ((_msl distance _v) > _ps) exitWith {};
  211.  
  212.  
  213. ///////////////////////////////////////////////////////////////////  begin spoofing section
  214.  
  215. _VXmis = vectorup _msl;
  216. _VYmis = vectordir _msl;
  217.  
  218.  
  219. /*
  220. // Freq - FUTURE: Set jammer to different modes/Freq
  221. // If false it halves the amount of deflection. Missile flight model
  222. // may still allow missile to overcome ECM with this active
  223.  
  224. if !(_B == 1) then {
  225. //  _Freq = _v getVariable "ECM_Freq";
  226.     if (_Freq in jammerarray) then {
  227.         _jam = active
  228.     };
  229.     _dev = _dev * 0.0025;
  230. };
  231. */
  232.  
  233. if (_ECM) then {
  234.  
  235.     while {(alive _msl) && (alive _v)} do {
  236.     // Distance calculation for spoof percentage increase as distance to target decreases
  237.     // Simulates the "burn-through" capability of missile's on-board radar
  238.     // examples:
  239.     //      X-band @ 2000m = 0.75% / 4000m = 1.50%
  240.     //      G-band @ 2000m = 1.00% / 4000m = 2.00%
  241.     //      C-band @ 2000m = 0.20% / 4000m = 0.40%
  242.         _distance = _v distance _msl; // closing distance in M
  243.         _burnThrough = _dev * _distance;
  244. //  hint format ["Burnthrough: %1, Distance: %2, curvupmis: %3, curvdirmis: %4",_burnThrough,_distance,_VXmis,_VYmis];
  245.  
  246.     // Frequency Hop check: Increased chance for ECM to fail
  247.     // (by pausing ECM actions) if missile can frequency hop
  248.     // The pause stacks on the HOJ pause, if > 0
  249.         if (_HOP == 1) then {
  250.             sleep (sqrt(floor(random _burnThrough)*0.1)*((sqrt _distance)*0.1));
  251.         };
  252.  
  253.         if (_distance < 4000) then {
  254.         // Home-On-Jam check: Increased chance for ECM to fail
  255.         // (by adding ECM pauses) if missile can Home-On-Jam
  256.             if (_HOJ == 1) then {
  257.                 sleep (floor(random 0.125)+((sqrt _distance)*0.1));
  258.             };
  259.  
  260.         };
  261.     // FUTURE: Adjust pitch/bank vector amounts based on _burnThrough
  262.         _msl setvectorup _VXmis;
  263.         _msl setvectordir _VYmis;
  264.  
  265.         _pbvar = _msl call EF2K_RWR_getpb; // frotate.sqf
  266.         _pitch = _pbvar select 0; // PITCH
  267.         _bank = _pbvar select 1;  // BANK
  268.         _bank = _bank - _dev;
  269.         _pitch = _pitch - _dev;
  270.         [_msl, _pitch, _bank] call EF2K_RWR_pitchbank; // fsetpitch.sqf
  271.  
  272.     // find missile vector up and vector dir for next loop
  273.         _VXmis = vectorup _msl;
  274.         _VYmis = vectordir _msl;
  275.     // 0.25 = spoof never successful
  276.         // closer to target, shorter sleep loops (more active scanner)
  277.         // This means more attempts to counter ECM, and the greater
  278.         // the chance for missile to succeed vs. ECM
  279.         sleep _burnThrough;
  280.  
  281.     };
  282.  
  283. } else {
  284.     _v forceWeaponFire ["CMFlareLauncher","Burst"];
  285. };
  286.  
  287. ///////////////////////////////////////////////////////////////////  end spoofing section
  288.  
  289. /** Reset RWR icons for THIS LOOP ***************************************************************/
  290. /**
  291. sleep 1;
  292. _v setObjectTexture [15,""];
  293. _v setObjectTexture [16,""];
  294. _v setObjectTexture [17,""];
  295. _v setObjectTexture [18,""];
  296. _v setObjectTexture [19,""];
  297. _v setObjectTexture [20,""];
  298. _v setObjectTexture [21,""];
  299. _v setObjectTexture [22,""];
  300. _v setObjectTexture [23,""];
  301. _v setObjectTexture [24,""];
  302. _v setObjectTexture [25,""];
  303. _v setObjectTexture [26,""];
  304. _v setObjectTexture [27,""];
  305. _v setObjectTexture [28,""];
  306. _v setObjectTexture [29,""];
  307. _v setObjectTexture [30,""];
  308. _v setObjectTexture [31,""];
  309. _v setObjectTexture [32,""];
  310. _v setObjectTexture [33,""];
  311. _v setObjectTexture [34,""];
  312. _v setObjectTexture [35,""];
  313.  
  314. }; // WHILE ALIVE MISSILE LOOP
  315. **/
  316.  
  317. /** CLEAN-UP: RESET COCKPIT WARN LIGHTS and RWR ***************************************************************/
  318.  
  319. _v animate ['missile_launch_ind',1];
  320. _v animate ['master_caution_ind',1];
  321. /**
  322. _v setObjectTexture [7,"\pook_EF2000\data\cockpit\mfd2_ca.paa"];
  323. _v setObjectTexture [8,"\pook_EF2000\data\cockpit\mfd2_ca.paa"];
  324. _v setObjectTexture [9,"\pook_EF2000\data\cockpit\mfd2_ca.paa"];
  325. _v setObjectTexture [10,"\pook_EF2000\data\cockpit\mfd2_ca.paa"];
  326. _v setObjectTexture [11,"\pook_EF2000\data\cockpit\mfd2_ca.paa"];
  327. _v setObjectTexture [12,"\pook_EF2000\data\cockpit\mfd2_ca.paa"];
  328. _v setObjectTexture [13,"\pook_EF2000\data\cockpit\mfd2_ca.paa"];
  329. _v setObjectTexture [14,"\pook_EF2000\data\cockpit\mfd2_ca.paa"];
  330.  
  331. _v setObjectTexture [15,""];
  332. _v setObjectTexture [16,""];
  333. _v setObjectTexture [17,""];
  334. _v setObjectTexture [18,""];
  335. _v setObjectTexture [19,""];
  336. _v setObjectTexture [20,""];
  337. _v setObjectTexture [21,""];
  338. _v setObjectTexture [22,""];
  339. _v setObjectTexture [23,""];
  340. _v setObjectTexture [24,""];
  341. _v setObjectTexture [25,""];
  342. _v setObjectTexture [26,""];
  343. _v setObjectTexture [27,""];
  344. _v setObjectTexture [28,""];
  345. _v setObjectTexture [29,""];
  346. _v setObjectTexture [30,""];
  347. _v setObjectTexture [31,""];
  348. _v setObjectTexture [32,""];
  349. _v setObjectTexture [33,""];
  350. _v setObjectTexture [34,""];
  351. _v setObjectTexture [35,""];
  352.  
  353. **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement