Compensate for ping, and fix speed/gravity issues on some projectiles

This commit is contained in:
BenCat07 2020-09-02 21:09:12 +02:00 committed by LightCat
parent 771e342db2
commit 2a7787e49e
3 changed files with 39 additions and 28 deletions

View File

@ -1171,11 +1171,18 @@ int BestHitbox(CachedEntity *target)
headonly = false; headonly = false;
// Rocket launcher // Rocket launcher
} }
else if (ci == CL_CLASS(CTFRocketLauncher) || ci == CL_CLASS(CTFRocketLauncher_AirStrike) || ci == CL_CLASS(CTFRocketLauncher_DirectHit) || ci == CL_CLASS(CTFRocketLauncher_Mortar) || ci == CL_CLASS(CTFPipebombLauncher)) // These weapons should aim at the foot if the target is grounded
else if (ci == CL_CLASS(CTFRocketLauncher) || ci == CL_CLASS(CTFRocketLauncher_AirStrike) || ci == CL_CLASS(CTFRocketLauncher_Mortar))
{ {
preferred = hitbox_t::hip_L; preferred = hitbox_t::foot_L;
} }
// Airborn projectile // These weapons should aim at the center of mass due to little/no splash
else if (ci == CL_CLASS(CTFPipebombLauncher) || ci == CL_CLASS(CTFRocketLauncher_DirectHit) || ci == CL_CLASS(CTFGrenadeLauncher))
{
preferred = hitbox_t::spine_3;
}
// Airborn targets should always get hit in center
if (GetWeaponMode() == weaponmode::weapon_projectile) if (GetWeaponMode() == weaponmode::weapon_projectile)
{ {
if (g_pLocalPlayer->weapon()->m_iClassID() != CL_CLASS(CTFCompoundBow)) if (g_pLocalPlayer->weapon()->m_iClassID() != CL_CLASS(CTFCompoundBow))

View File

@ -14,6 +14,7 @@
#include "Ragdolls.hpp" #include "Ragdolls.hpp"
static settings::Boolean tcm{ "debug.tcm", "true" }; static settings::Boolean tcm{ "debug.tcm", "true" };
static settings::Boolean should_correct_punch{ "debug.correct-punch", "true" };
std::vector<ConVar *> &RegisteredVarsList() std::vector<ConVar *> &RegisteredVarsList()
{ {
@ -1248,6 +1249,9 @@ bool GetProjectileData(CachedEntity *weapon, float &speed, float &gravity)
case CL_CLASS(CTFRocketLauncher): case CL_CLASS(CTFRocketLauncher):
{ {
rspeed = 1100.0f; rspeed = 1100.0f;
// Libery Launcher
if (CE_INT(weapon, netvar.iItemDefinitionIndex) == 414)
rspeed *= 1.4f;
break; break;
} }
case CL_CLASS(CTFCannon): case CL_CLASS(CTFCannon):
@ -1256,32 +1260,33 @@ bool GetProjectileData(CachedEntity *weapon, float &speed, float &gravity)
break; break;
} }
case CL_CLASS(CTFGrenadeLauncher): case CL_CLASS(CTFGrenadeLauncher):
{
IF_GAME(IsTF2())
{ {
rspeed = 1200.0f; rspeed = 1200.0f;
rgrav = 0.4f; rgrav = 0.4f;
} IF_GAME(IsTF2())
else IF_GAME(IsTF2C()) {
// Loch'n Load
if (CE_INT(weapon, netvar.iItemDefinitionIndex) == 308)
rspeed *= 1.25f;
}
IF_GAME(IsTF2C())
{ {
rspeed = 1100.0f;
rgrav = 0.5f; rgrav = 0.5f;
} }
break; break;
} }
case CL_CLASS(CTFPipebombLauncher): case CL_CLASS(CTFPipebombLauncher):
{ {
float chargebegin = *((float *) ((uint64_t) RAW_ENT(LOCAL_W) + 3152)); float chargetime = g_GlobalVars->curtime - CE_FLOAT(weapon, netvar.flChargeBeginTime);
float chargetime = g_GlobalVars->curtime - chargebegin; rspeed = RemapValClamped(chargetime, 0.0f, 4.0f, 900, 2400);
rspeed = (fminf(fmaxf(chargetime / 4.0f, 0.0f), 1.0f) * 1500.0f) + 900.0f; rgrav = 0.4f;
rgrav = (fminf(fmaxf(chargetime / 4.0f, 0.0f), 1.0f) * -0.70000001f) + 0.5f;
break; break;
} }
case CL_CLASS(CTFCompoundBow): case CL_CLASS(CTFCompoundBow):
{ {
float chargetime = g_GlobalVars->curtime - CE_FLOAT(weapon, netvar.flChargeBeginTime); float chargetime = g_GlobalVars->curtime - CE_FLOAT(weapon, netvar.flChargeBeginTime);
rspeed = (float) ((float) (fminf(fmaxf(chargetime, 0.0), 1.0) * 800.0) + 1800.0); rspeed = RemapValClamped(chargetime, 0.0f, 1.f, 1800, 2600);
rgrav = (float) ((float) (fminf(fmaxf(chargetime, 0.0), 1.0) * -0.40000001) + 0.5); rgrav = RemapValClamped(chargetime, 0.0f, 1.f, 0.5, 0.1);
break; break;
} }
case CL_CLASS(CTFBat_Giftwrap): case CL_CLASS(CTFBat_Giftwrap):
@ -1449,7 +1454,7 @@ Vector GetForwardVector(Vector origin, Vector viewangles, float distance, Cached
float sp, sy, cp, cy; float sp, sy, cp, cy;
QAngle angle = VectorToQAngle(viewangles); QAngle angle = VectorToQAngle(viewangles);
// Compensate for punch angle // Compensate for punch angle
if (punch_entity) if (punch_entity && should_correct_punch)
angle += VectorToQAngle(CE_VECTOR(punch_entity, netvar.vecPunchAngle)); angle += VectorToQAngle(CE_VECTOR(punch_entity, netvar.vecPunchAngle));
trace_t trace; trace_t trace;

View File

@ -8,7 +8,6 @@
#include <settings/Bool.hpp> #include <settings/Bool.hpp>
static settings::Boolean debug_pp_extrapolate{ "debug.pp-extrapolate", "false" }; static settings::Boolean debug_pp_extrapolate{ "debug.pp-extrapolate", "false" };
static settings::Boolean debug_pp_rockettimeping{ "debug.pp-rocket-time-ping", "false" };
static settings::Boolean debug_pp_draw{ "debug.pp-draw", "false" }; static settings::Boolean debug_pp_draw{ "debug.pp-draw", "false" };
// TODO there is a Vector() object created each call. // TODO there is a Vector() object created each call.
@ -271,8 +270,8 @@ Vector ProjectilePrediction_Engine(CachedEntity *ent, int hb, float speed, float
} }
float rockettime = g_pLocalPlayer->v_Eye.DistTo(current) / speed; float rockettime = g_pLocalPlayer->v_Eye.DistTo(current) / speed;
if (debug_pp_rockettimeping) // Compensate for ping
rockettime += g_IEngine->GetNetChannelInfo()->GetLatency(FLOW_OUTGOING); rockettime += g_IEngine->GetNetChannelInfo()->GetLatency(FLOW_OUTGOING) + cl_interp->GetFloat();
if (fabs(rockettime - currenttime) < mindelta) if (fabs(rockettime - currenttime) < mindelta)
{ {
besttime = currenttime; besttime = currenttime;
@ -282,8 +281,8 @@ Vector ProjectilePrediction_Engine(CachedEntity *ent, int hb, float speed, float
} }
const_cast<Vector &>(RAW_ENT(ent)->GetAbsOrigin()) = origin; const_cast<Vector &>(RAW_ENT(ent)->GetAbsOrigin()) = origin;
CE_VECTOR(ent, 0x354) = origin; CE_VECTOR(ent, 0x354) = origin;
if (debug_pp_rockettimeping) // Compensate for ping
besttime += g_IEngine->GetNetChannelInfo()->GetLatency(FLOW_OUTGOING); besttime += g_IEngine->GetNetChannelInfo()->GetLatency(FLOW_OUTGOING) + cl_interp->GetFloat();
bestpos.z += (400 * besttime * besttime * gravitymod); bestpos.z += (400 * besttime * besttime * gravitymod);
// S = at^2/2 ; t = sqrt(2S/a)*/ // S = at^2/2 ; t = sqrt(2S/a)*/
Vector result = bestpos + hitbox_offset; Vector result = bestpos + hitbox_offset;
@ -325,8 +324,8 @@ Vector BuildingPrediction(CachedEntity *building, Vector vec, float speed, float
curpos.z = result.z - dtg; curpos.z = result.z - dtg;
} }
float rockettime = g_pLocalPlayer->v_Eye.DistTo(curpos) / speed; float rockettime = g_pLocalPlayer->v_Eye.DistTo(curpos) / speed;
if (debug_pp_rockettimeping) // Compensate for ping
rockettime += g_IEngine->GetNetChannelInfo()->GetLatency(FLOW_OUTGOING); rockettime += g_IEngine->GetNetChannelInfo()->GetLatency(FLOW_OUTGOING) + cl_interp->GetFloat();
if (fabs(rockettime - currenttime) < mindelta) if (fabs(rockettime - currenttime) < mindelta)
{ {
besttime = currenttime; besttime = currenttime;
@ -334,8 +333,8 @@ Vector BuildingPrediction(CachedEntity *building, Vector vec, float speed, float
mindelta = fabs(rockettime - currenttime); mindelta = fabs(rockettime - currenttime);
} }
} }
if (debug_pp_rockettimeping) // Compensate for ping
besttime += g_IEngine->GetNetChannelInfo()->GetLatency(FLOW_OUTGOING); besttime += g_IEngine->GetNetChannelInfo()->GetLatency(FLOW_OUTGOING) + cl_interp->GetFloat();
bestpos.z += (400 * besttime * besttime * gravity); bestpos.z += (400 * besttime * besttime * gravity);
// S = at^2/2 ; t = sqrt(2S/a)*/ // S = at^2/2 ; t = sqrt(2S/a)*/
return bestpos; return bestpos;
@ -395,8 +394,8 @@ Vector ProjectilePrediction(CachedEntity *ent, int hb, float speed, float gravit
} }
float rockettime = g_pLocalPlayer->v_Eye.DistTo(current) / speed; float rockettime = g_pLocalPlayer->v_Eye.DistTo(current) / speed;
if (debug_pp_rockettimeping) // Compensate for ping
rockettime += g_IEngine->GetNetChannelInfo()->GetLatency(FLOW_OUTGOING); rockettime += g_IEngine->GetNetChannelInfo()->GetLatency(FLOW_OUTGOING) + cl_interp->GetFloat();
if (fabs(rockettime - currenttime) < mindelta) if (fabs(rockettime - currenttime) < mindelta)
{ {
besttime = currenttime; besttime = currenttime;
@ -404,8 +403,8 @@ Vector ProjectilePrediction(CachedEntity *ent, int hb, float speed, float gravit
mindelta = fabs(rockettime - currenttime); mindelta = fabs(rockettime - currenttime);
} }
} }
if (debug_pp_rockettimeping) // Compensate for ping
besttime += g_IEngine->GetNetChannelInfo()->GetLatency(FLOW_OUTGOING); besttime += g_IEngine->GetNetChannelInfo()->GetLatency(FLOW_OUTGOING) + cl_interp->GetFloat();
bestpos.z += (sv_gravity->GetFloat() / 2.0f * besttime * besttime * gravitymod); bestpos.z += (sv_gravity->GetFloat() / 2.0f * besttime * besttime * gravitymod);
// S = at^2/2 ; t = sqrt(2S/a)*/ // S = at^2/2 ; t = sqrt(2S/a)*/
Vector result = bestpos + hitbox_offset; Vector result = bestpos + hitbox_offset;