rendered paste body//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============////// Purpose: Essel likes to intrude into people's headers.////=============================================================================//#include "cbase.h"#include "npcevent.h"#include "in_buttons.h"#ifdef CLIENT_DLL #include "c_hl2mp_player.h"#else #include "hl2mp_player.h"#endif#include "weapon_hl2mpbasehlmpcombatweapon.h"#define PISTOL_FASTEST_REFIRE_TIME 0.1f#define PISTOL_FASTEST_DRY_REFIRE_TIME 0.2f#define PISTOL_ACCURACY_SHOT_PENALTY_TIME 0.2f // Applied amount of time each shot adds to the time we must recover from#define PISTOL_ACCURACY_MAXIMUM_PENALTY_TIME 1.5f // Maximum penalty to deal out#ifdef CLIENT_DLL#define CWeaponPistol C_WeaponPistol#endif//-----------------------------------------------------------------------------// CWeaponPistol//-----------------------------------------------------------------------------class CWeaponPistol : public CBaseHL2MPCombatWeapon{public: DECLARE_CLASS( CWeaponPistol, CBaseHL2MPCombatWeapon ); CWeaponPistol(void); DECLARE_NETWORKCLASS(); DECLARE_PREDICTABLE(); void Precache( void ); void ItemPostFrame( void ); void ItemPreFrame( void ); void ItemBusyFrame( void ); void PrimaryAttack( void ); void AddViewKick( void ); void DryFire( void ); void UpdatePenaltyTime( void ); virtual bool Reload( void ); virtual const Vector& GetBulletSpread( void ) { static Vector cone; float ramp = RemapValClamped( m_flAccuracyPenalty, 0.0f, PISTOL_ACCURACY_MAXIMUM_PENALTY_TIME, 0.0f, 1.0f ); // We lerp from very accurate to inaccurate over time // ^ Lol, lerp. VectorLerp( VECTOR_CONE_1DEGREES, VECTOR_CONE_3DEGREES, ramp, cone ); return cone; } virtual int GetMinBurst() { return 1; } virtual int GetMaxBurst() { return 3; } virtual float GetFireRate( void ) { return 1f; } #ifndef CLIENT_DLL DECLARE_ACTTABLE();#endifprivate: CNetworkVar( float, m_flSoonestPrimaryAttack ); CNetworkVar( float, m_flLastAttackTime ); CNetworkVar( float, m_flAccuracyPenalty ); CNetworkVar( int, m_nNumShotsFired ); bool Flip; // Flip?private: CWeaponPistol( const CWeaponPistol & );};IMPLEMENT_NETWORKCLASS_ALIASED( WeaponPistol, DT_WeaponPistol )BEGIN_NETWORK_TABLE( CWeaponPistol, DT_WeaponPistol )#ifdef CLIENT_DLL RecvPropTime( RECVINFO( m_flSoonestPrimaryAttack ) ), RecvPropTime( RECVINFO( m_flLastAttackTime ) ), RecvPropFloat( RECVINFO( m_flAccuracyPenalty ) ), RecvPropInt( RECVINFO( m_nNumShotsFired ) ),#else SendPropTime( SENDINFO( m_flSoonestPrimaryAttack ) ), SendPropTime( SENDINFO( m_flLastAttackTime ) ), SendPropFloat( SENDINFO( m_flAccuracyPenalty ) ), SendPropInt( SENDINFO( m_nNumShotsFired ) ),#endifEND_NETWORK_TABLE()BEGIN_PREDICTION_DATA( CWeaponPistol )END_PREDICTION_DATA()LINK_ENTITY_TO_CLASS( weapon_pistol, CWeaponPistol );PRECACHE_WEAPON_REGISTER( weapon_pistol );#ifndef CLIENT_DLLacttable_t CWeaponPistol::m_acttable[] = { { ACT_HL2MP_IDLE, ACT_HL2MP_IDLE_PISTOL, false }, { ACT_HL2MP_RUN, ACT_HL2MP_RUN_PISTOL, false }, { ACT_HL2MP_IDLE_CROUCH, ACT_HL2MP_IDLE_CROUCH_PISTOL, false }, { ACT_HL2MP_WALK_CROUCH, ACT_HL2MP_WALK_CROUCH_PISTOL, false }, { ACT_HL2MP_GESTURE_RANGE_ATTACK, ACT_HL2MP_GESTURE_RANGE_ATTACK_PISTOL, false }, { ACT_HL2MP_GESTURE_RELOAD, ACT_HL2MP_GESTURE_RELOAD_PISTOL, false }, { ACT_HL2MP_JUMP, ACT_HL2MP_JUMP_PISTOL, false }, { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_PISTOL, false },};IMPLEMENT_ACTTABLE( CWeaponPistol );#endif//-----------------------------------------------------------------------------// Purpose: Constructor//-----------------------------------------------------------------------------CWeaponPistol::CWeaponPistol( void ){ m_flSoonestPrimaryAttack = gpGlobals->curtime; m_flAccuracyPenalty = 0.0f; m_fMinRange1 = 24; m_fMaxRange1 = 1500; m_fMinRange2 = 24; m_fMaxRange2 = 200; m_bFiresUnderwater = true; Flip = true;}//-----------------------------------------------------------------------------// Purpose: //-----------------------------------------------------------------------------void CWeaponPistol::Precache( void ){ BaseClass::Precache();}//-----------------------------------------------------------------------------// Purpose://-----------------------------------------------------------------------------void CWeaponPistol::DryFire( void ){ WeaponSound( EMPTY ); SendWeaponAnim( ACT_VM_DRYFIRE ); m_flSoonestPrimaryAttack = gpGlobals->curtime + PISTOL_FASTEST_DRY_REFIRE_TIME; m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration();}//-----------------------------------------------------------------------------// Purpose://-----------------------------------------------------------------------------void CWeaponPistol::PrimaryAttack( void ){ if ( ( gpGlobals->curtime - m_flLastAttackTime ) > 0.5f ) { m_nNumShotsFired = 0; } else { m_nNumShotsFired++; } m_flLastAttackTime = gpGlobals->curtime; m_flSoonestPrimaryAttack = gpGlobals->curtime + PISTOL_FASTEST_REFIRE_TIME; CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); //Flipping shit that I wish would work. if ( Flip == true ) { SendWeaponAnim( ACT_VM_PRIMARYATTACK ); Flip = false; } else { SendWeaponAnim( ACT_VM_SECONDARYATTACK ); Flip = true; } if( pOwner ) { // Each time the player fires the pistol, reset the view punch. This prevents // the aim from 'drifting off' when the player fires very quickly. This may // not be the ideal way to achieve this, but it's cheap and it works, which is // great for a feature we're evaluating. (sjb) pOwner->ViewPunchReset(); } BaseClass::PrimaryAttack(); // Add an accuracy penalty which can move past our maximum penalty time if we're really spastic m_flAccuracyPenalty += PISTOL_ACCURACY_SHOT_PENALTY_TIME;}//-----------------------------------------------------------------------------// Purpose: //-----------------------------------------------------------------------------void CWeaponPistol::UpdatePenaltyTime( void ){ CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if ( pOwner == NULL ) return; // Check our penalty time decay if ( ( ( pOwner->m_nButtons & IN_ATTACK ) == false ) && ( m_flSoonestPrimaryAttack < gpGlobals->curtime ) ) { m_flAccuracyPenalty -= gpGlobals->frametime; m_flAccuracyPenalty = clamp( m_flAccuracyPenalty, 0.0f, PISTOL_ACCURACY_MAXIMUM_PENALTY_TIME ); }}//-----------------------------------------------------------------------------// Purpose: //-----------------------------------------------------------------------------void CWeaponPistol::ItemPreFrame( void ){ UpdatePenaltyTime(); BaseClass::ItemPreFrame();}//-----------------------------------------------------------------------------// Purpose: //-----------------------------------------------------------------------------void CWeaponPistol::ItemBusyFrame( void ){ UpdatePenaltyTime(); BaseClass::ItemBusyFrame();}//-----------------------------------------------------------------------------// Purpose: Allows firing as fast as button is pressed//-----------------------------------------------------------------------------void CWeaponPistol::ItemPostFrame( void ){ BaseClass::ItemPostFrame(); if ( m_bInReload ) return; CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if ( pOwner == NULL ) return; if ( pOwner->m_nButtons & IN_ATTACK2 ) { m_flLastAttackTime = gpGlobals->curtime + PISTOL_FASTEST_REFIRE_TIME; m_flSoonestPrimaryAttack = gpGlobals->curtime + PISTOL_FASTEST_REFIRE_TIME; m_flNextPrimaryAttack = gpGlobals->curtime + PISTOL_FASTEST_REFIRE_TIME; } //Allow a refire as fast as the player can click if ( ( ( pOwner->m_nButtons & IN_ATTACK ) == false ) && ( m_flSoonestPrimaryAttack < gpGlobals->curtime ) ) { m_flNextPrimaryAttack = gpGlobals->curtime - 0.1f; } else if ( ( pOwner->m_nButtons & IN_ATTACK ) && ( m_flNextPrimaryAttack < gpGlobals->curtime ) && ( m_iClip1 <= 0 ) ) { DryFire(); }}//-----------------------------------------------------------------------------//-----------------------------------------------------------------------------bool CWeaponPistol::Reload( void ){ bool fRet = DefaultReload( GetMaxClip1(), GetMaxClip2(), ACT_VM_RELOAD ); if ( fRet ) { WeaponSound( RELOAD ); m_flAccuracyPenalty = 0.0f; } return fRet;}//-----------------------------------------------------------------------------// Purpose: //-----------------------------------------------------------------------------void CWeaponPistol::AddViewKick( void ){ CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if ( pPlayer == NULL ) return; int iSeed = CBaseEntity::GetPredictionRandomSeed() & 255; RandomSeed( iSeed ); QAngle viewPunch; viewPunch.x = random->RandomFloat( 0.25f, 0.5f ); viewPunch.y = random->RandomFloat( -.6f, .6f ); viewPunch.z = 0.0f; //Add it to the view punch pPlayer->ViewPunch( viewPunch );}