From b31dcb267c7ce569482c8105b5a4817461acc65c Mon Sep 17 00:00:00 2001 From: Filip Maciejewski Date: Sun, 14 Aug 2022 13:51:46 +0200 Subject: [PATCH] Add support for other entrenching tools --- addons/trenches/CfgWeapons.hpp | 2 ++ addons/trenches/XEH_PREP.hpp | 1 + addons/trenches/XEH_preInit.sqf | 2 ++ addons/trenches/XEH_preStart.sqf | 7 ++++++ .../functions/fnc_canCamouflageTrench.sqf | 2 +- .../fnc_canContinueDiggingTrench.sqf | 2 +- .../trenches/functions/fnc_canDigTrench.sqf | 2 +- .../functions/fnc_canRemoveTrench.sqf | 2 +- .../functions/fnc_continueDiggingTrench.sqf | 2 +- .../fnc_handlePlayerInventoryChanged.sqf | 2 +- .../functions/fnc_hasEntrenchingTool.sqf | 24 +++++++++++++++++++ .../trenches/functions/fnc_removeTrench.sqf | 2 +- 12 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 addons/trenches/functions/fnc_hasEntrenchingTool.sqf diff --git a/addons/trenches/CfgWeapons.hpp b/addons/trenches/CfgWeapons.hpp index de79bc277fd..4e14153a1be 100644 --- a/addons/trenches/CfgWeapons.hpp +++ b/addons/trenches/CfgWeapons.hpp @@ -12,5 +12,7 @@ class CfgWeapons { class ItemInfo: CBA_MiscItem_ItemInfo { mass = 10; }; + + GVAR(entrenchingTool) = 1; }; }; diff --git a/addons/trenches/XEH_PREP.hpp b/addons/trenches/XEH_PREP.hpp index bace06f625b..05eb403fd82 100644 --- a/addons/trenches/XEH_PREP.hpp +++ b/addons/trenches/XEH_PREP.hpp @@ -11,6 +11,7 @@ PREP(handlePlayerChanged); PREP(handlePlayerInventoryChanged); PREP(handleScrollWheel); PREP(handleUnconscious); +PREP(hasEntrenchingTool); PREP(placeCancel); PREP(placeConfirm); PREP(placeTrench); diff --git a/addons/trenches/XEH_preInit.sqf b/addons/trenches/XEH_preInit.sqf index 9361d05015e..47d20d7c2bd 100644 --- a/addons/trenches/XEH_preInit.sqf +++ b/addons/trenches/XEH_preInit.sqf @@ -8,4 +8,6 @@ PREP_RECOMPILE_END; #include "initSettings.sqf" +GVAR(entrenchingTools) = call (uiNamespace getVariable QGVAR(entrenchingTools)); + ADDON = true; diff --git a/addons/trenches/XEH_preStart.sqf b/addons/trenches/XEH_preStart.sqf index 022888575ed..766aa329e50 100644 --- a/addons/trenches/XEH_preStart.sqf +++ b/addons/trenches/XEH_preStart.sqf @@ -1,3 +1,10 @@ #include "script_component.hpp" #include "XEH_PREP.hpp" + +private _entrenchingTools = []; + +uiNamespace setVariable [ + QGVAR(entrenchingTools), + compileFinal str (QUOTE(getNumber (_x >> QQGVAR(entrenchingTool)) > 0) configClasses (configFile >> "CfgWeapons") apply {configName _x}) +]; diff --git a/addons/trenches/functions/fnc_canCamouflageTrench.sqf b/addons/trenches/functions/fnc_canCamouflageTrench.sqf index 266f145e37c..2630d616986 100644 --- a/addons/trenches/functions/fnc_canCamouflageTrench.sqf +++ b/addons/trenches/functions/fnc_canCamouflageTrench.sqf @@ -18,7 +18,7 @@ params ["_trench", "_unit"]; -if !("ACE_EntrenchingTool" in (_unit call EFUNC(common,uniqueItems))) exitWith {false}; +if !(_unit call FUNC(hasEntrenchingTool)) exitWith {false}; // Prevent camouflage if not fully dug if ((_trench getVariable [QGVAR(progress), 0]) != 1) exitWith {false}; diff --git a/addons/trenches/functions/fnc_canContinueDiggingTrench.sqf b/addons/trenches/functions/fnc_canContinueDiggingTrench.sqf index 740b34df7c3..f63332e7539 100644 --- a/addons/trenches/functions/fnc_canContinueDiggingTrench.sqf +++ b/addons/trenches/functions/fnc_canContinueDiggingTrench.sqf @@ -18,7 +18,7 @@ params ["_trench", "_unit"]; -if !("ACE_EntrenchingTool" in (_unit call EFUNC(common,uniqueItems))) exitWith {false}; +if !(_unit call FUNC(hasEntrenchingTool)) exitWith {false}; if ((_trench getVariable [QGVAR(progress), 1]) >= 1) exitWith {false}; // Prevent removing/digging trench by more than one person diff --git a/addons/trenches/functions/fnc_canDigTrench.sqf b/addons/trenches/functions/fnc_canDigTrench.sqf index d6bf05993d8..1b6dd28fea3 100644 --- a/addons/trenches/functions/fnc_canDigTrench.sqf +++ b/addons/trenches/functions/fnc_canDigTrench.sqf @@ -17,6 +17,6 @@ params ["_unit"]; -if !("ACE_EntrenchingTool" in (_unit call EFUNC(common,uniqueItems))) exitWith {false}; +if !(_unit call FUNC(hasEntrenchingTool)) exitWith {false}; _unit call EFUNC(common,canDig) diff --git a/addons/trenches/functions/fnc_canRemoveTrench.sqf b/addons/trenches/functions/fnc_canRemoveTrench.sqf index 23347fc310e..ebebbd29a9c 100644 --- a/addons/trenches/functions/fnc_canRemoveTrench.sqf +++ b/addons/trenches/functions/fnc_canRemoveTrench.sqf @@ -18,7 +18,7 @@ params ["_trench", "_unit"]; -if !("ACE_EntrenchingTool" in (_unit call EFUNC(common,uniqueItems))) exitWith {false}; +if !(_unit call FUNC(hasEntrenchingTool)) exitWith {false}; // Prevent removing/digging trench by more than one person if (_trench getVariable [QGVAR(digging), false]) exitWith {false}; diff --git a/addons/trenches/functions/fnc_continueDiggingTrench.sqf b/addons/trenches/functions/fnc_continueDiggingTrench.sqf index 4c6c6f9546b..d66dfe83f5d 100644 --- a/addons/trenches/functions/fnc_continueDiggingTrench.sqf +++ b/addons/trenches/functions/fnc_continueDiggingTrench.sqf @@ -65,7 +65,7 @@ private _fnc_onFailure = { }; private _fnc_condition = { (_this select 0) params ["_unit"]; - "ACE_EntrenchingTool" in (_unit call EFUNC(common,uniqueItems)) + _unit call FUNC(hasEntrenchingTool) }; [(_digTimeLeft + 0.5), [_unit, _trench], _fnc_onFinish, _fnc_onFailure, localize LSTRING(DiggingTrench), _fnc_condition] call EFUNC(common,progressBar); diff --git a/addons/trenches/functions/fnc_handlePlayerInventoryChanged.sqf b/addons/trenches/functions/fnc_handlePlayerInventoryChanged.sqf index 3873e40b4a1..dcf6493491d 100644 --- a/addons/trenches/functions/fnc_handlePlayerInventoryChanged.sqf +++ b/addons/trenches/functions/fnc_handlePlayerInventoryChanged.sqf @@ -19,7 +19,7 @@ params ["_unit"]; if (_unit getVariable [QGVAR(isPlacing), false]) then { - if !("ACE_EntrenchingTool" in (_unit call EFUNC(common,uniqueItems))) then { + if !(_unit call FUNC(hasEntrenchingTool)) then { [_unit] call FUNC(placeCancel); }; }; diff --git a/addons/trenches/functions/fnc_hasEntrenchingTool.sqf b/addons/trenches/functions/fnc_hasEntrenchingTool.sqf new file mode 100644 index 00000000000..a3a227d3614 --- /dev/null +++ b/addons/trenches/functions/fnc_hasEntrenchingTool.sqf @@ -0,0 +1,24 @@ +#include "script_component.hpp" +/* + * Author: veteran29 + * Checks if unit has entrenching tool. + * + * Arguments: + * 0: Unit + * + * Return Value: + * Has entrenching tool + * + * Example: + * [bob] call ace_trenches_fnc_hasEntrenchingTool + * + * Public: Yes +*/ + +params [ + ["_unit", objNull, [objNull]] +]; + +private _uniqueItems = _unit call EFUNC(common,uniqueItems); + +GVAR(entrenchingTools) findIf {_x in _uniqueItems} != -1 // return diff --git a/addons/trenches/functions/fnc_removeTrench.sqf b/addons/trenches/functions/fnc_removeTrench.sqf index 2cdb874846a..c4ddb8a7c70 100644 --- a/addons/trenches/functions/fnc_removeTrench.sqf +++ b/addons/trenches/functions/fnc_removeTrench.sqf @@ -66,7 +66,7 @@ private _fnc_onFailure = { }; private _fnc_condition = { (_this select 0) params ["_unit"]; - "ACE_EntrenchingTool" in (_unit call EFUNC(common,uniqueItems)) + _unit call FUNC(hasEntrenchingTool) }; [(_removeTimeLeft + 0.5), [_unit, _trench], _fnc_onFinish, _fnc_onFailure, localize LSTRING(RemovingTrench), _fnc_condition] call EFUNC(common,progressBar);