Skip to content

Commit 2a24428

Browse files
committed
increase weapon prediction entity match range
Fix potential issues with duplicate weapon events when firing weapons from very fast moving platforms.
1 parent 89eac84 commit 2a24428

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

code/cgame/cg_predict_weapons.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,36 @@ static qboolean CG_WeaponPredict_CanStickGrenade( int entityNum ) {
409409
return qtrue;
410410
}
411411

412+
/*
413+
================
414+
CG_WeaponPredict_EntitySearchRange
415+
416+
Increase allowed match range for predicted entities and events when moving fast or standing on a
417+
fast mover. This range is just used as a sanity check so it's fine if the values are very rough.
418+
================
419+
*/
420+
static float CG_WeaponPredict_EntitySearchRange( void ) {
421+
int groundEntityNum = cg.predictedPlayerState.groundEntityNum;
422+
float range = 250.0f;
423+
424+
float speed = VectorLength( cg.predictedPlayerState.velocity ) / 8.0f;
425+
if ( speed > range ) {
426+
range = speed;
427+
}
428+
429+
if ( groundEntityNum > 0 && groundEntityNum <= ENTITYNUM_MAX_NORMAL ) {
430+
centity_t *cent = &cg_entities[groundEntityNum];
431+
if ( cent->currentState.eType == ET_MOVER ) {
432+
float speed = VectorLength( cent->currentState.pos.trDelta );
433+
if ( speed > range ) {
434+
range = speed;
435+
}
436+
}
437+
}
438+
439+
return range;
440+
}
441+
412442
/*
413443
================
414444
CG_WeaponPredict_FindMatchingEntity
@@ -627,7 +657,7 @@ static float CG_WeaponPredict_ComparePredictedEvent( const centity_t *cent, void
627657
float origin_delta = ORIGIN2_BASED_EVENT( event ) ? Distance( es->origin2, predicted->origin2 ) :
628658
Distance( es->pos.trBase, predicted->origin );
629659

630-
if ( origin_delta < 250.0f ) {
660+
if ( origin_delta < CG_WeaponPredict_EntitySearchRange() ) {
631661
return origin_delta;
632662
}
633663
}
@@ -1089,7 +1119,7 @@ static float CG_WeaponPredict_ComparePredictedMissile( const centity_t *cent, vo
10891119
dot = 0.5f;
10901120
}
10911121

1092-
if ( deltaOrigin < 250.0f ) {
1122+
if ( deltaOrigin < CG_WeaponPredict_EntitySearchRange() ) {
10931123
// take dot product into account even if deltaOrigin is 0
10941124
return deltaOrigin / dot + ( 10.0f - dot );
10951125
}

0 commit comments

Comments
 (0)