diff --git a/addons/minedetector/CfgVehicles.hpp b/addons/minedetector/CfgVehicles.hpp index 18cceef722..f2ee240ac4 100644 --- a/addons/minedetector/CfgVehicles.hpp +++ b/addons/minedetector/CfgVehicles.hpp @@ -12,7 +12,7 @@ class CfgVehicles { class ACE_SelfActions { class ACE_Equipment { class GVAR(activate) { - displayName = "Activate Detector"; + displayName = CSTRING(ActivateDetector); condition = QUOTE(call FUNC(canActivateDetector)); statement = QUOTE(call FUNC(activateDetector)); showDisabled = 0; @@ -21,7 +21,7 @@ class CfgVehicles { exceptions[] = {}; }; class GVAR(deactivate) { - displayName = "Deactivate Detector"; + displayName = CSTRING(DeactivateDetector); condition = QUOTE(call FUNC(canDeactivateDetector)); statement = QUOTE(call FUNC(deactivateDetector)); showDisabled = 0; diff --git a/addons/minedetector/XEH_clientInit.sqf b/addons/minedetector/XEH_clientInit.sqf index ff868766cb..8f0da14fe0 100644 --- a/addons/minedetector/XEH_clientInit.sqf +++ b/addons/minedetector/XEH_clientInit.sqf @@ -18,3 +18,23 @@ deleteVehicle _helperObject; }; }] call EFUNC(common,addEventhandler); + + + +//Shows detector and mine posistions in 3d when debug is on +#ifdef DEBUG_MODE_FULL +GVAR(debugDetector) = []; +addMissionEventHandler ["Draw3D", { + if (GVAR(debugDetector) isEqualTo []) exitWith {}; + GVAR(debugDetector) params ["_detectorPointAGL", "_mines"]; + drawIcon3D ["\A3\ui_f\data\map\markers\military\dot_CA.paa", [0,0,1,1], _detectorPointAGL, 1, 1, 0, "detector", 1, 0.02, "PuristaMedium"]; + { + _name = format ["%1@%2", typeOf _x, (floor ((_x distance _detectorPointAGL) * 10)) / 10]; + if ((getNumber (configFile >> "CfgVehicles" >> (typeOf _x) >> QGVAR(detectable))) == 1) then { + drawIcon3D ["\A3\ui_f\data\map\markers\military\dot_CA.paa", [1,0,0,1], (ASLtoAGL (getPosASL _x)), 1, 1, 0, _name, 1, 0.02, "PuristaMedium"]; + } else { + drawIcon3D ["\A3\ui_f\data\map\markers\military\dot_CA.paa", [1,1,0,1], (ASLtoAGL (getPosASL _x)), 1, 1, 0, _name, 1, 0.02, "PuristaMedium"]; + }; + } forEach _mines; +}]; +#endif diff --git a/addons/minedetector/functions/fnc_canDeactivateDetector.sqf b/addons/minedetector/functions/fnc_canDeactivateDetector.sqf index d680fdbd49..3423d0685c 100644 --- a/addons/minedetector/functions/fnc_canDeactivateDetector.sqf +++ b/addons/minedetector/functions/fnc_canDeactivateDetector.sqf @@ -16,4 +16,4 @@ #include "script_component.hpp" -([ACE_player] call FUNC(hasDetector)) && ([ACE_player, currentWeapon ACE_player] call FUNC(isDetectorEnabled)); +([ACE_player] call FUNC(hasDetector)) && {[ACE_player, currentWeapon ACE_player] call FUNC(isDetectorEnabled)}; diff --git a/addons/minedetector/functions/fnc_detectorLoop.sqf b/addons/minedetector/functions/fnc_detectorLoop.sqf index e1b817cc1c..a8a3a1e4a3 100644 --- a/addons/minedetector/functions/fnc_detectorLoop.sqf +++ b/addons/minedetector/functions/fnc_detectorLoop.sqf @@ -35,7 +35,7 @@ if !([_unit, _type] call FUNC(isDetectorEnabled)) exitwith { if (ACE_player == _unit && {currentWeapon _unit == _type}) then { private _detected = [_unit, _detectorConfig] call FUNC(getDetectedObject); _detected params ["_hasDetected", "_object", "_distance"]; - if (_hasDetected && (ACE_time - _lastPlayed > 0.9)) then { + if (_hasDetected && {ACE_time - _lastPlayed > 0.9}) then { _args set [3, ACE_time]; _detectorConfig params ["_type", "_radius", "_detectableTypes", "_sounds"]; private _sound = _sounds select (_distance >= 1.2); diff --git a/addons/minedetector/functions/fnc_getDetectedObject.sqf b/addons/minedetector/functions/fnc_getDetectedObject.sqf index 26daca7b14..62eebe63d3 100644 --- a/addons/minedetector/functions/fnc_getDetectedObject.sqf +++ b/addons/minedetector/functions/fnc_getDetectedObject.sqf @@ -25,20 +25,28 @@ _detectorConfig params ["_type", "_radius", "_detectableTypes", "_sounds"]; private _worldPosition = _unit modelToWorld (_unit selectionPosition "granat"); private _direction = _unit weaponDirection "Put"; -_worldPosition params ["_posX", "_posY", "_posZ"]; -_direction params ["_dirX", "_dirY", "_dirZ"]; +private _detectorPointAGL = _worldPosition vectorAdd (_direction vectorMultiply __DR); -private _dPnt = [_posX + __DR * _dirX, _posY + __DR * _dirY, _posZ + __DR * _dirZ]; +private _mines = nearestObjects [_detectorPointAGL, _detectableTypes, _radius]; -private _mines = nearestObjects [_dPnt, _detectableTypes, _radius]; -if (_mines isEqualTo []) exitwith { - [false, objNull, -1]; -}; +#ifdef DEBUG_MODE_FULL +GVAR(debugDetector) = [_detectorPointAGL, _mines]; +#endif -// guaranteed to have at least one element. Lets get the first -private _mine = _mines select 0; -private _distance = _dPnt distance _mine; +private _isDetectable = false; +private _mine = objNull; +private _distance = -1; -private _isDetectable = getNumber (configFile >> "CfgVehicles" >> typeOf _mine >> QGVAR(detectable)); +{ + //Try all mines in range and use first detectable one: + if ((getNumber (configFile >> "CfgVehicles" >> (typeOf _x) >> QGVAR(detectable))) == 1) exitWith { + _isDetectable = true; + _mine = _x; + _distance = _detectorPointAGL distance _x; + }; + nil +} count _mines; -[(_isDetectable > 0), _mine, _distance]; +TRACE_3("return",_isDetectable, _mine, _distance); + +[_isDetectable, _mine, _distance]; diff --git a/addons/minedetector/functions/fnc_playDetectorSound.sqf b/addons/minedetector/functions/fnc_playDetectorSound.sqf index 973e51628a..38cc01dbb7 100644 --- a/addons/minedetector/functions/fnc_playDetectorSound.sqf +++ b/addons/minedetector/functions/fnc_playDetectorSound.sqf @@ -10,7 +10,7 @@ * None * * Example: - * ["example"] call ace_minedetector_fnc_playDetectorSound + * [player, "ace_buzz_1"] call ace_minedetector_fnc_playDetectorSound * * Public: No */ @@ -19,13 +19,17 @@ params ["_unit", "_detectorSound"]; -if (isNull _unit) exitwith {}; // TODO log error - unit does not exist +if (isNull _unit) exitwith { + ACE_LOGERROR_1("unit does not exist [%1]",_unit); +}; if (!alive _unit) exitwith { - // log error, unit is not alive + ACE_LOGERROR_1("unit is not alive [%1]",_unit); }; private _helperObject = _unit getvariable [QGVAR(helperLogic), objNull]; if !(isNull _helperObject) then { _helperObject attachto [_unit,[0,0,-3],""]; [_helperObject, _unit] say3D _detectorSound; +} else { + ACE_LOGERROR_1("helper does not exist [%1]",_helperObject); }; diff --git a/addons/minedetector/stringtable.xml b/addons/minedetector/stringtable.xml index 09cb27e936..e4386b02c1 100644 --- a/addons/minedetector/stringtable.xml +++ b/addons/minedetector/stringtable.xml @@ -4,5 +4,11 @@ Vallon + + Activate Detector + + + Deactivate Detector +