forked from hitmen047/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweapon_awp.cpp
254 lines (188 loc) · 4.77 KB
/
weapon_awp.cpp
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
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "weapon_csbasegun.h"
#if defined( CLIENT_DLL )
#define CWeaponAWP C_WeaponAWP
#include "c_cs_player.h"
#else
#include "cs_player.h"
#include "KeyValues.h"
#endif
#define SNIPER_ZOOM_CONTEXT "SniperRifleThink"
#ifdef AWP_UNZOOM
ConVar sv_awpunzoomdelay(
"sv_awpunzoomdelay",
"1.0",
0,
"how many seconds to zoom the zoom up after firing",
true, 0, // min value
false, 0 // max value
);
#endif
class CWeaponAWP : public CWeaponCSBaseGun
{
public:
DECLARE_CLASS( CWeaponAWP, CWeaponCSBaseGun );
DECLARE_NETWORKCLASS();
DECLARE_PREDICTABLE();
#ifndef CLIENT_DLL
DECLARE_DATADESC();
#endif
CWeaponAWP();
virtual void Spawn();
virtual void PrimaryAttack();
virtual void SecondaryAttack();
virtual void AWPFire( float flSpread );
virtual float GetMaxSpeed() const;
virtual bool IsAwp() const;
virtual CSWeaponID GetWeaponID( void ) const { return WEAPON_AWP; }
private:
#ifndef CLIENT_DLL
void UnzoomThink( void );
#endif
CWeaponAWP( const CWeaponAWP & );
};
IMPLEMENT_NETWORKCLASS_ALIASED( WeaponAWP, DT_WeaponAWP )
BEGIN_NETWORK_TABLE( CWeaponAWP, DT_WeaponAWP )
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CWeaponAWP )
END_PREDICTION_DATA()
LINK_ENTITY_TO_CLASS( weapon_awp, CWeaponAWP );
PRECACHE_WEAPON_REGISTER( weapon_awp );
#ifndef CLIENT_DLL
BEGIN_DATADESC( CWeaponAWP )
DEFINE_THINKFUNC( UnzoomThink ),
END_DATADESC()
#endif
CWeaponAWP::CWeaponAWP()
{
}
void CWeaponAWP::Spawn()
{
Precache();
BaseClass::Spawn();
}
void CWeaponAWP::SecondaryAttack()
{
#ifndef CLIENT_DLL
CCSPlayer *pPlayer = GetPlayerOwner();
if (pPlayer == NULL)
{
Assert(pPlayer != NULL);
return;
}
if ( pPlayer->GetFOV() == pPlayer->GetDefaultFOV() )
{
pPlayer->SetFOV( pPlayer, 40, 0.15f );
}
else if ( pPlayer->GetFOV() == 40 )
{
pPlayer->SetFOV( pPlayer, 10, 0.08f );
}
else
{
pPlayer->SetFOV( pPlayer, pPlayer->GetDefaultFOV(), 0.1f );
}
pPlayer->ResetMaxSpeed();
#endif
#ifndef CLIENT_DLL
// If this isn't guarded, the sound will be emitted twice, once by the server and once by the client.
// Let the server play it since if only the client plays it, it's liable to get played twice cause of
// a prediction error. joy.
EmitSound( "Default.Zoom" );
// let the bots hear the rifle zoom
IGameEvent * event = gameeventmanager->CreateEvent( "weapon_zoom" );
if ( event )
{
event->SetInt( "userid", pPlayer->GetUserID() );
gameeventmanager->FireEvent( event );
}
#endif
m_flNextSecondaryAttack = gpGlobals->curtime + 0.3;
m_zoomFullyActiveTime = gpGlobals->curtime + 0.15; // The worst zoom time from above.
}
void CWeaponAWP::PrimaryAttack()
{
CCSPlayer *pPlayer = GetPlayerOwner();
if ( !pPlayer )
return;
if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) )
AWPFire( 0.85 );
else if ( pPlayer->GetAbsVelocity().Length2D() > 140 )
AWPFire( 0.25 );
else if ( pPlayer->GetAbsVelocity().Length2D() > 10 )
AWPFire( 0.10 );
else if ( FBitSet( pPlayer->GetFlags(), FL_DUCKING ) )
AWPFire( 0.0 );
else
AWPFire( 0.001 );
}
void CWeaponAWP::AWPFire( float flSpread )
{
CCSPlayer *pPlayer = GetPlayerOwner();
if (pPlayer == NULL)
{
Assert(pPlayer != NULL);
return;
}
// If we are not zoomed in, or we have very recently zoomed and are still transitioning, the bullet diverts more.
if (pPlayer->GetFOV() == pPlayer->GetDefaultFOV() || (gpGlobals->curtime < m_zoomFullyActiveTime))
{
flSpread += 0.08;
}
if (pPlayer->GetFOV() != pPlayer->GetDefaultFOV())
{
pPlayer->m_iLastZoom = pPlayer->GetFOV();
#ifndef CLIENT_DLL
#ifdef AWP_UNZOOM
SetContextThink( &CWeaponAWP::UnzoomThink, gpGlobals->curtime + sv_awpunzoomdelay.GetFloat(), SNIPER_ZOOM_CONTEXT );
#else
pPlayer->m_bResumeZoom = true;
pPlayer->SetFOV( pPlayer, pPlayer->GetDefaultFOV(), 0.1f );
#endif
#endif
}
if ( !CSBaseGunFire( flSpread, GetCSWpnData().m_flCycleTime, true ) )
return;
QAngle angle = pPlayer->GetPunchAngle();
angle.x -= 2;
pPlayer->SetPunchAngle( angle );
}
#ifndef CLIENT_DLL
void CWeaponAWP::UnzoomThink( void )
{
CCSPlayer *pPlayer = GetPlayerOwner();
if (pPlayer == NULL)
{
Assert(pPlayer != NULL);
return;
}
pPlayer->SetFOV( pPlayer, pPlayer->GetDefaultFOV(), 0.1f );
}
#endif
float CWeaponAWP::GetMaxSpeed() const
{
CCSPlayer *pPlayer = GetPlayerOwner();
if (pPlayer == NULL)
{
Assert(pPlayer != NULL);
return BaseClass::GetMaxSpeed();
}
if ( pPlayer->GetFOV() == pPlayer->GetDefaultFOV() )
{
return BaseClass::GetMaxSpeed();
}
else
{
// Slower speed when zoomed in.
return 150;
}
}
bool CWeaponAWP::IsAwp() const
{
return true;
}