Skip to content

Commit

Permalink
Add support for other entrenching tools
Browse files Browse the repository at this point in the history
  • Loading branch information
veteran29 committed Aug 14, 2022
1 parent b47b801 commit b31dcb2
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 7 deletions.
2 changes: 2 additions & 0 deletions addons/trenches/CfgWeapons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ class CfgWeapons {
class ItemInfo: CBA_MiscItem_ItemInfo {
mass = 10;
};

GVAR(entrenchingTool) = 1;
};
};
1 change: 1 addition & 0 deletions addons/trenches/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ PREP(handlePlayerChanged);
PREP(handlePlayerInventoryChanged);
PREP(handleScrollWheel);
PREP(handleUnconscious);
PREP(hasEntrenchingTool);
PREP(placeCancel);
PREP(placeConfirm);
PREP(placeTrench);
Expand Down
2 changes: 2 additions & 0 deletions addons/trenches/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ PREP_RECOMPILE_END;

#include "initSettings.sqf"

GVAR(entrenchingTools) = call (uiNamespace getVariable QGVAR(entrenchingTools));

ADDON = true;
7 changes: 7 additions & 0 deletions addons/trenches/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -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})

This comment has been minimized.

Copy link
@kymckay

kymckay Aug 14, 2022

Member

What's the advantage to deferring the config read from preStart to preInit? I guess this allows script modification of what's considered an entrenching tool. Is that why?

In any case, probably worth adding a comment with the rationale

This comment has been minimized.

Copy link
@veteran29

veteran29 Aug 14, 2022

Author Member

I've done it like this because "we do it like this", eg.:

uiNamespace setVariable [QGVAR(vehicleClasses_classEH), compileFinal str _vehicleClasses_addClassEH];
uiNamespace setVariable [QGVAR(objectClasses_classEH), compileFinal str _objectClasses_addClassEH];
uiNamespace setVariable [QGVAR(initializedVehicleClasses), compileFinal str _vehicleClasses_addAction];
uiNamespace setVariable [QGVAR(initializedItemClasses), compileFinal str _itemClasses_addAction];

The main rationale that comes to mind is that preStart is done once and preInit is done on every mission load.

];
2 changes: 1 addition & 1 deletion addons/trenches/functions/fnc_canCamouflageTrench.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion addons/trenches/functions/fnc_canContinueDiggingTrench.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion addons/trenches/functions/fnc_canDigTrench.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion addons/trenches/functions/fnc_canRemoveTrench.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion addons/trenches/functions/fnc_continueDiggingTrench.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
};
24 changes: 24 additions & 0 deletions addons/trenches/functions/fnc_hasEntrenchingTool.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "script_component.hpp"
/*
* Author: veteran29
* Checks if unit has entrenching tool.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* Has entrenching tool <BOOL>
*
* 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
2 changes: 1 addition & 1 deletion addons/trenches/functions/fnc_removeTrench.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b31dcb2

Please sign in to comment.