Skip to content

Commit 043a5ff

Browse files
authored
Compat SPE - Fix dropped SPE CSWs not converting to ACE CSWs (#11312)
* Fixed dropped SPE CSW weapons not converting to ACE CSWs * Handle exchanging tripods * Take surface slop into account * Improve CSW placement
1 parent fb7721a commit 043a5ff

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

addons/compat_spe/compat_spe_csw/config.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class CfgFunctions {
3535
OVERWRITE_FUNC(can_Reload);
3636
OVERWRITE_FUNC(can_resupply_ammo);
3737
OVERWRITE_FUNC(can_unload_ammo);
38+
OVERWRITE_FUNC(player_put_EH);
39+
OVERWRITE_FUNC(player_take_EH);
3840
};
3941
};
4042
};
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include "..\script_component.hpp"
2+
/*
3+
* Author: Kerc (SPE), original by www.3commandobrigade.com, edited by johnb43 to be made CSW compatible
4+
* EH to allow a player to drop a tripod from the launcher slot, converting it into a weapon base.
5+
*
6+
* Arguments:
7+
* 0: Unit <OBJECT>
8+
* 1: Container <OBJECT>
9+
* 2: Item <STRING>
10+
*
11+
* Return Value:
12+
* None
13+
*
14+
* Example:
15+
* [player, cursorObject, "SPE_MLE_27_31_Stand"] call SPE_Weapons_Static_fnc_player_put_EH
16+
*
17+
* Public: No
18+
*/
19+
20+
params ["_unit", "_container", "_item"];
21+
22+
if (!alive _unit) exitWith {};
23+
24+
// Don't run when placing a tripod in a vehicle/box
25+
if !(_container isKindOf "GroundWeaponHolder") exitWith {};
26+
27+
private _weaponConfig = configFile >> "CfgWeapons" >> _item;
28+
29+
// isKindOf does not currently work for weapons
30+
if (getNumber (_weaponConfig >> "SPE_isTripod") == 0) exitWith {};
31+
32+
private _tripodClass = if (EGVAR(csw,defaultAssemblyMode)) then {
33+
getText (_weaponConfig >> "ace_csw" >> "deploy")
34+
} else {
35+
// Note M6 is also considered a tripod as far as the next instruction is concerned
36+
getText (_weaponConfig >> "SPE_Deployed_Tripod_Name")
37+
};
38+
39+
if (_tripodClass == "") exitWith {};
40+
41+
// Check if there is a surface on which the tripod can be placed
42+
private _vectorDir = vectorDir _unit;
43+
private _posASL = (eyePos _unit) vectorAdd (_vectorDir vectorMultiply 1.1);
44+
private _lisPos = lineIntersectsSurfaces [_posASL, _posASL vectorAdd [0, 0, -3], _unit, objNull, true, 1, "ROADWAY", "FIRE"];
45+
46+
if (_lisPos isEqualTo []) exitWith {};
47+
48+
_lisPos = _lisPos select 0;
49+
50+
// Remove tripod from container
51+
_container addItemCargoGlobal [_item, -1];
52+
53+
// Create a vehicle replacing the tripod
54+
private _weaponPlatform = createVehicle [_tripodClass, (ASLToAGL (_lisPos select 0)) vectorAdd [0, 0, 0.1], [], 0, "CAN_COLLIDE"];
55+
56+
_weaponPlatform setVectorDirAndUp [_vectorDir, _lisPos select 1];
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include "..\script_component.hpp"
2+
/*
3+
* Author: Kerc (SPE), edited by johnb43 to be made CSW compatible
4+
* EH Backup for when the Put EH does not run (Swapping items).
5+
*
6+
* Arguments:
7+
* 0: Unit <OBJECT>
8+
* 1: Container <OBJECT>
9+
* 2: Item <STRING>
10+
*
11+
* Return Value:
12+
* None
13+
*
14+
* Example:
15+
* [player, cursorObject, "SPE_MLE_27_31_Stand"] call SPE_Weapons_Static_fnc_player_take_EH
16+
*
17+
* Public: No
18+
*/
19+
20+
params ["_unit", "_container", "_item"];
21+
22+
if (!alive _unit) exitWith {};
23+
24+
// Don't run when placing a tripod in a vehicle/box
25+
if !(_container isKindOf "GroundWeaponHolder") exitWith {};
26+
27+
private _cfgWeapons = configFile >> "CfgWeapons";
28+
private _tripods = (weaponCargo _container) select {getNumber (_cfgWeapons >> _x >> "SPE_isTripod") == 1};
29+
30+
if (_tripods isEqualTo []) exitWith {};
31+
32+
private _vectorDir = vectorDir _unit;
33+
private _posASL = (eyePos _unit) vectorAdd (_vectorDir vectorMultiply 1.1);
34+
35+
private _lisPos = lineIntersectsSurfaces [_posASL, _posASL vectorAdd [0, 0, -3], _unit, objNull, true, 1, "ROADWAY", "FIRE"];
36+
37+
if (_lisPos isEqualTo []) exitWith {};
38+
39+
_lisPos = _lisPos select 0;
40+
41+
_posASL = (ASLToAGL (_lisPos select 0)) vectorAdd [0, 0, 0.1];
42+
43+
{
44+
private _tripodClass = if (EGVAR(csw,defaultAssemblyMode)) then {
45+
getText (_cfgWeapons >> _x >> "ace_csw" >> "deploy")
46+
} else {
47+
// Note M6 is also considered a tripod as far as the next instruction is concerned
48+
getText (_cfgWeapons >> _x >> "SPE_Deployed_Tripod_Name")
49+
};
50+
51+
if (_tripodClass == "") then {
52+
continue;
53+
};
54+
55+
// Remove tripod from container
56+
_container addItemCargoGlobal [_x, -1];
57+
58+
// Create a vehicle replacing the tripod
59+
private _weaponPlatform = createVehicle [_tripodClass, _posASL, [], 0, ["NONE", "CAN_COLLIDE"] select (_forEachIndex == 0)];
60+
61+
_weaponPlatform setVectorDirAndUp [_vectorDir, _lisPos select 1];
62+
} forEach _tripods;

0 commit comments

Comments
 (0)