summaryrefslogtreecommitdiff
path: root/game/shared/tf2/weapon_pistols.cpp
blob: 47c51a9d49d411767ace1f539289f292298396c5 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:	Recon's dual semi-auto pistols
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "tf_player.h"
#include "tf_basecombatweapon.h"
#include "in_buttons.h"
#include "gamerules.h"
#include "ammodef.h"
#include "basegrenade_shared.h"

ConVar	weapon_pistols_damage( "weapon_pistols_damage","0", FCVAR_NONE, "Recon pistols maximum damage" );
ConVar	weapon_pistols_range( "weapon_pistols_range","0", FCVAR_NONE, "Recon pistols maximum range" );

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
class CWeaponPistols : public CTFMachineGun
{
	DECLARE_CLASS( CWeaponPistols, CTFMachineGun );
public:
	virtual float			GetFireRate( void );
	virtual const Vector&	GetBulletSpread( void ); 
	virtual bool			Deploy( void );
	virtual void			PrimaryAttack( void );
	virtual void			SecondaryAttack( void );
	virtual void			ItemPostFrame( void );

private:
	float		m_flSoonestPrimaryAttack;
	float		m_flLastPrimaryAttack;
};

LINK_ENTITY_TO_CLASS( weapon_pistols, CWeaponPistols );
PRECACHE_WEAPON_REGISTER(weapon_pistols);

//-----------------------------------------------------------------------------
// Purpose: Get the accuracy derived from weapon and player, and return it
//-----------------------------------------------------------------------------
const Vector& CWeaponPistols::GetBulletSpread( void )
{
	static Vector cone;
	cone = VECTOR_CONE_10DEGREES;

	// Modify accuracy based upon firing rate
	// Maximum accuracy's used if you're firing at the standard rate of the gun
	float flModifier = MIN( GetFireRate(), gpGlobals->curtime - m_flLastPrimaryAttack );
	flModifier = 1.0 - RemapVal( flModifier, 0, GetFireRate(), 0, 1.0 );
	cone *= flModifier;

	return cone;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
float CWeaponPistols::GetFireRate( void )
{	
	return 0.5; 
}

//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
bool CWeaponPistols::Deploy( void )
{
	m_flSoonestPrimaryAttack = gpGlobals->curtime;
	m_flLastPrimaryAttack = gpGlobals->curtime;
	return BaseClass::Deploy();
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponPistols::PrimaryAttack( void )
{
	m_flSoonestPrimaryAttack = gpGlobals->curtime + 0.1;
	BaseClass::PrimaryAttack();
	m_flLastPrimaryAttack = gpGlobals->curtime;
}

//-----------------------------------------------------------------------------
// Purpose: Throw out a sticky bomb
//-----------------------------------------------------------------------------
void CWeaponPistols::SecondaryAttack( void )
{
	/* FIXME: Temporarily disabled
	CBasePlayer *pPlayer = GetOwner();
	if ( pPlayer == NULL )
		return;

	// Calculate position & velocity
	Vector vecForward;
	pPlayer->EyeVectors( &vecForward );
	Vector vecOrigin = pPlayer->EyePosition();
	vecOrigin += (vecForward * 16);

	// Create the stickybomb
	CBaseGrenade *pGrenade = (CBaseGrenade*)CreateEntityByName("grenade_stickybomb");
	UTIL_SetOrigin( pGrenade->pev, vecOrigin );
	pGrenade->Spawn();
	pGrenade->SetOwnerEntity( pPlayer );
	pGrenade->m_hOwner = pPlayer;
	pGrenade->m_vecVelocity = vecForward * 1200;
	VectorAngles( vecForward, pGrenade->GetAngles() );

	// Reduce ammo, setup for refire
	pPlayer->m_iAmmo[m_iSecondaryAmmoType]--;
	m_flNextSecondaryAttack = gpGlobals->curtime + 0.5;
	*/
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CWeaponPistols::ItemPostFrame( void )
{
	CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
	if ( pPlayer == NULL )
		return;

	// Allow a refire as fast as the player can click
	if ( ( ( pPlayer->m_nButtons & IN_ATTACK ) == false ) && ( m_flSoonestPrimaryAttack < gpGlobals->curtime )
		/* && ( m_flNextSecondaryAttack < gpGlobals->curtime )*/ )
	{
		m_flNextPrimaryAttack = gpGlobals->curtime - 0.1f;
	}

	BaseClass::ItemPostFrame();
}