Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refueling fuel containers #7039

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 49 additions & 41 deletions addons/refuel/CfgVehicles.hpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,5 @@
#define MACRO_NOZZLE_ACTIONS \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not also be removed? I don't think anyone could have included this file from a built mod as it has config in it, it had to be copied, so it's safe to remove.

class ACE_Actions { \
class ACE_MainActions { \
displayName = CSTRING(Refuel); \
distance = REFUEL_ACTION_DISTANCE; \
position = "[0,-0.025,0.125]"; \
condition = "true"; \
statement = ""; \
exceptions[] = {INTERACT_EXCEPTIONS}; \
showDisabled = 0; \
icon = QPATHTOF(ui\icon_refuel_interact.paa); \
class GVAR(PickUpNozzle) { \
displayName = CSTRING(TakeNozzle); \
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canTakeNozzle)); \
statement = QUOTE([ARR_2(_player,_target)] call FUNC(takeNozzle)); \
exceptions[] = {INTERACT_EXCEPTIONS_REFUELING}; \
icon = QPATHTOF(ui\icon_refuel_interact.paa); \
}; \
class GVAR(TurnOn) { \
displayName = CSTRING(TurnOn); \
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canTurnOn)); \
statement = QUOTE([ARR_2(_player,_target)] call DFUNC(turnOn)); \
exceptions[] = {INTERACT_EXCEPTIONS}; \
icon = QPATHTOF(ui\icon_refuel_interact.paa); \
}; \
class GVAR(TurnOff) { \
displayName = CSTRING(TurnOff); \
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canTurnOff)); \
statement = QUOTE([ARR_2(_player,_target)] call DFUNC(turnOff)); \
exceptions[] = {INTERACT_EXCEPTIONS}; \
icon = QPATHTOF(ui\icon_refuel_interact.paa); \
}; \
class GVAR(Disconnect) { \
displayName = CSTRING(Disconnect); \
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canDisconnect)); \
statement = QUOTE([ARR_2(_player,_target)] call DFUNC(disconnect)); \
exceptions[] = {INTERACT_EXCEPTIONS_REFUELING}; \
icon = QPATHTOF(ui\icon_refuel_interact.paa); \
}; \
}; \
};


class CBA_Extended_EventHandlers;

Expand Down Expand Up @@ -75,11 +36,58 @@ class CfgVehicles {
class CBA_Extended_EventHandlers: CBA_Extended_EventHandlers {};
};

MACRO_NOZZLE_ACTIONS
displayName = QGVAR(fuelNozzle);
scope = 1;
scopeCurator = 1;
model = QPATHTOF(data\nozzle.p3d);

class ACE_Actions {
class ACE_MainActions {
displayName = CSTRING(Refuel);
distance = REFUEL_ACTION_DISTANCE;
position = "[0,-0.025,0.125]";
condition = "true";
statement = "";
exceptions[] = {INTERACT_EXCEPTIONS};
showDisabled = 0;
icon = QPATHTOF(ui\icon_refuel_interact.paa);
class GVAR(PickUpNozzle) {
displayName = CSTRING(TakeNozzle);
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canTakeNozzle));
statement = QUOTE([ARR_2(_player,_target)] call FUNC(takeNozzle));
exceptions[] = {INTERACT_EXCEPTIONS_REFUELING};
icon = QPATHTOF(ui\icon_refuel_interact.paa);
};
class GVAR(TurnOn) {
displayName = CSTRING(TurnOn);
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canTurnOn));
statement = QUOTE([ARR_2(_player,_target)] call DFUNC(turnOn));
exceptions[] = {INTERACT_EXCEPTIONS};
icon = QPATHTOF(ui\icon_refuel_interact.paa);
};
class GVAR(TurnOn_Container) {
displayName = CSTRING(TurnOn_Container);
condition = QUOTE([ARR_3(_player,_target,true)] call FUNC(canTurnOn));
statement = QUOTE([ARR_3(_player,_target,true)] call DFUNC(turnOn));
exceptions[] = {INTERACT_EXCEPTIONS};
icon = QPATHTOF(ui\icon_refuel_interact.paa);
};
class GVAR(TurnOff) {
displayName = CSTRING(TurnOff);
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canTurnOff));
statement = QUOTE([ARR_2(_player,_target)] call DFUNC(turnOff));
exceptions[] = {INTERACT_EXCEPTIONS};
icon = QPATHTOF(ui\icon_refuel_interact.paa);
};
class GVAR(Disconnect) {
displayName = CSTRING(Disconnect);
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canDisconnect));
statement = QUOTE([ARR_2(_player,_target)] call DFUNC(disconnect));
exceptions[] = {INTERACT_EXCEPTIONS_REFUELING};
icon = QPATHTOF(ui\icon_refuel_interact.paa);
};
};
};
};

