Updated should frag and fired functions to handle submunitions

This commit is contained in:
lambdatiger 2024-08-03 14:55:53 -05:00
parent 8c68f131fa
commit 9ea7a63496
4 changed files with 97 additions and 41 deletions

View File

@ -15,5 +15,6 @@ PREP(fired);
PREP(frago);
PREP(getFragInfo);
PREP(getSpallInfo);
PREP(roundInitFrag);
PREP(shouldFrag);
PREP(shouldSpall);

View File

@ -24,6 +24,12 @@ if (_ammo isEqualTo "" || {isNull _projectile} ||
TRACE_2("bad ammo or projectile, or blackList",_ammo,_projectile);
};
#ifdef DEBUG_MODE_DRAW
if (GVAR(debugOptions) && {true in (_ammo call FUNC(shouldFrag)) || {_ammo call FUNC(shouldSpall)}}) then {
[_projectile, "red", true] call FUNC(dev_trackObj);
};
#endif
if (GVAR(spallEnabled) && {_ammo call FUNC(shouldSpall)}) then {
private _hitPartEventHandler = _projectile addEventHandler [
"HitPart",
@ -52,38 +58,9 @@ if (GVAR(spallEnabled) && {_ammo call FUNC(shouldSpall)}) then {
];
_projectile setVariable [QGVAR(hitPartEventHandler), _hitPartEventHandler];
};
if (GVAR(reflectionsEnabled) || GVAR(enabled) && _ammo call FUNC(shouldFrag)) then {
private _explodeEventHandler = _projectile addEventHandler [
"Explode",
{
params ["_projectile", "_posASL"];
if (GVAR(reflectionsEnabled)) then {
[_posASL, _ammo] call FUNC(doReflections);
};
private _shotParents = getShotParents _projectile;
private _ammo = typeOf _projectile;
// only let a unit make a frag event once per second
private _instigator = _shotParents#1;
if (CBA_missionTime < (_instigator getVariable [QGVAR(nextFragEvent), -1])) exitWith {};
_instigator setVariable [QGVAR(nextFragEvent), CBA_missionTime + ACE_FRAG_FRAG_UNIT_HOLDOFF];
// Wait a frame to make sure it doesn't target the dead
[
{ [QGVAR(frag_eh), _this] call CBA_fnc_serverEvent; },
[_posASL, _ammo, [objNull, _instigator]]
] call CBA_fnc_execNextFrame;
}
];
_projectile setVariable [QGVAR(explodeEventHandler), _explodeEventHandler];
if !(GVAR(reflectionsEnabled) || GVAR(enabled)) exitWith {
TRACE_1("firedExit No frag/reflections",_ammo);
};
#ifdef DEBUG_MODE_DRAW
if (GVAR(debugOptions) && {_ammo call FUNC(shouldFrag) || {_ammo call FUNC(shouldSpall)}}) then {
[_projectile, "red", true] call FUNC(dev_trackObj);
};
#endif
[_ammo, _projectile] call FUNC(roundInitFrag);
TRACE_1("firedExit",_ammo);

View File

@ -0,0 +1,55 @@
#include "..\script_component.hpp"
/*
* Author: Lambda.Tiger
* Adds fragmentation event handlers to projectiles as needed.
* Seperated from fired function for use with submunitions.
*
* Arguments:
* 0: class name of projectile being initialized <STRING>
* 1: Projectile being initialized <OBJECT>
*
* Return Value:
* Nothing
*
* Example:
* ["ACE_20mm_HE", _projectile_ACE20mmHE] call ace_frag_fnc_roundInitFrag;
*
* Public: No
*/
params ["_ammo", "_projectile"];
_ammo call FUNC(shouldFrag) params ["_shouldFrag", "_submunitionShouldFrag"];
if (_shouldFrag) then {
_projectile addEventHandler [
"Explode",
{
params ["_projectile", "_posASL", "_velocity"];
if (GVAR(reflectionsEnabled)) then {
[_posASL, _ammo] call FUNC(doReflections);
};
if (_projectile getVariable [QGVAR(blacklisted), false]) exitWith {
TRACE_2("projectile blackisted",typeOf _projectile,_projectile);
};
private _shotParents = getShotParents _projectile;
private _ammo = typeOf _projectile;
// Wait a frame to make sure it doesn't target soon to be dead objects
[
{ [QGVAR(explosionEvent), _this] call CBA_fnc_serverEvent; },
[_posASL, _velocity, _ammo, _shotParents]
] call CBA_fnc_execNextFrame;
}
];
};
if (_submunitionShouldFrag) then {
_projectile addEventHandler [
"SubmunitionCreated",
{
params ["", "_submunitionProjectile"];
[typeOf _submunitionProjectile, _submunitionProjectile] call FUNC(roundInitFrag);
}
];
};

View File

@ -7,7 +7,9 @@
* 0: Ammo classname <STRING>
*
* Return Value:
* Could the ammo class generate fragments <BOOL>
* An array containing <ARRAY>
* 0: Should the ammo class generate fragments <BOOL>
* 1: Should the ammo class create submunitions that may fragment <BOOL>
*
* Example:
* "B_556x45_Ball" call ace_frag_fnc_shouldFrag
@ -21,30 +23,51 @@ private _shouldFrag = GVAR(shouldFragCache) get _ammo;
if (!isNil "_shouldFrag") exitWith {_shouldFrag};
_shouldFrag = true;
_shouldFrag = [true, false];
private _ammoConfig = configFile >> "CfgAmmo" >> _ammo;
private _skip = getNumber (_ammoConfig >> QGVAR(skip));
if (_skip == 1) then {
_shouldFrag = false;
_shouldFrag set [0, false];
TRACE_1("No frag: skip",_skip);
};
private _force = getNumber (_ammoConfig >> QGVAR(force));
if (_shouldFrag && _force == 0) then {
if (_shouldFrag#0 && _force == 0) then {
private _explosive = getNumber (_ammoConfig >> "explosive");
if (_explosive < 0.5) exitWith {
_shouldFrag = false;
if (_explosive < 0.4) exitWith {
_shouldFrag set [0, false];
TRACE_3("No frag: _explosive",_skip,_force,_explosive);
};
private _indirectHit = getNumber (_ammoConfig >> "indirectHit");
private _indirectRange = getNumber (_ammoConfig >> "indirectHitRange");
if (_indirectHit * sqrt(_indirectRange) < 35 || _indirectRange < 4.5) then {
_shouldFrag = false;
if (_indirectHit < 3 ||
{_indirectRange < 5 && _indirectHit < _indirectRange}) then {
_shouldFrag set [0, false];
TRACE_5("No frag",_ammo,_skip,_explosive,_indirectRange,_indirectHit);
};
};
private _ammoSubmunitionConfigPath = _ammoConfig >> "submunitionAmmo";
if (isText _ammoSubmunitionConfigPath) then {
private _submunitionAmmo = getText _ammoSubmunitionConfigPath;
TRACE_1("Submunition ammo text: ",_submunitionAmmo);
if (_submunitionAmmo isNotEqualTo "") then {
private _shouldSubmunitionFrag = _submunitionAmmo call FUNC(shouldFrag);
_shouldFrag set [1, _shouldSubmunitionFrag#0 || _shouldSubmunitionFrag#1];
};
} else {
private _submunitionArray = getArray _ammoSubmunitionConfigPath;
TRACE_1("Submunition ammo array: ",_submunitionArray);
for "_i" from 0 to count _submunitionArray - 1 step 2 do {
private _submunitionAmmo = _submunitionArray#_i;
if (_submunitionAmmo isNotEqualTo "") then {
private _shouldSubmunitionFrag = _submunitionAmmo call FUNC(shouldFrag);
_shouldFrag set [1, _shouldSubmunitionFrag#0 || _shouldSubmunitionFrag#1];
};
};
};
GVAR(shouldFragCache) set [_ammo, _shouldFrag];
_shouldFrag
_shouldFrag