summaryrefslogtreecommitdiff
path: root/game/server/tf2/tf_class_sniper.cpp
blob: f724ede9c3d0b58c2428d04749389a4a5ac2d4cc (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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: The Sniper Player Class
//
// $Workfile:     $
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "tf_player.h"
#include "tf_class_sniper.h"
#include "in_buttons.h"
#include "tf_team.h"
#include "tf_class_support.h"
#include "order_killmortarguy.h"


bool IsEntityVisibleToTactical( int iLocalTeamNumber, int iLocalTeamPlayers, 
	int iLocalTeamScanners, int iEntIndex, const char *pEntName, int pEntTeamNumber, const Vector &pEntOrigin );

ConVar	class_sniper_speed( "class_sniper_speed","200", FCVAR_NONE, "Sniper movement speed" );

// Stationary Camo
#define SNIPER_MAX_HIDE_LEVEL			60
#define SNIPER_HIDE_INCREASE_PER_SEC	15
#define SNIPER_FIRE_UNHIDE_TIME			5.0

//=============================================================================
//
// Sniper Data Table
//
BEGIN_SEND_TABLE_NOBASE( CPlayerClassSniper, DT_PlayerClassSniperData )
END_SEND_TABLE()



//-----------------------------------------------------------------------------
// Purpose: 
// Output : const char
//-----------------------------------------------------------------------------
const char *CPlayerClassSniper::GetClassModelString( int nTeam )
{
	static const char *string = "models/player/sniper.mdl";
	return string;
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
CPlayerClassSniper::CPlayerClassSniper( CBaseTFPlayer *pPlayer, TFClass iClass ) : CPlayerClass( pPlayer, iClass )
{
	for (int i = 0; i < MAX_TF_TEAMS; ++i)
	{
		SetClassModel( MAKE_STRING(GetClassModelString(i)), i ); 
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
CPlayerClassSniper::~CPlayerClassSniper()
{
}
 

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CPlayerClassSniper::ClassActivate( void )
{
	BaseClass::ClassActivate();

	// Setup movement data.
	SetupMoveData();

	m_bHiding = false;
	m_flHideTransparency = 0.0f;
	m_flLastHideUpdate = 0.0f;

	m_bCanHide = false;

	memset( &m_ClassData, 0, sizeof( m_ClassData ) );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CPlayerClassSniper::ClassDeactivate( void )
{
	BaseClass::ClassDeactivate();
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CPlayerClassSniper::RespawnClass( void )
{
	BaseClass::RespawnClass();
	
	// Hiding values
	m_bHiding = false;
	m_flHideTransparency = m_flLastHideUpdate = 0;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CPlayerClassSniper::ResupplyAmmo( float flFraction, ResupplyReason_t reason )
{
	bool bGiven = false;

	if ((reason == RESUPPLY_ALL_FROM_STATION) || (reason == RESUPPLY_AMMO_FROM_STATION))
	{
		if (ResupplyAmmoType( 100 * flFraction, "Bullets" ))
			bGiven = true;
	}

	if ( BaseClass::ResupplyAmmo(flFraction, reason) )
		bGiven = true;

	return bGiven;
}

//-----------------------------------------------------------------------------
// Purpose: Set sniper class specific movement data here.
//-----------------------------------------------------------------------------
void CPlayerClassSniper::SetupMoveData( void )
{
	// Setup Class statistics
	m_flMaxWalkingSpeed = class_sniper_speed.GetFloat();
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPlayerClassSniper::SetupSizeData( void )
{
	// Initially set the player to the base player class standing hull size.
	m_pPlayer->SetCollisionBounds( SNIPERCLASS_HULL_STAND_MIN, SNIPERCLASS_HULL_STAND_MAX );
	m_pPlayer->SetViewOffset( SNIPERCLASS_VIEWOFFSET_STAND );
	m_pPlayer->m_Local.m_flStepSize = SNIPERCLASS_STEPSIZE;	
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
float CPlayerClassSniper::GetDeployTime( void )
{ 
	return 2.8; 
};

//-----------------------------------------------------------------------------
// Purpose: Called every frame by the player PostThink()
//-----------------------------------------------------------------------------
void CPlayerClassSniper::ClassThink( void )
{
	// Only hide if we have the technology 
	if ( m_bCanHide )
	{
		CheckHiding();
	}

	BaseClass::ClassThink();
}

//-----------------------------------------------------------------------------
// Purpose: New technology has been gained. Recalculate any class specific technology dependencies.
//-----------------------------------------------------------------------------
void CPlayerClassSniper::GainedNewTechnology( CBaseTechnology *pTechnology )
{
	// Stealthed on deploy
	if ( m_pPlayer->HasNamedTechnology( "sniper_deploy_stealth" ) )
	{
		m_bCanHide = true;
	}
	else
	{
		m_bCanHide = false;
	}

	BaseClass::GainedNewTechnology( pTechnology );
}


//-----------------------------------------------------------------------------
// Purpose: If the player's prone, slowly make him transparent
//-----------------------------------------------------------------------------
void CPlayerClassSniper::CheckHiding( void )
{
	// Can't hide or stay hidden if taking EMP damage
	if ( m_pPlayer->HasPowerup(POWERUP_EMP) )
	{
		m_pPlayer->ClearCamouflage();
		return;
	}

	// See if the player's just fired
	if ( m_pPlayer->m_afButtonReleased & IN_ATTACK )
	{
		// Immediately mostly unhide if so
		m_pPlayer->ClearCamouflage();
	}
	else if ( !m_pPlayer->IsDeployed() )
	{
		// Not deployed? Immediately unhide if so
		m_pPlayer->ClearCamouflage();
	}
	else
	{
		// We're deployed, hide if we haven't fired for a bit.
		if ( m_pPlayer->LastAttackTime() + SNIPER_FIRE_UNHIDE_TIME < gpGlobals->curtime )
		{
			m_pPlayer->SetCamouflaged( SNIPER_MAX_HIDE_LEVEL, SNIPER_HIDE_INCREASE_PER_SEC );
		}
		else
		{
			m_pPlayer->ClearCamouflage();
		}
	}
}


void CPlayerClassSniper::CreatePersonalOrder( void )
{
	if ( CreateInitialOrder() )
		return;
	
	// Kill a support guy?
	if ( COrderKillMortarGuy::CreateOrder( this ) )
		return;

	BaseClass::CreatePersonalOrder();
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CPlayerClassSniper::SetPlayerHull( void )
{
	if ( m_pPlayer->GetFlags() & FL_DUCKING )
	{
		m_pPlayer->SetCollisionBounds( SNIPERCLASS_HULL_DUCK_MIN, SNIPERCLASS_HULL_DUCK_MAX );
	}
	else
	{
		m_pPlayer->SetCollisionBounds( SNIPERCLASS_HULL_STAND_MIN, SNIPERCLASS_HULL_STAND_MAX );
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CPlayerClassSniper::ResetViewOffset( void )
{
	if ( m_pPlayer )
	{
		m_pPlayer->SetViewOffset( SNIPERCLASS_VIEWOFFSET_STAND );
	}
}