mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Common/Adv. Fatigue/Medical - Add unified sway calculation (#9226)
* fix adv fatigue sway interaction with medical * change medical sway scaling * move to common * function header * number tweaks * baseline is always at least 1 * Add error msgs and warn if using old ACE_setCustomAimCoef * Update addons/common/functions/fnc_addSwayFactor.sqf --------- Co-authored-by: PabstMirror <pabstmirror@gmail.com>
This commit is contained in:
parent
8439a931e4
commit
cc26f00df3
@ -2,22 +2,22 @@
|
||||
|
||||
if (!hasInterface) exitWith {};
|
||||
|
||||
[missionNamespace, "ACE_setCustomAimCoef", QUOTE(ADDON), {
|
||||
private _unit = ACE_player;
|
||||
private _fatigue = _unit getVariable [QGVAR(aimFatigue), 0];
|
||||
|
||||
switch (stance _unit) do {
|
||||
["baseline", {
|
||||
private _fatigue = ACE_player getVariable [QGVAR(aimFatigue), 0];
|
||||
switch (stance ACE_player) do {
|
||||
case ("CROUCH"): {
|
||||
(1.0 + _fatigue ^ 2 * 0.1) * GVAR(swayFactor)
|
||||
(1.0 + _fatigue ^ 2 * 0.1)
|
||||
};
|
||||
case ("PRONE"): {
|
||||
(1.0 + _fatigue ^ 2 * 2.0) * GVAR(swayFactor)
|
||||
(1.0 + _fatigue ^ 2 * 2.0)
|
||||
};
|
||||
default {
|
||||
(1.5 + _fatigue ^ 2 * 3.0) * GVAR(swayFactor)
|
||||
(1.5 + _fatigue ^ 2 * 3.0)
|
||||
};
|
||||
};
|
||||
}] call EFUNC(common,arithmeticSetSource);
|
||||
}, QUOTE(ADDON)] call EFUNC(common,addSwayFactor);
|
||||
|
||||
["multiplier", {GVAR(swayFactor)}, QUOTE(ADDON)] call EFUNC(common,addSwayFactor);
|
||||
|
||||
// recheck weapon inertia after weapon swap, change of attachments or switching unit
|
||||
["weapon", {[ACE_player] call FUNC(getWeaponInertia)}, true] call CBA_fnc_addPlayerEventHandler;
|
||||
|
@ -94,6 +94,3 @@ if (_overexhausted) then {
|
||||
};
|
||||
|
||||
_unit setVariable [QGVAR(aimFatigue), _fatigue];
|
||||
|
||||
private _aimCoef = [missionNamespace, "ACE_setCustomAimCoef", "max"] call EFUNC(common,arithmeticGetResult);
|
||||
_unit setCustomAimCoef _aimCoef;
|
||||
|
@ -10,6 +10,7 @@ PREP(readSettingsFromParamsArray);
|
||||
PREP(actionKeysNamesConverted);
|
||||
PREP(addCanInteractWithCondition);
|
||||
PREP(addLineToDebugDraw);
|
||||
PREP(addSwayFactor);
|
||||
PREP(addToInventory);
|
||||
PREP(addWeapon);
|
||||
PREP(assignedItemFix);
|
||||
@ -181,6 +182,7 @@ PREP(statusEffect_sendEffects);
|
||||
PREP(statusEffect_set);
|
||||
PREP(stringCompare);
|
||||
PREP(stringToColoredText);
|
||||
PREP(swayLoop);
|
||||
PREP(switchPersistentLaser);
|
||||
PREP(switchToGroupSide);
|
||||
PREP(throttledPublicVariable);
|
||||
|
@ -476,6 +476,23 @@ GVAR(reloadMutex_lastMagazines) = [];
|
||||
GVAR(reloadMutex_lastMagazines) = _mags;
|
||||
}, true] call CBA_fnc_addPlayerEventHandler;
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Start the sway loop
|
||||
//////////////////////////////////////////////////
|
||||
["CBA_settingsInitialized", {
|
||||
[{
|
||||
// frame after settingsInitialized to ensure all other addons have added their factors
|
||||
if ((GVAR(swayFactorsBaseline) + GVAR(swayFactorsMultiplier)) isNotEqualTo []) then {
|
||||
call FUNC(swayLoop)
|
||||
};
|
||||
// check for pre-3.16 sway factors being added
|
||||
if (!isNil {missionNamespace getVariable "ACE_setCustomAimCoef"}) then {
|
||||
WARNING("ACE_setCustomAimCoef no longer supported - use ace_common_fnc_addSwayFactor");
|
||||
WARNING_1("source: %1",(missionNamespace getVariable "ACE_setCustomAimCoef") apply {_x});
|
||||
};
|
||||
}] call CBA_fnc_execNextFrame;
|
||||
}] call CBA_fnc_addEventHandler;
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Set up PlayerJIP eventhandler
|
||||
//////////////////////////////////////////////////
|
||||
|
@ -19,6 +19,9 @@ GVAR(isModLoadedCache) = createHashMap;
|
||||
GVAR(settingsInitFinished) = false;
|
||||
GVAR(runAtSettingsInitialized) = [];
|
||||
|
||||
GVAR(swayFactorsBaseline) = [];
|
||||
GVAR(swayFactorsMultiplier) = [];
|
||||
|
||||
// @todo: Generic local-managed global-synced objects (createVehicleLocal)
|
||||
|
||||
//Debug
|
||||
|
35
addons/common/functions/fnc_addSwayFactor.sqf
Normal file
35
addons/common/functions/fnc_addSwayFactor.sqf
Normal file
@ -0,0 +1,35 @@
|
||||
#include "script_component.hpp"
|
||||
/*
|
||||
* Author: LinkIsGrim
|
||||
* Adds a factor to player sway calculation
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Type of factor, "baseline" or "multiplier" <STRING>
|
||||
* 1: Factor function, must return number <CODE>
|
||||
* 2: Factor ID, unique to type <STRING>
|
||||
*
|
||||
* Return Value:
|
||||
* Factor added <BOOLEAN>
|
||||
*
|
||||
* Example:
|
||||
* ["baseline", {1}, "ace_common"] call ace_common_fnc_addSwayFactor
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
params ["_type", "_code", "_id"];
|
||||
|
||||
_type = toLower _type;
|
||||
|
||||
if !(_type in ["baseline", "multiplier"]) exitWith { ERROR_2("%1-%2 type unsupported",_type,_id); false };
|
||||
|
||||
if !((call _code) isEqualType 0) exitWith { ERROR_2("%1-%2 bad return type",_type,_id); false };
|
||||
|
||||
[missionNamespace, format ["ACE_setCustomAimCoef_%1", _type], _id, _code] call FUNC(arithmeticSetSource);
|
||||
|
||||
if (_type isEqualTo "baseline") then {
|
||||
GVAR(swayFactorsBaseline) pushBackUnique [_id];
|
||||
} else {
|
||||
GVAR(swayFactorsMultiplier) pushBackUnique [_id];
|
||||
};
|
||||
|
||||
true
|
30
addons/common/functions/fnc_swayLoop.sqf
Normal file
30
addons/common/functions/fnc_swayLoop.sqf
Normal file
@ -0,0 +1,30 @@
|
||||
#include "script_component.hpp"
|
||||
/*
|
||||
* Author: LinkIsGrim
|
||||
* Calculates and applies final sway coefficient from sway factors
|
||||
*
|
||||
* Arguments:
|
||||
* None
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* call ace_common_fnc_swayLoop
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
private _baseline = 1;
|
||||
if (GVAR(swayFactorsBaseline) isNotEqualTo []) then {
|
||||
_baseline = 1 max ([missionNamespace, "ACE_setCustomAimCoef_baseline", "max"] call EFUNC(common,arithmeticGetResult));
|
||||
};
|
||||
|
||||
private _multiplier = 1;
|
||||
if (GVAR(swayFactorsMultiplier) isNotEqualTo []) then {
|
||||
_multiplier = [missionNamespace, "ACE_setCustomAimCoef_multiplier", "product"] call EFUNC(common,arithmeticGetResult);
|
||||
};
|
||||
|
||||
ACE_player setCustomAimCoef (_baseline * _multiplier);
|
||||
|
||||
[FUNC(swayLoop), [], 1] call CBA_fnc_waitAndExecute
|
@ -5,9 +5,15 @@
|
||||
|
||||
if (!hasInterface) exitWith {};
|
||||
|
||||
[missionNamespace, "ACE_setCustomAimCoef", QUOTE(ADDON), {
|
||||
(linearConversion [0, 1, GET_PAIN_PERCEIVED(ACE_player), 1, 5, true]) + (ACE_player getVariable [QEGVAR(medical_engine,aimFracture), 0])
|
||||
}] call EFUNC(common,arithmeticSetSource);
|
||||
// Fractures affect base sway, pain makes it worse
|
||||
["baseline", {
|
||||
ACE_player getVariable [QEGVAR(medical_engine,aimFracture), 0]
|
||||
}, QUOTE(ADDON)] call EFUNC(common,addSwayFactor);
|
||||
|
||||
// Max pain = 5x sway
|
||||
["multiplier", {
|
||||
1 + (GET_PAIN_PERCEIVED(ACE_player) * 4)
|
||||
}, QUOTE(ADDON)] call EFUNC(common,addSwayFactor);
|
||||
|
||||
#ifdef DEBUG_MODE_FULL
|
||||
call compile preprocessFileLineNumbers QPATHTOF(dev\reportSettings.sqf);
|
||||
|
Loading…
Reference in New Issue
Block a user