2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
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>
|
2017-09-10 19:43:03 +00:00
|
|
|
* 1: Vehicle <OBJECT>
|
2017-06-23 03:58:57 +00:00
|
|
|
* 2: Visual Position ASL <ARRAY>
|
2015-08-20 20:10:26 +00:00
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
2017-09-10 19:43:03 +00:00
|
|
|
params [["_unit", objNull, [objNull]], ["_sink", objNull, [objNull]], ["_startingPosASL", [0,0,0], [[]], 3], ["_nozzle", objNull, [objNull]]];
|
2015-08-13 17:33:55 +00:00
|
|
|
|
|
|
|
|
2017-06-23 03:58:57 +00:00
|
|
|
private _bestPosASL = [];
|
2021-10-09 20:32:53 +00:00
|
|
|
private _bestPosDistance = 1e38;
|
2017-06-23 03:58:57 +00:00
|
|
|
private _viewPos = _startingPosASL vectorAdd (((positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [0,0,1])) vectorMultiply 3);
|
2021-10-10 13:37:05 +00:00
|
|
|
private _modelVector = _startingPosASL vectorFromTo (_sink modelToWorldWorld [0,0,0]);
|
|
|
|
private _modelVectorLow = _startingPosASL vectorFromTo (_sink modelToWorldWorld [0,0,-1]);
|
2015-08-13 17:33:55 +00:00
|
|
|
|
2017-06-23 03:58:57 +00:00
|
|
|
{
|
|
|
|
private _endPosASL = _x;
|
|
|
|
// [_startingPosASL, _endPosASL, [1,0,0,1]] call EFUNC(common,addLineToDebugDraw); // Debug scan lines
|
|
|
|
private _intersections = lineIntersectsSurfaces [_startingPosASL, _endPosASL, _unit];
|
2015-08-13 17:33:55 +00:00
|
|
|
{
|
2017-06-23 03:58:57 +00:00
|
|
|
_x params ["_intersectPosASL", "", "_intersectObject"];
|
2017-09-10 19:43:03 +00:00
|
|
|
if (_intersectObject == _sink) then {
|
2017-06-23 03:58:57 +00:00
|
|
|
private _distance = _startingPosASL distance _intersectPosASL;
|
|
|
|
if (_distance < _bestPosDistance) then {
|
|
|
|
_bestPosDistance = _distance;
|
|
|
|
_bestPosASL = _intersectPosASL;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} forEach _intersections;
|
|
|
|
} forEach [
|
|
|
|
// Shoot rays towards player's view angle and see which spot is closest
|
|
|
|
_startingPosASL vectorAdd (((positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [0,0,1])) vectorMultiply 3),
|
|
|
|
_startingPosASL vectorAdd (((positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [-0.25,0,1])) vectorMultiply 3),
|
|
|
|
_startingPosASL vectorAdd (((positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [0.25,0,1])) vectorMultiply 3),
|
|
|
|
_startingPosASL vectorAdd (((positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [0,-0.25,1])) vectorMultiply 3),
|
|
|
|
_startingPosASL vectorAdd (((positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [-0.25,-0.25,1])) vectorMultiply 3),
|
|
|
|
_startingPosASL vectorAdd (((positionCameraToWorld [0,0,0]) vectorFromTo (positionCameraToWorld [0.25,-0.25,1])) vectorMultiply 3),
|
2021-10-10 13:37:05 +00:00
|
|
|
_sink modelToWorldWorld [0,0,0], // Try old method of just using model center
|
|
|
|
_sink modelToWorldWorld [0,0,-0.5]
|
2017-06-23 03:58:57 +00:00
|
|
|
];
|
2015-08-13 17:33:55 +00:00
|
|
|
|
|
|
|
//Checks (too close to center or can't attach)
|
2017-06-23 03:58:57 +00:00
|
|
|
if (_bestPosASL isEqualTo []) exitWith {
|
2015-08-13 17:33:55 +00:00
|
|
|
[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)
|
2017-06-23 03:58:57 +00:00
|
|
|
_bestPosASL = _bestPosASL vectorAdd ((_bestPosASL vectorFromTo _startingPosASL) vectorMultiply 0.05);
|
2015-08-13 17:33:55 +00:00
|
|
|
|
2017-09-10 19:43:03 +00:00
|
|
|
private _attachPosModel = _sink worldToModel (ASLtoAGL _bestPosASL);
|
2015-08-13 17:33:55 +00:00
|
|
|
|
2015-08-21 20:43:45 +00:00
|
|
|
[
|
2022-08-17 11:25:37 +00:00
|
|
|
GVAR(progressDuration),
|
2017-09-10 19:43:03 +00:00
|
|
|
[_unit, _nozzle, _sink, _attachPosModel],
|
2015-08-21 20:43:45 +00:00
|
|
|
{
|
|
|
|
params ["_args"];
|
2017-09-10 19:43:03 +00:00
|
|
|
_args params [["_unit", objNull, [objNull]], ["_nozzle", objNull, [objNull]], ["_sink", 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];
|
2023-02-17 02:06:11 +00:00
|
|
|
|
|
|
|
private _source = _nozzle getVariable QGVAR(source);
|
2015-08-13 17:33:55 +00:00
|
|
|
|
2015-08-21 20:43:45 +00:00
|
|
|
detach _nozzle;
|
2017-09-10 19:43:03 +00:00
|
|
|
_nozzle attachTo [_sink, _endPosTestOffset];
|
2016-02-02 14:47:05 +00:00
|
|
|
_endPosTestOffset params ["_x", "_y"];
|
2017-09-10 19:43:03 +00:00
|
|
|
private _bb = boundingBoxReal _sink;
|
2016-02-02 14:03:06 +00:00
|
|
|
_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-06-04 10:12:56 +00:00
|
|
|
[QEGVAR(common,setVectorDirAndUp), [_nozzle, _dirAndUp], _nozzle] call CBA_fnc_targetEvent;
|
2017-09-16 09:36:42 +00:00
|
|
|
if (_nozzle isKindOf "Land_CanisterFuel_F") then { _nozzle setVariable [QEGVAR(cargo,canLoad), false, true]; };
|
2017-09-10 19:43:03 +00:00
|
|
|
_nozzle setVariable [QGVAR(sink), _sink, true];
|
2015-08-21 20:43:45 +00:00
|
|
|
_nozzle setVariable [QGVAR(isConnected), true, true];
|
2017-09-10 19:43:03 +00:00
|
|
|
_sink setVariable [QGVAR(nozzle), _nozzle, true];
|
2015-08-13 17:33:55 +00:00
|
|
|
|
2023-02-17 02:06:11 +00:00
|
|
|
// Reset fuel counter
|
|
|
|
_source setVariable [QGVAR(fuelCounter), 0, true];
|
2015-08-22 11:34:24 +00:00
|
|
|
|
2017-09-10 19:43:03 +00:00
|
|
|
[_unit, _sink, _nozzle, _endPosTestOffset] call FUNC(refuel);
|
2017-09-21 14:24:58 +00:00
|
|
|
|
2023-02-17 02:06:11 +00:00
|
|
|
private _canReceive = getNumber ((configOf _sink) >> QGVAR(canReceive)) == 1;
|
|
|
|
private _isContainer = ([_sink] call FUNC(getCapacity)) != REFUEL_DISABLED_FUEL;
|
|
|
|
|
|
|
|
// Decide if cargo or vehicle will be refueled
|
|
|
|
switch (true) do {
|
|
|
|
case (_canReceive && {!_isContainer || {_sink == _source}}): {
|
|
|
|
// is not a refueling vehicle or refueling vehicle tries to refuel itself
|
|
|
|
if ([_unit, _nozzle, false] call FUNC(canTurnOn)) then {
|
|
|
|
[_unit, _nozzle, false] call FUNC(turnOn);
|
|
|
|
} else {
|
|
|
|
[localize LSTRING(CouldNotTurnOn)] call EFUNC(common,displayText);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
case (!_canReceive && _isContainer): {
|
|
|
|
if ([_unit, _nozzle, true] call FUNC(canTurnOn)) then {
|
|
|
|
[_unit, _nozzle, true] call FUNC(turnOn);
|
|
|
|
} else {
|
|
|
|
[localize LSTRING(CouldNotTurnOn)] call EFUNC(common,displayText);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
default {
|
|
|
|
/* Target is a refueling vehicle, let user manually decide if he wants to refuel cargo or vehicle itself */
|
|
|
|
};
|
2017-09-21 14:24:58 +00:00
|
|
|
};
|
2015-08-21 20:43:45 +00:00
|
|
|
},
|
|
|
|
"",
|
|
|
|
localize LSTRING(ConnectAction),
|
|
|
|
{true},
|
2017-09-10 19:43:03 +00:00
|
|
|
[INTERACT_EXCEPTIONS]
|
2015-08-21 20:43:45 +00:00
|
|
|
] call EFUNC(common,progressBar);
|