ACE3/addons/refuel/functions/fnc_refuel.sqf

82 lines
3.1 KiB
Plaintext
Raw Normal View History

2015-08-13 17:33:55 +00:00
/*
* Author: GitHawk
* Refuels the vehicle
*
* Arguments:
2015-08-14 01:18:54 +00:00
* 0: The unit <OBJECT>
* 1: The target <OBJECT>
* 2: The 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
*
* Public: No
*/
#include "script_component.hpp"
private ["_sink", "_rate", "_maxFuel"];
params ["_unit", "_target", "_nozzle"];
2015-08-13 17:33:55 +00:00
_sink = _nozzle getVariable [QGVAR(sink), objNull];
if (isNull _sink) exitWith {};
_rate = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(flowRate)) * GVAR(rate);
_maxFuel = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(fuelCapacity));
2015-08-13 17:33:55 +00:00
[{
private ["_source", "_sink", "_fuelInSource", "_fuelInSink", "_finished", "_fueling"];
params ["_args", "_pfID"];
2015-08-14 01:18:54 +00:00
_args params ["_unit", "_nozzle", "_rate", "_startFuel", "_maxFuel"];
2015-08-13 17:33:55 +00:00
_fueling = _nozzle getVariable [QGVAR(fueling), 0];
_source = _nozzle getVariable [QGVAR(source), objNull];
_sink = _nozzle getVariable [QGVAR(sink), objNull];
2015-08-14 01:18:54 +00:00
if (isNull _source || {isNull _sink} || {(_source distance _sink) > 10}) exitWith {
[LSTRING(Hint_TooFar), 2, _unit] call EFUNC(common,displayTextStructured);
2015-08-13 17:33:55 +00:00
detach _nozzle;
_nozzle setPosATL [(getPosATL _nozzle) select 0,(getPosATL _nozzle) select 1, 0];
_nozzle setVariable [QGVAR(sink), objNull];
[_pfID] call cba_fnc_removePerFrameHandler;
};
_fuelInSource = [_unit, _source] call FUNC(getFuel);
if (_fuelInSource == 0) exitWith {
2015-08-14 01:18:54 +00:00
[LSTRING(Hint_SourceEmpty), 2, _unit] call EFUNC(common,displayTextStructured);
2015-08-13 17:33:55 +00:00
_nozzle setVariable [QGVAR(fueling), 0, true];
[_pfID] call cba_fnc_removePerFrameHandler;
};
_finished = false;
_fuelInSource = _fuelInSource - _rate;
if (_fuelInSource < 0 && {_fuelInSource > -1}) then {
_fuelInSource = 0;
_finished = true;
2015-08-14 01:18:54 +00:00
[LSTRING(Hint_Empty), 2, _unit] call EFUNC(common,displayTextStructured);
2015-08-13 17:33:55 +00:00
};
_fuelInSink = fuel _sink + ( _rate / _maxFuel);
if (_fuelInSink > 1) then {
_fuelInSink = 1;
_finished = true;
2015-08-14 01:18:54 +00:00
[LSTRING(Hint_Completed), 2, _unit] call EFUNC(common,displayTextStructured);
};
if !(local _sink) then {
[[_sink, _fuelInSink], QUOTE({(_this select 0) setFuel (_this select 1)}), _sink] call EFUNC(common,execRemoteFnc);
} else {
_sink setFuel _fuelInSink;
2015-08-13 17:33:55 +00:00
};
[_unit, _source, _fuelInSource] call FUNC(setFuel);
if (_finished || {_fueling == 0}) exitWith {
2015-08-14 01:18:54 +00:00
if (_fueling == 0) then {
[LSTRING(Hint_Stopped), 2, _unit] call EFUNC(common,displayTextStructured);
};
2015-08-13 17:33:55 +00:00
_nozzle setVariable [QGVAR(fueling), 0, true];
[_pfID] call cba_fnc_removePerFrameHandler;
};
2015-08-14 01:18:54 +00:00
// display flickers even at 1 second intervals
//["displayTextStructured", [_unit], [[localize LSTRING(Hint_FuelProgress), round((_fuelInSink - _startFuel) * _maxFuel)], 2, _unit]] call EFUNC(common,targetEvent);
//[[LSTRING(Hint_FuelProgress), round((_fuelInSink - _startFuel) * _maxFuel)], 2, _unit] call EFUNC(common,displayTextStructured);
}, 1, [_unit, _nozzle, _rate, fuel _target, _maxFuel]] call cba_fnc_addPerFrameHandler;