diff --git a/TO_MERGE/agm/GForces/clientInit.sqf b/TO_MERGE/agm/GForces/clientInit.sqf deleted file mode 100644 index 5b10456164..0000000000 --- a/TO_MERGE/agm/GForces/clientInit.sqf +++ /dev/null @@ -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; - }; -}; diff --git a/TO_MERGE/agm/GForces/config.cpp b/TO_MERGE/agm/GForces/config.cpp deleted file mode 100644 index b5fe1e12c5..0000000000 --- a/TO_MERGE/agm/GForces/config.cpp +++ /dev/null @@ -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; - }; -}; diff --git a/addons/gforces/$PBOPREFIX$ b/addons/gforces/$PBOPREFIX$ new file mode 100644 index 0000000000..215e681d94 --- /dev/null +++ b/addons/gforces/$PBOPREFIX$ @@ -0,0 +1 @@ +z\ace\addons\hearing \ No newline at end of file diff --git a/addons/gforces/CfgEventHandlers.hpp b/addons/gforces/CfgEventHandlers.hpp new file mode 100644 index 0000000000..eefe61652b --- /dev/null +++ b/addons/gforces/CfgEventHandlers.hpp @@ -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) ); + }; +}; diff --git a/addons/gforces/XEH_postInit.sqf b/addons/gforces/XEH_postInit.sqf new file mode 100644 index 0000000000..c56c83e8e2 --- /dev/null +++ b/addons/gforces/XEH_postInit.sqf @@ -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(updateGForces), 0, []] call CBA_fnc_addPerFrameHandler; diff --git a/addons/gforces/XEH_preInit.sqf b/addons/gforces/XEH_preInit.sqf new file mode 100644 index 0000000000..886c1aec21 --- /dev/null +++ b/addons/gforces/XEH_preInit.sqf @@ -0,0 +1,6 @@ +#include "script_component.hpp" + +PREP(updateGForces); + +GVAR(GForces) = []; +GVAR(GForces_Index) = 0; diff --git a/addons/gforces/config.cpp b/addons/gforces/config.cpp new file mode 100644 index 0000000000..0e1be82d83 --- /dev/null +++ b/addons/gforces/config.cpp @@ -0,0 +1,52 @@ +#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" + +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; + }; +}; diff --git a/addons/gforces/functions/fnc_updateGForces.sqf b/addons/gforces/functions/fnc_updateGForces.sqf new file mode 100644 index 0000000000..8f0b0fc8b6 --- /dev/null +++ b/addons/gforces/functions/fnc_updateGForces.sqf @@ -0,0 +1,76 @@ +// 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: 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 +*/ + +_average = 0; +if (count GVAR(GForces) > 0) then { + _sum = 0; + { + _sum = _sum + _x; + } forEach GVAR(GForces); + _average = _sum / (count GVAR(GForces)); +}; + +_downTolerance = ACE_player getVariable ["ACE_GForceCoef", + getNumber (configFile >> "CfgVehicles" >> (typeOf ACE_player) >> "ACE_GForceCoef")]; +_upTolerance = _downTolerance * getNumber (configFile >> "CfgWeapons" >> (uniform ACE_player) >> "ACE_GForceCoef"); + +["GForces", [_average, _upTolerance], {format ["_g _avgG _avgG*_upTol: %1, %2, %3", _currentGForce, _this select 0, (_this select 0) * (_this select 1)]}] call EFUNC(common,log); + +// @todo: Sort the interaction with medical +if (((_average * _upTolerance) > MAXVIRTUALG) and {isClass (configFile >> "CfgPatches" >> "ACE_Medical") and {!(ACE_player getVariable ["ACE_isUnconscious", false])}}) then { + [ACE_player, (10 + floor(random 5))] call EFUNC(medical,knockOut); +}; + +if ((abs _average > 2) and !(ACE_player getVariable ["ACE_isUnconscious", false])) then { + if (_average > 0) then { + _strength = 1.2 - (((_average - 2) * _upTolerance) / (MAXVIRTUALG - 2)); + GVAR(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)); + GVAR(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 { + 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 INTERVAL; diff --git a/addons/gforces/functions/script_component.hpp b/addons/gforces/functions/script_component.hpp new file mode 100644 index 0000000000..4d0ee63e05 --- /dev/null +++ b/addons/gforces/functions/script_component.hpp @@ -0,0 +1 @@ +#include "\z\ace\addons\gforces\script_component.hpp" \ No newline at end of file diff --git a/addons/gforces/script_component.hpp b/addons/gforces/script_component.hpp new file mode 100644 index 0000000000..784ab79a19 --- /dev/null +++ b/addons/gforces/script_component.hpp @@ -0,0 +1,16 @@ +#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.4