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

Trenches - Add modded Entrenching Tools support #8999

Merged
merged 8 commits into from
Sep 4, 2022
Merged
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
13 changes: 13 additions & 0 deletions addons/trenches/ACE_Arsenal_Stats.hpp
Original file line number Diff line number Diff line change
@@ -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}};
};
};
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;
};
};
16 changes: 3 additions & 13 deletions addons/trenches/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
ace_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;
};
};
```
Provides players with the capability of digging trenches.

Adds item 'ACE_EntrenchingTool'
Adds 2 trenches; Envelope - Small & Envelop - Big
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;
6 changes: 6 additions & 0 deletions addons/trenches/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -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];
1 change: 1 addition & 0 deletions addons/trenches/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class CfgPatches {
};
};

#include "ACE_Arsenal_Stats.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgVehicles.hpp"
#include "CfgWeapons.hpp"
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);
};
};
26 changes: 26 additions & 0 deletions addons/trenches/functions/fnc_hasEntrenchingTool.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#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);
_uniqueItems append weapons _unit;
_uniqueItems pushBack backpack _unit;

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
57 changes: 57 additions & 0 deletions docs/wiki/framework/trenches-framework.md
Original file line number Diff line number Diff line change
@@ -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 <OBJECT>
*
* Return Value:
* Has entrenching tool <BOOL>
*
* Example:
* [bob] call ace_trenches_fnc_hasEntrenchingTool
```