Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "vcollide_parse.h"
  8. #include "c_gib.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. //NOTENOTE: This is not yet coupled with the server-side implementation of CGib
  12. // This is only a client-side version of gibs at the moment
  13. //-----------------------------------------------------------------------------
  14. // Purpose:
  15. //-----------------------------------------------------------------------------
  16. C_Gib::~C_Gib( void )
  17. {
  18. VPhysicsDestroyObject();
  19. }
  20. //-----------------------------------------------------------------------------
  21. // Purpose:
  22. // Input : *pszModelName -
  23. // vecOrigin -
  24. // vecForceDir -
  25. // vecAngularImp -
  26. // Output : Returns true on success, false on failure.
  27. //-----------------------------------------------------------------------------
  28. C_Gib *C_Gib::CreateClientsideGib( const char *pszModelName, Vector vecOrigin, Vector vecForceDir, AngularImpulse vecAngularImp, float flLifetime )
  29. {
  30. C_Gib *pGib = new C_Gib;
  31. if ( pGib == NULL )
  32. return NULL;
  33. if ( pGib->InitializeGib( pszModelName, vecOrigin, vecForceDir, vecAngularImp, flLifetime ) == false )
  34. return NULL;
  35. return pGib;
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Purpose:
  39. // Input : *pszModelName -
  40. // vecOrigin -
  41. // vecForceDir -
  42. // vecAngularImp -
  43. // Output : Returns true on success, false on failure.
  44. //-----------------------------------------------------------------------------
  45. bool C_Gib::InitializeGib( const char *pszModelName, Vector vecOrigin, Vector vecForceDir, AngularImpulse vecAngularImp, float flLifetime )
  46. {
  47. if ( InitializeAsClientEntity( pszModelName, RENDER_GROUP_OPAQUE_ENTITY ) == false )
  48. {
  49. Release();
  50. return false;
  51. }
  52. SetAbsOrigin( vecOrigin );
  53. SetCollisionGroup( COLLISION_GROUP_DEBRIS );
  54. solid_t tmpSolid;
  55. PhysModelParseSolid( tmpSolid, this, GetModelIndex() );
  56. m_pPhysicsObject = VPhysicsInitNormal( SOLID_VPHYSICS, 0, false, &tmpSolid );
  57. if ( m_pPhysicsObject )
  58. {
  59. float flForce = m_pPhysicsObject->GetMass();
  60. vecForceDir *= flForce;
  61. m_pPhysicsObject->ApplyForceOffset( vecForceDir, GetAbsOrigin() );
  62. m_pPhysicsObject->SetCallbackFlags( m_pPhysicsObject->GetCallbackFlags() | CALLBACK_GLOBAL_TOUCH | CALLBACK_GLOBAL_TOUCH_STATIC );
  63. }
  64. else
  65. {
  66. // failed to create a physics object
  67. Release();
  68. return false;
  69. }
  70. SetNextClientThink( gpGlobals->curtime + flLifetime );
  71. return true;
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Purpose:
  75. //-----------------------------------------------------------------------------
  76. void C_Gib::ClientThink( void )
  77. {
  78. SetRenderMode( kRenderTransAlpha );
  79. m_nRenderFX = kRenderFxFadeFast;
  80. if ( m_clrRender->a == 0 )
  81. {
  82. #ifdef HL2_CLIENT_DLL
  83. s_AntlionGibManager.RemoveGib( this );
  84. #endif
  85. Release();
  86. return;
  87. }
  88. SetNextClientThink( gpGlobals->curtime + 1.0f );
  89. }
  90. //-----------------------------------------------------------------------------
  91. // Purpose:
  92. // Input : *pOther -
  93. //-----------------------------------------------------------------------------
  94. void C_Gib::StartTouch( C_BaseEntity *pOther )
  95. {
  96. // Limit the amount of times we can bounce
  97. if ( m_flTouchDelta < gpGlobals->curtime )
  98. {
  99. HitSurface( pOther );
  100. m_flTouchDelta = gpGlobals->curtime + 0.1f;
  101. }
  102. BaseClass::StartTouch( pOther );
  103. }
  104. //-----------------------------------------------------------------------------
  105. // Purpose:
  106. // Input : *pOther -
  107. //-----------------------------------------------------------------------------
  108. void C_Gib::HitSurface( C_BaseEntity *pOther )
  109. {
  110. //TODO: Implement splatter or effects in child versions
  111. }