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.

125 lines
2.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #include "cbase.h"
  10. #include "basetempentity.h"
  11. #include "event_tempentity_tester.h"
  12. #include "tier1/strtools.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. #define TEMPENT_TEST_GAP 1.0f
  16. //-----------------------------------------------------------------------------
  17. // Purpose:
  18. // Input : &vecOrigin -
  19. // &vecAngles -
  20. // *single_te -
  21. // Output : CBaseEntity
  22. //-----------------------------------------------------------------------------
  23. CBaseEntity *CTempEntTester::Create( const Vector &vecOrigin, const QAngle &vecAngles, const char *lifetime, const char *single_te )
  24. {
  25. float life;
  26. char classname[ 128 ];
  27. if ( lifetime && lifetime[0] )
  28. {
  29. life = atoi( lifetime );
  30. life = MAX( 1.0, life );
  31. life = MIN( 1000.0, life );
  32. life += gpGlobals->curtime;
  33. }
  34. else
  35. {
  36. Msg( "Usage: te <lifetime> <entname>\n" );
  37. return NULL;
  38. }
  39. if ( single_te && single_te[0] )
  40. {
  41. Q_strncpy( classname, single_te ,sizeof(classname));
  42. strlwr( classname );
  43. }
  44. else
  45. {
  46. Msg( "Usage: te <lifetime> <entname>\n" );
  47. return NULL;
  48. }
  49. CTempEntTester *p = ( CTempEntTester * )CBaseEntity::CreateNoSpawn( "te_tester", vecOrigin, vecAngles );
  50. if ( !p )
  51. {
  52. return NULL;
  53. }
  54. Q_strncpy( p->m_szClass, classname ,sizeof(p->m_szClass));
  55. p->m_fLifeTime = life;
  56. p->Spawn();
  57. return p;
  58. }
  59. LINK_ENTITY_TO_CLASS( te_tester, CTempEntTester );
  60. //-----------------------------------------------------------------------------
  61. // Purpose: Called when object is being created
  62. //-----------------------------------------------------------------------------
  63. void CTempEntTester::Spawn( void )
  64. {
  65. // Not a physical thing...
  66. AddEffects( EF_NODRAW );
  67. m_pCurrent = CBaseTempEntity::GetList();
  68. while ( m_pCurrent )
  69. {
  70. char name[ 128 ];
  71. Q_strncpy( name, m_pCurrent->GetName() ,sizeof(name));
  72. strlwr( name );
  73. if ( strstr( name, m_szClass ) )
  74. {
  75. break;
  76. }
  77. m_pCurrent = m_pCurrent->GetNext();
  78. }
  79. if ( !m_pCurrent )
  80. {
  81. DevMsg("Couldn't find temp entity '%s'\n", m_szClass );
  82. UTIL_Remove( this );
  83. return;
  84. }
  85. // Think right away
  86. SetNextThink( gpGlobals->curtime );
  87. }
  88. //-----------------------------------------------------------------------------
  89. // Purpose: Called when object should fire itself and move on
  90. //-----------------------------------------------------------------------------
  91. void CTempEntTester::Think( void )
  92. {
  93. // Should never happen
  94. if ( !m_pCurrent )
  95. {
  96. UTIL_Remove( this );
  97. return;
  98. }
  99. m_pCurrent->Test( GetLocalOrigin(), GetLocalAngles() );
  100. SetNextThink( gpGlobals->curtime + TEMPENT_TEST_GAP );
  101. // Time to destroy?
  102. if ( gpGlobals->curtime >= m_fLifeTime )
  103. {
  104. UTIL_Remove( this );
  105. return;
  106. }
  107. }