Merge pull request #47 from KoffeinFlummi/agmGForcesPort

Port: AGM_GForces
This commit is contained in:
Nicolás Badano 2015-01-17 01:15:52 -03:00
commit 7fd578326f
12 changed files with 192 additions and 150 deletions

View File

@ -1,94 +0,0 @@
#define AVERAGEDURATION 6
#define INTERVAL 0.25
#define MAXVIRTUALG 5.4
if !(hasInterface) exitWith {};
AGM_GForces = [];
AGM_GForces_Index = 0;
AGM_GForces_CC = ppEffectCreate ["ColorCorrections", 4215];
AGM_GForces_CC ppEffectEnable true;
AGM_GForces_CC ppEffectForceInNVG true;
AGM_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]];
AGM_GForces_CC ppEffectCommit 0.4;
0 spawn {
while {True} do {
_player = AGM_player;
if !((vehicle _player isKindOf "Air") or ((getPos _player select 2) > 5)) then {
AGM_GForces = [];
AGM_GForces_Index = 0;
waitUntil {sleep 5; (vehicle _player isKindOf "Air") or ((getPos _player select 2) > 5)};
};
_oldVel = velocity (vehicle _player);
sleep INTERVAL;
_newVel = velocity (vehicle _player);
_accel = ((_newVel vectorDiff _oldVel) vectorMultiply (1 / INTERVAL)) vectorAdd [0, 0, 9.8];
AGM_GForce_Current = (_accel vectorDotProduct vectorUp (vehicle _player)) / 9.8;
// Cap maximum G's to +- 10 to avoid g-effects when the update is low fps.
AGM_GForce_Current = (AGM_GForce_Current max -10) min 10;
AGM_GForces set [AGM_GForces_Index, AGM_GForce_Current];
AGM_GForces_Index = (AGM_GForces_Index + 1) % round (AVERAGEDURATION / INTERVAL);
};
};
/*
* source: http://en.wikipedia.org/wiki/G-LOC
* untrained persons without gsuit will fall unconscious between 4 and 6G
* pilots in gsuits will sustain up to 9G
* a person is for average 12 seconds unconscious
* after being unconscious, a person is unable to do simple tasks for average 15 seconds
*
* _upTolerance converts the effective 9G of a pilot to virtual 5.4G (= 0.8*0.75*9G)
* pilots with gsuit will get unconscious at an _average of 9G
* normal men without gsuit will get unconscious at an _average of 5.4G
*/
0 spawn {
while {True} do {
sleep INTERVAL;
_player = AGM_player;
_average = 0;
if (count AGM_GForces > 0) then {
_sum = 0;
{
_sum = _sum + _x;
} forEach AGM_GForces;
_average = _sum / (count AGM_GForces);
};
_downTolerance = _player getVariable ["AGM_GForceCoef",
getNumber (configFile >> "CfgVehicles" >> (typeOf _player) >> "AGM_GForceCoef")];
_upTolerance = _downTolerance * getNumber (configFile >> "CfgWeapons" >> (uniform _player) >> "AGM_GForceCoef");
["GForces", [_average, _upTolerance], {format ["_g _avgG _avgG*_upTol: %1, %2, %3", AGM_GForce_Current, _this select 0, (_this select 0) * (_this select 1)]}] call AGM_Debug_fnc_log;
if (((_average * _upTolerance) > MAXVIRTUALG) and {isClass (configFile >> "CfgPatches" >> "AGM_Medical") and {!(_player getVariable ["AGM_isUnconscious", false])}}) then {
[_player, (10 + floor(random 5))] call AGM_Medical_fnc_knockOut;
};
if ((abs _average > 2) and !(_player getVariable ["AGM_isUnconscious", false])) then {
if (_average > 0) then {
_strength = 1.2 - (((_average - 2) * _upTolerance) / (MAXVIRTUALG - 2));
AGM_GForces_CC ppEffectAdjust [1,1,0,[0,0,0,1],[0,0,0,0],[1,1,1,1],[_strength,_strength,0,0,0,0.1,0.5]];
addCamShake [((abs _average) - 2) / 3, 1, 15];
} else {
_strength = 1.2 - ((((-1 * _average) - 2) * _downTolerance) / (MAXVIRTUALG - 2));
AGM_GForces_CC ppEffectAdjust [1,1,0,[1,0.2,0.2,1],[0,0,0,0],[1,1,1,1],[_strength,_strength,0,0,0,0.1,0.5]];
addCamShake [((abs _average) - 2) / 5, 1, 15];
};
} else {
AGM_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]];
};
AGM_GForces_CC ppEffectCommit INTERVAL;
};
};

View File

