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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Base TF Combat weapon
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "animation.h"
#include "tf_player.h"
#include "tf_basecombatweapon.h"
#include "soundent.h"
#include "weapon_twohandedcontainer.h"
#include "tf_gamerules.h"
#include "tf_obj.h"
//====================================================================================================
// BASE TF MACHINEGUN
//====================================================================================================
IMPLEMENT_SERVERCLASS_ST(CTFMachineGun, DT_TFMachineGun )
END_SEND_TABLE()
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMachineGun::PrimaryAttack( void )
{
// Only the player fires this way so we can cast
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
if (!pPlayer)
return;
// Abort here to handle burst and auto fire modes
if ( (GetMaxClip1() != -1 && m_iClip1 == 0) || (GetMaxClip1() == -1 && !pPlayer->GetAmmoCount(m_iPrimaryAmmoType) ) )
return;
pPlayer->DoMuzzleFlash();
// To make the firing framerate independent, we may have to fire more than one bullet here on low-framerate systems,
// especially if the weapon we're firing has a really fast rate of fire.
if ( GetSequence() != SelectWeightedSequence( ACT_VM_PRIMARYATTACK ))
{
m_flNextPrimaryAttack = gpGlobals->curtime;
}
int iBulletsToFire = 0;
float fireRate = GetFireRate();
while ( m_flNextPrimaryAttack <= gpGlobals->curtime )
{
// MUST call sound before removing a round from the clip of a CMachineGun
WeaponSound(SINGLE, m_flNextPrimaryAttack);
m_flNextPrimaryAttack = m_flNextPrimaryAttack + fireRate;
iBulletsToFire++;
}
// Make sure we don't fire more than the amount in the clip, if this weapon uses clips
if ( GetMaxClip1() != -1 )
{
if ( iBulletsToFire > m_iClip1 )
iBulletsToFire = m_iClip1;
m_iClip1 -= iBulletsToFire;
}
else
{
if ( iBulletsToFire > pPlayer->GetAmmoCount(m_iPrimaryAmmoType) )
iBulletsToFire = pPlayer->GetAmmoCount(m_iPrimaryAmmoType);
pPlayer->RemoveAmmo( iBulletsToFire, m_iPrimaryAmmoType );
}
// Not time to fire any bullets yet?
if ( !iBulletsToFire )
return;
// Fire the bullets
Vector vecSrc = pPlayer->Weapon_ShootPosition( );
Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
// Factor in the view kick
AddViewKick();
float range = m_pRangeCVar ? m_pRangeCVar->GetFloat() : 1024.0f;
if ( !m_pRangeCVar )
{
Msg( "Weapon missing m_pRangeCVar!!!\n" );
}
FireBullets( this, iBulletsToFire, vecSrc, vecAiming, GetBulletSpread(), range, m_iPrimaryAmmoType, 2 );
if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0)
{
// HEV suit - indicate out of ammo condition
pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0);
}
PlayAttackAnimation( GetPrimaryAttackActivity() );
// Register a muzzleflash for the AI
pPlayer->SetMuzzleFlashTime( gpGlobals->curtime + 0.5 );
CheckRemoveDisguise();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
const Vector& CTFMachineGun::GetBulletSpread( void )
{
static Vector cone = VECTOR_CONE_3DEGREES;
return cone;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMachineGun::FireBullets( CBaseTFCombatWeapon *pWeapon, int cShots, const Vector &vecSrc, const Vector &vecDirShooting, const Vector &vecSpread, float flDistance, int iBulletType, int iTracerFreq)
{
if ( CBaseTFPlayer *pPlayer = (CBaseTFPlayer*)GetOwner() )
{
float damage = m_pDamageCVar ? m_pDamageCVar->GetFloat() : 1;
if ( !m_pDamageCVar )
{
Msg( "Weapon missing m_pDamageCVar!!!!\n" );
}
TFGameRules()->FireBullets( CTakeDamageInfo( this, pPlayer, damage, DMG_BULLET ), cShots, vecSrc, vecDirShooting, vecSpread, flDistance, iBulletType, 4, entindex(), 0 );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
float CTFMachineGun::GetFireRate( void )
{
return 1.0;
}
|