source-engine/game/server/hl2/weapon_smg2.cpp
FluorescentCIAAfricanAmerican 3bf9df6b27 1
2020-04-22 12:56:21 -04:00

124 lines
3.2 KiB
C++

//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "basehlcombatweapon.h"
#include "NPCevent.h"
#include "basecombatcharacter.h"
#include "ai_basenpc.h"
#include "player.h"
#include "game.h"
#include "in_buttons.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
class CWeaponSMG2 : public CHLSelectFireMachineGun
{
public:
DECLARE_CLASS( CWeaponSMG2, CHLSelectFireMachineGun );
CWeaponSMG2();
DECLARE_SERVERCLASS();
const Vector &GetBulletSpread( void );
void Precache( void );
void AddViewKick( void );
void Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator );
float GetFireRate( void ) { return 0.1f; }
int CapabilitiesGet( void ) { return bits_CAP_WEAPON_RANGE_ATTACK1; }
DECLARE_ACTTABLE();
};
IMPLEMENT_SERVERCLASS_ST(CWeaponSMG2, DT_WeaponSMG2)
END_SEND_TABLE()
LINK_ENTITY_TO_CLASS( weapon_smg2, CWeaponSMG2 );
PRECACHE_WEAPON_REGISTER(weapon_smg2);
acttable_t CWeaponSMG2::m_acttable[] =
{
{ ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_SMG2, true },
};
IMPLEMENT_ACTTABLE(CWeaponSMG2);
//=========================================================
CWeaponSMG2::CWeaponSMG2( )
{
m_fMaxRange1 = 2000;
m_fMinRange1 = 32;
m_iFireMode = FIREMODE_3RNDBURST;
}
void CWeaponSMG2::Precache( void )
{
BaseClass::Precache();
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : const Vector
//-----------------------------------------------------------------------------
const Vector &CWeaponSMG2::GetBulletSpread( void )
{
static const Vector cone = VECTOR_CONE_10DEGREES;
return cone;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pEvent -
// *pOperator -
//-----------------------------------------------------------------------------
void CWeaponSMG2::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator )
{
switch( pEvent->event )
{
case EVENT_WEAPON_SMG2:
{
Vector vecShootOrigin, vecShootDir;
vecShootOrigin = pOperator->Weapon_ShootPosition( );
CAI_BaseNPC *npc = pOperator->MyNPCPointer();
ASSERT( npc != NULL );
vecShootDir = npc->GetActualShootTrajectory( vecShootOrigin );
WeaponSound(SINGLE_NPC);
pOperator->FireBullets( 1, vecShootOrigin, vecShootDir, VECTOR_CONE_PRECALCULATED, MAX_TRACE_LENGTH, m_iPrimaryAmmoType, 2 );
pOperator->DoMuzzleFlash();
m_iClip1 = m_iClip1 - 1;
}
break;
default:
BaseClass::Operator_HandleAnimEvent( pEvent, pOperator );
break;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponSMG2::AddViewKick( void )
{
#define EASY_DAMPEN 0.5f
#define MAX_VERTICAL_KICK 2.0f //Degrees
#define SLIDE_LIMIT 1.0f //Seconds
//Get the view kick
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
if (!pPlayer)
return;
DoMachineGunKick( pPlayer, EASY_DAMPEN, MAX_VERTICAL_KICK, m_fFireDuration, SLIDE_LIMIT );
}