summaryrefslogtreecommitdiff
path: root/game/shared/tf2/weapon_infiltrator.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/weapon_infiltrator.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/shared/tf2/weapon_infiltrator.cpp')
-rw-r--r--game/shared/tf2/weapon_infiltrator.cpp150
1 files changed, 150 insertions, 0 deletions
diff --git a/game/shared/tf2/weapon_infiltrator.cpp b/game/shared/tf2/weapon_infiltrator.cpp
new file mode 100644
index 0000000..86dd51b
--- /dev/null
+++ b/game/shared/tf2/weapon_infiltrator.cpp
@@ -0,0 +1,150 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose: The Infiltrator's Weapon
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#include "cbase.h"
+#include "tf_player.h"
+#include "tf_defines.h"
+#include "in_buttons.h"
+#include "weapon_infiltrator.h"
+#include "gamerules.h"
+#include "ammodef.h"
+
+#define INFILTRATOR_STAB_RANGE 64.0f
+
+// Damage CVars
+ConVar weapon_infiltrator_damage( "weapon_infiltrator_damage","0", FCVAR_NONE, "Infiltrator backstab damage" );
+ConVar weapon_infiltrator_range( "weapon_infiltrator_range","0", FCVAR_NONE, "Infiltrator backstab range" );
+
+//=====================================================================================================
+// INFILTRATOR WEAPON
+//=====================================================================================================
+IMPLEMENT_SERVERCLASS_ST(CWeaponInfiltrator, DT_WeaponInfiltrator)
+END_SEND_TABLE()
+
+LINK_ENTITY_TO_CLASS( weapon_infiltrator, CWeaponInfiltrator );
+PRECACHE_WEAPON_REGISTER(weapon_infiltrator);
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+CWeaponInfiltrator::CWeaponInfiltrator( void )
+{
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CWeaponInfiltrator::Precache( void )
+{
+ BaseClass::Precache();
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+// Output : Returns true on success, false on failure.
+//-----------------------------------------------------------------------------
+bool CWeaponInfiltrator::ComputeEMPFireState( void )
+{
+ if (IsOwnerEMPed())
+ {
+ // FIXME: Need a sound
+ //UTIL_EmitSound( pPlayer->pev, CHAN_WEAPON, g_pszEMPGatlingFizzle, 1.0, ATTN_NORM );
+ return false;
+ }
+ return true;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+bool CWeaponInfiltrator::Deploy( void )
+{
+ // Play a shing! sound
+ WeaponSound( SPECIAL1 );
+ return DefaultDeploy( (char*)GetViewModel(), (char*)GetWorldModel(), ACT_VM_DRAW, (char*)GetAnimPrefix() );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CWeaponInfiltrator::PrimaryAttack( void )
+{
+ CBaseTFPlayer *pTarget = GetAssassinationTarget();
+ if ( pTarget == NULL )
+ return;
+
+ WeaponSound( SINGLE );
+ PlayAttackAnimation( ACT_VM_PRIMARYATTACK );
+ m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration( m_nSequence ) * 0.5;
+
+ // Instant kill
+ pTarget->TakeDamage( CTakeDamageInfo( this, GetOwner(), 500.0f, DMG_SLASH ) );
+ // Gag until respawn
+ pTarget->SetGagged( true );
+
+ CheckRemoveDisguise();
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Overloaded to handle the hold-down healing
+//-----------------------------------------------------------------------------
+void CWeaponInfiltrator::ItemPostFrame( void )
+{
+ CBaseTFPlayer *pOwner = ToBaseTFPlayer( GetOwner() );
+ if ( !pOwner )
+ return;
+
+ // Stab 'em
+ if (( pOwner->m_nButtons & IN_ATTACK ) && (m_flNextPrimaryAttack <= gpGlobals->curtime) )
+ {
+ PrimaryAttack();
+ }
+
+ WeaponIdle();
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: See if there's an assassination target in front of the player.
+// Output : Returns true if a target's found.
+//-----------------------------------------------------------------------------
+CBaseTFPlayer *CWeaponInfiltrator::GetAssassinationTarget( void )
+{
+ if ( !ComputeEMPFireState() )
+ return NULL;
+
+ CBaseTFPlayer *pPlayer = static_cast< CBaseTFPlayer * >( GetOwner() );
+ if ( !pPlayer )
+ return NULL;
+
+ trace_t tr;
+ Vector vecForward;
+ pPlayer->EyeVectors( &vecForward );
+ Vector vecOrigin = pPlayer->EyePosition();
+ UTIL_TraceLine( vecOrigin, vecOrigin + INFILTRATOR_STAB_RANGE * vecForward, MASK_SHOT, pPlayer, GetCollisionGroup(), &tr );
+ if ( tr.fraction == 1.0f || !tr.m_pEnt )
+ return NULL;
+ CBaseEntity *pEntity = tr.m_pEnt;
+ if ( !pEntity || !pEntity->IsPlayer() )
+ return NULL;
+ if ( !pEntity->IsPlayer() )
+ return NULL;
+
+ // Don't target friendlies
+ if ( pEntity->InSameTeam( pPlayer ) )
+ return NULL;
+
+ // See if the player is facing the right direction
+ Vector fwd1, fwd2;
+ AngleVectors( pPlayer->GetAbsAngles(), &fwd1, NULL, NULL );
+ AngleVectors( pEntity->GetAbsAngles(), &fwd2, NULL, NULL );
+
+ float dot = fwd1.Dot( fwd2 );
+ if ( dot <= 0.0f )
+ return NULL;
+
+ return (CBaseTFPlayer*)pEntity;
+} \ No newline at end of file