Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mine Detector - Added public framework #10785

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions addons/minedetector/ACE_detector.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
class ACE_detector {
class detectors {
class ACE_VMM3 {
detectorPosition[] = {1.3, -0.22, 0.4};
radius = 2.5;
sounds[] = {"ace_detector_1", "ace_detector_2", "ace_detector_3", "ace_detector_4"};
soundDistances[] = {0, 0.5, 1.25, 2};
soundIntervals[] = {0.5, 0.7, 0.85, 1};
soundIntervalDistances[] = {0, 0.75, 1.25, 2};
};
class ACE_VMH3: ACE_VMM3 {
detectorPosition[] = {1, -0.32, 0.3};
};
};
};
5 changes: 2 additions & 3 deletions addons/minedetector/CfgAmmo.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
class CfgAmmo {

// seems to not get inherited
// Seems to not get inherited
class Default;
class TimeBombCore: Default {
GVAR(detectable) = 1;
};

// these below do get inherited
// These below do get inherited
class DirectionalBombCore;
class DirectionalBombBase: DirectionalBombCore {
GVAR(detectable) = 1;
Expand Down
2 changes: 2 additions & 0 deletions addons/minedetector/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ class Extended_PreStart_EventHandlers {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
};
};

class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
};
};

class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_postInit));
Expand Down
8 changes: 4 additions & 4 deletions addons/minedetector/CfgSounds.hpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
class CfgSounds {
class ace_detector_1 {
name = "ace_detector_1";
sound[] = {QUOTE(PATHTOF(sounds\metal_detector.wss)), "db+3", 1};
sound[] = {QPATHTOF(sounds\metal_detector.wss), "db+3", 1};
titles[] = {};
};
class ace_detector_2 {
name = "ace_detector_2";
sound[] = {QUOTE(PATHTOF(sounds\metal_detector.wss)), "db+3", 0.9};
sound[] = {QPATHTOF(sounds\metal_detector.wss), "db+3", 0.9};
titles[] = {};
};
class ace_detector_3 {
name = "ace_detector_3";
sound[] = {QUOTE(PATHTOF(sounds\metal_detector.wss)), "db+3", 0.8};
sound[] = {QPATHTOF(sounds\metal_detector.wss), "db+3", 0.8};
titles[] = {};
};
class ace_detector_4 {
name = "ace_detector_4";
sound[] = {QUOTE(PATHTOF(sounds\metal_detector.wss)), "db+3", 0.7};
sound[] = {QPATHTOF(sounds\metal_detector.wss), "db+3", 0.7};
titles[] = {};
};
};
19 changes: 10 additions & 9 deletions addons/minedetector/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,43 @@ class CfgVehicles {
class ACE_Equipment {
class GVAR(metalDetector) {
displayName = CSTRING(MetalDetector);
condition = QUOTE([ACE_player] call FUNC(hasDetector));
condition = QUOTE(_player call FUNC(hasDetector));
statement = "";
icon = QPATHTOF(ui\icon_mineDetector.paa);
exceptions[] = {};
class GVAR(activate) {
displayName = CSTRING(ActivateDetector);
condition = QUOTE(call FUNC(canActivateDetector));
statement = QUOTE(call FUNC(activateDetector));
condition = QUOTE(_player call FUNC(canActivateDetector));
statement = QUOTE(_player call FUNC(activateDetector));
icon = QPATHTOF(ui\icon_mineDetectorOn.paa);
exceptions[] = {};
};
class GVAR(deactivate) {
displayName = CSTRING(DeactivateDetector);
condition = QUOTE(call FUNC(canDeactivateDetector));
statement = QUOTE(call FUNC(deactivateDetector));
condition = QUOTE(_player call FUNC(canDeactivateDetector));
statement = QUOTE(_player call FUNC(deactivateDetector));
icon = QPATHTOF(ui\icon_mineDetectorOff.paa);
exceptions[] = {};
};
class GVAR(connectHeadphones) {
displayName = CSTRING(ConnectHeadphones);
condition = QUOTE(call FUNC(canConnectHeadphones));
statement = QUOTE([ARR_2(ACE_player,true)] call FUNC(connectHeadphones));
condition = QUOTE(_player call FUNC(canConnectHeadphones));
statement = QUOTE([ARR_2(_player,true)] call FUNC(connectHeadphones));
icon = ""; //TODO
exceptions[] = {};
};
class GVAR(disconnectHeadphones) {
displayName = CSTRING(DisconnectHeadphones);
condition = QUOTE(call FUNC(canDisconnectHeadphones));
statement = QUOTE([ARR_2(ACE_player,false)] call FUNC(connectHeadphones));
condition = QUOTE(_player call FUNC(canDisconnectHeadphones));
statement = QUOTE([ARR_2(_player,false)] call FUNC(connectHeadphones));
icon = ""; //TODO
exceptions[] = {};
};
};
};
};
};

