Skip to content

Commit

Permalink
Merge pull request #1775 from SzwedzikPL/hearing_headgear
Browse files Browse the repository at this point in the history
Headgear influence on hearing
  • Loading branch information
nicolasbadano committed Jul 1, 2015
2 parents 319e50a + 6b4eeed commit 6cfaba0
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 8 deletions.
35 changes: 35 additions & 0 deletions addons/hearing/CfgWeapons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,39 @@ class CfgWeapons {
mass = 1;
};
};

class H_HelmetB;
class H_HelmetCrew_B: H_HelmetB {
GVAR(protection) = 1;
GVAR(lowerVolume) = 0.80;
};
class H_HelmetCrew_0: H_HelmetCrew_B {};
class H_HelmetCrew_I: H_HelmetCrew_B {};

class H_CrewHelmetHeli_B: H_HelmetB {
GVAR(protection) = 0.75;
GVAR(lowerVolume) = 0.70;
};
class H_CrewHelmetHeli_O: H_CrewHelmetHeli_B {};
class H_CrewHelmetHeli_I: H_CrewHelmetHeli_B {};

class H_PilotHelmetHeli_B: H_HelmetB {
GVAR(protection) = 0.75;
GVAR(lowerVolume) = 0.70;
};
class H_PilotHelmetHeli_O: H_PilotHelmetHeli_B {};
class H_PilotHelmetHeli_I: H_PilotHelmetHeli_B {};

class H_PilotHelmetFighter_B: H_HelmetB {
GVAR(protection) = 1;
GVAR(lowerVolume) = 0.80;
};
class H_PilotHelmetFighter_O: H_PilotHelmetFighter_B {};
class H_PilotHelmetFighter_I: H_PilotHelmetFighter_B {};

class H_Cap_headphones: H_HelmetB {
GVAR(protection) = 0.5;
GVAR(lowerVolume) = 0.60;
};
class H_Cap_marshal: H_Cap_headphones {};
};
2 changes: 1 addition & 1 deletion addons/hearing/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class CfgPatches {
units[] = {};
weapons[] = {"ACE_EarPlugs"};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_interaction"};
requiredAddons[] = {"ace_interaction", "A3_Characters_F", "A3_Characters_F_Kart"};
author[] = {"KoffeinFlummi", "esteldunedain", "HopeJ", "commy2", "Rocko", "Rommel", "Ruthberg"};
authorUrl = "https://github.com/KoffeinFlummi/";
VERSION_CONFIG;
Expand Down
21 changes: 15 additions & 6 deletions addons/hearing/functions/fnc_earRinging.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ if (_unit getVariable ["ACE_hasEarPlugsin", false]) then {
_strength = _strength / 4;
};

//headgear hearing protection
if(headgear _unit != "") then {
private ["_protection"];
_protection = (getNumber (configFile >> "CfgWeapons" >> (headgear _unit) >> QGVAR(protection))) min 1;
if(_protection > 0) then {
_strength = _strength * (1 - _protection);
};
};

_unit setVariable [QGVAR(dv), (_unit getVariable [QGVAR(dv), 0]) + _strength];

if (GVAR(earRingingPFH) != -1) exitWith {};
Expand All @@ -35,7 +44,7 @@ GVAR(earRingingPFH) = [{
EXPLODE_1_PVT(_this select 0,_unit);
private ["_prior"];
_prior = (_unit getvariable [QGVAR(dv), 0]) min 20;

if (!alive _unit || _prior <= 0) exitWith {
_unit setVariable [QGVAR(dv), 0];
_unit setVariable [QGVAR(prior), 0];
Expand All @@ -47,7 +56,7 @@ GVAR(earRingingPFH) = [{
GVAR(earRingingPFH) = -1;
[_this select 1] call cba_fnc_removePerFrameHandler;
};

if (((_unit getvariable [QGVAR(dv), 0]) - (_unit getvariable [QGVAR(prior), 0])) > 2) then {
if (ACE_time > GVAR(time3)) then {
GVAR(beep2) = false;
Expand All @@ -58,16 +67,16 @@ GVAR(earRingingPFH) = [{
GVAR(time3) = ACE_time + 5;
};
};

_unit setvariable [QGVAR(prior), _prior];
GVAR(volume) = (1 - (_prior / 20)) max 0;

if (_prior > 19.75) then {
_unit setvariable [QGVAR(deaf), true];
} else {
_unit setvariable [QGVAR(deaf), false];
};

if ((_unit getvariable [QGVAR(deaf), false]) && {ACE_time > GVAR(time4)}) then {
playSound "ACE_Combat_Deafness";
GVAR(beep2) = true;
Expand All @@ -77,7 +86,7 @@ GVAR(earRingingPFH) = [{

// Hearing takes longer to return to normal after it hits rock bottom
_unit setvariable [QGVAR(dv), _prior - (0.5 * (GVAR(volume) max 0.1))];

if (_prior > 10) then {
//check if the ringing is already being played
if (ACE_time > GVAR(time2)) then {
Expand Down
9 changes: 9 additions & 0 deletions addons/hearing/functions/fnc_updateVolume.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ if ([ACE_player] call FUNC(hasEarPlugsIn)) then {
_volume = _volume min GVAR(EarplugsVolume);
};

// Headgear can reduce hearing
if(headgear ACE_player != "") then {
private ["_lowerVolume"];
_lowerVolume = (getNumber (configFile >> "CfgWeapons" >> (headgear ACE_player) >> QGVAR(lowerVolume))) min 1;
if(_lowerVolume > 0) then {
_volume = _volume min (1 - _lowerVolume);
};
};

// Reduce volume if player is unconscious
if (ACE_player getVariable ["ACE_isUnconscious", false]) then {
_volume = _volume min GVAR(UnconsciousnessVolume);
Expand Down
2 changes: 2 additions & 0 deletions documentation/development/ace3-config-entries.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ ace_barrelLength
ace_laserpointer
ace_nextmodeclass
ace_modedescription
ace_hearing_protection
ace_hearing_lowerVolume
```


Expand Down
5 changes: 4 additions & 1 deletion documentation/feature/hearing.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ parent: wiki
### 1.1 Hearing damage simulation
Introduces hearing damage caused by nearby explosions and large-caliber weapons.

### 1.2 Earplugs
### 1.2 Earplugs
Adds earplugs to mitigate that effect. Soldiers with high caliber weapons or
missile launchers will be equipped with those, but remember to put them in.

### 1.3 Helmets
Some types of helmets can mitigate hearing damage also (ie. crewman helmet, pilot helmet etc.).

## 2. Usage

### 2.1 Equipping earplugs
Expand Down

0 comments on commit 6cfaba0

Please sign in to comment.