Merge pull request #2840 from acemod/fixOverpressure

Overpresure - Misc fixes
This commit is contained in:
PabstMirror 2015-11-20 15:38:24 -06:00
commit 0f62168250
4 changed files with 33 additions and 54 deletions

View File

@ -41,14 +41,14 @@ _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";
_distance = [_position, _direction, _backblastRange] call FUNC(getDistance);
_distance = [_position, _direction, _backblastRange, _firer] call FUNC(getDistance);
TRACE_1("Distance",_distance);

View File

@ -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);

View File

@ -7,60 +7,45 @@
* 0: Pos ASL of origin (ARRAY>
* 1: Direction <ARRAY>
* 2: Max distance to search <Number>
* 3: Shooter <OBJECT>
*
* Return value:
* Distance to intersection (+- 0.1 m) <NUMBER>
* Distance to intersection (999 if distance is greater than max) <NUMBER>
*
* 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"
EXPLODE_3_PVT(_this,_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};
};
if (_distance > _maxDistance) exitWith {_distance};
// If the intersection was with the terrain, check slope
if (_terrainIntersect || _lastTerrainIntersect) exitWith {
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];
// 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

View File

@ -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]);