Skip to content

Commit

Permalink
Advanced Ballistics - Improved random seed generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ulteq committed Oct 28, 2017
1 parent dc84082 commit 1ef2618
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
4 changes: 3 additions & 1 deletion addons/advanced_ballistics/functions/fnc_handleFired.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 (primaryWeapon _unit);

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

Expand Down
22 changes: 8 additions & 14 deletions extensions/advanced_ballistics/AdvancedBallistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,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;
Expand All @@ -347,6 +348,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++;
Expand Down Expand Up @@ -414,20 +416,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();
Expand Down

0 comments on commit 1ef2618

Please sign in to comment.