fnc_jammersPFH.sqf 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. params["_args", "_handle"];
  2. _args params["_player"];
  3. _jammers = missionNamespace getVariable ["rd501_jammers",[]];
  4. // Exit if jammer list is empty, remove PFH and rely on someone else calling it via jammer placement
  5. if(!alive _player || count _jammers == 0) exitWith {
  6. _player setVariable ["rd501_jammers_pfh", -1];
  7. _player setVariable ["tf_receivingDistanceMultiplicator", 1];
  8. _player setVariable ["tf_sendingDistanceMultiplicator", 1];
  9. [_handle] call CBA_fnc_removePerFrameHandler;
  10. };
  11. // Aggregate the mean interference (multiple jammers allowed)
  12. private _interference = 1;
  13. {
  14. _x params["_jammer", "_radius", "_strength", "", "_active"];
  15. if(!_active || _jammer == objNull || !alive _jammer) then {
  16. diag_log format["Skipping inactive, dead or null jammer"];
  17. }
  18. else {
  19. private _distance = _player distance _jammer;
  20. if (_distance < _radius) then {
  21. private _d = _distance/_radius;
  22. private _specificSignal = 1/(1 + ((_d/(1 -_d)) ^ -2.3));
  23. private _specificInterference = _strength * (1 - _specificSignal);
  24. if(_interference == 1) then {
  25. _interference = _specificInterference;
  26. continue
  27. };
  28. _interference = _interference max _specificInterference;
  29. if(_interference < 1) then {
  30. _interference = 1; //prevent 0 from being final value
  31. };
  32. if(_interference > _strength) then {
  33. _interference = _strength; // prevent tfar from being exposed to 1.6e^24 when distance is null
  34. }
  35. };
  36. };
  37. } forEach _jammers;
  38. _interference = _interference * 0.625; // Rebalance value after testing, to prevent having to change it everywhere
  39. // Set interference locally
  40. _player setVariable ["tf_receivingDistanceMultiplicator", _interference];
  41. _player setVariable ["tf_sendingDistanceMultiplicator", 1/_interference];
  42. if([_player] call ACE_common_fnc_getName == "CI Mirror") then {
  43. systemChat format["Interference: %1", _interference];
  44. };