Merge pull request #1 from jonpas/refuelFixes

Refuel Fixes and Additions
Thx @jonpas
This commit is contained in:
Hawk 2015-08-17 16:03:43 +02:00
commit 1bba0681c8
18 changed files with 299 additions and 259 deletions

View File

@ -1,51 +1,59 @@
#define REFUEL_ACTION_DISTANCE 4.5
#define MACRO_REFUEL_ACTIONS \ #define MACRO_REFUEL_ACTIONS \
class ACE_Actions : ACE_Actions { \ class ACE_Actions: ACE_Actions { \
class ACE_MainActions : ACE_MainActions { \ class ACE_MainActions: ACE_MainActions { \
class GVAR(Refuel) { \
displayName = CSTRING(Refuel); \
distance = REFUEL_ACTION_DISTANCE; \
condition = "true"; \
statement = ""; \
showDisabled = 0; \
priority = 2; \
icon = PATHTOF(ui\icon_refuel_interact.paa); \
class GVAR(TakeNozzle) { \ class GVAR(TakeNozzle) { \
displayName = CSTRING(TakeNozzle); \ displayName = CSTRING(TakeNozzle); \
distance = REFUEL_ACTION_DISTANCE; \
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canTakeNozzle)); \ condition = QUOTE([ARR_2(_player,_target)] call FUNC(canTakeNozzle)); \
statement = QUOTE([ARR_3(_player,_target,objNull)] call FUNC(TakeNozzle)); \ statement = QUOTE([ARR_3(_player,_target,objNull)] call FUNC(TakeNozzle)); \
exceptions[] = {"isNotInside"}; \ exceptions[] = {"isNotInside"}; \
icon = PATHTOF(ui\icon_refuel_interact.paa); \ icon = PATHTOF(ui\icon_refuel_interact.paa); \
}; \ }; \
class GVAR(Return) { \
displayName = CSTRING(Return); \
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canConnectNozzle)); \
statement = QUOTE([ARR_2(_player,_target)] call DFUNC(returnNozzle)); \
exceptions[] = {"isNotInside"}; \
icon = PATHTOF(ui\icon_refuel_interact.paa); \
}; \
class GVAR(CheckFuel) { \ class GVAR(CheckFuel) { \
displayName = CSTRING(CheckFuel); \ displayName = CSTRING(CheckFuel); \
distance = REFUEL_ACTION_DISTANCE; \ condition = QUOTE([ARR_2(_player,_target)] call FUNC(canCheckFuel)); \
condition = QUOTE(([ARR_2(_player,_target)] call FUNC(getFuel) >= 0) && {(_target distance _player) < REFUEL_ACTION_DISTANCE}); \
statement = QUOTE([ARR_2(_player,_target)] call FUNC(checkFuel)); \ statement = QUOTE([ARR_2(_player,_target)] call FUNC(checkFuel)); \
exceptions[] = {"isNotInside"}; \ exceptions[] = {"isNotInside"}; \
icon = PATHTOF(ui\icon_refuel_interact.paa); \ icon = PATHTOF(ui\icon_refuel_interact.paa); \
}; \ }; \
class GVAR(connect) { \
displayName = CSTRING(Return); \
distance = REFUEL_ACTION_DISTANCE; \
condition = QUOTE([ARR_1(_player)] call FUNC(canConnectNozzle)); \
statement = QUOTE([ARR_2(_player,_target)] call DFUNC(connectNozzle)); \
exceptions[] = {"isNotInside"}; \
icon = PATHTOF(ui\icon_refuel_interact.paa); \
}; \
}; \ }; \
}; }; \
};
#define MACRO_CONNECT_ACTIONS \ #define MACRO_CONNECT_ACTIONS \
class ACE_Actions { \ class ACE_Actions { \
class ACE_MainActions { \ class ACE_MainActions { \
displayName = ECSTRING(interaction,MainAction); \ class GVAR(Refuel) { \
selection = ""; \ displayName = CSTRING(Refuel); \
distance = 10; \ distance = REFUEL_ACTION_DISTANCE; \
condition = "true"; \ condition = "true"; \
class GVAR(connect) { \ statement = ""; \
displayName = CSTRING(connect); \ showDisabled = 0; \
distance = REFUEL_ACTION_DISTANCE; \ priority = 2; \
condition = QUOTE([ARR_1(_player)] call FUNC(canConnectNozzle)); \ icon = PATHTOF(ui\icon_refuel_interact.paa); \
class GVAR(Connect) { \
displayName = CSTRING(Connect); \
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canConnectNozzle)); \
statement = QUOTE([ARR_2(_player,_target)] call DFUNC(connectNozzle)); \ statement = QUOTE([ARR_2(_player,_target)] call DFUNC(connectNozzle)); \
exceptions[] = {"isNotInside"}; \ exceptions[] = {"isNotInside"}; \
icon = PATHTOF(ui\icon_refuel_interact.paa); \ icon = PATHTOF(ui\icon_refuel_interact.paa); \
}; \ }; \
class GVAR(Disconnect) { \ class GVAR(Disconnect) { \
displayName = CSTRING(Disconnect); \ displayName = CSTRING(Disconnect); \
distance = REFUEL_ACTION_DISTANCE; \
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canDisconnect)); \ condition = QUOTE([ARR_2(_player,_target)] call FUNC(canDisconnect)); \
statement = QUOTE([ARR_2(_player,_target)] call DFUNC(disconnect)); \ statement = QUOTE([ARR_2(_player,_target)] call DFUNC(disconnect)); \
exceptions[] = {"isNotInside"}; \ exceptions[] = {"isNotInside"}; \
@ -53,33 +61,26 @@
}; \ }; \
class GVAR(TurnOff) { \ class GVAR(TurnOff) { \
displayName = CSTRING(TurnOff); \ displayName = CSTRING(TurnOff); \
distance = REFUEL_ACTION_DISTANCE; \
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canTurnOff)); \ condition = QUOTE([ARR_2(_player,_target)] call FUNC(canTurnOff)); \
statement = QUOTE([ARR_2(_player,_target)] call DFUNC(turnOff)); \ statement = QUOTE([_target] call DFUNC(turnOff)); \
exceptions[] = {"isNotInside"}; \ exceptions[] = {"isNotInside"}; \
icon = PATHTOF(ui\icon_refuel_interact.paa); \ icon = PATHTOF(ui\icon_refuel_interact.paa); \
}; \ }; \
}; \ }; \
}; }; \
};
// does not work
#define MACRO_NOZZLE_ACTIONS \ #define MACRO_NOZZLE_ACTIONS \
class ACE_Actions { \ class ACE_Actions { \
class ACE_MainActions { \ class ACE_MainActions { \
displayName = ECSTRING(interaction,MainAction); \ displayName = CSTRING(TakeNozzle); \
selection = ""; \ distance = 2; \
distance = 2; \ condition = QUOTE([ARR_2(_player,_target)] call FUNC(canTakeNozzle)); \
condition = "true"; \ statement = QUOTE([ARR_3(_player,_target,_target)] call FUNC(TakeNozzle)); \
class GVAR(TakeNozzle) { \ exceptions[] = {"isNotInside"}; \
displayName = CSTRING(TakeNozzle); \ icon = PATHTOF(ui\icon_refuel_interact.paa); \
distance = REFUEL_ACTION_DISTANCE; \ }; \
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canTakeNozzle)); \ };
statement = QUOTE([ARR_3(_player,_target,_target)] call FUNC(TakeNozzle)); \
exceptions[] = {"isNotInside"}; \
icon = PATHTOF(ui\icon_refuel_interact.paa); \
}; \
}; \
};
class CfgVehicles { class CfgVehicles {
class ACE_Module; class ACE_Module;
@ -116,7 +117,8 @@ class CfgVehicles {
class Sign_Sphere10cm_F; class Sign_Sphere10cm_F;
class ACE_refuel_fuelNozzle : Sign_Sphere10cm_F { class ACE_refuel_fuelNozzle : Sign_Sphere10cm_F {
// TODO replace with custom model XEH_ENABLED;
MACRO_NOZZLE_ACTIONS
}; };
class All; class All;

View File

@ -2,6 +2,7 @@
ADDON = false; ADDON = false;
PREP(canCheckFuel);
PREP(canConnectNozzle); PREP(canConnectNozzle);
PREP(canDisconnect); PREP(canDisconnect);
PREP(canRefuel); PREP(canRefuel);
@ -13,9 +14,10 @@ PREP(connectNozzleAction);
PREP(disconnect); PREP(disconnect);
PREP(getFuel); PREP(getFuel);
PREP(moduleRefuelSettings); PREP(moduleRefuelSettings);
PREP(refuel);
PREP(returnNozzle);
PREP(setFuel); PREP(setFuel);
PREP(takeNozzle); PREP(takeNozzle);
PREP(turnOff); PREP(turnOff);
PREP(refuel);
ADDON = true; ADDON = true;

View File

@ -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

View File

@ -17,9 +17,9 @@
#include "script_component.hpp" #include "script_component.hpp"
private ["_nozzle"]; private ["_nozzle"];
params ["_unit"]; params ["_unit", "_target"];
_nozzle = _unit getVariable QGVAR(nozzle); _nozzle = _unit getVariable QGVAR(nozzle);
if (isNil "_nozzle") exitWith {false}; if (isNil "_nozzle" || {(_target distance _unit) > REFUEL_ACTION_DISTANCE}) exitWith {false};
true true

View File

@ -19,7 +19,7 @@
private ["_nozzle", "_sink", "_fueling"]; private ["_nozzle", "_sink", "_fueling"];
params ["_unit", "_nozzleHolder"]; 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]; _nozzle = _nozzleHolder getVariable [QGVAR(nozzle), objNull];
if (isNull _nozzle) exitWith {false}; if (isNull _nozzle) exitWith {false};

View File

@ -17,9 +17,9 @@
private ["_fuel"]; private ["_fuel"];
params ["_unit", "_target"]; 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}; if (_fuel > 0 || {_fuel == -1}) exitWith {true};
false false

View File

@ -18,7 +18,7 @@
params ["_unit", "_target"]; 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 // Check if the fuel source is already in use
!(_target getVariable [QGVAR(isConnected), false]) && {!(_unit getVariable [QGVAR(isRefueling), false])} !(_target getVariable [QGVAR(isConnected), false]) && {!(_unit getVariable [QGVAR(isRefueling), false])}

View File

@ -16,7 +16,6 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_nozzle", "_fueling"];
params ["_unit", "_nozzleHolder"]; 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};

