2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2016-05-03 20:37:02 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal
|
2016-07-04 22:04:58 +00:00
|
|
|
* Get the distance to the nearest detectable object
|
2016-05-03 20:37:02 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Unit <OBJECT>
|
|
|
|
* 1: Configuration <ARRAY>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* [isDetected <BOOL>, mine <OBJECT>, distance <NUMBER>] <ARRAY>
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [ace_player, DETECTOR_CONFIG] call ace_minedetector_fnc_getDetectedObject
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
params ["_unit", "_detectorConfig"];
|
2016-07-04 22:04:58 +00:00
|
|
|
_detectorConfig params ["", "_radius"];
|
2016-05-03 20:37:02 +00:00
|
|
|
|
|
|
|
private _worldPosition = _unit modelToWorld (_unit selectionPosition "granat");
|
2016-07-04 22:32:40 +00:00
|
|
|
private _ref = (_unit weaponDirection currentWeapon _unit) call EFUNC(common,createOrthonormalReference);
|
|
|
|
_ref params ["_v1", "_v2", "_v3"];
|
|
|
|
private _detectorPointAGL = _worldPosition vectorAdd
|
|
|
|
(_v1 vectorMultiply ( 0.9 * __DR)) vectorAdd
|
|
|
|
(_v2 vectorMultiply (-0.2 * __DR)) vectorAdd
|
|
|
|
(_v3 vectorMultiply ( 0.4 * __DR));
|
2016-05-03 20:37:02 +00:00
|
|
|
|
2016-06-16 15:20:15 +00:00
|
|
|
private _nearestObjects = nearestObjects [_detectorPointAGL, [], _radius];
|
2016-05-03 20:37:02 +00:00
|
|
|
|
2016-05-07 17:08:36 +00:00
|
|
|
#ifdef DEBUG_MODE_FULL
|
2016-06-16 15:20:15 +00:00
|
|
|
GVAR(debugDetector) = [_detectorPointAGL, _nearestObjects];
|
2016-05-07 17:08:36 +00:00
|
|
|
#endif
|
2016-05-03 20:37:02 +00:00
|
|
|
|
2016-05-07 17:08:36 +00:00
|
|
|
private _isDetectable = false;
|
|
|
|
private _mine = objNull;
|
|
|
|
private _distance = -1;
|
2016-05-03 20:37:02 +00:00
|
|
|
|
2016-05-07 17:08:36 +00:00
|
|
|
{
|
2016-07-04 22:04:58 +00:00
|
|
|
private _objectType = typeOf _x;
|
2016-06-16 15:20:15 +00:00
|
|
|
|
2016-07-04 22:04:58 +00:00
|
|
|
_isDetectable = GVAR(detectableClasses) getVariable _objectType;
|
2017-10-15 11:13:16 +00:00
|
|
|
if (isNil "_isDetectable" || {(getModelInfo _x) select 0 == "empty.p3d"}) then {
|
2016-07-04 22:04:58 +00:00
|
|
|
_isDetectable = false;
|
2016-05-07 17:08:36 +00:00
|
|
|
};
|
2016-06-16 15:36:37 +00:00
|
|
|
|
2016-07-04 22:04:58 +00:00
|
|
|
// If a nun-null object was detected exit the search
|
|
|
|
if (_isDetectable && {!isNull _x}) exitWith {
|
|
|
|
_distance = _detectorPointAGL distance _x;
|
|
|
|
_mine = _x;
|
|
|
|
TRACE_3("return", _isDetectable, _mine, _distance);
|
|
|
|
};
|
2016-06-16 15:20:15 +00:00
|
|
|
} forEach _nearestObjects;
|
2016-05-03 20:37:02 +00:00
|
|
|
|
2016-05-07 17:08:36 +00:00
|
|
|
[_isDetectable, _mine, _distance];
|