From 8f0c6f7a1fd4a012a5c2770d9baf06370eccca74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Badano?= Date: Sun, 25 Jan 2015 00:56:23 -0300 Subject: [PATCH 1/4] common: function for drawing debug lines --- addons/common/XEH_preInit.sqf | 2 + .../functions/fnc_addLineToDebugDraw.sqf | 48 +++++++++++++++++++ .../fnc_createOrthonormalReference.sqf | 21 ++++++++ 3 files changed, 71 insertions(+) create mode 100644 addons/common/functions/fnc_addLineToDebugDraw.sqf create mode 100644 addons/common/functions/fnc_createOrthonormalReference.sqf diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index f33b3c47fe..498321b857 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -6,6 +6,7 @@ PREP(addActionEventHandler); PREP(addActionMenuEventHandler); PREP(addCameraEventHandler); PREP(addCustomEventHandler); +PREP(addLineToDebugDraw); PREP(addMapMarkerCreatedEventHandler); PREP(addScrollWheelEventHandler); PREP(adminKick); @@ -24,6 +25,7 @@ PREP(closeDialogIfTargetMoves); PREP(codeToLetter); PREP(codeToString); PREP(convertKeyCode); +PREP(createOrthonormalReference); PREP(currentChannel); PREP(disableUserInput); PREP(displayText); diff --git a/addons/common/functions/fnc_addLineToDebugDraw.sqf b/addons/common/functions/fnc_addLineToDebugDraw.sqf new file mode 100644 index 0000000000..cfe45359c9 --- /dev/null +++ b/addons/common/functions/fnc_addLineToDebugDraw.sqf @@ -0,0 +1,48 @@ +/* + * Author: CAA-Picard + * + * Add line to draw on debug + * + * Argument: + * 0: Start point ASL (Array) + * 1: End point ASL (Array) + * 2: Color (Array) + * + * Return value: + * + */ +#include "script_component.hpp" + +if (isNil QGVAR(debugLines)) then { + GVAR(debugLines) = []; + GVAR(debugLinesIndex) = 0; +}; + +if (count GVAR(debugLines) < 100) then { + GVAR(debugLines) pushBack _this; + GVAR(debugLinesIndex) = 0; +} else { + GVAR(debugLines) set [GVAR(debugLinesIndex), _this]; + GVAR(debugLinesIndex) = (GVAR(debugLinesIndex) + 1) mod 100; +}; + +if (isNil QGVAR(debugDrawHandler)) then { + GVAR(debugDrawHandler) = addMissionEventHandler ["Draw3D", { + if (count GVAR(debugLines) == 0) exitWith { + removeMissionEventHandler GVAR(debugDrawHandler); + GVAR(debugDrawHandler) = nil; + }; + + { + _p0 = _x select 0; + if (!surfaceIsWater _p0) then { + _p0 = ASLtoATL _p0; + }; + _p1 = _x select 1; + if (!surfaceIsWater _p1) then { + _p1 = ASLtoATL _p1; + }; + drawLine3D [_p0, _p1, _x select 2]; + } forEach GVAR(debugLines); + }]; +}; \ No newline at end of file diff --git a/addons/common/functions/fnc_createOrthonormalReference.sqf b/addons/common/functions/fnc_createOrthonormalReference.sqf new file mode 100644 index 0000000000..a92464a7f3 --- /dev/null +++ b/addons/common/functions/fnc_createOrthonormalReference.sqf @@ -0,0 +1,21 @@ +/* + * Author: CAA-Picard + * + * Returns a orthonormal system of reference aligned with the supplied vector + * + * Argument: + * Vector to align the coordinate system with (Array) + * + * Return value: + * 0: v1 (Array) + * 1: v2 (Array) + * 2: v3 (Array) + */ +#include "script_component.hpp" + +private ["_v1","_v2","_v3"]; +_v1 = vectorNormalized _this; +_v2 = vectorNormalized (_v1 vectorCrossProduct [0,0,1]); +_v3 = _v2 vectorCrossProduct _v1; + +[_v1,_v2,_v3] From 8d1ee8c2c2989241ee39b886c04f09728bb79c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Badano?= Date: Sun, 25 Jan 2015 00:59:20 -0300 Subject: [PATCH 2/4] backblast: overhaul - Replace firedNear by firedBIS XEH - Calculate the origin of the backblast and overpressure zones using the projectile position and direction - Handle all effects for each unit on their local machine - Posibility of drawing effect cone for debug - Simplified angle calculations --- addons/backblast/CfgEventHandlers.hpp | 14 ++- addons/backblast/XEH_postInit.sqf | 4 + addons/backblast/XEH_preInit.sqf | 6 +- .../functions/fnc_backblastDamage.sqf | 67 ++++++++++++++ .../functions/fnc_fireLauncherBackblast.sqf | 91 +++++++++++++++++++ .../functions/fnc_fireOverpressureZone.sqf | 65 +++++++++++++ .../backblast/functions/fnc_getDistance.sqf | 45 +++++---- .../functions/fnc_launcherBackblast.sqf | 72 --------------- .../functions/fnc_overpressureDamage.sqf | 65 +++++++++++++ .../functions/fnc_tankDangerZone.sqf | 54 ----------- 10 files changed, 334 insertions(+), 149 deletions(-) create mode 100644 addons/backblast/XEH_postInit.sqf create mode 100644 addons/backblast/functions/fnc_backblastDamage.sqf create mode 100644 addons/backblast/functions/fnc_fireLauncherBackblast.sqf create mode 100644 addons/backblast/functions/fnc_fireOverpressureZone.sqf delete mode 100644 addons/backblast/functions/fnc_launcherBackblast.sqf create mode 100644 addons/backblast/functions/fnc_overpressureDamage.sqf delete mode 100644 addons/backblast/functions/fnc_tankDangerZone.sqf diff --git a/addons/backblast/CfgEventHandlers.hpp b/addons/backblast/CfgEventHandlers.hpp index a336a5dd41..979a683aeb 100644 --- a/addons/backblast/CfgEventHandlers.hpp +++ b/addons/backblast/CfgEventHandlers.hpp @@ -5,13 +5,21 @@ class Extended_PreInit_EventHandlers { }; }; -class Extended_FiredNear_EventHandlers { +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit) ); + }; +}; + +class Extended_FiredBIS_EventHandlers { class CAManBase { class GVAR(LauncherBackblast) { - FiredNear = QUOTE( if (local (_this select 0) && {getNumber (configfile >> 'CfgWeapons' >> _this select 3 >> 'ACE_Backblast_Damage') > 0}) then {_this call FUNC(launcherBackblast)} ); + firedBIS = QUOTE( if (local (_this select 0) && {getNumber (configfile >> 'CfgWeapons' >> _this select 1 >> 'ACE_Backblast_Damage') > 0}) then {_this call FUNC(fireLauncherBackblast)} ); }; + }; + class AllVehicles { class GVAR(TankDangerZone) { - FiredNear = QUOTE( if (local (_this select 0) && {getNumber (configfile >> 'CfgWeapons' >> _this select 3 >> 'ACE_DangerZone_Damage') > 0}) then {_this call FUNC(tankDangerZone)} ); + firedBIS = QUOTE( if (local (_this select 0) && {getNumber (configfile >> 'CfgWeapons' >> _this select 1 >> 'ACE_DangerZone_Damage') > 0}) then {_this call FUNC(fireOverpressureZone)} ); }; }; }; diff --git a/addons/backblast/XEH_postInit.sqf b/addons/backblast/XEH_postInit.sqf new file mode 100644 index 0000000000..72ca42a012 --- /dev/null +++ b/addons/backblast/XEH_postInit.sqf @@ -0,0 +1,4 @@ +#include "script_component.hpp" + +["backblast", FUNC(backblastDamage)] call EFUNC(common,addEventHandler); +["overpressure", FUNC(overpressureDamage)] call EFUNC(common,addEventHandler); diff --git a/addons/backblast/XEH_preInit.sqf b/addons/backblast/XEH_preInit.sqf index 1becf28c05..1927bc850b 100644 --- a/addons/backblast/XEH_preInit.sqf +++ b/addons/backblast/XEH_preInit.sqf @@ -1,5 +1,7 @@ #include "script_component.hpp" +PREP(backblastDamage); +PREP(fireLauncherBackblast); +PREP(fireOverpressureZone); PREP(getDistance); -PREP(launcherBackblast); -PREP(tankDangerZone); +PREP(overpressureDamage); diff --git a/addons/backblast/functions/fnc_backblastDamage.sqf b/addons/backblast/functions/fnc_backblastDamage.sqf new file mode 100644 index 0000000000..21d2e81736 --- /dev/null +++ b/addons/backblast/functions/fnc_backblastDamage.sqf @@ -0,0 +1,67 @@ +/* + * Author: Commy2 and CAA-Picard + * + * Calculate and apply backblast damage to potentially affected local units + * + * Argument: + * 0: Unit that fired (Object) + * 1: Pos ASL of the projectile (Array) + * 2: Direction of the projectile (Array) + * 3: Weapon fired (String) + * + * Return value: + * None + */ +#include "script_component.hpp" + +EXPLODE_4_PVT(_this,_firer,_posASL,_direction,_weapon); + +private ["_backblastAngle","_backblastRange","_backblastDamage"]; +_backblastAngle = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Angle") / 2; +_backblastRange = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Range"); +_backblastDamage = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Damage"); +TRACE_4("Parameters:",_backblastAngle,_backblastRange,_backblastDamage,_weapon); + +_pos = _posASL; +if (!surfaceIsWater _pos) then { + _pos = ASLtoATL _pos; +}; + +_affected = _pos nearEntities ["CAManBase", _backblastRange]; +{ + _unit = _x; + if (local _unit && _unit != _firer && vehicle _unit == _unit) then { + + _targetPositionASL = eyePos _unit; + _relativePosition = _targetPositionASL vectorDiff _posASL; + _axisDistance = _relativePosition vectorDotProduct _direction; + _distance = vectorMagnitude _relativePosition; + _angle = acos (_axisDistance / _distance); + + _line = [_posASL, _targetPositionASL, _firer, _unit]; + _line2 = [_posASL, _targetPositionASL]; + TRACE_4("Affected:",_unit,_axisDistance,_distance,_angle); + if (_angle < _backblastAngle && {_distance < _backblastRange} && {!lineIntersects _line} && {!terrainIntersectASL _line2}) then { + _alpha = sqrt (1 - _distance / _backblastRange); + _beta = sqrt (1 - _angle / _backblastAngle); + + _damage = 2 * _alpha * _beta * _backblastDamage; + + // If the target is the ACE_player + if (_unit == ACE_player) then {[_damage * 100] call BIS_fnc_bloodEffect}; + + // TODO: Sort this interaction with medical + if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then { + [_unit, "HitBody", ([_unit, "", ((_unit getHitPointDamage "HitBody") + _damage), objNull, objNull] call EFUNC(medical,handleDamage))] call EFUNC(medical,setHitPointDamage); + _unit spawn { + sleep 0.5; + [_this, "", 0, objNull, objNull] call EFUNC(medical,handleDamage); + }; + } else { + _unit setDamage (damage _unit + _damage); + }; + }; + }; +} forEach _affected; + + diff --git a/addons/backblast/functions/fnc_fireLauncherBackblast.sqf b/addons/backblast/functions/fnc_fireLauncherBackblast.sqf new file mode 100644 index 0000000000..5970e7b9c2 --- /dev/null +++ b/addons/backblast/functions/fnc_fireLauncherBackblast.sqf @@ -0,0 +1,91 @@ +/* + * Author: Commy2 and CAA-Picard + * + * Handle fire of local launchers + * + * Argument: + * 0: Unit that fired (Object) + * 1: Weapon fired (String) + * 2: Muzzle (String) + * 3: Mode (String) + * 4: Ammo (String) + * 5: Magazine (String) + * 6: Projectile (Object) + * + * Return value: + * None + */ +//#define DEBUG_MODE_FULL +#include "script_component.hpp" + +EXPLODE_7_PVT(_this,_firer,_weapon,_muzzle,_mode,_ammo,_magazine,_projectile); + +// Prevent AI from causing backblast damage +if !([_firer] call EFUNC(common,isPlayer)) exitWith {}; + +private ["_position","_direction","_distance","_alpha","_beta","_damage","_affected"]; +_position = getPosASL _projectile; +_direction = [0, 0, 0] vectorDiff (vectorDir _projectile); + +private ["_backblastAngle","_backblastRange","_backblastDamage"]; +_backblastAngle = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Angle") / 2; +_backblastRange = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Range"); +_backblastDamage = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Damage"); + + +// Damage to others +_affected = getPos _projectile nearEntities ["CAManBase", _backblastRange]; +// Let each client handle their own affected units +["backblast", _affected, [_firer,_position,_direction,_weapon]] call EFUNC(common,targetEvent); + + +// Damage to the firer +_distance = [_position, _direction, _backblastRange] call FUNC(getDistance); +TRACE_1("Distance", _distance); + +if (_distance < _backblastRange) then { + + _alpha = sqrt (1 - _distance / _backblastRange); + _beta = sqrt 0.5; + + _damage = 2 * _alpha * _beta * _backblastDamage; + [_damage * 100] call BIS_fnc_bloodEffect; + + // TODO: Sort this interaction with medical + if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then { + [_firer, "HitBody", ([_firer, "", ((_firer getHitPointDamage "HitBody") + _damage), objNull, objNull] call EFUNC(medical,handleDamage))] call EFUNC(medical,setHitPointDamage); + } 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); + + _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 min _backblastRange)), + [1,0,0,1] + ] call EFUNC(common,addLineToDebugDraw); +#endif \ No newline at end of file diff --git a/addons/backblast/functions/fnc_fireOverpressureZone.sqf b/addons/backblast/functions/fnc_fireOverpressureZone.sqf new file mode 100644 index 0000000000..c638f4ad82 --- /dev/null +++ b/addons/backblast/functions/fnc_fireOverpressureZone.sqf @@ -0,0 +1,65 @@ +/* + * Author: Commy2 and CAA-Picard + * + * Handle fire of local vehicle weapons creating overpressure zones + * + * Argument: + * 0: Unit that fired (Object) + * 1: Weapon fired (String) + * 2: Muzzle (String) + * 3: Mode (String) + * 4: Ammo (String) + * 5: Magazine (String) + * 6: Projectile (Object) + * + * Return value: + * None + *///#define DEBUG_MODE_FULL +#include "script_component.hpp" + +EXPLODE_7_PVT(_this,_firer,_weapon,_muzzle,_mode,_ammo,_magazine,_projectile); + +// Prevent AI from causing backblast damage +if !([gunner _firer] call EFUNC(common,isPlayer)) exitWith {}; + +private ["_position","_direction","_distance","_alpha","_beta","_damage","_affected"]; +_position = getPosASL _projectile; +_direction = vectorDir _projectile; + +private ["_dangerZoneAngle","_dangerZoneRange","_dangerZoneDamage"]; +_dangerZoneAngle = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Angle") / 2; +_dangerZoneRange = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Range"); +_dangerZoneDamage = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Damage"); + + +// Damage to others +_affected = getPos _projectile nearEntities ["CAManBase", _dangerZoneRange]; +// Let each client handle their own affected units +["overpressure", _affected, [_firer,_position,_direction,_weapon]] 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); + + _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 \ No newline at end of file diff --git a/addons/backblast/functions/fnc_getDistance.sqf b/addons/backblast/functions/fnc_getDistance.sqf index 83b290e2b0..b6f61548c6 100644 --- a/addons/backblast/functions/fnc_getDistance.sqf +++ b/addons/backblast/functions/fnc_getDistance.sqf @@ -1,31 +1,40 @@ -// by commy2 +/* + * Author: Commy2 and CAA-Picard + * + * Calculate the distance to the first intersection of a line + * + * Argument: + * 0: Pos ASL of origin (Array) + * 1: Direction (Array) + * 2: Max distance to search (Number) + * + * Return value: + * Distance to intersection (+- 0.1 m) + */ #include "script_component.hpp" -private ["_position", "_direction", "_maxDistance", "_distance", "_iteration", "_laser", "_line"]; +private ["_distance", "_interval", "_line", "_line"]; -_position = + _this select 0; -_direction = + _this select 1; -_maxDistance = _this select 2; +EXPLODE_3_PVT(_this,_posASL,_direction,_maxDistance); _distance = _maxDistance; -_iteration = _distance; -_laser = []; -_line = [_position, _laser]; +_interval = _distance; +_line = [_posASL, []]; while { - _iteration > 0.1 + _interval > 0.1 } do { - _iteration = _iteration / 2; + _interval = _interval / 2; - _laser set [0, (_position select 0) - _distance * (_direction select 0)]; - _laser set [1, (_position select 1) - _distance * (_direction select 1)]; - _laser set [2, (_position select 2) - _distance * (_direction select 2)]; + _line set [1, _posASL vectorAdd (_direction vectorMultiply _distance)]; - _intersections = { - _x isKindOf "Static" || {_x isKindOf "AllVehicles"} - } count (lineIntersectsWith _line); + _intersections = { + _x isKindOf "Static" || {_x isKindOf "AllVehicles"} + } count (lineIntersectsWith _line); - _distance = _distance + ([1, -1] select (_intersections > 0)) * _iteration; + _distance = _distance + ([1, -1] select (_intersections > 0 || {terrainIntersectASL _line})) * _interval; + + if (_distance > _maxDistance) exitWith {_distance = 999}; }; -if (_distance > _maxDistance) then {999} else {_distance} +_distance diff --git a/addons/backblast/functions/fnc_launcherBackblast.sqf b/addons/backblast/functions/fnc_launcherBackblast.sqf deleted file mode 100644 index b2cde50c5d..0000000000 --- a/addons/backblast/functions/fnc_launcherBackblast.sqf +++ /dev/null @@ -1,72 +0,0 @@ -// by commy2 -#include "script_component.hpp" - -_unit = _this select 0; -_firer = _this select 1; -_distance = _this select 2; -_weapon = _this select 3; - -if (vehicle _unit != _unit || {!([_firer] call EFUNC(common,isPlayer))}) exitWith {}; - -_backblastAngle = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Angle") / 2; -_backblastRange = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Range"); -_backblastDamage = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_Backblast_Damage"); - -_position = eyePos _firer; -_direction = _firer weaponDirection currentWeapon _firer; - -if (_unit == _firer) then { - _distance = [_position, _direction, _backblastRange] call FUNC(getDistance); - hint format ["%1", _distance]; - if (_distance < _backblastRange) then { - _alpha = sqrt (1 - _distance / _backblastRange); - _beta = sqrt 0.5; - - _damage = 2 * _alpha * _beta * _backblastDamage; - [_damage * 100] call BIS_fnc_bloodEffect; - - // TODO: Sort this interaction with medical - if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then { - [_unit, "HitBody", ([_unit, "", ((_unit getHitPointDamage "HitBody") + _damage), objNull, objNull] call EFUNC(medical,handleDamage))] call EFUNC(medical,setHitPointDamage); - } else { - _unit setDamage (damage _unit + _damage); - }; - - }; -} else { - _direction = [0, 0, 0] vectorDiff _direction; - - _azimuth = (_direction select 0) atan2 (_direction select 1); - _inclination = asin (_direction select 2); - - _relativePosition = eyePos _unit; - _relativeDirection = _relativePosition vectorDiff _position; - - _relativeAzimuth = (_relativeDirection select 0) atan2 (_relativeDirection select 1); - _relativeInclination = asin (_relativeDirection select 2); - - _angle = sqrt ((_relativeAzimuth - _azimuth) ^ 2 + (_relativeInclination - _inclination) ^ 2); - _distance = vectorMagnitude _relativeDirection; - - _line = [_position, _relativePosition]; - - if (_angle < _backblastAngle && {_distance < _backblastRange} && {!lineIntersects _line} && {!terrainIntersectASL _line}) then { - _alpha = sqrt (1 - _distance / _backblastRange); - _beta = sqrt (1 - _angle / _backblastAngle); - - _damage = 2 * _alpha * _beta * _backblastDamage; - if (_unit == ACE_player) then {[_damage * 100] call BIS_fnc_bloodEffect}; - - // TODO: Sort this interaction with medical - if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then { - [_unit, "HitBody", ([_unit, "", ((_unit getHitPointDamage "HitBody") + _damage), objNull, objNull] call EFUNC(medical,handleDamage))] call EFUNC(medical,setHitPointDamage); - _unit spawn { - sleep 0.5; - [_this, "", 0, objNull, objNull] call EFUNC(medical,handleDamage); - }; - } else { - _unit setDamage (damage _unit + _damage); - }; - - }; -}; diff --git a/addons/backblast/functions/fnc_overpressureDamage.sqf b/addons/backblast/functions/fnc_overpressureDamage.sqf new file mode 100644 index 0000000000..5dd7447ce8 --- /dev/null +++ b/addons/backblast/functions/fnc_overpressureDamage.sqf @@ -0,0 +1,65 @@ +/* + * Author: Commy2 and CAA-Picard + * + * Calculate and apply overpressure damage to potentially affected local units + * + * Argument: + * 0: Unit that fired (Object) + * 1: Pos ASL of the projectile (Array) + * 2: Direction of the projectile (Array) + * 3: Weapon fired (String) + * + * Return value: + * None + */ +#include "script_component.hpp" + +EXPLODE_4_PVT(_this,_firer,_posASL,_direction,_weapon); + +private ["_dangerZoneAngle","_dangerZoneRange","_dangerZoneDamage"]; +_dangerZoneAngle = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Angle") / 2; +_dangerZoneRange = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Range"); +_dangerZoneDamage = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Damage"); +TRACE_4("Parameters:",_dangerZoneAngle,_dangerZoneRange,_dangerZoneDamage,_weapon); + +_pos = _posASL; +if (!surfaceIsWater _pos) then { + _pos = ASLtoATL _pos; +}; + +_affected = _pos nearEntities ["CAManBase", _dangerZoneRange]; +{ + _unit = _x; + if (local _unit && _unit != _firer && vehicle _unit == _unit) then { + + _targetPositionASL = eyePos _unit; + _relativePosition = _targetPositionASL vectorDiff _posASL; + _axisDistance = _relativePosition vectorDotProduct _direction; + _distance = vectorMagnitude _relativePosition; + _angle = acos (_axisDistance / _distance); + + _line = [_posASL, _targetPositionASL, _firer, _unit]; + _line2 = [_posASL, _targetPositionASL]; + TRACE_4("Affected:",_unit,_axisDistance,_distance,_angle); + if (_angle < _dangerZoneAngle && {_distance < _dangerZoneRange} && {!lineIntersects _line} && {!terrainIntersectASL _line2}) then { + _alpha = sqrt (1 - _distance / _dangerZoneRange); + _beta = sqrt (1 - _angle / _dangerZoneAngle); + + _damage = 2 * _alpha * _beta * _dangerZoneDamage; + + // If the target is the ACE_player + if (_unit == ACE_player) then {[_damage * 100] call BIS_fnc_bloodEffect}; + + // @todo: Sort this interaction with medical + if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then { + [_unit, "HitBody", ([_unit, "", ((_unit getHitPointDamage "HitBody") + _damage), objNull, objNull] call EFUNC(medical,handleDamage))] call EFUNC(medical,setHitPointDamage); + _unit spawn { + sleep 0.5; + [_this, "", 0, objNull, objNull] call EFUNC(medical,handleDamage); + }; + } else { + _unit setDamage (damage _unit + _damage); + }; + }; + }; +} forEach _affected; diff --git a/addons/backblast/functions/fnc_tankDangerZone.sqf b/addons/backblast/functions/fnc_tankDangerZone.sqf deleted file mode 100644 index 0371ec9620..0000000000 --- a/addons/backblast/functions/fnc_tankDangerZone.sqf +++ /dev/null @@ -1,54 +0,0 @@ -// by commy2 -#include "script_component.hpp" - -#define BARREL_MUZZLE "usti hlavne" - -_unit = _this select 0; -_vehicle = vehicle (_this select 1); -_distance = _this select 2; -_weapon = _this select 3; - -if (vehicle _unit != _unit || {!([gunner _firer] call EFUNC(common,isPlayer))}) exitWith {}; - -_dangerZoneAngle = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Angle") / 2; -_dangerZoneRange = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Range"); -_dangerZoneDamage = getNumber (configFile >> "CfgWeapons" >> _weapon >> "ACE_DangerZone_Damage"); - -_position = ATLToASL (_vehicle modelToWorld (_vehicle selectionPosition BARREL_MUZZLE)); -_direction = _vehicle weaponDirection _weapon; - -if (_unit != _vehicle) then { - _azimuth = (_direction select 0) atan2 (_direction select 1); - _inclination = asin (_direction select 2); - - _relativePosition = eyePos _unit; - _relativeDirection = _relativePosition vectorDiff _position; - - _relativeAzimuth = (_relativeDirection select 0) atan2 (_relativeDirection select 1); - _relativeInclination = asin (_relativeDirection select 2); - - _angle = sqrt ((_relativeAzimuth - _azimuth) ^ 2 + (_relativeInclination - _inclination) ^ 2); - _distance = vectorMagnitude _relativeDirection; - - _line = [_position, _relativePosition]; - - if (_angle < _dangerZoneAngle && {_distance < _dangerZoneRange} && {!lineIntersects (_line + [_vehicle])} && {!terrainIntersectASL _line}) then { - _alpha = sqrt (1 - _distance / _dangerZoneRange); - _beta = sqrt (1 - _angle / _dangerZoneAngle); - - _damage = 2 * _alpha * _beta * _dangerZoneDamage; - if (_unit == ACE_player) then {[_damage * 100] call BIS_fnc_bloodEffect}; - - // TODO: Sort this interaction with medical - if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then { - [_unit, "HitBody", ([_unit, "", ((_unit getHitPointDamage "HitBody") + _damage), objNull, objNull] call EFUNC(medical,handleDamage))] call EFUNC(medical,setHitPointDamage); - _unit spawn { - sleep 0.5; - [_this, "", 0, objNull, objNull] call EFUNC(medical,handleDamage); - }; - } else { - _unit setDamage (damage _unit + _damage); - }; - - }; -}; From 05d209191cf60d82ac8581a50f0f2fda18079d3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Badano?= Date: Sun, 25 Jan 2015 01:05:19 -0300 Subject: [PATCH 3/4] common: fixed fnc_addLineToDebugDraw --- addons/common/functions/fnc_addLineToDebugDraw.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/common/functions/fnc_addLineToDebugDraw.sqf b/addons/common/functions/fnc_addLineToDebugDraw.sqf index cfe45359c9..1c7d5d5cd1 100644 --- a/addons/common/functions/fnc_addLineToDebugDraw.sqf +++ b/addons/common/functions/fnc_addLineToDebugDraw.sqf @@ -29,7 +29,7 @@ if (count GVAR(debugLines) < 100) then { if (isNil QGVAR(debugDrawHandler)) then { GVAR(debugDrawHandler) = addMissionEventHandler ["Draw3D", { if (count GVAR(debugLines) == 0) exitWith { - removeMissionEventHandler GVAR(debugDrawHandler); + removeMissionEventHandler ["Draw3D", GVAR(debugDrawHandler)]; GVAR(debugDrawHandler) = nil; }; From 30cd9a7499eda9287e7ae4815f8a349dd6041206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Badano?= Date: Sun, 25 Jan 2015 01:16:44 -0300 Subject: [PATCH 4/4] me too --- addons/backblast/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/backblast/config.cpp b/addons/backblast/config.cpp index 88de936cf9..8c59163c54 100644 --- a/addons/backblast/config.cpp +++ b/addons/backblast/config.cpp @@ -6,7 +6,7 @@ class CfgPatches { weapons[] = {}; requiredVersion = REQUIRED_VERSION; requiredAddons[] = {"ace_common"}; - author[] = {"commy2", "KoffeinFlummi"}; + author[] = {"commy2", "KoffeinFlummi", "CAA-Picard"}; authorUrl = "https://github.com/commy2/"; VERSION_CONFIG; };