class Items_base_F;
class ACE_Explosives_Place: Items_base_F {
GVAR(detectable) = 1;
Expand Down
8 changes: 4 additions & 4 deletions addons/minedetector/CfgWeapons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class CfgWeapons {
author = ECSTRING(common,ACETeam);
displayName = "VMM3";
descriptionShort = CSTRING(VMM3_Description);
model = QUOTE(PATHTOF(ace_wallon_vmm3.p3d));
picture = QUOTE(PATHTOF(data\equip\w_vmm3_ca.paa));
model = QPATHTOF(ace_wallon_vmm3.p3d);
picture = QPATHTOF(data\equip\w_vmm3_ca.paa);
magazines[] = { };
modes[] = { "Single" };
cursor = "EmptyCursor";
Expand Down Expand Up @@ -43,8 +43,8 @@ class CfgWeapons {
scope = 2;
displayName = "VMH3";
author = ECSTRING(common,ACETeam);
model = QUOTE(PATHTOF(ace_wallon_vmh3.p3d));
picture = QUOTE(PATHTOF(data\equip\w_vmh3_ca.paa));
model = QPATHTOF(ace_wallon_vmh3.p3d);
picture = QPATHTOF(data\equip\w_vmh3_ca.paa);
class WeaponSlotsInfo: WeaponSlotsInfo {
mass = 55;
};
Expand Down
9 changes: 3 additions & 6 deletions addons/minedetector/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@

PREP(activateDetector);
PREP(canActivateDetector);
PREP(canConnectHeadphones);
PREP(canDeactivateDetector);
PREP(canDisconnectHeadphones);
PREP(connectHeadphones);
PREP(activateDetector);
PREP(deactivateDetector);
PREP(hasDetector);
PREP(detectorLoop);
PREP(disableDetector);
PREP(enableDetector);
PREP(getDetectedObject);
PREP(getDetectorConfig);
PREP(hasDetector);
PREP(isDetectorEnabled);
PREP(playDetectorSound);
PREP(getDetectorConfig);
16 changes: 7 additions & 9 deletions addons/minedetector/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
// Create a dictionary to store detector configs
GVAR(detectorConfigs) = createHashMap;

[QGVAR(enableDetector), LINKFUNC(enableDetector)] call CBA_fnc_addEventHandler;
[QGVAR(disableDetector), LINKFUNC(disableDetector)] call CBA_fnc_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"];

drawIcon3D ["\A3\ui_f\data\map\markers\military\dot_CA.paa", [0, 0, 1, 1], _detectorPointAGL, 1, 1, 0, "detector", 1, 0.02, "PuristaMedium"];

{
private _name = format ["%1@%2", typeOf _x, (floor ((_x distance _detectorPointAGL) * 10)) / 10];
if ((getNumber (configOf _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"];
};

drawIcon3D ["\A3\ui_f\data\map\markers\military\dot_CA.paa", [[1, 1, 0, 1], [1, 0, 0, 1]] select (getNumber (configOf _x >> QGVAR(detectable)) == 1), ASLtoAGL (getPosASL _x), 1, 1, 0, _name, 1, 0.02, "PuristaMedium"];
} forEach _mines;
}];
#endif
4 changes: 3 additions & 1 deletion addons/minedetector/XEH_preStart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

#include "XEH_PREP.hpp"

// Cache detectable classes, see XEH_postInit.sqf
// Cache detectable classes
private _detectableClasses = [];

{
if ((getNumber (_x >> QGVAR(detectable))) == 1) then {
_detectableClasses pushBackUnique configName _x;
};
} forEach (configProperties [configFile >> "CfgVehicles", "isClass _x", true]);

{
if ((getNumber (_x >> QGVAR(detectable))) == 1) then {
_detectableClasses pushBackUnique configName _x;
Expand Down
2 changes: 1 addition & 1 deletion addons/minedetector/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class CfgPatches {
class ADDON {
name = COMPONENT_NAME;
units[] = {};
weapons[] = {"ACE_VMH3","ACE_VMM3"};
weapons[] = {"ACE_VMH3", "ACE_VMM3"};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_explosives"};
author = ECSTRING(common,ACETeam);
Expand Down
42 changes: 35 additions & 7 deletions addons/minedetector/functions/fnc_activateDetector.sqf
Original file line number Diff line number Diff line change
@@ -1,20 +1,48 @@
#include "..\script_component.hpp"
/*
* Author: Glowbal
* Activate the mine detector
* Activates the mine detector. Selects the mine detector if not selected.
*
* Arguments:
* None
* 0: Unit <OBJECT>
* 1: Detector type <STRING> (default: currentWeapon Unit)
*
* Return Value:
* None
* If the detector was activated <BOOL>
*
* Example:
* [] call ace_minedetector_fnc_activateDetector
* [player, currentWeapon player] call ace_minedetector_fnc_activateDetector
*
* Public: No
* Public: Yes
*/

if (call FUNC(canActivateDetector)) then {
[ACE_player, currentWeapon ACE_player] call FUNC(enableDetector);
params [["_unit", objNull, [objNull]]];

if (!local _unit || {!alive _unit}) exitWith {
false // return
};

private _currentWeapon = currentWeapon _unit;
private _detectorType = param [1, _currentWeapon, [""]];

if (_detectorType == "" || {!([_unit, _detectorType] call FUNC(canActivateDetector))}) exitWith {false};

// Select mine detector if not already selected
if (_currentWeapon != _detectorType) then {
_unit selectWeapon _detectorType;
};

// This prevents multiple PFH for the same weapon
_unit setVariable [format [QGVAR(enable_%1), _detectorType], true, true];

if (_unit == ACE_player) then {
playSoundUI ["ACE_Sound_Click"];
};

// API
[QGVAR(detectorEnabled), [_unit, _detectorType]] call CBA_fnc_localEvent;

// Start monitoring
[LINKFUNC(detectorLoop), 0.05, [_unit, _detectorType, _detectorType call FUNC(getDetectorConfig), CBA_missionTime - 0.25]] call CBA_fnc_addPerFrameHandler;

true // return
18 changes: 13 additions & 5 deletions addons/minedetector/functions/fnc_canActivateDetector.sqf
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
#include "..\script_component.hpp"
/*
* Author: Glowbal
* Check if the mine detector can be activated
* Checks if the mine detector can be activated.
*
* Arguments:
* None
* 0: Unit <OBJECT>
* 1: Detector type <STRING> (default: currentWeapon Unit)
*
* Return Value:
* Can be activated <BOOL>
*
* Example:
* [] call ace_minedetector_fnc_canActivateDetector
* [player, currentWeapon player] call ace_minedetector_fnc_canActivateDetector
*
* Public: No
*/

([ACE_player] call FUNC(hasDetector)) &&
!([ACE_player, currentWeapon ACE_player] call FUNC(isDetectorEnabled));
params ["_unit"];

if (!local _unit || {!alive _unit}) exitWith {
false // return
};

private _detectorType = param [1, currentWeapon _unit, [""]];

[_unit, _detectorType] call FUNC(hasDetector) && {!([_unit, _detectorType] call FUNC(isDetectorEnabled))} // return
11 changes: 6 additions & 5 deletions addons/minedetector/functions/fnc_canConnectHeadphones.sqf
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#include "..\script_component.hpp"
/*
* Author: esteldunedain
* Check if headphones can be connected to the mine detector
* Checks if headphones can be connected to the mine detector.
*
* Arguments:
* None
* 0: Unit <OBJECT>
*
* Return Value:
* Can be connected <BOOL>
*
* Example:
* [] call ace_minedetector_fnc_canConnectHeadphones
* player call ace_minedetector_fnc_canConnectHeadphones
*
* Public: No
*/

!(ACE_player getVariable [QGVAR(isUsingHeadphones), false]) &&
{[ACE_player] call FUNC(hasDetector)};
params ["_unit"];

!(_unit getVariable [QGVAR(isUsingHeadphones), false]) && {_unit call FUNC(hasDetector)} // return
14 changes: 9 additions & 5 deletions addons/minedetector/functions/fnc_canDeactivateDetector.sqf
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
#include "..\script_component.hpp"
/*
* Author: Glowbal
* Check if the mine detector can be deactivated
* Checks if the mine detector can be deactivated.
*
* Arguments:
* None
* 0: Unit <OBJECT>
* 1: Detector type <STRING> (default: currentWeapon Unit)
*
* Return Value:
* Can be deactivated <BOOL>
*
* Example:
* [] call ace_minedetector_fnc_canDeactivateDetector
* call ace_minedetector_fnc_canDeactivateDetector
*
* Public: No
*/

([ACE_player] call FUNC(hasDetector)) &&
{[ACE_player, currentWeapon ACE_player] call FUNC(isDetectorEnabled)};
params ["_unit"];

private _detectorType = param [1, currentWeapon _unit, [""]];

[_unit, _detectorType] call FUNC(hasDetector) && {[_unit, _detectorType] call FUNC(isDetectorEnabled)} // return
11 changes: 6 additions & 5 deletions addons/minedetector/functions/fnc_canDisconnectHeadphones.sqf
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#include "..\script_component.hpp"
/*
* Author: esteldunedain
* Check if headphones can be disconnected from the mine detector
* Checks if headphones can be disconnected from the mine detector.
*
* Arguments:
* None
* 0: Unit <OBJECT>
*
* Return Value:
* Can be disconnected <BOOL>
*
* Example:
* [] call ace_minedetector_fnc_canDisconnectHeadphones
* player call ace_minedetector_fnc_canDisconnectHeadphones
*
* Public: No
*/

(ACE_player getVariable [QGVAR(isUsingHeadphones), false]) &&
{[ACE_player] call FUNC(hasDetector)};
params ["_unit"];

(_unit getVariable [QGVAR(isUsingHeadphones), false]) && {_unit call FUNC(hasDetector)} // return
Loading