diff --git a/BunnymodXT/cvars.cpp b/BunnymodXT/cvars.cpp index b28c60e2..a80ee07a 100644 --- a/BunnymodXT/cvars.cpp +++ b/BunnymodXT/cvars.cpp @@ -137,6 +137,9 @@ namespace CVars CVarWrapper bxt_hud_jumpspeed("bxt_hud_jumpspeed", "0"); CVarWrapper bxt_hud_jumpspeed_offset("bxt_hud_jumpspeed_offset", ""); CVarWrapper bxt_hud_jumpspeed_anchor("bxt_hud_jumpspeed_anchor", "0.5 1"); + CVarWrapper bxt_hud_jumpdistance("bxt_hud_jumpdistance", "0"); + CVarWrapper bxt_hud_jumpdistance_offset("bxt_hud_jumpdistance_offset", ""); + CVarWrapper bxt_hud_jumpdistance_anchor("bxt_hud_jumpdistance_anchor", "0.5 1"); CVarWrapper bxt_hud_health("bxt_hud_health", "0"); CVarWrapper bxt_hud_health_offset("bxt_hud_health_offset", ""); CVarWrapper bxt_hud_health_anchor("bxt_hud_health_anchor", "0.5 1"); @@ -319,6 +322,9 @@ namespace CVars &bxt_hud_jumpspeed, &bxt_hud_jumpspeed_offset, &bxt_hud_jumpspeed_anchor, + &bxt_hud_jumpdistance, + &bxt_hud_jumpdistance_offset, + &bxt_hud_jumpdistance_anchor, &bxt_hud_health, &bxt_hud_health_offset, &bxt_hud_health_anchor, diff --git a/BunnymodXT/cvars.hpp b/BunnymodXT/cvars.hpp index da65c970..4979a4f5 100644 --- a/BunnymodXT/cvars.hpp +++ b/BunnymodXT/cvars.hpp @@ -252,6 +252,9 @@ namespace CVars extern CVarWrapper bxt_hud_jumpspeed; extern CVarWrapper bxt_hud_jumpspeed_offset; extern CVarWrapper bxt_hud_jumpspeed_anchor; + extern CVarWrapper bxt_hud_jumpdistance; + extern CVarWrapper bxt_hud_jumpdistance_offset; + extern CVarWrapper bxt_hud_jumpdistance_anchor; extern CVarWrapper bxt_hud_health; extern CVarWrapper bxt_hud_health_offset; extern CVarWrapper bxt_hud_health_anchor; diff --git a/BunnymodXT/hud_custom.cpp b/BunnymodXT/hud_custom.cpp index 411b61a0..d3533c59 100644 --- a/BunnymodXT/hud_custom.cpp +++ b/BunnymodXT/hud_custom.cpp @@ -661,6 +661,58 @@ namespace CustomHud vecCopy(player.velocity, prevVel); } + static void DrawJumpDistance(float flTime) + { + static float prevOrigin[3] = { 0.0f, 0.0f, 0.0f }; + static float prevPlayerOrigin[3] = { 0.0f, 0.0f, 0.0f }; + static float prevVel[3] = { 0.0f, 0.0f, 0.0f }; + + if (CVars::bxt_hud_jumpdistance.GetBool()) + { + static bool inJump = false; + static double jumpDistance = 0.0; + + // 1 = jumpdistance will update when velocity is reasonably positive + // not 1 = jumpdistance will update when velocity changes, eg just falling + if (!inJump && ( + (((CVars::bxt_hud_jumpdistance.GetInt() == 1) ? + player.velocity[2] > 0.0f : player.velocity[2] != 0.0f) && prevVel[2] == 0.0f) || + (player.velocity[2] > 0.0f && prevVel[2] < 0.0f))) + { + inJump = true; + + // by the time the instantaneous velocity is here + // there is already displacement, which is in the previous frame + vecCopy(prevPlayerOrigin, prevOrigin); + } + else if (inJump && ((player.velocity[2] == 0.0f && prevVel[2] < 0.0f))) + { + inJump = false; + + // add 16*2 because of player size can reach the edge of the block up to 16 unit + double distance = length(player.origin[0] - prevOrigin[0], player.origin[1] - prevOrigin[1]) + 32.0; + + if (distance > 150.0 || CVars::bxt_hud_jumpdistance.GetInt() != 1) // from uq_jumpstats default + { + jumpDistance = distance; + } + } + else if (player.origin[2] == prevPlayerOrigin[2]) + { + // walking + inJump = false; + } + + int x, y; + GetPosition(CVars::bxt_hud_jumpdistance_offset, CVars::bxt_hud_jumpdistance_anchor, &x, &y, 0, -4 * NumberHeight); + DrawNumber(static_cast(trunc(jumpDistance)), x, y, hudColor[0], hudColor[1], hudColor[2]); + } + + vecCopy(player.origin, prevPlayerOrigin); + vecCopy(player.velocity, prevVel); + } + + void DrawTimer(float flTime) { if (CVars::bxt_hud_timer.GetBool()) @@ -1558,6 +1610,7 @@ namespace CustomHud DrawViewangles(flTime); DrawSpeedometer(flTime); DrawJumpspeed(flTime); + DrawJumpDistance(flTime); DrawTimer(flTime); DrawDistance(flTime); DrawEntityInfo(flTime); diff --git a/BunnymodXT/modules/ClientDLL.cpp b/BunnymodXT/modules/ClientDLL.cpp index 584cc59a..a1532821 100644 --- a/BunnymodXT/modules/ClientDLL.cpp +++ b/BunnymodXT/modules/ClientDLL.cpp @@ -878,6 +878,9 @@ void ClientDLL::RegisterCVarsAndCommands() REG(bxt_hud_jumpspeed); REG(bxt_hud_jumpspeed_offset); REG(bxt_hud_jumpspeed_anchor); + REG(bxt_hud_jumpdistance); + REG(bxt_hud_jumpdistance_offset); + REG(bxt_hud_jumpdistance_anchor); REG(bxt_hud_health); REG(bxt_hud_health_offset); REG(bxt_hud_health_anchor);