Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions addons/csw/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ class Extended_PreStart_EventHandlers {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
};
};

class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
};
};

class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_postInit));
};
};

class Extended_DisplayLoad_EventHandlers {
class RscDisplayMission {
ADDON = QUOTE(call COMPILE_FILE(XEH_missionDisplayLoad));
};
};
2 changes: 1 addition & 1 deletion addons/csw/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CfgVehicles {
class GVAR(placeTripod) {
displayName = CSTRING(PlaceTripod_displayName);
condition = QUOTE(call FUNC(canDeployTripod));
statement = QUOTE(call FUNC(assemble_deployTripod));
statement = QUOTE(call FUNC(assemble_startDeployTripod));
exceptions[] = {};
};
};
Expand Down
5 changes: 4 additions & 1 deletion addons/csw/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ PREP(assemble_deployWeapon);
PREP(assemble_deployWeaponModifier);
PREP(assemble_pickupTripod);
PREP(assemble_pickupWeapon);
PREP(assemble_startDeployTripod);

PREP(canGetIn);

PREP(deployCancel);
PREP(deployConfirm);
PREP(getCarryMagazine);
PREP(handleScrollWheel);
PREP(proxyWeapon);

PREP(getLoadActions);
Expand Down
11 changes: 11 additions & 0 deletions addons/csw/XEH_missionDisplayLoad.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "script_component.hpp"

params ["_display"];

_display displayAddEventHandler ["MouseZChanged", {(_this select 1) call FUNC(handleScrollWheel)}];
_display displayAddEventHandler ["MouseButtonDown", {
// Right clicking cancels deployment
if ((_this select 1) == 1 && {ACE_player getVariable [QGVAR(isDeploying), false]}) then {
GVAR(placeAction) = PLACE_CANCEL;
};
}];
16 changes: 16 additions & 0 deletions addons/csw/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "script_component.hpp"

GVAR(vehicleMagCache) = createHashMap;
GVAR(deployPFH) = -1;

