ACE3/addons/concertina_wire/functions/fnc_deploy.sqf

86 lines
2.7 KiB
Plaintext
Raw Normal View History

/*
* Author: Rocko, Ruthberg
*
* Deploys the concertina wire
*
* Arguments:
* 0: wire coil <OBJECT>
* 1: unit <OBJECT>
*
* Return Value:
* Nothing
*
* Return value:
* None
*/
2015-06-04 15:11:09 +00:00
#include "script_component.hpp"
PARAMS_2(_wirecoil,_unit);
private ["_wireNoGeo", "_dir", "_pos", "_wireNoGeoPos"];
_wireNoGeo = "ACE_ConcertinaWireNoGeo" createVehicle [0,0,0];
{
_wireNoGeo animate [_x, 1];
} foreach WIRE_FAST;
GVAR(placer) = _unit;
_dir = getDir _unit;
_pos = getPosASL _unit;
_wireNoGeoPos = _pos vectorAdd [1.1 * sin(_dir), 1.1 * cos(_dir), 0];
_wireNoGeo setDir _dir;
_wireNoGeo setPosASL _wireNoGeoPos;
deleteVehicle _wirecoil;
_unit setVariable [QGVAR(wireDeployed), false];
GVAR(deployPFH) = [{
EXPLODE_3_PVT(_this select 0,_wireNoGeo,_wireNoGeoPos,_unit);
2015-06-04 15:11:09 +00:00
private ["_range", "_posStart", "_posEnd", "_dirVect", "_dir", "_anim", "_wire"];
_posStart = (_wireNoGeo modelToWorldVisual (_wireNoGeo selectionPosition "start")) call EFUNC(common,positionToASL);
_posEnd = (getPosASL _unit) vectorAdd (vectorDir _unit);
_dirVect = _posStart vectorDiff _posEnd;
_dir = _dirVect call CBA_fnc_vectDir;
_range = vectorMagnitude _dirVect;
_anim = 0 max (1 - (_range / 12));
if (!(alive _unit) || _range >= 12 || (_unit getVariable [QGVAR(wireDeployed), false])) exitWith {
_wire = "ACE_ConcertinaWire" createvehicle [0, 0, 0];
{
_wire animate [_x, _anim];
} foreach WIRE_FAST;
[{
EXPLODE_5_PVT(_this select 0,_wireNoGeo,_wire,_anim,_dir,_wireNoGeoPos);
if (_wire animationPhase "wire_2" == _anim) then {
deleteVehicle _wireNoGeo;
_wire setDir _dir;
_wire setPosASL _wireNoGeoPos;
[_this select 1] call CBA_fnc_removePerFrameHandler;
};
}, 0, [_wireNoGeo, _wire, _anim, _dir, _wireNoGeoPos]] call CBA_fnc_addPerFrameHandler;
[_unit, "DefaultAction", _unit getVariable [QGVAR(Deploy), -1]] call EFUNC(Common,removeActionEventHandler);
call EFUNC(interaction,hideMouseHint);
[_this select 1] call CBA_fnc_removePerFrameHandler;
};
_wireNoGeo setDir _dir;
{
_wireNoGeo animate [_x, _anim];
} foreach WIRE_FAST;
}, 0, [_wireNoGeo, _wireNoGeoPos, _unit]] call CBA_fnc_addPerFrameHandler;
2015-06-04 15:11:09 +00:00
[localize "STR_ACE_ROLLWIRE", "", ""] call EFUNC(interaction,showMouseHint);
[{ //wait a frame to handle "Do When releasing action menu key" option
GVAR(placer) setVariable [QGVAR(Deploy),
[GVAR(placer), "DefaultAction",
{GVAR(deployPFH) != -1},
{GVAR(placer) setVariable [QGVAR(wireDeployed), true]}
] call EFUNC(common,AddActionEventHandler)];
}, _this] call EFUNC(common,execNextFrame);