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.

163 lines
4.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: A clientside, visual only model that's positioned relative to players
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "c_playerrelativemodel.h"
  8. //-----------------------------------------------------------------------------
  9. // Purpose:
  10. //-----------------------------------------------------------------------------
  11. C_PlayerRelativeModel *C_PlayerRelativeModel::Create( const char *pszModelName, C_BaseEntity *pParent, Vector vecOffset, QAngle angleOffset, float flAnimSpeed, float flLifetime, int iFlags )
  12. {
  13. C_PlayerRelativeModel *pFlash = new C_PlayerRelativeModel;
  14. if ( !pFlash )
  15. return NULL;
  16. if ( !pFlash->Initialize( pszModelName, pParent, vecOffset, angleOffset, flAnimSpeed, flLifetime, iFlags ) )
  17. return NULL;
  18. return pFlash;
  19. }
  20. //-----------------------------------------------------------------------------
  21. // Purpose:
  22. //-----------------------------------------------------------------------------
  23. bool C_PlayerRelativeModel::Initialize( const char *pszModelName, C_BaseEntity *pParent, Vector vecOffset, QAngle angleOffset, float flAnimSpeed, float flLifetime, int iFlags )
  24. {
  25. AddEffects( EF_NORECEIVESHADOW | EF_NOSHADOW );
  26. if ( InitializeAsClientEntity( pszModelName, RENDER_GROUP_OPAQUE_ENTITY ) == false )
  27. {
  28. Release();
  29. return false;
  30. }
  31. m_vecOffsetPos = vecOffset;
  32. m_angleOffset = angleOffset;
  33. SetParent( pParent, 0 );
  34. SetLocalOrigin( vec3_origin );
  35. SetLocalAngles( vec3_angle );
  36. AddSolidFlags( FSOLID_NOT_SOLID );
  37. SetLifetime( flLifetime );
  38. SetNextClientThink( CLIENT_THINK_ALWAYS );
  39. SetCycle( 0 );
  40. m_qOffsetRotation = vec3_angle;
  41. m_flAnimSpeed = flAnimSpeed;
  42. m_iFlags = iFlags;
  43. return true;
  44. }
  45. //-----------------------------------------------------------------------------
  46. // Purpose:
  47. //-----------------------------------------------------------------------------
  48. void C_PlayerRelativeModel::SetLifetime( float flLifetime )
  49. {
  50. if ( flLifetime == PRM_PERMANENT )
  51. {
  52. m_flExpiresAt = PRM_PERMANENT;
  53. }
  54. else
  55. {
  56. // Expire when the lifetime is up
  57. m_flExpiresAt = gpGlobals->curtime + flLifetime;
  58. }
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose:
  62. //-----------------------------------------------------------------------------
  63. void C_PlayerRelativeModel::ClientThink( void )
  64. {
  65. if ( !GetMoveParent() || (m_flExpiresAt != PRM_PERMANENT && gpGlobals->curtime > m_flExpiresAt) )
  66. {
  67. Release();
  68. return;
  69. }
  70. // Animate
  71. C_BaseEntity *pParent = GetMoveParent();
  72. Vector out(0, 0, 0);
  73. if ( m_iFlags & PRM_SPIN_Z )
  74. {
  75. m_qOffsetRotation += QAngle(0, gpGlobals->frametime * m_flAnimSpeed, 0);
  76. VectorRotate( m_vecOffsetPos, m_qOffsetRotation, out );
  77. }
  78. SetAbsOrigin( pParent->GetAbsOrigin() + out );
  79. SetAbsAngles( m_qOffsetRotation + m_angleOffset );
  80. }
  81. //-----------------------------------------------------------------------------
  82. // C_MerasmusBombEffect
  83. //-----------------------------------------------------------------------------
  84. C_MerasmusBombEffect *C_MerasmusBombEffect::Create( const char *pszModelName, C_TFPlayer *pParent, Vector vecOffset, QAngle angleOffset, float flAnimSpeed, float flLifetime, int iFlags )
  85. {
  86. C_MerasmusBombEffect *pFlash = new C_MerasmusBombEffect;
  87. if ( !pFlash )
  88. return NULL;
  89. if ( !pFlash->Initialize( pszModelName, pParent, vecOffset, angleOffset, flAnimSpeed, flLifetime, iFlags ) )
  90. return NULL;
  91. return pFlash;
  92. }
  93. //-----------------------------------------------------------------------------
  94. bool C_MerasmusBombEffect::Initialize( const char *pszModelName, C_TFPlayer *pParent, Vector vecOffset, QAngle angleOffset, float flAnimSpeed, float flLifetime, int iFlags )
  95. {
  96. if ( !BaseClass::Initialize(pszModelName, pParent, vecOffset, angleOffset, flAnimSpeed, flLifetime, iFlags ) )
  97. return false;
  98. // Create a particle effect
  99. const char *pszEffectName = "bombonomicon_spell_trail";
  100. if ( m_pBombonomiconBeam )
  101. {
  102. m_pBombonomiconBeam->StopEmission();
  103. m_pBombonomiconBeam = NULL;
  104. }
  105. if ( m_pBombonomiconEffect )
  106. {
  107. m_pBombonomiconEffect->StopEmission();
  108. m_pBombonomiconEffect = NULL;
  109. }
  110. m_pBombonomiconBeam = ParticleProp()->Create( pszEffectName, PATTACH_ABSORIGIN_FOLLOW, INVALID_PARTICLE_ATTACHMENT, Vector(0,0,-10) );
  111. if ( m_pBombonomiconBeam )
  112. {
  113. ParticleProp()->AddControlPoint( m_pBombonomiconBeam, 1, pParent, PATTACH_POINT_FOLLOW, "head", Vector(0,0,0) );
  114. }
  115. return true;
  116. }
  117. //-----------------------------------------------------------------------------
  118. void C_MerasmusBombEffect::ClientThink( void )
  119. {
  120. if ( !GetMoveParent() || (m_flExpiresAt != PRM_PERMANENT && gpGlobals->curtime > m_flExpiresAt) )
  121. {
  122. if ( m_pBombonomiconBeam )
  123. {
  124. m_pBombonomiconBeam->StopEmission();
  125. m_pBombonomiconBeam = NULL;
  126. }
  127. if ( m_pBombonomiconEffect )
  128. {
  129. m_pBombonomiconEffect->StopEmission();
  130. m_pBombonomiconEffect = NULL;
  131. }
  132. }
  133. BaseClass::ClientThink();
  134. }