2015-08-13 17:33:55 +00:00
|
|
|
/*
|
2015-08-20 20:10:26 +00:00
|
|
|
* Author: GitHawk et.al.
|
|
|
|
* Calculates a connection for refueling.
|
2015-08-13 17:33:55 +00:00
|
|
|
* With code from ace_attach
|
|
|
|
*
|
|
|
|
* Arguments:
|
2015-08-20 20:10:26 +00:00
|
|
|
* 0: Unit <OBJECT>
|
|
|
|
* 1: Target <OBJECT>
|
|
|
|
* 2: Visual Position <ARRAY>
|
|
|
|
* 3: Nozzle <OBJECT>
|
2015-08-13 17:33:55 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-08-14 01:18:54 +00:00
|
|
|
* None
|
2015-08-13 17:33:55 +00:00
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [player, tank, [0,0,0], nozzle] call ace_refuel_fnc_connectNozzleAction
|
|
|
|
*
|
2015-08-14 01:18:54 +00:00
|
|
|
* Public: No
|
2015-08-13 17:33:55 +00:00
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
2016-02-02 14:03:06 +00:00
|
|
|
private ["_closeInDistance", "_endPosTestOffset"];
|
2015-08-13 17:33:55 +00:00
|
|
|
|
2016-02-02 14:03:06 +00:00
|
|
|
params [["_unit", objNull, [objNull]], ["_target", objNull, [objNull]], ["_startingPosition", [0,0,0], [[]], 3], ["_nozzle", objNull, [objNull]]];
|
|
|
|
private _startingOffset = _target worldToModel _startingPosition;
|
2015-08-13 17:33:55 +00:00
|
|
|
|
2016-02-02 14:03:06 +00:00
|
|
|
private _startDistanceFromCenter = vectorMagnitude _startingOffset;
|
|
|
|
private _closeInUnitVector = vectorNormalized (_startingOffset vectorFromTo [0,0,0]);
|
2015-08-13 17:33:55 +00:00
|
|
|
|
2016-02-02 14:03:06 +00:00
|
|
|
private _closeInMax = _startDistanceFromCenter;
|
|
|
|
private _closeInMin = 0;
|
2015-08-13 17:33:55 +00:00
|
|
|
|
|
|
|
while {(_closeInMax - _closeInMin) > 0.01} do {
|
|
|
|
_closeInDistance = (_closeInMax + _closeInMin) / 2;
|
|
|
|
_endPosTestOffset = _startingOffset vectorAdd (_closeInUnitVector vectorMultiply _closeInDistance);
|
|
|
|
_endPosTestOffset set [2, (_startingOffset select 2)];
|
2016-02-02 14:03:06 +00:00
|
|
|
private _endPosTest = _target modelToWorldVisual _endPosTestOffset;
|
2015-08-13 17:33:55 +00:00
|
|
|
|
2016-02-02 14:03:06 +00:00
|
|
|
private _doesIntersect = false;
|
2015-08-13 17:33:55 +00:00
|
|
|
{
|
|
|
|
if (_doesIntersect) exitWith {};
|
2016-02-02 14:03:06 +00:00
|
|
|
private _startingPosShifted = _startingPosition vectorAdd _x;
|
2015-08-13 17:33:55 +00:00
|
|
|
_startASL = if (surfaceIsWater _startingPosShifted) then {_startingPosShifted} else {ATLtoASL _startingPosShifted};
|
|
|
|
{
|
|
|
|
_endPosShifted = _endPosTest vectorAdd _x;
|
2016-02-02 14:03:06 +00:00
|
|
|
private _endASL = if (surfaceIsWater _startingPosShifted) then {_endPosShifted} else {ATLtoASL _endPosShifted};
|
2015-08-13 17:33:55 +00:00
|
|
|
|
|
|
|
//Uncomment to see the lazor show, and see how the scanning works:
|
|
|
|
// drawLine3D [_startingPosShifted, _endPosShifted, [1,0,0,1]];
|
|
|
|
if (_target in lineIntersectsWith [_startASL, _endASL, _unit]) exitWith {_doesIntersect = true};
|
|
|
|
} 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]];
|
|
|
|
|
|
|
|
if (_doesIntersect) then {
|
|
|
|
_closeInMax = _closeInDistance;
|
|
|
|
} else {
|
|
|
|
_closeInMin = _closeInDistance;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
_closeInDistance = (_closeInMax + _closeInMin) / 2;
|
|
|
|
|
|
|
|
//Checks (too close to center or can't attach)
|
2016-02-25 09:11:28 +00:00
|
|
|
if ((_startDistanceFromCenter - _closeInDistance) < 0.1) exitWith {
|
2015-08-13 17:33:55 +00:00
|
|
|
TRACE_2("no valid spot found",_closeInDistance,_startDistanceFromCenter);
|
|
|
|
[localize LSTRING(Failed)] call EFUNC(common,displayTextStructured);
|
|
|
|
};
|
|
|
|
|
|
|
|
//Move it out slightly, for visibility sake (better to look a little funny than be embedded//sunk in the hull and be useless)
|
2016-02-02 14:03:06 +00:00
|
|
|
_closeInDistance = (_closeInDistance - 0.05);
|
2015-08-13 17:33:55 +00:00
|
|
|
|
|
|
|
_endPosTestOffset = _startingOffset vectorAdd (_closeInUnitVector vectorMultiply _closeInDistance);
|
|
|
|
_endPosTestOffset set [2, (_startingOffset select 2)];
|
|
|
|
|
2015-08-21 20:43:45 +00:00
|
|
|
[
|
|
|
|
2,
|
|
|
|
[_unit, _nozzle, _target, _endPosTestOffset],
|
|
|
|
{
|
|
|
|
params ["_args"];
|
2016-02-02 14:03:06 +00:00
|
|
|
_args params [["_unit", objNull, [objNull]], ["_nozzle", objNull, [objNull]], ["_target", objNull, [objNull]], ["_endPosTestOffset", [0,0,0], [[]], 3]];
|
2016-02-19 16:24:32 +00:00
|
|
|
_unit setVariable [QGVAR(nozzle), nil, true];
|
2015-08-21 20:43:45 +00:00
|
|
|
_unit setVariable [QGVAR(isRefueling), false];
|
2016-01-19 15:34:59 +00:00
|
|
|
[_unit, "forceWalk", "ACE_refuel", false] call EFUNC(common,statusEffect_set);
|
2015-08-21 20:43:45 +00:00
|
|
|
REFUEL_UNHOLSTER_WEAPON
|
2016-02-02 14:03:06 +00:00
|
|
|
private _actionID = _unit getVariable [QGVAR(ReleaseActionID), -1];
|
2015-08-21 20:43:45 +00:00
|
|
|
if (_actionID != -1) then {
|
|
|
|
_unit removeAction _actionID;
|
|
|
|
_unit setVariable [QGVAR(ReleaseActionID), nil];
|
|
|
|
};
|
2015-08-13 17:33:55 +00:00
|
|
|
|
2015-08-21 20:43:45 +00:00
|
|
|
detach _nozzle;
|
|
|
|
_nozzle attachTo [_target, _endPosTestOffset];
|
2016-02-02 14:47:05 +00:00
|
|
|
_endPosTestOffset params ["_x", "_y"];
|
2016-02-02 14:03:06 +00:00
|
|
|
private _bb = boundingBoxReal _target;
|
|
|
|
_bb params ["_ll", "_rr"];
|
|
|
|
_ll set [2, 0];
|
|
|
|
_rr set [2, 0];
|
2016-02-02 14:47:05 +00:00
|
|
|
_ll params ["_x1", "_y1"];
|
|
|
|
_rr params ["_x2", "_y2"];
|
2016-02-02 14:03:06 +00:00
|
|
|
private _c1 = _ll vectorCos _endPosTestOffset;
|
|
|
|
private _c2 = _ll vectorCos [_x1, _y2, 0];
|
2016-02-02 14:45:57 +00:00
|
|
|
private _cn = (_ll vectorCrossProduct [0, 0, 1]) vectorCos _endPosTestOffset;
|
2016-02-02 14:03:06 +00:00
|
|
|
private _dirAndUp = [[1, 0, 0],[0, 0, 1]];
|
2016-02-02 14:45:57 +00:00
|
|
|
if (_c1 > _c2 && (_cn > 0)) then {
|
2016-02-02 14:03:06 +00:00
|
|
|
_dirAndUp = [[1, 0, 0.8],[0, 0, 1]];
|
|
|
|
} else {
|
|
|
|
_c1 = [_x1, _y2, 0] vectorCos _endPosTestOffset;
|
|
|
|
_c2 = [_x1, _y2, 0] vectorCos _rr;
|
2016-02-02 14:45:57 +00:00
|
|
|
_cn = ([_x1, _y2, 0] vectorCrossProduct [0, 0, 1]) vectorCos _endPosTestOffset;
|
|
|
|
if (_c1 > _c2 && (_cn > 0)) then {
|
2016-02-02 14:03:06 +00:00
|
|
|
_dirAndUp = [[0, -1, 0.8],[0, 0, 1]];
|
|
|
|
} else {
|
|
|
|
_c1 = _rr vectorCos _endPosTestOffset;
|
|
|
|
_c2 = _rr vectorCos [_x2, _y1, 0];
|
2016-02-02 14:45:57 +00:00
|
|
|
_cn = (_rr vectorCrossProduct [0, 0, 1]) vectorCos _endPosTestOffset;
|
|
|
|
if (_c1 > _c2 && (_cn > 0)) then {
|
2016-02-02 14:03:06 +00:00
|
|
|
_dirAndUp = [[-1, 0, 0.8],[0, 0, 1]];
|
|
|
|
} else {
|
|
|
|
_dirAndUp = [[0, 1, 0.8],[0, 0, 1]];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2016-03-05 17:16:09 +00:00
|
|
|
["setVectorDirAndUp", _nozzle, [_nozzle, _dirAndUp]] call EFUNC(common,objectEvent);
|
2015-08-21 20:43:45 +00:00
|
|
|
_nozzle setVariable [QGVAR(sink), _target, true];
|
|
|
|
_nozzle setVariable [QGVAR(isConnected), true, true];
|
|
|
|
_target setVariable [QGVAR(nozzle), _nozzle, true];
|
2015-08-13 17:33:55 +00:00
|
|
|
|
2015-08-22 11:34:24 +00:00
|
|
|
_source = _nozzle getVariable QGVAR(source);
|
2016-02-26 15:35:34 +00:00
|
|
|
private _fuel = [_source] call FUNC(getFuel);
|
|
|
|
if (_fuel == REFUEL_INFINITE_FUEL) then {
|
|
|
|
_source setVariable [QGVAR(fuelCounter), 0, true];
|
|
|
|
} else {
|
|
|
|
_source setVariable [QGVAR(fuelCounter), _fuel, true];
|
|
|
|
};
|
2015-08-22 11:34:24 +00:00
|
|
|
|
2015-08-21 20:43:45 +00:00
|
|
|
[_unit, _target, _nozzle, _endPosTestOffset] call FUNC(refuel);
|
|
|
|
},
|
|
|
|
"",
|
|
|
|
localize LSTRING(ConnectAction),
|
|
|
|
{true},
|
|
|
|
["isnotinside"]
|
|
|
|
] call EFUNC(common,progressBar);
|