Kaynağa Gözat

Add Vehicle EMP

m3ales 2 yıl önce
ebeveyn
işleme
d3a565f211

+ 6 - 0
addons - Copy/RD501_Main/XEH_preInit.sqf

@@ -176,4 +176,10 @@ macro_prep_xeh(shield\fnc_shield_onLowHealth.sqf,shield_onLowHealth)
 macro_prep_xeh(shield\fnc_shield_onNormalHealth.sqf,shield_onNormalHealth)
 macro_prep_xeh(shield\fnc_shield_regenPerFrameHandler.sqf,shield_regenPerFrameHandler)
 
+// Vehicle EMP
+macro_prep_xeh(emp_vehicle\fnc_emp_hitVehicle.sqf,emp_hitVehicle)
+macro_prep_xeh(emp_vehicle\fnc_emp_hitHandler.sqf,emp_hitHandler)
+macro_prep_xeh(emp_vehicle\fnc_emp_enableVehicle.sqf,emp_enableVehicle)
+macro_prep_xeh(emp_vehicle\fnc_emp_disableVehicle.sqf,emp_disableVehicle)
+
 diag_log "RD501 PREP Complete";

+ 65 - 0
addons - Copy/RD501_Main/functions/emp_vehicle/README.md

@@ -0,0 +1,65 @@
+# Vehicle EMP
+
+## EMP Duration
+
+The calculated duration is given by:
+
+```sqf
+ _effectiveDuration = _empDuration * (1 + ((-_empResistancePercent)/100));
+```
+
+or
+
+```c
+Effective Duration = Ammo Duration * (1 + (-Resistance/100))
+```
+
+Therefore:
+
+- A resistance of < 0 will produce an INCREASE in duration.
+- A resistance of > 0 will produce a DECREASE in duration.
+- A resistance of 0 will produce the same duration defined on the ammo.
+- A resistance of 100 will produce a 0 duration (no effect).
+- A duration of 0 will always result in no effect.
+
+> An effective duration of 0 is assumed for calculated durations < 1 for performance.
+
+## Configuration Properties
+
+### EMP Enabled
+
+Specify if the given ammo has an emp effect on vehicles.
+
+Where to define: `CfgAmmo -> Ammo`.
+
+`rd501_emp_vehicle_enabled=1`
+
+Default: `0`
+
+### EMP Max Duration
+
+You can specify how long a given set of ammo can disable a vehicle for (at maximum). Resistance will reduce this.
+
+Where to define: `CfgAmmo -> Ammo`.
+
+`rd501_emp_vehicle_duration=number`
+
+> `number` is the number of seconds this ammo will disable a vehicle for.
+
+> Note that this is only factored in, if a vehicle has a resistance of 100%, then the emp will not do anything. 50% resistance will halve the duration etc.
+
+Default: `10`
+
+### EMP Resistance
+
+You can specify a vehicles resistance (as a %) to the effects of EMP.
+
+Where to define: `CfgVehicles -> Vehicle`.
+
+`rd501_emp_vehicle_resistance_percent=number`
+
+> `number` is the whole number percentage (max 100, min unbound) which will be applied as a reduction to the given ammo's EMP duration.
+
+> `rd501_emp_vehicle_resistance_percent=100` is effectively disabling the effects on emp on the vehicle. (Immunity)
+
+Default: `0`

+ 34 - 0
addons - Copy/RD501_Main/functions/emp_vehicle/fnc_emp_disableVehicle.sqf

