From 794a1f9922ee43123c510797975dc4c97cfd9f39 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 10 Mar 2015 16:01:46 -0500 Subject: [PATCH] Wirecutter handles interact event adds helper objects to all fences that have actions --- .../logistics_wirecutter/CfgEventHandlers.hpp | 5 ++ addons/logistics_wirecutter/CfgVehicles.hpp | 19 ------ .../logistics_wirecutter/XEH_clientInit.sqf | 5 ++ addons/logistics_wirecutter/XEH_preInit.sqf | 2 +- addons/logistics_wirecutter/config.cpp | 3 +- .../functions/fnc_canCutFence.sqf | 18 ------ .../functions/fnc_cutDownFence.sqf | 31 ++++++---- .../functions/fnc_cutDownFenceAbort.sqf | 16 ++++- .../functions/fnc_cutDownFenceCallback.sqf | 17 +++++- .../functions/fnc_getNearestFence.sqf | 29 +++++---- .../functions/fnc_interactEH.sqf | 60 +++++++++++++++++++ .../functions/fnc_isFence.sqf | 43 ++++++------- 12 files changed, 163 insertions(+), 85 deletions(-) delete mode 100644 addons/logistics_wirecutter/CfgVehicles.hpp create mode 100644 addons/logistics_wirecutter/XEH_clientInit.sqf delete mode 100644 addons/logistics_wirecutter/functions/fnc_canCutFence.sqf create mode 100644 addons/logistics_wirecutter/functions/fnc_interactEH.sqf diff --git a/addons/logistics_wirecutter/CfgEventHandlers.hpp b/addons/logistics_wirecutter/CfgEventHandlers.hpp index f0a9f14d91..79c3aaa959 100644 --- a/addons/logistics_wirecutter/CfgEventHandlers.hpp +++ b/addons/logistics_wirecutter/CfgEventHandlers.hpp @@ -4,3 +4,8 @@ class Extended_PreInit_EventHandlers { init = QUOTE(call COMPILE_FILE(XEH_preInit)); }; }; +class Extended_PostInit_EventHandlers { + class ADDON { + clientInit = QUOTE( call COMPILE_FILE(XEH_clientInit) ); + }; +}; diff --git a/addons/logistics_wirecutter/CfgVehicles.hpp b/addons/logistics_wirecutter/CfgVehicles.hpp deleted file mode 100644 index 8a16d1b828..0000000000 --- a/addons/logistics_wirecutter/CfgVehicles.hpp +++ /dev/null @@ -1,19 +0,0 @@ -class CfgVehicles { - class Man; - class CAManBase: Man { - class ACE_SelfActions { - class ACE_Equipment { - class GVAR(CutFence) { - displayName = "$STR_ACE_logistics_wirecutter_CutFence"; - condition = QUOTE([_player] call FUNC(canCutFence)); - statement = QUOTE([_player] call FUNC(cutDownFence)); - exceptions[] = {}; - showDisabled = 1; - priority = 0; - icon = PATHTOF(UI\wirecutter_ca.paa); - hotkey = "C"; - }; - }; - }; - }; -}; \ No newline at end of file diff --git a/addons/logistics_wirecutter/XEH_clientInit.sqf b/addons/logistics_wirecutter/XEH_clientInit.sqf new file mode 100644 index 0000000000..4d82dce0a8 --- /dev/null +++ b/addons/logistics_wirecutter/XEH_clientInit.sqf @@ -0,0 +1,5 @@ +#include "script_component.hpp" + +if (!hasInterface) exitWith {}; + +["interact_keyDown", {_this call FUNC(interactEH)}] call EFUNC(common,addEventHandler); diff --git a/addons/logistics_wirecutter/XEH_preInit.sqf b/addons/logistics_wirecutter/XEH_preInit.sqf index 7588a109e6..44eb941c16 100644 --- a/addons/logistics_wirecutter/XEH_preInit.sqf +++ b/addons/logistics_wirecutter/XEH_preInit.sqf @@ -2,11 +2,11 @@ ADDON = false; -PREP(canCutFence); PREP(cutDownFence); PREP(cutDownFenceAbort); PREP(cutDownFenceCallback); PREP(getNearestFence); +PREP(interactEH); PREP(isFence); ADDON = true; diff --git a/addons/logistics_wirecutter/config.cpp b/addons/logistics_wirecutter/config.cpp index 7f292132fa..27d4467ccf 100644 --- a/addons/logistics_wirecutter/config.cpp +++ b/addons/logistics_wirecutter/config.cpp @@ -5,7 +5,7 @@ class CfgPatches { units[] = {}; weapons[] = {}; requiredVersion = REQUIRED_VERSION; - requiredAddons[] = {"ace_common", "ace_interaction"}; + requiredAddons[] = {"ace_interact_menu"}; author[] = {"gpgpgpgp", "PabstMirror"}; authorUrl = ""; VERSION_CONFIG; @@ -13,6 +13,5 @@ class CfgPatches { }; #include "CfgEventHandlers.hpp" -#include "CfgVehicles.hpp" #include "CfgSounds.hpp" #include "CfgWeapons.hpp" diff --git a/addons/logistics_wirecutter/functions/fnc_canCutFence.sqf b/addons/logistics_wirecutter/functions/fnc_canCutFence.sqf deleted file mode 100644 index f57a970d58..0000000000 --- a/addons/logistics_wirecutter/functions/fnc_canCutFence.sqf +++ /dev/null @@ -1,18 +0,0 @@ -/* fnc_canCutFence.sqf -* -* Author: PabstMirror -* -* Condition check if player is able to cut a fence. -* Checks for "ACE_wirecutter" item and if there is a nearby fence. -* -* Argument: -* 0: OBJECT - Unit to check condition for (player) -* -* Return value: -* BOOL -*/ - -#include "script_component.hpp" -PARAMS_1(_unit); - -("ACE_wirecutter" in (items _unit)) && {!(isNull ([_unit] call FUNC(getNearestFence)))} diff --git a/addons/logistics_wirecutter/functions/fnc_cutDownFence.sqf b/addons/logistics_wirecutter/functions/fnc_cutDownFence.sqf index 0a42d5d56b..ee4c512cd2 100644 --- a/addons/logistics_wirecutter/functions/fnc_cutDownFence.sqf +++ b/addons/logistics_wirecutter/functions/fnc_cutDownFence.sqf @@ -1,20 +1,31 @@ -// by gpgpgpgp, edited by commy2 +/* + * Author: gpgpgpgp, edited by commy2, PabstMirror + * Starts cutting down a fence + * + * Arguments: + * 0: Unit + * 1: Fence + * + * Return Value: + * Nothing + * + * Example: + * [player, berlinWall] call ace_logistics_wirecutter_fnc_cutDownFence + * + * Public: No + */ #include "script_component.hpp" -PARAMS_1(_unit); +private ["_timeToCut"]; + +PARAMS_2(_unit,_fenceObject); if (_unit != ACE_player) exitWith {}; -_fenceObject = [ACE_player] call FUNC(getNearestFence); -if (isNull _fenceObject) exitWith {}; - -_timeToCut = 5; -if !([ACE_player] call EFUNC(common,isEngineer)) then { - _timeToCut = _timeToCut + 5; -}; +_timeToCut = if ([ACE_player] call EFUNC(common,isEngineer)) then {5} else {10}; [ACE_player, "AinvPknlMstpSnonWnonDr_medic5", 0] call EFUNC(common,doAnimation); -if (_timeToCut > 4.5) then { +if (_timeToCut > 5) then { playSound "ACE_wirecutter_sound_long"; } else { playSound "ACE_wirecutter_sound"; diff --git a/addons/logistics_wirecutter/functions/fnc_cutDownFenceAbort.sqf b/addons/logistics_wirecutter/functions/fnc_cutDownFenceAbort.sqf index d17038af7c..20cb092131 100644 --- a/addons/logistics_wirecutter/functions/fnc_cutDownFenceAbort.sqf +++ b/addons/logistics_wirecutter/functions/fnc_cutDownFenceAbort.sqf @@ -1,4 +1,18 @@ -// by commy2 +/* + * Author: commy2 + * Stops cutting down fence (reset animation) + * + * Arguments: + * Nothing + * + * Return Value: + * Nothing + * + * Example: + * [] call ace_logistics_wirecutter_fnc_cutDownFenceAbort + * + * Public: No + */ #include "script_component.hpp" [ACE_player, "AmovPknlMstpSrasWrflDnon", 1] call EFUNC(common,doAnimation); diff --git a/addons/logistics_wirecutter/functions/fnc_cutDownFenceCallback.sqf b/addons/logistics_wirecutter/functions/fnc_cutDownFenceCallback.sqf index 57c0289461..77bc4f2ba6 100644 --- a/addons/logistics_wirecutter/functions/fnc_cutDownFenceCallback.sqf +++ b/addons/logistics_wirecutter/functions/fnc_cutDownFenceCallback.sqf @@ -1,7 +1,22 @@ +/* + * Author: PabstMirror + * Once progressbar is done: Fence is cutdown + * + * Arguments: + * 0: Fence Object + * + * Return Value: + * Nothing + * + * Example: + * [aFence] call ace_logistics_wirecutter_fnc_cutDownFenceCallback + * + * Public: No + */ #include "script_component.hpp" PARAMS_1(_fenceObject); _fenceObject setdamage 1; -[localize "STR_ACE_logistics_wirecutter_FenceCut"] call EFUNC(common,displayTextStructured); +// [localize "STR_ACE_logistics_wirecutter_FenceCut"] call EFUNC(common,displayTextStructured); [ACE_player, "AmovPknlMstpSrasWrflDnon", 1] call EFUNC(common,doAnimation); diff --git a/addons/logistics_wirecutter/functions/fnc_getNearestFence.sqf b/addons/logistics_wirecutter/functions/fnc_getNearestFence.sqf index 5004315fcd..c9e59b41a0 100644 --- a/addons/logistics_wirecutter/functions/fnc_getNearestFence.sqf +++ b/addons/logistics_wirecutter/functions/fnc_getNearestFence.sqf @@ -1,15 +1,18 @@ -/* fnc_getNearestFence.sqf -* -* Author: PabstMirror -* -* Gets nearest fence within 5 meters to the unit. -* -* Argument: -* 0: OBJECT - Unit to search for fence objects arround -* -* Return value: -* OBJECT - Nearest object that is a fence, objNull if none found. -*/ +/* + * Author: PabstMirror + * Gets nearest fence object (not actully used, left for utility) + * + * Arguments: + * 0: Unit + * + * Return Value: + * The return value + * + * Example: + * [player] call ace_logistics_wirecutter_fnc_getNearestFence + * + * Public: Yes + */ #include "script_component.hpp" private "_nearestFence"; @@ -20,6 +23,6 @@ _nearestFence = objNull; if ((isNull _nearestFence) && {[_x] call FUNC(isFence)}) then { _nearestFence = _x; }; -} forEach nearestObjects [_unit, [], 5]; +} forEach nearestObjects [_unit, [], 15]; _nearestFence diff --git a/addons/logistics_wirecutter/functions/fnc_interactEH.sqf b/addons/logistics_wirecutter/functions/fnc_interactEH.sqf new file mode 100644 index 0000000000..c2a721adeb --- /dev/null +++ b/addons/logistics_wirecutter/functions/fnc_interactEH.sqf @@ -0,0 +1,60 @@ +/* + * Author: PabstMirror + * When interact_menu starts rendering (from "interact_keyDown" event) + * + * Arguments: + * Nothing + * + * Return Value: + * Nothing + * + * Example: + * [] call ace_logistics_wirecutter_fnc_interactEH + * + * Public: Yes + */ +#include "script_component.hpp" + + +//for performance only do stuff it they have a wirecutter item +//(if they somehow get one durring keydown they'll just have to reopen) +if (!("ACE_wirecutter" in (items ace_player))) exitWith {}; + +[{ + PARAMS_2(_args,_pfID); + EXPLODE_3_PVT(_args,_setPosition,_addedHelpers,_fencesHelped); + + if (!EGVAR(interact_menu,keyDown)) then { + {deleteVehicle _x;} forEach _addedHelpers; + [_pfID] call CBA_fnc_removePerFrameHandler; + } else { + //If play moved >5 meters from last pos, then rescan + if (((getPosASL ace_player) distance _setPosition) > 5) then { + + _fncStatement = { + _attachedFence = _target getVariable [QGVAR(attachedFence), objNull]; + [ace_player, _attachedFence] call FUNC(cutDownFence); + }; + _fncCondition = { + _attachedFence = _target getVariable [QGVAR(attachedFence), objNull]; + ((!isNull _attachedFence) && {(damage _attachedFence) < 1} && {("ACE_wirecutter" in (items ace_player))}) + }; + + { + if (!(_x in _fencesHelped)) then { + if ([_x] call FUNC(isFence)) then { + _fencesHelped pushBack _x; + _helper = "Sign_Sphere25cm_F" createVehicleLocal (getpos _x); + [_helper, 0, [""], (localize "STR_ACE_logistics_wirecutter_CutFence"), QUOTE(PATHTOF(ui\wirecutter_ca.paa)), [0,0,0], _fncStatement, _fncCondition, 5] call EFUNC(interact_menu,addAction); + _helper setPosASL ((getPosASL _x) vectorAdd [0,0,1.25]); + _helper hideObject true; + _helper setVariable [QGVAR(attachedFence), _x]; + _addedHelpers pushBack _helper; + }; + }; + } forEach nearestObjects [ace_player, [], 15]; + + _args set [0, (getPosASL ace_player)]; + }; + }; +}, 0.1, [((getPosASL ace_player) vectorAdd [-100,0,0]), [], []]] call CBA_fnc_addPerFrameHandler; diff --git a/addons/logistics_wirecutter/functions/fnc_isFence.sqf b/addons/logistics_wirecutter/functions/fnc_isFence.sqf index 2c00cec92b..aee9a22ef9 100644 --- a/addons/logistics_wirecutter/functions/fnc_isFence.sqf +++ b/addons/logistics_wirecutter/functions/fnc_isFence.sqf @@ -1,16 +1,19 @@ -/* fnc_isFence.sqf -* -* Author: PabstMirror -* -* Checks if object is a fence. Should work on any fence type, even (typeof == ""). -* Call is fairly expensive because of all of the string checking. -* -* Argument: -* 0: OBJECT - Ojbect to test -* -* Return value: -* BOOL -*/ +/* + * Author: PabstMirror + * Checks if object is a fence. Should work on any fence type, even (typeof == ""). + * Call is fairly expensive because of all of the string checking. + * + * Arguments: + * 0: An Object To Test + * + * Return Value: + * Is it a fence + * + * Example: + * [aFence] call ace_logistics_wirecutter_fnc_isFence + * + * Public: No + */ #include "script_component.hpp" //find is case sensitive, so keep everything lowercase @@ -27,14 +30,14 @@ _typeOf = toLower (typeOf _object); _returnValue = false; if (_typeOf != "") then { - _returnValue = _typeOf in (FENCE_A3_TYPENAMES + FENCE_AIA_TYPENAMES); + _returnValue = _typeOf in (FENCE_A3_TYPENAMES + FENCE_AIA_TYPENAMES); } else { - _typeOf = toLower (str _object); //something like "123201: wall_indfnc_9.p3d" - { - if ((_typeOf find _x) != -1) then { - _returnValue = true; - }; - } forEach (FENCE_A3_P3DS + FENCE_AIA_P3DS); + _typeOf = toLower (str _object); //something like "123201: wall_indfnc_9.p3d" + { + if ((_typeOf find _x) != -1) then { + _returnValue = true; + }; + } forEach (FENCE_A3_P3DS + FENCE_AIA_P3DS); }; _returnValue