2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2021-10-12 09:33:05 +00:00
|
|
|
/*
|
2023-08-16 23:18:01 +00:00
|
|
|
* Author: tcvm
|
2021-10-12 09:33:05 +00:00
|
|
|
* PFH which allows the user to attach a rope to the given target vehicle
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Unit wanting to attach rope <OBJECT>
|
|
|
|
* 1: Vehicle to attach rope <OBJECT>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [player, cursorObject] call ace_towing_fnc_attachRopePFH
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
params ["_unit", "_target", "_ignoreParent", "_ignoreRope", "_source", "_maxRange"];
|
|
|
|
|
|
|
|
private _viewDirection = getCameraViewDirection _unit;
|
|
|
|
GVAR(attachHelper) setPosASL (_unit modelToWorldVisualWorld [0, 1, 1.5]);
|
|
|
|
|
|
|
|
private _hintLMB = "";
|
|
|
|
private _hintRMB = localize ELSTRING(dragging,Drop);
|
|
|
|
|
|
|
|
private _startPos = eyePos _unit;
|
|
|
|
private _endPos = _startPos vectorAdd (_viewDirection vectorMultiply TOW_ACTION_DISTANCE);
|
|
|
|
private _intersections = lineIntersectsSurfaces [_startPos, _endPos, _unit, GVAR(attachHelper), true, 2];
|
|
|
|
GVAR(canAttach) = false;
|
|
|
|
if (_intersections isNotEqualTo []) then {
|
|
|
|
private _intersectionToUse = [];
|
|
|
|
{
|
|
|
|
_x params ["", "", "_object"];
|
|
|
|
if (_object isKindOf "AllVehicles" && { _object isNotEqualTo _ignoreRope && { _object isNotEqualTo _ignoreParent } }) exitWith {
|
|
|
|
_intersectionToUse = _x;
|
|
|
|
};
|
|
|
|
} forEach _intersections;
|
|
|
|
|
|
|
|
if (_intersectionToUse isEqualTo []) exitWith {};
|
|
|
|
|
|
|
|
_intersectionToUse params ["_intersectPosition", "", "_intersectObject"];
|
|
|
|
|
2024-02-05 18:54:51 +00:00
|
|
|
GVAR(canAttach) =
|
|
|
|
_intersectObject isNotEqualTo _ignoreParent
|
|
|
|
&& {
|
|
|
|
// if we have a target object, we assume we are attaching to the parent. If no target object, we are attaching to child
|
|
|
|
if (!isNull _target) then {
|
|
|
|
_intersectObject isEqualTo _target
|
|
|
|
} else {
|
|
|
|
[_intersectObject] call FUNC(isSuitableSimulation)
|
|
|
|
&& { // ignore _intersectObject which has parent != _ignoreParent
|
|
|
|
private _intersectObjectParent = _intersectObject getVariable [QGVAR(parent), objNull];
|
|
|
|
isNull _intersectObjectParent || {_intersectObjectParent == _ignoreParent}
|
|
|
|
} && { // arma prevents making rings (ropeAttachTo silently fails)
|
|
|
|
private _ancestor = _ignoreParent getVariable [QGVAR(parent), objNull];
|
|
|
|
while {!isNull _ancestor && {_ancestor != _intersectObject}} do {
|
|
|
|
_ancestor = _ancestor getVariable [QGVAR(parent), objNull];
|
|
|
|
};
|
|
|
|
isNull _ancestor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
2021-10-12 09:33:05 +00:00
|
|
|
|
|
|
|
if (GVAR(canAttach)) then {
|
2024-02-05 18:54:51 +00:00
|
|
|
// TRACE_4("can attach",_target,_intersectObject,_ignoreParent,_ignoreRope);
|
2021-10-12 09:33:05 +00:00
|
|
|
GVAR(attachHelper) setPosASL _intersectPosition;
|
2024-02-05 18:54:51 +00:00
|
|
|
_hintLMB = LLSTRING(attach);
|
2021-10-12 09:33:05 +00:00
|
|
|
|
|
|
|
GVAR(attachHelper) setVariable [QGVAR(object), _intersectObject];
|
|
|
|
};
|
2021-10-30 21:42:03 +00:00
|
|
|
|
2021-10-12 09:33:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (_source isNotEqualTo [0, 0, 0]) then {
|
|
|
|
private _distanceFromSource = _source vectorDistance getPosASLVisual GVAR(attachHelper);
|
|
|
|
if (_distanceFromSource > _maxRange) then {
|
|
|
|
GVAR(canAttach) = false;
|
|
|
|
|
|
|
|
private _direction = _source vectorFromTo getPosASLVisual GVAR(attachHelper);
|
|
|
|
GVAR(attachHelper) setPosASL (_source vectorAdd (_direction vectorMultiply _maxRange));
|
|
|
|
|
|
|
|
_hintLMB = "";
|
|
|
|
|
|
|
|
if (_distanceFromSource > _maxRange + 2) then {
|
|
|
|
GVAR(cancel) = true;
|
|
|
|
} else {
|
|
|
|
GVAR(cancel) = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
private _hint = [_hintLMB, _hintRMB];
|
|
|
|
if (_hint isNotEqualTo (_unit getVariable [QGVAR(hint), []])) then {
|
|
|
|
_unit setVariable [QGVAR(hint), _hint];
|
|
|
|
_hint call EFUNC(interaction,showMouseHint);
|
|
|
|
};
|