diff --git a/addons/overpressure/CfgEventHandlers.hpp b/addons/overpressure/CfgEventHandlers.hpp index 472c253f7d..0cd959a047 100644 --- a/addons/overpressure/CfgEventHandlers.hpp +++ b/addons/overpressure/CfgEventHandlers.hpp @@ -10,42 +10,3 @@ class Extended_PostInit_EventHandlers { init = QUOTE(call COMPILE_FILE(XEH_postInit)); }; }; - -class Extended_FiredBIS_EventHandlers { - class CAManBase { - class ADDON { - clientFiredBIS = QUOTE(if (local (_this select 0)) then {_this call FUNC(firedEHBB);};); - }; - }; - - class Tank { - class ADDON { - firedBIS = QUOTE(if (local (_this select 0)) then {_this call FUNC(firedEHOP);};); - }; - }; - class Car { - class ADDON { - firedBIS = QUOTE(if (local (_this select 0)) then {_this call FUNC(firedEHOP);};); - }; - }; - class Helicopter { - class ADDON { - firedBIS = QUOTE(if (local (_this select 0)) then {_this call FUNC(firedEHOP);};); - }; - }; - class Plane { - class ADDON { - firedBIS = QUOTE(if (local (_this select 0)) then {_this call FUNC(firedEHOP);};); - }; - }; - class Ship_F { - class ADDON { - firedBIS = QUOTE(if (local (_this select 0)) then {_this call FUNC(firedEHOP);};); - }; - }; - class StaticWeapon { - class ADDON { - firedBIS = QUOTE(if (local (_this select 0)) then {_this call FUNC(firedEHOP);};); - }; - }; -}; diff --git a/addons/overpressure/XEH_postInit.sqf b/addons/overpressure/XEH_postInit.sqf index 33c2e679c9..f7f0bc2ace 100644 --- a/addons/overpressure/XEH_postInit.sqf +++ b/addons/overpressure/XEH_postInit.sqf @@ -1,3 +1,7 @@ #include "script_component.hpp" ["overpressure", FUNC(overpressureDamage)] call EFUNC(common,addEventHandler); + +// Register fire event handler +["firedPlayer", DFUNC(firedEHBB)] call EFUNC(common,addEventHandler); +["firedPlayerVehicle", DFUNC(firedEHOP)] call EFUNC(common,addEventHandler); diff --git a/addons/overpressure/XEH_preInit.sqf b/addons/overpressure/XEH_preInit.sqf index d0ce7cbcf1..37f44a2e9a 100644 --- a/addons/overpressure/XEH_preInit.sqf +++ b/addons/overpressure/XEH_preInit.sqf @@ -2,8 +2,6 @@ ADDON = false; -PREP(fireLauncherBackblast); -PREP(fireOverpressureZone); PREP(getDistance); PREP(overpressureDamage); PREP(cacheOverPressureValues); diff --git a/addons/overpressure/functions/fnc_fireLauncherBackblast.sqf b/addons/overpressure/functions/fnc_fireLauncherBackblast.sqf deleted file mode 100644 index 3b6691fb81..0000000000 --- a/addons/overpressure/functions/fnc_fireLauncherBackblast.sqf +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Author: commy2 and esteldunedain - * Handle fire of local launchers - * Called from firedEHBB, only for ace_player with shot that will cause damage - * - * Arguments: - * 0: Unit that fired - * 1: Weapon fired - * 2: Muzzle - * 3: Mode - * 4: Ammo - * 5: Magazine - * 6: Projectile - * - * Return value: - * None - * - * Example: - * [player, "launch_RPG32_F", "launch_RPG32_F", "Single", "R_PG32V_F", "RPG32_F", projectile] call ace_overpressure_fnc_fireLauncherBackblast; - * - * Public: No - */ -#include "script_component.hpp" - -params ["_firer", "_weapon", "_muzzle", "", "_ammo", "_magazine", "_projectile"]; -TRACE_6("params",_firer,_weapon,_muzzle,_ammo,_magazine,_projectile); - -private _position = getPosASL _projectile; -private _direction = [0, 0, 0] vectorDiff (vectorDir _projectile); - -// Bake variable name and check if the variable exists, call the caching function otherwise -private _varName = format [QGVAR(values%1%2%3), _weapon, _ammo, _magazine]; -private _var = if (isNil _varName) then { - [_weapon, _ammo, _magazine] call FUNC(cacheOverPressureValues); -} else { - missionNameSpace getVariable _varName; -}; -_var params["_backblastAngle","_backblastRange","_backblastDamage"]; -TRACE_3("cache",_backblastAngle,_backblastRange,_backblastDamage); - -// Damage to others -private _affected = (ASLtoAGL _position) nearEntities ["CAManBase", _backblastRange]; - -// Let each client handle their own affected units -["overpressure", _affected, [_firer, _position, _direction, _weapon, _magazine, _ammo]] call EFUNC(common,targetEvent); - -// Damage to the firer -private _distance = 2 * ([_position, _direction, _backblastRange, _firer] call FUNC(getDistance)); - -TRACE_1("Distance",_distance); - -if (_distance < _backblastRange) then { - private _alpha = sqrt (1 - _distance / _backblastRange); - private _beta = sqrt 0.5; - - private _damage = _alpha * _beta * _backblastDamage; - [_damage * 100] call BIS_fnc_bloodEffect; - - if (isClass (configFile >> "CfgPatches" >> "ACE_Medical") && {([_firer] call EFUNC(medical,hasMedicalEnabled))}) then { - [_firer, _damage, "body", "backblast"] call EFUNC(medical,addDamageToUnit); - } else { - _firer setDamage (damage _firer + _damage); - }; -}; - -// Draw debug lines -#ifdef DEBUG_MODE_FULL - [ _position, - _position vectorAdd (_direction vectorMultiply _backblastRange), - [1,1,0,1] - ] call EFUNC(common,addLineToDebugDraw); - - private _ref = _direction call EFUNC(common,createOrthonormalReference); - [ _position, - _position vectorAdd (_direction vectorMultiply _backblastRange) vectorAdd ((_ref select 1) vectorMultiply _backblastRange * tan _backblastAngle), - [1,1,0,1] - ] call EFUNC(common,addLineToDebugDraw); - [ _position, - _position vectorAdd (_direction vectorMultiply _backblastRange) vectorDiff ((_ref select 1) vectorMultiply _backblastRange * tan _backblastAngle), - [1,1,0,1] - ] call EFUNC(common,addLineToDebugDraw); - [ _position, - _position vectorAdd (_direction vectorMultiply _backblastRange) vectorAdd ((_ref select 2) vectorMultiply _backblastRange * tan _backblastAngle), - [1,1,0,1] - ] call EFUNC(common,addLineToDebugDraw); - [ _position, - _position vectorAdd (_direction vectorMultiply _backblastRange) vectorDiff ((_ref select 2) vectorMultiply _backblastRange * tan _backblastAngle), - [1,1,0,1] - ] call EFUNC(common,addLineToDebugDraw); - - [ _position, - _position vectorAdd (_direction vectorMultiply ((_distance/2) min _backblastRange)), - [1,0,0,1] - ] call EFUNC(common,addLineToDebugDraw); -#endif diff --git a/addons/overpressure/functions/fnc_fireOverpressureZone.sqf b/addons/overpressure/functions/fnc_fireOverpressureZone.sqf deleted file mode 100644 index f254151307..0000000000 --- a/addons/overpressure/functions/fnc_fireOverpressureZone.sqf +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Author: commy2 and esteldunedain - * Handle fire of local vehicle weapons creating overpressure zones - * Called from firedEHOP, only for local vehicles - * - * Arguments: - * 0: Vehicle that fired - * 1: Weapon fired - * 2: Muzzle - * 3: Mode - * 4: Ammo - * 5: Magazine - * 6: Projectile - * - * Return value: - * None - * - * Example: - * [tank, "cannon_125mm", "cannon_125mm", "player", "Sh_125mm_APFSDS_T_Green", "24Rnd_125mm_APFSDS_T_Green", projectile] call ace_overpressure_fnc_fireOverpressureZone - * - * Public: No - */ -#include "script_component.hpp" - -params ["_firer", "_weapon", "_muzzle", "", "_ammo", "_magazine", "_projectile"]; -TRACE_6("params",_firer,_weapon,_muzzle,_ammo,_magazine,_projectile); - -// Prevent AI from causing overpressure damage (NOTE: Vehicle is local, but turret gunner may not be) -if !([gunner _firer] call EFUNC(common,isPlayer)) exitWith {}; - -private _position = getPosASL _projectile; -private _direction = vectorDir _projectile; - -// Bake variable name and check if the variable exists, call the caching function otherwise -private _varName = format [QGVAR(values%1%2%3), _weapon, _ammo, _magazine]; -private _var = if (isNil _varName) then { - [_weapon, _ammo, _magazine] call FUNC(cacheOverPressureValues); -} else { - missionNameSpace getVariable _varName; -}; -_var params["_dangerZoneAngle","_dangerZoneRange","_dangerZoneDamage"]; -TRACE_3("cache",_dangerZoneAngle,_dangerZoneRange,_dangerZoneDamage); - -// Damage to others -private _affected = (ASLtoAGL _position) nearEntities ["CAManBase", _dangerZoneRange]; - -// Let each client handle their own affected units -["overpressure", _affected, [_firer, _position, _direction, _weapon, _magazine, _ammo]] call EFUNC(common,targetEvent); - -// Draw debug lines -#ifdef DEBUG_MODE_FULL - [ _position, - _position vectorAdd (_direction vectorMultiply _dangerZoneRange), - [1,0,0,1] - ] call EFUNC(common,addLineToDebugDraw); - - private _ref = _direction call EFUNC(common,createOrthonormalReference); - [ _position, - _position vectorAdd (_direction vectorMultiply _dangerZoneRange) vectorAdd ((_ref select 1) vectorMultiply _dangerZoneRange * tan _dangerZoneAngle), - [1,1,0,1] - ] call EFUNC(common,addLineToDebugDraw); - [ _position, - _position vectorAdd (_direction vectorMultiply _dangerZoneRange) vectorDiff ((_ref select 1) vectorMultiply _dangerZoneRange * tan _dangerZoneAngle), - [1,1,0,1] - ] call EFUNC(common,addLineToDebugDraw); - [ _position, - _position vectorAdd (_direction vectorMultiply _dangerZoneRange) vectorAdd ((_ref select 2) vectorMultiply _dangerZoneRange * tan _dangerZoneAngle), - [1,1,0,1] - ] call EFUNC(common,addLineToDebugDraw); - [ _position, - _position vectorAdd (_direction vectorMultiply _dangerZoneRange) vectorDiff ((_ref select 2) vectorMultiply _dangerZoneRange * tan _dangerZoneAngle), - [1,1,0,1] - ] call EFUNC(common,addLineToDebugDraw); - -#endif diff --git a/addons/overpressure/functions/fnc_firedEHBB.sqf b/addons/overpressure/functions/fnc_firedEHBB.sqf index 6327cc67c9..8dc15e0f0a 100644 --- a/addons/overpressure/functions/fnc_firedEHBB.sqf +++ b/addons/overpressure/functions/fnc_firedEHBB.sqf @@ -1,39 +1,90 @@ /* * Author: joko // Jonas - * Handle fire of local launchers + * Handle fire of local launchers. Called from the unified fired EH only for the local player. * * Arguments: - * 0: Unit that fired - * 1: Weapon fired - * 2: Muzzle - * 3: Mode - * 4: Ammo - * 5: Magazine - * 6: Projectile + * None. Parameters inherited from EFUNC(common,firedEH) * * Return value: * None * - * Example: + * Example: * [player, "launch_RPG32_F", "launch_RPG32_F", "Single", "R_PG32V_F", "RPG32_F", projectile] call ace_overpressure_fnc_firedEHBB; * * Public: No */ #include "script_component.hpp" -params ["_firer", "_weapon", "", "", "_ammo", "_magazine", ""]; - -// Prevent AI from causing backblast damage (fast exit to only run for local players) -if (_firer != ACE_player) exitWith {}; +//IGNORE_PRIVATE_WARNING ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_vehicle", "_gunner", "_turret"]; +TRACE_10("firedEH:",_unit, _weapon, _muzzle, _mode, _ammo, _magazine, _projectile, _vehicle, _gunner, _turret); // Bake variable name and check if the variable exists, call the caching function otherwise private _varName = format [QGVAR(values%1%2%3), _weapon, _ammo, _magazine]; -private _damage = if (isNil _varName) then { - ([_weapon, _ammo, _magazine] call FUNC(cacheOverPressureValues)) select 2; +private _var = if (isNil _varName) then { + [_weapon, _ammo, _magazine] call FUNC(cacheOverPressureValues); } else { - (missionNameSpace getVariable _varName) select 2; + missionNameSpace getVariable _varName; +}; +_var params["_backblastAngle","_backblastRange","_backblastDamage"]; +TRACE_3("cache",_backblastAngle,_backblastRange,_backblastDamage); + +if (_backblastDamage <= 0) exitWith {}; + +private _position = getPosASL _projectile; +private _direction = [0, 0, 0] vectorDiff (vectorDir _projectile); + +// Damage to others +private _affected = (ASLtoAGL _position) nearEntities ["CAManBase", _backblastRange]; + +// Let each client handle their own affected units +["overpressure", _affected, [_unit, _position, _direction, _weapon, _magazine, _ammo]] call EFUNC(common,targetEvent); + +// Damage to the firer +private _distance = 2 * ([_position, _direction, _backblastRange, _unit] call FUNC(getDistance)); + +TRACE_1("Distance",_distance); + +if (_distance < _backblastRange) then { + private _alpha = sqrt (1 - _distance / _backblastRange); + private _beta = sqrt 0.5; + + private _damage = _alpha * _beta * _backblastDamage; + [_damage * 100] call BIS_fnc_bloodEffect; + + if (isClass (configFile >> "CfgPatches" >> "ACE_Medical") && {([_unit] call EFUNC(medical,hasMedicalEnabled))}) then { + [_unit, _damage, "body", "backblast"] call EFUNC(medical,addDamageToUnit); + } else { + _unit setDamage (damage _unit + _damage); + }; }; -if (_damage > 0) then { - _this call DFUNC(fireLauncherBackblast) -}; +// Draw debug lines +#ifdef DEBUG_MODE_FULL + [ _position, + _position vectorAdd (_direction vectorMultiply _backblastRange), + [1,1,0,1] + ] call EFUNC(common,addLineToDebugDraw); + + private _ref = _direction call EFUNC(common,createOrthonormalReference); + [ _position, + _position vectorAdd (_direction vectorMultiply _backblastRange) vectorAdd ((_ref select 1) vectorMultiply _backblastRange * tan _backblastAngle), + [1,1,0,1] + ] call EFUNC(common,addLineToDebugDraw); + [ _position, + _position vectorAdd (_direction vectorMultiply _backblastRange) vectorDiff ((_ref select 1) vectorMultiply _backblastRange * tan _backblastAngle), + [1,1,0,1] + ] call EFUNC(common,addLineToDebugDraw); + [ _position, + _position vectorAdd (_direction vectorMultiply _backblastRange) vectorAdd ((_ref select 2) vectorMultiply _backblastRange * tan _backblastAngle), + [1,1,0,1] + ] call EFUNC(common,addLineToDebugDraw); + [ _position, + _position vectorAdd (_direction vectorMultiply _backblastRange) vectorDiff ((_ref select 2) vectorMultiply _backblastRange * tan _backblastAngle), + [1,1,0,1] + ] call EFUNC(common,addLineToDebugDraw); + + [ _position, + _position vectorAdd (_direction vectorMultiply ((_distance/2) min _backblastRange)), + [1,0,0,1] + ] call EFUNC(common,addLineToDebugDraw); +#endif diff --git a/addons/overpressure/functions/fnc_firedEHOP.sqf b/addons/overpressure/functions/fnc_firedEHOP.sqf index fbcb034279..dff9215a52 100644 --- a/addons/overpressure/functions/fnc_firedEHOP.sqf +++ b/addons/overpressure/functions/fnc_firedEHOP.sqf @@ -1,15 +1,9 @@ /* * Author: joko // Jonas - * Handle fire of Vehicle Weapons + * Handle fire of Vehicle Weapons. Called from the unified fired EH only for the local player vehicle. * * Arguments: - * 0: Vehicle that fired (XEH will filter only local) - * 1: Weapon fired - * 2: Muzzle - * 3: Mode - * 4: Ammo - * 5: Magazine - * 6: Projectile + * None. Parameters inherited from EFUNC(common,firedEH) * * Return value: * None @@ -21,16 +15,56 @@ */ #include "script_component.hpp" -params ["", "_weapon", "", "", "_ammo", "_magazine", ""]; +//IGNORE_PRIVATE_WARNING ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_vehicle", "_gunner", "_turret"]; +TRACE_10("firedEH:",_unit, _weapon, _muzzle, _mode, _ammo, _magazine, _projectile, _vehicle, _gunner, _turret); // Bake variable name and check if the variable exists, call the caching function otherwise private _varName = format [QGVAR(values%1%2%3), _weapon, _ammo, _magazine]; -private _damage = if (isNil _varName) then { - ([_weapon, _ammo, _magazine] call FUNC(cacheOverPressureValues)) select 2; +private _var = if (isNil _varName) then { + [_weapon, _ammo, _magazine] call FUNC(cacheOverPressureValues); } else { - (missionNameSpace getVariable _varName) select 2; + missionNameSpace getVariable _varName; }; +_var params["_dangerZoneAngle","_dangerZoneRange","_dangerZoneDamage"]; +TRACE_3("cache",_dangerZoneAngle,_dangerZoneRange,_dangerZoneDamage); -if (_damage > 0) then { - _this call DFUNC(fireOverpressureZone) -}; +if (_dangerZoneDamage <= 0) exitWith {}; + + + +// The weapon produces overpressure, calculate +private _position = getPosASL _projectile; +private _direction = vectorDir _projectile; + +// Damage to others +private _affected = (ASLtoAGL _position) nearEntities ["CAManBase", _dangerZoneRange]; + +// Let each client handle their own affected units +["overpressure", _affected, [_unit, _position, _direction, _weapon, _magazine, _ammo]] call EFUNC(common,targetEvent); + +// Draw debug lines +#ifdef DEBUG_MODE_FULL + [ _position, + _position vectorAdd (_direction vectorMultiply _dangerZoneRange), + [1,0,0,1] + ] call EFUNC(common,addLineToDebugDraw); + + private _ref = _direction call EFUNC(common,createOrthonormalReference); + [ _position, + _position vectorAdd (_direction vectorMultiply _dangerZoneRange) vectorAdd ((_ref select 1) vectorMultiply _dangerZoneRange * tan _dangerZoneAngle), + [1,1,0,1] + ] call EFUNC(common,addLineToDebugDraw); + [ _position, + _position vectorAdd (_direction vectorMultiply _dangerZoneRange) vectorDiff ((_ref select 1) vectorMultiply _dangerZoneRange * tan _dangerZoneAngle), + [1,1,0,1] + ] call EFUNC(common,addLineToDebugDraw); + [ _position, + _position vectorAdd (_direction vectorMultiply _dangerZoneRange) vectorAdd ((_ref select 2) vectorMultiply _dangerZoneRange * tan _dangerZoneAngle), + [1,1,0,1] + ] call EFUNC(common,addLineToDebugDraw); + [ _position, + _position vectorAdd (_direction vectorMultiply _dangerZoneRange) vectorDiff ((_ref select 2) vectorMultiply _dangerZoneRange * tan _dangerZoneAngle), + [1,1,0,1] + ] call EFUNC(common,addLineToDebugDraw); + +#endif