class All;
Expand Down
28 changes: 24 additions & 4 deletions addons/refuel/functions/fnc_canTurnOn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Arguments:
* 0: Unit <OBJECT>
* 1: Nozzle <OBJECT>
* 2: Refuel container (optional) <BOOL>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 2: Refuel container (optional) <BOOL>
* 2: Refuel container <BOOL> (default: false)

*
* Return Value:
* Can turn on <BOOL>
Expand All @@ -16,15 +17,34 @@
* Public: No
*/

params [["_unit", objNull, [objNull]], ["_nozzle", objNull, [objNull]]];
params [["_unit", objNull, [objNull]], ["_nozzle", objNull, [objNull]], ["_refuelContainer", false, [false]]];

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

private _source = _nozzle getVariable [QGVAR(source), objNull];
private _sink = _nozzle getVariable [QGVAR(sink), objNull];
private _isContainer = !(isNil {_sink getVariable QGVAR(currentFuelCargo)})
|| {isNumber (configFile >> "CfgVehicles" >> typeOf _sink >> QGVAR(fuelCargo))};

private _isFull = if (_refuelContainer) then {
private _currentFuel = [_sink] call FUNC(getFuel);
private _capacity = _sink getVariable [
QGVAR(capacity),
getNumber (configFile >> "CfgVehicles" >> typeOf _sink >> QGVAR(fuelCargo))
];

(_currentFuel == REFUEL_INFINITE_FUEL) || {_capacity == REFUEL_INFINITE_FUEL} || {_currentFuel == _capacity}
} else {
fuel _sink == 1
};

!(_nozzle getVariable [QGVAR(isRefueling), false]) &&
{[_nozzle getVariable QGVAR(source)] call FUNC(getFuel) != 0} &&
{!isNull (_nozzle getVariable [QGVAR(sink), objNull])} &&
{(fuel (_nozzle getVariable QGVAR(sink))) < 1}
{[_source] call FUNC(getFuel) != 0} &&
{!isNull _sink} &&
{!_isFull} &&
{!(_refuelContainer && {_source == _sink})} && // No endless container ot itself loop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{!(_refuelContainer && {_source == _sink})} && // No endless container ot itself loop
{!(_refuelContainer && {_source == _sink})} && // No endless container of itself loop

{!_refuelContainer || _isContainer} // Container refueling only if it actually is one
31 changes: 25 additions & 6 deletions addons/refuel/functions/fnc_connectNozzleAction.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private _attachPosModel = _sink worldToModel (ASLtoAGL _bestPosASL);
_nozzle setVariable [QGVAR(isConnected), true, true];
_sink setVariable [QGVAR(nozzle), _nozzle, true];

