ACE3/addons/gforces/functions/fnc_pfhUpdateGForces.sqf

92 lines
3.2 KiB
Plaintext
Raw Normal View History

2015-01-17 02:01:41 +00:00
// by KoffeinFlummi and CAA-Picard
#include "script_component.hpp"
EXPLODE_2_PVT(_this,_params,_pfhId);
_interval = 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 {};
2015-01-17 02:01:41 +00:00
GVAR(lastUpdateTime) = 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;
// Cap maximum G's to +- 10 to avoid g-effects when the update is low fps.
_currentGForce = (_currentGForce max -10) min 10;
GVAR(GForces) set [GVAR(GForces_Index), _currentGForce];
GVAR(GForces_Index) = (GVAR(GForces_Index) + 1) % round (AVERAGEDURATION / INTERVAL);
GVAR(oldVel) = _newVel;
/* Source: https://github.com/KoffeinFlummi/AGM/issues/1774#issuecomment-70341573
2015-01-17 02:01:41 +00:00
*
* For untrained people without g-suits:
* GLOC: 5G for 6 s
* RedOut: 2.5G for 6 s
*
* For trained jet pilots without g-suits:
* GLOC: 9G for 6 s
* RedOut: 4.5G
*
* For trained jet pilots with g-suits:
* GLOC: 10.5G for 6 s
* RedOut: 4.5G
*
* Effects and camera shake start 30% the limit value, and build gradually
2015-01-17 02:01:41 +00:00
*/
_average = 0;
if (count GVAR(GForces) > 0) then {
_sum = 0;
{
_sum = _sum + _x;
} forEach GVAR(GForces);
_average = _sum / (count GVAR(GForces));
2015-01-17 02:01:41 +00:00
};
_classCoef = ACE_player getVariable ["ACE_GForceCoef",
getNumber (configFile >> "CfgVehicles" >> (typeOf ACE_player) >> "AGM_GForceCoef")];
_suitCoef = getNumber (configFile >> "CfgWeapons" >> (uniform ACE_player) >> "AGM_GForceCoef");
2015-01-17 02:01:41 +00:00
_gBlackOut = MAXVIRTUALG / _classCoef + MAXVIRTUALG / _suitCoef - MAXVIRTUALG;
_gRedOut = MINVIRTUALG / _classCoef;
["GForces", [], {format ["_g _gBO _coef: %1, %2, %3", _average, _gBlackOut, 2 * ((1.0 - ((_average - 0.30 * _gBlackOut) / (0.70 * _gBlackOut)) ^ 2) max 0) ]}] call EFUNC(common,log);
2015-01-17 02:01:41 +00:00
// @todo: Sort the interaction with medical
if ((_average > _gBlackOut) and {isClass (configFile >> "CfgPatches" >> "ACE_Medical") and {!(ACE_player getVariable ["ACE_isUnconscious", false])}}) then {
[ACE_player, (10 + floor(random 5))] call EFUNC(medical,knockOut);
2015-01-17 02:01:41 +00:00
};
GVAR(GForces_CC) ppEffectAdjust [1,1,0,[0,0,0,1],[0,0,0,0],[1,1,1,1],[10,10,0,0,0,0.1,0.5]];
if !(ACE_player getVariable ["ACE_isUnconscious", false]) then {
if (_average > 0.30 * _gBlackOut) then {
_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 {
if (_average < -0.30 * _gRedOut) then {
_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];
};
};
2015-01-17 02:01:41 +00:00
};
GVAR(GForces_CC) ppEffectCommit INTERVAL;