From 391bfc160a1f2f75d19fce9c9424f08816e41ff7 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Wed, 11 Nov 2015 13:24:27 -0600 Subject: [PATCH 1/2] Overpresure - Misc fixes - Fix passing magazine/ammo to overpressure event - Use AGL for nearEntities - Fix getDistance returning nil --- .../functions/fnc_fireLauncherBackblast.sqf | 4 ++-- .../functions/fnc_fireOverpressureZone.sqf | 2 +- addons/overpressure/functions/fnc_getDistance.sqf | 10 ++++++---- .../overpressure/functions/fnc_overpressureDamage.sqf | 8 +------- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/addons/overpressure/functions/fnc_fireLauncherBackblast.sqf b/addons/overpressure/functions/fnc_fireLauncherBackblast.sqf index 1653fce9e1..672031676e 100644 --- a/addons/overpressure/functions/fnc_fireLauncherBackblast.sqf +++ b/addons/overpressure/functions/fnc_fireLauncherBackblast.sqf @@ -41,10 +41,10 @@ _var params["_backblastAngle","_backblastRange","_backblastDamage"]; // Damage to others private "_affected"; -_affected = getPos _projectile nearEntities ["CAManBase", _backblastRange]; +_affected = (ASLtoAGL _position) nearEntities ["CAManBase", _backblastRange]; // Let each client handle their own affected units -["overpressure", _affected, [_firer, _position, _direction, _weapon]] call EFUNC(common,targetEvent); +["overpressure", _affected, [_firer, _position, _direction, _weapon, _magazine, _ammo]] call EFUNC(common,targetEvent); // Damage to the firer private "_distance"; diff --git a/addons/overpressure/functions/fnc_fireOverpressureZone.sqf b/addons/overpressure/functions/fnc_fireOverpressureZone.sqf index 3068928ba4..02de0eb311 100644 --- a/addons/overpressure/functions/fnc_fireOverpressureZone.sqf +++ b/addons/overpressure/functions/fnc_fireOverpressureZone.sqf @@ -40,7 +40,7 @@ _var params["_dangerZoneAngle","_dangerZoneRange","_dangerZoneDamage"]; // Damage to others private "_affected"; -_affected = getPos _projectile nearEntities ["CAManBase", _dangerZoneRange]; +_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); diff --git a/addons/overpressure/functions/fnc_getDistance.sqf b/addons/overpressure/functions/fnc_getDistance.sqf index 3b3103d951..6c5a5e6500 100644 --- a/addons/overpressure/functions/fnc_getDistance.sqf +++ b/addons/overpressure/functions/fnc_getDistance.sqf @@ -13,7 +13,8 @@ */ #include "script_component.hpp" -EXPLODE_3_PVT(_this,_posASL,_direction,_maxDistance); +params ["_posASL", "_direction", "_maxDistance"]; +TRACE_3("params",_posASL,_direction,_maxDistance); private ["_distance", "_interval", "_line", "_intersections", "_terrainIntersect", "_lastTerrainIntersect"]; @@ -42,20 +43,21 @@ while { }; _distance = _distance + ([1, -1] select (_intersections > 0 || _terrainIntersect)) * _interval; - if (_distance > _maxDistance) exitWith {_distance = 999}; }; +TRACE_4("while done",_distance,_maxDistance,_terrainIntersect,_lastTerrainIntersect); + if (_distance > _maxDistance) exitWith {_distance}; // If the intersection was with the terrain, check slope -if (_terrainIntersect || _lastTerrainIntersect) exitWith { +if (_terrainIntersect || _lastTerrainIntersect) then { private ["_slope","_angle"]; _slope = surfaceNormal (_posASL vectorAdd (_direction vectorMultiply _distance)); // Calculate the angle between the terrain and the back blast direction _angle = 90 - acos (- (_slope vectorDotProduct _direction)); - //systemChat format ["Angle: %1", _angle]; + TRACE_3("Terrain Intersect",_slope,_direction,_angle); // Angles is below 25º, no backblast at all if (_angle < 25) exitWith {_distance = 999}; // Angles is below 45º the distance is increased according to the difference diff --git a/addons/overpressure/functions/fnc_overpressureDamage.sqf b/addons/overpressure/functions/fnc_overpressureDamage.sqf index a39aec3c14..f9c58050e0 100644 --- a/addons/overpressure/functions/fnc_overpressureDamage.sqf +++ b/addons/overpressure/functions/fnc_overpressureDamage.sqf @@ -30,12 +30,6 @@ _var params["_overpressureAngle","_overpressureRange","_overpressureDamage"]; TRACE_4("Parameters:",_overpressureAngle,_overpressureRange,_overpressureDamage,_weapon); -private "_pos"; -_pos = _posASL; -if (!surfaceIsWater _pos) then { - _pos = ASLtoATL _pos; -}; - { if (local _x && {_x != _firer} && {vehicle _x == _x}) then { private ["_targetPositionASL", "_relativePosition", "_axisDistance", "_distance", "_angle", "_line", "_line2"]; @@ -68,4 +62,4 @@ if (!surfaceIsWater _pos) then { }; }; }; -} forEach (_pos nearEntities ["CAManBase", _overpressureRange]); +} forEach ((ASLtoAGL _posASL) nearEntities ["CAManBase", _overpressureRange]); From 9b2c79e7e117876fe8196a95feb7a6ba4cbd9c96 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Wed, 11 Nov 2015 14:12:42 -0600 Subject: [PATCH 2/2] getDistance - use lineIntersectsSurfaces --- .../functions/fnc_fireLauncherBackblast.sqf | 2 +- .../functions/fnc_getDistance.sqf | 71 +++++++------------ 2 files changed, 28 insertions(+), 45 deletions(-) diff --git a/addons/overpressure/functions/fnc_fireLauncherBackblast.sqf b/addons/overpressure/functions/fnc_fireLauncherBackblast.sqf index 672031676e..e457e023c6 100644 --- a/addons/overpressure/functions/fnc_fireLauncherBackblast.sqf +++ b/addons/overpressure/functions/fnc_fireLauncherBackblast.sqf @@ -48,7 +48,7 @@ _affected = (ASLtoAGL _position) nearEntities ["CAManBase", _backblastRange]; // Damage to the firer private "_distance"; -_distance = [_position, _direction, _backblastRange] call FUNC(getDistance); +_distance = [_position, _direction, _backblastRange, _firer] call FUNC(getDistance); TRACE_1("Distance",_distance); diff --git a/addons/overpressure/functions/fnc_getDistance.sqf b/addons/overpressure/functions/fnc_getDistance.sqf index 6c5a5e6500..a583700127 100644 --- a/addons/overpressure/functions/fnc_getDistance.sqf +++ b/addons/overpressure/functions/fnc_getDistance.sqf @@ -7,62 +7,45 @@ * 0: Pos ASL of origin (ARRAY> * 1: Direction * 2: Max distance to search + * 3: Shooter * * Return value: - * Distance to intersection (+- 0.1 m) + * Distance to intersection (999 if distance is greater than max) + * + * Example: + * [[1823.41,5729.05,6.66627], [-0.953255,0.109689,-0.281554], 15, ace_player] call ace_overpressure_fnc_getDistance + * */ #include "script_component.hpp" -params ["_posASL", "_direction", "_maxDistance"]; +params ["_posASL", "_direction", "_maxDistance", "_shooter"]; TRACE_3("params",_posASL,_direction,_maxDistance); -private ["_distance", "_interval", "_line", "_intersections", "_terrainIntersect", "_lastTerrainIntersect"]; +local _intersections = lineIntersectsSurfaces [_posASL, _posASL vectorAdd (_direction vectorMultiply _maxDistance), _shooter, objNull, true, 99]; -_distance = _maxDistance; -_interval = _distance; -_line = [_posASL, []]; -_terrainIntersect = false; -_lastTerrainIntersect = false; +TRACE_1("lineIntersectsSurfaces",_intersections); -while { - _interval > 0.1 -} do { - _lastTerrainIntersect = _terrainIntersect; - _interval = _interval / 2; +local _distance = 999; - _line set [1, _posASL vectorAdd (_direction vectorMultiply _distance)]; +{ + _x params ["_intersectPosASL", "_surfaceNormal", "_intersectObject"]; - _intersections = { - _x isKindOf "Static" || {_x isKindOf "AllVehicles"} - } count (lineIntersectsWith _line); + //Hit something solid that can reflect - (Static covers Building) + if ((isNull _intersectObject) || {(_intersectObject isKindOf "Static") || {_intersectObject isKindOf "AllVehicles"}}) exitWith { + _distance = _posASL vectorDistance _intersectPosASL; + TRACE_3("hit solid object",_distance,_intersectObject,typeOf _intersectObject); - _terrainIntersect = if (_intersections > 0) then { - false - } else { - terrainIntersectASL _line + if (isNull _intersectObject) then { //Terrain: + // Calculate the angle between the terrain and the back blast direction + _angle = 90 - acos (- (_surfaceNormal vectorDotProduct _direction)); + TRACE_3("Terrain Intersect",_surfaceNormal,_direction,_angle); + // Angles is below 25deg, no backblast at all + if (_angle < 25) exitWith {_distance = 999}; + // Angles is below 45deg the distance is increased according to the difference + if (_angle < 45) exitWith {_distance = _distance * (5 - 4 * sqrt ((_angle - 25)/20))}; + // Angles above 45degcreate full backblast + }; }; - - _distance = _distance + ([1, -1] select (_intersections > 0 || _terrainIntersect)) * _interval; - if (_distance > _maxDistance) exitWith {_distance = 999}; -}; - -TRACE_4("while done",_distance,_maxDistance,_terrainIntersect,_lastTerrainIntersect); - -if (_distance > _maxDistance) exitWith {_distance}; - -// If the intersection was with the terrain, check slope -if (_terrainIntersect || _lastTerrainIntersect) then { - private ["_slope","_angle"]; - _slope = surfaceNormal (_posASL vectorAdd (_direction vectorMultiply _distance)); - // Calculate the angle between the terrain and the back blast direction - _angle = 90 - acos (- (_slope vectorDotProduct _direction)); - - TRACE_3("Terrain Intersect",_slope,_direction,_angle); - // Angles is below 25º, no backblast at all - if (_angle < 25) exitWith {_distance = 999}; - // Angles is below 45º the distance is increased according to the difference - if (_angle < 45) exitWith {_distance = _distance * (5 - 4 * sqrt ((_angle - 25)/20))}; - // Angles above 45º create full backblast -}; +} forEach _intersections; _distance