Merge pull request #3163 from acemod/unifiedStatusEffects

Unified status effect handler
This commit is contained in:
PabstMirror 2016-01-22 14:55:25 -06:00
commit 45138aea18
44 changed files with 452 additions and 146 deletions

View File

@ -49,7 +49,7 @@ if (_unit == _attachToVehicle) then { //Self Attachment
} else {
GVAR(placeAction) = PLACE_WAITING;
[_unit, QGVAR(vehAttach), true] call EFUNC(common,setForceWalkStatus);
[_unit, "forceWalk", "ACE_Attach", true] call EFUNC(common,statusEffect_set);
[{[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, "forceWalk", "ACE_Attach", false] call EFUNC(common,statusEffect_set);
[] call EFUNC(interaction,hideMouseHint);
[_unit, "DefaultAction", (_unit getVariable [QGVAR(placeActionEH), -1])] call EFUNC(common,removeActionEventHandler);
_unit removeAction _actionID;

View File

@ -40,12 +40,12 @@ if (_respawn > 3) then {
if (_unit getVariable [QGVAR(isHandcuffed), false]) then {
[_unit, false] call FUNC(setHandcuffed);
};
[_unit, QGVAR(Handcuffed), false] call EFUNC(common,setCaptivityStatus);
[_unit, "setCaptive", QGVAR(Handcuffed), false] call EFUNC(common,statusEffect_set);
if (_unit getVariable [QGVAR(isSurrendering), false]) then {
[_unit, false] call FUNC(setSurrendered);
};
[_unit, QGVAR(Surrendered), false] call EFUNC(common,setCaptivityStatus);
[_unit, "setCaptive", QGVAR(Surrendered), false] call EFUNC(common,statusEffect_set);
if (_oldUnit getVariable [QGVAR(isEscorting), false]) then {
_oldUnit setVariable [QGVAR(isEscorting), false, true];

View File

@ -28,7 +28,7 @@ if ((_unit getVariable [QGVAR(isHandcuffed), false]) isEqualTo _state) exitWith
if (_state) then {
_unit setVariable [QGVAR(isHandcuffed), true, true];
[_unit, QGVAR(Handcuffed), true] call EFUNC(common,setCaptivityStatus);
[_unit, "setCaptive", QGVAR(Handcuffed), true] call EFUNC(common,statusEffect_set);
if (_unit getVariable [QGVAR(isSurrendering), false]) then { //If surrendering, stop
[_unit, false] call FUNC(setSurrendered);
@ -89,7 +89,7 @@ if (_state) then {
}, [_unit], 0.01] call EFUNC(common,waitAndExecute);
} else {
_unit setVariable [QGVAR(isHandcuffed), false, true];
[_unit, QGVAR(Handcuffed), false] call EFUNC(common,setCaptivityStatus);
[_unit, "setCaptive", QGVAR(Handcuffed), false] call EFUNC(common,statusEffect_set);
//remove AnimChanged EH
private _animChangedEHID = _unit getVariable [QGVAR(handcuffAnimEHID), -1];

View File

@ -33,7 +33,7 @@ if (_state) then {
_unit setVariable [QGVAR(isSurrendering), true, true];
[_unit, QGVAR(Surrendered), true] call EFUNC(common,setCaptivityStatus);
[_unit, "setCaptive", QGVAR(Surrendered), true] call EFUNC(common,statusEffect_set);
if (_unit == ACE_player) then {
["captive", [false, false, false, false, false, false, false, false]] call EFUNC(common,showHud);
@ -65,7 +65,7 @@ if (_state) then {
}, [_unit], 0.01] call EFUNC(common,waitAndExecute);
} else {
_unit setVariable [QGVAR(isSurrendering), false, true];
[_unit, QGVAR(Surrendered), false] call EFUNC(common,setCaptivityStatus);
[_unit, "setCaptive", QGVAR(Surrendered), false] call EFUNC(common,statusEffect_set);
//remove AnimChanged EH
private _animChangedEHID = _unit getVariable [QGVAR(surrenderAnimEHID), -1];

View File

@ -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));
};
};
};

View File

@ -1,5 +1,6 @@
// ACE - Common
// #define ENABLE_PERFORMANCE_COUNTERS
// #define DEBUG_MODE_FULL
#include "script_component.hpp"
@ -57,6 +58,39 @@
// 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);
["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);
["forceWalk", {
params ["_object", "_set"];
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("setCaptive EH",_object,_set);
_object setCaptive (_set > 0);
}] call FUNC(addEventHandler);
["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);
_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 +465,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);

View File

@ -10,7 +10,6 @@ PREP(addToInventory);
PREP(assignedItemFix);
PREP(assignObjectsInList);
PREP(ambientBrightness);
PREP(applyForceWalkStatus);
PREP(ASLToPosition);
PREP(binarizeNumber);
PREP(blurScreen);
@ -53,8 +52,8 @@ PREP(fixLoweredRifleAnimation);
PREP(fixPosition);
PREP(getAllDefinedSetVariables);
PREP(getAllGear);
PREP(getCaptivityStatus);
PREP(getDeathAnim);
PREP(getCaptivityStatus);
PREP(getDefaultAnim);
PREP(getDefinedVariable);
PREP(getDefinedVariableDefault);
@ -170,6 +169,13 @@ PREP(setVariablePublic);
PREP(setVolume);
PREP(sortAlphabeticallyBy);
PREP(showHud);
PREP(statusEffect_addType);
PREP(statusEffect_get);
PREP(statusEffect_localEH);
PREP(statusEffect_resetVariables);
PREP(statusEffect_respawnEH);
PREP(statusEffect_sendEffects);
PREP(statusEffect_set);
PREP(stringCompare);
PREP(stringToColoredText);
PREP(stringRemoveWhiteSpace);
@ -316,6 +322,8 @@ if (isServer) then {
call FUNC(loadSettingsOnServer);
};
GVAR(statusEffect_Names) = [];
GVAR(statusEffect_isGlobal) = [];
//////////////////////////////////////////////////
// Set up PlayerChanged eventhandler for pre init

View File

@ -1,22 +0,0 @@
/*
* Author: Pabst Mirror
* Applys the forceWalk status of an unit. Called from Extended_InitPost_EventHandlers.
*
* Arguments:
* 0: Unit <OBJECT>
*
* 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);

View File

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

View File

@ -1,6 +1,7 @@
/*
* Author: commy2
* Attempt to fix floating physx with disabled damage after setPosXXX commands.
* Handles the "fixFloating" event
*
* Arguments:
* PhysX object <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);

View File

@ -14,15 +14,7 @@
params ["_unit"];
private _captivityReasons = missionNamespace getVariable ["ACE_captivityReasons", []];
private _unitCaptivityStatus = [captiveNum _unit, count _captivityReasons] call FUNC(binarizeNumber);
//Now just a wrapper for FUNC(statusEffect_get) [No longer used in ace as of 3.5]
ACE_DEPRECATED("ace_common_fnc_getCaptivityStatus","3.7.0","ace_common_fnc_statusEffect_get");
private _unitCaptivityReasons = [];
{
if (_unitCaptivityStatus select _forEachIndex) then {
_unitCaptivityReasons pushBack _x;
};
} forEach _captivityReasons;
_unitCaptivityReasons
([_unit, "setCaptive"] call FUNC(statusEffect_get)) select 1

View File

@ -17,16 +17,7 @@
params ["_unit"];
private _forceWalkReasons = missionNamespace getVariable ["ACE_forceWalkReasons", []];
private _unitForceWalkNumber = _unit getVariable ["ACE_forceWalkStatusNumber", 0];
private _unitForceWalkStatus = [_unitForceWalkNumber, count _forceWalkReasons] call FUNC(binarizeNumber);
//Now just a wrapper for FUNC(statusEffect_get) [No longer used in ace as of 3.5]
ACE_DEPRECATED("ace_common_fnc_getForceWalkStatus","3.7.0","ace_common_fnc_statusEffect_get");
private _unitForceWalkReasons = [];
{
if (_unitForceWalkStatus select _forEachIndex) then {
_unitForceWalkReasons pushBack _x;
};
} forEach _forceWalkReasons;
_unitForceWalkReasons
([_unit, "forceWalk"] call FUNC(statusEffect_get)) select 1

View File

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

View File

@ -16,28 +16,7 @@
params ["_unit", "_reason", "_status"];
private _captivityReasons = missionNamespace getVariable ["ACE_captivityReasons", []];
//Now just a wrapper for FUNC(statusEffect_set) [No longer used in ace as of 3.5]
ACE_DEPRECATED("ace_common_fnc_setCaptivityStatus","3.7.0","ace_common_fnc_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);

View File

@ -20,29 +20,7 @@
params ["_unit", "_reason", "_status"];
private _forceWalkReasons = missionNamespace getVariable ["ACE_forceWalkReasons", []];
//Now just a wrapper for FUNC(statusEffect_set) [No longer used in ace as of 3.5]
ACE_DEPRECATED("ace_common_fnc_setForceWalkStatus","3.7.0","ace_common_fnc_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);

View File

@ -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 <STRING>
* 1: Send event globaly <BOOL>
* 2: Common Effect Reaons to pre-seed durring init <ARRAY>
*
* 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];
};

View File

@ -0,0 +1,63 @@
/*
* Author: PabstMirror
* Retrives list of current status effects
*
* Arguments:
* 0: vehicle that it will be attached to (player or vehicle) <OBJECT>
* 1: Effect Name <STRING>
*
* Return Value:
* Effect status <ARRAY>
* 0: is activly set (if false, the effect is ignored and never modified) <BOOL>
* 1: reasons why it is set true (list of strings, count of 0 = false, 1+ = true) <ARRAY>
*
* 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]

View File

@ -0,0 +1,36 @@
/*
* Author: PabstMirror
* Handles locality switch, runs a respawn check and then reapplies all effect events.
*
* Arguments:
* 0: vehicle that it will be attached to (player or vehicle) <OBJECT>
*
* 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);

View File

@ -0,0 +1,45 @@
/*
* Author: PabstMirror
* Resets all effect numbers to 0 when an object respawns (but does not apply the effect event).
*
* Arguments:
* 0: vehicle that it will be attached to (player or vehicle) <OBJECT>
*
* 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];

View File

@ -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) <OBJECT>
*
* 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);

View File

@ -0,0 +1,48 @@
/*
* Author: PabstMirror
* Sends all status effects for an object (can be run on non-local objects)
*
* Arguments:
* 0: Object <OBJECT>
* 1: Effect name (or "" or send all) <STRING>
*
* 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);

View File

@ -0,0 +1,70 @@
/*
* Author: PabstMirror
* Adds or removes an id to a status effect and will send an event to apply.
*
* Arguments:
* 0: vehicle that it will be attached to (player or vehicle) <OBJECT>
* 1: Effect Name <STRING>
* 2: Unique Reason ID <STRING>
* 3: Is Set (true adds/false removes) <BOOL>
*
* 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 {TRACE_1("null",_object);};
[_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}; //reset (-1/nil) to 0
//if no change: skip sending publicVar and events
private _effectBoolArray = [_effectNumber, count _statusReasons] call FUNC(binarizeNumber);
TRACE_2("bitArray",_statusIndex,_effectBoolArray);
if (_set isEqualTo (_effectBoolArray select _statusIndex)) exitWith {
TRACE_2("No Change, exiting",_set,_effectBoolArray select _statusIndex);
};
TRACE_2("Setting to new value",_set,_effectBoolArray select _statusIndex);
_effectBoolArray set [_statusIndex, _set];
_effectNumber = _effectBoolArray call FUNC(toBitmask); //Convert array back to number
TRACE_2("Saving globaly",_effectVarName,_effectNumber);
_object setVariable [_effectVarName, _effectNumber, true];
[_object, _effectName] call FUNC(statusEffect_sendEffects);

View File

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

View File

@ -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, "forceWalk", "ACE_dragging", false] call EFUNC(common,statusEffect_set);
// prevent object from flipping inside buildings
if (_inBuilding) then {

View File

@ -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, "forceWalk", "ACE_dragging", true] call EFUNC(common,statusEffect_set);
};

View File

@ -32,7 +32,7 @@ if (!isClass (configFile >> "CfgVehicles" >> _setupObjectClass)) exitWith {ERROR
_p3dModel = getText (configFile >> "CfgVehicles" >> _setupObjectClass >> "model");
if (_p3dModel == "") exitWith {ERROR("No Model");}; //"" - will crash game!
[_unit, "ACE_Explosives", true] call EFUNC(common,setForceWalkStatus);
[_unit, "ACE_Explosives", true] call EFUNC(common,statusEffect_set);
//Show mouse buttons:
[localize LSTRING(PlaceAction), localize LSTRING(CancelAction), localize LSTRING(ScrollAction)] call EFUNC(interaction,showMouseHint);
@ -152,7 +152,7 @@ GVAR(TweakedAngle) = 0;
[_pfID] call CBA_fnc_removePerFrameHandler;
GVAR(pfeh_running) = false;
[_unit, "ACE_Explosives", false] call EFUNC(common,setForceWalkStatus);
[_unit, "forceWalk", "ACE_Explosives", false] call EFUNC(common,statusEffect_set);
[] call EFUNC(interaction,hideMouseHint);
[_unit, "DefaultAction", (_unit getVariable [QGVAR(placeActionEH), -1])] call EFUNC(common,removeActionEventHandler);
[_unit, "zoomtemp", (_unit getVariable [QGVAR(cancelActionEH), -1])] call EFUNC(common,removeActionEventHandler);

View File

@ -7,7 +7,7 @@ params ["_unit"];
// Reset captive status for respawning unit
if (!(_unit getVariable ["ACE_isUnconscious", false])) then {
[_unit, QGVAR(unconscious), false] call EFUNC(common,setCaptivityStatus);
[_unit, "setCaptive", QGVAR(unconscious), false] call EFUNC(common,statusEffect_set);
};
// Remove maximum unconsciousness time handler

View File

@ -95,7 +95,7 @@ if (GVAR(moveUnitsFromGroupOnUnconscious)) then {
[_unit, true, "ACE_isUnconscious", side group _unit] call EFUNC(common,switchToGroupSide);
};
[_unit, QGVAR(unconscious), true] call EFUNC(common,setCaptivityStatus);
[_unit, "setCaptive", QGVAR(unconscious), true] call EFUNC(common,statusEffect_set);
_anim = [_unit] call EFUNC(common,getDeathAnim);
[_unit, _anim, 1, true] call EFUNC(common,doAnimation);
[{

View File

@ -33,7 +33,7 @@ if (!alive _unit) exitWith {
if (GVAR(moveUnitsFromGroupOnUnconscious)) then {
[_unit, false, "ACE_isUnconscious", side group _unit] call EFUNC(common,switchToGroupSide);
};
[_unit, QGVAR(unconscious), false] call EFUNC(common,setCaptivityStatus);
[_unit, "setCaptive", QGVAR(unconscious), false] call EFUNC(common,statusEffect_set);
[_unit, false] call EFUNC(common,disableAI);
//_unit setUnitPos _originalPos;
_unit setUnconscious false;
@ -102,7 +102,7 @@ if !(_unit getVariable ["ACE_isUnconscious",false]) exitWith {
};
if (!_hasMovedOut) then {
// Reset the unit back to the previous captive state.
[_unit, QGVAR(unconscious), false] call EFUNC(common,setCaptivityStatus);
[_unit, "setCaptive", QGVAR(unconscious), false] call EFUNC(common,statusEffect_set);
// Swhich the unit back to its original group
//Unconscious units shouldn't be put in another group #527:

View File

@ -36,7 +36,7 @@ if (_actionID != -1) then {
_unit removeAction _actionID;
_unit setVariable [QGVAR(ReleaseActionID), nil];
};
[_unit, QGVAR(vehRearm), false] call EFUNC(common,setForceWalkStatus);
[_unit, "forceWalk", QGVAR(vehRearm), false] call EFUNC(common,statusEffect_set);
if (_unholster) then {
REARM_UNHOLSTER_WEAPON

View File

@ -19,7 +19,7 @@
params ["_dummy", "_unit"];
REARM_HOLSTER_WEAPON
[_unit, QGVAR(vehRearm), true] call EFUNC(common,setForceWalkStatus);
[_unit, "forceWalk", QGVAR(vehRearm), true] call EFUNC(common,statusEffect_set);
[
5,

View File

@ -22,7 +22,7 @@ private ["_ammo", "_dummyName", "_dummy", "_actionID"];
params ["_args"];
_args params ["_unit", "_magazineClass", "_target"]; // _target is for future possible finite ammo
[_unit, QGVAR(vehRearm), true] call EFUNC(common,setForceWalkStatus);
[_unit, "forceWalk", QGVAR(vehRearm), true] call EFUNC(common,statusEffect_set);
_dummy = [_unit, _magazineClass] call FUNC(createDummy);
[_dummy, _unit] call FUNC(pickUpAmmo);

View File

@ -6,6 +6,6 @@ _unit = _this select 0;
if !(local _unit) exitWith {};
[_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
[_unit, "forceWalk", "ACE_refuel", false] call EFUNC(common,statusEffect_set);
_unit setVariable [QGVAR(selectedWeaponOnRefuel), nil];
_unit setVariable [QGVAR(isRefueling), false];

View File

@ -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, "forceWalk", "ACE_refuel", false] call EFUNC(common,statusEffect_set);
REFUEL_UNHOLSTER_WEAPON
_actionID = _unit getVariable [QGVAR(ReleaseActionID), -1];
if (_actionID != -1) then {

View File

@ -22,7 +22,7 @@ if (!local _unit || {!_isUnconscious}) exitWith {};
private "_nozzle";
[_unit, QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
[_unit, "forceWalk", "ACE_refuel", false] call EFUNC(common,statusEffect_set);
_nozzle = _unit getVariable [QGVAR(nozzle), objNull];
if !(isNull _nozzle) then {
[_unit, _nozzle] call FUNC(dropNozzle);

View File

@ -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,statusEffect_set);
REFUEL_UNHOLSTER_WEAPON
_unit setVariable [QGVAR(isRefueling), false];
_actionID = _unit getVariable [QGVAR(ReleaseActionID), -1];

View File

@ -21,7 +21,7 @@
private ["_endPosOffset"],
params ["_unit", "_target", ["_nozzle", objNull]];
[_unit, QGVAR(vehAttach), true] call EFUNC(common,setForceWalkStatus);
[_unit, "forceWalk", "ACE_refuel", true] call EFUNC(common,statusEffect_set);
REFUEL_HOLSTER_WEAPON
@ -70,7 +70,7 @@ if (isNull _nozzle) then { // func is called on fuel truck
};
_actionID = _unit addAction [
format ["<t color='#FF0000'>%1</t>", 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, "forceWalk", "ACE_refuel", false] call EFUNC(common,statusEffect_set); REFUEL_UNHOLSTER_WEAPON',
nil,
20,
false,
@ -107,7 +107,7 @@ if (isNull _nozzle) then { // func is called on fuel truck
};
_actionID = _unit addAction [
format ["<t color='#FF0000'>%1</t>", 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, "forceWalk", "ACE_refuel", false] call EFUNC(common,statusEffect_set); 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, "forceWalk", "ACE_refuel", false] call EFUNC(common,statusEffect_set);
[LSTRING(Hint_TooFar), 2, _unit] call EFUNC(common,displayTextStructured);
};
[_pfID] call cba_fnc_removePerFrameHandler;

View File

@ -18,7 +18,7 @@
params ["_unit"];
// prevent the placing unit from running
[_unit, "ACE_Sandbag", true] call EFUNC(common,setForceWalkStatus);
[_unit, "forceWalk", "ACE_Sandbag", true] call EFUNC(common,statusEffect_set);
// create the sandbag
private "_sandBag";

View File

@ -18,7 +18,7 @@
params ["_unit"];
// enable running again
[_unit, "ACE_Sandbag", false] call EFUNC(common,setForceWalkStatus);
[_unit, "forceWalk", "ACE_Sandbag", false] call EFUNC(common,statusEffect_set);
// delete placement dummy
deleteVehicle GVAR(sandBag);

View File

@ -18,7 +18,7 @@
params ["_unit"];
// enable running again
[_unit, "ACE_Sandbag", false] call EFUNC(common,setForceWalkStatus);
[_unit, "forceWalk", "ACE_Sandbag", false] call EFUNC(common,statusEffect_set);
// remove sandbag from inventory
_unit removeItem "ACE_Sandbag_empty";

View File

@ -39,7 +39,7 @@ if (vehicle _playerUnit == _playerUnit) then {
_playerUnit linkItem "ItemMap";
removeUniform _playerUnit;
[_playerUnit, "ACE_SwitchUnits", true] call EFUNC(common,setForceWalkStatus);
[_playerUnit, "forceWalk", "ACE_SwitchUnits", true] call EFUNC(common,statusEffect_set);
[_playerUnit, _sides] call FUNC(addMapFunction);
};

View File

@ -21,7 +21,7 @@
params ["_unit", "_ladder"];
// enable running again
[_unit, "ACE_Ladder", false] call EFUNC(common,setForceWalkStatus);
[_unit, "forceWalk", "ACE_Ladder", false] call EFUNC(common,statusEffect_set);
detach _ladder;

View File

@ -19,7 +19,7 @@
params ["_unit", "_ladder"];
// enable running again
[_unit, "ACE_Ladder", false] call EFUNC(common,setForceWalkStatus);
[_unit, "forceWalk", "ACE_Ladder", false] call EFUNC(common,statusEffect_set);
private ["_pos1", "_pos2"];

View File

@ -21,7 +21,7 @@
params ["_unit", "_ladder"];
// prevent the placing unit from running
[_unit, "ACE_Ladder", true] call EFUNC(common,setForceWalkStatus);
[_unit, "forceWalk", "ACE_Ladder", true] call EFUNC(common,statusEffect_set);
{
_ladder animate [_x, 0];