Skip to content

Commit

Permalink
Fixed grenades disappearing when speed exceeds 2000 fixed units ignor…
Browse files Browse the repository at this point in the history
…ing sv_maxvelocity (#888)

* Fixed grenades disappearing when speed exceeds 2000 fixed units ignoring sv_maxvelocity
* Clamp nades velocity to sv_maxvelocity value when reached
* Make IsInWorld behave like SV_CheckVelocity: less/greater without equal
* Enclose IsInWorld changes with FIXES macro
  • Loading branch information
dystopm authored Nov 26, 2023
1 parent b10489f commit 193c1ed
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
12 changes: 12 additions & 0 deletions regamedll/dlls/cbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,17 @@ BOOL CBaseEntity::IsInWorld()
}

// speed
#ifdef REGAMEDLL_FIXES
float maxvel = g_psv_maxvelocity->value;
if (pev->velocity.x > maxvel || pev->velocity.y > maxvel || pev->velocity.z > maxvel)
{
return FALSE;
}
if (pev->velocity.x < -maxvel || pev->velocity.y < -maxvel || pev->velocity.z < -maxvel)
{
return FALSE;
}
#else
if (pev->velocity.x >= 2000.0 || pev->velocity.y >= 2000.0 || pev->velocity.z >= 2000.0)
{
return FALSE;
Expand All @@ -878,6 +889,7 @@ BOOL CBaseEntity::IsInWorld()
{
return FALSE;
}
#endif

return TRUE;
}
Expand Down
2 changes: 2 additions & 0 deletions regamedll/dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cvar_t *g_psv_friction = nullptr;
cvar_t *g_psv_stopspeed = nullptr;
cvar_t *g_psv_stepsize = nullptr;
cvar_t *g_psv_clienttrace = nullptr;
cvar_t *g_psv_maxvelocity = nullptr;

cvar_t displaysoundlist = { "displaysoundlist", "0", 0, 0.0f, nullptr };
cvar_t timelimit = { "mp_timelimit", "0", FCVAR_SERVER, 0.0f, nullptr };
Expand Down Expand Up @@ -238,6 +239,7 @@ void EXT_FUNC GameDLLInit()
g_psv_stopspeed = CVAR_GET_POINTER("sv_stopspeed");
g_psv_stepsize = CVAR_GET_POINTER("sv_stepsize");
g_psv_clienttrace = CVAR_GET_POINTER("sv_clienttrace");
g_psv_maxvelocity = CVAR_GET_POINTER("sv_maxvelocity");

CVAR_REGISTER(&displaysoundlist);
CVAR_REGISTER(&timelimit);
Expand Down
3 changes: 2 additions & 1 deletion regamedll/dlls/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@
extern cvar_t *g_pskill;
extern cvar_t *g_psv_gravity;
extern cvar_t *g_psv_aim;
extern cvar_t *g_footsteps;
extern cvar_t *g_psv_accelerate;
extern cvar_t *g_psv_friction;
extern cvar_t *g_psv_stopspeed;
extern cvar_t *g_psv_stepsize;
extern cvar_t *g_psv_clienttrace;
extern cvar_t *g_footsteps;
extern cvar_t *g_psv_maxvelocity;

extern cvar_t displaysoundlist;
extern cvar_t timelimit;
Expand Down
21 changes: 21 additions & 0 deletions regamedll/dlls/ggrenade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,13 @@ void CGrenade::BounceSound()

void CGrenade::TumbleThink()
{
#ifdef REGAMEDLL_FIXES
if (pev->velocity.IsLengthGreaterThan(g_psv_maxvelocity->value))
{
pev->velocity = pev->velocity.Normalize() * g_psv_maxvelocity->value;
}
#endif

if (!IsInWorld())
{
UTIL_Remove(this);
Expand Down Expand Up @@ -809,6 +816,13 @@ void CGrenade::TumbleThink()

void CGrenade::SG_TumbleThink()
{
#ifdef REGAMEDLL_FIXES
if (pev->velocity.IsLengthGreaterThan(g_psv_maxvelocity->value))
{
pev->velocity = pev->velocity.Normalize() * g_psv_maxvelocity->value;
}
#endif

if (!IsInWorld())
{
UTIL_Remove(this);
Expand Down Expand Up @@ -1322,6 +1336,13 @@ void AnnounceFlashInterval(float interval, float offset)

void CGrenade::C4Think()
{
#ifdef REGAMEDLL_FIXES
if (pev->velocity.IsLengthGreaterThan(g_psv_maxvelocity->value))
{
pev->velocity = pev->velocity.Normalize() * g_psv_maxvelocity->value;
}
#endif

if (!IsInWorld())
{
#ifdef REGAMEDLL_FIXES
Expand Down
5 changes: 2 additions & 3 deletions regamedll/dlls/gib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ LINK_ENTITY_TO_CLASS(gib, CGib, CCSGib)

void CGib::LimitVelocity()
{
float length = pev->velocity.Length();
float topspeed = CVAR_GET_FLOAT("sv_maxvelocity") * 0.75f;
float topspeed = g_psv_maxvelocity->value * 0.75f;

// ceiling at topspeed. The gib velocity equation is not bounded properly. Rather than tune it
// in 3 separate places again, I'll just limit it here.
if (length > topspeed)
if (pev->velocity.IsLengthGreaterThan(topspeed))
{
// DONE: This should really be sv_maxvelocity * 0.75 or something
pev->velocity = pev->velocity.Normalize() * topspeed;
Expand Down

0 comments on commit 193c1ed

Please sign in to comment.