ACE3/addons/refuel/functions/fnc_refuel.sqf

100 lines
3.4 KiB
Plaintext
Raw Normal View History

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>
* 3: Connection Point <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
*
* Public: No
*/
#include "script_component.hpp"
2015-08-20 20:10:26 +00:00
#define PFH_STEPSIZE 0.1
2015-08-13 17:33:55 +00:00
2015-08-20 20:10:26 +00:00
private ["_rate", "_maxFuel"];
params ["_unit", "_target", "_nozzle", "_connectToPoint"];
2015-08-13 17:33:55 +00:00
2015-08-20 20:10:26 +00:00
_rate = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(flowRate)) * GVAR(rate) * PFH_STEPSIZE;
_maxFuel = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(fuelCapacity));
[{
2015-08-20 20:10:26 +00:00
private ["_source", "_tooFar", "_fuelInSource", "_fuelInSink", "_finished", "_fueling"];
2015-08-13 17:33:55 +00:00
params ["_args", "_pfID"];
2015-08-20 20:10:26 +00:00
_args params ["_source", "_sink", "_unit", "_nozzle", "_rate", "_startFuel", "_maxFuel", "_connectFromPoint", "_connectToPoint"];
_fueling = _nozzle getVariable [QGVAR(isRefueling), false];
2015-08-20 20:10:26 +00:00
if (!alive _source || {!alive _sink}) exitWith {
[objNull, _nozzle] call FUNC(dropNozzle);
2015-08-18 14:09:59 +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;
};
_tooFar = ((_sink modelToWorld _connectToPoint) distance (_source modelToWorld _connectFromPoint)) > (REFUEL_HOSE_LENGTH - 2);
if (_tooFar) exitWith {
[LSTRING(Hint_TooFar), 2, _unit] call EFUNC(common,displayTextStructured);
[objNull, _nozzle] call FUNC(dropNozzle);
_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-13 17:33:55 +00:00
_finished = false;
if (_fueling) then {
_fuelInSource = [_source] call FUNC(getFuel);
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;
};
if (_fuelInSource < 0 && {_fuelInSource > -1}) then {
_fuelInSource = 0;
_finished = true;
[LSTRING(Hint_SourceEmpty), 2, _unit] call EFUNC(common,displayTextStructured);
};
_fuelInSink = (_unit getVariable [QGVAR(tempFuel), _startFuel]) + ( _rate / _maxFuel);
if (_fuelInSink > 1) then {
_fuelInSink = 1;
_finished = true;
[LSTRING(Hint_Completed), 2, _unit] call EFUNC(common,displayTextStructured);
};
_unit setVariable [QGVAR(tempFuel), _fuelInSink];
if !(local _sink) then {
[[_sink, _fuelInSink], "{(_this select 0) setFuel (_this select 1)}", _sink] call EFUNC(common,execRemoteFnc);
} else {
_sink setFuel _fuelInSink;
};
2015-08-21 20:43:45 +00:00
[_source, _fuelInSource] call FUNC(setFuel);
} else {
_unit setVariable [QGVAR(tempFuel), fuel _sink];
2015-08-13 17:33:55 +00:00
};
2015-08-20 20:10:26 +00:00
if (_finished) exitWith {
_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;