Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add estimated crouched/ducked distance for noduck jumps #479

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions addons/sourcemod/scripting/gokz-jumpstats/jump_reporting.sp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static void DoConsoleReport(int client, bool isFailstat, Jump jump, int tier, ch
return;
}

char releaseWString[32], blockString[32], edgeString[32], deviationString[32], missString[32];
char releaseWString[32], blockString[32], edgeString[32], deviationString[32], missString[32], duckedDistString[32];

if (jump.originalType == JumpType_LongJump ||
jump.originalType == JumpType_LadderJump ||
Expand Down Expand Up @@ -215,10 +215,15 @@ static void DoConsoleReport(int client, bool isFailstat, Jump jump, int tier, ch
{
FormatEx(edgeString, sizeof(edgeString), " %s", GetFloatConsoleString2(client, "Edge", jump.edge));
}


if (jump.estimatedDuckedDistance > 0.0)
{
FormatEx(duckedDistString, sizeof(duckedDistString), " %s", GetFloatConsoleString2(client, "Estimated Crouch Distance", jump.estimatedDuckedDistance));
}

PrintToConsole(client, "%t", header, jump.jumper, jump.distance, gC_JumpTypes[jump.originalType]);

PrintToConsole(client, "%s%s%s%s %s %s %s %s%s %s %s%s %s %s %s %s %s",
PrintToConsole(client, "%s%s%s%s %s %s %s %s%s %s %s%s %s %s %s %s %s%s",
gC_ModeNamesShort[GOKZ_GetCoreOption(jump.jumper, Option_Mode)],
blockString,
edgeString,
Expand All @@ -235,7 +240,8 @@ static void DoConsoleReport(int client, bool isFailstat, Jump jump, int tier, ch
GetFloatConsoleString1(client, "Height", jump.height),
GetIntConsoleString(client, "Airtime", jump.duration),
GetFloatConsoleString1(client, "Offset", jump.offset),
GetIntConsoleString(client, "Crouch Ticks", jump.crouchTicks));
GetIntConsoleString(client, "Crouch Ticks", jump.crouchTicks),
duckedDistString);

PrintToConsole(client, " #. %12t%12t%12t%12t%12t%9t%t", "Sync (Table)", "Gain (Table)", "Loss (Table)", "Airtime (Table)", "Width (Table)", "Overlap (Table)", "Dead Air (Table)");
if (jump.strafes_ticks[0] > 0)
Expand Down
82 changes: 80 additions & 2 deletions addons/sourcemod/scripting/gokz-jumpstats/jump_tracking.sp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static bool doFailstatAlways[MAXPLAYERS + 1];
static bool isInAir[MAXPLAYERS + 1];
static const Jump emptyJump;
static Handle acceptInputHook;

static ConVar cvGravity;

// =====[ DEFINITIONS ]========================================================

Expand Down Expand Up @@ -201,14 +201,16 @@ enum struct JumpTracker
// Fix the edgebug for the current position
Movement_GetNobugLandingOrigin(this.jumper, this.position);

this.CalculateDuckedDistance();
// There are a couple bugs and exploits we have to check for
this.EndBugfixExploits();

// Calculate the last stats
this.jump.distance = this.CalcDistance();
this.jump.sync = float(this.syncTicks) / float(this.jump.duration) * 100.0;
this.jump.offset = this.position[2] - this.takeoffOrigin[2];

this.jump.estimatedDuckedDistance = this.CalculateDuckedDistance();

this.EndBlockDistance();

// Make sure the ladder has no offset for ladder jumps
Expand Down Expand Up @@ -693,6 +695,76 @@ enum struct JumpTracker
}
}

float CalculateDuckedDistance()
{
// Try to use the more correct origin to use as the base.
// This would be the nobug origin if the jump is bugged (landing origin height is roughly the same height as bugged).
float nbLandingOrigin[3], guessedDuckedOrigin[3];
Movement_GetNobugLandingOrigin(this.jumper, nbLandingOrigin);
Movement_GetLandingOrigin(this.jumper, guessedDuckedOrigin);

if (guessedDuckedOrigin[2] - nbLandingOrigin[2] < JS_OFFSET_EPSILON)
{
guessedDuckedOrigin = nbLandingOrigin;
}

float velocity[3];
Movement_GetLandingVelocity(this.jumper, velocity);

if (!GetEntProp(this.jumper, Prop_Send, "m_bDucked"))
{
float tempOrigin[3], tempOrigin2[3];

tempOrigin = guessedDuckedOrigin;
tempOrigin2 = guessedDuckedOrigin;

tempOrigin[2] += 9.0;
tempOrigin2[2] += 9.0;
bool success;
for (int futureTick = 0; futureTick < JS_NODUCK_MAX_ESTIMATED_TICKS; futureTick++)
{
float gravityFactor = Movement_GetGravity(this.jumper);
if (gravityFactor == 0.0)
{
gravityFactor = 1.0;
}
velocity[2] -= gravityFactor * cvGravity.FloatValue * GetTickInterval();
for (int i = 0; i < 3; i++)
{
tempOrigin2[i] += velocity[i] * GetTickInterval();
}
float destination[3];
// If it hits, that means it landed!
if (TraceHullPosition(tempOrigin, tempOrigin2, PLAYER_MINS, PLAYER_MAXS_DUCKED, destination))
{
success = true;
// Mirror MovementAPI's optimistic realdist estimation.
tempOrigin2[2] += gravityFactor * cvGravity.FloatValue * GetTickInterval() * GetTickInterval();
TraceHullPosition(tempOrigin, tempOrigin2, PLAYER_MINS, PLAYER_MAXS_DUCKED, destination);
tempOrigin = tempOrigin2;
tempOrigin2 = destination;
break;
}
else
{
tempOrigin = tempOrigin2;
}
}

if (success)
{
float distance = GetVectorHorizontalDistance(this.takeoffOrigin, tempOrigin2);

if (this.jump.originalType != JumpType_LadderJump)
{
return distance + 32.0;
}

}
}
return -1.0;
}

void EndBugfixExploits()
{
// Try to prevent a form of booster abuse
Expand Down Expand Up @@ -1299,6 +1371,12 @@ void OnPluginStart_JumpTracking()
DHookAddParam(acceptInputHook, HookParamType_Object, 20, DHookPass_ByVal|DHookPass_ODTOR|DHookPass_OCTOR|DHookPass_OASSIGNOP);
DHookAddParam(acceptInputHook, HookParamType_Int);
delete gd;

cvGravity = FindConVar("sv_gravity");
if (cvGravity == null)
{
SetFailState("Could not find sv_gravity");
}
}

void OnOptionChanged_JumpTracking(int client, const char[] option)
Expand Down
2 changes: 2 additions & 0 deletions addons/sourcemod/scripting/include/gokz/jumpstats.inc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ enum
#define JS_MIN_TELEPORT_DELAY 5
#define JS_SPEED_MODIFICATION_TOLERANCE 0.1
#define JS_OFFSET_EPSILON 0.03125
#define JS_NODUCK_MAX_ESTIMATED_TICKS 20

stock char gC_JumpTypes[JUMPTYPE_COUNT][] =
{
Expand Down Expand Up @@ -274,6 +275,7 @@ enum struct Jump
float preSpeed;
float sync;
float width;
float estimatedDuckedDistance;

// For the 'always' stats
float miss;
Expand Down
4 changes: 4 additions & 0 deletions addons/sourcemod/translations/gokz-jumpstats.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@
"en" "Miss"
"ru" "Miss"
}
"Estimated Crouch Distance"
{
"en" "ECD"
}


// =====[ CHAT MESSAGES ]=====
Expand Down