From c344130f9bcd6c7e198eb91b6a2d3d0a6699c7e4 Mon Sep 17 00:00:00 2001 From: lambdatiger Date: Thu, 18 Jul 2024 22:58:52 -0500 Subject: [PATCH] increased code legiblity and optimized some randomizations --- addons/frag/functions/fnc_doSpall.sqf | 36 +++++++++++++-------------- addons/frag/functions/fnc_frago.sqf | 21 ++++++++-------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/addons/frag/functions/fnc_doSpall.sqf b/addons/frag/functions/fnc_doSpall.sqf index 1c9e039094..fd98f5ef4a 100644 --- a/addons/frag/functions/fnc_doSpall.sqf +++ b/addons/frag/functions/fnc_doSpall.sqf @@ -34,7 +34,7 @@ private _idh = getNumber (configFile >> "CfgAmmo" >> _roundType >> "indirectHitR _roundType call FUNC(getSpallInfo) params ["_caliber", "_explosive"]; private _exit = false; -private _vm = 1; +private _velocityModifier = 1; private _curVelocity = velocity _round; private _oldSpeed = vectorMagnitude _oldVelocity; @@ -48,7 +48,7 @@ if (alive _round) then { if (_caliber < 2.5) then { _exit = true; } else { - SUB(_vm,_curSpeed / _oldSpeed); + SUB(_velocityModifier,_curSpeed / _oldSpeed); }; }; }; @@ -83,16 +83,16 @@ private _spread = 15 + (random 25); private _spallCount = 5 + (random 10); TRACE_1("",_spallCount); for "_i" from 1 to _spallCount do { - private _elev = ((_spallVelocitySpherical select 2) - _spread) + (random (_spread * 2)); - private _dir = ((_spallVelocitySpherical select 1) - _spread) + (random (_spread * 2)); - if (abs _elev > 90) then { - ADD(_dir,180); + private _fragmentElevation = ((_spallVelocitySpherical select 2) - _spread) + (random (_spread * 2)); + private _fragmentAzimuth = ((_spallVelocitySpherical select 1) - _spread) + (random (_spread * 2)); + if (abs _fragmentElevation > 90) then { + ADD(_fragmentAzimuth,180); }; - _dir = _dir % 360; - private _vel = (_spallVelocitySpherical select 0) * 0.33 * _vm; - _vel = (_vel - (_vel * 0.25)) + (random (_vel * 0.5)); + _fragmentAzimuth = _fragmentAzimuth % 360; + private _fragmentSpeed = (_spallVelocitySpherical select 0) * 0.33 * _velocityModifier; + _fragmentSpeed = _fragmentSpeed * (0.75 + random 0.5); - private _spallFragVect = [_vel, _dir, _elev] call CBA_fnc_polar2vect; + private _spallFragVect = [_fragmentSpeed, _fragmentAzimuth, _fragmentElevation] call CBA_fnc_polar2vect; private _fragment = createVehicleLocal [selectRandomWeighted WEIGHTED_SIZE, _spallPosAGL, [], 0, "CAN_COLLIDE"]; _fragment setVelocity _spallFragVect; _fragment setShotParents _shotParents; @@ -105,16 +105,16 @@ for "_i" from 1 to _spallCount do { _spread = 5 + (random 5); _spallCount = 3 + (random 5); for "_i" from 1 to _spallCount do { - private _elev = ((_spallVelocitySpherical select 2) - _spread) + (random (_spread * 2)); - private _dir = ((_spallVelocitySpherical select 1) - _spread) + (random (_spread * 2)); - if (abs _elev > 90) then { - ADD(_dir,180); + private _fragmentElevation = ((_spallVelocitySpherical select 2) - _spread) + (random (_spread * 2)); + private _fragmentAzimuth = ((_spallVelocitySpherical select 1) - _spread) + (random (_spread * 2)); + if (abs _fragmentElevation > 90) then { + ADD(_fragmentAzimuth,180); }; - _dir = _dir % 360; - private _vel = (_spallVelocitySpherical select 0) * 0.55 * _vm; - _vel = (_vel - (_vel * 0.25)) + (random (_vel * 0.5)); + _fragmentAzimuth = _fragmentAzimuth % 360; + private _fragmentSpeed = (_spallVelocitySpherical select 0) * 0.55 * _velocityModifier; + _fragmentSpeed = _fragmentSpeed * (0.75 + random 0.5); - private _spallFragVect = [_vel, _dir, _elev] call CBA_fnc_polar2vect; + private _spallFragVect = [_fragmentSpeed, _fragmentAzimuth, _fragmentElevation] call CBA_fnc_polar2vect; private _fragment = createVehicleLocal [selectRandomWeighted WEIGHTED_SIZE, _spallPosAGL, [], 0, "CAN_COLLIDE"]; _fragment setVelocity _spallFragVect; _fragment setShotParents _shotParents; diff --git a/addons/frag/functions/fnc_frago.sqf b/addons/frag/functions/fnc_frago.sqf index a238dc3718..9f43a69290 100644 --- a/addons/frag/functions/fnc_frago.sqf +++ b/addons/frag/functions/fnc_frago.sqf @@ -32,7 +32,6 @@ GVAR(lastFragTime) = CBA_missionTime; _shellType call ace_frag_fnc_getFragInfo params ["_fragRange", "_fragVelocity", "_fragTypes", "_metalMassModifier"]; -private _fragVelocityRandom = _fragVelocity * 0.5; private _fragPosAGL = ASLtoAGL _fragPosASL; // Post 2.18 change - uncomment line 41, and remove lines 43, 50-55, 64-66 // private _targets = [ASLtoAGL _fragPosAGL, _fragRange, _fragRange, 0, false, _fragRange] nearEntities [["Car", "Motorcycle", "Tank", "StaticWeapon", "CAManBase", "Air", "Ship"], false, true, true]; @@ -96,19 +95,19 @@ if (_targets isNotEqualTo []) then { }; for "_i" from 1 to _count do { - private _vec = _baseVec vectorDiff [ + private _vectorDir = _baseVec vectorDiff [ (_vecVar / 2) + (random _vecVar), (_vecVar / 2) + (random _vecVar), (_vecVar / 2) + (random _vecVar) ]; - private _fp = _fragVelocity - (random (_fragVelocityRandom)); - private _vel = _vec vectorMultiply _fp; + private _fragObjSpeed = _fragVelocity * (1 - random 0.5); + private _fragObjVelocity = _vectorDir vectorMultiply _fragObjSpeed; private _fragObj = createVehicleLocal [(selectRandom _fragTypes), _fragPosAGL, [], 0, "CAN_COLLIDE"]; - _fragObj setVectorDir _vec; - _fragObj setVelocity _vel; + _fragObj setVectorDir _vectorDir; + _fragObj setVelocity _fragObjVelocity; _fragObj setShotParents _shotParents; #ifdef DEBUG_MODE_DRAW [_fragObj, "green", true] call FUNC(dev_trackObj); @@ -132,16 +131,16 @@ if (_targets isNotEqualTo []) then { // Distribute evenly private _sectorOffset = 360 * (_i - 1) / (_randomCount max 1); private _randomDir = random (_sectorSize); - _vec = [cos (_sectorOffset + _randomDir), sin (_sectorOffset + _randomDir), sin (30 - (random 45))]; + private _vectorDir = [cos (_sectorOffset + _randomDir), sin (_sectorOffset + _randomDir), sin (30 - (random 45))]; - _fp = (_fragVelocity - (random (_fragVelocityRandom))); + private _fragObjSpeed = _fragVelocity * (1 - random 0.5); - _vel = _vec vectorMultiply _fp; + _fragObjVelocity = _vectorDir vectorMultiply _fragObjSpeed; private _fragObj = createVehicleLocal [(selectRandom _fragTypes), _fragPosAGL, [], 0, "CAN_COLLIDE"]; _fragObj setPosASL _fragPosASL; - _fragObj setVectorDir _vec; - _fragObj setVelocity _vel; + _fragObj setVectorDir _vectorDir; + _fragObj setVelocity _fragObjVelocity; _fragObj setShotParents _shotParents; #ifdef DEBUG_MODE_DRAW