From 9a3972de764440884f24a2736e5b282406def633 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 12 Jan 2016 18:18:12 -0600 Subject: [PATCH] Unified Status Effect Handler --- addons/attach/functions/fnc_attach.sqf | 4 +- addons/common/CfgEventHandlers.hpp | 15 ++++- addons/common/XEH_postInit.sqf | 31 ++++++++- addons/common/XEH_preInit.sqf | 11 +++- .../functions/fnc_applyForceWalkStatus.sqf | 22 ------- addons/common/functions/fnc_fixCollision.sqf | 6 +- addons/common/functions/fnc_fixFloating.sqf | 11 ++++ .../functions/fnc_getCaptivityStatus.sqf | 28 -------- .../functions/fnc_getForceWalkStatus.sqf | 32 ---------- .../common/functions/fnc_resetAllDefaults.sqf | 7 -- .../functions/fnc_setCaptivityStatus.sqf | 26 +------- .../functions/fnc_setForceWalkStatus.sqf | 27 +------- .../functions/fnc_statusEffect_addType.sqf | 37 +++++++++++ .../functions/fnc_statusEffect_localEH.sqf | 36 +++++++++++ .../fnc_statusEffect_resetVariables.sqf | 45 +++++++++++++ .../functions/fnc_statusEffect_respawnEH.sqf | 36 +++++++++++ .../fnc_statusEffect_sendEffects.sqf | 48 ++++++++++++++ .../common/functions/fnc_statusEffect_set.sqf | 64 +++++++++++++++++++ addons/common/script_component.hpp | 1 + .../functions/fnc_dropObject_carry.sqf | 2 +- addons/dragging/functions/fnc_startCarry.sqf | 2 +- addons/refuel/XEH_respawn.sqf | 2 +- .../functions/fnc_connectNozzleAction.sqf | 2 +- .../functions/fnc_handleUnconscious.sqf | 2 +- addons/refuel/functions/fnc_returnNozzle.sqf | 2 +- addons/refuel/functions/fnc_takeNozzle.sqf | 8 +-- 26 files changed, 345 insertions(+), 162 deletions(-) delete mode 100644 addons/common/functions/fnc_applyForceWalkStatus.sqf delete mode 100644 addons/common/functions/fnc_getCaptivityStatus.sqf delete mode 100644 addons/common/functions/fnc_getForceWalkStatus.sqf create mode 100644 addons/common/functions/fnc_statusEffect_addType.sqf create mode 100644 addons/common/functions/fnc_statusEffect_localEH.sqf create mode 100644 addons/common/functions/fnc_statusEffect_resetVariables.sqf create mode 100644 addons/common/functions/fnc_statusEffect_respawnEH.sqf create mode 100644 addons/common/functions/fnc_statusEffect_sendEffects.sqf create mode 100644 addons/common/functions/fnc_statusEffect_set.sqf diff --git a/addons/attach/functions/fnc_attach.sqf b/addons/attach/functions/fnc_attach.sqf index 6362edb33c..eff33607ef 100644 --- a/addons/attach/functions/fnc_attach.sqf +++ b/addons/attach/functions/fnc_attach.sqf @@ -49,7 +49,7 @@ if (_unit == _attachToVehicle) then { //Self Attachment } else { GVAR(placeAction) = PLACE_WAITING; - [_unit, QGVAR(vehAttach), true] call EFUNC(common,setForceWalkStatus); + [_unit, "ACE_Attach", true] call EFUNC(common,setForceWalkStatus); [{[localize LSTRING(PlaceAction), ""] call EFUNC(interaction,showMouseHint)}, []] call EFUNC(common,execNextFrame); _unit setVariable [QGVAR(placeActionEH), [_unit, "DefaultAction", {true}, {GVAR(placeAction) = PLACE_APPROVE;}] call EFUNC(common,AddActionEventHandler)]; @@ -88,7 +88,7 @@ if (_unit == _attachToVehicle) then { //Self Attachment {!([_attachToVehicle, _unit, _itemClassname] call FUNC(canAttach))}) then { [_idPFH] call CBA_fnc_removePerFrameHandler; - [_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus); + [_unit, "ACE_Attach", false] call EFUNC(common,setForceWalkStatus); [] call EFUNC(interaction,hideMouseHint); [_unit, "DefaultAction", (_unit getVariable [QGVAR(placeActionEH), -1])] call EFUNC(common,removeActionEventHandler); _unit removeAction _actionID; diff --git a/addons/common/CfgEventHandlers.hpp b/addons/common/CfgEventHandlers.hpp index bea7b6e7bc..55a1df4c7c 100644 --- a/addons/common/CfgEventHandlers.hpp +++ b/addons/common/CfgEventHandlers.hpp @@ -23,9 +23,6 @@ class Extended_InitPost_EventHandlers { class GVAR(setName) { init = QUOTE(if (local (_this select 0)) then {_this call FUNC(setName)};); }; - class GVAR(forceWalk) { - init = QUOTE(_this call FUNC(applyForceWalkStatus)); - }; class GVAR(muteUnit) { init = QUOTE(_this call FUNC(muteUnitHandleInitPost)); }; @@ -43,6 +40,9 @@ class Extended_Respawn_EventHandlers { class GVAR(RESETDefaults) { respawn = QUOTE(_this call FUNC(resetAllDefaults)); }; + class GVAR(statusEffect) { + respawn = QUOTE(_this call FUNC(statusEffect_respawnEH)); + }; }; class CAManBase { class GVAR(muteUnit) { @@ -50,3 +50,12 @@ class Extended_Respawn_EventHandlers { }; }; }; + +class Extended_Local_EventHandlers { + class All { + class GVAR(statusEffect) { + local = QUOTE(_this call FUNC(statusEffect_localEH)); + }; + }; +}; + diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 22cf7a944e..6e2fa28869 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -1,5 +1,6 @@ // ACE - Common // #define ENABLE_PERFORMANCE_COUNTERS +// #define DEBUG_MODE_FULL #include "script_component.hpp" @@ -57,6 +58,33 @@ // Eventhandlers ////////////////////////////////////////////////// +//Status Effect EHs: +["setStatusEffect", {_this call FUNC(statusEffect_set)}] call FUNC(addEventHandler); +["forceWalk", false, ["ACE_SwitchUnits", "ACE_Attach", "ACE_dragging", "ACE_Explosives", "ACE_Ladder", "ACE_Sandbag", "ACE_refuel", "ACE_rearm", "ACE_dragging"]] call FUNC(statusEffect_addType); +["setCaptive", true, [QEGVAR(captives,Handcuffed), QEGVAR(captives,Surrendered), QEGVAR(medical,unconscious)]] call FUNC(statusEffect_addType); +["blockDamage", false, ["fixCollision"]] call FUNC(statusEffect_addType); + +["forceWalk", { + params ["_object", "_set"]; + TRACE_2("forceWalk EH",_object,_set); + _object forceWalk (_set > 0); +}] call FUNC(addEventHandler); +["setCaptive", { + params ["_object", "_set"]; + TRACE_2("forceWalk EH",_object,_set); + _object setCaptive (_set > 0); +}] call FUNC(addEventHandler); +["blockDamage", { + params ["_object", "_set"]; + if ((_object isKindOf "CAManBase") && {(["ace_medical"] call FUNC(isModLoaded))}) then { + TRACE_2("blockDamage EH (using medical)",_object,_set); + _object setvariable [QEGVAR(medical,allowDamage), (_set == 0), true]; + } else { + TRACE_2("blockDamage EH (using allowDamage)",_object,_set); + _object allowDamage (_set == 0); + }; +}] call FUNC(addEventHandler); + //Add a fix for BIS's zeus remoteControl module not reseting variables on DC when RC a unit //This variable is used for isPlayer checks if (isServer) then { @@ -431,9 +459,6 @@ if (!isNil QGVAR(PreInit_playerChanged_PFHID)) then { // Eventhandlers for player controlled machines ////////////////////////////////////////////////// -// @todo still needed? -[QGVAR(StateArrested), false, true, QUOTE(ADDON)] call FUNC(defineVariable); - ["displayTextStructured", {_this call FUNC(displayTextStructured)}] call FUNC(addEventhandler); ["displayTextPicture", {_this call FUNC(displayTextPicture)}] call FUNC(addEventhandler); diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 1b7bdc624c..732b4d94c0 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -10,7 +10,6 @@ PREP(addToInventory); PREP(assignedItemFix); PREP(assignObjectsInList); PREP(ambientBrightness); -PREP(applyForceWalkStatus); PREP(ASLToPosition); PREP(binarizeNumber); PREP(blurScreen); @@ -53,7 +52,6 @@ PREP(fixLoweredRifleAnimation); PREP(fixPosition); PREP(getAllDefinedSetVariables); PREP(getAllGear); -PREP(getCaptivityStatus); PREP(getDeathAnim); PREP(getDefaultAnim); PREP(getDefinedVariable); @@ -61,7 +59,6 @@ PREP(getDefinedVariableDefault); PREP(getDefinedVariableInfo); PREP(getFirstObjectIntersection); PREP(getFirstTerrainIntersection); -PREP(getForceWalkStatus); PREP(getGunner); PREP(getInPosition); PREP(getMapGridData); @@ -170,6 +167,12 @@ PREP(setVariablePublic); PREP(setVolume); PREP(sortAlphabeticallyBy); PREP(showHud); +PREP(statusEffect_addType); +PREP(statusEffect_localEH); +PREP(statusEffect_resetVariables); +PREP(statusEffect_respawnEH); +PREP(statusEffect_sendEffects); +PREP(statusEffect_set); PREP(stringCompare); PREP(stringToColoredText); PREP(stringRemoveWhiteSpace); @@ -316,6 +319,8 @@ if (isServer) then { call FUNC(loadSettingsOnServer); }; +GVAR(statusEffect_Names) = []; +GVAR(statusEffect_isGlobal) = []; ////////////////////////////////////////////////// // Set up PlayerChanged eventhandler for pre init diff --git a/addons/common/functions/fnc_applyForceWalkStatus.sqf b/addons/common/functions/fnc_applyForceWalkStatus.sqf deleted file mode 100644 index 656e4a6d25..0000000000 --- a/addons/common/functions/fnc_applyForceWalkStatus.sqf +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Author: Pabst Mirror - * Applys the forceWalk status of an unit. Called from Extended_InitPost_EventHandlers. - * - * Arguments: - * 0: Unit - * - * Return Value: - * None - * - * Example: - * [ACE_Player] call ace_common_fnc_applyForceWalkStatus - * - * Public: No - */ -#include "script_component.hpp" - -params ["_unit"]; - -private _forceWalkNumber = _unit getVariable ["ACE_forceWalkStatusNumber", 0]; - -_unit forceWalk (_forceWalkNumber > 0); diff --git a/addons/common/functions/fnc_fixCollision.sqf b/addons/common/functions/fnc_fixCollision.sqf index 1d55eb1454..c0cf7b93e7 100644 --- a/addons/common/functions/fnc_fixCollision.sqf +++ b/addons/common/functions/fnc_fixCollision.sqf @@ -15,8 +15,8 @@ // allowDamage requires local object if (!local _this) exitWith {}; -// prevent collision damage, @todo allowDamage API -_this allowDamage false; +// prevent collision damage +[_this, "blockDamage", "fixCollision", true] call FUNC(statusEffect_set); // re-allow damage after 2 seconds -[{_this allowDamage true}, _this, 2, 0] call EFUNC(common,waitAndExecute); +[{[_this, "blockDamage", "fixCollision", false] call FUNC(statusEffect_set);}, _this, 2] call EFUNC(common,waitAndExecute); diff --git a/addons/common/functions/fnc_fixFloating.sqf b/addons/common/functions/fnc_fixFloating.sqf index 5391402ca4..1d8da1c8a4 100644 --- a/addons/common/functions/fnc_fixFloating.sqf +++ b/addons/common/functions/fnc_fixFloating.sqf @@ -1,6 +1,7 @@ /* * Author: commy2 * Attempt to fix floating physx with disabled damage after setPosXXX commands. + * Handles the "fixFloating" event * * Arguments: * PhysX object @@ -16,6 +17,11 @@ params ["_object"]; // setHitPointDamage requires local object if (!local _object) exitWith {}; +//Ignore mans +if (_object isKindOf "CAManBase") exitWith {}; + +//We need to manually set allowDamage to true for setHitIndex to function +["blockDamage", [_object, 0]] call FUNC(localEvent); // save and restore hitpoints, see below why private _hitPointDamages = getAllHitPointsDamage _object; @@ -31,3 +37,8 @@ _object setDamage damage _object; { _object setHitIndex [_forEachIndex, _x]; } forEach (_hitPointDamages select 2); + +//manually re-enable allowDamage to previous setting (ref statusEffect_funcs) +private _effectVarName = format [QGVAR(effect_%1), "blockDamage"]; +private _effectNumber = _object getVariable [_effectVarName, 0]; +["blockDamage", [_object, _effectNumber]] call FUNC(localEvent); diff --git a/addons/common/functions/fnc_getCaptivityStatus.sqf b/addons/common/functions/fnc_getCaptivityStatus.sqf deleted file mode 100644 index e2663a892e..0000000000 --- a/addons/common/functions/fnc_getCaptivityStatus.sqf +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Author: commy2 - * Return the captivity status of an unit. - * - * Arguments: - * 0: Unit - * - * Return Value: - * Captivity Reasons, empty if not captive - * - * Public: Yes - */ -#include "script_component.hpp" - -params ["_unit"]; - -private _captivityReasons = missionNamespace getVariable ["ACE_captivityReasons", []]; -private _unitCaptivityStatus = [captiveNum _unit, count _captivityReasons] call FUNC(binarizeNumber); - -private _unitCaptivityReasons = []; - -{ - if (_unitCaptivityStatus select _forEachIndex) then { - _unitCaptivityReasons pushBack _x; - }; -} forEach _captivityReasons; - -_unitCaptivityReasons diff --git a/addons/common/functions/fnc_getForceWalkStatus.sqf b/addons/common/functions/fnc_getForceWalkStatus.sqf deleted file mode 100644 index 16eca5ccc7..0000000000 --- a/addons/common/functions/fnc_getForceWalkStatus.sqf +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Author: PabstMirror, commy2 - * Returns reasons why the unit is forceWalk-ing. - * - * Arguments: - * 0: unit - * - * Return Value: - * Force Walk reasons - * - * Example: - * [ACE_Player] call ace_common_fnc_getForceWalkStatus - * - * Public: Yes - */ -#include "script_component.hpp" - -params ["_unit"]; - -private _forceWalkReasons = missionNamespace getVariable ["ACE_forceWalkReasons", []]; -private _unitForceWalkNumber = _unit getVariable ["ACE_forceWalkStatusNumber", 0]; -private _unitForceWalkStatus = [_unitForceWalkNumber, count _forceWalkReasons] call FUNC(binarizeNumber); - -private _unitForceWalkReasons = []; - -{ - if (_unitForceWalkStatus select _forEachIndex) then { - _unitForceWalkReasons pushBack _x; - }; -} forEach _forceWalkReasons; - -_unitForceWalkReasons diff --git a/addons/common/functions/fnc_resetAllDefaults.sqf b/addons/common/functions/fnc_resetAllDefaults.sqf index d9850ffd5b..6432f3759e 100644 --- a/addons/common/functions/fnc_resetAllDefaults.sqf +++ b/addons/common/functions/fnc_resetAllDefaults.sqf @@ -19,11 +19,6 @@ _unit setVariable ["ACE_isUnconscious", nil, true]; if (isPlayer _unit) then { [true] call FUNC(setVolume); - // [false] call FUNC(disableKeyInput); //func does not exist - - if (["ace_medical"] call FUNC(isModLoaded)) then { - // [false] call EFUNC(medical,effectBlackOut); //func does not exist - }; if !(isNil QGVAR(DISABLE_USER_INPUT_COLLECTION)) then { // clear all disable user input @@ -40,5 +35,3 @@ if (isPlayer _unit) then { }; false } count ([_unit] call FUNC(getAllDefinedSetVariables)); - -_unit setVariable ["ACE_forceWalkStatusNumber", 0, true]; diff --git a/addons/common/functions/fnc_setCaptivityStatus.sqf b/addons/common/functions/fnc_setCaptivityStatus.sqf index 3e84c1753d..f835a84919 100644 --- a/addons/common/functions/fnc_setCaptivityStatus.sqf +++ b/addons/common/functions/fnc_setCaptivityStatus.sqf @@ -16,28 +16,6 @@ params ["_unit", "_reason", "_status"]; -private _captivityReasons = missionNamespace getVariable ["ACE_captivityReasons", []]; +//Now just a wrapper for FUNC(statusEffect_set) -// register new reason (these reasons are shared publicly, since units can change ownership, but keep their captivity status) -if !(_reason in _captivityReasons) then { - _captivityReasons pushBack _reason; - - ACE_captivityReasons = _captivityReasons; - publicVariable "ACE_captivityReasons"; -}; - -// get reasons why the unit is captive already and update to the new status -private _unitCaptivityReasons = _unit call FUNC(getCaptivityStatus); - -private _captivityReasonsBooleans = []; - -{ - _captivityReasonsBooleans set [_forEachIndex, (_captivityReasons select _forEachIndex) in _unitCaptivityReasons]; -} forEach _captivityReasons; - -_captivityReasonsBooleans set [_captivityReasons find _reason, _status]; - -private _bitmask = _captivityReasonsBooleans call FUNC(toBitmask); - -// actually apply the setCaptive command globaly -[[_unit, _bitmask], "{(_this select 0) setCaptive (_this select 1)}", _unit] call FUNC(execRemoteFnc); +[_unit, "setCaptive", _reason, _status] call FUNC(statusEffect_set); \ No newline at end of file diff --git a/addons/common/functions/fnc_setForceWalkStatus.sqf b/addons/common/functions/fnc_setForceWalkStatus.sqf index 3842457395..8bd3250759 100644 --- a/addons/common/functions/fnc_setForceWalkStatus.sqf +++ b/addons/common/functions/fnc_setForceWalkStatus.sqf @@ -20,29 +20,6 @@ params ["_unit", "_reason", "_status"]; -private _forceWalkReasons = missionNamespace getVariable ["ACE_forceWalkReasons", []]; +//Now just a wrapper for FUNC(statusEffect_set) -// register new reason (these reasons are shared publicly, since units can change ownership, but keep their forceWalk status) -if !(_reason in _forceWalkReasons) then { - _forceWalkReasons pushBack _reason; - ACE_forceWalkReasons = _forceWalkReasons; - publicVariable "ACE_forceWalkReasons"; -}; - -// get reasons why the unit is forceWalking already and update to the new status -private _unitForceWalkReasons = [_unit] call FUNC(getForceWalkStatus); - -private _forceWalkReasonsBooleans = []; - -{ - _forceWalkReasonsBooleans set [_forEachIndex, (_forceWalkReasons select _forEachIndex) in _unitForceWalkReasons]; -} forEach _forceWalkReasons; - -_forceWalkReasonsBooleans set [_forceWalkReasons find _reason, _status]; - -private _bitmaskNumber = _forceWalkReasonsBooleans call FUNC(toBitmask); - -_unit setVariable ["ACE_forceWalkStatusNumber", _bitmaskNumber, true]; - -// actually apply the forceWalk command globaly -[[_unit], QFUNC(applyForceWalkStatus), 2] call FUNC(execRemoteFnc); +[_unit, "forceWalk", _reason, _status] call FUNC(statusEffect_set); diff --git a/addons/common/functions/fnc_statusEffect_addType.sqf b/addons/common/functions/fnc_statusEffect_addType.sqf new file mode 100644 index 0000000000..afd7ff7be7 --- /dev/null +++ b/addons/common/functions/fnc_statusEffect_addType.sqf @@ -0,0 +1,37 @@ +/* + * Author: PabstMirror + * Adds a status effect that will be handled. + * + * Arguments: + * 0: Status Effect Name, this should match a corisponding event name + * 1: Send event globaly + * 2: Common Effect Reaons to pre-seed durring init + * + * Return Value: + * Nothing + * + * Example: + * ["setCaptive", true, []] call ace_common_fnc_statusEffect_addType + * + * Public: No + */ +// #define DEBUG_MODE_FULL +#include "script_component.hpp" + +params [["_name", "", [""]], ["_isGlobal", false, [false]], ["_commonReasonsArray", [], [[]]]]; +TRACE_3("params",_name,_isGlobal,_commonReasonsArray); + +if (_name == "") exitWith {ACE_LOGERROR_1("addStatusEffect - Bad Name %1", _this)}; +if (_name in GVAR(statusEffect_Names)) exitWith {ACE_LOGWARNING_1("addStatusEffect - Effect Already Added (note, will not update global bit) %1", _this)}; + +GVAR(statusEffect_Names) pushBack _name; +GVAR(statusEffect_isGlobal) pushBack _isGlobal; + +//We add reasons at any time, but more efficenet to add all common ones at one time during init +if (isServer && {!(_commonReasonsArray isEqualTo [])}) then { + //Switch case to lower: + { + _commonReasonsArray set [_forEachIndex, toLower _x]; + } forEach _commonReasonsArray; + missionNamespace setVariable [(format [QGVAR(statusEffects_%1), _name]), _commonReasonsArray, true]; +}; diff --git a/addons/common/functions/fnc_statusEffect_localEH.sqf b/addons/common/functions/fnc_statusEffect_localEH.sqf new file mode 100644 index 0000000000..af839d683f --- /dev/null +++ b/addons/common/functions/fnc_statusEffect_localEH.sqf @@ -0,0 +1,36 @@ +/* + * Author: PabstMirror + * + * + * Arguments: + * 0: vehicle that it will be attached to (player or vehicle) + * + * Return Value: + * Nothing + * + * Example: + * [player, true] call ace_common_fnc_statusEffect_localEH + * + * Public: No + */ +// #define DEBUG_MODE_FULL +#include "script_component.hpp" + +params ["_object", "_isLocal"]; +TRACE_2("params",_object,_isLocal); + +//Only run this after the settings are initialized +//Need to wait for all EH to be installed (local event will happen between pre and post init) +if !(GVAR(settingsInitFinished)) exitWith { + TRACE_1("pushing to runAtSettingsInitialized", _this); + GVAR(runAtSettingsInitialized) pushBack [FUNC(statusEffect_localEH), _this]; +}; + +if (!_isLocal) exitWith {TRACE_1("object no longer local", _this)}; +if (isNull _object) exitWith {TRACE_1("object null", _this)}; + + //Reset any variables because of respawn +[_object, false] call FUNC(statusEffect_resetVariables); + +//Send all Variables to client +[_object, ""] call FUNC(statusEffect_sendEffects); diff --git a/addons/common/functions/fnc_statusEffect_resetVariables.sqf b/addons/common/functions/fnc_statusEffect_resetVariables.sqf new file mode 100644 index 0000000000..3f7d00d26f --- /dev/null +++ b/addons/common/functions/fnc_statusEffect_resetVariables.sqf @@ -0,0 +1,45 @@ +/* + * Author: PabstMirror + * + * + * Arguments: + * 0: vehicle that it will be attached to (player or vehicle) + * + * Return Value: + * Nothing + * + * Example: + * [player, true] call ace_common_fnc_statusEffect_resetVariables + * + * Public: No + */ +// #define DEBUG_MODE_FULL +#include "script_component.hpp" + +params [["_object", objNull, [objNull]], ["_setObjectRef", false, [false]]]; +TRACE_2("params",_object,_setObjectRef); + +if (isNull _object) exitWith {}; + +private _objectRef = _object getVariable QGVAR(statusEffect_object); +TRACE_2("testing",_object,_objectRef); + +// If nothing was ever set, or objects match, exit (always true unless respawned) +if (isNil "_objectRef") exitWith { + if (_setObjectRef) then { + _object setVariable [QGVAR(statusEffect_object), _object, true]; //explicitly set new object ref + }; +}; +if (_object == _objectRef) exitWith {}; + +//Mismatch, so if effect has ever been defined, reset to 0 +{ + private _effectVarName = format [QGVAR(effect_%1), _x]; + private _effectNumber = _object getVariable [_effectVarName, -1]; + if (_effectNumber != -1) then { + TRACE_2("forced reset defined array on object mismatch",_x,_effectNumber); + _object setVariable [_effectVarName, 0, true]; //This always resets to 0 (not -1/nil)! + }; +} forEach GVAR(statusEffect_Names); + +_object setVariable [QGVAR(statusEffect_object), _object, true]; diff --git a/addons/common/functions/fnc_statusEffect_respawnEH.sqf b/addons/common/functions/fnc_statusEffect_respawnEH.sqf new file mode 100644 index 0000000000..92717b68c7 --- /dev/null +++ b/addons/common/functions/fnc_statusEffect_respawnEH.sqf @@ -0,0 +1,36 @@ +/* + * Author: PabstMirror + * Handles the Respawn Event Handler to reset effects. + * + * Arguments: + * 0: vehicle that it will be attached to (player or vehicle) + * + * Return Value: + * Nothing + * + * Example: + * [player, objNull] call ace_common_fnc_statusEffect_respawnEH + * + * Public: No + */ +// #define DEBUG_MODE_FULL +#include "script_component.hpp" + +params ["_object"]; +TRACE_1("params",_object); + +//Only run this after the settings are initialized +//Need to wait for all EH to be installed (local event will happen between pre and post init) +if !(GVAR(settingsInitFinished)) exitWith { + TRACE_1("pushing to runAtSettingsInitialized", _this); + GVAR(runAtSettingsInitialized) pushBack [FUNC(statusEffect_respawnEH), _this]; +}; + +if (!local _object) exitWith {TRACE_1("object no longer local", _this)}; +if (isNull _object) exitWith {TRACE_1("object null", _this)}; + + //Reset any variables on "real" respawn +[_object, false] call FUNC(statusEffect_resetVariables); + +//Send all Variables to client +[_object, ""] call FUNC(statusEffect_sendEffects); diff --git a/addons/common/functions/fnc_statusEffect_sendEffects.sqf b/addons/common/functions/fnc_statusEffect_sendEffects.sqf new file mode 100644 index 0000000000..4291de1ad8 --- /dev/null +++ b/addons/common/functions/fnc_statusEffect_sendEffects.sqf @@ -0,0 +1,48 @@ +/* + * Author: PabstMirror + * Sends all status effects for an object (can be run on non-local objects) + * + * Arguments: + * 0: Object + * 1: Effect name (or "" or send all) + * + * Return Value: + * Nothing + * + * Example: + * [player, ""] call ace_common_fnc_statusEffect_sendEffects + * + * Public: No + */ +// #define DEBUG_MODE_FULL +#include "script_component.hpp" + +params [["_object", objNull, [objNull]], ["_effectName", "", [""]]]; +TRACE_2("params",_object,_effectName); + +if (isNull _object) exitWith {}; + +{ + if ((_effectName == "") || {_effectName == _x}) then { + private _effectVarName = format [QGVAR(effect_%1), _x]; + private _effectNumber = _object getVariable [_effectVarName, -1]; + + //We only do anything if the effect has been defined at some point in the game for this unit + TRACE_2("checking if event is nil",_x,_effectNumber); + if (_effectNumber != -1) then { + if (GVAR(statusEffect_isGlobal) select _forEachIndex) then { + TRACE_2("Sending Global Event", _object, _effectNumber); + [_x, [_object, _effectNumber]] call FUNC(globalEvent); + } else { + if (local _object) then { + //If local, send directly to bypass network delay of targetEvent call + TRACE_2("Sending Target Local Event", _object, _effectNumber); + [_x, [_object, _effectNumber]] call FUNC(localEvent); + } else { + TRACE_2("Sending Target Non-Local Event", _object, _effectNumber); + [_x, [_object], [_object, _effectNumber]] call FUNC(targetEvent); + }; + }; + }; + }; +} forEach GVAR(statusEffect_Names); diff --git a/addons/common/functions/fnc_statusEffect_set.sqf b/addons/common/functions/fnc_statusEffect_set.sqf new file mode 100644 index 0000000000..944e5caf9b --- /dev/null +++ b/addons/common/functions/fnc_statusEffect_set.sqf @@ -0,0 +1,64 @@ +/* + * Author: PabstMirror + * Adds or removes an id to a status effect and then updates the value + * + * Arguments: + * 0: vehicle that it will be attached to (player or vehicle) + * 1: Effect Name + * 2: Unique Reason ID + * 3: Is Set (true adds/false removes) + * + * Return Value: + * Nothing + * + * Example: + * [player, "setCaptive", "reason1", true] call ace_common_fnc_statusEffect_set + * + * Public: Yes + */ +// #define DEBUG_MODE_FULL +#include "script_component.hpp" + +params [["_object", objNull, [objNull]], ["_effectName", "", [""]], ["_ID", "", [""]], ["_set", true, [false]]]; +TRACE_4("params",_object,_effectName,_ID,_set); + +//Only run this after the settings are initialized +if !(GVAR(settingsInitFinished)) exitWith { + TRACE_1("pushing to runAtSettingsInitialized", _this); + GVAR(runAtSettingsInitialized) pushBack [FUNC(statusEffect_set), _this]; +}; + +if (isNull _object) exitWith {ACE_LOGERROR_1("setStatusEffect - Bad Input %1", _this)}; + +[_object, true] call FUNC(statusEffect_resetVariables); //Check for mismatch, and set object ref + +//check ID case and set globaly if not already set: +_ID = toLower _ID; +private _statusReasons = missionNamespace getVariable [(format [QGVAR(statusEffects_%1), _effectName]), []]; +private _statusIndex = _statusReasons find _ID; +if (_statusIndex == -1) then { + TRACE_2("ID not in global reasons, adding",_statusReasons,_ID); + _statusIndex = _statusReasons pushBack _ID; + missionNamespace setVariable [(format [QGVAR(statusEffects_%1), _effectName]), _statusReasons, true]; +}; + +private _effectVarName = format [QGVAR(effect_%1), _effectName]; +private _effectNumber = _object getVariable [_effectVarName, -1]; +TRACE_2("current",_effectVarName,_effectNumber); + +if ((_effectNumber == -1) && {!_set}) exitWith { + //Optimization for modules that always set an ID to false even if never set true + TRACE_2("Set False on nil array, exiting",_set,_effectNumber); +}; + +if (_effectNumber == -1) then {_effectNumber = 0}; + +private _effectBoolArray = [_effectNumber, count _statusReasons] call FUNC(binarizeNumber); +TRACE_3("Setting New Value", _set, _statusIndex, _effectBoolArray); +_effectBoolArray set [_statusIndex, _set]; +_effectNumber = _effectBoolArray call FUNC(toBitmask); + +TRACE_2("Saving globaly",_effectVarName,_effectNumber); +_object setVariable [_effectVarName, _effectNumber, true]; + +[_object, _effectName] call FUNC(statusEffect_sendEffects); diff --git a/addons/common/script_component.hpp b/addons/common/script_component.hpp index 7c266c169d..70bdff7ff3 100644 --- a/addons/common/script_component.hpp +++ b/addons/common/script_component.hpp @@ -2,6 +2,7 @@ #include "\z\ace\addons\main\script_mod.hpp" // #define DEBUG_MODE_FULL +// #define CBA_DEBUG_SYNCHRONOUS #ifdef DEBUG_ENABLED_COMMON #define DEBUG_MODE_FULL diff --git a/addons/dragging/functions/fnc_dropObject_carry.sqf b/addons/dragging/functions/fnc_dropObject_carry.sqf index c9c34c82a0..01e4cdfa8f 100644 --- a/addons/dragging/functions/fnc_dropObject_carry.sqf +++ b/addons/dragging/functions/fnc_dropObject_carry.sqf @@ -48,7 +48,7 @@ _unit removeWeapon "ACE_FakePrimaryWeapon"; // reselect weapon and re-enable sprint _unit selectWeapon primaryWeapon _unit; -[_unit, "isDragging", false] call EFUNC(common,setforceWalkStatus); +[_unit, "ACE_dragging", false] call EFUNC(common,setforceWalkStatus); // prevent object from flipping inside buildings if (_inBuilding) then { diff --git a/addons/dragging/functions/fnc_startCarry.sqf b/addons/dragging/functions/fnc_startCarry.sqf index 3b08de2c9d..d9927c10b2 100644 --- a/addons/dragging/functions/fnc_startCarry.sqf +++ b/addons/dragging/functions/fnc_startCarry.sqf @@ -53,7 +53,7 @@ if (_target isKindOf "CAManBase") then { _unit action ["SwitchWeapon", _unit, _unit, 99]; [_unit, "AmovPercMstpSnonWnonDnon", 0] call EFUNC(common,doAnimation); - [_unit, "isDragging", true] call EFUNC(common,setforceWalkStatus); + [_unit, "ACE_dragging", true] call EFUNC(common,setforceWalkStatus); }; diff --git a/addons/refuel/XEH_respawn.sqf b/addons/refuel/XEH_respawn.sqf index 39225f2521..d304c8a91a 100644 --- a/addons/refuel/XEH_respawn.sqf +++ b/addons/refuel/XEH_respawn.sqf @@ -6,6 +6,6 @@ _unit = _this select 0; if !(local _unit) exitWith {}; -[_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus); +[_unit, "ACE_refuel", false] call EFUNC(common,setForceWalkStatus); _unit setVariable [QGVAR(selectedWeaponOnRefuel), nil]; _unit setVariable [QGVAR(isRefueling), false]; diff --git a/addons/refuel/functions/fnc_connectNozzleAction.sqf b/addons/refuel/functions/fnc_connectNozzleAction.sqf index 42190aacc6..f306985a77 100644 --- a/addons/refuel/functions/fnc_connectNozzleAction.sqf +++ b/addons/refuel/functions/fnc_connectNozzleAction.sqf @@ -80,7 +80,7 @@ _endPosTestOffset set [2, (_startingOffset select 2)]; _args params ["_unit", "_nozzle", "_target", "_endPosTestOffset"]; _unit setVariable [QGVAR(nozzle), nil]; _unit setVariable [QGVAR(isRefueling), false]; - [_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus); + [_unit, "ACE_refuel", false] call EFUNC(common,setForceWalkStatus); REFUEL_UNHOLSTER_WEAPON _actionID = _unit getVariable [QGVAR(ReleaseActionID), -1]; if (_actionID != -1) then { diff --git a/addons/refuel/functions/fnc_handleUnconscious.sqf b/addons/refuel/functions/fnc_handleUnconscious.sqf index 6a6e561230..2481749f2c 100644 --- a/addons/refuel/functions/fnc_handleUnconscious.sqf +++ b/addons/refuel/functions/fnc_handleUnconscious.sqf @@ -22,7 +22,7 @@ if (!local _unit || {!_isUnconscious}) exitWith {}; private "_nozzle"; -[_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus); +[_unit, "ACE_refuel", false] call EFUNC(common,setForceWalkStatus); _nozzle = _unit getVariable [QGVAR(nozzle), objNull]; if !(isNull _nozzle) then { [_unit, _nozzle] call FUNC(dropNozzle); diff --git a/addons/refuel/functions/fnc_returnNozzle.sqf b/addons/refuel/functions/fnc_returnNozzle.sqf index d3fca33021..0f494886e8 100644 --- a/addons/refuel/functions/fnc_returnNozzle.sqf +++ b/addons/refuel/functions/fnc_returnNozzle.sqf @@ -33,7 +33,7 @@ if (isNull _nozzle || {_source != _target}) exitWith {false}; _args params ["_unit", "_nozzle", "_target"]; _unit setVariable [QGVAR(nozzle), nil]; detach _nozzle; - [_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus); + [_unit, "ACE_refuel", false] call EFUNC(common,setForceWalkStatus); REFUEL_UNHOLSTER_WEAPON _unit setVariable [QGVAR(isRefueling), false]; _actionID = _unit getVariable [QGVAR(ReleaseActionID), -1]; diff --git a/addons/refuel/functions/fnc_takeNozzle.sqf b/addons/refuel/functions/fnc_takeNozzle.sqf index 3c52748efc..a84d20fb0b 100644 --- a/addons/refuel/functions/fnc_takeNozzle.sqf +++ b/addons/refuel/functions/fnc_takeNozzle.sqf @@ -21,7 +21,7 @@ private ["_endPosOffset"], params ["_unit", "_target", ["_nozzle", objNull]]; -[_unit, QGVAR(vehAttach), true] call EFUNC(common,setForceWalkStatus); +[_unit, "ACE_refuel", true] call EFUNC(common,setForceWalkStatus); REFUEL_HOLSTER_WEAPON @@ -70,7 +70,7 @@ if (isNull _nozzle) then { // func is called on fuel truck }; _actionID = _unit addAction [ format ["%1", localize ELSTRING(dragging,Drop)], - '_unit = _this select 0; _nozzle = _unit getVariable QGVAR(nozzle); [_unit, _nozzle] call FUNC(dropNozzle); [_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus); REFUEL_UNHOLSTER_WEAPON', + '_unit = _this select 0; _nozzle = _unit getVariable QGVAR(nozzle); [_unit, _nozzle] call FUNC(dropNozzle); [_unit, "ACE_refuel", false] call EFUNC(common,setForceWalkStatus); REFUEL_UNHOLSTER_WEAPON', nil, 20, false, @@ -107,7 +107,7 @@ if (isNull _nozzle) then { // func is called on fuel truck }; _actionID = _unit addAction [ format ["%1", localize ELSTRING(dragging,Drop)], - '_unit = _this select 0; _nozzle = _unit getVariable QGVAR(nozzle); [_unit, _nozzle] call FUNC(dropNozzle); [_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus); REFUEL_UNHOLSTER_WEAPON', + '_unit = _this select 0; _nozzle = _unit getVariable QGVAR(nozzle); [_unit, _nozzle] call FUNC(dropNozzle); [_unit, "ACE_refuel", false] call EFUNC(common,setForceWalkStatus); REFUEL_UNHOLSTER_WEAPON', nil, 20, false, @@ -138,7 +138,7 @@ if !(_nozzle getVariable [QGVAR(jerryCan), false]) then { [_unit, _nozzle] call FUNC(dropNozzle); REFUEL_UNHOLSTER_WEAPON - [_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus); + [_unit, "ACE_refuel", false] call EFUNC(common,setForceWalkStatus); [LSTRING(Hint_TooFar), 2, _unit] call EFUNC(common,displayTextStructured); }; [_pfID] call cba_fnc_removePerFrameHandler;