2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-02-08 22:58:41 +00:00
|
|
|
/*
|
2015-03-24 04:18:00 +00:00
|
|
|
* Author: KoffeinFlummi and esteldunedain
|
2015-02-08 22:58:41 +00:00
|
|
|
* Calculates average g-forces and triggers g-effects
|
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Arguments:
|
2015-02-08 22:58:41 +00:00
|
|
|
* 0: Arguments <ARRAY>
|
|
|
|
* 1: pfh_id <NUMBER>
|
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Return Value:
|
2015-02-08 22:58:41 +00:00
|
|
|
* None
|
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Example:
|
|
|
|
* [[args], 5] call ace_gforces_fnc_pfhUpdateGForces
|
|
|
|
*
|
2015-02-08 22:58:41 +00:00
|
|
|
* Public: No
|
|
|
|
*/
|
2015-01-17 02:01:41 +00:00
|
|
|
|
2016-01-19 03:18:01 +00:00
|
|
|
// Update the g-forces at constant mission time intervals (taking accTime into account)
|
2016-03-02 10:01:39 +00:00
|
|
|
if ((CBA_missionTime - GVAR(lastUpdateTime)) < INTERVAL) exitWith {};
|
|
|
|
GVAR(lastUpdateTime) = CBA_missionTime;
|
2015-01-17 02:01:41 +00:00
|
|
|
|
2017-05-12 18:12:17 +00:00
|
|
|
if (GVAR(playerIsVirtual) || {!alive ACE_player}) exitWith {};
|
2015-01-17 02:01:41 +00:00
|
|
|
|
2016-04-19 17:59:41 +00:00
|
|
|
BEGIN_COUNTER(everyInterval);
|
|
|
|
|
2016-01-19 03:18:01 +00:00
|
|
|
private _newVel = velocity (vehicle ACE_player);
|
|
|
|
private _accel = ((_newVel vectorDiff GVAR(oldVel)) vectorMultiply (1 / INTERVAL)) vectorAdd [0, 0, 9.8];
|
2015-01-17 02:01:41 +00:00
|
|
|
// Cap maximum G's to +- 10 to avoid g-effects when the update is low fps.
|
2016-01-19 03:18:01 +00:00
|
|
|
private _currentGForce = (((_accel vectorDotProduct vectorUp (vehicle ACE_player)) / 9.8) max -10) min 10;
|
2015-01-17 02:01:41 +00:00
|
|
|
|
2020-06-13 00:06:03 +00:00
|
|
|
GVAR(GForces) set [GVAR(GForces_Index), _currentGForce * GVAR(coef)];
|
2017-03-09 22:49:50 +00:00
|
|
|
GVAR(GForces_Index) = (GVAR(GForces_Index) + 1) % 30; // 30 = round (AVERAGEDURATION / INTERVAL);
|
2015-01-17 02:01:41 +00:00
|
|
|
GVAR(oldVel) = _newVel;
|
|
|
|
|
2015-01-17 03:59:45 +00:00
|
|
|
/* Source: https://github.com/KoffeinFlummi/AGM/issues/1774#issuecomment-70341573
|
2015-01-17 02:01:41 +00:00
|
|
|
*
|
2015-01-17 03:59:45 +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
|
|
|
*/
|
|
|
|
|
2016-01-19 03:18:01 +00:00
|
|
|
private _average = 0;
|
|
|
|
private _count = {
|
|
|
|
_average = _average + _x;
|
|
|
|
true
|
|
|
|
} count GVAR(GForces);
|
|
|
|
|
|
|
|
if (_count > 0) then {
|
|
|
|
_average = _average / _count;
|
2015-01-17 02:01:41 +00:00
|
|
|
};
|
|
|
|
|
2016-01-19 03:18:01 +00:00
|
|
|
private _classCoef = (ACE_player getVariable ["ACE_GForceCoef",
|
2022-01-30 17:56:20 +00:00
|
|
|
getNumber ((configOf ACE_player) >> "ACE_GForceCoef")]) max 0.001;
|
2016-01-19 03:18:01 +00:00
|
|
|
private _suitCoef = if ((uniform ACE_player) != "") then {
|
|
|
|
(getNumber (configFile >> "CfgWeapons" >> (uniform ACE_player) >> "ACE_GForceCoef")) max 0.001
|
2015-02-01 19:09:17 +00:00
|
|
|
} else {
|
|
|
|
1
|
|
|
|
};
|
|
|
|
|
2016-01-19 03:18:01 +00:00
|
|
|
private _gBlackOut = MAXVIRTUALG / _classCoef + MAXVIRTUALG / _suitCoef - MAXVIRTUALG;
|
2015-01-17 02:01:41 +00:00
|
|
|
|
2016-01-19 03:18:01 +00:00
|
|
|
// Unconsciousness
|
2022-01-30 17:56:20 +00:00
|
|
|
if ((_average > _gBlackOut) && {["ACE_Medical"] call EFUNC(common,isModLoaded) && {!(ACE_player getVariable ["ACE_isUnconscious", false])}}) then {
|
2017-06-05 16:42:46 +00:00
|
|
|
[ACE_player, true, (10 + floor(random 5)), true] call EFUNC(medical,setUnconscious);
|
2015-01-17 02:01:41 +00:00
|
|
|
};
|
|
|
|
|
2015-01-17 03:59:45 +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 {
|
2016-01-19 03:18:01 +00:00
|
|
|
private _strength = ((_average - 0.30 * _gBlackOut) / (0.70 * _gBlackOut)) max 0;
|
2019-03-11 02:42:08 +00:00
|
|
|
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]];
|
2015-01-17 03:59:45 +00:00
|
|
|
addCamShake [_strength, 1, 15];
|
|
|
|
} else {
|
2016-01-19 03:18:01 +00:00
|
|
|
private _gRedOut = MINVIRTUALG / _classCoef;
|
|
|
|
|
2015-01-17 03:59:45 +00:00
|
|
|
if (_average < -0.30 * _gRedOut) then {
|
2016-01-19 03:18:01 +00:00
|
|
|
private _strength = ((abs _average - 0.30 * _gRedOut) / (0.70 * _gRedOut)) max 0;
|
2019-03-11 02:42:08 +00:00
|
|
|
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]];
|
2015-01-17 03:59:45 +00:00
|
|
|
addCamShake [_strength / 1.5, 1, 15];
|
|
|
|
};
|
|
|
|
};
|
2015-01-17 02:01:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GVAR(GForces_CC) ppEffectCommit INTERVAL;
|
2016-04-19 17:59:41 +00:00
|
|
|
|
|
|
|
END_COUNTER(everyInterval);
|