Better LOS check

This commit is contained in:
PabstMirror 2015-04-11 21:42:57 -05:00
parent 8fc3b53507
commit c3c815db8d

View File

@ -15,7 +15,7 @@
*/
#include "script_component.hpp"
private ["_affected", "_strength", "_posGrenade", "_posUnit", "_angleGrenade", "_angleView", "_angleDiff", "_light"];
private ["_affected", "_strength", "_posGrenade", "_posUnit", "_angleGrenade", "_angleView", "_angleDiff", "_light", "_losCount"];
PARAMS_1(_grenade);
@ -53,8 +53,15 @@ _affected = _grenade nearEntities ["CAManBase", 20];
_eyePos = eyePos ACE_player; //PositionASL
_posGrenade set [2, (_posGrenade select 2) + 0.2]; // compensate for grenade glitching into ground
//Check for line of sight:
if (lineIntersects [_posGrenade, _eyePos, _grenade, _x]) then {
_losCount = 0;
//Check for line of sight (check 4 points in case grenade is stuck in an object or underground)
{
if (!lineIntersects [(_posGrenade vectorAdd _x), _eyePos, _grenade, ACE_player]) then {
_losCount = _losCount + 1;
};
} forEach [[0,0,0], [0,0,0.2], [0.1, 0.1, 0.1], [-0.1, -0.1, 0.1]];
TRACE_1("Line of sight count (out of 4)",_losCount);
if (_losCount == 0) then {
_strength = _strength / 10;
};
@ -74,7 +81,7 @@ _affected = _grenade nearEntities ["CAManBase", 20];
_strength = _strength - _strength * ((_angleDiff - 45) / 120);
};
TRACE_1("Final strength for player %1",_strength);
TRACE_1("Final strength for player",_strength);
//Add ace_medical pain effect: