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.

109 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "grenadetrail.h"
  10. #include "dt_send.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. #define GRENADETRAIL_ENTITYNAME "env_grenadetrail"
  14. //-----------------------------------------------------------------------------
  15. //Data table
  16. //-----------------------------------------------------------------------------
  17. IMPLEMENT_SERVERCLASS_ST(CGrenadeTrail, DT_GrenadeTrail)
  18. SendPropFloat(SENDINFO(m_SpawnRate), 8, 0, 1, 1024),
  19. SendPropFloat(SENDINFO(m_ParticleLifetime), 16, SPROP_ROUNDUP, 0.1, 100),
  20. SendPropFloat(SENDINFO(m_StopEmitTime), 0, SPROP_NOSCALE),
  21. SendPropBool(SENDINFO(m_bEmit) ),
  22. SendPropInt(SENDINFO(m_nAttachment), 32 ),
  23. END_SEND_TABLE()
  24. BEGIN_DATADESC( CGrenadeTrail )
  25. DEFINE_KEYFIELD( m_SpawnRate, FIELD_FLOAT, "spawnrate" ),
  26. DEFINE_KEYFIELD( m_ParticleLifetime, FIELD_FLOAT, "lifetime" ),
  27. DEFINE_FIELD( m_StopEmitTime, FIELD_TIME ),
  28. DEFINE_FIELD( m_bEmit, FIELD_BOOLEAN ),
  29. DEFINE_FIELD( m_nAttachment, FIELD_INTEGER ),
  30. END_DATADESC()
  31. LINK_ENTITY_TO_CLASS(env_grenadetrail, CGrenadeTrail);
  32. //-----------------------------------------------------------------------------
  33. // Purpose:
  34. // Output :
  35. //-----------------------------------------------------------------------------
  36. CGrenadeTrail::CGrenadeTrail()
  37. {
  38. m_SpawnRate = 10;
  39. m_ParticleLifetime = 5;
  40. m_StopEmitTime = 0; // Don't stop emitting particles
  41. m_bEmit = true;
  42. m_nAttachment = 0;
  43. }
  44. //-----------------------------------------------------------------------------
  45. // Purpose :
  46. // Input :
  47. // Output :
  48. //-----------------------------------------------------------------------------
  49. void CGrenadeTrail::SetEmit(bool bVal)
  50. {
  51. m_bEmit = bVal;
  52. }
  53. //-----------------------------------------------------------------------------
  54. // Purpose:
  55. // Output : CGrenadeTrail*
  56. //-----------------------------------------------------------------------------
  57. CGrenadeTrail* CGrenadeTrail::CreateGrenadeTrail()
  58. {
  59. CBaseEntity *pEnt = CreateEntityByName(GRENADETRAIL_ENTITYNAME);
  60. if(pEnt)
  61. {
  62. CGrenadeTrail *pTrail = dynamic_cast<CGrenadeTrail*>(pEnt);
  63. if(pTrail)
  64. {
  65. pTrail->Activate();
  66. return pTrail;
  67. }
  68. else
  69. {
  70. UTIL_Remove(pEnt);
  71. }
  72. }
  73. return NULL;
  74. }
  75. //-----------------------------------------------------------------------------
  76. // Purpose: Attach the smoke trail to an entity or point
  77. // Input : index - entity that has the attachment
  78. // attachment - point to attach to
  79. //-----------------------------------------------------------------------------
  80. void CGrenadeTrail::FollowEntity( CBaseEntity *pEntity, const char *pAttachmentName )
  81. {
  82. // For attachments
  83. if ( pAttachmentName && pEntity && pEntity->GetBaseAnimating() )
  84. {
  85. m_nAttachment = pEntity->GetBaseAnimating()->LookupAttachment( pAttachmentName );
  86. }
  87. else
  88. {
  89. m_nAttachment = 0;
  90. }
  91. BaseClass::FollowEntity( pEntity );
  92. }