2023-09-12 18:58:10 +00:00
#include "..\script_component.hpp"
2015-01-11 16:42:31 +00:00
/*
2015-02-14 06:39:01 +00:00
* Author: commy2
2016-02-06 20:20:30 +00:00
* Adjust the grenades throwing direction and speed to the selected throwing mode. Called from the unified fired EH only for CAManBase
2015-02-14 06:39:01 +00:00
*
* Arguments:
2016-02-06 20:20:30 +00:00
* None. Parameters inherited from EFUNC(common,firedEH)
2015-02-14 06:39:01 +00:00
*
* Return Value:
2015-08-13 20:36:58 +00:00
* None
2015-02-14 06:39:01 +00:00
*
* Example:
* [clientFiredBIS-XEH] call ace_grenades_fnc_throwGrenade
*
* Public: No
*/
2015-01-14 09:06:47 +00:00
2016-02-06 20:20:30 +00:00
//IGNORE_PRIVATE_WARNING ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_vehicle", "_gunner", "_turret"];
2024-02-05 17:04:24 +00:00
TRACE_10("firedEH:",_unit,_weapon,_muzzle,_mode,_ammo,_magazine,_projectile,_vehicle,_gunner,_turret);
2015-01-11 16:42:31 +00:00
if (_weapon != "Throw") exitWith {};
2015-09-01 21:56:25 +00:00
// http://feedback.arma3.com/view.php?id=12340
if (isNull _projectile) then {
_projectile = nearestObject [_unit, _ammo];
};
2016-01-06 21:42:02 +00:00
private _config = configFile >> "CfgAmmo" >> _ammo;
2024-06-18 08:05:01 +00:00
// Handle special grenades and sounds
2015-09-01 21:19:49 +00:00
if (local _unit) then {
2024-06-18 08:05:01 +00:00
// Handle priming sound, if present
private _soundConfig = getArray (_config >> QGVAR(pullPinSound));
2021-02-27 17:05:05 +00:00
if (_soundConfig isNotEqualTo []) then {
2016-06-16 01:16:28 +00:00
_soundConfig params ["_file", "_volume", "_pitch", "_distance"];
2024-06-18 08:05:01 +00:00
playSound3D [_file, objNull, insideBuilding _unit >= 0.5, getPosASL _projectile, _volume, _pitch, _distance];
2016-06-08 00:22:48 +00:00
};
2016-01-06 21:42:02 +00:00
if (getNumber (_config >> QGVAR(flashbang)) == 1) then {
2019-05-12 04:43:32 +00:00
private _fuzeTimeBase = getNumber (_config >> "explosionTime");
2024-06-18 08:05:01 +00:00
private _bangs = [_config >> QGVAR(flashbangBangs), "NUMBER", 1] call CBA_fnc_getConfigEntry;
private _interval = [_config >> QGVAR(flashbangInterval), "NUMBER", 0.5] call CBA_fnc_getConfigEntry;
private _maxDeviation = [_config >> QGVAR(flashbangIntervalMaxDeviation), "NUMBER", 0.1] call CBA_fnc_getConfigEntry;
2019-05-12 04:43:32 +00:00
for "_i" from 0 to (_bangs - 1) do {
2024-06-18 08:05:01 +00:00
private _fuzeTime = _fuzeTimeBase + _i * _interval + random [-_maxDeviation, 0, _maxDeviation];
2019-05-12 04:43:32 +00:00
2024-06-18 08:05:01 +00:00
[LINKFUNC(flashbangThrownFuze), _projectile, _fuzeTime] call CBA_fnc_waitAndExecute;
2019-05-12 04:43:32 +00:00
};
2015-09-01 21:19:49 +00:00
};
2015-09-01 21:56:25 +00:00
};
2015-09-01 21:19:49 +00:00
2016-01-06 21:42:02 +00:00
if (getNumber (_config >> QGVAR(flare)) == 1) then {
private _fuzeTime = getNumber (_config >> "explosionTime");
private _timeToLive = getNumber (_config >> "timeToLive");
private _color = getArray (_config >> QGVAR(color));
private _intensity = _color deleteAt 3;
2015-09-01 21:19:49 +00:00
2024-06-18 08:05:01 +00:00
[LINKFUNC(flare), [_projectile, _color, _intensity, _timeToLive], _fuzeTime] call CBA_fnc_waitAndExecute;
2016-07-13 22:01:14 +00:00
};
if (getNumber (_config >> QGVAR(incendiary)) == 1) then {
private _fuzeTime = getNumber (_config >> "explosionTime");
private _timeToLive = getNumber (_config >> "timeToLive");
2024-06-18 08:05:01 +00:00
[LINKFUNC(incendiary), [_projectile, _timeToLive, side group _unit], _fuzeTime] call CBA_fnc_waitAndExecute; // Get the unit's real side (will return civilian if unconscious)
2015-09-01 21:19:49 +00:00
};
2024-06-18 08:05:01 +00:00
// Handle throw modes
2015-09-01 21:19:49 +00:00
if (_unit != ACE_player) exitWith {};
2016-09-06 19:54:42 +00:00
if (_unit getVariable [QEGVAR(advanced_throwing,primed), false]) exitWith {LOG("advanced_throwing throw");};
2015-09-01 21:19:49 +00:00
2024-06-18 08:05:01 +00:00
if (GVAR(currentThrowMode) == 0) exitWith {};
2015-01-11 16:42:31 +00:00
2024-06-18 08:05:01 +00:00
private _velocity = velocity _projectile;
2015-02-14 06:39:01 +00:00
2024-06-18 08:05:01 +00:00
switch (GVAR(currentThrowMode)) do {
// High throw
case 1: {
_velocity = _velocity vectorMultiply 0.5;
2024-05-27 09:19:52 +00:00
2024-06-18 08:05:01 +00:00
_velocity set [2, vectorMagnitude _velocity];
};
// Precise throw
case 2: {
_velocity = (_unit weaponDirection _weapon) vectorMultiply (vectorMagnitude _velocity);
};
// Roll grenade
case 3: {
private _posASL = getPosASL _projectile;
2024-05-27 09:19:52 +00:00
2024-06-18 08:05:01 +00:00
// getPos is unreliable, as surfaces in some ruins are not recognised as surfaces
private _lisPos = (lineIntersectsSurfaces [_posASL, _posASL vectorAdd [0, 0, -1e11], ACE_player, objNull, true, 1, "ROADWAY", "FIRE"]) select 0;
_projectile setPosASL ((_lisPos select 0) vectorAdd [0, 0, 0.2]);
2024-05-27 09:19:52 +00:00
2024-06-18 08:05:01 +00:00
// Rotate throwables by 90° to the side by default, so cylindrical throwables can be rolled
private _vectorDirAndUp = getArray (_config >> QGVAR(rollVectorDirAndUp));
_vectorDirAndUp params [["_vectorDir", [0, 1, 0], [[]], 3], ["_vectorUp", [1, 0, 0], [[]], 3]];
2024-05-27 09:19:52 +00:00
2024-06-18 08:05:01 +00:00
// Do as if object were facing north
_projectile setVectorDirAndUp ([[_vectorDir, _vectorUp], -(direction _projectile), 0, 0] call BIS_fnc_transformVectorDirAndUp);
2015-01-11 16:42:31 +00:00
2024-06-18 08:05:01 +00:00
_velocity = (vectorDir _unit) vectorMultiply 10;
};
// Drop grenade
case 4: {
_velocity = [0, 0, 0];
};
2015-01-11 16:42:31 +00:00
};
2024-06-18 08:05:01 +00:00
_projectile setVelocity _velocity;