diff --git a/addons/trenches/ACE_Arsenal_Stats.hpp b/addons/trenches/ACE_Arsenal_Stats.hpp new file mode 100644 index 0000000000..ab467ea588 --- /dev/null +++ b/addons/trenches/ACE_Arsenal_Stats.hpp @@ -0,0 +1,13 @@ +class EGVAR(arsenal,stats) { + class statBase; + class GVAR(entrenchingTool): statBase { + scope = 2; + priority = -1; + stats[] = {QGVAR(entrenchingTool)}; + displayName = CSTRING(EntrenchingToolName); + showText = 1; + textStatement = QUOTE(localize 'STR_ACE_Common_Yes'); // using localization macros in QUOTE is a PITA + condition = QUOTE(getNumber (_this select 1 >> (_this select 0) select 0) > 0); + tabs[] = {{0,1,5}, {7}}; + }; +}; diff --git a/addons/trenches/CfgWeapons.hpp b/addons/trenches/CfgWeapons.hpp index de79bc277f..4e14153a1b 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/README.md b/addons/trenches/README.md index 0d33527da4..cd19758221 100644 --- a/addons/trenches/README.md +++ b/addons/trenches/README.md @@ -1,17 +1,7 @@ ace_trenches ================= -Adds item 'ACE_entrenchingtool' +Provides players with the capability of digging trenches. + +Adds item 'ACE_EntrenchingTool' Adds 2 trenches; Envelope - Small & Envelop - Big - -### Whitelist surfaces for digging -Single surfaces can be whitelisted by adding `ACE_canDig = 1` into `CfgSurfaces`. -Example: -```cpp -class CfgSurfaces { - class myAwesomeSurface { - ACE_canDig = 1; - }; -}; -``` - diff --git a/addons/trenches/XEH_PREP.hpp b/addons/trenches/XEH_PREP.hpp index bace06f625..05eb403fd8 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 9361d05015..47d20d7c2b 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 022888575e..c966b2c9b6 100644 --- a/addons/trenches/XEH_preStart.sqf +++ b/addons/trenches/XEH_preStart.sqf @@ -1,3 +1,9 @@ #include "script_component.hpp" #include "XEH_PREP.hpp" + +private _entrenchingTools = (QUOTE(getNumber (_x >> QQGVAR(entrenchingTool)) > 0) configClasses (configFile >> "CfgWeapons") apply {configName _x}); +_entrenchingTools append (QUOTE(getNumber (_x >> QQGVAR(entrenchingTool)) > 0) configClasses (configFile >> "CfgVehicles") apply {configName _x}); +TRACE_1("",_entrenchingTools); + +uiNamespace setVariable [QGVAR(entrenchingTools), compileFinal str _entrenchingTools]; diff --git a/addons/trenches/config.cpp b/addons/trenches/config.cpp index 3f76f012ed..18d5e4a3d6 100644 --- a/addons/trenches/config.cpp +++ b/addons/trenches/config.cpp @@ -14,6 +14,7 @@ class CfgPatches { }; }; +#include "ACE_Arsenal_Stats.hpp" #include "CfgEventHandlers.hpp" #include "CfgVehicles.hpp" #include "CfgWeapons.hpp" diff --git a/addons/trenches/functions/fnc_canCamouflageTrench.sqf b/addons/trenches/functions/fnc_canCamouflageTrench.sqf index 266f145e37..2630d61698 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 740b34df7c..f63332e753 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 d6bf05993d..1b6dd28fea 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 23347fc310..ebebbd29a9 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 8380a83af9..e6eab0c548 100644 --- a/addons/trenches/functions/fnc_continueDiggingTrench.sqf +++ b/addons/trenches/functions/fnc_continueDiggingTrench.sqf @@ -67,7 +67,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 3873e40b4a..dcf6493491 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 0000000000..30fb34f441 --- /dev/null +++ b/addons/trenches/functions/fnc_hasEntrenchingTool.sqf @@ -0,0 +1,26 @@ +#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); +_uniqueItems append weapons _unit; +_uniqueItems pushBack backpack _unit; + +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 2cdb874846..c4ddb8a7c7 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); diff --git a/docs/wiki/framework/trenches-framework.md b/docs/wiki/framework/trenches-framework.md new file mode 100644 index 0000000000..5fc2dc636e --- /dev/null +++ b/docs/wiki/framework/trenches-framework.md @@ -0,0 +1,57 @@ +--- +layout: wiki +title: Trenches Framework +description: Explains how to set-up surface whitelisting and entrenching tools. +group: framework +order: 5 +parent: wiki +mod: ace +version: + major: 3 + minor: 5 + patch: 0 +--- + +## 1. Config Values + +### 1.1 Whitelisting surfaces for digging + +Single surfaces can be whitelisted by adding `ACE_canDig = 1` into `CfgSurfaces`. +```cpp +class CfgSurfaces { + class myAwesomeSurface { + ACE_canDig = 1; + }; +}; +``` + +### 1.2 Enabling entrenching tool features on an item or backpack + +```cpp +class CfgWeapons { // same config also works on backpacks (CfgVehicles) + class yourBaseClass; + class yourEntrenchingToolClass: yourBaseClass + ace_trenches_entrenchingTool = 1; + }; +}; +``` + +## 2. Scripting + +### 2.1 Checking if unit has entrenching tool + +`ace_trenches_fnc_hasEntrenchingTool` +Used to check if unit has any entrenching capable tool. + +```sqf + * Checks if unit has entrenching tool. + * + * Arguments: + * 0: Unit + * + * Return Value: + * Has entrenching tool + * + * Example: + * [bob] call ace_trenches_fnc_hasEntrenchingTool +```