diff --git a/SQF/dayz_code/compile/fn_fieldOfView.sqf b/SQF/dayz_code/compile/fn_fieldOfView.sqf index 1d2f461c3..5f591de08 100644 --- a/SQF/dayz_code/compile/fn_fieldOfView.sqf +++ b/SQF/dayz_code/compile/fn_fieldOfView.sqf @@ -1,39 +1,39 @@ // This function checks to see if a potential zombie spawn position is in the field of view of near players. -private ["_isOk","_zPos","_fov","_safeDistance","_farDistance","_xasl","_eye","_ed","_deg"]; +local _zASL = +(_this select 0); // zombie position ATL -_isOk = true; -_zPos = +(_this select 0); -if (count _zPos < 3) exitWith { - diag_log format["%1::fn_fieldOfView illegal pos %2", __FILE__, _zPos]; +if (count _zASL < 3) exitWith { + //diag_log format["%1::fn_fieldOfView illegal pos %2", __FILE__, _zASL]; false }; -_zPos = ATLtoASL _zPos; -_fov = _this select 1; // players half field of view -_safeDistance = _this select 2; // minimum distance. closer is wrong -_farDistance = _this select 3; // distance further we won't check -_zPos set [2, (_zPos select 2) + 1.7]; +_zASL set [2, ((ATLtoASL _zASL) select 2) + 1.7]; // approximate eyePos of zombie + +local _isOk = true; +local _fov = _this select 1; // 30 // players half field of view +local _safeDistance = _this select 2; // 10 // minimum distance +local _farDistance = _this select 3; // 200 // ignore anything beyond this distance + +scopeName "exit"; { - _xasl = getPosASL _x; - if (_xasl distance _zPos < _farDistance) then { - if (_xasl distance _zPos < _safeDistance) then { - _isOk = false; - } else { - _eye = eyePos _x; // ASL - _ed = eyeDirection _x; - _ed = (_ed select 0) atan2 (_ed select 1); - _deg = [_xasl, _zPos] call BIS_fnc_dirTo; - _deg = (_deg - _ed + 720) % 360; - if (_deg > 180) then { _deg = _deg - 360; }; - if ((abs(_deg) < _fov) && {( // in right angle sector? - (!(terrainIntersectASL [_zPos, _eye]) // no terrain between? - && {(!(lineIntersects [_zPos, _eye]))}) // and no object between? - )}) then { + local _pASL = getPosASL _x; // player position ASL + local _dist = _pASL distance _zASL; + + if (_dist < _safeDistance) exitWith {_isOk = false}; // zombie is too close + + if (_dist < _farDistance) then { // zombie is within range + + local _dir = eyeDirection _x; // only x,y coords are useful here + _dir = (((_dir select 0) atan2 (_dir select 1)) + 360) % 360;; // convert vector to CW direction + + if ([_pASL, _dir, _fov * 2, _zASL] call fnc_inAngleSector) then { // zombie within player's FOV + local _eye = eyePos _x; + + if (!(lineIntersects [_eye, _zASL]) && {!(terrainIntersectASL [_eye, _zASL])}) then { // clear line of sight from player to zombie _isOk = false; + breakTo "exit"; }; }; }; - if (!_isOk) exitWith {false}; } count playableUnits; _isOk diff --git a/SQF/dayz_code/compile/fn_inAngleSector.sqf b/SQF/dayz_code/compile/fn_inAngleSector.sqf index bcc6033df..b2573e9aa 100644 --- a/SQF/dayz_code/compile/fn_inAngleSector.sqf +++ b/SQF/dayz_code/compile/fn_inAngleSector.sqf @@ -8,7 +8,7 @@ //