diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/client/c_gib.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'game/client/c_gib.cpp')
| -rw-r--r-- | game/client/c_gib.cpp | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/game/client/c_gib.cpp b/game/client/c_gib.cpp new file mode 100644 index 0000000..e4941cf --- /dev/null +++ b/game/client/c_gib.cpp @@ -0,0 +1,133 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#include "cbase.h" +#include "vcollide_parse.h" +#include "c_gib.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +//NOTENOTE: This is not yet coupled with the server-side implementation of CGib +// This is only a client-side version of gibs at the moment + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +C_Gib::~C_Gib( void ) +{ + VPhysicsDestroyObject(); +} + +//----------------------------------------------------------------------------- +// Purpose: +// Input : *pszModelName - +// vecOrigin - +// vecForceDir - +// vecAngularImp - +// Output : Returns true on success, false on failure. +//----------------------------------------------------------------------------- +C_Gib *C_Gib::CreateClientsideGib( const char *pszModelName, Vector vecOrigin, Vector vecForceDir, AngularImpulse vecAngularImp, float flLifetime ) +{ + C_Gib *pGib = new C_Gib; + + if ( pGib == NULL ) + return NULL; + + if ( pGib->InitializeGib( pszModelName, vecOrigin, vecForceDir, vecAngularImp, flLifetime ) == false ) + return NULL; + + return pGib; +} + +//----------------------------------------------------------------------------- +// Purpose: +// Input : *pszModelName - +// vecOrigin - +// vecForceDir - +// vecAngularImp - +// Output : Returns true on success, false on failure. +//----------------------------------------------------------------------------- +bool C_Gib::InitializeGib( const char *pszModelName, Vector vecOrigin, Vector vecForceDir, AngularImpulse vecAngularImp, float flLifetime ) +{ + if ( InitializeAsClientEntity( pszModelName, RENDER_GROUP_OPAQUE_ENTITY ) == false ) + { + Release(); + return false; + } + + SetAbsOrigin( vecOrigin ); + SetCollisionGroup( COLLISION_GROUP_DEBRIS ); + + solid_t tmpSolid; + PhysModelParseSolid( tmpSolid, this, GetModelIndex() ); + + m_pPhysicsObject = VPhysicsInitNormal( SOLID_VPHYSICS, 0, false, &tmpSolid ); + + if ( m_pPhysicsObject ) + { + float flForce = m_pPhysicsObject->GetMass(); + vecForceDir *= flForce; + + m_pPhysicsObject->ApplyForceOffset( vecForceDir, GetAbsOrigin() ); + m_pPhysicsObject->SetCallbackFlags( m_pPhysicsObject->GetCallbackFlags() | CALLBACK_GLOBAL_TOUCH | CALLBACK_GLOBAL_TOUCH_STATIC ); + } + else + { + // failed to create a physics object + Release(); + return false; + } + + SetNextClientThink( gpGlobals->curtime + flLifetime ); + + return true; +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void C_Gib::ClientThink( void ) +{ + SetRenderMode( kRenderTransAlpha ); + m_nRenderFX = kRenderFxFadeFast; + + if ( m_clrRender->a == 0 ) + { +#ifdef HL2_CLIENT_DLL + s_AntlionGibManager.RemoveGib( this ); +#endif + Release(); + return; + } + + SetNextClientThink( gpGlobals->curtime + 1.0f ); +} + +//----------------------------------------------------------------------------- +// Purpose: +// Input : *pOther - +//----------------------------------------------------------------------------- +void C_Gib::StartTouch( C_BaseEntity *pOther ) +{ + // Limit the amount of times we can bounce + if ( m_flTouchDelta < gpGlobals->curtime ) + { + HitSurface( pOther ); + m_flTouchDelta = gpGlobals->curtime + 0.1f; + } + + BaseClass::StartTouch( pOther ); +} + +//----------------------------------------------------------------------------- +// Purpose: +// Input : *pOther - +//----------------------------------------------------------------------------- +void C_Gib::HitSurface( C_BaseEntity *pOther ) +{ + //TODO: Implement splatter or effects in child versions +} |