summaryrefslogtreecommitdiff
path: root/game/shared/tf2/weapon_combat_usedwithshieldbase.cpp
blob: 53fc9a28a12d80cfb963384db0247f6f97a04fa4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#include "cbase.h"
#include "basetfplayer_shared.h"
#include "weapon_combat_usedwithshieldbase.h"
#include "weapon_combatshield.h"
#include "weapon_twohandedcontainer.h"

//-----------------------------------------------------------------------------
// Purpose: Make sure we're not switching directly to this weapon, since this 
//			weapon can only be "switched" to by the twohandedcontainer weapon.
//-----------------------------------------------------------------------------
bool CWeaponCombatUsedWithShieldBase::CanDeploy( void )
{
	CBaseTFPlayer *pPlayer = ToBaseTFPlayer( GetOwner() );
	if (!pPlayer)
		return false;

	// Make sure the current weapon is a twohanded weapon container
	CWeaponTwoHandedContainer *pContainer = dynamic_cast<CWeaponTwoHandedContainer*>(pPlayer->GetActiveWeapon());
	if ( !pContainer )
	{
		// Not the two handed container, so deploy the two handed container instead
		pContainer = ( CWeaponTwoHandedContainer * )pPlayer->Weapon_OwnsThisType( "weapon_twohandedcontainer" );
		if ( !pContainer )
			return BaseClass::Deploy();

		// Deploy the container
		pPlayer->Weapon_Switch( pContainer );

		// Make sure the container's using the desired weapon
		pContainer->SetWeapons( this, pContainer->GetRightWeapon() );
		return false;
	}

	return BaseClass::CanDeploy();
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : allow - 
//-----------------------------------------------------------------------------
void CWeaponCombatUsedWithShieldBase::AllowShieldPostFrame( bool allow )
{
	CBaseTFPlayer *pOwner = ToBaseTFPlayer( GetOwner() );
	if (!pOwner)
		return;

	CWeaponCombatShield *shield = static_cast< CWeaponCombatShield * >( pOwner->Weapon_OwnsThisType( "weapon_combat_shield" ) );
	if ( !shield )
		return;

	shield->SetAllowPostFrame( allow );
}

//-----------------------------------------------------------------------------
// Purpose: 
// Output : int
//-----------------------------------------------------------------------------
int CWeaponCombatUsedWithShieldBase::GetShieldState( void )
{	
	CBaseTFPlayer *pOwner = ToBaseTFPlayer( GetOwner() );
	if ( !pOwner )
		return SS_DOWN;

	CWeaponCombatShield *pShield = pOwner->GetCombatShield();
	if ( !pShield )
		return SS_DOWN;

	return pShield->GetShieldState();
}

//-----------------------------------------------------------------------------
// Purpose: Mirror the values in the container, if there is one
// Input  : *pPlayer - 
// Output : int
//-----------------------------------------------------------------------------
int CWeaponCombatUsedWithShieldBase::UpdateClientData( CBasePlayer *pPlayer )
{
	if ( !pPlayer )
	{
		return BaseClass::UpdateClientData( pPlayer );
	}

	CWeaponTwoHandedContainer *pContainer = ( CWeaponTwoHandedContainer * )pPlayer->Weapon_OwnsThisType( "weapon_twohandedcontainer" );
	if ( !pContainer || pContainer != pPlayer->GetActiveWeapon() )
		return BaseClass::UpdateClientData( pPlayer );

	// Make sure this weapon is one of the container's active weapons
	if ( pContainer->GetLeftWeapon() != this && pContainer->GetRightWeapon() != this )
		return BaseClass::UpdateClientData( pPlayer );

	int retval = pContainer->UpdateClientData( pPlayer );
	m_iState =  pContainer->m_iState;
	return retval;
}

LINK_ENTITY_TO_CLASS( weapon_combat_usedwithshieldbase, CWeaponCombatUsedWithShieldBase );

IMPLEMENT_NETWORKCLASS_ALIASED( WeaponCombatUsedWithShieldBase, DT_WeaponCombatUsedWithShieldBase )

BEGIN_NETWORK_TABLE( CWeaponCombatUsedWithShieldBase, DT_WeaponCombatUsedWithShieldBase )
END_NETWORK_TABLE()

BEGIN_PREDICTION_DATA( CWeaponCombatUsedWithShieldBase )
END_PREDICTION_DATA()