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 all 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 @@ -126,6 +126,7 @@ Keithen <Keithen.Neu@gmail.com>
Kllrt <kllrtik@gmail.com>
KokaKolaA3
Krzyciu
LAxemann
legman <juicemelon@msn.com>
Legolasindar "Viper" <legolasindar@gmail.com>
licht-im-Norden87 <lichtimnorden87@gmail.com>
Expand Down
66 changes: 66 additions & 0 deletions addons/cookoff/CfgSounds.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#define VOLUME 2
#define PITCH 1

#define SHOTSOUND(type,dist,N,maxDistance)\
class GVAR(TRIPLES(type,dist,N)) {\
sound[] = {QPATHTOF(sounds\type\DOUBLES(dist,N).wss), VOLUME, PITCH, maxDistance};\
titles[] = {};\
}

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

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

// Allows other mods to change sounds for cook-off
class CfgSounds {
// These macros set up the sounds for the various classes
SHOTSOUNDCLASSTYPE(shotbullet,1250);
SHOTSOUNDCLASSTYPE(shotrocket,1600);
SHOTSOUNDCLASSTYPE(shotshell,1300);

johnb432 marked this conversation as resolved.
Show resolved Hide resolved
// Missiles use the same sounds as rockets
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) {};

// Submunitions have the same sound as bullets, but a higher maxDistance
class GVAR(shotsubmunitions_close_1): GVAR(shotbullet_close_1) {
sound[] = {QPATHTOF(sounds\shotbullet\close_1.wss), VOLUME, PITCH, 1600};
};
class GVAR(shotsubmunitions_close_2): GVAR(shotbullet_close_2) {
sound[] = {QPATHTOF(sounds\shotbullet\close_2.wss), VOLUME, PITCH, 1600};
};
class GVAR(shotsubmunitions_close_3): GVAR(shotbullet_close_3) {
sound[] = {QPATHTOF(sounds\shotbullet\close_3.wss), VOLUME, PITCH, 1600};
};
class GVAR(shotsubmunitions_mid_1): GVAR(shotbullet_far_1) {
sound[] = {QPATHTOF(sounds\shotbullet\mid_1.wss), VOLUME, PITCH, 1600};
};
class GVAR(shotsubmunitions_mid_2): GVAR(shotbullet_mid_2) {
sound[] = {QPATHTOF(sounds\shotbullet\mid_2.wss), VOLUME, PITCH, 1600};
};
class GVAR(shotsubmunitions_mid_3): GVAR(shotbullet_mid_3) {
sound[] = {QPATHTOF(sounds\shotbullet\mid_3.wss), VOLUME, PITCH, 1600};
};
class GVAR(shotsubmunitions_far_1): GVAR(shotbullet_far_1) {
sound[] = {QPATHTOF(sounds\shotbullet\far_1.wss), VOLUME, PITCH, 1600};
};
class GVAR(shotsubmunitions_far_2): GVAR(shotbullet_far_2) {
sound[] = {QPATHTOF(sounds\shotbullet\far_2.wss), VOLUME, PITCH, 1600};
};
class GVAR(shotsubmunitions_far_3): GVAR(shotbullet_far_3) {
sound[] = {QPATHTOF(sounds\shotbullet\far_3.wss), VOLUME, PITCH, 1600};
};
};
45 changes: 42 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,42 @@
[FUNC(detonateAmmunition), [_vehicle, _mags, _total], _delay] call CBA_fnc_waitAndExecute;
};
}, nil, ["Man","StaticWeapon"]] call CBA_fnc_addClassEventHandler;

if (hasInterface) then {
// Plays a sound locally, so that different sounds can be used for various distances
[QGVAR(playCookoffSound), {
params ["_object", "_sound"];

if (isNull _object) exitWith {};

private _distance = _object distance (positionCameraToWorld [0, 0, 0]);

TRACE_3("",_object,_sound,_maxDistance);

// 3 classes of distances: close, mid and far, each having different sound files
private _classDistance = switch (true) do {
case (_distance < DISTANCE_CLOSE): {"close"};
case (_distance < DISTANCE_MID): {"mid"};
default {"far"};
};

_sound = format [QGVAR(%1_%2_%3), _sound, _classDistance, floor (random 3) + 1];

TRACE_1("",_sound);

// Allows other mods to change sounds for cook-off
_sound = getArray (configFile >> "CfgSounds" >> _sound >> "sound");

if (_sound isEqualTo []) exitWith {};

_sound params ["_sound", "_volume", "_pitch", "_maxDistance"];

if (_distance > _maxDistance) exitWith {};

// Make sure file exists, so RPT isn't spammed with non-existent entry errors
if (!fileExists _sound) exitWith {};

// Obeys speed of sound and takes doppler effects into account
playSound3D [_sound, objNull, insideBuilding _object >= 0.5, getPosASL _object, _volume, _pitch + (random 0.2) - 0.1, _maxDistance, 0, true];
}] call CBA_fnc_addEventHandler;
};
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"
103 changes: 50 additions & 53 deletions addons/cookoff/functions/fnc_detonateAmmunition.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -32,90 +32,89 @@ 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]] 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]] 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]] 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 +123,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;
3 changes: 3 additions & 0 deletions addons/cookoff/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@

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

#define DISTANCE_CLOSE 235
#define DISTANCE_MID 952
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.
Loading