["CBA_settingsInitialized", {
TRACE_3("settingsInit",GVAR(defaultAssemblyMode),GVAR(handleExtraMagazines),GVAR(ammoHandling));
Expand Down Expand Up @@ -42,6 +43,21 @@ GVAR(vehicleMagCache) = createHashMap;
[QGVAR(returnAmmo), LINKFUNC(reload_handleReturnAmmo)] call CBA_fnc_addEventHandler;
[QGVAR(autofire_fire), LINKFUNC(autofire_fire)] call CBA_fnc_addEventHandler;

// Cancel placement if interact menu open
["ace_interactMenuOpened", {
if (GVAR(deployPFH) != -1) then {
GVAR(placeAction) = PLACE_CANCEL;
};
}] call CBA_fnc_addEventHandler;

// When changing cameras, drop deploying CSWs
["featureCamera", {
if ((_this select 1) == "") exitWith {};

if (GVAR(deployPFH) != -1) then {
GVAR(placeAction) = PLACE_CANCEL;
};
}] call CBA_fnc_addPlayerEventHandler;

#ifdef DEBUG_MODE_FULL
call compile preprocessFileLineNumbers QPATHTOF(dev\checkStaticWeapons.sqf);
Expand Down
126 changes: 61 additions & 65 deletions addons/csw/functions/fnc_assemble_deployTripod.sqf
Original file line number Diff line number Diff line change
@@ -1,100 +1,96 @@
#include "..\script_component.hpp"
/*
* Author: tcvm
* Author: tcvm, johnb43
* Deploys the tripod.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Position ASL <ARRAY>
* 2: Vector direction & up <NUMBER>
*
* Return Value:
* None
*
* Example:
* player call ace_csw_fnc_assemble_deployTripod
* [player, (getPosASL player) vectorAdd [0, 2, 0], [[1, 0, 0], [0, 0, 1]]] call ace_csw_fnc_assemble_deployTripod
*
* Public: No
*/

[{
params ["_player"];
TRACE_1("assemble_deployTripod",_player);
params ["_player", "_posASL", "_vectorDirAndUp"];
TRACE_1("assemble_deployTripod",_player);

// Save magazines and attachments (handle loaded launchers which can become csw like CUP Metis)
private _secondaryWeaponInfo = (getUnitLoadout _player) select 1;
private _secondaryWeaponClassname = _secondaryWeaponInfo deleteAt 0;
// Save magazines and attachments (handle loaded launchers which can become csw like CUP Metis)
private _secondaryWeaponInfo = (getUnitLoadout _player) select 1;
private _secondaryWeaponClassname = _secondaryWeaponInfo deleteAt 0;

// Remove empty entries
_secondaryWeaponInfo = _secondaryWeaponInfo select {_x isNotEqualTo "" && {_x isNotEqualTo []}};
// Remove empty entries
_secondaryWeaponInfo = _secondaryWeaponInfo select {_x isNotEqualTo "" && {_x isNotEqualTo []}};

// Remove the tripod from the launcher slot
_player removeWeaponGlobal _secondaryWeaponClassname;
// Remove the tripod from the launcher slot
_player removeWeaponGlobal _secondaryWeaponClassname;

private _onFinish = {
params ["_args"];
_args params ["_player", "_secondaryWeaponClassname", "_secondaryWeaponInfo"];
TRACE_3("deployTripod finish",_player,_secondaryWeaponClassname,_secondaryWeaponInfo);
private _onFinish = {
params ["_args"];
_args params ["_player", "_secondaryWeaponClassname", "_secondaryWeaponInfo", "_posASL", "_vectorDirAndUp"];
TRACE_5("deployTripod finish",_player,_secondaryWeaponClassname,_secondaryWeaponInfo,_posASL,_vectorDirAndUp);

private _tripodClassname = getText (configFile >> "CfgWeapons" >> _secondaryWeaponClassname >> QUOTE(ADDON) >> "deploy");
private _tripodClassname = getText (configFile >> "CfgWeapons" >> _secondaryWeaponClassname >> QUOTE(ADDON) >> "deploy");

// Create a tripod
private _cswTripod = createVehicle [_tripodClassname, [0, 0, 0], [], 0, "NONE"];
// Because the tripod can be a "full weapon" we disable any data that will allow it to be loaded
_cswTripod setVariable [QGVAR(assemblyMode), 2, true]; // Explicitly set enabled&unload assembly mode and broadcast
// Create a tripod
private _cswTripod = createVehicle [_tripodClassname, [0, 0, 0], [], 0, "CAN_COLLIDE"];
// Because the tripod can be a "full weapon" we disable any data that will allow it to be loaded
_cswTripod setVariable [QGVAR(assemblyMode), 2, true]; // Explicitly set enabled&unload assembly mode and broadcast

private _secondaryWeaponMagazines = [];
private _secondaryWeaponMagazines = [];

{
// Magazines
if (_x isEqualType []) then {
_secondaryWeaponMagazines pushBack _x;
} else {
// Items
[_player, _x, true] call CBA_fnc_addItem;
};
} forEach _secondaryWeaponInfo;

// Only add magazines once the weapon is fully ready
if (_secondaryWeaponMagazines isNotEqualTo []) then {
_cswTripod setVariable [QGVAR(secondaryWeaponMagazines), _secondaryWeaponMagazines, true];
{
// Magazines
if (_x isEqualType []) then {
_secondaryWeaponMagazines pushBack _x;
} else {
// Items
[_player, _x, true] call CBA_fnc_addItem;
};
} forEach _secondaryWeaponInfo;

// Disable vanilla assembly until FUNC(initVehicle) runs and sets the definite value
[_cswTripod, "disableWeaponAssembly", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);
// Only add magazines once the weapon is fully ready
if (_secondaryWeaponMagazines isNotEqualTo []) then {
_cswTripod setVariable [QGVAR(secondaryWeaponMagazines), _secondaryWeaponMagazines, true];
};

private _posATL = _player getRelPos [2, 0];
_posATL set [2, ((getPosATL _player) select 2) + 0.5];
// Disable vanilla assembly until FUNC(initVehicle) runs and sets the definite value
[_cswTripod, "disableWeaponAssembly", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);

_cswTripod setDir (direction _player);
_cswTripod setPosATL _posATL;
_cswTripod setVectorUp (surfaceNormal _posATL);
_cswTripod setPosASL _posASL;
_cswTripod setVectorDirAndUp _vectorDirAndUp;

[_player, "PutDown"] call EFUNC(common,doGesture);
[_player, "PutDown"] call EFUNC(common,doGesture);

// drag after deploying
if ((missionNamespace getVariable [QGVAR(dragAfterDeploy), false]) && {["ace_dragging"] call EFUNC(common,isModLoaded)}) then {
if ([_player, _cswTripod] call EFUNC(dragging,canCarry)) then {
TRACE_1("starting carry",_cswTripod);
[_player, _cswTripod] call EFUNC(dragging,startCarry);
} else {
TRACE_1("cannot carry",_cswTripod);
};
// drag after deploying
if ((missionNamespace getVariable [QGVAR(dragAfterDeploy), false]) && {["ace_dragging"] call EFUNC(common,isModLoaded)}) then {
if ([_player, _cswTripod] call EFUNC(dragging,canCarry)) then {
TRACE_1("starting carry",_cswTripod);
[_player, _cswTripod] call EFUNC(dragging,startCarry);
} else {
TRACE_1("cannot carry",_cswTripod);
};
};
};

private _onFailure = {
params ["_args"];
_args params ["_player", "_secondaryWeaponClassname", "_secondaryWeaponInfo"];
TRACE_3("deployTripod failure",_player,_secondaryWeaponClassname,_secondaryWeaponInfo);
private _onFailure = {
params ["_args"];
_args params ["_player", "_secondaryWeaponClassname", "_secondaryWeaponInfo"];
TRACE_3("deployTripod failure",_player,_secondaryWeaponClassname,_secondaryWeaponInfo);

// Add tripod back
[_player, _secondaryWeaponClassname] call CBA_fnc_addWeaponWithoutItems;
// Add tripod back
[_player, _secondaryWeaponClassname] call CBA_fnc_addWeaponWithoutItems;

// Add all attachments back
{
_player addWeaponItem [_secondaryWeaponClassname, _x, true];
} forEach _secondaryWeaponInfo;
};
// Add all attachments back
{
_player addWeaponItem [_secondaryWeaponClassname, _x, true];
} forEach _secondaryWeaponInfo;
};

private _deployTime = getNumber (configFile >> "CfgWeapons" >> _secondaryWeaponClassname >> QUOTE(ADDON) >> "deployTime");
[TIME_PROGRESSBAR(_deployTime), [_player, _secondaryWeaponClassname, _secondaryWeaponInfo], _onFinish, _onFailure, LLSTRING(PlaceTripod_progressBar)] call EFUNC(common,progressBar);
}, _this] call CBA_fnc_execNextFrame;
private _deployTime = getNumber (configFile >> "CfgWeapons" >> _secondaryWeaponClassname >> QUOTE(ADDON) >> "deployTime");
[TIME_PROGRESSBAR(_deployTime), [_player, _secondaryWeaponClassname, _secondaryWeaponInfo, _posASL, _vectorDirAndUp], _onFinish, _onFailure, LLSTRING(PlaceTripod_progressBar)] call EFUNC(common,progressBar);
87 changes: 87 additions & 0 deletions addons/csw/functions/fnc_assemble_startDeployTripod.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include "..\script_component.hpp"
/*
* Author: Garth 'L-H' de Wet, Ruthberg, commy2, Smith, johnb43
* Starts the deploy process for unloading an object.
*
* Arguments:
* 0: Unit deploying <OBJECT>
*
* Return Value:
* None
*
* Example:
* player call ace_csw_fnc_assemble_startDeployTripod
*
* Public: No
*/

params ["_player"];

// Don't allow deploying if already deploying
if (_player getVariable [QGVAR(isDeploying), false]) exitWith {};

private _secondaryWeaponClassname = secondaryWeapon _player;
private _classname = getText (configFile >> "CfgWeapons" >> _secondaryWeaponClassname >> QUOTE(ADDON) >> "deploy");

// Prevent the placing unit from running
[_player, "forceWalk", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);
[_player, "blockThrow", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);

// Create a local preview object
private _tripodPreviewObject = createVehicleLocal [_classname, [0, 0, 0], [], 0, "CAN_COLLIDE"];

GVAR(tripodPreviewObject) = _tripodPreviewObject;

// Prevent collisions with object
_tripodPreviewObject disableCollisionWith _player;
_tripodPreviewObject enableSimulation false;
_tripodPreviewObject setMass 1e-12;

// Detect radius of zone where collision can damage the player
private _tripodPreviewObjectRadius = 1 max ((boundingBoxReal [_tripodPreviewObject, "FireGeometry"]) select 2);

// Add height offset of model
private _offset = ((_tripodPreviewObject modelToWorldVisual [0, 0, 0]) select 2) - ((_player modelToWorldVisual [0, 0, 0]) select 2) + 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_tripodPreviewObject modelToWorldVisual [0, 0, 0] 
= [0.0249804,-0.180422,-142.346]

_player modelToWorldVisual [0, 0, 0] 
= [1686.61,5628.52,0.00143862]

offset is -141.348?
placement is blocked, until I scroll mouse, then it works fine

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, although the solution isn't as elegant as I'd like it to be. Constant offset is easier to handle though.
I'll have to update cargo's deploy too, as it has the same problem.


// Attach object
_tripodPreviewObject attachTo [_player, [0, 1.5 * _tripodPreviewObjectRadius, _offset]];

GVAR(placeAction) = PLACE_WAITING;

// PFH that runs while the deployment is in progress
GVAR(deployPFH) = [{
(_this select 0) params ["_player", "_secondaryWeaponClassname", "_tripodPreviewObject"];

// Cancel deployment if criteria not met
if (
isNull _tripodPreviewObject ||
{secondaryWeapon _player != _secondaryWeaponClassname} ||
{!(_player call FUNC(canDeployTripod))} ||
{GVAR(placeAction) == PLACE_CANCEL}
) exitWith {
_player call FUNC(deployCancel);
};

// Check if the center of the object is not inside another (don't check for other intersections though)
private _validPosition = (lineIntersectsSurfaces [eyePos _player, getPosASL _tripodPreviewObject, _player]) isEqualTo [];

// Update mouse hint
((uiNamespace getVariable [QEGVAR(interaction,mouseHint), displayNull]) displayCtrl 2420) ctrlSetText (localize ([LSTRING(BlockedAction), LSTRING(PlaceAction)] select _validPosition));

if (GVAR(placeAction) != PLACE_APPROVE) exitWith {};

// Deploy the CSW
if (_validPosition) exitWith {
_player call FUNC(deployConfirm);
};

// Don't allow placing in an invalid position
GVAR(placeAction) = PLACE_WAITING;
}, 0, [_player, _secondaryWeaponClassname, _tripodPreviewObject]] call CBA_fnc_addPerFrameHandler;

// Add mouse button action and hint
[LLSTRING(PlaceAction), LELSTRING(common,Cancel), LLSTRING(RaiseLowerRotate)] call EFUNC(interaction,showMouseHint);

_player setVariable [QGVAR(deploy), [_player, "DefaultAction", {GVAR(deployPFH) != -1}, {GVAR(placeAction) = PLACE_APPROVE}] call EFUNC(common,addActionEventHandler)];

_player setVariable [QGVAR(isDeploying), true, true];
22 changes: 22 additions & 0 deletions addons/csw/functions/fnc_cancelDeployTripod.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "..\script_component.hpp"
/*
* Author: Garth 'L-H' de Wet, johnb43
* Cancels CSW tripod placement.
*
* Arguments:
* 0: Key <NUMBER>
*
* Return Value:
* None
*
* Example:
* 1 call ace_csw_fnc_cancelDeployTripod
*
* Public: No
*/

params ["_key"];

if (_key != 1 || {GVAR(deployPFH) == -1}) exitWith {};

GVAR(placeAction) = PLACE_CANCEL;
Loading