summaryrefslogtreecommitdiff
path: root/game/shared/tf/tf_weapon_sniperrifle.h
blob: a2dec0049d975f21f8b0078efe6e26372860b334 (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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: TF Sniper Rifle
//
//=============================================================================//
#ifndef TF_WEAPON_SNIPERRIFLE_H
#define TF_WEAPON_SNIPERRIFLE_H
#ifdef _WIN32
#pragma once
#endif

#include "tf_weaponbase_gun.h"
#include "Sprite.h"

#if defined( CLIENT_DLL )
#define CTFSniperRifle C_TFSniperRifle
#define CTFSniperRifleDecap C_TFSniperRifleDecap
#define CTFSniperRifleClassic C_TFSniperRifleClassic
#define CTFSniperRifleRevolver C_TFSniperRifleRevolver
#define CSniperDot C_SniperDot
#endif

enum RifleTypes_t
{
	RIFLE_NORMAL = 0,
	RIFLE_JARATE,
	RIFLE_MACHINA,
	RIFLE_CLASSIC,
};

//=============================================================================
//
// Sniper Rifle Laser Dot class.
//
class CSniperDot : public CBaseEntity
{
public:

	DECLARE_CLASS( CSniperDot, CBaseEntity );
	DECLARE_NETWORKCLASS();
	DECLARE_DATADESC();

	// Creation/Destruction.
	CSniperDot( void );
	~CSniperDot( void );

	static CSniperDot *Create( const Vector &origin, CBaseEntity *pOwner = NULL, bool bVisibleDot = true );
	void		ResetChargeTime( void ) { m_flChargeStartTime = gpGlobals->curtime; }

	// Attributes.
	int			ObjectCaps()							{ return (BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | FCAP_DONT_SAVE; }

	// Targeting.
	void        Update( CBaseEntity *pTarget, const Vector &vecOrigin, const Vector &vecNormal );
	CBaseEntity	*GetTargetEntity( void )				{ return m_hTargetEnt; }
	Vector		GetChasePosition();

// Client specific.
#ifdef CLIENT_DLL

	bool GetRenderingPositions( C_TFPlayer *pPlayer, Vector &vecAttachment, Vector &vecEndPos, float &flSize );

	// Rendering.
	virtual bool			IsTransparent( void )		{ return true; }
	virtual RenderGroup_t	GetRenderGroup( void )		{ return RENDER_GROUP_TRANSLUCENT_ENTITY; }
	virtual int				DrawModel( int flags );
	virtual bool			ShouldDraw( void );

	virtual void			ClientThink( void );

	virtual void			OnDataChanged( DataUpdateType_t updateType );

	CMaterialReference		m_hSpriteMaterial;
	HPARTICLEFFECT			m_laserBeamEffect;
#endif

protected:

	Vector					m_vecSurfaceNormal;
	EHANDLE					m_hTargetEnt;

	CNetworkVar( float, m_flChargeStartTime );
};

//=============================================================================
//
// Sniper Rifle class.
//
class CTFSniperRifle : public CTFWeaponBaseGun
{
public:

	DECLARE_CLASS( CTFSniperRifle, CTFWeaponBaseGun );
	DECLARE_NETWORKCLASS(); 
	DECLARE_PREDICTABLE();
	DECLARE_DATADESC();

	CTFSniperRifle();
	virtual ~CTFSniperRifle();

	virtual int	GetWeaponID( void ) const			{ return TF_WEAPON_SNIPERRIFLE; }

	virtual void Spawn();
	virtual void Precache() OVERRIDE;
	void		 ResetTimers( void );

	virtual bool Reload( void );
	virtual bool CanHolster( void ) const;
	virtual bool Holster( CBaseCombatWeapon *pSwitchingTo );

	virtual bool OwnerCanJump( void ) OVERRIDE;

	virtual void HandleZooms( void );
	virtual void ItemPostFrame( void );
	virtual bool Lower( void );
	virtual float GetProjectileDamage( void );
	virtual int	GetDamageType() const;
	int		GetRifleType( void ) const { int iMode = 0; CALL_ATTRIB_HOOK_INT( iMode, set_weapon_mode ); return iMode; };

	virtual void WeaponReset( void );

	virtual bool CanFireCriticalShot( bool bIsHeadshot = false );

	virtual void PlayWeaponShootSound( void );
	virtual bool MustBeZoomedToFire( void );

	virtual ETFDmgCustom GetPenetrateType() const;

#ifdef CLIENT_DLL
	float GetHUDDamagePerc( void );

	virtual bool ShouldEjectBrass();
#endif

	bool IsZoomed( void );
	bool IsFullyCharged( void ) const;			// have we been zoomed in long enough for our shot to do max damage

	virtual void OnControlStunned( void );

	virtual int GetCustomDamageType() const;

#ifdef GAME_DLL
	// Hit tracking for achievements
	virtual void	OnPlayerKill( CTFPlayer *pVictim, const CTakeDamageInfo &info ) OVERRIDE;
	virtual void	OnBulletFire( int iEnemyPlayersHit ) OVERRIDE;

	void			ExplosiveHeadShot( CTFPlayer *pAttacker, CTFPlayer *pVictim );
#endif
	
	void			Detach( void ) OVERRIDE;

	virtual bool	IsJarateRifle( void ) const;
	virtual float	GetJarateTime( void ) const;

	virtual float	SniperRifleChargeRateMod() { return 0.f; }

	virtual int		GetBuffType() { int iBuffType = 0; CALL_ATTRIB_HOOK_INT( iBuffType, set_buff_type ); return iBuffType; }

	float			GetProgress( void );
	bool			IsRageFull( void ); // same as GetProgress() without the division by 100.0f
	const char*		GetEffectLabelText( void ) { return "#TF_SNIPERRAGE"; }
	bool			EffectMeterShouldFlash( void );

#ifdef SIXENSE
	float			GetRezoomTime() const;
#endif
	virtual void	ZoomIn( void );
	virtual void	ZoomOut( void );

	void			ApplyScopeSpeedModifications( float &flBaseRef );
	void			ApplyChargeSpeedModifications( float &flBaseRef );

protected:

	float			GetJarateTimeInternal( void ) const;

	bool	m_bCurrentShotIsHeadshot;

	void CreateSniperDot( void );
	void DestroySniperDot( void );
	void UpdateSniperDot( void );

	void Fire( CTFPlayer *pPlayer );

	// Auto-rezooming handling
	void SetRezoom( bool bRezoom, float flDelay );
	virtual void Zoom( void );
	void ZoomOutIn( void );

	void HandleNoScopeFireDeny( void );

	CNetworkVar( float,	m_flChargedDamage );

#ifdef GAME_DLL
	CHandle<CSniperDot>		m_hSniperDot;
#else
	bool m_bPlayedBell;
#endif

	// Handles rezooming after the post-fire unzoom
	float m_flUnzoomTime;
	float m_flRezoomTime;
	bool m_bRezoomAfterShot;

	float m_flChargePerSec;
	bool m_bWasAimedAtEnemy;

	CTFSniperRifle( const CTFSniperRifle & );
};

class CTFSniperRifleDecap : public CTFSniperRifle
{
public:
	DECLARE_CLASS( CTFSniperRifleDecap, CTFSniperRifle );
	DECLARE_NETWORKCLASS(); 
	DECLARE_PREDICTABLE();

	virtual int	GetWeaponID( void ) const			{ return TF_WEAPON_SNIPERRIFLE_DECAP; }

#ifdef GAME_DLL
	virtual void	OnPlayerKill( CTFPlayer *pVictim, const CTakeDamageInfo &info );
#endif // GAME_DLL

	virtual float	SniperRifleChargeRateMod() OVERRIDE;
	const char*		GetEffectLabelText( void ) { return "#TF_BERZERK"; }
	float		GetProgress( void ) { return 0.f; }
	int			GetCount( void );
};

//=============================================================================
//
// Classic Sniper Rifle class.
//
class CTFSniperRifleClassic : public CTFSniperRifle
{
public:

	DECLARE_CLASS( CTFSniperRifleClassic, CTFSniperRifle );
	DECLARE_NETWORKCLASS();
	DECLARE_PREDICTABLE();

	CTFSniperRifleClassic();
	~CTFSniperRifleClassic();
	virtual void Precache() OVERRIDE;

	virtual int	GetWeaponID( void ) const			{ return TF_WEAPON_SNIPERRIFLE_CLASSIC; }

	virtual void ZoomOut( void ) OVERRIDE;
	virtual void ZoomIn( void ) OVERRIDE;
	virtual void Zoom( void ) OVERRIDE;
 	virtual void HandleZooms( void ) OVERRIDE;
 	virtual void ItemPostFrame( void ) OVERRIDE;
	virtual bool Lower( void ) OVERRIDE;
	virtual bool Deploy( void ) OVERRIDE;
	virtual bool MustBeZoomedToFire( void ) OVERRIDE { return false; }
	virtual int	GetDamageType() const OVERRIDE;
	virtual bool Holster( CBaseCombatWeapon *pSwitchingTo ) OVERRIDE;
	virtual void WeaponReset( void ) OVERRIDE;
#ifdef CLIENT_DLL
	virtual void OnDataChanged( DataUpdateType_t updateType ) OVERRIDE;
#endif

	void		Detach( void ) OVERRIDE;

private:
	CNetworkVar( bool, m_bCharging );
#ifdef CLIENT_DLL
	void ManageChargeBeam( void );
	HPARTICLEFFECT	m_pChargedEffect;
#endif
};

#ifdef STAGING_ONLY
//=============================================================================
//
// Projectile Based Sniper Rifle
//
class CTFSniperRifleRevolver : public CTFSniperRifleClassic
{
public:

	DECLARE_CLASS( CTFSniperRifleRevolver, CTFSniperRifleClassic );
	DECLARE_NETWORKCLASS();
	DECLARE_PREDICTABLE();

	virtual int		GetWeaponID( void ) const			{ return TF_WEAPON_SNIPERRIFLE_REVOLVER; }

	// Fire the sniper shot.
	virtual void	PrimaryAttack() OVERRIDE;

	virtual float	GetProjectileDamage() OVERRIDE;
	virtual void	ZoomIn( void ) OVERRIDE;
	virtual void	ZoomOut( void ) OVERRIDE;
	virtual bool	Reload( void ) OVERRIDE;
	virtual void	ItemPostFrame( void ) OVERRIDE;

	virtual bool CanFireCriticalShot( bool bIsHeadshot = false ) OVERRIDE;

	virtual float GetProjectileSpeed( void ) OVERRIDE;
	virtual float GetProjectileGravity( void ) OVERRIDE;

};
#endif // STAGING_ONLY

#endif // TF_WEAPON_SNIPERRIFLE_H