From d2ee1e987a60a8fbef8bf3d7be25f2d96b96c129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20E=C4=9Fitmen?= Date: Fri, 10 Feb 2017 21:28:27 +0300 Subject: [PATCH] Frag Superanal Cleanup (#4803) * Minimal frag cleanup * Why did this even happen in the first place --- addons/frag/XEH_postInit.sqf | 2 +- addons/frag/functions/fnc_addPfhRound.sqf | 2 +- addons/frag/functions/fnc_doSpall.sqf | 1 + addons/frag/functions/fnc_findReflections.sqf | 13 +-- addons/frag/functions/fnc_fired.sqf | 2 +- addons/frag/functions/fnc_frago.sqf | 110 +++++++++--------- addons/frag/functions/fnc_masterPFH.sqf | 2 +- addons/frag/functions/fnc_pfhRound.sqf | 3 +- addons/frag/functions/fnc_removePfhRound.sqf | 2 +- 9 files changed, 66 insertions(+), 71 deletions(-) diff --git a/addons/frag/XEH_postInit.sqf b/addons/frag/XEH_postInit.sqf index 20a6a1ca707..038b7a36c44 100644 --- a/addons/frag/XEH_postInit.sqf +++ b/addons/frag/XEH_postInit.sqf @@ -1,6 +1,6 @@ #include "script_component.hpp" -if (GVAR(EnableDebugTrace) && {!isMultiplayer}) then { +if (GVAR(enableDebugTrace) && {!isMultiplayer}) then { GVAR(traceFrags) = true; GVAR(autoTrace) = true; }; diff --git a/addons/frag/functions/fnc_addPfhRound.sqf b/addons/frag/functions/fnc_addPfhRound.sqf index a211752e989..f6cddbbd37e 100644 --- a/addons/frag/functions/fnc_addPfhRound.sqf +++ b/addons/frag/functions/fnc_addPfhRound.sqf @@ -13,7 +13,7 @@ if (_round in GVAR(blackList)) exitWith { }; // Exit on max track -if ((count GVAR(objects)) > GVAR(MaxTrack)) exitWith {}; +if ((count GVAR(objects)) > GVAR(maxTrack)) exitWith {}; if ( _gun == ACE_player || diff --git a/addons/frag/functions/fnc_doSpall.sqf b/addons/frag/functions/fnc_doSpall.sqf index 5b9bf757c46..97c52062d17 100644 --- a/addons/frag/functions/fnc_doSpall.sqf +++ b/addons/frag/functions/fnc_doSpall.sqf @@ -103,6 +103,7 @@ for "_i" from 1 to _spallCount do { [ACE_player, _fragment, [1, 0.5, 0, 1]] call FUNC(addTrack); }; }; + _spread = 5 + (random 5); _spallCount = 3 + (random 5); for "_i" from 1 to _spallCount do { diff --git a/addons/frag/functions/fnc_findReflections.sqf b/addons/frag/functions/fnc_findReflections.sqf index f8c9685bdae..dbde4d7a982 100644 --- a/addons/frag/functions/fnc_findReflections.sqf +++ b/addons/frag/functions/fnc_findReflections.sqf @@ -75,23 +75,18 @@ if (_zIndex < 5) then { private _explosions = []; { private _blist = _x select 1; - private _avgX = 0; - private _avgY = 0; - private _avgZ = 0; + private _avg = [0, 0, 0]; { - ADD(_avgX,_x select 0); - ADD(_avgY,_x select 1); - ADD(_avgZ,_x select 2); + _avg = _avg vectorAdd _x; } forEach _blist; _c = count _blist; - private _bpos = [_avgX / _c, _avgY / _c, _avgZ / _c]; + private _bpos = _avg vectorMultiply (1 / _c); private _distance = _pos vectorDistance _bpos; private _hitFactor = 1 - (((_distance / (_indirectHitRange * 4)) min 1) max 0); // _hitFactor = 1 / (_distance ^ 2); - private _hit = _indirectHit * _hitFactor; - _hit = (floor (_hit / 4)) min 500; + private _hit = (floor (_indirectHit * _hitFactor / 4)) min 500; SUB(_hit,_hit % 10); private _range = (floor (_indirectHitRange - (_distance / 4))) min 100; SUB(_range,_range % 2); diff --git a/addons/frag/functions/fnc_fired.sqf b/addons/frag/functions/fnc_fired.sqf index 6b12e09d765..96841dd7aca 100644 --- a/addons/frag/functions/fnc_fired.sqf +++ b/addons/frag/functions/fnc_fired.sqf @@ -30,7 +30,7 @@ if (isNil "_shouldAdd") then { _shouldAdd = false; }; - if (GVAR(SpallEnabled)) exitWith { + if (GVAR(spallEnabled)) exitWith { //Always want to run whenever spall is enabled? _shouldAdd = true; TRACE_2("SettingCache[spallEnabled]",_ammo,_shouldAdd); diff --git a/addons/frag/functions/fnc_frago.sqf b/addons/frag/functions/fnc_frago.sqf index 51ed23cfea3..d9915f787cc 100644 --- a/addons/frag/functions/fnc_frago.sqf +++ b/addons/frag/functions/fnc_frago.sqf @@ -60,13 +60,13 @@ if (_warn) then { }; private _fragPower = (((_m / _c) + _k) ^ - (1 / 2)) * _gC; -_fragPower = _fragPower * 0.8; // Gunery equation is for a non-fragmenting metal, imperical value of 80% represents fragmentation +MUL(_fragPower,0.8); // Gunery equation is for a non-fragmenting metal, imperical value of 80% represents fragmentation private _atlPos = ASLtoATL _lastPos; private _fragPowerRandom = _fragPower * 0.5; if ((_atlPos select 2) < 0.5) then { - _lastPos set [2, (_lastPos select 2) + 0.5]; + _lastPos vectorAdd [0, 0, 0.5]; }; // _manObjects = _atlPos nearEntities ["CaManBase", _fragRange]; @@ -96,7 +96,7 @@ _fragArcs set [360, 0]; private _doRandom = true; if (_isArmed && {!(_objects isEqualTo [])}) then { - if (GVAR(ReflectionsEnabled)) then { + if (GVAR(reflectionsEnabled)) then { [_lastPos, _shellType] call FUNC(doReflections); }; { @@ -104,63 +104,63 @@ if (_isArmed && {!(_objects isEqualTo [])}) then { private _target = _x; if (alive _target) then { private _boundingBox = boundingBox _target; + + private _cubic = 1; + for "_i" from 0 to 2 do { + MUL(_cubic,(abs ((_boundingBox select 0) select _i)) + ((_boundingBox select 1) select _i)); + }; + + if (_cubic <= 1) exitWith {}; + _doRandom = true; + + private _targetVel = velocity _target; private _targetPos = getPosASL _target; - private _distance = _targetPos distance _lastPos; + private _distance = _targetPos vectorDistance _lastPos; private _add = (((_boundingBox select 1) select 2) / 2) + ((((_distance - (_fragpower / 8)) max 0) / _fragPower) * 10); - private _bbX = (abs ((_boundingBox select 0) select 0)) + ((_boundingBox select 1) select 0); - private _bbY = (abs ((_boundingBox select 0) select 1)) + ((_boundingBox select 1) select 1); - private _bbZ = (abs ((_boundingBox select 0) select 2)) + ((_boundingBox select 1) select 2); - private _cubic = _bbX * _bbY * _bbZ; - if (_cubic > 1) then { - _doRandom = true; - - private _targetVel = velocity _target; - - _targetPos = _targetPos vectorAdd [ - (_targetVel select 0) * (_distance / _fragPower), - (_targetVel select 1) * (_distance / _fragPower), - _add - ]; - - private _baseVec = _lastPos vectorFromTo _targetPos; - - private _dir = floor (_baseVec call CBA_fnc_vectDir); - private _currentCount = _fragArcs select _dir; - ISNILS(_currentCount,0); - if (_currentCount < 20) then { - private _count = ceil (random (sqrt (_m / 1000))); - private _vecVar = FRAG_VEC_VAR; - if (!(_target isKindOf "Man")) then { - _vecVar = ((sqrt _cubic) / 2000) + FRAG_VEC_VAR; - if ((crew _target) isEqualTo [] && {_count > 0}) then { - _count = 0 max (_count / 2); - }; + + _targetPos = _targetPos vectorAdd [ + (_targetVel select 0) * (_distance / _fragPower), + (_targetVel select 1) * (_distance / _fragPower), + _add + ]; + + private _baseVec = _lastPos vectorFromTo _targetPos; + + private _dir = floor (_baseVec call CBA_fnc_vectDir); + private _currentCount = RETDEF(_fragArcs select _dir,0); + if (_currentCount < 20) then { + private _count = ceil (random (sqrt (_m / 1000))); + private _vecVar = FRAG_VEC_VAR; + if (!(_target isKindOf "Man")) then { + ADD(_vecVar,(sqrt _cubic) / 2000); + if ((crew _target) isEqualTo [] && {_count > 0}) then { + _count = 0 max (_count / 2); }; - for "_i" from 1 to _count do { - private _vec = _baseVec vectorDiff [ - (_vecVar / 2) + (random _vecVar), - (_vecVar / 2) + (random _vecVar), - (_vecVar / 2) + (random _vecVar) - ]; - - private _fp = _fragPower - (random (_fragPowerRandom)); - private _vel = _vec vectorMultiply _fp; - - private _fragType = round (random ((count _fragTypes) - 1)); - private _fragObj = (_fragTypes select _fragType) createVehicleLocal [0,0,10000]; - // diag_log text format ["fp: %1 %2", _fp, typeOf _fragObj]; - _fragObj setPosASL _lastPos; - _fragObj setVectorDir _vec; - _fragObj setVelocity _vel; - if (GVAR(traceFrags)) then { - INC(GVAR(totalFrags)); - [ACE_player, _fragObj, [1,0,0,1]] call FUNC(addTrack); - }; - INC(_fragCount); - INC(_currentCount); + }; + for "_i" from 1 to _count do { + private _vec = _baseVec vectorDiff [ + (_vecVar / 2) + (random _vecVar), + (_vecVar / 2) + (random _vecVar), + (_vecVar / 2) + (random _vecVar) + ]; + + private _fp = _fragPower - (random (_fragPowerRandom)); + private _vel = _vec vectorMultiply _fp; + + private _fragType = round (random ((count _fragTypes) - 1)); + private _fragObj = (_fragTypes select _fragType) createVehicleLocal [0,0,10000]; + // diag_log text format ["fp: %1 %2", _fp, typeOf _fragObj]; + _fragObj setPosASL _lastPos; + _fragObj setVectorDir _vec; + _fragObj setVelocity _vel; + if (GVAR(traceFrags)) then { + INC(GVAR(totalFrags)); + [ACE_player, _fragObj, [1,0,0,1]] call FUNC(addTrack); }; - _fragArcs set [_dir, _currentCount]; + INC(_fragCount); + INC(_currentCount); }; + _fragArcs set [_dir, _currentCount]; }; }; //}; diff --git a/addons/frag/functions/fnc_masterPFH.sqf b/addons/frag/functions/fnc_masterPFH.sqf index d543c35bf74..f6adb561615 100644 --- a/addons/frag/functions/fnc_masterPFH.sqf +++ b/addons/frag/functions/fnc_masterPFH.sqf @@ -19,7 +19,7 @@ private _gcIndex = []; private _iter = 0; private _objectCount = count GVAR(objects); -while {_objectCount > 0 && {_iter < (GVAR(MaxTrackPerFrame) min _objectCount)}} do { +while {_objectCount > 0 && {_iter < (GVAR(maxTrackPerFrame) min _objectCount)}} do { if (GVAR(lastIterationIndex) >= _objectCount) then { GVAR(lastIterationIndex) = 0; diff --git a/addons/frag/functions/fnc_pfhRound.sqf b/addons/frag/functions/fnc_pfhRound.sqf index 1338e8fef91..f233fa45a69 100644 --- a/addons/frag/functions/fnc_pfhRound.sqf +++ b/addons/frag/functions/fnc_pfhRound.sqf @@ -32,8 +32,7 @@ _this set [1, getPosASL _round]; _this set [2, velocity _round]; if (_doSpall) then { - private ["_scale"]; - _scale = ((count GVAR(objects)) / GVAR(MaxTrackPerFrame)) max 0.1; + private _scale = ((count GVAR(objects)) / GVAR(maxTrackPerFrame)) max 0.1; [_round, _scale, _spallTrack, _foundObjectHPIds] call FUNC(spallTrack); }; diff --git a/addons/frag/functions/fnc_removePfhRound.sqf b/addons/frag/functions/fnc_removePfhRound.sqf index b9df2756430..9241c7aecb1 100644 --- a/addons/frag/functions/fnc_removePfhRound.sqf +++ b/addons/frag/functions/fnc_removePfhRound.sqf @@ -2,7 +2,7 @@ // THIS FUNCTION SHOULD NOT BE USED BECAUSE IT CAUSES AN SEARCH AND REBUILD -PARAMS_1(_round); +params ["_round"]; if (_round in GVAR(blackList)) then { REM(GVAR(blackList),_round);