updated initialization and should frag to check for submunitions since we no longer rely on init EH

This commit is contained in:
lambdatiger 2024-07-16 21:45:41 -05:00
parent 9df2e5b181
commit f65fcbf44f
3 changed files with 83 additions and 9 deletions

View File

@ -3,7 +3,6 @@ PREP(dev_addRound);
PREP(dev_clearTraces);
PREP(dev_debugAmmo);
PREP(dev_drawTrace);
PREP(dev_fired);
PREP(dev_fragCalcDump);
PREP(dev_trackHitBox);
PREP(dev_trackObj);
@ -13,12 +12,13 @@ PREP(doFrag);
PREP(doFragRandom);
PREP(doFragTargeted);
PREP(doReflections);
PREP(doSpall);
PREP(doSpallLocal);
PREP(doSpallServer);
PREP(findReflections);
PREP(fired);
PREP(getMaterialInfo);
PREP(getSpallInfo);
PREP(getFragInfo);
PREP(initMaterialCache);
PREP(initRound);
PREP(shouldFrag);
PREP(shouldSpall);

View File

@ -0,0 +1,54 @@
#include "..\script_component.hpp"
/*
* Author: Lambda.Tiger
* Adds fragmentation event handlers to projectiles as needed.
*
* Arguments:
* 0: class name of projectile being initialized <STRING>
* 1: Projectile being initialized <OBJECT>
*
* Return Value:
* Nothing
*
* Example:
* [clientFiredBIS-XEH] call ace_frag_fnc_fired
*
* 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;
// Call server event for fragment generation
[
QGVAR(explosionEvent),
[_posASL, _velocity, _ammo, _shotParents]
] call CBA_fnc_serverEvent;
}
];
};
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:
* Should the specific round fragment <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,31 +23,49 @@ 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.4) exitWith {
_shouldFrag = false;
_shouldFrag set [0, false];
TRACE_3("No frag: _explosive",_skip,_force,_explosive);
};
private _indirectHit = getNumber (_ammoConfig >> "indirectHit");
private _indirectRange = getNumber (_ammoConfig >> "indirectHitRange");
if (_indirectHit < 3 ||
{_indirectRange < 5 && _indirectHit < _indirectRange}) then {
_shouldFrag = false;
_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;
if (_submunitionAmmo isNotEqualTo "") then {
private _shouldSubmunitionFrag = _submunitionAmmo call FUNC(shouldFrag);
_shouldFrag set [1, _shouldSubmunitionFrag#0 || _shouldSubmunitionFrag#1];
};
} else {
private _submunitionArray = getArray _ammoSubmunitionConfigPath;
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