2015-08-13 17:33:55 +00:00
|
|
|
/*
|
|
|
|
* Author: GitHawk et.al.
|
2015-08-20 20:10:26 +00:00
|
|
|
* Connect a fuel nozzle.
|
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>
|
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:
|
2015-08-21 20:43:45 +00:00
|
|
|
* [player, tank] call ace_refuel_fnc_connectNozzle
|
2015-08-13 17:33:55 +00:00
|
|
|
*
|
2015-08-14 01:18:54 +00:00
|
|
|
* Public: No
|
2015-08-13 17:33:55 +00:00
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
|
|
|
#define PLACE_WAITING -1
|
|
|
|
#define PLACE_CANCEL 0
|
|
|
|
#define PLACE_APPROVE 1
|
|
|
|
|
|
|
|
private ["_nozzle", "_actionID"];
|
|
|
|
params ["_unit", "_target"];
|
|
|
|
|
2015-08-22 11:34:24 +00:00
|
|
|
_nozzle = _unit getVariable [QGVAR(nozzle), objNull];
|
|
|
|
if (isNull _nozzle) exitWith {};
|
2015-08-13 17:33:55 +00:00
|
|
|
|
|
|
|
GVAR(placeAction) = PLACE_WAITING;
|
|
|
|
|
|
|
|
[{[localize LSTRING(Connect_Action), ""] call EFUNC(interaction,showMouseHint)}, []] call EFUNC(common,execNextFrame);
|
|
|
|
_unit setVariable [QGVAR(placeActionEH), [_unit, "DefaultAction", {true}, {GVAR(placeAction) = PLACE_APPROVE;}] call EFUNC(common,AddActionEventHandler)];
|
|
|
|
|
|
|
|
_actionID = _unit addAction [format ["<t color='#FF0000'>%1</t>", localize LSTRING(Cancel)], {GVAR(placeAction) = PLACE_CANCEL;}];
|
|
|
|
|
2015-08-20 20:10:26 +00:00
|
|
|
[{
|
2015-08-13 17:33:55 +00:00
|
|
|
private["_virtualPos", "_virtualPosASL", "_lineInterection"];
|
|
|
|
params ["_args","_pfID"];
|
2015-08-14 01:18:54 +00:00
|
|
|
_args params ["_unit", "_target", "_nozzle", "_actionID"];
|
2015-08-20 20:10:26 +00:00
|
|
|
|
2015-08-13 17:33:55 +00:00
|
|
|
_virtualPosASL = (eyePos _unit) vectorAdd (positionCameraToWorld [0,0,0.6]) vectorDiff (positionCameraToWorld [0,0,0]);
|
|
|
|
if (cameraView == "EXTERNAL") then {
|
|
|
|
_virtualPosASL = _virtualPosASL vectorAdd ((positionCameraToWorld [0.3,0,0]) vectorDiff (positionCameraToWorld [0,0,0]));
|
|
|
|
};
|
|
|
|
_virtualPos = _virtualPosASL call EFUNC(common,ASLToPosition);
|
|
|
|
_lineInterection = lineIntersects [eyePos ace_player, _virtualPosASL, ace_player];
|
2015-08-20 20:10:26 +00:00
|
|
|
|
2015-08-13 17:33:55 +00:00
|
|
|
//Don't allow placing in a bad position:
|
|
|
|
if (_lineInterection && {GVAR(placeAction) == PLACE_APPROVE}) then {GVAR(placeAction) = PLACE_WAITING;};
|
2015-08-20 20:10:26 +00:00
|
|
|
|
2015-08-13 17:33:55 +00:00
|
|
|
if ((GVAR(placeAction) != PLACE_WAITING) ||
|
|
|
|
{_unit != ace_player} ||
|
|
|
|
{!([_unit, _target, []] call EFUNC(common,canInteractWith))}) then {
|
|
|
|
|
|
|
|
[_pfID] call CBA_fnc_removePerFrameHandler;
|
|
|
|
[] call EFUNC(interaction,hideMouseHint);
|
|
|
|
[_unit, "DefaultAction", (_unit getVariable [QGVAR(placeActionEH), -1])] call EFUNC(common,removeActionEventHandler);
|
|
|
|
_unit removeAction _actionID;
|
2015-08-20 20:10:26 +00:00
|
|
|
|
2015-08-13 17:33:55 +00:00
|
|
|
if (GVAR(placeAction) == PLACE_APPROVE) then {
|
|
|
|
[_unit, _target, _virtualPos, _nozzle] call FUNC(ConnectNozzleAction);
|
|
|
|
};
|
|
|
|
}; // TODO add model like in attach/functions/fnc_attach
|
2015-08-20 20:10:26 +00:00
|
|
|
}, 0, [_unit, _target, _nozzle, _actionID] ] call cba_fnc_addPerFrameHandler;
|