Skip to content

Commit

Permalink
Merge pull request #1 from jonpas/refuelFixes
Browse files Browse the repository at this point in the history
Refuel Fixes and Additions
Thx @jonpas
  • Loading branch information
GitHawk committed Aug 17, 2015
2 parents 214c639 + 539fc69 commit 1bba068
Show file tree
Hide file tree
Showing 18 changed files with 299 additions and 259 deletions.
354 changes: 178 additions & 176 deletions addons/refuel/CfgVehicles.hpp

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion addons/refuel/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

ADDON = false;

PREP(canCheckFuel);
PREP(canConnectNozzle);
PREP(canDisconnect);
PREP(canRefuel);
Expand All @@ -13,9 +14,10 @@ PREP(connectNozzleAction);
PREP(disconnect);
PREP(getFuel);
PREP(moduleRefuelSettings);
PREP(refuel);
PREP(returnNozzle);
PREP(setFuel);
PREP(takeNozzle);
PREP(turnOff);
PREP(refuel);

ADDON = true;
23 changes: 23 additions & 0 deletions addons/refuel/functions/fnc_canCheckFuel.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Author: Jonpas
* Checks if unit can check fuel.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Target <OBJECT>
*
* Return Value:
* Can Check Fuel <BOOL>
*
* Example:
* [unit, target] call ace_refuel_fnc_canCheckFuel
*
* Public: No
*/
#include "script_component.hpp"

params ["_unit", "_target"];

if (isNull _unit || {!(_unit isKindOf "CAManBase")} || {!local _unit} || {(_target distance _unit) > REFUEL_ACTION_DISTANCE}) exitWith {false};

true
6 changes: 3 additions & 3 deletions addons/refuel/functions/fnc_canConnectNozzle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#include "script_component.hpp"

private ["_nozzle"];
params ["_unit"];
params ["_unit", "_target"];

_nozzle = _unit getVariable QGVAR(nozzle);
if (isNil "_nozzle") exitWith {false};
if (isNil "_nozzle" || {(_target distance _unit) > REFUEL_ACTION_DISTANCE}) exitWith {false};

true
true
4 changes: 2 additions & 2 deletions addons/refuel/functions/fnc_canDisconnect.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
private ["_nozzle", "_sink", "_fueling"];
params ["_unit", "_nozzleHolder"];

if (isNull _unit || {!(_unit isKindOf "CAManBase")} || {!local _unit} || {(_nozzleHolder distance _unit) > REFUEL_ACTION_DISTANCE}) exitWith {false};
if (isNull _unit || {!(_unit isKindOf "CAManBase")} || {!local _unit} || {(_nozzleHolder distance _unit) > REFUEL_ACTION_DISTANCE}) exitWith {false};

_nozzle = _nozzleHolder getVariable [QGVAR(nozzle), objNull];
if (isNull _nozzle) exitWith {false};
Expand All @@ -30,4 +30,4 @@ if (isNull _sink) exitWith {false};
_fueling = _nozzle getVariable [QGVAR(fueling), 0];
if (_fueling == 1) exitWith {false};

true
true
6 changes: 3 additions & 3 deletions addons/refuel/functions/fnc_canRefuel.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
private ["_fuel"];
params ["_unit", "_target"];

if (isNull _unit || {!(_unit isKindOf "CAManBase")} || {!local _unit} || { (_target distance _unit) > 7}) exitWith {false};
if (isNull _unit || {!(_unit isKindOf "CAManBase")} || {!local _unit} || {(_target distance _unit) > REFUEL_ACTION_DISTANCE}) exitWith {false};

_fuel = [_unit, _target] call FUNC(getFuel);
_fuel = [_target] call FUNC(getFuel);
if (_fuel > 0 || {_fuel == -1}) exitWith {true};

false
false
2 changes: 1 addition & 1 deletion addons/refuel/functions/fnc_canTakeNozzle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

params ["_unit", "_target"];

