2015-08-13 17:33:55 +00:00
|
|
|
/*
|
|
|
|
* Author: GitHawk
|
2015-08-20 20:10:26 +00:00
|
|
|
* Refuels the vehicle.
|
2015-08-13 17:33:55 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2015-08-20 20:10:26 +00:00
|
|
|
* 0: Unit <OBJECT>
|
|
|
|
* 1: Target <OBJECT>
|
|
|
|
* 2: Nozzle <OBJECT>
|
2016-02-02 14:03:06 +00:00
|
|
|
* 3: Connection Point <ARRAY>
|
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
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2016-03-05 16:44:03 +00:00
|
|
|
#define PFH_STEPSIZE 1
|
2015-08-13 17:33:55 +00:00
|
|
|
|
2016-02-02 14:03:06 +00:00
|
|
|
params [["_unit", objNull, [objNull]], ["_target", objNull, [objNull]], ["_nozzle", objNull, [objNull]], ["_connectToPoint", [0,0,0], [[]], 3]];
|
2015-08-13 17:33:55 +00:00
|
|
|
|
2016-02-02 14:03:06 +00:00
|
|
|
private _rate = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(flowRate)) * GVAR(rate) * PFH_STEPSIZE;
|
|
|
|
private _maxFuel = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(fuelCapacity));
|
2015-08-15 14:49:57 +00:00
|
|
|
|
2015-08-16 23:57:05 +00:00
|
|
|
[{
|
2015-08-13 17:33:55 +00:00
|
|
|
params ["_args", "_pfID"];
|
2016-02-02 14:03:06 +00:00
|
|
|
_args params [["_source", objNull, [objNull]], ["_sink", objNull, [objNull]], ["_unit", objNull, [objNull]], ["_nozzle", objNull, [objNull]], ["_rate", 1, [0]], ["_startFuel", 0, [0]], ["_maxFuel", 0, [0]], ["_connectFromPoint", [0,0,0], [[]], 3], ["_connectToPoint", [0,0,0], [[]], 3]];
|
2015-08-16 23:57:05 +00:00
|
|
|
|
2015-12-12 14:12:50 +00:00
|
|
|
if !(_nozzle getVariable [QGVAR(isConnected), false]) exitWith {
|
2016-01-01 02:51:44 +00:00
|
|
|
[_pfID] call CBA_fnc_removePerFrameHandler;
|
2015-12-11 21:45:28 +00:00
|
|
|
};
|
|
|
|
|
2015-08-20 20:10:26 +00:00
|
|
|
if (!alive _source || {!alive _sink}) exitWith {
|
2015-08-22 11:34:24 +00:00
|
|
|
[objNull, _nozzle] call FUNC(dropNozzle);
|
2015-08-18 14:09:59 +00:00
|
|
|
_nozzle setVariable [QGVAR(isConnected), false, true];
|
2015-08-17 22:42:35 +00:00
|
|
|
_nozzle setVariable [QGVAR(sink), objNull, true];
|
|
|
|
_sink setVariable [QGVAR(nozzle), objNull, true];
|
2015-08-13 17:33:55 +00:00
|
|
|
[_pfID] call cba_fnc_removePerFrameHandler;
|
|
|
|
};
|
2016-02-02 14:03:06 +00:00
|
|
|
private _tooFar = ((_sink modelToWorld _connectToPoint) distance (_source modelToWorld _connectFromPoint)) > (REFUEL_HOSE_LENGTH - 2);
|
2015-12-21 16:54:52 +00:00
|
|
|
if (_tooFar && {!(_nozzle getVariable [QGVAR(jerryCan), false])}) exitWith {
|
2015-08-18 21:18:32 +00:00
|
|
|
[LSTRING(Hint_TooFar), 2, _unit] call EFUNC(common,displayTextStructured);
|
|
|
|
|
2015-08-22 11:34:24 +00:00
|
|
|
[objNull, _nozzle] call FUNC(dropNozzle);
|
2015-08-18 21:18:32 +00:00
|
|
|
_nozzle setVariable [QGVAR(isConnected), false, true];
|
|
|
|
_nozzle setVariable [QGVAR(sink), objNull, true];
|
|
|
|
_sink setVariable [QGVAR(nozzle), objNull, true];
|
2015-08-13 17:33:55 +00:00
|
|
|
[_pfID] call cba_fnc_removePerFrameHandler;
|
|
|
|
};
|
2015-08-18 21:18:32 +00:00
|
|
|
|
2016-02-02 14:03:06 +00:00
|
|
|
private _finished = false;
|
|
|
|
private _fueling = _nozzle getVariable [QGVAR(isRefueling), false];
|
2015-08-18 21:18:32 +00:00
|
|
|
if (_fueling) then {
|
2016-03-04 12:59:14 +00:00
|
|
|
if (isEngineOn _sink) exitWith {
|
|
|
|
_nozzle setVariable [QGVAR(isRefueling), false, true];
|
|
|
|
};
|
2016-02-02 14:03:06 +00:00
|
|
|
private _fuelInSource = [_source] call FUNC(getFuel);
|
2015-08-18 21:18:32 +00:00
|
|
|
if (_fuelInSource == 0) exitWith {
|
|
|
|
[LSTRING(Hint_SourceEmpty), 2, _unit] call EFUNC(common,displayTextStructured);
|
|
|
|
_nozzle setVariable [QGVAR(isRefueling), false, true];
|
|
|
|
};
|
|
|
|
if !(_fuelInSource == REFUEL_INFINITE_FUEL) then {
|
|
|
|
_fuelInSource = _fuelInSource - _rate;
|
2016-02-26 15:35:34 +00:00
|
|
|
} else {
|
|
|
|
_source setVariable [QGVAR(fuelCounter), (_source getVariable [QGVAR(fuelCounter), 0]) + _rate, true];
|
2015-08-18 21:18:32 +00:00
|
|
|
};
|
2016-02-26 15:35:34 +00:00
|
|
|
if (_fuelInSource < 0 && {_fuelInSource > REFUEL_INFINITE_FUEL}) then {
|
2015-08-18 21:18:32 +00:00
|
|
|
_fuelInSource = 0;
|
|
|
|
_finished = true;
|
|
|
|
[LSTRING(Hint_SourceEmpty), 2, _unit] call EFUNC(common,displayTextStructured);
|
|
|
|
};
|
2015-08-16 23:57:05 +00:00
|
|
|
|
2016-02-02 14:03:06 +00:00
|
|
|
private _fuelInSink = (_unit getVariable [QGVAR(tempFuel), _startFuel]) + ( _rate / _maxFuel);
|
2015-08-18 21:18:32 +00:00
|
|
|
if (_fuelInSink > 1) then {
|
|
|
|
_fuelInSink = 1;
|
|
|
|
_finished = true;
|
|
|
|
[LSTRING(Hint_Completed), 2, _unit] call EFUNC(common,displayTextStructured);
|
|
|
|
};
|
2015-08-22 11:34:24 +00:00
|
|
|
_unit setVariable [QGVAR(tempFuel), _fuelInSink];
|
|
|
|
|
2016-05-24 13:13:11 +00:00
|
|
|
["ace_setFuel", [_sink, _fuelInSink], _sink] call CBA_fnc_targetEvent;
|
2015-08-21 20:43:45 +00:00
|
|
|
[_source, _fuelInSource] call FUNC(setFuel);
|
2015-08-22 11:34:24 +00:00
|
|
|
} else {
|
|
|
|
_unit setVariable [QGVAR(tempFuel), fuel _sink];
|
2015-08-13 17:33:55 +00:00
|
|
|
};
|
2015-08-16 23:57:05 +00:00
|
|
|
|
2015-08-20 20:10:26 +00:00
|
|
|
if (_finished) exitWith {
|
2015-08-17 22:42:35 +00:00
|
|
|
_nozzle setVariable [QGVAR(isRefueling), false, true];
|
2015-08-13 17:33:55 +00:00
|
|
|
};
|
2015-08-20 20:10:26 +00:00
|
|
|
},
|
|
|
|
PFH_STEPSIZE,
|
|
|
|
[_nozzle getVariable QGVAR(source),
|
|
|
|
_target,
|
|
|
|
_unit,
|
|
|
|
_nozzle,
|
|
|
|
_rate,
|
|
|
|
fuel _target,
|
|
|
|
_maxFuel,
|
|
|
|
_nozzle getVariable [QGVAR(attachPos), [0,0,0]],
|
|
|
|
_connectToPoint]
|
|
|
|
] call cba_fnc_addPerFrameHandler;
|