View File

@ -18,9 +18,7 @@
private ["_fuel", "_type"]; private ["_fuel", "_type"];
params ["_unit", "_target"]; params ["_unit", "_target"];
if (isNull _unit || {!(_unit isKindOf "CAManBase")} || {!local _unit} || { (_target distance _unit) > 7}) exitWith {0}; _fuel = [_target] call FUNC(getFuel);
_fuel = [_unit, _target] call FUNC(getFuel);
[ [
5, 5,
@ -40,4 +38,3 @@ _fuel = [_unit, _target] call FUNC(getFuel);
{true}, {true},
["isnotinside"] ["isnotinside"]
] call EFUNC(common,progressBar); ] call EFUNC(common,progressBar);

View File

@ -81,14 +81,6 @@ _weaponSelect = _unit getVariable QGVAR(selectedWeaponOnRefuel);
_unit selectWeapon _weaponSelect; _unit selectWeapon _weaponSelect;
_unit setVariable [QGVAR(selectedWeaponOnRefuel), nil]; _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 attachTo [_target, _endPosTestOffset];
_nozzle setVariable [QGVAR(sink), _target, true]; _nozzle setVariable [QGVAR(sink), _target, true];
_nozzle setVariable [QGVAR(fueling), 1, true]; _nozzle setVariable [QGVAR(fueling), 1, true];

