diff --git a/addons/minedetector/ACE_detector.hpp b/addons/minedetector/ACE_detector.hpp index b6effc2436..f575ab9cd7 100644 --- a/addons/minedetector/ACE_detector.hpp +++ b/addons/minedetector/ACE_detector.hpp @@ -1,10 +1,10 @@ class ACE_detector { - class detectableObjects { - }; class detectors { class ACE_VMM3 { radius = 2.5; - sounds[] = {"ace_detector_1", "ace_detector_2", "ace_detector_3", "ace_detector_4"}; + name = "ace_detector_1"; + sound = QUOTE(PATHTO_R(sounds\metal_detector.wss)); + pitchs[] = {1, 0.9, 0.8, 0.7}; }; class ACE_VMH3: ACE_VMM3 { }; diff --git a/addons/minedetector/CfgSounds.hpp b/addons/minedetector/CfgSounds.hpp deleted file mode 100644 index 544bf94379..0000000000 --- a/addons/minedetector/CfgSounds.hpp +++ /dev/null @@ -1,22 +0,0 @@ -class CfgSounds { - class ace_detector_1 { - name = "ace_detector_1"; - sound[] = {QUOTE(PATHTOF(sounds\metal_detector.wav)), "db+1", 1}; - titles[] = {}; - }; - class ace_detector_2 { - name = "ace_detector_2"; - sound[] = {QUOTE(PATHTOF(sounds\metal_detector.wav)), "db+1", 0.9}; - titles[] = {}; - }; - class ace_detector_3 { - name = "ace_detector_3"; - sound[] = {QUOTE(PATHTOF(sounds\metal_detector.wav)), "db+1", 0.8}; - titles[] = {}; - }; - class ace_detector_4 { - name = "ace_detector_4"; - sound[] = {QUOTE(PATHTOF(sounds\metal_detector.wav)), "db+1", 0.7}; - titles[] = {}; - }; -}; diff --git a/addons/minedetector/CfgVehicles.hpp b/addons/minedetector/CfgVehicles.hpp index c486a049e3..1f770df675 100644 --- a/addons/minedetector/CfgVehicles.hpp +++ b/addons/minedetector/CfgVehicles.hpp @@ -15,8 +15,6 @@ class CfgVehicles { displayName = CSTRING(ActivateDetector); condition = QUOTE(call FUNC(canActivateDetector)); statement = QUOTE(call FUNC(activateDetector)); - showDisabled = 0; - priority = 0.1; icon = QPATHTOF(ui\icon_mineDetectorOn.paa); exceptions[] = {}; }; @@ -24,8 +22,6 @@ class CfgVehicles { displayName = CSTRING(DeactivateDetector); condition = QUOTE(call FUNC(canDeactivateDetector)); statement = QUOTE(call FUNC(deactivateDetector)); - showDisabled = 0; - priority = 0.1; icon = QPATHTOF(ui\icon_mineDetectorOff.paa); exceptions[] = {}; }; diff --git a/addons/minedetector/XEH_clientInit.sqf b/addons/minedetector/XEH_clientInit.sqf index 83aca7467a..ca660ad51d 100644 --- a/addons/minedetector/XEH_clientInit.sqf +++ b/addons/minedetector/XEH_clientInit.sqf @@ -1,27 +1,30 @@ #include "script_component.hpp" +// Create a dictionary to store detector configs +GVAR(detectorConfigs) = call CBA_fnc_createNamespace; + +// Create a dictionary of detectable classnames +GVAR(detectableClasses) = call CBA_fnc_createNamespace; +{ + if ((getNumber (_x >> QGVAR(detectable))) == 1) then { + GVAR(detectableClasses) setVariable [configName _x, true]; + }; +} forEach (configProperties [configFile >> "CfgVehicles", "isClass _x", true]); +{ + if ((getNumber (_x >> QGVAR(detectable))) == 1) then { + GVAR(detectableClasses) setVariable [configName _x, true]; + }; +} forEach (configProperties [configFile >> "CfgAmmo", "isClass _x", true]); + [QGVAR(detectorEnabled), { params ["_unit", "_type"]; private _config = [_type] call FUNC(getDetectorConfig); - private _helperObject = "ACE_LogicDummy" createVehicleLocal (getPos _unit); - _unit setVariable [QGVAR(helperLogic), _helperObject]; - - [FUNC(detectorLoop), 0.01, [_unit, _type, _config, CBA_missionTime, _helperObject]] call CBA_fnc_addPerFrameHandler; + [FUNC(detectorLoop), 0.05, [_unit, _type, _config, CBA_missionTime - 0.25]] call CBA_fnc_addPerFrameHandler; }] call CBA_fnc_addEventHandler; -[QGVAR(detectorDisabled), { - params ["_unit", "_type"]; - private _helperObject = _unit getVariable [QGVAR(helperLogic), objNull]; - if !(isNull _helperObject) then { - deleteVehicle _helperObject; - }; -}] call CBA_fnc_addEventHandler; - - - -//Shows detector and mine posistions in 3d when debug is on +// Shows detector and mine posistions in 3d when debug is on #ifdef DEBUG_MODE_FULL GVAR(debugDetector) = []; addMissionEventHandler ["Draw3D", { diff --git a/addons/minedetector/XEH_preInit.sqf b/addons/minedetector/XEH_preInit.sqf index 9529c201c5..a7feade1c3 100644 --- a/addons/minedetector/XEH_preInit.sqf +++ b/addons/minedetector/XEH_preInit.sqf @@ -4,7 +4,4 @@ ADDON = false; #include "XEH_PREP.hpp" -// TODO load from config instead of hardcoded in sqf -GVAR(ALL_DETECTABLE_TYPES) = ["ACE_Explosive_Object", "ACE_Explosive_Helper", "ACE_Explosives_Place", "ModuleMine_F", "TimeBombCore", "MineBase", "DirectionalBombBase", "BoundingMineBase", "PipeBombBase"]; - ADDON = true; diff --git a/addons/minedetector/config.cpp b/addons/minedetector/config.cpp index 9926d08f8c..9b3fbf2581 100644 --- a/addons/minedetector/config.cpp +++ b/addons/minedetector/config.cpp @@ -18,5 +18,4 @@ class CfgPatches { #include "CfgWeapons.hpp" #include "CfgAmmo.hpp" #include "CfgVehicles.hpp" -#include "CfgSounds.hpp" #include "ACE_detector.hpp" diff --git a/addons/minedetector/functions/fnc_detectorLoop.sqf b/addons/minedetector/functions/fnc_detectorLoop.sqf index 4a708147e2..4217a0b4de 100644 --- a/addons/minedetector/functions/fnc_detectorLoop.sqf +++ b/addons/minedetector/functions/fnc_detectorLoop.sqf @@ -32,24 +32,28 @@ if !([_unit, _type] call FUNC(isDetectorEnabled)) exitWith { [_idPFH] call CBA_fnc_removePerFrameHandler; }; -if (ACE_player == _unit && {currentWeapon _unit == _type}) then { - private _detected = [_unit, _detectorConfig] call FUNC(getDetectedObject); - _detected params ["_hasDetected", "_object", "_distance"]; - 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 (_hasDetected && {(CBA_missionTime - _lastPlayed > _distanceTiming)}) then { - _args set [3, CBA_missionTime]; - _detectorConfig params ["_type", "_radius", "_detectableTypes", "_sounds"]; - private _sound = switch (true) do { - case (_distance >= 2): {_sounds select 3}; - case (_distance >= 1.25): {_sounds select 2}; - case (_distance >= 0.5): {_sounds select 1}; - default {_sounds select 0}; - }; - [_unit, _sound, true] call FUNC(playDetectorSound); - }; +if (ACE_player != _unit || {currentWeapon _unit != _type}) exitWith {}; + +private _detected = [[_unit, _detectorConfig], FUNC(getDetectedObject), _unit, QGVAR(detectedObjects), 0.15] call EFUNC(common,cachedCall); +_detected params ["_hasDetected", "", "_distance"]; + +if (!_hasDetected) exitWith {}; + +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]; +_detectorConfig params ["", "", "_sound", "_pitchs"]; +private _pitch = switch (true) do { + case (_distance >= 2): {_pitchs select 3}; + case (_distance >= 1.25): {_pitchs select 2}; + case (_distance >= 0.5): {_pitchs select 1}; + default {_pitchs select 0}; +}; +[_unit, _sound, _pitch] call FUNC(playDetectorSound); diff --git a/addons/minedetector/functions/fnc_getDetectedObject.sqf b/addons/minedetector/functions/fnc_getDetectedObject.sqf index 79c20964ca..6e6081ed58 100644 --- a/addons/minedetector/functions/fnc_getDetectedObject.sqf +++ b/addons/minedetector/functions/fnc_getDetectedObject.sqf @@ -1,6 +1,6 @@ /* * Author: Glowbal - * Enables the mine detector + * Get the distance to the nearest detectable object * * Arguments: * 0: Unit @@ -15,16 +15,13 @@ * Public: No */ -#define __DR 1.3 - #include "script_component.hpp" params ["_unit", "_detectorConfig"]; -_detectorConfig params ["_type", "_radius", "_detectableTypes", "_sounds"]; +_detectorConfig params ["", "_radius"]; private _worldPosition = _unit modelToWorld (_unit selectionPosition "granat"); private _direction = _unit weaponDirection "Put"; - private _detectorPointAGL = _worldPosition vectorAdd (_direction vectorMultiply __DR); private _nearestObjects = nearestObjects [_detectorPointAGL, [], _radius]; @@ -38,27 +35,19 @@ private _mine = objNull; private _distance = -1; { - private _object = _x; + private _objectType = typeOf _x; - if ({_object isKindOf _x} count _detectableTypes > 0) then { - //Try all unprepared 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; - }; - //Try all prepared mines in range and use first detectable one: - if ((getNumber (configFile >> "CfgAmmo" >> (typeOf _x) >> QGVAR(detectable))) == 1) exitWith { - _isDetectable = true; - _mine = _x; - _distance = _detectorPointAGL distance _x; - }; + _isDetectable = GVAR(detectableClasses) getVariable _objectType; + if (isNil "_isDetectable") then { + _isDetectable = false; }; - if (!isNull _mine) exitWith {}; - + // 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); + }; } forEach _nearestObjects; -TRACE_3("return",_isDetectable,_mine,_distance); - [_isDetectable, _mine, _distance]; diff --git a/addons/minedetector/functions/fnc_getDetectorConfig.sqf b/addons/minedetector/functions/fnc_getDetectorConfig.sqf index 87b9d0a88a..17b609cd77 100644 --- a/addons/minedetector/functions/fnc_getDetectorConfig.sqf +++ b/addons/minedetector/functions/fnc_getDetectorConfig.sqf @@ -1,6 +1,6 @@ /* * Author: Glowbal - * Get the mine detector configuration from the config file + * Get the mine detector configuration from the cache or config file * * Arguments: * 0: Detector class name @@ -18,14 +18,19 @@ params ["_detectorType"]; -private _config = (configFile >> "ACE_detector" >> "detectors" >> _detectorType); -if (isClass _config) then { - [ - _detectorType, - getNumber (_config >> "radius"), - GVAR(ALL_DETECTABLE_TYPES), // TODO read from config and use this as a back up value instead - getArray (_config >> "sounds") - ]; -} else { - []; +private _detectorConfig = GVAR(detectorConfigs) getVariable _detectorType; +if (isNil "_detectorConfig") then { + private _cfgEntry = (configFile >> "ACE_detector" >> "detectors" >> _detectorType); + if (isClass _cfgEntry) then { + _detectorConfig = [ + _detectorType, + getNumber (_cfgEntry >> "radius"), + getText (_cfgEntry >> "sound"), + getArray (_cfgEntry >> "pitchs") + ]; + } else { + _detectorConfig = []; + }; + GVAR(detectorConfigs) setVariable [_detectorType, _detectorConfig]; }; +_detectorConfig diff --git a/addons/minedetector/functions/fnc_playDetectorSound.sqf b/addons/minedetector/functions/fnc_playDetectorSound.sqf index 4da6b5f45c..1fff29531c 100644 --- a/addons/minedetector/functions/fnc_playDetectorSound.sqf +++ b/addons/minedetector/functions/fnc_playDetectorSound.sqf @@ -4,20 +4,21 @@ * * Arguments: * 0: Unit - * 1: Sound class name + * 1: Sound file name + * 2: Sound pitch * * Return Value: * None * * Example: - * [player, "ace_buzz_1"] call ace_minedetector_fnc_playDetectorSound + * [player, "ace_buzz_1", 1] call ace_minedetector_fnc_playDetectorSound * * Public: No */ #include "script_component.hpp" -params ["_unit", "_detectorSound"]; +params ["_unit", "_sound", "_pitch"]; if (isNull _unit) exitWith { ACE_LOGERROR_1("unit does not exist [%1]",_unit); @@ -26,17 +27,6 @@ if (!alive _unit) exitWith { ACE_LOGERROR_1("unit is not alive [%1]",_unit); }; -private _helperObject = _unit getVariable [QGVAR(helperLogic), objNull]; -if (!isNull _helperObject) then { - deleteVehicle _helperObject; -}; -_helperObject = "ACE_LogicDummy" createVehicleLocal (getPos _unit); +private _posASL = AGLtoASL (_unit modelToWorld (_unit selectionPosition "granat")); -if !(isNull _helperObject) then { - _helperObject attachTo [_unit,[0,0,-3],""]; - _unit setVariable [QGVAR(helperLogic), _helperObject]; - - [_helperObject, _unit] say3D _detectorSound; -} else { - ACE_LOGERROR_1("helper does not exist [%1]",_helperObject); -}; +playSound3D [_sound, objNull, false, _posASL, 5, _pitch, 15]; diff --git a/addons/minedetector/script_component.hpp b/addons/minedetector/script_component.hpp index 935825a31c..f6a1d05dfc 100644 --- a/addons/minedetector/script_component.hpp +++ b/addons/minedetector/script_component.hpp @@ -16,3 +16,5 @@ #endif #include "\z\ace\addons\main\script_macros.hpp" + +#define __DR 1.3 diff --git a/addons/minedetector/sounds/metal_detector.wss b/addons/minedetector/sounds/metal_detector.wss new file mode 100644 index 0000000000..9f62569c10 Binary files /dev/null and b/addons/minedetector/sounds/metal_detector.wss differ