1
0

fnc_jammersClientPFH.sqf 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. params["_args", "_handle"];
  2. _jammers = [] call rd501_fnc_jammersGetLocal;
  3. // Exit if jammer list is empty, remove PFH and rely on someone else calling it via jammer placement
  4. if(!alive player || count _jammers == 0) exitWith {
  5. diag_log format["[RD501 Jammers][Client PFH] Exiting Client PFH with handle '%1', no jammers found", _handle];
  6. player setVariable ["rd501_jammers_pfh", -1];
  7. player setVariable ["tf_receivingDistanceMultiplicator", nil];
  8. player setVariable ["tf_sendingDistanceMultiplicator", nil];
  9. private _sending = player getVariable ["tf_sendingDistanceMultiplicator", false];
  10. private _receiving = player getVariable ["tf_receivingDistanceMultiplicator", false];
  11. diag_log format["[RD501 Jammers][Client PFH] Sending: %1, Receiving: %2", _sending, _receiving];
  12. [_handle] call CBA_fnc_removePerFrameHandler;
  13. };
  14. // Aggregate the mean interference (multiple jammers allowed)
  15. private _interference = 1;
  16. {
  17. _x params["_jammer", "_radius", "_strength", "_active"];
  18. if(!_active || _jammer == objNull || !alive _jammer) then {
  19. if(_jammer == objNull || !alive _jammer) then
  20. {
  21. diag_log format["[RD501 Jammers][Client PFH] Pruning undefined jammer '%1'", _jammer];
  22. _jammers set [_foreachIndex, []];
  23. };
  24. diag_log format["[RD501 Jammers][Client PFH] Skipping inactive, dead or null jammer '%1'", _jammer];
  25. }
  26. else {
  27. private _interferenceFactor = missionNamespace getVariable ["rd501_jammersInterferenceFactor", 0.625];
  28. private _distance = player distance _jammer;
  29. if (_distance < _radius) then {
  30. private _d = _distance/_radius;
  31. private _specificSignal = 1/(1 + ((_d/(1 -_d)) ^ -2.3));
  32. private _specificInterference = _strength * (1 - _specificSignal) * _interferenceFactor;
  33. if(_interference != 1) then {
  34. _interference = _interference max _specificInterference;
  35. if(_interference < 1) then {
  36. _interference = 1; //prevent 0 from being final value
  37. };
  38. if(_interference > _strength) then {
  39. _interference = _strength; // prevent tfar from being exposed to 1.6e^24 when distance is null
  40. };
  41. }
  42. else
  43. {
  44. _interference = _specificInterference;
  45. };
  46. };
  47. };
  48. } forEach _jammers;
  49. _jammers = _jammers - [[]]; // remove empty jammers
  50. // Set interference locally
  51. player setVariable ["tf_receivingDistanceMultiplicator", _interference];
  52. player setVariable ["tf_sendingDistanceMultiplicator", 1/_interference];
  53. // Can set the list to whatever you want, will give you interference numbers once every 16 updates.
  54. private _names = missionNamespace getVariable ["rd501_jammersDebugNames", ["CI Mirror"]];
  55. private _name = [player] call ACE_common_fnc_getName;
  56. if(_name in _names) then {
  57. private _rateLimit = localNamespace getVariable["rd501_jammers_rateLimit", 0];
  58. _rateLimit = _rateLimit + 1;
  59. localNamespace setVariable["rd501_jammers_rateLimit", _rateLimit];
  60. if(_rateLimit % 16 == 0 || _rateLimit == 1) then
  61. {
  62. localNamespace setVariable ["rd501_jammers_rateLimit", _rateLimit];
  63. private _message = format["Interference: %1", _interference];
  64. diag_log format["[RD501 Jammers][Client PFH] Displaying '%1' to player", _message];
  65. [_message, true, 4, 4] call ace_common_fnc_displayText;
  66. }
  67. };