mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Merge pull request #3183 from acemod/codeCleanupGforces
Code cleanup of Gforces module V2
This commit is contained in:
commit
f5d71ca03c
@ -12,4 +12,4 @@ GVAR(GForces_CC) ppEffectCommit 0.4;
|
||||
GVAR(lastUpdateTime) = 0;
|
||||
GVAR(oldVel) = [0,0,0];
|
||||
|
||||
[FUNC(pfhUpdateGForces), 0, []] call CBA_fnc_addPerFrameHandler;
|
||||
[DFUNC(pfhUpdateGForces), 0, []] call CBA_fnc_addPerFrameHandler;
|
||||
|
@ -13,34 +13,18 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_interval", "_player", "_newVel", "_accel", "_currentGForce", "_average", "_sum", "_classCoef", "_suitCoef", "_gBlackOut", "_gRedOut", "_g", "_gBO", "_coef", "_strength"];
|
||||
|
||||
EXPLODE_2_PVT(_this,_params,_pfhId);
|
||||
|
||||
_interval = ACE_time - GVAR(lastUpdateTime);
|
||||
|
||||
// Update the g-forces at constant game time intervals
|
||||
if (_interval < INTERVAL) exitWith {};
|
||||
|
||||
if (isNull ACE_player) exitWith {};
|
||||
|
||||
if !(alive ACE_player) exitWith {};
|
||||
|
||||
// Update the g-forces at constant mission time intervals (taking accTime into account)
|
||||
if ((ACE_time - GVAR(lastUpdateTime)) < INTERVAL) exitWith {};
|
||||
GVAR(lastUpdateTime) = ACE_time;
|
||||
|
||||
/*if !(vehicle ACE_player isKindOf "Air") exitWith {
|
||||
GVAR(GForces) = [];
|
||||
GVAR(GForces_Index) = 0;
|
||||
waitUntil {sleep 5; (vehicle _player isKindOf "Air") or ((getPos _player select 2) > 5)};
|
||||
};*/
|
||||
|
||||
_newVel = velocity (vehicle ACE_player);
|
||||
|
||||
_accel = ((_newVel vectorDiff GVAR(oldVel)) vectorMultiply (1 / INTERVAL)) vectorAdd [0, 0, 9.8];
|
||||
_currentGForce = (_accel vectorDotProduct vectorUp (vehicle ACE_player)) / 9.8;
|
||||
if (isNull ACE_player || !(alive ACE_player)) exitWith {};
|
||||
|
||||
private _newVel = velocity (vehicle ACE_player);
|
||||
private _accel = ((_newVel vectorDiff GVAR(oldVel)) vectorMultiply (1 / INTERVAL)) vectorAdd [0, 0, 9.8];
|
||||
// Cap maximum G's to +- 10 to avoid g-effects when the update is low fps.
|
||||
_currentGForce = (_currentGForce max -10) min 10;
|
||||
private _currentGForce = (((_accel vectorDotProduct vectorUp (vehicle ACE_player)) / 9.8) max -10) min 10;
|
||||
|
||||
GVAR(GForces) set [GVAR(GForces_Index), _currentGForce];
|
||||
GVAR(GForces_Index) = (GVAR(GForces_Index) + 1) % round (AVERAGEDURATION / INTERVAL);
|
||||
@ -63,31 +47,27 @@ GVAR(oldVel) = _newVel;
|
||||
* Effects and camera shake start 30% the limit value, and build gradually
|
||||
*/
|
||||
|
||||
_average = 0;
|
||||
if (count GVAR(GForces) > 0) then {
|
||||
_sum = 0;
|
||||
{
|
||||
_sum = _sum + _x;
|
||||
} forEach GVAR(GForces);
|
||||
_average = _sum / (count GVAR(GForces));
|
||||
private _average = 0;
|
||||
private _count = {
|
||||
_average = _average + _x;
|
||||
true
|
||||
} count GVAR(GForces);
|
||||
|
||||
if (_count > 0) then {
|
||||
_average = _average / _count;
|
||||
};
|
||||
|
||||
_classCoef = ACE_player getVariable ["ACE_GForceCoef",
|
||||
getNumber (configFile >> "CfgVehicles" >> (typeOf ACE_player) >> "ACE_GForceCoef")];
|
||||
_suitCoef = if ((uniform ACE_player) != "") then {
|
||||
getNumber (configFile >> "CfgWeapons" >> (uniform ACE_player) >> "ACE_GForceCoef")
|
||||
private _classCoef = (ACE_player getVariable ["ACE_GForceCoef",
|
||||
getNumber (configFile >> "CfgVehicles" >> (typeOf ACE_player) >> "ACE_GForceCoef")]) max 0.001;
|
||||
private _suitCoef = if ((uniform ACE_player) != "") then {
|
||||
(getNumber (configFile >> "CfgWeapons" >> (uniform ACE_player) >> "ACE_GForceCoef")) max 0.001
|
||||
} else {
|
||||
1
|
||||
};
|
||||
|
||||
//Fix "Error Zero divisor"
|
||||
if (_classCoef == 0) then {_classCoef = 0.001};
|
||||
if (_suitCoef == 0) then {_suitCoef = 0.001};
|
||||
private _gBlackOut = MAXVIRTUALG / _classCoef + MAXVIRTUALG / _suitCoef - MAXVIRTUALG;
|
||||
|
||||
_gBlackOut = MAXVIRTUALG / _classCoef + MAXVIRTUALG / _suitCoef - MAXVIRTUALG;
|
||||
_gRedOut = MINVIRTUALG / _classCoef;
|
||||
|
||||
// @todo: Sort the interaction with medical
|
||||
// Unconsciousness
|
||||
if ((_average > _gBlackOut) and {isClass (configFile >> "CfgPatches" >> "ACE_Medical") and {!(ACE_player getVariable ["ACE_isUnconscious", false])}}) then {
|
||||
[ACE_player, true, (10 + floor(random 5))] call EFUNC(medical,setUnconscious);
|
||||
};
|
||||
@ -96,12 +76,14 @@ GVAR(GForces_CC) ppEffectAdjust [1,1,0,[0,0,0,1],[0,0,0,0],[1,1,1,1],[10,10,0,0,
|
||||
|
||||
if !(ACE_player getVariable ["ACE_isUnconscious", false]) then {
|
||||
if (_average > 0.30 * _gBlackOut) then {
|
||||
_strength = ((_average - 0.30 * _gBlackOut) / (0.70 * _gBlackOut)) max 0;
|
||||
private _strength = ((_average - 0.30 * _gBlackOut) / (0.70 * _gBlackOut)) max 0;
|
||||
GVAR(GForces_CC) ppEffectAdjust [1,1,0,[0,0,0,1],[0,0,0,0],[1,1,1,1],[2*(1-_strength),2*(1-_strength),0,0,0,0.1,0.5]];
|
||||
addCamShake [_strength, 1, 15];
|
||||
} else {
|
||||
private _gRedOut = MINVIRTUALG / _classCoef;
|
||||
|
||||
if (_average < -0.30 * _gRedOut) then {
|
||||
_strength = ((abs _average - 0.30 * _gRedOut) / (0.70 * _gRedOut)) max 0;
|
||||
private _strength = ((abs _average - 0.30 * _gRedOut) / (0.70 * _gRedOut)) max 0;
|
||||
GVAR(GForces_CC) ppEffectAdjust [1,1,0,[1,0.2,0.2,1],[0,0,0,0],[1,1,1,1],[2*(1-_strength),2*(1-_strength),0,0,0,0.1,0.5]];
|
||||
addCamShake [_strength / 1.5, 1, 15];
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user