_source = _nozzle getVariable QGVAR(source);
private _source = _nozzle getVariable QGVAR(source);
private _fuel = [_source] call FUNC(getFuel);
if (_fuel == REFUEL_INFINITE_FUEL) then {
_source setVariable [QGVAR(fuelCounter), 0, true];
Expand All @@ -121,11 +121,30 @@ private _attachPosModel = _sink worldToModel (ASLtoAGL _bestPosASL);

[_unit, _sink, _nozzle, _endPosTestOffset] call FUNC(refuel);

if ([_unit, _nozzle] call FUNC(canTurnOn)) then {
_unit setVariable [QGVAR(tempFuel), nil];
[_unit, _nozzle] call FUNC(turnOn);
} else {
[localize LSTRING(CouldNotTurnOn)] call EFUNC(common,displayText);
private _canReceive = getNumber (configFile >> "CfgVehicles" >> typeOf _sink >> QGVAR(canReceive)) == 1;
private _isContainer = !(isNil {_sink getVariable QGVAR(currentFuelCargo)})
|| {isNumber (configFile >> "CfgVehicles" >> typeOf _sink >> QGVAR(fuelCargo))};

// Decide if cargo or vehicle will be refueled
switch (true) do {
case (_canReceive && {!_isContainer || {_sink == _source}}): {
// is not a refueling vehicle or refueling vehicle tries to refuel itself
if ([_unit, _nozzle, false] call FUNC(canTurnOn)) then {
[_unit, _nozzle, false] call FUNC(turnOn);
} else {
[localize LSTRING(CouldNotTurnOn)] call EFUNC(common,displayText);
};
};
case (!_canReceive && _isContainer): {
if ([_unit, _nozzle, true] call FUNC(canTurnOn)) then {
[_unit, _nozzle, true] call FUNC(turnOn);
} else {
[localize LSTRING(CouldNotTurnOn)] call EFUNC(common,displayText);
};
};
default {
/* Target is a refueling vehicle, let user manually decide if he wants to refuel cargo or vehicle itself */
};
};
},
"",
Expand Down
8 changes: 5 additions & 3 deletions addons/refuel/functions/fnc_disconnect.sqf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "script_component.hpp"
/*
* Author: GitHawk
* Disconnect a fuel nozzle.
* Disconnect a fuel nozzle and make unit pick it up.
*
* Arguments:
* 0: Unit <OBJECT>
* 0: Unit <OBJECT> (optional)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 0: Unit <OBJECT> (optional)
* 0: Unit <OBJECT> (default: objNull - drop on floor)

* 1: Nozzle <OBJECT>
*
* Return Value:
Expand All @@ -27,4 +27,6 @@ _nozzle setVariable [QGVAR(sink), nil, true];
_nozzle setVariable [QGVAR(isConnected), false, true];
[objNull, _nozzle, true] call FUNC(dropNozzle);

[_unit, _nozzle] call FUNC(takeNozzle);
if (!isNull _unit) then {
[_unit, _nozzle] call FUNC(takeNozzle);
};
13 changes: 13 additions & 0 deletions addons/refuel/functions/fnc_makeJerryCan.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ if (isServer) then {
};
_target setVariable [QGVAR(jerryCan), true];
_target setVariable [QGVAR(source), _target];
_target setVariable [QGVAR(capacity), _fuelAmount];

// Main Action
private _action = [QGVAR(Refuel),
Expand Down Expand Up @@ -64,6 +65,18 @@ _action = [QGVAR(TurnOn),
REFUEL_ACTION_DISTANCE] call EFUNC(interact_menu,createAction);
[_target, 0, ["ACE_MainActions", QGVAR(Refuel)], _action] call EFUNC(interact_menu,addActionToObject);

// Add turnOn container
_action = [QGVAR(TurnOn_Container),
localize LSTRING(TurnOn_Container),
QPATHTOF(ui\icon_refuel_interact.paa),
{[_player, _target, true] call FUNC(turnOn)},
{[_player, _target, true] call FUNC(canTurnOn)},
{},
[],
[0, 0, 0],
REFUEL_ACTION_DISTANCE] call EFUNC(interact_menu,createAction);
[_target, 0, ["ACE_MainActions", QGVAR(Refuel)], _action] call EFUNC(interact_menu,addActionToObject);

// Add turnOff
_action = [QGVAR(TurnOff),
localize LSTRING(TurnOff),
Expand Down
8 changes: 7 additions & 1 deletion addons/refuel/functions/fnc_onMouseButtonDown.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ private _virtualPosASL = (eyePos _unit) vectorAdd (positionCameraToWorld [0,0,0.
if (cameraView == "EXTERNAL") then {
_virtualPosASL = _virtualPosASL vectorAdd ((positionCameraToWorld [0.3,0,0]) vectorDiff (positionCameraToWorld [0,0,0]));
};

private _canReceive = _cursorObject getVariable [
QGVAR(jerryCan), // Jerry cans can always be refueled
getNumber (configFile >> "CfgVehicles" >> (typeOf _cursorObject) >> QGVAR(canReceive)) == 1
];

if (
!isNull _cursorObject
&& {_distance < REFUEL_NOZZLE_ACTION_DISTANCE}
&& {1 == getNumber (configFile >> "CfgVehicles" >> (typeOf _cursorObject) >> QGVAR(canReceive))}
&& {_canReceive}
&& {isNull (_cursorObject getVariable [QGVAR(nozzle), objNull])}
&& {!lineIntersects [eyePos _unit, _virtualPosASL, _unit]}
) then {
Expand Down
Loading