From 2a24428ab6dbac3c9d1b9f7eeeae72a2b19f12a9 Mon Sep 17 00:00:00 2001 From: Noah Metzger Date: Sun, 17 Sep 2023 18:13:51 -0500 Subject: [PATCH] increase weapon prediction entity match range Fix potential issues with duplicate weapon events when firing weapons from very fast moving platforms. --- code/cgame/cg_predict_weapons.c | 34 +++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/code/cgame/cg_predict_weapons.c b/code/cgame/cg_predict_weapons.c index e85d941..1de49d2 100644 --- a/code/cgame/cg_predict_weapons.c +++ b/code/cgame/cg_predict_weapons.c @@ -409,6 +409,36 @@ static qboolean CG_WeaponPredict_CanStickGrenade( int entityNum ) { return qtrue; } +/* +================ +CG_WeaponPredict_EntitySearchRange + +Increase allowed match range for predicted entities and events when moving fast or standing on a +fast mover. This range is just used as a sanity check so it's fine if the values are very rough. +================ +*/ +static float CG_WeaponPredict_EntitySearchRange( void ) { + int groundEntityNum = cg.predictedPlayerState.groundEntityNum; + float range = 250.0f; + + float speed = VectorLength( cg.predictedPlayerState.velocity ) / 8.0f; + if ( speed > range ) { + range = speed; + } + + if ( groundEntityNum > 0 && groundEntityNum <= ENTITYNUM_MAX_NORMAL ) { + centity_t *cent = &cg_entities[groundEntityNum]; + if ( cent->currentState.eType == ET_MOVER ) { + float speed = VectorLength( cent->currentState.pos.trDelta ); + if ( speed > range ) { + range = speed; + } + } + } + + return range; +} + /* ================ CG_WeaponPredict_FindMatchingEntity @@ -627,7 +657,7 @@ static float CG_WeaponPredict_ComparePredictedEvent( const centity_t *cent, void float origin_delta = ORIGIN2_BASED_EVENT( event ) ? Distance( es->origin2, predicted->origin2 ) : Distance( es->pos.trBase, predicted->origin ); - if ( origin_delta < 250.0f ) { + if ( origin_delta < CG_WeaponPredict_EntitySearchRange() ) { return origin_delta; } } @@ -1089,7 +1119,7 @@ static float CG_WeaponPredict_ComparePredictedMissile( const centity_t *cent, vo dot = 0.5f; } - if ( deltaOrigin < 250.0f ) { + if ( deltaOrigin < CG_WeaponPredict_EntitySearchRange() ) { // take dot product into account even if deltaOrigin is 0 return deltaOrigin / dot + ( 10.0f - dot ); }