Next few things

Clean up
Removed MP issues
Added macros for reused code
Added death handling
Added unconscious handling
Added fueling restart
This commit is contained in:
IngoKauffmann 2015-08-18 23:18:32 +02:00
parent 2816e8863a
commit cdd0c4c013
20 changed files with 250 additions and 61 deletions

View File

@ -3,3 +3,25 @@ class Extended_PreInit_EventHandlers {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};
class Extended_Respawn_EventHandlers {
class CAManBase {
class ADDON {
respawn = QUOTE(call COMPILE_FILE(XEH_respawn));
};
};
};
class Extended_Killed_EventHandlers {
class CAManBase {
class ADDON {
killed = QUOTE(_this call FUNC(handleKilled));
};
};
};

View File

@ -52,6 +52,13 @@
exceptions[] = {"isNotInside"}; \
icon = PATHTOF(ui\icon_refuel_interact.paa); \
}; \
class GVAR(TurnOn) { \
displayName = CSTRING(TurnOn); \
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canTurnOn)); \
statement = QUOTE([_target] call DFUNC(turnOn)); \
exceptions[] = {"isNotInside"}; \
icon = PATHTOF(ui\icon_refuel_interact.paa); \
}; \
class GVAR(Disconnect) { \
displayName = CSTRING(Disconnect); \
condition = QUOTE([ARR_2(_player,_target)] call FUNC(canDisconnect)); \
@ -89,7 +96,7 @@ class CfgVehicles {
displayName = CSTRING(RefuelSettings_Module_DisplayName);
icon = QUOTE(PATHTOF(ui\icon_module_refuel.paa));
category = "ACE";
function = QUOTE(DFUNC(moduleRefuelSettings));
function = QFUNC(moduleRefuelSettings);
functionPriority = 1;
isGlobal = 0;
isTriggerActivated = 0;
@ -451,7 +458,6 @@ class CfgVehicles {
};
class ReammoBox_F;
class Slingload_01_Base_F : ReammoBox_F {
class ACE_Actions {
class ACE_MainActions {
@ -494,7 +500,7 @@ class CfgVehicles {
transportFuel = 0; //50k
MACRO_REFUEL_ACTIONS
GVAR(hooks[]) = {{0,0,-1}};
GVAR(fuelCargo) = INFINITE_FUEL;
GVAR(fuelCargo) = REFUEL_INFINITE_FUEL;
};
class Land_fs_feed_F : House_Small_F {
@ -502,7 +508,7 @@ class CfgVehicles {
transportFuel = 0; //50k
MACRO_REFUEL_ACTIONS
GVAR(hooks[]) = {{-0.4,0.022,-.23}};
GVAR(fuelCargo) = INFINITE_FUEL;
GVAR(fuelCargo) = REFUEL_INFINITE_FUEL;
};
/* // Barrels from rhs?

11
addons/refuel/README.md Normal file
View File

@ -0,0 +1,11 @@
ace_refuel
===============
The Refuel module introduces ability to refuel vehicles on different realistic levels.
## Maintainers
The people responsible for merging changes to this component or answering potential questions.
- [GitHawk] (https://github.com/GitHawk)
- [Jonpas] (https://github.com/jonpas)

View File

@ -0,0 +1,3 @@
#include "script_component.hpp"
["medical_onUnconscious", {_this call FUNC(handleOnUnconscious)}] call EFUNC(common,addEventHandler);

View File

@ -8,16 +8,20 @@ PREP(canDisconnect);
PREP(canRefuel);
PREP(canTakeNozzle);
PREP(canTurnOff);
PREP(canTurnOn);
PREP(checkFuel);
PREP(connectNozzle);
PREP(connectNozzleAction);
PREP(disconnect);
PREP(getFuel);
PREP(handleKilled);
PREP(handleUnconscious);
PREP(moduleRefuelSettings);
PREP(refuel);
PREP(returnNozzle);
PREP(setFuel);
PREP(takeNozzle);
PREP(turnOff);
PREP(turnOn);
ADDON = true;

View File

@ -0,0 +1,11 @@
#include "script_component.hpp"
private ["_unit"];
_unit = _this select 0;
if !(local _unit) exitWith {};
[_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
_unit setVariable [QGVAR(selectedWeaponOnRefuel), nil];
_unit setVariable [QGVAR(isRefueling), false];

View File

@ -12,6 +12,6 @@ class CfgPatches {
};
};
#include "ACE_Settings.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgVehicles.hpp"
#include "ACE_Settings.hpp"

View File

@ -21,5 +21,6 @@ params ["_unit", "_target"];
!(isNull _unit ||
{!(_unit isKindOf "CAManBase")} ||
{!local _unit} ||
{!alive _target} ||
{(_target distance _unit) > REFUEL_ACTION_DISTANCE} ||
{(_target call FUNC(getFuel) == INFINITE_FUEL)})
{(_target call FUNC(getFuel) == REFUEL_INFINITE_FUEL)})

View File

@ -18,6 +18,10 @@
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} ||
{!alive _target} ||
{(_target distance _unit) > REFUEL_ACTION_DISTANCE}) exitWith {false};
!(_target getVariable [QGVAR(isConnected), false]) && {!(_unit getVariable [QGVAR(isRefueling), false])}

View File

@ -18,6 +18,9 @@
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};
!(isNull (_nozzleHolder getVariable [QGVAR(nozzle), objNull])) && {(_nozzleHolder getVariable QGVAR(nozzle)) getVariable [QGVAR(isRefueling), false]}

View File

@ -0,0 +1,31 @@
/*
* Author: GitHawk
* Check if a unit can turn on a fuel nozzle
*
* Arguments:
* 0: The unit <OBJECT>
* 1: The object holding the nozzle <OBJECT>
*
* Return Value:
* Can turn on <BOOL>
*
* Example:
* [player, truck] call ace_refuel_fnc_canTurnOn
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit", "_nozzleHolder"];
if (isNull _unit ||
{!(_unit isKindOf "CAManBase")} ||
{!local _unit} ||
{(_nozzleHolder distance _unit) > REFUEL_ACTION_DISTANCE}) exitWith {false};
private "_nozzle";
_nozzle = _nozzleHolder getVariable [QGVAR(nozzle), objNull];
(!isNull _nozzle) &&
{!(_nozzle getVariable [QGVAR(isRefueling), false])} &&
{[_nozzle getVariable QGVAR(source)] call FUNC(getFuel) != 0}

View File

@ -0,0 +1,26 @@
/*
* Author: GitHawk, Jonpas
* Handles medical on set dead event.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* [unit] call ace_refuel_fnc_handleKilled
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit"];
if (!local _unit) exitWith {};
_unit setVariable [QGVAR(selectedWeaponOnRefuel), nil];
_nozzle = _unit setVariable [QGVAR(nozzle), objNull];
if !(isNull _nozzle) then {
REFUEL_UNIT_DROP_NOZZLE
};

View File

@ -0,0 +1,29 @@
/*
* Author: GitHawk, Jonpas
* Handles medical on unconscious event.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Is Unconscious <BOOL>
*
* Return Value:
* None
*
* Example:
* [unit, true] call ace_refuel_fnc_handleUnconscious
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit", "_isUnconscious"];
if (!local _unit || {!_isUnconscious}) exitWith {};
private "_nozzle";
[_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
_nozzle = _unit setVariable [QGVAR(nozzle), objNull];
if !(isNull _nozzle) then {
REFUEL_UNIT_DROP_NOZZLE
};

View File

@ -25,7 +25,7 @@ _rate = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(flo
_maxFuel = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(fuelCapacity));
[{
private ["_source", "_sink", "_fuelInSource", "_fuelInSink", "_finished", "_fueling"];
private ["_source", "_sink", "_tooFar", "_fuelInSource", "_fuelInSink", "_finished", "_fueling"];
params ["_args", "_pfID"];
_args params ["_unit", "_nozzle", "_rate", "_startFuel", "_maxFuel"];
@ -34,48 +34,55 @@ _maxFuel = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(f
_source = _nozzle getVariable [QGVAR(source), objNull];
_sink = _nozzle getVariable [QGVAR(sink), objNull];
if (isNull _source ||
{isNull _sink} ||
{(_sink distance (_source modelToWorld (_nozzle getVariable [QGVAR(attachPos), [0,0,0]]))) > 10} ||
{!alive _source} ||
{isNull _sink} ||
{!alive _sink}) exitWith {
[LSTRING(Hint_TooFar), 2, _unit] call EFUNC(common,displayTextStructured);
detach _nozzle;
_nozzle setPosATL [(getPosATL _nozzle) select 0,(getPosATL _nozzle) select 1, 0];
_nozzle setVelocity [0, 0, 0];
REFUEL_DROP_NOZZLE(_nozzle)
_nozzle setVariable [QGVAR(isConnected), false, true];
_nozzle setVariable [QGVAR(isRefueling), false, true];
_nozzle setVariable [QGVAR(sink), objNull, true];
_sink setVariable [QGVAR(nozzle), objNull, true];
[_pfID] call cba_fnc_removePerFrameHandler;
};
_fuelInSource = [_source] call FUNC(getFuel);
if (_fuelInSource == 0) exitWith {
[LSTRING(Hint_SourceEmpty), 2, _unit] call EFUNC(common,displayTextStructured);
_nozzle setVariable [QGVAR(isRefueling), false, true];
_tooFar = (_sink distance (_source modelToWorld (_nozzle getVariable [QGVAR(attachPos), [0,0,0]]))) > 10;
if (_tooFar) exitWith {
[LSTRING(Hint_TooFar), 2, _unit] call EFUNC(common,displayTextStructured);
REFUEL_DROP_NOZZLE(_nozzle)
_nozzle setVariable [QGVAR(isConnected), false, true];
_nozzle setVariable [QGVAR(sink), objNull, true];
_sink setVariable [QGVAR(nozzle), objNull, true];
[_pfID] call cba_fnc_removePerFrameHandler;
};
_finished = false;
if !(_fuelInSource == INFINITE_FUEL) then {
_fuelInSource = _fuelInSource - _rate;
};
if (_fuelInSource < 0 && {_fuelInSource > -1}) then {
_fuelInSource = 0;
_finished = true;
[LSTRING(Hint_Empty), 2, _unit] call EFUNC(common,displayTextStructured);
};
_fuelInSink = fuel _sink + ( _rate / _maxFuel);
if (_fuelInSink > 1) then {
_fuelInSink = 1;
_finished = true;
[LSTRING(Hint_Completed), 2, _unit] call EFUNC(common,displayTextStructured);
_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 = fuel _sink + ( _rate / _maxFuel);
if (_fuelInSink > 1) then {
_fuelInSink = 1;
_finished = true;
[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;
};
[_unit, _source, _fuelInSource] call FUNC(setFuel);
};
if !(local _sink) then {
[[_sink, _fuelInSink], QUOTE({(_this select 0) setFuel (_this select 1)}), _sink] call EFUNC(common,execRemoteFnc);
} else {
_sink setFuel _fuelInSink;
};
[_unit, _source, _fuelInSource] call FUNC(setFuel);
if (_finished || {!_fueling}) exitWith {
if !(_fueling) then {
@ -83,8 +90,4 @@ _maxFuel = getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(f
};
_nozzle setVariable [QGVAR(isRefueling), false, true];
};
// 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;

View File

@ -27,10 +27,9 @@ if (isNil "_nozzle" || {_source != _target}) 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];
REFUEL_UNHOLSTER_WEAPON
_unit setVariable [QGVAR(isRefueling), false];
_target setVariable [QGVAR(isConnected), false, true];
ropeDestroy (_nozzle getVariable QGVAR(rope));
deleteVehicle _nozzle;

View File

@ -22,8 +22,7 @@ params ["_unit", "_target", "_nozzle"];
[_unit, QGVAR(vehAttach), true] call EFUNC(common,setForceWalkStatus);
_unit setVariable [QGVAR(selectedWeaponOnRefuel), currentWeapon _unit];
_unit action ["SwitchWeapon", _unit, _unit, 99];
REFUEL_HOLSTER_WEAPON
if (isNull _nozzle) then { // func is called on fuel truck
_endPosOffset = getArray (configFile >> "CfgVehicles" >> typeOf _target >> "ace_refuel_hooks");
@ -60,16 +59,8 @@ if (isNull _nozzle) then { // func is called on fuel truck
if (_unit distance (_source modelToWorld _endPosOffset) > 10) exitWith {
_nozzle = _unit getVariable [QGVAR(nozzle), objNull];
if !(isNull _nozzle) then {
detach _nozzle;
_nozzle setPosATL [(getPosATL _unit) select 0,(getPosATL _unit) select 1, 0];
_nozzle setVelocity [0,0,0];
_nozzle setVariable [QGVAR(isRefueling), false, true];
_unit setVariable [QGVAR(isRefueling), false];
_unit setVariable [QGVAR(nozzle), objNull];
_weaponSelect = _unit getVariable QGVAR(selectedWeaponOnRefuel);
_unit selectWeapon _weaponSelect;
_unit setVariable [QGVAR(selectedWeaponOnRefuel), nil];
REFUEL_UNIT_DROP_NOZZLE
REFUEL_UNHOLSTER_WEAPON
[_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
[LSTRING(Hint_TooFar), 2, _unit] call EFUNC(common,displayTextStructured);

View File

@ -9,7 +9,7 @@
* None
*
* Example:
* [player, nozzle] call ace_refuel_fnc_turnOff
* [tank] call ace_refuel_fnc_turnOff
*
* Public: No
*/

View File

@ -0,0 +1,20 @@
/*
* Author: GitHawk
* Turn on a fuel nozzle
*
* Arguments:
* 0: The object holding the nozzle <OBJECT>
*
* Return Value:
* None
*
* Example:
* [tank] call ace_refuel_fnc_turnOn
*
* Public: No
*/
#include "script_component.hpp"
params ["_nozzleHolder"];
(_nozzleHolder getVariable QGVAR(nozzle)) setVariable [QGVAR(isRefueling), true, true];

View File

@ -11,5 +11,26 @@
#include "\z\ace\addons\main\script_macros.hpp"
#define INFINITE_FUEL -1
#define REFUEL_INFINITE_FUEL -1
#define REFUEL_ACTION_DISTANCE 7
#define REFUEL_DROP_NOZZLE(obj) \
detach _nozzle; \
_nozzle setPosATL [(getPosATL obj) select 0,(getPosATL obj) select 1, 0]; \
_nozzle setVelocity [0,0,0]; \
_nozzle setVariable [QGVAR(isRefueling), false, true];
#define REFUEL_UNIT_DROP_NOZZLE \
REFUEL_DROP_NOZZLE(_unit) \
_unit setVariable [QGVAR(isRefueling), false]; \
_unit setVariable [QGVAR(nozzle), objNull];
#define REFUEL_HOLSTER_WEAPON \
_unit setVariable [QGVAR(selectedWeaponOnRefuel), currentWeapon _unit]; \
_unit action ["SwitchWeapon", _unit, _unit, 99];
#define REFUEL_UNHOLSTER_WEAPON \
_weaponSelect = _unit getVariable QGVAR(selectedWeaponOnRefuel); \
_unit selectWeapon _weaponSelect; \
_unit setVariable [QGVAR(selectedWeaponOnRefuel), nil];

View File

@ -65,6 +65,10 @@
<English>Stop fueling</English>
<German>Betankung anhalten</German>
</Key>
<Key ID="STR_ACE_Refuel_TurnOn">
<English>Start fueling</English>
<German>Betankung beginnen</German>
</Key>
<Key ID="STR_ACE_Refuel_Hint_FuelProgress">
<English>%1 Liters fueled</English>
<German>%1 Liters getankt</German>