Ver Fonte

Fix jammer range, fix jammers cleanup pfh

m3ales há 4 anos atrás
pai
commit
ad9fb96401

+ 33 - 30
addons - Copy/RD501_Main/functions/jammer/fnc_jammersPFH.sqf

@@ -20,40 +20,43 @@ if(count _jammers == 0) exitWith {
 };
 
 // Aggregate the mean interference (multiple jammers allowed)
-private _interference = 1;
+private _signalStrength = 1;
 {
 	_x params["_jammer", "_radius"];
 	private _distance = _player distance _jammer;
-	if (_distance >= _radius) then { continue };
-	//cubic bezier curve
-	// private _t = 0;
-	// private _m = 1 -_t;
-	// private _x0 = 0;
-	// private _x1 = 1.1;
-	// private _x2 = 0.9;
-	// private _x3 = 1;
-	// private _y0 = 0.1;
-	// private _y1 = 0.5;
-	// private _y2 = 0.8;
-	// private _y3 = 1;
-	// private _xr = (_y0*_m*_m*_m) + (3*_t*_y1*_m*_m) + (3*_t*_t*_y2*_m) + (_t*_t*_t*_y3); // Unneeded for now
-	// private _yr = (_x0*_m*_m*_m) + (3*_t*_x1*_m*_m) + (3*_t*_t*_x2*_m) + (_t*_t*_t*_x3);
-	// simplifies approx to y=1.6t³ - 3.9t² + 3.3t
-	// or t(1.6t² - 3.9t + 3.3)
-
-	private _t = _distance/_radius;
-	private _specificInterference = _t * ((1.6*_t*_t) - (3.9 * _t) + 3.3);
-	if(_interference == 1) then {
-		_interference = _specificInterference;
-		continue
-	};
-	_interference = (_interference + _specificInterference)/2; // Average of interference plus current
-	if(_interference == 0) then {
-		_interference = 0.01; //prevent 0 from being final value
+	if (_distance < _radius) then {
+		//cubic bezier curve
+		// private _t = 0;
+		// private _m = 1 -_t;
+		// private _x0 = 0;
+		// private _x1 = 1.1;
+		// private _x2 = 0.9;
+		// private _x3 = 1;
+		// private _y0 = 0.1;
+		// private _y1 = 0.5;
+		// private _y2 = 0.8;
+		// private _y3 = 1;
+		// private _xr = (_y0*_m*_m*_m) + (3*_t*_y1*_m*_m) + (3*_t*_t*_y2*_m) + (_t*_t*_t*_y3);
+		// private _yr = (_x0*_m*_m*_m) + (3*_t*_x1*_m*_m) + (3*_t*_t*_x2*_m) + (_t*_t*_t*_x3);
+		// _yr simplifies approx to y=1.6t³ - 3.9t² + 3.3t
+		// or t(1.6t² - 3.9t + 3.3)
+		private _t = _distance/_radius;
+		private _specificInterference = _t * ((1.6*_t*_t) - (3.9 * _t) + 3.3);
+		if(_signalStrength == 1) then {
+			_signalStrength = _specificInterference;
+			continue
+		};
+		_signalStrength = (_signalStrength + _specificInterference)/2; // Average of interference plus current
+		if(_signalStrength < 0.01) then {
+			_signalStrength = 0.01; //prevent 0 from being final value
+		};
+		if(_signalStrength > 1) then {
+			_signalStrength = 1; // prevent tfar from being exposed to 1.6e^24 when distance is null
+		}
 	};
 } forEach _jammers;
 
 // Set interference locally
-_player setVariable ["tf_receivingDistanceMultiplicator", _interference];
-_player setVariable ["tf_transmittingDistanceMultiplicator", _interference];
-systemChat format["Interference: %1", _interference];
+_player setVariable ["tf_receivingDistanceMultiplicator", _signalStrength];
+_player setVariable ["tf_transmittingDistanceMultiplicator", _signalStrength];
+systemChat format["Signal Strength: %1", _signalStrength];

+ 16 - 16
addons - Copy/RD501_Main/functions/jammer/fnc_jammersServerPFH.sqf

@@ -4,23 +4,23 @@ if(!isServer) exitWith {
 	[_handle] call CBA_fnc_removePerFrameHandler;
 };
 
-_jammers = missionNamespace getVariable ["rd501_jammers",[]];
-if(_jammers == []) exitWith { };
+private _jammers = missionNamespace getVariable ["rd501_jammers",[]]; 
+ 
+private _toRemove = []; 
+{ 
+	_x params["_jammer", "_radius", "_strength"]; 
+	systemChat format["%1 -- %2", _jammer, _radius];
+	_jipId = _jammer getVariable ["rd501_jammer_jipId", -1]; 
+	if(_jammer == objNull || !(alive _jammer)) then { 
+	 	_toRemove pushBack _x;
+		 if(_jipId != 1) then {
+ 			[_jipId] call CBA_fnc_removeGlobalEventJIP;
+		};
+	}; 
+} forEach _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];
+_jammers = _jammers - _toRemove;
+missionNamespace setVariable ["rd501_jammers", _jammers, true]; 
 
 if(count _jammers == 0) exitWith {
 	systemChat "Exiting Server PFH";