summaryrefslogtreecommitdiff
path: root/game/shared/tf2/weapon_shield.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_shield.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_shield.cpp')
-rw-r--r--game/shared/tf2/weapon_shield.cpp218
1 files changed, 218 insertions, 0 deletions
diff --git a/game/shared/tf2/weapon_shield.cpp b/game/shared/tf2/weapon_shield.cpp
new file mode 100644
index 0000000..f711a50
--- /dev/null
+++ b/game/shared/tf2/weapon_shield.cpp
@@ -0,0 +1,218 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose: The Escort's Shield weapon
+//
+// $Revision: $
+// $NoKeywords: $
+//=============================================================================//
+
+#include "cbase.h"
+#include "weapon_shield.h"
+#include "in_buttons.h"
+#include <float.h>
+#include "mathlib/mathlib.h"
+#include "engine/IEngineSound.h"
+
+#if defined( CLIENT_DLL )
+#include "c_shield.h"
+#else
+#include "tf_shield.h"
+#endif
+
+//-----------------------------------------------------------------------------
+// Shield WEAPON
+//-----------------------------------------------------------------------------
+LINK_ENTITY_TO_CLASS( weapon_shield, CWeaponShield );
+PRECACHE_WEAPON_REGISTER(weapon_shield);
+
+IMPLEMENT_NETWORKCLASS_ALIASED( WeaponShield, DT_WeaponShield )
+
+BEGIN_NETWORK_TABLE(CWeaponShield, DT_WeaponShield)
+#ifdef CLIENT_DLL
+ RecvPropEHandle (RECVINFO(m_hDeployedShield)),
+#else
+ SendPropEHandle (SENDINFO(m_hDeployedShield)),
+#endif
+END_NETWORK_TABLE()
+
+
+BEGIN_PREDICTION_DATA( CWeaponShield )
+
+ DEFINE_FIELD( m_bIsDeployed, FIELD_BOOLEAN ),
+ DEFINE_FIELD( m_bShieldPositionLocked, FIELD_BOOLEAN ),
+
+END_PREDICTION_DATA()
+
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+CWeaponShield::CWeaponShield( void )
+{
+ SetPredictionEligible( true );
+ m_bIsDeployed = false;
+}
+
+void CWeaponShield::UpdateOnRemove( void )
+{
+#ifdef GAME_DLL
+ if ( m_hDeployedShield.Get() )
+ {
+ m_hDeployedShield.Get()->Remove( );
+ m_hDeployedShield.Set( NULL );
+ }
+#endif
+
+ // Chain at end to mimic destructor unwind order
+ BaseClass::UpdateOnRemove();
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Given the distance the hit occurred at, return the damage done
+//-----------------------------------------------------------------------------
+float CWeaponShield::GetDamage( float flDistance, int iLocation )
+{
+ // Can't injure at all over this distance
+ return 0.0;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+float CWeaponShield::GetFireRate( void )
+{
+ return 1.0;
+}
+
+
+//-----------------------------------------------------------------------------
+// Deploy the shield!
+//-----------------------------------------------------------------------------
+bool CWeaponShield::Deploy( )
+{
+ if ( !BaseClass::Deploy() )
+ return false;
+
+ // NOTE: the underlying system can cause Deploy to be called twice in a row
+ if ( m_bIsDeployed )
+ return true;
+
+ // We gotta make the actual shield effect....
+ CBaseTFPlayer *pPlayer = ToBaseTFPlayer( GetOwner() );
+ if ( !pPlayer )
+ return false;
+
+#ifdef GAME_DLL
+ Assert( !m_hDeployedShield.Get().IsValid() );
+ m_hDeployedShield = CreateMobileShield( pPlayer );
+#endif
+
+ SetShieldPositionLocked( false );
+ m_bIsDeployed = true;
+
+ return true;
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Remove the shield
+//-----------------------------------------------------------------------------
+bool CWeaponShield::Holster( CBaseCombatWeapon *pSwitchingTo )
+{
+#ifdef GAME_DLL
+ if ( m_hDeployedShield.Get() )
+ {
+ m_hDeployedShield.Get()->Remove( );
+ m_hDeployedShield.Set( NULL );
+ }
+#endif
+
+ m_bIsDeployed = false;
+
+ return BaseClass::Holster( pSwitchingTo );
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CWeaponShield::ItemPostFrame( void )
+{
+ CBaseTFPlayer *pPlayer = ToBaseTFPlayer( GetOwner() );
+ if (pPlayer == NULL)
+ return;
+
+ // Disabled
+ if ( ComputeEMPFireState() )
+ {
+ // Handle deployment & pick-up (firing is handled on the client)
+ if ( pPlayer->m_nButtons & IN_ATTACK2 )
+ {
+ if ( gpGlobals->curtime >= m_flNextPrimaryAttack)
+ {
+ PrimaryAttack();
+ }
+ }
+ }
+
+ WeaponIdle();
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CWeaponShield::PrimaryAttack( void )
+{
+ CShield *shield = m_hDeployedShield.Get();
+ if ( shield )
+ {
+ SetShieldPositionLocked( !m_bShieldPositionLocked );
+
+#ifdef GAME_DLL
+ if ( m_bShieldPositionLocked )
+ {
+ ClientPrint( ToBasePlayer(GetOwner()), HUD_PRINTCENTER, "Projected Shield Locked" );
+ }
+ else
+ {
+ ClientPrint( ToBasePlayer(GetOwner()), HUD_PRINTCENTER, "Projected Shield Tracking" );
+ }
+#endif
+ }
+
+ m_flNextPrimaryAttack = gpGlobals->curtime + 0.25f;
+}
+
+
+//-----------------------------------------------------------------------------
+// Lock the projected shield
+//-----------------------------------------------------------------------------
+void CWeaponShield::SetShieldPositionLocked( bool bLocked )
+{
+ m_bShieldPositionLocked = bLocked;
+ if ( m_hDeployedShield.Get() )
+ {
+ if ( bLocked && m_hDeployedShield.Get()->IsAlwaysOrienting() )
+ {
+ CBaseTFPlayer *pPlayer = ToBaseTFPlayer( GetOwner() );
+ m_hDeployedShield.Get()->SetCenterAngles( pPlayer->EyeAngles() );
+ }
+ m_hDeployedShield.Get()->SetAlwaysOrient( !bLocked );
+ }
+}
+
+
+//-----------------------------------------------------------------------------
+// Idle processing
+//-----------------------------------------------------------------------------
+void CWeaponShield::WeaponIdle( void )
+{
+ bool isEmped = IsOwnerEMPed();
+
+ if (m_hDeployedShield.Get())
+ {
+ m_hDeployedShield.Get()->SetEMPed( isEmped );
+ }
+}