summaryrefslogtreecommitdiff
path: root/game/server/pointhurt.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/server/pointhurt.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/server/pointhurt.cpp')
-rw-r--r--game/server/pointhurt.cpp182
1 files changed, 182 insertions, 0 deletions
diff --git a/game/server/pointhurt.cpp b/game/server/pointhurt.cpp
new file mode 100644
index 0000000..137f043
--- /dev/null
+++ b/game/server/pointhurt.cpp
@@ -0,0 +1,182 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose: Implements hurting point entity
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#include "cbase.h"
+#include "entitylist.h"
+#include "gamerules.h"
+#include "basecombatcharacter.h"
+#include "ammodef.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+const int SF_PHURT_START_ON = 1;
+
+class CPointHurt : public CPointEntity
+{
+ DECLARE_CLASS( CPointHurt, CPointEntity );
+
+public:
+ void Spawn( void );
+ void Precache( void );
+ void HurtThink( void );
+
+ // Input handlers
+ void InputTurnOn(inputdata_t &inputdata);
+ void InputTurnOff(inputdata_t &inputdata);
+ void InputToggle(inputdata_t &inputdata);
+ void InputHurt(inputdata_t &inputdata);
+
+ DECLARE_DATADESC();
+
+ int m_nDamage;
+ int m_bitsDamageType;
+ float m_flRadius;
+ float m_flDelay;
+ string_t m_strTarget;
+ EHANDLE m_pActivator;
+};
+
+BEGIN_DATADESC( CPointHurt )
+
+ DEFINE_KEYFIELD( m_flRadius, FIELD_FLOAT, "DamageRadius" ),
+ DEFINE_KEYFIELD( m_nDamage, FIELD_INTEGER, "Damage" ),
+ DEFINE_KEYFIELD( m_flDelay, FIELD_FLOAT, "DamageDelay" ),
+ DEFINE_KEYFIELD( m_bitsDamageType, FIELD_INTEGER, "DamageType" ),
+ DEFINE_KEYFIELD( m_strTarget, FIELD_STRING, "DamageTarget" ),
+
+ // Function Pointers
+ DEFINE_FUNCTION( HurtThink ),
+
+ // Inputs
+ DEFINE_INPUTFUNC( FIELD_VOID, "TurnOn", InputTurnOn ),
+ DEFINE_INPUTFUNC( FIELD_VOID, "TurnOff", InputTurnOff ),
+ DEFINE_INPUTFUNC( FIELD_VOID, "Toggle", InputToggle ),
+ DEFINE_INPUTFUNC( FIELD_VOID, "Hurt", InputHurt ),
+
+ DEFINE_FIELD( m_pActivator, FIELD_EHANDLE ),
+
+END_DATADESC()
+
+LINK_ENTITY_TO_CLASS( point_hurt, CPointHurt );
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CPointHurt::Spawn(void)
+{
+ SetThink( NULL );
+ SetUse( NULL );
+
+ m_pActivator = NULL;
+
+ if ( HasSpawnFlags( SF_PHURT_START_ON ) )
+ {
+ SetThink( &CPointHurt::HurtThink );
+ }
+
+ SetNextThink( gpGlobals->curtime + 0.1f );
+
+ if ( m_flRadius <= 0.0f )
+ {
+ m_flRadius = 128.0f;
+ }
+
+ if ( m_nDamage <= 0 )
+ {
+ m_nDamage = 2;
+ }
+
+ if ( m_flDelay <= 0 )
+ {
+ m_flDelay = 0.1f;
+ }
+
+ Precache();
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CPointHurt::Precache( void )
+{
+ BaseClass::Precache();
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CPointHurt::HurtThink( void )
+{
+ if ( m_strTarget != NULL_STRING )
+ {
+ CBaseEntity *pEnt = NULL;
+
+ CTakeDamageInfo info( this, m_pActivator, m_nDamage, m_bitsDamageType );
+ while ( ( pEnt = gEntList.FindEntityByName( pEnt, m_strTarget, NULL, m_pActivator ) ) != NULL )
+ {
+ GuessDamageForce( &info, (pEnt->GetAbsOrigin() - GetAbsOrigin()), pEnt->GetAbsOrigin() );
+ pEnt->TakeDamage( info );
+ }
+ }
+ else
+ {
+ RadiusDamage( CTakeDamageInfo( this, this, m_nDamage, m_bitsDamageType ), GetAbsOrigin(), m_flRadius, CLASS_NONE, NULL );
+ }
+
+ SetNextThink( gpGlobals->curtime + m_flDelay );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Input handler for turning on the point hurt.
+//-----------------------------------------------------------------------------
+void CPointHurt::InputTurnOn( inputdata_t &data )
+{
+ SetThink( &CPointHurt::HurtThink );
+
+ SetNextThink( gpGlobals->curtime + 0.1f );
+
+ m_pActivator = data.pActivator;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Input handler for turning off the point hurt.
+//-----------------------------------------------------------------------------
+void CPointHurt::InputTurnOff( inputdata_t &data )
+{
+ SetThink( NULL );
+
+ m_pActivator = data.pActivator;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Input handler for toggling the on/off state of the point hurt.
+//-----------------------------------------------------------------------------
+void CPointHurt::InputToggle( inputdata_t &data )
+{
+ m_pActivator = data.pActivator;
+
+ if ( m_pfnThink == (void (CBaseEntity::*)())&CPointHurt::HurtThink )
+ {
+ SetThink( NULL );
+ }
+ else
+ {
+ SetThink( &CPointHurt::HurtThink );
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Input handler for instantaneously hurting whatever is near us.
+//-----------------------------------------------------------------------------
+void CPointHurt::InputHurt( inputdata_t &data )
+{
+ m_pActivator = data.pActivator;
+
+ HurtThink();
+}
+