increased code legiblity and optimized some randomizations

This commit is contained in:
lambdatiger 2024-07-18 22:58:52 -05:00
parent 4f251767d7
commit c344130f9b
2 changed files with 28 additions and 29 deletions

View File

@ -34,7 +34,7 @@ private _idh = getNumber (configFile >> "CfgAmmo" >> _roundType >> "indirectHitR
_roundType call FUNC(getSpallInfo) params ["_caliber", "_explosive"]; _roundType call FUNC(getSpallInfo) params ["_caliber", "_explosive"];
private _exit = false; private _exit = false;
private _vm = 1; private _velocityModifier = 1;
private _curVelocity = velocity _round; private _curVelocity = velocity _round;
private _oldSpeed = vectorMagnitude _oldVelocity; private _oldSpeed = vectorMagnitude _oldVelocity;
@ -48,7 +48,7 @@ if (alive _round) then {
if (_caliber < 2.5) then { if (_caliber < 2.5) then {
_exit = true; _exit = true;
} else { } else {
SUB(_vm,_curSpeed / _oldSpeed); SUB(_velocityModifier,_curSpeed / _oldSpeed);
}; };
}; };
}; };
@ -83,16 +83,16 @@ private _spread = 15 + (random 25);
private _spallCount = 5 + (random 10); private _spallCount = 5 + (random 10);
TRACE_1("",_spallCount); TRACE_1("",_spallCount);
for "_i" from 1 to _spallCount do { for "_i" from 1 to _spallCount do {
private _elev = ((_spallVelocitySpherical select 2) - _spread) + (random (_spread * 2)); private _fragmentElevation = ((_spallVelocitySpherical select 2) - _spread) + (random (_spread * 2));
private _dir = ((_spallVelocitySpherical select 1) - _spread) + (random (_spread * 2)); private _fragmentAzimuth = ((_spallVelocitySpherical select 1) - _spread) + (random (_spread * 2));
if (abs _elev > 90) then { if (abs _fragmentElevation > 90) then {
ADD(_dir,180); ADD(_fragmentAzimuth,180);
}; };
_dir = _dir % 360; _fragmentAzimuth = _fragmentAzimuth % 360;
private _vel = (_spallVelocitySpherical select 0) * 0.33 * _vm; private _fragmentSpeed = (_spallVelocitySpherical select 0) * 0.33 * _velocityModifier;
_vel = (_vel - (_vel * 0.25)) + (random (_vel * 0.5)); _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"]; private _fragment = createVehicleLocal [selectRandomWeighted WEIGHTED_SIZE, _spallPosAGL, [], 0, "CAN_COLLIDE"];
_fragment setVelocity _spallFragVect; _fragment setVelocity _spallFragVect;
_fragment setShotParents _shotParents; _fragment setShotParents _shotParents;
@ -105,16 +105,16 @@ for "_i" from 1 to _spallCount do {
_spread = 5 + (random 5); _spread = 5 + (random 5);
_spallCount = 3 + (random 5); _spallCount = 3 + (random 5);
for "_i" from 1 to _spallCount do { for "_i" from 1 to _spallCount do {
private _elev = ((_spallVelocitySpherical select 2) - _spread) + (random (_spread * 2)); private _fragmentElevation = ((_spallVelocitySpherical select 2) - _spread) + (random (_spread * 2));
private _dir = ((_spallVelocitySpherical select 1) - _spread) + (random (_spread * 2)); private _fragmentAzimuth = ((_spallVelocitySpherical select 1) - _spread) + (random (_spread * 2));
if (abs _elev > 90) then { if (abs _fragmentElevation > 90) then {
ADD(_dir,180); ADD(_fragmentAzimuth,180);
}; };
_dir = _dir % 360; _fragmentAzimuth = _fragmentAzimuth % 360;
private _vel = (_spallVelocitySpherical select 0) * 0.55 * _vm; private _fragmentSpeed = (_spallVelocitySpherical select 0) * 0.55 * _velocityModifier;
_vel = (_vel - (_vel * 0.25)) + (random (_vel * 0.5)); _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"]; private _fragment = createVehicleLocal [selectRandomWeighted WEIGHTED_SIZE, _spallPosAGL, [], 0, "CAN_COLLIDE"];
_fragment setVelocity _spallFragVect; _fragment setVelocity _spallFragVect;
_fragment setShotParents _shotParents; _fragment setShotParents _shotParents;

View File

@ -32,7 +32,6 @@ GVAR(lastFragTime) = CBA_missionTime;
_shellType call ace_frag_fnc_getFragInfo params ["_fragRange", "_fragVelocity", "_fragTypes", "_metalMassModifier"]; _shellType call ace_frag_fnc_getFragInfo params ["_fragRange", "_fragVelocity", "_fragTypes", "_metalMassModifier"];
private _fragVelocityRandom = _fragVelocity * 0.5;
private _fragPosAGL = ASLtoAGL _fragPosASL; private _fragPosAGL = ASLtoAGL _fragPosASL;
// Post 2.18 change - uncomment line 41, and remove lines 43, 50-55, 64-66 // 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]; // 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 { 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), (_vecVar / 2) + (random _vecVar),
(_vecVar / 2) + (random _vecVar) (_vecVar / 2) + (random _vecVar)
]; ];
private _fp = _fragVelocity - (random (_fragVelocityRandom)); private _fragObjSpeed = _fragVelocity * (1 - random 0.5);
private _vel = _vec vectorMultiply _fp; private _fragObjVelocity = _vectorDir vectorMultiply _fragObjSpeed;
private _fragObj = createVehicleLocal [(selectRandom _fragTypes), _fragPosAGL, [], 0, "CAN_COLLIDE"]; private _fragObj = createVehicleLocal [(selectRandom _fragTypes), _fragPosAGL, [], 0, "CAN_COLLIDE"];
_fragObj setVectorDir _vec; _fragObj setVectorDir _vectorDir;
_fragObj setVelocity _vel; _fragObj setVelocity _fragObjVelocity;
_fragObj setShotParents _shotParents; _fragObj setShotParents _shotParents;
#ifdef DEBUG_MODE_DRAW #ifdef DEBUG_MODE_DRAW
[_fragObj, "green", true] call FUNC(dev_trackObj); [_fragObj, "green", true] call FUNC(dev_trackObj);
@ -132,16 +131,16 @@ if (_targets isNotEqualTo []) then {
// Distribute evenly // Distribute evenly
private _sectorOffset = 360 * (_i - 1) / (_randomCount max 1); private _sectorOffset = 360 * (_i - 1) / (_randomCount max 1);
private _randomDir = random (_sectorSize); 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"]; private _fragObj = createVehicleLocal [(selectRandom _fragTypes), _fragPosAGL, [], 0, "CAN_COLLIDE"];
_fragObj setPosASL _fragPosASL; _fragObj setPosASL _fragPosASL;
_fragObj setVectorDir _vec; _fragObj setVectorDir _vectorDir;
_fragObj setVelocity _vel; _fragObj setVelocity _fragObjVelocity;
_fragObj setShotParents _shotParents; _fragObj setShotParents _shotParents;
#ifdef DEBUG_MODE_DRAW #ifdef DEBUG_MODE_DRAW