@ -1,56 +0,0 @@
class CfgPatches {
class AGM_GForces {
units[] = {};
weapons[] = {};
requiredVersion = 0.60;
requiredAddons[] = {AGM_Core};
version = "0.95";
versionStr = "0.95";
versionAr[] = {0,95,0};
author[] = {"KoffeinFlummi"};
authorUrl = "https://github.com/KoffeinFlummi/";
};
};
class Extended_PostInit_EventHandlers {
class AGM_GForces {
clientInit = "call compile preprocessFileLineNumbers '\AGM_GForces\clientInit.sqf'";
};
};
class CfgWeapons {
class ItemCore;
class Uniform_Base: ItemCore {
AGM_GForceCoef = 1;
};
class U_B_PilotCoveralls: Uniform_Base {
AGM_GForceCoef = 0.8;
};
class U_I_pilotCoveralls: Uniform_Base {
AGM_GForceCoef = 0.8;
};
class U_O_PilotCoveralls: Uniform_Base {
AGM_GForceCoef = 0.8;
};
};
class CfgVehicles {
class Man;
class CAManBase: Man {
AGM_GForceCoef = 1;
};
class B_Soldier_05_f;
class B_Pilot_F: B_Soldier_05_f {
AGM_GForceCoef = 0.75;
};
class I_Soldier_04_F;
class I_pilot_F: I_Soldier_04_F {
AGM_GForceCoef = 0.75;
};
class O_helipilot_F;
class O_Pilot_F: O_helipilot_F {
AGM_GForceCoef = 0.75;
};
};

View File

@ -0,0 +1 @@
z\ace\addons\hearing

View File

@ -0,0 +1,12 @@
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit) );
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
clientInit = QUOTE( call COMPILE_FILE(XEH_postInit) );
};
};

View File

@ -0,0 +1,19 @@
class CfgVehicles {
class Man;
class CAManBase: Man {
AGM_GForceCoef = 1;
};
class B_Soldier_05_f;
class B_Pilot_F: B_Soldier_05_f {
AGM_GForceCoef = 0.55;
};
class I_Soldier_04_F;
class I_pilot_F: I_Soldier_04_F {
AGM_GForceCoef = 0.55;
};
class O_helipilot_F;
class O_Pilot_F: O_helipilot_F {
AGM_GForceCoef = 0.55;
};
};

View File

@ -0,0 +1,16 @@
class CfgWeapons {
class ItemCore;
class Uniform_Base: ItemCore {
AGM_GForceCoef = 1;
};
class U_B_PilotCoveralls: Uniform_Base {
AGM_GForceCoef = 0.8;
};
class U_I_pilotCoveralls: Uniform_Base {
AGM_GForceCoef = 0.8;
};
class U_O_PilotCoveralls: Uniform_Base {
AGM_GForceCoef = 0.8;
};
};

View File

@ -0,0 +1,15 @@
#include "script_component.hpp"
if !(hasInterface) exitWith {};
// Setup ppEffect
GVAR(GForces_CC) = ppEffectCreate ["ColorCorrections", 4215];
GVAR(GForces_CC) ppEffectEnable true;
GVAR(GForces_CC) ppEffectForceInNVG true;
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]];
GVAR(GForces_CC) ppEffectCommit 0.4;
GVAR(lastUpdateTime) = 0;
GVAR(oldVel) = [0,0,0];
[FUNC(pfhUpdateGForces), 0, []] call CBA_fnc_addPerFrameHandler;

View File

@ -0,0 +1,6 @@
#include "script_component.hpp"
PREP(pfhUpdateGForces);
GVAR(GForces) = [];
GVAR(GForces_Index) = 0;

19
addons/gforces/config.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "script_component.hpp"
class CfgPatches {
class ADDON {
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_common"};
author[] = {"KoffeinFlummi", "CAA-Picard"};
authorUrl = "https://github.com/KoffeinFlummi/";
VERSION_CONFIG;
};
};
#include "CfgEventHandlers.hpp"
#include "CfgWeapons.hpp"
#include "CfgVehicles.hpp"

View File

@ -0,0 +1,86 @@
// 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 {};
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
*
* 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
*/
_average = 0;
if (count GVAR(GForces) > 0) then {
_sum = 0;
{
_sum = _sum + _x;
} forEach GVAR(GForces);
_average = _sum / (count GVAR(GForces));
};
_classCoef = ACE_player getVariable ["ACE_GForceCoef",
getNumber (configFile >> "CfgVehicles" >> (typeOf ACE_player) >> "AGM_GForceCoef")];
_suitCoef = getNumber (configFile >> "CfgWeapons" >> (uniform ACE_player) >> "AGM_GForceCoef");
_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);
// @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);
};
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];
};
};
};
GVAR(GForces_CC) ppEffectCommit INTERVAL;

View File

@ -0,0 +1 @@
#include "\z\ace\addons\gforces\script_component.hpp"

View File

@ -0,0 +1,17 @@
#define COMPONENT gforces
#include "\z\ace\Addons\main\script_mod.hpp"
#ifdef DEBUG_ENABLED_GFORCES
#define DEBUG_MODE_FULL
#endif
#ifdef DEBUG_SETTINGS_GFORCES
#define DEBUG_SETTINGS DEBUG_SETTINGS_GFORCES
#endif
#include "\z\ace\Addons\main\script_macros.hpp"
#define AVERAGEDURATION 6
#define INTERVAL 0.20
#define MAXVIRTUALG 5.0
#define MINVIRTUALG 2.5