Update fn_fieldOfView

Made by @Victor-the-Cleaner
This commit is contained in:
A Man
2022-05-17 15:59:47 +02:00
parent 24492798a8
commit b276f1f8c5
2 changed files with 27 additions and 27 deletions

View File

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

View File

@@ -8,7 +8,7 @@
// <center angle of sector> and <sector width>. // <center angle of sector> and <sector width>.
// //
// Example: // Example:
// [position player, getDir player, 30, position enemy_tank] call BIS_fnc_inAngleSector // [position player, getDir player, 30, position enemy_tank] call fnc_inAngleSector
// will return true if the vehicle named enemy_tank is within 30 degrees of where the player is pointing. // will return true if the vehicle named enemy_tank is within 30 degrees of where the player is pointing.
// //
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////