Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookoff - Improve ammo detonation sounds #5327

Merged
merged 25 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e3c5f78
initital commit
jokoho48 Jun 29, 2017
298924e
use Define for SOS
jokoho48 Jun 29, 2017
0b4e0b8
fix some issues that got introduced in 1.70
jokoho48 Jul 1, 2017
575b0a3
Prepare config for sounds
jokoho48 Jul 1, 2017
b24e3f1
add New Sounds
jokoho48 Jul 4, 2017
2c52150
add LAxemann to Author
jokoho48 Jul 4, 2017
50b225d
add Object Pooling
jokoho48 Jul 5, 2017
607aa68
fix small mistake
jokoho48 Jul 5, 2017
6f734e6
change pool clearing timing
jokoho48 Jul 5, 2017
61c56c3
change pool wait time
jokoho48 Jul 5, 2017
e5863a9
fix Cookoff sound cleanup
jokoho48 Jul 5, 2017
294f22d
Merge branch 'master' into ImproveCookoffSounds
jokoho48 Jul 22, 2017
0acbf75
Merge branch 'master' into ImproveCookoffSounds
jokoho48 Dec 6, 2017
ff7e60b
change to Jonpas Method
jokoho48 Dec 6, 2017
abe1cc3
improve sound Volume over Distance (asked by Bux)
jokoho48 Dec 9, 2017
6effc54
Merge branch 'master' into ImproveCookoffSounds
jokoho48 Dec 9, 2017
3852d10
improve a calculation
jokoho48 Dec 9, 2017
37a00c2
Merge branch 'master' into ImproveCookoffSounds
jokoho48 Mar 28, 2021
93e3e67
Merge branch 'master' into ImproveCookoffSounds
johnb432 Nov 5, 2023
ff585a7
Merge branch 'master' into ImproveCookoffSounds
johnb432 Jan 13, 2024
771219e
Use playSound3D locally
johnb432 Jan 13, 2024
3fa025a
Merge branch 'master' into ImproveCookoffSounds
johnb432 Feb 2, 2024
bc044fd
Make sounds configurable by 3rd party mods
johnb432 Feb 2, 2024
4bc2016
Added comments, used macros
johnb432 Feb 3, 2024
baa749e
Update CfgSounds.hpp
johnb432 Feb 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ Karneck <dschultz26@hotmail.com>
Kavinsky <nmunozfernandez@gmail.com>
Keithen <Keithen.Neu@gmail.com>
Kllrt <kllrtik@gmail.com>
LAxemann
KokaKolaA3
Krzyciu
legman <juicemelon@msn.com>
Expand Down
43 changes: 43 additions & 0 deletions addons/cookoff/CfgSounds.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#define SHOTSOUND(type,dist,N) \
class GVAR(TRIPLES(type,dist,N)) { \
name = QGVAR(TRIPLES(type,dist,N)); \
sound[] = {QPATHTOF(sounds\type\DOUBLES(dist,N).wss), 0.56, 1, 3000}; \
titles[] = {}; \
}

#define SHOTSOUNDCLASS(type,dist) \
SHOTSOUND(type,dist,1);\
SHOTSOUND(type,dist,2);\
SHOTSOUND(type,dist,3)

#define SHOTSOUNDCLASSTYPE(type) \
SHOTSOUNDCLASS(type,close);\
SHOTSOUNDCLASS(type,mid);\
SHOTSOUNDCLASS(type,far)

