Cookoff - Improve ammo detonation sounds (#5327)

* initital commit

* use Define for SOS

* fix some issues that got introduced in 1.70

* Prepare config for sounds

* add New Sounds 

improve distanced volume values

* add LAxemann to Author

* add Object Pooling

improve Distances

* fix small mistake

* change pool clearing timing

* change pool wait time

* fix Cookoff sound cleanup

* change to Jonpas Method

change random Distance add

* improve sound Volume over Distance (asked by Bux)

improve mid sounds

* improve a calculation

* Use playSound3D locally

* Make sounds configurable by 3rd party mods

* Added comments, used macros

* Update CfgSounds.hpp

---------

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
This commit is contained in:
Joko 2024-02-04 10:36:59 +01:00 committed by GitHub
parent 7696d9aa2e
commit 2a6fd19762
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
67 changed files with 169 additions and 61 deletions

View File

@ -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>

View File

@ -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);
// 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};
};
};

View File

@ -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;
};

View File

@ -21,4 +21,5 @@ class CfgPatches {
#include "CfgAmmo.hpp"
#include "CfgCloudlets.hpp"
#include "CfgSFX.hpp"
#include "CfgSounds.hpp"
#include "CfgVehicles.hpp"

View File

@ -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)));
if (_amountOfMagazines < 0) exitWith {
ERROR_1("mag with no ammo - %1", _magazine);
};
private _removed = _amountOfMagazines min floor(1 + random(6 / GVAR(ammoCookoffDuration)));
_amountOfMagazines = _amountOfMagazines - _removed;
if (_amountOfMagazines <= 0) then {
_magazines deleteAt _magazineIndex;
_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;
private _speedOfAmmo = getNumber (configFile >> "CfgMagazines" >> _magazineClassname >> "initSpeed");
private _simType = getText (_ammoCfg >> "simulation");
private _effect2pos = _vehicle selectionPosition "destructionEffect2";
private _spawnProjectile = {
params ["_vehicle", "_ammo", "_speed", "_flyAway"];
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 _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 {
_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;
private _speedOfAmmo = getNumber (configFile >> "CfgMagazines" >> _magazineClassname >> "initSpeed");
private _simType = getText (_ammoCfg >> "simulation");
private _effect2pos = _vehicle selectionPosition "destructionEffect2";
private _spawnProjectile = {
params ["_vehicle", "_ammo", "_speed", "_flyAway"];
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 _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;
};
_projectile;
_projectile setDamage 1;
};
private _speed = random (_speedOfAmmo / 10) max 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;
@ -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;

View File

@ -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 not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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 not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.