2018-09-17 19:19:29 +00:00
#include "script_component.hpp"
2015-08-13 17:33:55 +00:00
/*
* Author: GitHawk
2015-08-20 20:10:26 +00:00
* Take a fuel nozzle either from a fuel truck/station or from the ground.
2015-08-13 17:33:55 +00:00
*
* Arguments:
2015-08-20 20:10:26 +00:00
* 0: Unit <OBJECT>
2017-09-10 19:43:03 +00:00
* 1: Fuel Source or 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:
2017-09-10 19:43:03 +00:00
* [player, cursorObject] call ace_refuel_fnc_takeNozzle
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
*/
2016-05-12 15:11:35 +00:00
params [
["_unit", objNull, [objNull]],
2017-09-10 19:43:03 +00:00
["_object", objNull, [objNull]]
2016-05-12 15:11:35 +00:00
];
2015-08-13 17:33:55 +00:00
2017-09-10 19:43:03 +00:00
[
2022-08-17 11:25:37 +00:00
GVAR(progressDuration),
2017-09-10 19:43:03 +00:00
[_unit, _object],
{
params ["_args"];
_args params ["_unit", "_object"];
2015-08-13 17:33:55 +00:00
2017-09-10 19:43:03 +00:00
if !([_unit, _object] call FUNC(canTakeNozzle)) exitWith {};
2015-08-21 20:43:45 +00:00
2017-09-10 19:43:03 +00:00
private _source = _object;
private _nozzle = _object;
if (typeOf _object isEqualTo QGVAR(fuelNozzle) || {_object getVariable [QGVAR(jerryCan), false]}) then { // func is called on muzzle either connected or on ground
_source = _nozzle getVariable QGVAR(source);
if (_nozzle getVariable [QGVAR(jerryCan), false]) then {
_nozzle attachTo [_unit, [0,1,0], "pelvis"];
} else {
_nozzle attachTo [_unit, [-0.02,0.05,-0.12], "righthandmiddle1"];
};
} else { // func is called on fuel truck
_nozzle = QGVAR(fuelNozzle) createVehicle [0,0,0];
_nozzle attachTo [_unit, [-0.02,0.05,-0.12], "righthandmiddle1"];
2015-08-13 17:33:55 +00:00
2017-09-10 19:43:03 +00:00
private _ropeTarget = _source;
if !(_source isKindOf "AllVehicles") then {
2017-05-29 18:48:02 +00:00
private _helper = QGVAR(helper) createVehicle [0,0,0];
[QEGVAR(common,hideObjectGlobal), [_helper, true]] call CBA_fnc_serverEvent;
2021-02-18 18:58:08 +00:00
if ((getText (configOf _source >> "simulation")) isEqualTo "thingX") then {
2017-09-10 19:43:03 +00:00
_helper attachTo [_source, [0,0,0]];
2017-05-29 18:48:02 +00:00
} else {
2017-09-10 19:43:03 +00:00
_helper setPosWorld (getPosWorld _source);
_helper setDir (getDir _source);
_helper setVectorUp (vectorUp _source);
2017-05-29 18:48:02 +00:00
};
2017-09-10 19:43:03 +00:00
_nozzle setVariable [QGVAR(helper), _helper, true];
2017-05-29 18:48:02 +00:00
_ropeTarget = _helper;
2016-02-26 09:46:12 +00:00
};
2021-02-18 18:58:08 +00:00
private _attachPos = _source getVariable [QGVAR(hooks), getArray (configOf _source >> QGVAR(hooks))];
2017-09-10 19:43:03 +00:00
if (_attachPos isEqualTo []) then {
_attachPos = [[0,0,0]];
2015-08-21 20:43:45 +00:00
};
2017-09-10 19:43:03 +00:00
if (count _attachPos == 1) then {
_attachPos = _attachPos select 0;
2015-12-21 16:54:52 +00:00
} else {
2017-09-10 19:43:03 +00:00
// select closest hook
private _hookDistances = _attachPos apply {_unit distance (_source modelToWorld _x)};
_attachPos = _attachPos select (_hookDistances find selectMin _hookDistances);
2015-12-21 16:54:52 +00:00
};
2017-09-10 19:43:03 +00:00
private _hoseLength = _source getVariable [QGVAR(hoseLength), GVAR(hoseLength)];
2022-08-17 11:00:54 +00:00
private _rope = ropeCreate [_ropeTarget, _attachPos, _nozzle, [0, -0.20, 0.12], _hoseLength, [], [], QGVAR(fuelHose)];
2017-09-10 19:43:03 +00:00
_nozzle setVariable [QGVAR(rope), _rope, true];
_nozzle setVariable [QGVAR(attachPos), _attachPos, true];
_nozzle setVariable [QGVAR(source), _source, true];
2015-08-21 20:43:45 +00:00
2017-09-10 19:43:03 +00:00
[_source, "blockEngine", "ACE_Refuel", true] call EFUNC(common,statusEffect_set);
_source setVariable [QGVAR(isConnected), true, true];
_source setVariable [QGVAR(ownedNozzle), _nozzle, true];
};
_unit setVariable [QGVAR(nozzle), _nozzle, true];
_unit setVariable [QGVAR(isRefueling), true];
// holster weapon
_unit setVariable [QGVAR(selectedWeaponOnRefuel), currentWeapon _unit];
_unit call EFUNC(common,fixLoweredRifleAnimation);
_unit action ["SwitchWeapon", _unit, _unit, 299];
[_unit, "forceWalk", "ACE_refuel", true] call EFUNC(common,statusEffect_set);
2017-12-07 17:26:21 +00:00
[_unit, "blockThrow", "ACE_refuel", true] call EFUNC(common,statusEffect_set);
2016-10-08 13:31:39 +00:00
2017-09-10 19:43:03 +00:00
[_unit, _nozzle] call FUNC(startNozzleInHandsPFH);
},
{},
localize LSTRING(TakeNozzleAction),
{true},
2017-10-01 18:38:11 +00:00
[INTERACT_EXCEPTIONS_REFUELING]
2017-09-10 19:43:03 +00:00
] call EFUNC(common,progressBar);