Browse Source

Initial work on jammer

m3ales 4 years ago
parent
commit
62c88337a5

+ 4 - 0
addons - Copy/RD501_Main/functions/jammer/fnc_addJammer.sqf

@@ -0,0 +1,4 @@
+params["_jammer", ["_strength", 400], ["_radius", 500]];
+_jipId = ["rd501_addJammerLocal", [_jammer, _radius, _strength]] call CBA_fnc_globalEventJIP;
+_jammer setVariable ["rd501_jammer_jipId", _jipId, true];
+[{ _this call rd501_jammersServerPFH }, 1, [_jammer,_radius,_strength]] call CBA_fnc_addPerFrameHandler;

+ 8 - 0
addons - Copy/RD501_Main/functions/jammer/fnc_addJammerLocal.sqf

@@ -0,0 +1,8 @@
+if(isDedicated || !hasInterface) exitWith { };
+
+if(player getVariable ["rd501_jammers_pfh", -1] == -1) exitWith {
+	private _handler = [{
+			_this call rd501_fnc_jammersPFH;
+		}, 0.5, [player]] call CBA_fnc_addPerFrameHandler;
+	player setVariable ["rd501_jammers_pfh", _handler];
+};

+ 37 - 0
addons - Copy/RD501_Main/functions/jammer/fnc_jammersPFH.sqf

@@ -0,0 +1,37 @@
+params["_args", "_handle"];
+_args params["_player"];
+/*
+*	_jammers = [
+*		[_jammer, _radius, _strength],
+*		["bis_o1", 1000, 400]
+*	];
+*/
+if(!alive _player) exitWith { systemChat format["Player dead for %1", _handle] };
+
+_jammers = missionNamespace getVariable ["rd501_jammers",[]];
+
+// Exit if jammer list is empty, remove PFH and rely on someone else calling it via jammer placement
+if(count _jammers == 0) exitWith {
+	[_handle] call CBA_fnc_removePerFrameHandler;
+	_player setVariable ["rd501_jammers_pfh", -1];
+	_player setVariable ["tf_receivingDistanceMultiplicator", 1];
+	_player setVariable ["tf_transmittingDistanceMultiplicator", 1];
+};
+
+// Aggregate the mean interference (multiple jammers allowed)
+private _interference = 1;
+{
+	_x params["_jammer", "_radius", "_strength"];
+	private _distance = _player distance _jammer;
+	if (_distance >= _radius) then { continue };
+	private _specificInterference = _strength - ((_distance/_radius) * _strength) + 1;
+	if(_interference == 1) then {
+		_interference = _specificInterference;
+		continue
+	};
+	_interference = (_interference + _specificInterference)/2; // Average of interference plus current
+} forEach _jammers;
+
+// Set interference locally
+_player setVariable ["tf_receivingDistanceMultiplicator", _interference];
+_player setVariable ["tf_transmittingDistanceMultiplicator", _interference];

+ 26 - 0
addons - Copy/RD501_Main/functions/jammer/fnc_jammersServerPFH.sqf

@@ -0,0 +1,26 @@
+params["_args", "_handle"];
+
+if(!isServer) exitWith {
+	[_handle] call CBA_fnc_removePerFrameHandler;
+};
+
+_jammers = missionNamespace getVariable ["rd501_jammers",[]];
+
+_toRemoveIndexes = [];
+{
+	_x params["_jammer", "_radius", "_strength"];
+	_jipId = _jammer getVariable ["rd501_jammer_jipId", -1];
+	if!(alive _jammer) then { _toRemoveIndexes append [[_foreachIndex, _jipId]]};
+} forEach _jammers;
+
+{
+	_x params["_index", "_jipId"];
+	_jammers deleteAt _index;
+	[_jipId] call CBA_fnc_removeGlobalEventJIP;
+} forEach _toRemoveIndexes;
+
+missionNamespace setVariable ["rd501_jammers", _jammers, true];
+
+if(count _jammers == 0) exitWith {
+	[_handle] call CBA_fnc_removePerFrameHandler;
+};