ACE3/addons/frag/functions/fnc_initRound.sqf

74 lines
2.5 KiB
Plaintext
Raw Normal View History

2024-01-11 20:01:50 +00:00
#include "..\script_component.hpp"
2024-01-09 00:06:57 +00:00
/*
* Author: Lambda.Tiger
* This function adds projectile explode and hitPart event handlers and is
* intended to be called from an projectile config init event handler.
*
2024-01-09 00:06:57 +00:00
* Arguments:
* 0: The projectile to be initialized <OBJECT>
*
2024-01-09 00:06:57 +00:00
* Return Value:
* None
2024-01-09 00:06:57 +00:00
*
* Example:
2024-01-18 03:39:54 +00:00
* [_projectile] call ace_frag_fnc_initRound;
2024-01-09 00:06:57 +00:00
*
* Public: No
*/
TRACE_1("ACE_Frag rndInit",_this);
if (!isServer) exitWith {};
params ["_projectile"];
private _ammo = typeOf _projectile;
if (_ammo isEqualTo "" || {isNull _projectile}) exitWith {
TRACE_2("bad ammo or projectile",_ammo,_projectile);
2024-01-09 00:06:57 +00:00
};
if (GVAR(enabled) && {_ammo call FUNC(shouldFrag)}) then {
_projectile addEventHandler [
"Explode",
{
2024-01-18 03:39:54 +00:00
params ["_projectile", "_posASL", "_velocity"];
2024-01-18 05:13:31 +00:00
private _shotParents = _projectile getVariable [QGVAR(shotParent), getShotParents _projectile];
2024-01-18 03:39:54 +00:00
private _ammo = typeOf _projectile;
2024-01-11 01:47:05 +00:00
// wait for frag damage to kill units before spawning fragments
2024-01-11 21:44:15 +00:00
[
FUNC(doFrag),
[_posASL, _velocity, _ammo, _shotParents]
2024-01-11 21:44:15 +00:00
] call CBA_fnc_execNextFrame;
if (GVAR(reflectionsEnabled)) then {
[_posASL, _ammo] call FUNC(doReflections);
};
2024-01-09 00:06:57 +00:00
}
];
};
if (GVAR(spallEnabled) && {_ammo call FUNC(shouldSpall)}) then {
_projectile addEventHandler [
2024-01-09 00:06:57 +00:00
"HitPart",
{
params ["_projectile", "_hitObject", "", "_posASL", "_velocity", "_surfNorm", "", "", "_surfType"];
// starting v2.18 it may be faster to use the instigator parameter, the same as the second entry shotParents, to recreate _shotParent
// The "explode" EH does not get the same parameter
2024-01-18 03:39:54 +00:00
private _shotParent = getShotParents _projectile;
private _ammo = typeOf _projectile;
private _vectorUp = vectorUp _projectile;
/*
* Wait a frame to see what happens to the round, may result in
* multiple hits / slowdowns getting shunted to the first hit
*/
2024-01-11 21:44:15 +00:00
[
FUNC(doSpall),
2024-01-18 03:39:54 +00:00
[_projectile, _hitObject, _posASL, _velocity, _surfNorm, _surfType, _ammo, _shotParent, _vectorUp]
] call CBA_fnc_execNextFrame;
}
2024-01-09 00:06:57 +00:00
];
};
#ifdef DEBUG_MODE_DRAW
if (GVAR(debugOptions) && {_ammo call FUNC(shouldFrag) || {_ammo call FUNC(shouldSpall)}}) then {
[_projectile, "red", true] call FUNC(dev_trackObj);
};
#endif
TRACE_1("initExit",_ammo);