From 48d37a96e0e44a682d59e4a6f4568714a288094d Mon Sep 17 00:00:00 2001 From: lambdatiger Date: Tue, 9 Jan 2024 14:00:43 -0600 Subject: [PATCH] update caching access function names to align with each other and added some preliminary material consideration for spalling --- ...Addition.hpp => cfgAmmoFragParameters.hpp} | 0 addons/frag/functions/fnc_doFrag.sqf | 2 +- addons/frag/functions/fnc_doFragRandom.sqf | 3 +- addons/frag/functions/fnc_doSpall.sqf | 2 +- addons/frag/functions/fnc_doSpallMomentum.sqf | 14 ++++---- .../{fnc_fragInfo.sqf => fnc_getFragInfo.sqf} | 2 +- addons/frag/functions/fnc_getMaterialInfo.sqf | 35 +++++++++++++++++++ 7 files changed, 46 insertions(+), 12 deletions(-) rename addons/frag/{cfgAmmoFragAddition.hpp => cfgAmmoFragParameters.hpp} (100%) rename addons/frag/functions/{fnc_fragInfo.sqf => fnc_getFragInfo.sqf} (97%) create mode 100644 addons/frag/functions/fnc_getMaterialInfo.sqf diff --git a/addons/frag/cfgAmmoFragAddition.hpp b/addons/frag/cfgAmmoFragParameters.hpp similarity index 100% rename from addons/frag/cfgAmmoFragAddition.hpp rename to addons/frag/cfgAmmoFragParameters.hpp diff --git a/addons/frag/functions/fnc_doFrag.sqf b/addons/frag/functions/fnc_doFrag.sqf index 1b47fe053a..074b0cd2e1 100644 --- a/addons/frag/functions/fnc_doFrag.sqf +++ b/addons/frag/functions/fnc_doFrag.sqf @@ -44,7 +44,7 @@ private _maxFrags = round (linearConversion [0.1, 1.5, _timeSince, ACE_FRAG_COUN TRACE_3("",_timeSince,CBA_missionTime,_maxFrags); -private _ammoArr = [_ammo] call FUNC(fragInfo); +private _ammoArr = [_ammo] call FUNC(getFragInfo); _ammoArr params ["_fragRange", "_fragVel", "_fragTypes", "_modFragCount"]; private _heightAGL = (ASLToAGL _posASL)#2; diff --git a/addons/frag/functions/fnc_doFragRandom.sqf b/addons/frag/functions/fnc_doFragRandom.sqf index 39d78370cb..919a3ee049 100644 --- a/addons/frag/functions/fnc_doFragRandom.sqf +++ b/addons/frag/functions/fnc_doFragRandom.sqf @@ -31,14 +31,13 @@ params [ ]; TRACE_5("fnc_doFragRandom", _posASL, _projVel, _heightAGL, _fragType, _fragCnt); -// See CfgAmmo for different frag types +// See cfgAmmoFragSpawner for different frag types private _hMode = switch (true) do { case (_heightAGL > 10): {"_top"}; case (_heightAGL > 5): {"_hi"}; default {"_mid"}; }; -// Select the cfgAmmo type private _type = if (count _fragType > 0 && {"ace_frag_tiny" isEqualTo (_fragType#0)}) then { QGVAR(def_tiny_) diff --git a/addons/frag/functions/fnc_doSpall.sqf b/addons/frag/functions/fnc_doSpall.sqf index 00cbe9adde..8777be45ea 100644 --- a/addons/frag/functions/fnc_doSpall.sqf +++ b/addons/frag/functions/fnc_doSpall.sqf @@ -66,7 +66,7 @@ systemChat ("dV: " + str _dv + ", caliber: " + str _caliber + ", product: " + st #endif if (_explosive > 0) then { - private _fragMod = (_ammo call FUNC(fragInfo))#1; + private _fragMod = (_ammo call FUNC(getFragInfo))#1; _velMod = _fragMod * _velMod; }; diff --git a/addons/frag/functions/fnc_doSpallMomentum.sqf b/addons/frag/functions/fnc_doSpallMomentum.sqf index b35baa4d04..dc84389944 100644 --- a/addons/frag/functions/fnc_doSpallMomentum.sqf +++ b/addons/frag/functions/fnc_doSpallMomentum.sqf @@ -51,18 +51,19 @@ private _lVelUnit = vectorNormalized _lVel; private _ammo = typeOf _projectile; private _dV = vectorMagnitude _lVel - vectorMagnitude _vel; private _caliber = getNumber (configFile >> "cfgAmmo" >> _ammo >> "caliber"); // !*! optimize this later? -private _deltaMomentum = 0.4 * _caliber * sqrt( _dV * 0.032 ); +// scaled momentum change made on caliber-mass assumption ~sqrt(2)/20 * caliber ~= mass +private _deltaMomentum = 0.07071 * _caliber * sqrt( _dV ); TRACE_3("found speed",_dV,_caliber,_deltaMomentum); -if (_deltaMomentum < 1) exitWith { +if (_deltaMomentum < 2) exitWith { TRACE_1("lowImpulse",_ammo); }; //** start calculating where the spalling should come !*! could be better **// private _unitStep = _lVelUnit vectorMultiply 0.05; private _spallPos = +_lPosASL; -// exit if we hit the ground + if (terrainIntersectASL [_lPosASL vectorAdd _unitStep, _lPosASL]) exitWith { TRACE_3("terrainIntersect",_lPosASL,_unitStep,_lPosASL); }; @@ -81,16 +82,15 @@ for "_i" from 1 to 20 do [_spallPos, "green"] call FUNC(dev_sphereDraw); [_lPosASL vectorAdd _lVelUnit, "orange"] call FUNC(dev_sphereDraw); [_lPosASL, "orange"] call FUNC(dev_sphereDraw); -private _str = GVAR(materialSpallCache) getOrDefault [str _surfaceType, "["]; -_str =_str + str [_dV, _caliber, abs vectorMagnitude (_lPosASL vectorDiff _spallPos)] + ";"; -GVAR(materialSpallCache) set [str _surfaceType, _str]; -if (_deltaMomentum < 2) exitWith {}; #endif //***** Passed all other exit withs, performance o'clock */ GVAR(lastSpallTime) = CBA_missionTime; //***** Select spalled fragment spawner **// + +private _material = [_surfaceType] call FUNC(getMaterialInfo); + private _fragSpawnType = switch (true) do { case (_deltaMomentum < 3): { QGVAR(spall_tiny) }; diff --git a/addons/frag/functions/fnc_fragInfo.sqf b/addons/frag/functions/fnc_getFragInfo.sqf similarity index 97% rename from addons/frag/functions/fnc_fragInfo.sqf rename to addons/frag/functions/fnc_getFragInfo.sqf index 9211b79bd2..0044896f77 100644 --- a/addons/frag/functions/fnc_fragInfo.sqf +++ b/addons/frag/functions/fnc_getFragInfo.sqf @@ -16,7 +16,7 @@ * of spherical fragmentation * * Example: - * ["B_556x45_Ball"] call ace_frag_fnc_fragInfo; + * ["B_556x45_Ball"] call ace_frag_fnc_getFragInfo; * * Public: No */ diff --git a/addons/frag/functions/fnc_getMaterialInfo.sqf b/addons/frag/functions/fnc_getMaterialInfo.sqf new file mode 100644 index 0000000000..a4423a05cf --- /dev/null +++ b/addons/frag/functions/fnc_getMaterialInfo.sqf @@ -0,0 +1,35 @@ +#include "script_component.hpp" +/* + * Author: Lambda.Tiger + * This function returns fragmentation parameters for a specific + * ammo type. + * + * Arguments: + * 0: _ammo - cfgAmmo type of ammo to check + * + * Return Value: + * _ammoInfo + * 0: _fragRange - search range for fragments + * 1: _fragVel - gurney equation calculated velocity + * 2: _fragTypes - array of fragment types + * 3: _fragCount - modified frag count used under assumptions + * of spherical fragmentation + * + * Example: + * ["B_556x45_Ball"] call ace_frag_fnc_getFragInfo; + * + * Public: No + */ + +params ["_surfType"]; + +private _material = GVAR(materialSpallCache) get _surfType; + +if !(isNil "_material") exitWith {_material}; + +private _str = GVAR(materialSpallCache) getOrDefault [str _surfaceType, "["]; +_str =_str + str [_dV, _caliber, abs vectorMagnitude (_lPosASL vectorDiff _spallPos)] + ";"; + +GVAR(materialSpallCache) set [_surfaceType, _material]; + +_material \ No newline at end of file