@@ -0,0 +1,34 @@
+params["_vehicle"];
+
+if!(local _vehicle) exitWith { };
+
+_vehicle allowCrewInImmobile true;
+_vehicle lock 2;
+
+{
+	_x setBehaviour "CARELESS";
+	_x setCombatMode "BLUE";
+	_x disableAI "TARGET";
+	_x disableAI "AUTOTARGET";
+	_x disableAI "MOVE";
+	_x disableAI "FSM";
+} forEach crew _vehicle;
+
+(getAllHitPointsDamage _vehicle) params [["_allHitPoints", []], ["", []], ["", []]];
+
+{
+	private _isEngineLower = (_x find "engine") != -1;
+	private _isEngineUpper = (_x find "Engine") != -1;
+	if(_isEngineLower || _isEngineUpper) then {
+		_vehicle setHitPointDamage [_x, 1, true];
+		diag_log format["[RD501][Vehicle EMP] Damaging %1", _x];
+	};
+
+	private _isTurretLower = (_x find "turret") != -1;
+	private _isTurretUpper = (_x find "Turret") != -1;
+	if(_isEngineLower || _isEngineUpper) then {
+		_vehicle setHitPointDamage [_x, 1, true];
+		diag_log format["[RD501][Vehicle EMP] Damaging %1", _x];
+	};
+} forEach _allHitPoints;
+

+ 35 - 0
addons - Copy/RD501_Main/functions/emp_vehicle/fnc_emp_enableVehicle.sqf

@@ -0,0 +1,35 @@
+params["_vehicle"];
+
+if!(local _vehicle) exitWith { };
+
+_vehicle allowCrewInImmobile false;
+_vehicle lock 0;
+
+{
+	_x setBehaviour "AWARE";
+	_x setCombatMode "YELLOW";
+	_x enableAI "TARGET";
+	_x enableAI "AUTOTARGET";
+	_x enableAI "MOVE";
+	_x enableAI "FSM";
+} forEach crew _vehicle;
+
+(getAllHitPointsDamage _vehicle) params [["_allHitPoints", []], ["_allHitPointsSelections", []], ["_allHitPointDamages", []]];
+
+{
+	private _isEngineLower = (_x find "engine") != -1;
+	private _isEngineUpper = (_x find "Engine") != -1;
+	if(_isEngineLower || _isEngineUpper) then {
+		_vehicle setHitPointDamage [_x, 0];
+		diag_log format["[RD501][Vehicle EMP] Repairing %1", _x];
+	};
+
+	private _isTurretLower = (_x find "turret") != -1;
+	private _isTurretUpper = (_x find "Turret") != -1;
+	if(_isEngineLower || _isEngineUpper) then {
+		_vehicle setHitPointDamage [_x, 0];
+		diag_log format["[RD501][Vehicle EMP] Repairing %1", _x];
+	};
+} forEach _allHitPoints;
+
+_vehicle engineOn true;

+ 0 - 0
addons - Copy/RD501_Main/functions/emp_vehicle/fnc_emp_hitHandler.sqf


+ 36 - 0
addons - Copy/RD501_Main/functions/emp_vehicle/fnc_emp_hitVehicle.sqf

@@ -0,0 +1,36 @@
+params["_ammo", "_vehicle"];
+
+private _config = configFile >> "CfgAmmo" >> _ammo;
+
+private _empEnabled = 10;
+if(isNumber (_config >> "rd501_emp_vehicle_duration")) then {
+	_empEnabled = getNumber (_config >> "rd501_emp_vehicle_duration");
+};
+
+private _empDuration = 10;
+if(isNumber (_config >> "rd501_emp_vehicle_duration")) then {
+	_empDuration = getNumber (_config >> "rd501_emp_vehicle_duration");
+};
+
+_config = configFile >> "CfgVehicles" >> (typeOf _vehicle);
+private _empResistancePercent = 0;
+if(isNumber (_config >> "rd501_emp_vehicle_resistance_percent")) then {
+	_empResistancePercent = getNumber (_config >> "rd501_emp_vehicle_resistance_percent");
+	_empResistancePercent = _empResistancePercent max 100;
+};
+
+private _effectiveDuration = _empDuration * (1 + ((- _empResistancePercent)/100));
+
+if(_effectiveDuration <= 1) exitWith { diag_log "[RD501][Vehicle EMP] Effective EMP Duration too low, not worth setting. Skipped." };
+
+[_vehicle] call rd501_fnc_emp_disableVehicle;
+[
+	{
+		params["_vehicle"];
+		if(alive _vehicle) then {
+			[_vehicle] call rd501_fnc_emp_enableVehicle;
+		};
+	},
+	[_vehicle],
+	_effectiveDuration
+] call CBA_fnc_waitAndExecute;