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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "weapon_sdkbase.h"
#include "sdk_fx_shared.h"
#if defined( CLIENT_DLL )
#define CWeaponShotgun C_WeaponShotgun
#include "c_sdk_player.h"
#else
#include "sdk_player.h"
#include "te_firebullets.h"
#endif
class CWeaponShotgun : public CWeaponSDKBase
{
public:
DECLARE_CLASS( CWeaponShotgun, CWeaponSDKBase );
DECLARE_NETWORKCLASS();
DECLARE_PREDICTABLE();
CWeaponShotgun();
virtual void PrimaryAttack();
virtual bool Reload();
virtual void WeaponIdle();
virtual SDKWeaponID GetWeaponID( void ) const { return WEAPON_SHOTGUN; }
private:
CWeaponShotgun( const CWeaponShotgun & );
float m_flPumpTime;
CNetworkVar( int, m_fInSpecialReload );
};
IMPLEMENT_NETWORKCLASS_ALIASED( WeaponShotgun, DT_WeaponShotgun )
BEGIN_NETWORK_TABLE( CWeaponShotgun, DT_WeaponShotgun )
#ifdef CLIENT_DLL
RecvPropInt( RECVINFO( m_fInSpecialReload ) )
#else
SendPropInt( SENDINFO( m_fInSpecialReload ), 2, SPROP_UNSIGNED )
#endif
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CWeaponShotgun )
END_PREDICTION_DATA()
LINK_ENTITY_TO_CLASS( weapon_shotgun, CWeaponShotgun );
PRECACHE_WEAPON_REGISTER( weapon_shotgun );
CWeaponShotgun::CWeaponShotgun()
{
m_flPumpTime = 0;
}
void CWeaponShotgun::PrimaryAttack()
{
CSDKPlayer *pPlayer = GetPlayerOwner();
if ( !pPlayer )
return;
// don't fire underwater
if (pPlayer->GetWaterLevel() == 3)
{
PlayEmptySound( );
m_flNextPrimaryAttack = gpGlobals->curtime + 0.15;
return;
}
// Out of ammo?
if ( m_iClip1 <= 0 )
{
Reload();
if ( m_iClip1 == 0 )
{
PlayEmptySound();
m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
}
return;
}
SendWeaponAnim( ACT_VM_PRIMARYATTACK );
m_iClip1--;
pPlayer->DoMuzzleFlash();
// player "shoot" animation
pPlayer->SetAnimation( PLAYER_ATTACK1 );
// Dispatch the FX right away with full accuracy.
FX_FireBullets(
pPlayer->entindex(),
pPlayer->Weapon_ShootPosition(),
pPlayer->EyeAngles() + 2.0f * pPlayer->GetPunchAngle(),
GetWeaponID(),
Primary_Mode,
CBaseEntity::GetPredictionRandomSeed() & 255, // wrap it for network traffic so it's the same between client and server
0.0675 );
if (!m_iClip1 && pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0)
{
// HEV suit - indicate out of ammo condition
pPlayer->SetSuitUpdate("!HEV_AMO0", false, 0);
}
if (m_iClip1 != 0)
m_flPumpTime = gpGlobals->curtime + 0.5;
m_flNextPrimaryAttack = gpGlobals->curtime + 0.875;
m_flNextSecondaryAttack = gpGlobals->curtime + 0.875;
if (m_iClip1 != 0)
SetWeaponIdleTime( gpGlobals->curtime + 2.5 );
else
SetWeaponIdleTime( gpGlobals->curtime + 0.875 );
m_fInSpecialReload = 0;
// Update punch angles.
QAngle angle = pPlayer->GetPunchAngle();
if ( pPlayer->GetFlags() & FL_ONGROUND )
{
angle.x -= SharedRandomInt( "ShotgunPunchAngleGround", 4, 6 );
}
else
{
angle.x -= SharedRandomInt( "ShotgunPunchAngleAir", 8, 11 );
}
pPlayer->SetPunchAngle( angle );
}
bool CWeaponShotgun::Reload()
{
CSDKPlayer *pPlayer = GetPlayerOwner();
if (pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0 || m_iClip1 == GetMaxClip1())
return true;
// don't reload until recoil is done
if (m_flNextPrimaryAttack > gpGlobals->curtime)
return true;
// check to see if we're ready to reload
if (m_fInSpecialReload == 0)
{
pPlayer->SetAnimation( PLAYER_RELOAD );
SendWeaponAnim( ACT_SHOTGUN_RELOAD_START );
m_fInSpecialReload = 1;
pPlayer->m_flNextAttack = gpGlobals->curtime + 0.5;
m_flNextPrimaryAttack = gpGlobals->curtime + 0.5;
m_flNextSecondaryAttack = gpGlobals->curtime + 0.5;
SetWeaponIdleTime( gpGlobals->curtime + 0.5 );
return true;
}
else if (m_fInSpecialReload == 1)
{
if (m_flTimeWeaponIdle > gpGlobals->curtime)
return true;
// was waiting for gun to move to side
m_fInSpecialReload = 2;
SendWeaponAnim( ACT_VM_RELOAD );
SetWeaponIdleTime( gpGlobals->curtime + 0.45 );
}
else
{
// Add them to the clip
m_iClip1 += 1;
#ifdef GAME_DLL
SendReloadEvents();
#endif
CSDKPlayer *pPlayer = GetPlayerOwner();
if ( pPlayer )
pPlayer->RemoveAmmo( 1, m_iPrimaryAmmoType );
m_fInSpecialReload = 1;
}
return true;
}
void CWeaponShotgun::WeaponIdle()
{
CSDKPlayer *pPlayer = GetPlayerOwner();
if (m_flPumpTime && m_flPumpTime < gpGlobals->curtime)
{
// play pumping sound
m_flPumpTime = 0;
}
if (m_flTimeWeaponIdle < gpGlobals->curtime)
{
if (m_iClip1 == 0 && m_fInSpecialReload == 0 && pPlayer->GetAmmoCount( m_iPrimaryAmmoType ))
{
Reload( );
}
else if (m_fInSpecialReload != 0)
{
if (m_iClip1 != 8 && pPlayer->GetAmmoCount( m_iPrimaryAmmoType ))
{
Reload( );
}
else
{
// reload debounce has timed out
//MIKETODO: shotgun anims
SendWeaponAnim( ACT_SHOTGUN_RELOAD_FINISH );
// play cocking sound
m_fInSpecialReload = 0;
SetWeaponIdleTime( gpGlobals->curtime + 1.5 );
}
}
else
{
SendWeaponAnim( ACT_VM_IDLE );
}
}
}
|