if (isNull _unit || {!(_unit isKindOf "CAManBase")} || {!local _unit} || {(_target distance _unit) > REFUEL_ACTION_DISTANCE}) exitWith {false};
if (isNull _unit || {!(_unit isKindOf "CAManBase")} || {!local _unit} || {(_target distance _unit) > REFUEL_ACTION_DISTANCE}) exitWith {false};

// Check if the fuel source is already in use
!(_target getVariable [QGVAR(isConnected), false]) && {!(_unit getVariable [QGVAR(isRefueling), false])}
1 change: 0 additions & 1 deletion addons/refuel/functions/fnc_canTurnOff.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
#include "script_component.hpp"

private ["_nozzle", "_fueling"];
params ["_unit", "_nozzleHolder"];

if (isNull _unit || {!(_unit isKindOf "CAManBase")} || {!local _unit} || {(_nozzleHolder distance _unit) > REFUEL_ACTION_DISTANCE}) exitWith {false};
Expand Down
5 changes: 1 addition & 4 deletions addons/refuel/functions/fnc_checkFuel.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
private ["_fuel", "_type"];
params ["_unit", "_target"];

if (isNull _unit || {!(_unit isKindOf "CAManBase")} || {!local _unit} || { (_target distance _unit) > 7}) exitWith {0};

_fuel = [_unit, _target] call FUNC(getFuel);
_fuel = [_target] call FUNC(getFuel);

[
5,
Expand All @@ -40,4 +38,3 @@ _fuel = [_unit, _target] call FUNC(getFuel);
{true},
["isnotinside"]
] call EFUNC(common,progressBar);

10 changes: 1 addition & 9 deletions addons/refuel/functions/fnc_connectNozzleAction.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,11 @@ _weaponSelect = _unit getVariable QGVAR(selectedWeaponOnRefuel);
_unit selectWeapon _weaponSelect;
_unit setVariable [QGVAR(selectedWeaponOnRefuel), nil];

_source = _nozzle getVariable QGVAR(source);
if (_source == _target) exitWith {
_source setVariable [QGVAR(isConnected), false, true];
ropeDestroy (_nozzle getVariable QGVAR(rope));
deleteVehicle _nozzle;
_unit setVariable [QGVAR(isRefueling), false];
};

_nozzle attachTo [_target, _endPosTestOffset];
_nozzle setVariable [QGVAR(sink), _target, true];
_nozzle setVariable [QGVAR(fueling), 1, true];
_target setVariable [QGVAR(nozzle), _nozzle, true];

[_unit, _target, _nozzle] call FUNC(refuel);

true
true
18 changes: 8 additions & 10 deletions addons/refuel/functions/fnc_getFuel.sqf
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
/*
* Author: GitHawk
* Get the remaining fuel amount
* Author: GitHawk, Jonpas
* Get the remaining fuel amount.
*
* Arguments:
* 0: The unit <OBJECT>
* 1: The target <OBJECT>
* 0: Target <OBJECT>
*
* Return Value:
* Fuel left (in liters) <NUMBER>
*
* Example:
* [unit, target] call ace_refuel_fnc_getFuel
* [target] call ace_refuel_fnc_getFuel
*
* Public: No
*/
#include "script_component.hpp"
private ["_fuel"];
params ["_unit", "_target"];

if (isNull _unit || {!(_unit isKindOf "CAManBase")} || {!local _unit}) exitWith {0};
private ["_fuel"];
params ["_target"];

_fuel = _target getVariable [QGVAR(currentFuelCargo), -2];
_fuel = _target getVariable [QGVAR(currentFuelCargo), nil];

if (_fuel == -2) then {
if (isNil "_fuel") then {
_fuel = getNumber (configFile >> "CfgVehicles" >> typeOf _target >> QGVAR(fuelCargo));
_target setVariable [QGVAR(currentFuelCargo), _fuel, true];
};
Expand Down
16 changes: 8 additions & 8 deletions addons/refuel/functions/fnc_refuel.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ if (isNull _sink) exitWith {};
_rate = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(flowRate)) * GVAR(rate);
_maxFuel = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(fuelCapacity));

