summaryrefslogtreecommitdiff
path: root/game/shared/tf/tf_weapon_bonesaw.cpp
blob: 6895d89ded3dbfd7cca420377e6185dee9549154 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================

#include "cbase.h"
#include "tf_weapon_bonesaw.h"
#include "tf_weapon_medigun.h"
#ifdef GAME_DLL
#include "tf_player.h"
#else
#include "c_tf_player.h"
#endif


#define UBERSAW_CHARGE_POSEPARAM		"syringe_charge_level"

//=============================================================================
//
// Weapon Bonesaw tables.
//

IMPLEMENT_NETWORKCLASS_ALIASED( TFBonesaw, DT_TFWeaponBonesaw )

BEGIN_NETWORK_TABLE( CTFBonesaw, DT_TFWeaponBonesaw )
END_NETWORK_TABLE()

BEGIN_PREDICTION_DATA( CTFBonesaw )
END_PREDICTION_DATA()

LINK_ENTITY_TO_CLASS( tf_weapon_bonesaw, CTFBonesaw );
PRECACHE_WEAPON_REGISTER( tf_weapon_bonesaw );

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTFBonesaw::Activate( void )
{
	BaseClass::Activate();
}
//-----------------------------------------------------------------------------
void CTFBonesaw::SecondaryAttack( void )
{
	CTFPlayer *pPlayer = GetTFPlayerOwner();
	if ( !pPlayer )
		return;

#ifdef GAME_DLL
	int iSpecialTaunt = 0;
	CALL_ATTRIB_HOOK_INT( iSpecialTaunt, special_taunt );
	if ( iSpecialTaunt )
	{
		pPlayer->Taunt( TAUNT_BASE_WEAPON );
		return;
	}
#endif
	BaseClass::SecondaryAttack();
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CTFBonesaw::DefaultDeploy( char *szViewModel, char *szWeaponModel, int iActivity, char *szAnimExt )
{
	if ( BaseClass::DefaultDeploy( szViewModel, szWeaponModel, iActivity, szAnimExt ) )
	{
#ifdef CLIENT_DLL
		UpdateChargePoseParam();
#endif
		return true;
	}

	return false;
}

//-----------------------------------------------------------------------------
void CTFBonesaw::DoMeleeDamage( CBaseEntity* ent, trace_t& trace )
{
	// We hit a target, take a head
	CTFPlayer *pPlayer = ToTFPlayer( GetOwnerEntity() );
	CTFPlayer *pVictim = ToTFPlayer( ent );
	
	int iTakeHeads = 0;
	CALL_ATTRIB_HOOK_INT( iTakeHeads, add_head_on_hit );
	if ( pPlayer && pVictim && iTakeHeads && (pVictim->GetTeamNumber() != pPlayer->GetTeamNumber() ) )
	{
		int iDecaps = pPlayer->m_Shared.GetDecapitations() + 1;
		pPlayer->m_Shared.SetDecapitations( iDecaps );
		pPlayer->TeamFortress_SetSpeed();
	}

	BaseClass::DoMeleeDamage( ent, trace );
}

//-----------------------------------------------------------------------------
float CTFBonesaw::GetBoneSawSpeedMod( void ) 
{ 
	const int MAX_HEADS_FOR_SPEED = 10;
	// Calculate Speed based on heads
	CTFPlayer *pPlayer = ToTFPlayer( GetOwnerEntity() );

	int iTakeHeads = 0;
	CALL_ATTRIB_HOOK_INT( iTakeHeads, add_head_on_hit );
	if ( pPlayer && iTakeHeads )
	{
		int iDecaps = Min( MAX_HEADS_FOR_SPEED, pPlayer->m_Shared.GetDecapitations() );
		return 1.f + (iDecaps * 0.05f);
	}
	return 1.f; 
}

//-----------------------------------------------------------------------------
int CTFBonesaw::GetCount( void )
{
	CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
	if ( !pOwner )
		return 0;

	return pOwner->m_Shared.GetDecapitations();
}

#ifdef CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTFBonesaw::OnDataChanged( DataUpdateType_t updateType )
{
	BaseClass::OnDataChanged( updateType );

	UpdateChargePoseParam(); 
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTFBonesaw::UpdateAttachmentModels( void )
{
	BaseClass::UpdateAttachmentModels();

	if ( m_hViewmodelAttachment )
	{
		m_iUberChargePoseParam = m_hViewmodelAttachment->LookupPoseParameter( m_hViewmodelAttachment->GetModelPtr(), UBERSAW_CHARGE_POSEPARAM );
	}
	else
	{
		m_iUberChargePoseParam = LookupPoseParameter( GetModelPtr(), UBERSAW_CHARGE_POSEPARAM );
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTFBonesaw::UpdateChargePoseParam( void )
{
	if ( m_iUberChargePoseParam >= 0 )
	{
		CTFPlayer *pTFPlayer = ToTFPlayer( GetOwner() );
		if ( pTFPlayer && pTFPlayer->IsPlayerClass( TF_CLASS_MEDIC ) )
		{
			CWeaponMedigun *pMedigun = (CWeaponMedigun *)pTFPlayer->Weapon_OwnsThisID( TF_WEAPON_MEDIGUN );
			if ( pMedigun )
			{
				m_flChargeLevel = pMedigun->GetChargeLevel();

				// On the local client, we push the pose parameters onto the attached model
				if ( m_hViewmodelAttachment )
				{
					m_hViewmodelAttachment->SetPoseParameter( m_iUberChargePoseParam, pMedigun->GetChargeLevel() );
				}
			}
		}
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTFBonesaw::GetPoseParameters( CStudioHdr *pStudioHdr, float poseParameter[MAXSTUDIOPOSEPARAM] )
{
	if ( !pStudioHdr )
		return;

	BaseClass::GetPoseParameters( pStudioHdr, poseParameter );

	if ( m_iUberChargePoseParam >= 0 )
	{
		poseParameter[m_iUberChargePoseParam] = m_flChargeLevel;
	}
}

#endif