View File

@ -1,28 +1,26 @@
/* /*
* Author: GitHawk * Author: GitHawk, Jonpas
* Get the remaining fuel amount * Get the remaining fuel amount.
* *
* Arguments: * Arguments:
* 0: The unit <OBJECT> * 0: Target <OBJECT>
* 1: The target <OBJECT>
* *
* Return Value: * Return Value:
* Fuel left (in liters) <NUMBER> * Fuel left (in liters) <NUMBER>
* *
* Example: * Example:
* [unit, target] call ace_refuel_fnc_getFuel * [target] call ace_refuel_fnc_getFuel
* *
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_fuel"]; private ["_fuel"];
params ["_unit", "_target"]; params ["_target"];
if (isNull _unit || {!(_unit isKindOf "CAManBase")} || {!local _unit}) exitWith {0}; _fuel = _target getVariable [QGVAR(currentFuelCargo), nil];
_fuel = _target getVariable [QGVAR(currentFuelCargo), -2]; if (isNil "_fuel") then {
if (_fuel == -2) then {
_fuel = getNumber (configFile >> "CfgVehicles" >> typeOf _target >> QGVAR(fuelCargo)); _fuel = getNumber (configFile >> "CfgVehicles" >> typeOf _target >> QGVAR(fuelCargo));
_target setVariable [QGVAR(currentFuelCargo), _fuel, true]; _target setVariable [QGVAR(currentFuelCargo), _fuel, true];
}; };

View File

@ -40,7 +40,7 @@ _maxFuel = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(f
_nozzle setVariable [QGVAR(sink), objNull]; _nozzle setVariable [QGVAR(sink), objNull];
[_pfID] call cba_fnc_removePerFrameHandler; [_pfID] call cba_fnc_removePerFrameHandler;
}; };
_fuelInSource = [_unit, _source] call FUNC(getFuel); _fuelInSource = [_source] call FUNC(getFuel);
if (_fuelInSource == 0) exitWith { if (_fuelInSource == 0) exitWith {
[LSTRING(Hint_SourceEmpty), 2, _unit] call EFUNC(common,displayTextStructured); [LSTRING(Hint_SourceEmpty), 2, _unit] call EFUNC(common,displayTextStructured);
_nozzle setVariable [QGVAR(fueling), 0, true]; _nozzle setVariable [QGVAR(fueling), 0, true];

View File

@ -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

View File

@ -31,23 +31,13 @@ if (isNull _nozzle) then { // func is called on fuel truck
// TODO add pickup animation ? // TODO add pickup animation ?
[{ [{
params ["_unit", "_target", "_endPosTestOffset"]; params ["_unit", "_target"];
_newNozzle = "ACE_refuel_fuelNozzle" createVehicle position _unit; _newNozzle = "ACE_refuel_fuelNozzle" createVehicle position _unit;
_newNozzle attachTo [_unit, [-0.02,-0.05,0], "righthandmiddle1"]; // TODO replace with right coordinates for real model _newNozzle attachTo [_unit, [-0.02,-0.05,0], "righthandmiddle1"]; // TODO replace with right coordinates for real model
_unit setVariable [QGVAR(nozzle), _newNozzle]; _unit setVariable [QGVAR(nozzle), _newNozzle];
// TODO action is only local // Create rope with offset -1 to prevent wrapping over interaction base point
_action = [QGVAR(TakeNozzleFromGround), _rope = ropeCreate [_target, [0, 0, -1], _newNozzle, [0, 0, 0], 12];
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];
_newNozzle setVariable [QGVAR(source), _target, true]; _newNozzle setVariable [QGVAR(source), _target, true];
_newNozzle setVariable [QGVAR(rope), _rope, true]; _newNozzle setVariable [QGVAR(rope), _rope, true];

View File

@ -1,26 +1,20 @@
/* /*
* Author: GitHawk * Author: GitHawk
* Check if a unit can turn off a fuel nozzle * Turn off a fuel nozzle
* *
* Arguments: * Arguments:
* 0: The unit <OBJECT> * 0: The object holding the nozzle <OBJECT>
* 1: The object holding the nozzle <OBJECT>
* *
* Return Value: * Return Value:
* Can turn off <BOOL> * None
* *
* Example: * Example:
* [player, nozzle] call ace_refuel_fnc_canTurnOff * [player, nozzle] call ace_refuel_fnc_turnOff
* *
* Public: No * Public: No
*/ */
#include "script_component.hpp" #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}; (_nozzleHolder getVariable QGVAR(nozzle)) setVariable [QGVAR(fueling), 0];
_nozzle = _nozzleHolder getVariable QGVAR(nozzle);
_nozzle setVariable [QGVAR(fueling), 0];
true