class CfgSounds {

SHOTSOUNDCLASSTYPE(shotbullet);
SHOTSOUNDCLASSTYPE(shotrocket);
SHOTSOUNDCLASSTYPE(shotshell);

johnb432 marked this conversation as resolved.
Show resolved Hide resolved
class GVAR(shotmissile_close_1): GVAR(shotrocket_close_1) {};
class GVAR(shotmissile_close_2): GVAR(shotrocket_close_2) {};
class GVAR(shotmissile_close_3): GVAR(shotrocket_close_3) {};
class GVAR(shotmissile_mid_1): GVAR(shotrocket_mid_1) {};
class GVAR(shotmissile_mid_2): GVAR(shotrocket_mid_2) {};
class GVAR(shotmissile_mid_3): GVAR(shotrocket_mid_3) {};
class GVAR(shotmissile_far_1): GVAR(shotrocket_far_1) {};
class GVAR(shotmissile_far_2): GVAR(shotrocket_far_2) {};
class GVAR(shotmissile_far_3): GVAR(shotrocket_far_3) {};

class GVAR(shotsubmunitions_close_1): GVAR(shotbullet_close_1) {};
class GVAR(shotsubmunitions_close_2): GVAR(shotbullet_close_2) {};
class GVAR(shotsubmunitions_close_3): GVAR(shotbullet_close_3) {};
class GVAR(shotsubmunitions_mid_1): GVAR(shotbullet_far_1) {};
class GVAR(shotsubmunitions_mid_2): GVAR(shotbullet_mid_2) {};
class GVAR(shotsubmunitions_mid_3): GVAR(shotbullet_mid_3) {};
class GVAR(shotsubmunitions_far_1): GVAR(shotbullet_far_1) {};
class GVAR(shotsubmunitions_far_2): GVAR(shotbullet_far_2) {};
class GVAR(shotsubmunitions_far_3): GVAR(shotbullet_far_3) {};
};
53 changes: 50 additions & 3 deletions addons/cookoff/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
// handle cleaning up effects when vehicle is deleted mid-cookoff
[QGVAR(addCleanupHandlers), {
params ["_vehicle"];

// Don't add a new EH if cookoff is run multiple times
if ((_vehicle getVariable [QGVAR(deletedEH), -1]) == -1) then {
private _deletedEH = _vehicle addEventHandler ["Deleted", {
params ["_vehicle"];

[QGVAR(cleanupEffects), [_vehicle]] call CBA_fnc_localEvent;
}];

_vehicle setVariable [QGVAR(deletedEH), _deletedEH];
};
}] call CBA_fnc_addEventHandler;
Expand Down Expand Up @@ -58,3 +58,50 @@
[FUNC(detonateAmmunition), [_vehicle, _mags, _total], _delay] call CBA_fnc_waitAndExecute;
};
}, nil, ["Man","StaticWeapon"]] call CBA_fnc_addClassEventHandler;

