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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 357 - hand gun
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "npcevent.h"
#include "hl1mp_basecombatweapon_shared.h"
#ifdef CLIENT_DLL
#include "c_baseplayer.h"
#else
#include "player.h"
#endif
#include "gamerules.h"
#include "in_buttons.h"
#ifndef CLIENT_DLL
#include "soundent.h"
#include "game.h"
#endif
#include "vstdlib/random.h"
#include "engine/IEngineSound.h"
#ifdef CLIENT_DLL
#define CWeapon357 C_Weapon357
#endif
//-----------------------------------------------------------------------------
// CWeapon357
//-----------------------------------------------------------------------------
class CWeapon357 : public CBaseHL1MPCombatWeapon
{
DECLARE_CLASS( CWeapon357, CBaseHL1CombatWeapon );
public:
DECLARE_NETWORKCLASS();
DECLARE_PREDICTABLE();
CWeapon357( void );
void Precache( void );
bool Deploy( void );
void PrimaryAttack( void );
void SecondaryAttack( void );
bool Reload( void );
void WeaponIdle( void );
bool Holster( CBaseCombatWeapon *pSwitchingTo = NULL );
// DECLARE_SERVERCLASS();
// DECLARE_DATADESC();
private:
void ToggleZoom( void );
private:
CNetworkVar( float, m_fInZoom );
};
IMPLEMENT_NETWORKCLASS_ALIASED( Weapon357, DT_Weapon357 );
BEGIN_NETWORK_TABLE( CWeapon357, DT_Weapon357 )
#ifdef CLIENT_DLL
RecvPropFloat( RECVINFO( m_fInZoom ) ),
#else
SendPropFloat( SENDINFO( m_fInZoom ) ),
#endif
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CWeapon357 )
#ifdef CLIENT_DLL
DEFINE_PRED_FIELD( m_fInZoom, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
#endif
END_PREDICTION_DATA()
LINK_ENTITY_TO_CLASS( weapon_357, CWeapon357 );
PRECACHE_WEAPON_REGISTER( weapon_357 );
//IMPLEMENT_SERVERCLASS_ST( CWeapon357, DT_Weapon357 )
//END_SEND_TABLE()
//BEGIN_DATADESC( CWeapon357 )
//END_DATADESC()
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CWeapon357::CWeapon357( void )
{
m_bReloadsSingly = false;
m_bFiresUnderwater = false;
m_fInZoom = false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeapon357::Precache( void )
{
BaseClass::Precache();
#ifndef CLIENT_DLL
UTIL_PrecacheOther( "ammo_357" );
#endif
}
bool CWeapon357::Deploy( void )
{
// Bodygroup stuff not currently working correctly
// if ( g_pGameRules->IsMultiplayer() )
// {
// enable laser sight geometry.
// SetBodygroup( 4, 1 );
// }
// else
// {
// SetBodygroup( 4, 0 );
// }
return BaseClass::Deploy();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeapon357::PrimaryAttack( void )
{
// Only the player fires this way so we can cast
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
if ( !pPlayer )
{
return;
}
if ( m_iClip1 <= 0 )
{
if ( !m_bFireOnEmpty )
{
Reload();
}
else
{
WeaponSound( EMPTY );
m_flNextPrimaryAttack = 0.15;
}
return;
}
WeaponSound( SINGLE );
pPlayer->DoMuzzleFlash();
SendWeaponAnim( ACT_VM_PRIMARYATTACK );
pPlayer->SetAnimation( PLAYER_ATTACK1 );
m_flNextPrimaryAttack = gpGlobals->curtime + 0.75;
m_flNextSecondaryAttack = gpGlobals->curtime + 0.75;
m_iClip1--;
Vector vecSrc = pPlayer->Weapon_ShootPosition();
Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
// pPlayer->FireBullets( 1, vecSrc, vecAiming, VECTOR_CONE_1DEGREES, MAX_TRACE_LENGTH, m_iPrimaryAmmoType, 0 );
FireBulletsInfo_t info( 1, vecSrc, vecAiming, VECTOR_CONE_1DEGREES, MAX_TRACE_LENGTH, m_iPrimaryAmmoType );
info.m_pAttacker = pPlayer;
pPlayer->FireBullets( info );
#ifndef CLIENT_DLL
pPlayer->SetMuzzleFlashTime( gpGlobals->curtime + 0.5 );
#endif
pPlayer->ViewPunch( QAngle( -10, 0, 0 ) );
#ifndef CLIENT_DLL
CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), 600, 0.2 );
#endif
if ( !m_iClip1 && pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0 )
{
// HEV suit - indicate out of ammo condition
pPlayer->SetSuitUpdate( "!HEV_AMO0", FALSE, 0 );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeapon357::SecondaryAttack( void )
{
// only in multiplayer
if ( !g_pGameRules->IsMultiplayer() )
{
#ifndef CLIENT_DLL
// unless we have cheats on
if ( !sv_cheats->GetBool() )
{
return;
}
#endif
}
ToggleZoom();
m_flNextSecondaryAttack = gpGlobals->curtime + 0.5;
}
bool CWeapon357::Reload( void )
{
bool fRet;
fRet = DefaultReload( GetMaxClip1(), GetMaxClip2(), ACT_VM_RELOAD );
if ( fRet )
{
if ( m_fInZoom )
{
ToggleZoom();
}
}
return fRet;
}
void CWeapon357::WeaponIdle( void )
{
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
if ( pPlayer )
{
pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES );
}
if ( !HasWeaponIdleTimeElapsed() )
return;
if ( random->RandomFloat( 0, 1 ) <= 0.9 )
{
SendWeaponAnim( ACT_VM_IDLE );
}
else
{
SendWeaponAnim( ACT_VM_FIDGET );
}
}
bool CWeapon357::Holster( CBaseCombatWeapon *pSwitchingTo )
{
if ( m_fInZoom )
{
ToggleZoom();
}
return BaseClass::Holster( pSwitchingTo );
}
void CWeapon357::ToggleZoom( void )
{
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
if ( !pPlayer )
{
return;
}
#ifndef CLIENT_DLL
if ( m_fInZoom )
{
if ( pPlayer->SetFOV( this, 0 ) )
{
m_fInZoom = false;
pPlayer->ShowViewModel( true );
}
}
else
{
if ( pPlayer->SetFOV( this, 40 ) )
{
m_fInZoom = true;
pPlayer->ShowViewModel( false );
}
}
#endif
}
|