2015-01-30 20:32:21 +00:00
|
|
|
/*
|
2015-02-01 20:56:19 +00:00
|
|
|
* Author: Pabst Mirror (based on Explosive attach by Garth de Wet (LH))
|
|
|
|
* Approves placement of the lightObject, scans for an appropriate location and attaches
|
2015-03-27 16:14:04 +00:00
|
|
|
* A player can release the attachObject with it floating in mid-air.
|
|
|
|
* This will use lineIntersectsWith to scan towards the center of the vehicle to find a collision
|
|
|
|
* ArmA's collision detection is of couse terrible and often misses collisions (difference between what we see and collision LOD)
|
|
|
|
* So it does multiple scans at slighly different angles
|
|
|
|
* This is VERY computationaly intensive, but doesn't happen that often.
|
2015-02-01 20:56:19 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* Nothing
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Nothing
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* Nothing
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2015-01-30 20:32:21 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-03-27 16:14:04 +00:00
|
|
|
private ["_startingOffset", "_startDistanceFromCenter", "_closeInUnitVector", "_closeInMax", "_closeInMin", "_setupObject", "_closeInDistance", "_endPosTestOffset", "_endPosTest", "_doesIntersect", "_startingPosShifted", "_startASL", "_endPosShifted", "_endASL", "_attachedObject", "_currentObjects", "_currentItemNames"];
|
2015-01-30 20:32:21 +00:00
|
|
|
|
2015-03-27 16:14:04 +00:00
|
|
|
PARAMS_6(_unit,_attachToVehicle,_itemClassname,_itemVehClass,_onAtachText,_startingPosition);
|
2015-01-30 20:32:21 +00:00
|
|
|
|
2015-01-31 09:05:07 +00:00
|
|
|
_startingOffset = _attachToVehicle worldToModel _startingPosition;
|
|
|
|
|
2015-03-26 22:49:11 +00:00
|
|
|
_startDistanceFromCenter = vectorMagnitude _startingOffset;
|
2015-01-31 09:05:07 +00:00
|
|
|
_closeInUnitVector = vectorNormalized (_startingOffset vectorFromTo [0,0,0]);
|
|
|
|
|
2015-03-26 22:49:11 +00:00
|
|
|
_closeInMax = _startDistanceFromCenter;
|
|
|
|
_closeInMin = 0;
|
2015-01-31 09:05:07 +00:00
|
|
|
|
2015-03-27 05:12:39 +00:00
|
|
|
//Delete Local Placement Object
|
|
|
|
deleteVehicle _setupObject;
|
|
|
|
|
2015-03-26 22:49:11 +00:00
|
|
|
while {(_closeInMax - _closeInMin) > 0.01} do {
|
|
|
|
_closeInDistance = (_closeInMax + _closeInMin) / 2;
|
|
|
|
// systemChat format ["Trying %1 from %2 start %3", _closeInDistance, [_closeInMax, _closeInMin], _startDistanceFromCenter];
|
2015-02-01 20:56:19 +00:00
|
|
|
_endPosTestOffset = _startingOffset vectorAdd (_closeInUnitVector vectorMultiply _closeInDistance);
|
|
|
|
_endPosTestOffset set [2, (_startingOffset select 2)];
|
|
|
|
_endPosTest = _attachToVehicle modelToWorld _endPosTestOffset;
|
2015-01-31 09:05:07 +00:00
|
|
|
|
2015-03-26 22:49:11 +00:00
|
|
|
_doesIntersect = false;
|
2015-01-30 20:32:21 +00:00
|
|
|
{
|
2015-03-26 22:49:11 +00:00
|
|
|
if (_doesIntersect) exitWith {};
|
2015-02-01 20:56:19 +00:00
|
|
|
_startingPosShifted = _startingPosition vectorAdd _x;
|
|
|
|
_startASL = if (surfaceIsWater _startingPosShifted) then {_startingPosShifted} else {ATLtoASL _startingPosShifted};
|
|
|
|
{
|
|
|
|
_endPosShifted = _endPosTest vectorAdd _x;
|
|
|
|
_endASL = if (surfaceIsWater _startingPosShifted) then {_endPosShifted} else {ATLtoASL _endPosShifted};
|
|
|
|
|
|
|
|
//Uncomment to see the lazor show, and see how the scanning works:
|
2015-03-27 16:14:04 +00:00
|
|
|
drawLine3D [_startingPosShifted, _endPosShifted, [1,0,0,1]];
|
|
|
|
if (_attachToVehicle in lineIntersectsWith [_startASL, _endASL, _unit]) exitWith {_doesIntersect = true};
|
2015-02-01 20:56:19 +00:00
|
|
|
} forEach [[0,0,0.045], [0,0,-0.045], [0,0.045,0], [0,-0.045,0], [0.045,0,0], [-0.045,0,0]];
|
|
|
|
} forEach [[0,0,0], [0,0,0.05], [0,0,-0.05]];
|
2015-03-27 05:12:39 +00:00
|
|
|
|
2015-03-26 22:49:11 +00:00
|
|
|
if (_doesIntersect) then {
|
|
|
|
_closeInMax = _closeInDistance;
|
|
|
|
} else {
|
|
|
|
_closeInMin = _closeInDistance;
|
|
|
|
};
|
2015-01-30 20:32:21 +00:00
|
|
|
};
|
|
|
|
|
2015-03-26 22:49:11 +00:00
|
|
|
_closeInDistance = (_closeInMax + _closeInMin) / 2;
|
|
|
|
|
2015-03-27 05:12:39 +00:00
|
|
|
//Checks (too close to center or can't attach)
|
2015-03-27 16:14:04 +00:00
|
|
|
if (((_startDistanceFromCenter - _closeInDistance) < 0.1) || {!([_attachToVehicle, _unit, _itemClassname] call FUNC(canAttach))}) exitWith {
|
2015-03-26 22:49:11 +00:00
|
|
|
TRACE_2("no valid spot found",_closeInDistance,_startDistanceFromCenter);
|
2015-02-01 20:56:19 +00:00
|
|
|
[localize "STR_ACE_Attach_Failed"] call EFUNC(common,displayTextStructured);
|
2015-01-31 17:43:58 +00:00
|
|
|
};
|
2015-01-31 09:05:07 +00:00
|
|
|
|
2015-03-26 22:49:11 +00:00
|
|
|
//Move it out slightly, for visability sake (better to look a little funny than be embedded//sunk in the hull and be useless)
|
2015-01-31 09:05:07 +00:00
|
|
|
_closeInDistance = (_closeInDistance - 0.0085);
|
|
|
|
|
2015-01-30 20:32:21 +00:00
|
|
|
//Create New 'real' Object
|
2015-01-31 09:05:07 +00:00
|
|
|
_endPosTestOffset = _startingOffset vectorAdd (_closeInUnitVector vectorMultiply _closeInDistance);
|
|
|
|
_endPosTestOffset set [2, (_startingOffset select 2)];
|
2015-03-27 16:14:04 +00:00
|
|
|
_attachedObject = _itemVehClass createVehicle (getPos _unit);
|
2015-01-31 09:05:07 +00:00
|
|
|
_attachedObject attachTo [_attachToVehicle, _endPosTestOffset];
|
2015-01-30 20:32:21 +00:00
|
|
|
|
|
|
|
//Remove Item from inventory
|
2015-03-27 16:14:04 +00:00
|
|
|
_unit removeItem _itemClassname;
|
2015-01-30 20:32:21 +00:00
|
|
|
|
|
|
|
//Add Object to ACE_AttachedObjects and ACE_AttachedItemNames
|
2015-02-15 14:31:09 +00:00
|
|
|
_currentObjects = _attachToVehicle getVariable [QGVAR(Objects), []];
|
2015-01-30 20:32:21 +00:00
|
|
|
_currentObjects pushBack _attachedObject;
|
2015-02-15 14:31:09 +00:00
|
|
|
_attachToVehicle setVariable [QGVAR(Objects), _currentObjects, true];
|
|
|
|
_currentItemNames = _attachToVehicle getVariable [QGVAR(ItemNames), []];
|
2015-01-30 20:32:21 +00:00
|
|
|
_currentItemNames pushBack _itemClassname;
|
2015-02-15 14:31:09 +00:00
|
|
|
_attachToVehicle setVariable [QGVAR(ItemNames), _currentItemNames, true];
|
2015-01-30 20:32:21 +00:00
|
|
|
|
2015-03-27 16:14:04 +00:00
|
|
|
[_onAtachText] call EFUNC(common,displayTextStructured);
|