ACE3/addons/cookoff/functions/fnc_detonateAmmunition.sqf
Grim e06c6f7835
General - Replace toLower with toLowerANSI where applicable (#9790)
* General - Replace toLower with toLowerANSI where applicable

* whoops

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

* Update addons/repair/functions/fnc_setHitPointDamage.sqf

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>

* Update addons/repair/dev/draw_showRepairInfo.sqf

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>

* Update addons/tagging/XEH_preStart.sqf

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>

* Update addons/vehicle_damage/functions/fnc_handleCookoff.sqf

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>

* Update addons/tagging/XEH_preStart.sqf

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>

* comparment -> compartment

* Update fnc_showHud.sqf

* Update fnc_registerObjects.sqf

* Update addons/common/functions/fnc_cbaSettings_settingChanged.sqf

---------

Co-authored-by: PabstMirror <pabstmirror@gmail.com>
Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
2024-03-07 22:08:13 +01:00

133 lines
4.6 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: Glowbal
* Detonates ammunition from a vehicle until no ammo left
*
* Arguments:
* 0: vehicle <OBJECT>
* 1: Ammo Array <ARRAY>
* - 0: Magazine Classname <STRING>
* - 1: Ammo Count <NUMBER>
* 2: Total Ammo Count <NUMBER>
*
* Return Value:
* None
*
* Example:
* [_vehicle, magazinesAmmo _vehicle] call ace_cookoff_fnc_detonateAmmunition
*
* Public: No
*/
params ["_vehicle", "_magazines", "_totalAmmo"];
if (GVAR(enable) == 0) exitWith {};
if !(GVAR(enableAmmoCookoff)) exitWith {};
if (isNull _vehicle) exitWith {}; // vehicle got deleted
if (_magazines isEqualTo []) exitWith {}; // nothing to detonate anymore
if (underwater _vehicle) exitWith {};
private _magazineIndex = floor random(count _magazines);
private _magazine = _magazines select _magazineIndex;
_magazine params ["_magazineClassname", "_amountOfMagazines"];
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;
} 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;
};
private _speed = random (_speedOfAmmo / 10) max 1;
_simType = toLowerANSI _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;
};
};
case ("shotshell"): {
[QGVAR(playCookoffSound), [_vehicle, _simType]] call CBA_fnc_globalEvent;
if (random 1 < 0.15) then {
[_vehicle, _ammo, _speed, true] call _spawnProjectile;
};
};
case ("shotgrenade"): {
if (random 1 < 0.9) then {
_speed = 0;
};
[_vehicle, _ammo, _speed, random 1 < 0.5] call _spawnProjectile;
};
case ("shotrocket");
case ("shotmissile");
case ("shotsubmunitions"): {
if (random 1 < 0.1) then {
[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"];
};
};
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;
} else {
createvehicle ["SmallSecondary", (_vehicle modelToWorld _effect2pos), [], 0 , "CAN_COLLIDE"];
};
};
};
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;