From fecc77e2255c130aac31682a5b360e998eb73fa3 Mon Sep 17 00:00:00 2001 From: ulteq Date: Sat, 28 Oct 2017 18:19:42 +0200 Subject: [PATCH] Advanced Ballistics - Improved random seed generator --- .../functions/fnc_handleFired.sqf | 4 +++- .../AdvancedBallistics.cpp | 22 +++++++------------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/addons/advanced_ballistics/functions/fnc_handleFired.sqf b/addons/advanced_ballistics/functions/fnc_handleFired.sqf index 806f40c624..81a167696f 100644 --- a/addons/advanced_ballistics/functions/fnc_handleFired.sqf +++ b/addons/advanced_ballistics/functions/fnc_handleFired.sqf @@ -112,7 +112,9 @@ if (_caliber > 0 && _bulletLength > 0 && _bulletMass > 0 && _barrelTwist > 0) th GVAR(currentbulletID) = (GVAR(currentbulletID) + 1) % 10000; -"ace_advanced_ballistics" callExtension format["new:%1:%2:%3:%4:%5:%6:%7:%8:%9:%10:%11:%12:%13:%14:%15:%16:%17", GVAR(currentbulletID), _airFriction, _ballisticCoefficients, _velocityBoundaries, _atmosphereModel, _dragModel, _stabilityFactor, _twistDirection, _transonicStabilityCoef, getPosASL _projectile, _bulletVelocity, EGVAR(common,mapLatitude), EGVAR(weather,currentTemperature), EGVAR(common,mapAltitude), EGVAR(weather,currentHumidity), EGVAR(weather,currentOvercast), CBA_missionTime toFixed 6]; +private _ammoCount = _unit ammo _muzzle; + +"ace_advanced_ballistics" callExtension format["new:%1:%2:%3:%4:%5:%6:%7:%8:%9:%10:%11:%12:%13:%14:%15:%16:%17:%18", GVAR(currentbulletID), _ammoCount, _airFriction, _ballisticCoefficients, _velocityBoundaries, _atmosphereModel, _dragModel, _stabilityFactor, _twistDirection, _transonicStabilityCoef, getPosASL _projectile, _bulletVelocity, EGVAR(common,mapLatitude), EGVAR(weather,currentTemperature), EGVAR(common,mapAltitude), EGVAR(weather,currentHumidity), EGVAR(weather,currentOvercast), CBA_missionTime toFixed 6]; GVAR(allBullets) pushBack [_projectile, _caliber, _bulletTraceVisible, GVAR(currentbulletID)]; diff --git a/extensions/advanced_ballistics/AdvancedBallistics.cpp b/extensions/advanced_ballistics/AdvancedBallistics.cpp index 5760ae797d..2c00538569 100644 --- a/extensions/advanced_ballistics/AdvancedBallistics.cpp +++ b/extensions/advanced_ballistics/AdvancedBallistics.cpp @@ -322,6 +322,7 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function) EXTENSION_RETURN(); } else if (!strcmp(mode, "new")) { unsigned int index = 0; + unsigned int ammoCount = 0; double airFriction = 0.0; char* ballisticCoefficientArray; char* ballisticCoefficient; @@ -348,6 +349,7 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function) double tickTime = 0.0; index = strtol(strtok_s(NULL, ":", &next_token), NULL, 10); + ammoCount = strtol(strtok_s(NULL, ":", &next_token), NULL, 10); airFriction = strtod(strtok_s(NULL, ":", &next_token), NULL); ballisticCoefficientArray = strtok_s(NULL, ":", &next_token); ballisticCoefficientArray++; @@ -415,20 +417,12 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function) bulletDatabase[index].overcast = overcast; bulletDatabase[index].startTime = tickTime; bulletDatabase[index].lastFrame = tickTime; - - int angle = (int)round(atan2(bulletDatabase[index].bulletVelocity[0], bulletDatabase[index].bulletVelocity[1]) * 360 / M_PI); - bulletDatabase[index].randSeed = (unsigned)(720 + angle) % 720; - bulletDatabase[index].randSeed *= 3; - bulletDatabase[index].randSeed += (unsigned)round(abs(bulletDatabase[index].bulletVelocity[2]) / 2); - bulletDatabase[index].randSeed *= 3; - bulletDatabase[index].randSeed += (unsigned)round(abs(bulletDatabase[index].origin[0] / 2)); - bulletDatabase[index].randSeed *= 3; - bulletDatabase[index].randSeed += (unsigned)round(abs(bulletDatabase[index].origin[1] / 2)); - bulletDatabase[index].randSeed *= 3; - bulletDatabase[index].randSeed += (unsigned)abs(bulletDatabase[index].temperature) * 10; - bulletDatabase[index].randSeed *= 3; - bulletDatabase[index].randSeed += (unsigned)abs(bulletDatabase[index].humidity) * 10; - bulletDatabase[index].randGenerator.seed(bulletDatabase[index].randSeed); + if (transonicStabilityCoef < 1) { + unsigned int k1 = (unsigned)round(tickTime / 2); + unsigned int k2 = ammoCount; + bulletDatabase[index].randSeed = 0.5 * (k1 + k2) * (k1 + k2 + 1) + k2; + bulletDatabase[index].randGenerator.seed(bulletDatabase[index].randSeed); + } strncpy_s(output, outputSize, "", _TRUNCATE); EXTENSION_RETURN();