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.

182 lines
4.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implements hurting point entity
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "entitylist.h"
  9. #include "gamerules.h"
  10. #include "basecombatcharacter.h"
  11. #include "ammodef.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. const int SF_PHURT_START_ON = 1;
  15. class CPointHurt : public CPointEntity
  16. {
  17. DECLARE_CLASS( CPointHurt, CPointEntity );
  18. public:
  19. void Spawn( void );
  20. void Precache( void );
  21. void HurtThink( void );
  22. // Input handlers
  23. void InputTurnOn(inputdata_t &inputdata);
  24. void InputTurnOff(inputdata_t &inputdata);
  25. void InputToggle(inputdata_t &inputdata);
  26. void InputHurt(inputdata_t &inputdata);
  27. DECLARE_DATADESC();
  28. int m_nDamage;
  29. int m_bitsDamageType;
  30. float m_flRadius;
  31. float m_flDelay;
  32. string_t m_strTarget;
  33. EHANDLE m_pActivator;
  34. };
  35. BEGIN_DATADESC( CPointHurt )
  36. DEFINE_KEYFIELD( m_flRadius, FIELD_FLOAT, "DamageRadius" ),
  37. DEFINE_KEYFIELD( m_nDamage, FIELD_INTEGER, "Damage" ),
  38. DEFINE_KEYFIELD( m_flDelay, FIELD_FLOAT, "DamageDelay" ),
  39. DEFINE_KEYFIELD( m_bitsDamageType, FIELD_INTEGER, "DamageType" ),
  40. DEFINE_KEYFIELD( m_strTarget, FIELD_STRING, "DamageTarget" ),
  41. // Function Pointers
  42. DEFINE_FUNCTION( HurtThink ),
  43. // Inputs
  44. DEFINE_INPUTFUNC( FIELD_VOID, "TurnOn", InputTurnOn ),
  45. DEFINE_INPUTFUNC( FIELD_VOID, "TurnOff", InputTurnOff ),
  46. DEFINE_INPUTFUNC( FIELD_VOID, "Toggle", InputToggle ),
  47. DEFINE_INPUTFUNC( FIELD_VOID, "Hurt", InputHurt ),
  48. DEFINE_FIELD( m_pActivator, FIELD_EHANDLE ),
  49. END_DATADESC()
  50. LINK_ENTITY_TO_CLASS( point_hurt, CPointHurt );
  51. //-----------------------------------------------------------------------------
  52. // Purpose:
  53. //-----------------------------------------------------------------------------
  54. void CPointHurt::Spawn(void)
  55. {
  56. SetThink( NULL );
  57. SetUse( NULL );
  58. m_pActivator = NULL;
  59. if ( HasSpawnFlags( SF_PHURT_START_ON ) )
  60. {
  61. SetThink( &CPointHurt::HurtThink );
  62. }
  63. SetNextThink( gpGlobals->curtime + 0.1f );
  64. if ( m_flRadius <= 0.0f )
  65. {
  66. m_flRadius = 128.0f;
  67. }
  68. if ( m_nDamage <= 0 )
  69. {
  70. m_nDamage = 2;
  71. }
  72. if ( m_flDelay <= 0 )
  73. {
  74. m_flDelay = 0.1f;
  75. }
  76. Precache();
  77. }
  78. //-----------------------------------------------------------------------------
  79. // Purpose:
  80. //-----------------------------------------------------------------------------
  81. void CPointHurt::Precache( void )
  82. {
  83. BaseClass::Precache();
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Purpose:
  87. //-----------------------------------------------------------------------------
  88. void CPointHurt::HurtThink( void )
  89. {
  90. if ( m_strTarget != NULL_STRING )
  91. {
  92. CBaseEntity *pEnt = NULL;
  93. CTakeDamageInfo info( this, m_pActivator, m_nDamage, m_bitsDamageType );
  94. while ( ( pEnt = gEntList.FindEntityByName( pEnt, m_strTarget, NULL, m_pActivator ) ) != NULL )
  95. {
  96. GuessDamageForce( &info, (pEnt->GetAbsOrigin() - GetAbsOrigin()), pEnt->GetAbsOrigin() );
  97. pEnt->TakeDamage( info );
  98. }
  99. }
  100. else
  101. {
  102. RadiusDamage( CTakeDamageInfo( this, this, m_nDamage, m_bitsDamageType ), GetAbsOrigin(), m_flRadius, CLASS_NONE, NULL );
  103. }
  104. SetNextThink( gpGlobals->curtime + m_flDelay );
  105. }
  106. //-----------------------------------------------------------------------------
  107. // Purpose: Input handler for turning on the point hurt.
  108. //-----------------------------------------------------------------------------
  109. void CPointHurt::InputTurnOn( inputdata_t &data )
  110. {
  111. SetThink( &CPointHurt::HurtThink );
  112. SetNextThink( gpGlobals->curtime + 0.1f );
  113. m_pActivator = data.pActivator;
  114. }
  115. //-----------------------------------------------------------------------------
  116. // Purpose: Input handler for turning off the point hurt.
  117. //-----------------------------------------------------------------------------
  118. void CPointHurt::InputTurnOff( inputdata_t &data )
  119. {
  120. SetThink( NULL );
  121. m_pActivator = data.pActivator;
  122. }
  123. //-----------------------------------------------------------------------------
  124. // Purpose: Input handler for toggling the on/off state of the point hurt.
  125. //-----------------------------------------------------------------------------
  126. void CPointHurt::InputToggle( inputdata_t &data )
  127. {
  128. m_pActivator = data.pActivator;
  129. if ( m_pfnThink == (void (CBaseEntity::*)())&CPointHurt::HurtThink )
  130. {
  131. SetThink( NULL );
  132. }
  133. else
  134. {
  135. SetThink( &CPointHurt::HurtThink );
  136. }
  137. }
  138. //-----------------------------------------------------------------------------
  139. // Purpose: Input handler for instantaneously hurting whatever is near us.
  140. //-----------------------------------------------------------------------------
  141. void CPointHurt::InputHurt( inputdata_t &data )
  142. {
  143. m_pActivator = data.pActivator;
  144. HurtThink();
  145. }