if (hasInterface) then {
GVAR(soundObjPool) = [];
[QFUNC(poolGetObject), {
private _pooledObject = GVAR(soundObjPool) param [0, [-999, objNull]];
_pooledObject params ["_time", "_obj"];
if (isNull _obj || _time >= time) then {
_obj = "#particlesource" createVehicleLocal [0, 0, 0];
} else {
GVAR(soundObjPool) deleteAt 0;
};
GVAR(soundObjPool) pushBack [time + 8, _obj];
_obj; // return
}] call CBA_fnc_compileFinal;

[QGVAR(playCookoffSound), {
params ["_obj", "_sound", "_maxDist"];
if (isNull _obj) exitWith {};
private _distance = _obj distance (positionCameraToWorld [0,0,0]);
if (_distance > _maxDist) exitWith {};

// Delay sound after Rule of SOS.
[{
params ["_obj", "_sound", "_maxDist"];
private _distance = _obj distance (positionCameraToWorld [0, 0, 0]); // update Value so that distance is correct to the current camera Position
private _sDistance = _distance + ((random 5) - 2.5);
private _disStep = [[["far", 1.5], ["mid", 1.3]] select (_sDistance < 952), ["close", 1]] select (_sDistance < 235);
_sound = format [QGVAR(%1_%2_%3), _sound, _disStep select 0, ceil (random 3)];
hintSilent _sound;
// fix for Vanilla Say3d Falloff
private _value = 1 - (_distance / _maxDist);
private _fakeValue = linearConversion ([[0, 0.7, _value, 1, 0.8], [0.7, 1, _value, 0.8, 0]] select (_value >= 0.7));
private _soundSource = call FUNC(poolGetObject);
_soundSource setPos (getPos _obj);
_soundSource say3D [_sound, (_distance / _fakeValue) * (_disStep select 1), 0.9 + (random 0.2)];
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
}, [_obj, _sound, _maxDist], _distance / SPEED_OF_SOUND] call CBA_fnc_waitAndExecute;
}] call CBA_fnc_addEventHandler;

[{
if (GVAR(soundObjPool) isEqualTo []) exitWith {};
private _element = GVAR(soundObjPool) param [0, [time, objNull]];
if (((_element select 0) + 120) < time) then {
GVAR(soundObjPool) deleteAt 0;
deleteVehicle (_element select 1);
};
}, 0.5] call CBA_fnc_addPerFrameHandler;
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
};
1 change: 1 addition & 0 deletions addons/cookoff/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ class CfgPatches {
#include "CfgAmmo.hpp"
#include "CfgCloudlets.hpp"
#include "CfgSFX.hpp"
#include "CfgSounds.hpp"
#include "CfgVehicles.hpp"
100 changes: 47 additions & 53 deletions addons/cookoff/functions/fnc_detonateAmmunition.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -32,90 +32,86 @@ private _magazineIndex = floor random(count _magazines);
private _magazine = _magazines select _magazineIndex;
_magazine params ["_magazineClassname", "_amountOfMagazines"];

if (_amountOfMagazines > 0) exitWith {
private _removed = _amountOfMagazines min floor(1 + random(6 / GVAR(ammoCookoffDuration)));

_amountOfMagazines = _amountOfMagazines - _removed;
if (_amountOfMagazines <= 0) then {
_magazines deleteAt _magazineIndex;
} else {
_magazine set [1, _amountOfMagazines]; // clear out the magazine
};
private _timeBetweenAmmoDetonation = (((random 10) / (sqrt _totalAmmo)) min MAX_TIME_BETWEEN_AMMO_DET) max 0.1;
TRACE_2("",_totalAmmo,_timeBetweenAmmoDetonation);
_totalAmmo = _totalAmmo - _removed;

private _ammo = getText (configFile >> "CfgMagazines" >> _magazineClassname >> "ammo");
private _ammoCfg = configFile >> "CfgAmmo" >> _ammo;
if (_amountOfMagazines < 0) exitWith {
ERROR_1("mag with no ammo - %1", _magazine);
};
private _removed = _amountOfMagazines min floor(1 + random(6 / GVAR(ammoCookoffDuration)));

private _speedOfAmmo = getNumber (configFile >> "CfgMagazines" >> _magazineClassname >> "initSpeed");
private _simType = getText (_ammoCfg >> "simulation");
_amountOfMagazines = _amountOfMagazines - _removed;
if (_amountOfMagazines <= 0) then {
_magazines deleteAt _magazineIndex;
} else {
_magazine set [1, _amountOfMagazines]; // clear out the magazine
};
private _timeBetweenAmmoDetonation = (((random 10) / (sqrt _totalAmmo)) min MAX_TIME_BETWEEN_AMMO_DET) max 0.1;
TRACE_2("",_totalAmmo,_timeBetweenAmmoDetonation);
_totalAmmo = _totalAmmo - _removed;

private _effect2pos = _vehicle selectionPosition "destructionEffect2";
private _ammo = getText (configFile >> "CfgMagazines" >> _magazineClassname >> "ammo");
private _ammoCfg = configFile >> "CfgAmmo" >> _ammo;

private _spawnProjectile = {
params ["_vehicle", "_ammo", "_speed", "_flyAway"];
private _speedOfAmmo = getNumber (configFile >> "CfgMagazines" >> _magazineClassname >> "initSpeed");
private _simType = getText (_ammoCfg >> "simulation");

private _spawnPos = _vehicle modelToWorld [-0.2 + (random 0.4), -0.2 + (random 0.4), random 3];
if (_spawnPos select 2 < 0) then {
_spawnPos set [2, 0];
};
private _effect2pos = _vehicle selectionPosition "destructionEffect2";

private _projectile = createVehicle [_ammo, _spawnPos, [], 0, "CAN_COLLIDE"];
if (_flyAway) then {
private _vectorAmmo = [(-1 + (random 2)), (-1 + (random 2)), -0.2 + (random 1)];
private _velVec = _vectorAmmo vectorMultiply _speed;
_projectile setVectorDir _velVec;
_projectile setVelocity _velVec;
} else {
_projectile setDamage 1;
};
private _spawnProjectile = {
params ["_vehicle", "_ammo", "_speed", "_flyAway"];

_projectile;
private _spawnPos = _vehicle modelToWorld [-0.2 + (random 0.4), -0.2 + (random 0.4), random 3];
if (_spawnPos select 2 < 0) then {
_spawnPos set [2, 0];
};

private _speed = random (_speedOfAmmo / 10) max 1;
private _projectile = createVehicle [_ammo, _spawnPos, [], 0, "CAN_COLLIDE"];
if (_flyAway) then {
private _vectorAmmo = [(-1 + (random 2)), (-1 + (random 2)), -0.2 + (random 1)];
private _velVec = _vectorAmmo vectorMultiply _speed;
_projectile setVectorDir _velVec;
_projectile setVelocity _velVec;
} else {
_projectile setDamage 1;
};

if (toLower _simType == "shotbullet") then {
private _sound = selectRandom [QUOTE(PATHTO_R(sounds\light_crack_close.wss)), QUOTE(PATHTO_R(sounds\light_crack_close_filtered.wss)), QUOTE(PATHTO_R(sounds\heavy_crack_close.wss)), QUOTE(PATHTO_R(sounds\heavy_crack_close_filtered.wss))];
playSound3D [_sound, objNull, false, (getPosASL _vehicle), 2, 1, 1250];
_projectile;
};

private _speed = random (_speedOfAmmo / 10) max 1;
_simType = toLower _simType;
switch (_simType) do {
case ("shotbullet"): {
[QGVAR(playCookoffSound), [_vehicle, _simType, 1250]] call CBA_fnc_globalEvent;
if (random 1 < 0.6) then {
[_vehicle, _ammo, _speed, true] call _spawnProjectile;
};
};
if (toLower _simType == "shotshell") then {
private _sound = selectRandom [QUOTE(PATHTO_R(sounds\heavy_crack_close.wss)), QUOTE(PATHTO_R(sounds\heavy_crack_close_filtered.wss))];
playSound3D [_sound, objNull, false, (getPosASL _vehicle), 2, 1, 1300];

case ("shotshell"): {
[QGVAR(playCookoffSound), [_vehicle, _simType, 1300]] call CBA_fnc_globalEvent;
if (random 1 < 0.15) then {
[_vehicle, _ammo, _speed, true] call _spawnProjectile;
};
};
if (toLower _simType == "shotgrenade") then {
case ("shotgrenade"): {
if (random 1 < 0.9) then {
_speed = 0;
};
[_vehicle, _ammo, _speed, random 1 < 0.5] call _spawnProjectile;
};
if (toLower _simType in ["shotrocket", "shotmissile", "shotsubmunitions"]) then {
case ("shotrocket"); case ("shotmissile"); case ("shotsubmunitions"): {
if (random 1 < 0.1) then {
private _sound = selectRandom [QUOTE(PATHTO_R(sounds\cannon_crack_close.wss)), QUOTE(PATHTO_R(sounds\cannon_crack_close_filtered.wss))];
playSound3D [_sound, objNull, false, (getPosASL _vehicle), 3, 1, 1600];

[QGVAR(playCookoffSound), [_vehicle, _simType, 1600]] call CBA_fnc_globalEvent;
[_vehicle, _ammo, _speed, random 1 < 0.3] call _spawnProjectile;
} else {
createvehicle ["ACE_ammoExplosionLarge", (_vehicle modelToWorld _effect2pos), [], 0 , "CAN_COLLIDE"];
};
};
if (toLower _simType in ["shotdirectionalbomb", "shotmine"]) then {
case ("shotmine"); case ("shotdirectionalbomb"): {
if (random 1 < 0.5) then {
// Not all explosives detonate on destruction, some have scripted alternatives
private _scripted = getNumber (_ammoCfg >> "triggerWhenDestroyed") == 1;
if !(_scripted) then {
_ammo = getText (_ammoCfg >> "ace_explosives_Explosive");
};

// If a scripted alternative doesn't exist use generic explosion
if (_ammo != "") then {
[_vehicle, _ammo, 0, false] call _spawnProjectile;
Expand All @@ -124,12 +120,10 @@ if (_amountOfMagazines > 0) exitWith {
};
};
};
if (toLower _simType == "shotilluminating") then {
case ("shotilluminating"): {
if (random 1 < 0.15) then {
[_vehicle, _ammo, _speed, random 1 < 0.3] call _spawnProjectile;
};
};

[FUNC(detonateAmmunition), [_vehicle, _magazines, _totalAmmo], _timeBetweenAmmoDetonation] call CBA_fnc_waitAndExecute;
};
ERROR_1("mag with no ammo - %1", _magazine);
[FUNC(detonateAmmunition), [_vehicle, _magazines, _totalAmmo], _timeBetweenAmmoDetonation] call CBA_fnc_waitAndExecute;
2 changes: 2 additions & 0 deletions addons/cookoff/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@

// Common commander hatch defines for default vehicles
#define DEFAULT_COMMANDER_HATCHES ["osa_poklop_commander", "hatch_commander_axis"]

#define SPEED_OF_SOUND 343
Binary file removed addons/cookoff/sounds/cannon_crack_close.wss
Binary file not shown.
Binary file not shown.
Binary file removed addons/cookoff/sounds/heavy_crack_close.wss
Binary file not shown.
Binary file not shown.
Binary file removed addons/cookoff/sounds/light_crack_close.wss
Binary file not shown.
Binary file not shown.
Binary file added addons/cookoff/sounds/shotbullet/close_1.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotbullet/close_2.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotbullet/close_3.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotbullet/far_1.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotbullet/far_2.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotbullet/far_3.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotbullet/mid_1.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotbullet/mid_2.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotbullet/mid_3.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotrocket/close_1.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotrocket/close_2.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotrocket/close_3.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotrocket/far_1.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotrocket/far_2.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotrocket/far_3.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotrocket/mid_1.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotrocket/mid_2.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotrocket/mid_3.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotshell/close_1.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotshell/close_2.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotshell/close_3.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotshell/far_1.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotshell/far_2.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotshell/far_3.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotshell/mid_1.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotshell/mid_2.wss
Binary file not shown.
Binary file added addons/cookoff/sounds/shotshell/mid_3.wss
Binary file not shown.
1 change: 1 addition & 0 deletions extras/assets/CookoffSounds/ConvertWAVtoWSS.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
forfiles /s /m *.wav /c "DeWSSDos -wss/0 -P -V -Y @path @FNAME.wss"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotbullet/far_1.wav
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotbullet/far_2.wav
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotbullet/far_3.wav
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotbullet/mid_1.wav
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotbullet/mid_2.wav
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotbullet/mid_3.wav
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotrocket/far_1.wav
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotrocket/far_2.wav
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotrocket/far_3.wav
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotrocket/mid_1.wav
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotrocket/mid_2.wav
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotrocket/mid_3.wav
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotshell/far_1.wav
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotshell/far_2.wav
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotshell/far_3.wav
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotshell/mid_1.wav
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotshell/mid_2.wav
Binary file not shown.
Binary file added extras/assets/CookoffSounds/shotshell/mid_3.wav
Binary file not shown.