View File

@ -1,3 +1 @@
#include "\z\ace\addons\refuel\script_component.hpp" #include "\z\ace\addons\refuel\script_component.hpp"
#define REFUEL_ACTION_DISTANCE 4.5

View File

@ -10,3 +10,6 @@
#endif #endif
#include "\z\ace\addons\main\script_macros.hpp" #include "\z\ace\addons\main\script_macros.hpp"
#define REFUEL_ACTION_DISTANCE 7

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project name="ACE"> <Project name="ACE">
<Package name="Refuel"> <Package name="Refuel">
<Key ID="STR_ACE_Refuel_RefuelSettings_Module_DisplayName"> <Key ID="STR_ACE_Refuel_RefuelSettings_Module_DisplayName">
@ -45,15 +45,18 @@
<English>How many liters does a stationary object e.g. a fuel station hold? -1 is infinite.</English> <English>How many liters does a stationary object e.g. a fuel station hold? -1 is infinite.</English>
<German>Wieviele Liter enthält ein stationäres Objekt z.B. eine Tankstelle? -1 bedeutet unendlich.</German> <German>Wieviele Liter enthält ein stationäres Objekt z.B. eine Tankstelle? -1 bedeutet unendlich.</German>
</Key> </Key>
<Key ID="STR_ACE_Refuel_TakeNozzle"> <Key ID="STR_ACE_Refuel_Refuel">
<English>Refuel</English>
</Key>
<Key ID="STR_ACE_Refuel_TakeNozzle">
<English>Take fuel nozzle</English> <English>Take fuel nozzle</English>
<German>Zapfpistole nehmen</German> <German>Zapfpistole nehmen</German>
</Key> </Key>
<Key ID="STR_ACE_Refuel_Connect"> <Key ID="STR_ACE_Refuel_Connect">
<English>Connect fuel nozzle</English> <English>Connect fuel nozzle</English>
<German>Zapfpistole anschließen</German> <German>Zapfpistole anschließen</German>
</Key> </Key>
<Key ID="STR_ACE_Refuel_Disconnect"> <Key ID="STR_ACE_Refuel_Disconnect">
<English>Disconnect fuel nozzle</English> <English>Disconnect fuel nozzle</English>
<German>Zapfpistole entfernen</German> <German>Zapfpistole entfernen</German>
</Key> </Key>