[{
[{
private ["_source", "_sink", "_fuelInSource", "_fuelInSink", "_finished", "_fueling"];
params ["_args", "_pfID"];
_args params ["_unit", "_nozzle", "_rate", "_startFuel", "_maxFuel"];

_fueling = _nozzle getVariable [QGVAR(fueling), 0];

_source = _nozzle getVariable [QGVAR(source), objNull];
_sink = _nozzle getVariable [QGVAR(sink), objNull];
if (isNull _source || {isNull _sink} || {(_source distance _sink) > 10}) exitWith {
Expand All @@ -40,7 +40,7 @@ _maxFuel = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(f
_nozzle setVariable [QGVAR(sink), objNull];
[_pfID] call cba_fnc_removePerFrameHandler;
};
_fuelInSource = [_unit, _source] call FUNC(getFuel);
_fuelInSource = [_source] call FUNC(getFuel);
if (_fuelInSource == 0) exitWith {
[LSTRING(Hint_SourceEmpty), 2, _unit] call EFUNC(common,displayTextStructured);
_nozzle setVariable [QGVAR(fueling), 0, true];
Expand All @@ -53,7 +53,7 @@ _maxFuel = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(f
_finished = true;
[LSTRING(Hint_Empty), 2, _unit] call EFUNC(common,displayTextStructured);
};

_fuelInSink = fuel _sink + ( _rate / _maxFuel);
if (_fuelInSink > 1) then {
_fuelInSink = 1;
Expand All @@ -66,16 +66,16 @@ _maxFuel = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(f
_sink setFuel _fuelInSink;
};
[_unit, _source, _fuelInSource] call FUNC(setFuel);

if (_finished || {_fueling == 0}) exitWith {
if (_fueling == 0) then {
[LSTRING(Hint_Stopped), 2, _unit] call EFUNC(common,displayTextStructured);
};
_nozzle setVariable [QGVAR(fueling), 0, true];
[_pfID] call cba_fnc_removePerFrameHandler;
};
// display flickers even at 1 second intervals

// 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;
39 changes: 39 additions & 0 deletions addons/refuel/functions/fnc_returnNozzle.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Author: GitHawk et.al., Jonpas
* Returns the nozzle back to source vehicle.
*
* Arguments:
* 0: Player <OBJECT>
* 1: Target <OBJECT>
*
* Return Value:
* Returned Nozzle <BOOL>
*
* Example:
* [player] call ace_refuel_fnc_returnNozzle
*
* Public: No
*/
#include "script_component.hpp"

private ["_nozzle"];

params ["_unit", "_target"];

_source = _nozzle getVariable QGVAR(source);
_nozzle = _unit getVariable QGVAR(nozzle);

if (_source != _target || {isNil "_nozzle"}) exitWith {false};

_unit setVariable [QGVAR(nozzle), nil];
detach _nozzle;
[_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
_unit selectWeapon (_unit getVariable QGVAR(selectedWeaponOnRefuel));
_unit setVariable [QGVAR(selectedWeaponOnRefuel), nil];
_unit setVariable [QGVAR(isRefueling), false];

_target setVariable [QGVAR(isConnected), false, true];
ropeDestroy (_nozzle getVariable QGVAR(rope));
deleteVehicle _nozzle;

true
34 changes: 12 additions & 22 deletions addons/refuel/functions/fnc_takeNozzle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,26 @@ if (isNull _nozzle) then { // func is called on fuel truck
_endPosOffset = getArray (configFile >> "CfgVehicles" >> typeOf _target >> "ace_refuel_hooks") select 0;

// TODO add pickup animation ?

[{
params ["_unit", "_target", "_endPosTestOffset"];
params ["_unit", "_target"];
_newNozzle = "ACE_refuel_fuelNozzle" createVehicle position _unit;
_newNozzle attachTo [_unit, [-0.02,-0.05,0], "righthandmiddle1"]; // TODO replace with right coordinates for real model
_unit setVariable [QGVAR(nozzle), _newNozzle];

// TODO action is only local
_action = [QGVAR(TakeNozzleFromGround),
localize LSTRING(TakeNozzle),
QUOTE(PATHTOF(ui\icon_refuel_interact.paa)),
{params ["_nozzle", "_unit"]; [ARR_3(_unit,_nozzle,_nozzle)] call DFUNC(TakeNozzle); true},
{params ["_nozzle", "_unit"]; [ARR_2(_unit,_nozzle)] call FUNC(canTakeNozzle)},
{},
[]
] call EFUNC(interact_menu,createAction);
[_newNozzle, 0, [], _action] call EFUNC(interact_menu,addActionToObject);

_rope = ropeCreate [_target, _endPosTestOffset, _newNozzle, [0, 0, 0], 12];


// Create rope with offset -1 to prevent wrapping over interaction base point
_rope = ropeCreate [_target, [0, 0, -1], _newNozzle, [0, 0, 0], 12];

_newNozzle setVariable [QGVAR(source), _target, true];
_newNozzle setVariable [QGVAR(rope), _rope, true];
_target setVariable [QGVAR(isConnected), true, true];
}, [_unit, _target, _endPosOffset], 2, 0] call EFUNC(common,waitAndExecute);

[{
private ["_nozzle"];
params ["_args", "_pfID"];
_args params ["_unit", "_target"];

if ((_unit distance _target) > 10) exitWith {
_nozzle = _unit getVariable [QGVAR(nozzle), objNull];
if !(isNull _nozzle) then {
Expand All @@ -67,11 +57,11 @@ if (isNull _nozzle) then { // func is called on fuel truck
_nozzle setVelocity [0,0,0];
_unit setVariable [QGVAR(isRefueling), false];
_unit setVariable [QGVAR(nozzle), objNull];

_weaponSelect = _unit getVariable QGVAR(selectedWeaponOnRefuel);
_unit selectWeapon _weaponSelect;
_unit setVariable [QGVAR(selectedWeaponOnRefuel), nil];

[_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
[LSTRING(Hint_TooFar), 2, _unit] call EFUNC(common,displayTextStructured);
};
Expand All @@ -82,10 +72,10 @@ if (isNull _nozzle) then { // func is called on fuel truck
_unit setVariable [QGVAR(isRefueling), true];
} else { // func is called in muzzle either connected or on ground
// TODO add pickup animation ?

[{
params ["_unit", "_target", "_nozzle"];

detach _nozzle;
_target setVariable [QGVAR(nozzle), objNull, true];
_nozzle attachTo [_unit, [-0.02,-0.05,0], "righthandmiddle1"]; // TODO replace with right coordinates for real model
Expand Down
18 changes: 6 additions & 12 deletions addons/refuel/functions/fnc_turnOff.sqf
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
/*
* Author: GitHawk
* Check if a unit can turn off a fuel nozzle
* Turn off a fuel nozzle
*
* Arguments:
* 0: The unit <OBJECT>
* 1: The object holding the nozzle <OBJECT>
* 0: The object holding the nozzle <OBJECT>
*
* Return Value:
* Can turn off <BOOL>
* None
*
* Example:
* [player, nozzle] call ace_refuel_fnc_canTurnOff
* [player, nozzle] call ace_refuel_fnc_turnOff
*
* Public: No
*/
#include "script_component.hpp"

params ["_unit", "_nozzleHolder"];
params ["_nozzleHolder"];

if (isNull _unit || {!(_unit isKindOf "CAManBase")} || {!local _unit} || { (_nozzleHolder distance _unit) > REFUEL_ACTION_DISTANCE}) exitWith {false};

_nozzle = _nozzleHolder getVariable QGVAR(nozzle);
_nozzle setVariable [QGVAR(fueling), 0];

true
(_nozzleHolder getVariable QGVAR(nozzle)) setVariable [QGVAR(fueling), 0];
2 changes: 0 additions & 2 deletions addons/refuel/functions/script_component.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
#include "\z\ace\addons\refuel\script_component.hpp"

#define REFUEL_ACTION_DISTANCE 4.5
3 changes: 3 additions & 0 deletions addons/refuel/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
#endif

#include "\z\ace\addons\main\script_macros.hpp"


#define REFUEL_ACTION_DISTANCE 7
Loading

0 comments on commit 1bba068

Please sign in to comment.