Counter Strike : Global Offensive Source Code
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.

180 lines
4.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "tesla.h"
  8. #include "te_effect_dispatch.h"
  9. #include "sendproxy.h"
  10. #include "engine/IEngineSound.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. LINK_ENTITY_TO_CLASS( point_tesla, CTesla );
  14. BEGIN_DATADESC( CTesla )
  15. DEFINE_KEYFIELD( m_SourceEntityName,FIELD_STRING, "m_SourceEntityName" ),
  16. DEFINE_KEYFIELD( m_SoundName, FIELD_STRING, "m_SoundName" ),
  17. DEFINE_KEYFIELD( m_iszSpriteName, FIELD_STRING, "texture" ),
  18. DEFINE_KEYFIELD( m_Color, FIELD_COLOR32, "m_Color" ),
  19. DEFINE_KEYFIELD( m_flRadius, FIELD_FLOAT, "m_flRadius" ),
  20. //DEFINE_ARRAY( m_flThickness, FIELD_FLOAT, 2 ),
  21. DEFINE_KEYFIELD( m_flThickness[0], FIELD_FLOAT, "thick_min" ),
  22. DEFINE_KEYFIELD( m_flThickness[1], FIELD_FLOAT, "thick_max" ),
  23. //DEFINE_ARRAY( m_flTimeVisible, FIELD_FLOAT, 2 ),
  24. DEFINE_KEYFIELD( m_flTimeVisible[0],FIELD_FLOAT, "lifetime_min" ),
  25. DEFINE_KEYFIELD( m_flTimeVisible[1],FIELD_FLOAT, "lifetime_max" ),
  26. //DEFINE_ARRAY( m_flArcInterval, FIELD_FLOAT, 2 ),
  27. DEFINE_KEYFIELD( m_flArcInterval[0],FIELD_FLOAT, "interval_min" ),
  28. DEFINE_KEYFIELD( m_flArcInterval[1],FIELD_FLOAT, "interval_max" ),
  29. //DEFINE_ARRAY( m_NumBeams, FIELD_INTEGER, 2 ),
  30. DEFINE_KEYFIELD( m_NumBeams[0], FIELD_INTEGER, "beamcount_min" ),
  31. DEFINE_KEYFIELD( m_NumBeams[1], FIELD_INTEGER, "beamcount_max" ),
  32. DEFINE_KEYFIELD( m_bOn, FIELD_BOOLEAN, "m_bOn" ),
  33. DEFINE_INPUTFUNC( FIELD_VOID, "TurnOn", InputTurnOn ),
  34. DEFINE_INPUTFUNC( FIELD_VOID, "TurnOff", InputTurnOff ),
  35. DEFINE_INPUTFUNC( FIELD_VOID, "DoSpark", InputDoSpark ),
  36. DEFINE_FUNCTION( ShootArcThink )
  37. END_DATADESC()
  38. IMPLEMENT_SERVERCLASS_ST( CTesla, DT_Tesla )
  39. SendPropStringT( SENDINFO( m_SoundName ) ),
  40. SendPropStringT( SENDINFO( m_iszSpriteName ) )
  41. END_SEND_TABLE()
  42. CTesla::CTesla()
  43. {
  44. m_SourceEntityName = NULL_STRING;
  45. m_SoundName = NULL_STRING;
  46. m_iszSpriteName = NULL_STRING;
  47. m_NumBeams[0] = m_NumBeams[1] = 6;
  48. m_flRadius = 200;
  49. m_flThickness[0] = m_flThickness[1] = 5;
  50. m_flTimeVisible[0] = 0.3;
  51. m_flTimeVisible[1] = 0.55;
  52. m_flArcInterval[0] = m_flArcInterval[1] = 0.5;
  53. AddEFlags( EFL_FORCE_CHECK_TRANSMIT );
  54. }
  55. void CTesla::Spawn()
  56. {
  57. if ( m_iszSpriteName.Get() == NULL_STRING )
  58. {
  59. m_iszSpriteName = AllocPooledString("sprites/physbeam.vmt");
  60. }
  61. Precache();
  62. BaseClass::Spawn();
  63. }
  64. void CTesla::Activate()
  65. {
  66. BaseClass::Activate();
  67. SetThink( &CTesla::ShootArcThink );
  68. SetupForNextArc();
  69. }
  70. void CTesla::Precache()
  71. {
  72. PrecacheModel( STRING(m_iszSpriteName.Get()) );
  73. BaseClass::Precache();
  74. PrecacheScriptSound( STRING( m_SoundName.Get() ) );
  75. }
  76. void CTesla::SetupForNextArc()
  77. {
  78. if (m_bOn)
  79. {
  80. float flTimeToNext = RandomFloat( m_flArcInterval[0], m_flArcInterval[1] );
  81. SetNextThink( gpGlobals->curtime + flTimeToNext );
  82. }
  83. else
  84. {
  85. SetNextThink( TICK_NEVER_THINK );
  86. }
  87. }
  88. CBaseEntity* CTesla::GetSourceEntity()
  89. {
  90. if ( m_SourceEntityName != NULL_STRING )
  91. {
  92. CBaseEntity *pRet = gEntList.FindEntityByName( NULL, m_SourceEntityName );
  93. if ( pRet )
  94. return pRet;
  95. }
  96. return this;
  97. }
  98. void CTesla::ShootArcThink()
  99. {
  100. DoSpark();
  101. SetupForNextArc();
  102. }
  103. void CTesla::DoSpark()
  104. {
  105. // Shoot out an arc.
  106. EntityMessageBegin( this );
  107. CBaseEntity *pEnt = GetSourceEntity();
  108. WRITE_VEC3COORD( pEnt->GetAbsOrigin() );
  109. WRITE_SHORT( pEnt->entindex() );
  110. WRITE_FLOAT( m_flRadius );
  111. WRITE_BYTE( m_Color.r );
  112. WRITE_BYTE( m_Color.g );
  113. WRITE_BYTE( m_Color.b );
  114. WRITE_BYTE( m_Color.a );
  115. WRITE_CHAR( RandomInt( m_NumBeams[0], m_NumBeams[1] ) );
  116. WRITE_FLOAT( RandomFloat( m_flThickness[0], m_flThickness[1] ) );
  117. WRITE_FLOAT( RandomFloat( m_flTimeVisible[0], m_flTimeVisible[1] ) );
  118. MessageEnd();
  119. }
  120. void CTesla::InputDoSpark( inputdata_t &inputdata )
  121. {
  122. DoSpark();
  123. }
  124. void CTesla::InputTurnOn( inputdata_t &inputdata )
  125. {
  126. m_bOn = true;
  127. SetupForNextArc();
  128. }
  129. void CTesla::InputTurnOff( inputdata_t &inputdata )
  130. {
  131. m_bOn = false;
  132. SetupForNextArc();
  133. }