Fixed weapon spread for fake clients (bots). Thanks Neoptolemus!

This commit is contained in:
pierow 2023-08-13 15:11:43 -04:00
parent 52630598ad
commit 96a268a91f

View file

@ -108,8 +108,22 @@ Vector UTIL_GetRandomSpreadDir(unsigned int inSeed, int inShotNumber, const Vect
{ {
// Use player's random seed. // Use player's random seed.
// get circular gaussian spread // get circular gaussian spread
float x = UTIL_SharedRandomFloat( inSeed + inShotNumber, -0.5, 0.5 ) + UTIL_SharedRandomFloat( inSeed + ( 1 + inShotNumber ) , -0.5, 0.5 ); float x, y;
float y = UTIL_SharedRandomFloat( inSeed + ( 2 + inShotNumber ), -0.5, 0.5 ) + UTIL_SharedRandomFloat( inSeed + ( 3 + inShotNumber ), -0.5, 0.5 );
// Check if seed is 0 to fix bot weapon spread.
if (inSeed == 0)
{
x = g_engfuncs.pfnRandomFloat(-0.5, 0.5);
x = g_engfuncs.pfnRandomFloat(-0.5, 0.5) + x;
y = g_engfuncs.pfnRandomFloat(-0.5, 0.5);
y = g_engfuncs.pfnRandomFloat(-0.5, 0.5) + y;
}
else
{
x = UTIL_SharedRandomFloat(inSeed + inShotNumber, -0.5, 0.5) + UTIL_SharedRandomFloat(inSeed + (1 + inShotNumber), -0.5, 0.5);
y = UTIL_SharedRandomFloat(inSeed + (2 + inShotNumber), -0.5, 0.5) + UTIL_SharedRandomFloat(inSeed + (3 + inShotNumber), -0.5, 0.5);
}
float z = x * x + y * y; float z = x * x + y * y;
Vector theRandomDir = inBaseDirection + x * inSpread.x * inRight + y * inSpread.y * inUp; Vector theRandomDir = inBaseDirection + x * inSpread.x * inRight + y * inSpread.y * inUp;
@ -122,8 +136,22 @@ Vector UTIL_GetRandomSpreadDirFrom(unsigned int inSeed, int inShotNumber, const
{ {
// Use player's random seed. // Use player's random seed.
// get circular gaussian spread // get circular gaussian spread
float x = UTIL_SharedRandomFloat( inSeed + inShotNumber, -0.5, 0.5 ) + UTIL_SharedRandomFloat( inSeed + ( 1 + inShotNumber ) , -0.5, 0.5 ); float x, y;
float y = UTIL_SharedRandomFloat( inSeed + ( 2 + inShotNumber ), -0.5, 0.5 ) + UTIL_SharedRandomFloat( inSeed + ( 3 + inShotNumber ), -0.5, 0.5 );
// Check if seed is 0 to fix bot weapon spread.
if (inSeed == 0)
{
x = g_engfuncs.pfnRandomFloat(-0.5, 0.5);
x = g_engfuncs.pfnRandomFloat(-0.5, 0.5) + x;
y = g_engfuncs.pfnRandomFloat(-0.5, 0.5);
y = g_engfuncs.pfnRandomFloat(-0.5, 0.5) + y;
}
else
{
x = UTIL_SharedRandomFloat(inSeed + inShotNumber, -0.5, 0.5) + UTIL_SharedRandomFloat(inSeed + (1 + inShotNumber), -0.5, 0.5);
y = UTIL_SharedRandomFloat(inSeed + (2 + inShotNumber), -0.5, 0.5) + UTIL_SharedRandomFloat(inSeed + (3 + inShotNumber), -0.5, 0.5);
}
float z = x * x + y * y; float z = x * x + y * y;
float xdir = x / fabs(x); float xdir = x / fabs(x);
float ydir = y / fabs(y); float ydir = y / fabs(y);