From fafc3554a533f38b84d5e4994b48dc8ea7e217a1 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Wed, 31 Aug 2022 18:22:56 +0300 Subject: [PATCH] game(hl1): fix UTIL_DropToFloor --- game/server/ai_basenpc.cpp | 6 -- game/server/func_break.cpp | 5 +- game/server/hl1/hl1_basecombatweapon.cpp | 55 ++++++++++++++----- game/server/props.cpp | 5 +- game/server/util.cpp | 6 +- game/shared/hl1/hl1_basecombatweapon_shared.h | 1 + game/shared/hl1/hl1mp_weapon_mp5.cpp | 2 +- 7 files changed, 53 insertions(+), 27 deletions(-) diff --git a/game/server/ai_basenpc.cpp b/game/server/ai_basenpc.cpp index 25fbc0c3..0acc458f 100644 --- a/game/server/ai_basenpc.cpp +++ b/game/server/ai_basenpc.cpp @@ -6560,12 +6560,6 @@ float CAI_BaseNPC::ThrowLimit( const Vector &vecStart, //----------------------------------------------------------------------------- void CAI_BaseNPC::SetupVPhysicsHull() { - if( GetModelPtr() == NULL ) - { - UTIL_Remove( this ); - return; - } - if ( GetMoveType() == MOVETYPE_VPHYSICS || GetMoveType() == MOVETYPE_NONE ) return; diff --git a/game/server/func_break.cpp b/game/server/func_break.cpp index b61a8605..4ce31d93 100644 --- a/game/server/func_break.cpp +++ b/game/server/func_break.cpp @@ -1250,10 +1250,9 @@ void CPushable::Spawn( void ) CreateVPhysics(); } -// nillerusr: VALVEWHY? -#if 0 //def HL1_DLL +#ifdef HL1_DLL // Force HL1 Pushables to stay axially aligned. - VPhysicsGetObject()->SetInertia( Vector( 1e30, 1e30, 1e30 ) ); + VPhysicsGetObject()->SetInertia( Vector( 3.f, 3.f, 3.f ) ); #endif//HL1_DLL } diff --git a/game/server/hl1/hl1_basecombatweapon.cpp b/game/server/hl1/hl1_basecombatweapon.cpp index 39a4707c..3bb00c35 100644 --- a/game/server/hl1/hl1_basecombatweapon.cpp +++ b/game/server/hl1/hl1_basecombatweapon.cpp @@ -23,26 +23,46 @@ void CBaseHL1CombatWeapon::Precache() PrecacheScriptSound( "BaseCombatWeapon.WeaponDrop" ); } +bool CBaseHL1CombatWeapon::CreateVPhysics( void ) +{ + VPhysicsInitNormal( SOLID_BBOX, GetSolidFlags() | FSOLID_TRIGGER, false ); + IPhysicsObject *pPhysObj = VPhysicsGetObject(); + if ( pPhysObj ) + { + pPhysObj->SetMass( 30 ); + return true; + } + + return false; +} + + //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CBaseHL1CombatWeapon::FallInit( void ) { SetModel( GetWorldModel() ); - SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); - SetSolid( SOLID_BBOX ); - AddSolidFlags( FSOLID_TRIGGER ); - AddSolidFlags( FSOLID_NOT_SOLID ); + + if( !CreateVPhysics() ) + { + SetSolid( SOLID_BBOX ); + SetMoveType( MOVETYPE_FLYGRAVITY ); + SetSolid( SOLID_BBOX ); + AddSolidFlags( FSOLID_TRIGGER ); + } SetPickupTouch(); - + SetThink( &CBaseHL1CombatWeapon::FallThink ); SetNextThink( gpGlobals->curtime + 0.1f ); // HACKHACK - On ground isn't always set, so look for ground underneath trace_t tr; - UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() - Vector(0,0,2), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr ); + UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() - Vector(0,0,256), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr ); + + SetAbsOrigin( tr.endpos ); if ( tr.fraction < 1.0 ) { @@ -63,7 +83,20 @@ void CBaseHL1CombatWeapon::FallThink ( void ) { SetNextThink( gpGlobals->curtime + 0.1f ); - if ( GetFlags() & FL_ONGROUND ) + bool shouldMaterialize = false; + IPhysicsObject *pPhysics = VPhysicsGetObject(); + if ( pPhysics ) + { + shouldMaterialize = pPhysics->IsAsleep(); + } + else + { + shouldMaterialize = (GetFlags() & FL_ONGROUND) ? true : false; + if( shouldMaterialize ) + SetSize( Vector( -24, -24, 0 ), Vector( 24, 24, 16 ) ); + } + + if ( shouldMaterialize ) { // clatter if we have an owner (i.e., dropped by someone) // don't clatter if the gun is waiting to respawn (if it's waiting, it is invisible!) @@ -73,14 +106,8 @@ void CBaseHL1CombatWeapon::FallThink ( void ) } // lie flat - QAngle ang = GetAbsAngles(); - ang.x = 0; - ang.z = 0; - SetAbsAngles( ang ); - - Materialize(); + Materialize(); - SetSize( Vector( -24, -24, 0 ), Vector( 24, 24, 16 ) ); } } diff --git a/game/server/props.cpp b/game/server/props.cpp index e536447b..5a981687 100644 --- a/game/server/props.cpp +++ b/game/server/props.cpp @@ -5525,6 +5525,7 @@ class CPhysicsPropMultiplayer : public CPhysicsProp, public IMultiplayerPhysics { m_iPhysicsMode = PHYSICS_MULTIPLAYER_AUTODETECT; m_usingCustomCollisionBounds = false; + m_fMass = 0.f; } // IBreakableWithPropData: @@ -5618,8 +5619,8 @@ class CPhysicsPropMultiplayer : public CPhysicsProp, public IMultiplayerPhysics SetCollisionGroup( COLLISION_GROUP_DEBRIS ); } - if(VPhysicsGetObject()) - m_fMass = VPhysicsGetObject()->GetMass(); + if(VPhysicsGetObject()) + m_fMass = VPhysicsGetObject()->GetMass(); // VPhysicsGetObject() is NULL on the client, which prevents the client from finding a decent // AABB surrounding the collision bounds. If we've got a VPhysicsGetObject()->GetCollide(), we'll diff --git a/game/server/util.cpp b/game/server/util.cpp index 4a1144e7..974ddf8d 100644 --- a/game/server/util.cpp +++ b/game/server/util.cpp @@ -352,8 +352,12 @@ int UTIL_DropToFloor( CBaseEntity *pEntity, unsigned int mask, CBaseEntity *pIgn return -1; #endif // HL2MP - UTIL_TraceEntity( pEntity, pEntity->GetAbsOrigin(), pEntity->GetAbsOrigin() - Vector(0,0,256), mask, pIgnore, pEntity->GetCollisionGroup(), &trace ); + UTIL_TraceEntity( pEntity, pEntity->GetAbsOrigin() + Vector(0,0,1), pEntity->GetAbsOrigin() - Vector(0,0,256), mask, pIgnore, pEntity->GetCollisionGroup(), &trace ); +#ifdef HL1_DLL + if( fabs(pEntity->GetAbsOrigin().z - trace.endpos.z) <= 2.f ) + return -1; +#endif if (trace.allsolid) return -1; diff --git a/game/shared/hl1/hl1_basecombatweapon_shared.h b/game/shared/hl1/hl1_basecombatweapon_shared.h index 48d209d2..9bd0ac82 100644 --- a/game/shared/hl1/hl1_basecombatweapon_shared.h +++ b/game/shared/hl1/hl1_basecombatweapon_shared.h @@ -35,6 +35,7 @@ public: void FallInit( void ); // prepare to fall to the ground virtual void FallThink( void ); // make the weapon fall to the ground after spawning + bool CreateVPhysics( void ); void EjectShell( CBaseEntity *pPlayer, int iType ); diff --git a/game/shared/hl1/hl1mp_weapon_mp5.cpp b/game/shared/hl1/hl1mp_weapon_mp5.cpp index b9fbbb7a..f0bf3511 100644 --- a/game/shared/hl1/hl1mp_weapon_mp5.cpp +++ b/game/shared/hl1/hl1mp_weapon_mp5.cpp @@ -125,7 +125,7 @@ void CWeaponMP5::PrimaryAttack( void ) EjectShell( pPlayer, 0 ); - pPlayer->ViewPunch( QAngle( -1, 0, 0 ) ); + pPlayer->ViewPunch( QAngle( random->RandomFloat( -0.5f, 0.5f ), 0, 0 ) ); #ifdef CLIENT_DLL pPlayer->DoMuzzleFlash(); #else