Skip to content

Commit 6d20a30

Browse files
Explosives - Add ability to attach explosives to objects (#11307)
* Add config flag to attach explosives to objects * Add workaround for terrain objects * Slight optimization * Move isTerrainObject logic to common * Add docs, rename property * Rename to make it clearer * Apply suggestions from code review Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> * Use CBA's isTerrainObject * Fix missing comma * Fix extra brackets --------- Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
1 parent 043a5ff commit 6d20a30

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

addons/explosives/CfgMagazines.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class CfgMagazines {
7878
class SatchelCharge_Remote_Mag: CA_Magazine {
7979
useAction = 0;
8080
GVAR(placeable) = 1;
81+
GVAR(isSticky) = 1;
8182
GVAR(setupObject) = "ACE_Explosives_Place_SatchelCharge";
8283
class ACE_Triggers {
8384
SupportedTriggers[] = {"Timer", "Command", "MK16_Transmitter", "DeadmanSwitch"};

addons/explosives/functions/fnc_setupExplosive.sqf

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ _unit setVariable [QGVAR(cancelActionEH), [_unit, "zoomtemp", {true}, {GVAR(plac
5757
private _supportedTriggers = getArray (_configMagazine >> "ACE_Triggers" >> "SupportedTriggers");
5858
private _aceTriggers = configFile >> "ACE_Triggers";
5959
private _isAttachable = _supportedTriggers findIf {(getNumber (_aceTriggers >> _x >> "isAttachable")) == 1} != -1;
60+
private _isSticky = getNumber (_configMagazine >> QGVAR(isSticky)) == 1;
6061

6162
GVAR(pfeh_running) = true;
6263
GVAR(placeAction) = PLACE_WAITING;
@@ -68,7 +69,7 @@ GVAR(TweakedAngle) = 0;
6869
disableSerialization;
6970

7071
params ["_args", "_pfhID"];
71-
_args params ["_unit", "_magClassname", "_setupObjectClass", "_isAttachable"];
72+
_args params ["_unit", "_magClassname", "_setupObjectClass", "_isAttachable", "_isSticky"];
7273

7374
private _lookDirVector = ((positionCameraToWorld [0, 0, 0]) call EFUNC(common,positionToASL)) vectorFromTo ((positionCameraToWorld [0, 0, 10]) call EFUNC(common,positionToASL));
7475
private _basePosASL = eyePos _unit;
@@ -121,14 +122,20 @@ GVAR(TweakedAngle) = 0;
121122
} forEach [[0, 0], [-TEST_LENGTH, -TEST_LENGTH], [TEST_LENGTH, -TEST_LENGTH], [-TEST_LENGTH, TEST_LENGTH], [TEST_LENGTH, TEST_LENGTH]];
122123

123124
if (
124-
!isNull _attachVehicle &&
125-
{(_attachVehicle isKindOf "Car") || {_attachVehicle isKindOf "Tank"} || {_attachVehicle isKindOf "Air"} || {_attachVehicle isKindOf "Ship"}} &&
125+
!isNull _attachVehicle && (
126+
// Allow attaching to non-unit objects (if set) or any vehicle
127+
(_isSticky && {!(_attachVehicle isKindOf "Man")}) ||
128+
{_attachVehicle isKindOf "Car"} ||
129+
{_attachVehicle isKindOf "Tank"} ||
130+
{_attachVehicle isKindOf "Air"} ||
131+
{_attachVehicle isKindOf "Ship"}
132+
) &&
126133
{PLACE_RANGE_MIN call _testPositionIsValid}
127134
) then {
128135
private _min = PLACE_RANGE_MIN;
129136
private _max = PLACE_RANGE_MAX;
130137

131-
for "_index" from 0 to 6 do {
138+
for "_" from 0 to 6 do {
132139
_distanceFromBase = (_min + _max) / 2;
133140

134141
if (_distanceFromBase call _testPositionIsValid) then {
@@ -207,7 +214,17 @@ GVAR(TweakedAngle) = 0;
207214
_expSetupVehicle setPosASL _virtualPosASL;
208215
_placeAngle = _placeAngle + 180; // CfgAmmos seem to be 180 for some reason
209216
} else {
210-
private _modelOffset = _attachVehicle worldToModel (_virtualPosASL call EFUNC(common,ASLToPosition));
217+
// Terrain objects (seemingly) can't have objects attached to them, so create a dummy instead
218+
private _modelOffset = if (_attachVehicle call CBA_fnc_isTerrainObject) then {
219+
_attachVehicle = createVehicle ["Helper_Base_F", [0, 0, 0], [], 0, "CAN_COLLIDE"];
220+
_attachVehicle setPosASL _virtualPosASL;
221+
_attachVehicle setDir _placeAngle;
222+
223+
[0, 0, 0];
224+
} else {
225+
_attachVehicle worldToModel (_virtualPosASL call EFUNC(common,ASLToPosition));
226+
};
227+
211228
_placeAngle = _cameraAngle - (getDir _attachVehicle) + 180;
212229
_expSetupVehicle attachTo [_attachVehicle, _modelOffset];
213230
_expSetupVehicle setVectorDirAndUp [[0, 0, -1], [sin _placeAngle, cos _placeAngle, 0]];
@@ -255,6 +272,6 @@ GVAR(TweakedAngle) = 0;
255272
};
256273

257274
END_COUNTER(pfeh);
258-
}, 0, [_unit, _magClassname, _setupObjectClass, _isAttachable]] call CBA_fnc_addPerFrameHandler;
275+
}, 0, [_unit, _magClassname, _setupObjectClass, _isAttachable, _isSticky]] call CBA_fnc_addPerFrameHandler;
259276

260277
nil

docs/wiki/framework/explosives-framework.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class CfgMagazines {
2727
class banana_satchel_remote_mag: CA_Magazine {
2828
useAction = 0; // Disable the vanilla interaction
2929
ace_explosives_placeable = 1; // Can be placed
30+
ace_explosives_isSticky = 1; // 1 = Explosive can be attached to objects, also requires an attachable trigger
3031
ace_explosives_setupObject = "banana_satchel_place"; // The object placed before the explosive is armed
3132
class ACE_Triggers { // Trigger configurations
3233
SupportedTriggers[] = {"Timer", "Command", "MK16_Transmitter", "DeadmanSwitch"}; // Triggers that can be used

0 commit comments

Comments
 (0)