From 7e84a9d9b02b9420958749b4c7aa7bf9be45ead4 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sat, 16 Jan 2016 17:27:42 -0600 Subject: [PATCH] Add getter, readd old public funcs, add blockSprint --- addons/common/XEH_postInit.sqf | 10 ++- addons/common/XEH_preInit.sqf | 3 + .../functions/fnc_getCaptivityStatus.sqf | 19 ++++++ .../functions/fnc_getForceWalkStatus.sqf | 22 +++++++ .../functions/fnc_setCaptivityStatus.sqf | 2 +- .../common/functions/fnc_statusEffect_get.sqf | 63 +++++++++++++++++++ .../common/functions/fnc_statusEffect_set.sqf | 2 +- 7 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 addons/common/functions/fnc_getCaptivityStatus.sqf create mode 100644 addons/common/functions/fnc_getForceWalkStatus.sqf create mode 100644 addons/common/functions/fnc_statusEffect_get.sqf diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 6e2fa28869..65b9804da5 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -61,6 +61,7 @@ //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); +["blockSprint", false, []] 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); @@ -69,12 +70,17 @@ TRACE_2("forceWalk EH",_object,_set); _object forceWalk (_set > 0); }] call FUNC(addEventHandler); +["blockSprint", { //Name reversed from `allowSprint` because we want NOR logic + params ["_object", "_set"]; + TRACE_2("blockSprint EH",_object,_set); + _object allowSprint (_set == 0); +}] call FUNC(addEventHandler); ["setCaptive", { params ["_object", "_set"]; - TRACE_2("forceWalk EH",_object,_set); + TRACE_2("setCaptive EH",_object,_set); _object setCaptive (_set > 0); }] call FUNC(addEventHandler); -["blockDamage", { +["blockDamage", { //Name reversed from `allowDamage` because we want NOR logic params ["_object", "_set"]; if ((_object isKindOf "CAManBase") && {(["ace_medical"] call FUNC(isModLoaded))}) then { TRACE_2("blockDamage EH (using medical)",_object,_set); diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 732b4d94c0..ce67009b4f 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -53,12 +53,14 @@ PREP(fixPosition); PREP(getAllDefinedSetVariables); PREP(getAllGear); PREP(getDeathAnim); +PREP(getCaptivityStatus); PREP(getDefaultAnim); PREP(getDefinedVariable); PREP(getDefinedVariableDefault); PREP(getDefinedVariableInfo); PREP(getFirstObjectIntersection); PREP(getFirstTerrainIntersection); +PREP(getForceWalkStatus); PREP(getGunner); PREP(getInPosition); PREP(getMapGridData); @@ -168,6 +170,7 @@ PREP(setVolume); PREP(sortAlphabeticallyBy); PREP(showHud); PREP(statusEffect_addType); +PREP(statusEffect_get); PREP(statusEffect_localEH); PREP(statusEffect_resetVariables); PREP(statusEffect_respawnEH); diff --git a/addons/common/functions/fnc_getCaptivityStatus.sqf b/addons/common/functions/fnc_getCaptivityStatus.sqf new file mode 100644 index 0000000000..3eca2ce831 --- /dev/null +++ b/addons/common/functions/fnc_getCaptivityStatus.sqf @@ -0,0 +1,19 @@ +/* + * 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"]; + +//Now just a wrapper for FUNC(statusEffect_get) + +([player, "setCaptive"] call FUNC(statusEffect_get)) select 1 diff --git a/addons/common/functions/fnc_getForceWalkStatus.sqf b/addons/common/functions/fnc_getForceWalkStatus.sqf new file mode 100644 index 0000000000..4c48b64030 --- /dev/null +++ b/addons/common/functions/fnc_getForceWalkStatus.sqf @@ -0,0 +1,22 @@ +/* + * 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"]; + +//Now just a wrapper for FUNC(statusEffect_get) + +([player, "forceWalk"] call FUNC(statusEffect_get)) select 1 diff --git a/addons/common/functions/fnc_setCaptivityStatus.sqf b/addons/common/functions/fnc_setCaptivityStatus.sqf index f835a84919..79b2a654a9 100644 --- a/addons/common/functions/fnc_setCaptivityStatus.sqf +++ b/addons/common/functions/fnc_setCaptivityStatus.sqf @@ -18,4 +18,4 @@ params ["_unit", "_reason", "_status"]; //Now just a wrapper for FUNC(statusEffect_set) -[_unit, "setCaptive", _reason, _status] call FUNC(statusEffect_set); \ No newline at end of file +[_unit, "setCaptive", _reason, _status] call FUNC(statusEffect_set); diff --git a/addons/common/functions/fnc_statusEffect_get.sqf b/addons/common/functions/fnc_statusEffect_get.sqf new file mode 100644 index 0000000000..2d7e17e0ec --- /dev/null +++ b/addons/common/functions/fnc_statusEffect_get.sqf @@ -0,0 +1,63 @@ +/* + * Author: PabstMirror + * Retrives list of current status effects + * + * Arguments: + * 0: vehicle that it will be attached to (player or vehicle) + * 1: Effect Name + * + * Return Value: + * Effect status + * 0: is activly set (if false, the effect is ignored and never modified) + * 1: reasons why it is set true (list of strings, count of 0 = false, 1+ = true) + * + * Example: + * [player, "forceWalk"] call ace_common_fnc_statusEffect_get + * + * Public: Yes + */ +// #define DEBUG_MODE_FULL +#include "script_component.hpp" + +params [["_object", objNull, [objNull]], ["_effectName", "", [""]]]; +TRACE_2("params",_object,_effectName); + +if (isNull _object) exitWith { + TRACE_1("null",_object); + [false, []] +}; + +[_object, false] call FUNC(statusEffect_resetVariables); //Check for mismatch + +//List of reasons +private _statusReasons = missionNamespace getVariable [(format [QGVAR(statusEffects_%1), _effectName]), []]; +if (_statusReasons isEqualTo []) exitWith { + TRACE_1("no reasons - bad effect?",_statusReasons); + [false, []] +}; + +//Get Effect Number +private _effectVarName = format [QGVAR(effect_%1), _effectName]; +private _effectNumber = _object getVariable [_effectVarName, -1]; +TRACE_2("current",_effectVarName,_effectNumber); + +if (_effectNumber == -1) exitWith { //Nil array - no effect + [false, []] +}; +if (_effectNumber == 0) exitWith { //empty array - false effect + [true, []] +}; + +//if no change: skip sending publicVar and events +private _effectBoolArray = [_effectNumber, count _statusReasons] call FUNC(binarizeNumber); +TRACE_2("bitArray",_statusIndex,_effectBoolArray); + +private _activeEffects = []; +{ + if (_x) then { + _activeEffects pushBack (_statusReasons select _forEachIndex); + }; +} forEach _effectBoolArray; + +//non-empty array - true effect +[true, _activeEffects] diff --git a/addons/common/functions/fnc_statusEffect_set.sqf b/addons/common/functions/fnc_statusEffect_set.sqf index 117ce251b8..a0be8d8719 100644 --- a/addons/common/functions/fnc_statusEffect_set.sqf +++ b/addons/common/functions/fnc_statusEffect_set.sqf @@ -28,7 +28,7 @@ if !(GVAR(settingsInitFinished)) exitWith { GVAR(runAtSettingsInitialized) pushBack [FUNC(statusEffect_set), _this]; }; -if (isNull _object) exitWith {ACE_LOGERROR_1("setStatusEffect - Bad Input %1", _this)}; +if (isNull _object) exitWith {TRACE_1("null",_object);}; [_object, true] call FUNC(statusEffect_resetVariables); //Check for mismatch, and set object ref