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"];
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;

View File

@ -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