summaryrefslogtreecommitdiff
path: root/game/shared/tf2/grenade_base_empable.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/shared/tf2/grenade_base_empable.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/shared/tf2/grenade_base_empable.cpp')
-rw-r--r--game/shared/tf2/grenade_base_empable.cpp89
1 files changed, 89 insertions, 0 deletions
diff --git a/game/shared/tf2/grenade_base_empable.cpp b/game/shared/tf2/grenade_base_empable.cpp
new file mode 100644
index 0000000..2d46e80
--- /dev/null
+++ b/game/shared/tf2/grenade_base_empable.cpp
@@ -0,0 +1,89 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+#include "cbase.h"
+#include "basegrenade_shared.h"
+#include "engine/IEngineSound.h"
+#include "grenade_base_empable.h"
+#include "IEffects.h"
+
+#if !defined( CLIENT_DLL )
+// Global Savedata
+BEGIN_DATADESC( CBaseEMPableGrenade )
+ // Function Pointers
+ DEFINE_THINKFUNC( FizzleThink ),
+END_DATADESC()
+#endif
+
+IMPLEMENT_NETWORKCLASS_ALIASED( BaseEMPableGrenade, DT_BaseEMPableGrenade )
+
+BEGIN_NETWORK_TABLE( CBaseEMPableGrenade, DT_BaseEMPableGrenade )
+#if !defined( CLIENT_DLL )
+ SendPropFloat( SENDINFO( m_flFizzleDuration ), 10, SPROP_ROUNDDOWN, 0.0, 256.0f ),
+#else
+ RecvPropFloat( RECVINFO( m_flFizzleDuration ) ),
+#endif
+END_NETWORK_TABLE()
+
+LINK_ENTITY_TO_CLASS( base_empable_grenade, CBaseEMPableGrenade );
+
+BEGIN_PREDICTION_DATA( CBaseEMPableGrenade )
+
+ DEFINE_PRED_FIELD( m_flFizzleDuration, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
+
+END_PREDICTION_DATA()
+
+#define GRENADE_FIZZLE_DURATION 0.5
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+CBaseEMPableGrenade::CBaseEMPableGrenade( void )
+{
+ m_flFizzleDuration = 0;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Apply EMP damage to class
+//-----------------------------------------------------------------------------
+bool CBaseEMPableGrenade::TakeEMPDamage( float duration )
+{
+ // If we're fizzling already, ignore extra EMP damage
+ if ( m_flFizzleDuration )
+ return true;
+
+ // Fizzle away in a couple of seconds
+ m_flFizzleDuration = gpGlobals->curtime + MIN( duration, GRENADE_FIZZLE_DURATION );
+ SetThink( FizzleThink );
+ SetNextThink( gpGlobals->curtime + 0.1f );
+ return true;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Fizzle out and remove self from the world.
+//-----------------------------------------------------------------------------
+void CBaseEMPableGrenade::FizzleThink( void )
+{
+ float flDeltaTime = m_flFizzleDuration - gpGlobals->curtime;
+
+ // Keep fizzling until it's time to go
+ if ( flDeltaTime > 0.0f )
+ {
+ // Emit a fizzle sound
+ EmitSound( "BaseEMPableGrenade.Fizzle" );
+
+ // Smoke & Spark
+ g_pEffects->Sparks( GetAbsOrigin() );
+ UTIL_Smoke( GetAbsOrigin(), random->RandomInt( 4, 7), 10 );
+ }
+ else
+ {
+ Remove( );
+ return;
+ }
+
+ SetNextThink( gpGlobals->curtime + 0.1f );
+}