2016-05-03 20:37:02 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal
|
|
|
|
* Handle mine detection in a PFH loop
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: args <ARRAY>
|
|
|
|
* 1: PHD Id <PFH_ID>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Example:
|
|
|
|
* [[args], 2] call ACE_minedetector_fnc_detectorLoop
|
|
|
|
*
|
2016-05-03 20:37:02 +00:00
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
|
|
|
params ["_args", "_idPFH"];
|
|
|
|
_args params ["_unit", "_type", "_detectorConfig", "_lastPlayed"];
|
|
|
|
|
2016-07-07 15:38:53 +00:00
|
|
|
// If locality switched just turn off the detector
|
|
|
|
if !(local _unit) exitWith {
|
|
|
|
[QGVAR(disableDetector), [_unit, _type], _unit] call CBA_fnc_targetEvent;
|
|
|
|
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
|
|
|
};
|
|
|
|
|
2016-06-20 18:58:37 +00:00
|
|
|
if !([_unit, _type] call FUNC(hasDetector)) exitWith {
|
2016-05-03 20:37:02 +00:00
|
|
|
// disable detector type
|
|
|
|
[_unit, _type] call FUNC(disableDetector);
|
|
|
|
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
|
|
|
};
|
|
|
|
|
2016-06-16 15:33:21 +00:00
|
|
|
if (!alive _unit) exitWith {
|
2016-05-03 20:37:02 +00:00
|
|
|
[_unit, _type] call FUNC(disableDetector);
|
|
|
|
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
|
|
|
};
|
|
|
|
|
2016-06-16 15:33:21 +00:00
|
|
|
if !([_unit, _type] call FUNC(isDetectorEnabled)) exitWith {
|
2016-05-03 20:37:02 +00:00
|
|
|
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
|
|
|
};
|
|
|
|
|
2016-07-07 15:38:53 +00:00
|
|
|
if (currentWeapon _unit != _type) exitWith {
|
|
|
|
[_unit, _type] call FUNC(disableDetector);
|
|
|
|
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
|
|
|
};
|
2016-07-04 22:04:58 +00:00
|
|
|
|
|
|
|
private _detected = [[_unit, _detectorConfig], FUNC(getDetectedObject), _unit, QGVAR(detectedObjects), 0.15] call EFUNC(common,cachedCall);
|
2016-07-07 14:17:57 +00:00
|
|
|
_detected params ["_hasDetected", "_mine", "_distance"];
|
2016-07-04 22:04:58 +00:00
|
|
|
|
|
|
|
if (!_hasDetected) exitWith {};
|
|
|
|
|
2016-07-07 14:17:57 +00:00
|
|
|
// Launch a local event stating which mine was detected for mission purposes
|
|
|
|
[QGVAR(mineDetected), [_unit, _mine, _distance]] call CBA_fnc_localEvent;
|
|
|
|
|
2016-07-04 22:04:58 +00:00
|
|
|
private _distanceTiming = switch (true) do {
|
|
|
|
case (_distance >= 2): {1};
|
|
|
|
case (_distance >= 1.25): {0.85};
|
|
|
|
case (_distance >= 0.75): {0.7};
|
|
|
|
default {0.5};
|
|
|
|
};
|
|
|
|
|
|
|
|
if (CBA_missionTime - _lastPlayed < _distanceTiming) exitWith {};
|
|
|
|
|
|
|
|
_args set [3, CBA_missionTime];
|
2016-07-07 01:14:26 +00:00
|
|
|
_detectorConfig params ["", "", "_soundClasses"];
|
|
|
|
private _soundClass = switch (true) do {
|
|
|
|
case (_distance >= 2): {_soundClasses select 3};
|
|
|
|
case (_distance >= 1.25): {_soundClasses select 2};
|
|
|
|
case (_distance >= 0.5): {_soundClasses select 1};
|
|
|
|
default {_soundClasses select 0};
|
2016-05-03 20:37:02 +00:00
|
|
|
};
|
2016-07-07 01:14:26 +00:00
|
|
|
|
|
|
|
[_unit, _soundClass] call FUNC(playDetectorSound);
|