Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ========= Whackjob Interactive - Pseudonym_Tim ============ //
- // //
- // GLOCK17 WEAPON REFERENCE //
- // Business Related Inquiries/Contact Info: Mute2673@gmail.com //
- //=============================================================================//
- /* NOTE: Not sure if I needed to change these to different headers that may be in your source build,
- but I did change some anyway to what I'm pretty sure they are. Fix them if they are incorrect. */
- #include "cbase.h"
- #include "npcevent.h"
- #include "baseweapon.h" // "basehlcombatweapon" Changed to presumed counterpart "baseweapon"...
- #include "basecombatcharacter.h"
- #include "ai_basenpc.h"
- #include "player.h"
- #include "p3gamerules.h" // "gamerules" Changed to presumed counterpart "p3gamerules"...
- #include "in_buttons.h"
- #include "soundent.h"
- #include "game.h"
- #include "vstdlib/random.h"
- #include "gamestats.h" // Didn't change this but I think it's worth noting that I assumed it was the same because I found it exists inside of the client/server.dll
- // memdbgon must be the last include file in a .cpp file!!!
- #include "tier0/memdbgon.h"
- #define GLOCK17_FASTEST_REFIRE_TIME 0.2f
- #define GLOCK17_FASTEST_DRY_REFIRE_TIME 0.2f
- #define GLOCK17_ACCURACY_SHOT_PENALTY_TIME 0.2f // Applied amount of time each shot adds to the time we must recover from
- #define GLOCK17_ACCURACY_MAXIMUM_PENALTY_TIME 1.5f // Maximum penalty to deal out
- ConVar glock17_use_new_accuracy( "glock17_use_new_accuracy", "1" );
- //-----------------------------------------------------------------------------
- // CWeaponGlock17
- //-----------------------------------------------------------------------------
- /* NOTE: I'm not sure if the public statements and classes needed to be change to your source builds counterparts but I did it anyway
- with the information from the .dll files. Fix them if they are incorrect. */
- class CP3WeaponGlock17 : public CBaseWeapon // public "CBaseHLCombatWeapon" Changed to presumed counterpart "CBaseWeapon", And class "CWeaponGlock17" changed to presumed counterpart "CP3WeaponGlock17"
- {
- DECLARE_DATADESC();
- public:
- DECLARE_CLASS( CP3WeaponGlock17, CBaseWeapon ); // "CBaseHLCombatWeapon" Changed to presumed counterpart "CBaseWeapon", And class "CWeaponGlock17" changed to presumed counterpart "CP3WeaponGlock17"
- {
- CP3WeaponGlock17(void); // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
- DECLARE_SERVERCLASS();
- void Precache( void );
- void ItemPostFrame( void );
- void ItemPreFrame( void );
- void ItemBusyFrame( void );
- void PrimaryAttack( void );
- void AddViewKick( void );
- void DryFire( void );
- void Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ); // Not sure if CBaseCombatCharacter needed to be changed.
- void UpdatePenaltyTime( void );
- int CapabilitiesGet( void ) { return bits_CAP_WEAPON_RANGE_ATTACK1; }
- Activity GetPrimaryAttackActivity( void );
- virtual bool Reload( void );
- virtual const Vector& GetBulletSpread( void )
- {
- // Handle NPCs first
- static Vector npcCone = VECTOR_CONE_5DEGREES;
- if ( GetOwner() && GetOwner()->IsNPC() )
- return npcCone;
- static Vector cone;
- if ( glock17_use_new_accuracy.GetBool() )
- {
- float ramp = RemapValClamped( m_flAccuracyPenalty,
- 0.0f,
- GLOCK17_ACCURACY_MAXIMUM_PENALTY_TIME,
- 0.0f,
- 1.0f );
- // We lerp from very accurate to inaccurate over time
- VectorLerp( VECTOR_CONE_1DEGREES, VECTOR_CONE_6DEGREES, ramp, cone );
- }
- else
- {
- // Old value
- // *Cough...*
- cone = VECTOR_CONE_4DEGREES;
- }
- return cone;
- }
- virtual int GetMinBurst()
- {
- return 1;
- }
- virtual int GetMaxBurst()
- {
- return 3;
- }
- virtual float GetFireRate( void )
- {
- return 0.2f;
- }
- DECLARE_ACTTABLE();
- private:
- float m_flSoonestPrimaryAttack;
- float m_flLastAttackTime;
- float m_flAccuracyPenalty;
- int m_nNumShotsFired;
- };
- IMPLEMENT_SERVERCLASS_ST(CP3WeaponGlock17, DT_P3_WeaponGlock17) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17", And changed "DT_WeaponGlock17" to presumed counterpart "DT_P3_WeaponGlock17"...
- END_SEND_TABLE()
- LINK_ENTITY_TO_CLASS( p3_weapon_glock17, CP3WeaponGlock17 ); // "weapon_glock17" changed to presumed counterpart "p3_weapon_glock17", And "CWeaponGlock17" changed to presumed counterpart "CP3WeaponGlock17"...
- PRECACHE_WEAPON_REGISTER( p3_weapon_glock17 ); // "weapon_glock17" changed to presumed counterpart "p3_weapon_glock17"...
- BEGIN_DATADESC( CP3WeaponGlock17 ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
- DEFINE_FIELD( m_flSoonestPrimaryAttack, FIELD_TIME ),
- DEFINE_FIELD( m_flLastAttackTime, FIELD_TIME ),
- DEFINE_FIELD( m_flAccuracyPenalty, FIELD_FLOAT ), //NOTE: This is NOT tracking game time
- DEFINE_FIELD( m_nNumShotsFired, FIELD_INTEGER ),
- END_DATADESC()
- // Adding new ACT's for weapons here. However, the Glock17 doesn't need any new ones for it's anims, so It's fine the way it is...
- acttable_t CP3WeaponGlock17::m_acttable[] = // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
- {
- { ACT_IDLE, ACT_IDLE_GLOCK17, true },
- { ACT_IDLE_ANGRY, ACT_IDLE_ANGRY_GLOCK17, true },
- { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_GLOCK17, true },
- { ACT_RELOAD, ACT_RELOAD_GLOCK17, true },
- { ACT_WALK_AIM, ACT_WALK_AIM_GLOCK17, true },
- { ACT_RUN_AIM, ACT_RUN_AIM_GLOCK17, true },
- { ACT_GESTURE_RANGE_ATTACK1, ACT_GESTURE_RANGE_ATTACK_GLOCK17,true },
- { ACT_RELOAD_LOW, ACT_RELOAD_GLOCK17_LOW, false }, // Nope
- { ACT_RANGE_ATTACK1_LOW, ACT_RANGE_ATTACK_GLOCK17_LOW, false }, // Nope
- { ACT_COVER_LOW, ACT_COVER_GLOCK17_LOW, false }, // Nope
- { ACT_RANGE_AIM_LOW, ACT_RANGE_AIM_GLOCK17_LOW, false }, // Nope
- { ACT_GESTURE_RELOAD, ACT_GESTURE_RELOAD_GLOCK17, false }, // Nope
- { ACT_WALK, ACT_WALK_GLOCK17, false }, // Nope
- { ACT_RUN, ACT_RUN_GLOCK17, false }, // Nope
- };
- IMPLEMENT_ACTTABLE( CP3WeaponGlock17 ); // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
- //-----------------------------------------------------------------------------
- // Purpose: Constructor
- //-----------------------------------------------------------------------------
- CP3WeaponGlock17::CP3WeaponGlock17( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
- {
- m_flSoonestPrimaryAttack = gpGlobals->curtime;
- m_flAccuracyPenalty = 0.0f;
- m_fMinRange1 = 24;
- m_fMaxRange1 = 1500;
- m_fMinRange2 = 24;
- m_fMaxRange2 = 200;
- m_bFiresUnderwater = true; // Doesn't really matter I guess, because the player will never be able to go underwater, but ehh... why not?...
- }
- //-----------------------------------------------------------------------------
- // Purpose:
- //-----------------------------------------------------------------------------
- void CP3WeaponGlock17::Precache( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
- {
- BaseClass::Precache();
- }
- //-----------------------------------------------------------------------------
- // Purpose:
- // Input :
- // Output :
- //-----------------------------------------------------------------------------
- void CP3WeaponGlock17::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ) // "CWeaponGlock17" changed to presumed counterpart "CP3WeaponGlock17", And CBaseCombatCharacter I didn't change
- {
- switch( pEvent->event )
- {
- case EVENT_WEAPON_GLOCK17_FIRE:
- {
- Vector vecShootOrigin, vecShootDir;
- vecShootOrigin = pOperator->Weapon_ShootPosition();
- CAI_BaseNPC *npc = pOperator->MyNPCPointer();
- ASSERT( npc != NULL );
- vecShootDir = npc->GetActualShootTrajectory( vecShootOrigin );
- CSoundEnt::InsertSound( SOUND_COMBAT|SOUND_CONTEXT_GUNFIRE, pOperator->GetAbsOrigin(), SOUNDENT_VOLUME_GLOCK17, 0.2, pOperator, SOUNDENT_CHANNEL_WEAPON, pOperator->GetEnemy() );
- 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 CP3WeaponGlock17::DryFire( void ) // Changed "CPWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
- {
- WeaponSound( EMPTY );
- SendWeaponAnim( ACT_VM_DRYFIRE );
- m_flSoonestPrimaryAttack = gpGlobals->curtime + GLOCK17_FASTEST_DRY_REFIRE_TIME;
- m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration();
- }
- //-----------------------------------------------------------------------------
- // Purpose:
- //-----------------------------------------------------------------------------
- void CP3WeaponGlock17::PrimaryAttack( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
- {
- if ( ( gpGlobals->curtime - m_flLastAttackTime ) > 0.5f )
- {
- m_nNumShotsFired = 0;
- }
- else
- {
- m_nNumShotsFired++;
- }
- m_flLastAttackTime = gpGlobals->curtime;
- m_flSoonestPrimaryAttack = gpGlobals->curtime + GLOCK17_FASTEST_REFIRE_TIME;
- CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), SOUNDENT_VOLUME_GLOCK17, 0.2, GetOwner() );
- CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); // Not sure if I needed to change "CBasePlayer" or not... found some strings of code that may replace that base but I don't know at the moment.
- if( pOwner )
- {
- // Each time the player fires the glock17, it 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 += GLOCK17_ACCURACY_SHOT_PENALTY_TIME;
- m_iPrimaryAttacks++;
- gamestats->Event_WeaponFired( pOwner, true, GetClassname() );
- }
- //-----------------------------------------------------------------------------
- // Purpose:
- //-----------------------------------------------------------------------------
- void CP3WeaponGlock17::UpdatePenaltyTime( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
- {
- CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); // Not sure if I needed to change "CBasePlayer" or not... found some strings of code that may replace that base but I don't know at the moment.
- 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, GLOCK17_ACCURACY_MAXIMUM_PENALTY_TIME );
- }
- }
- //-----------------------------------------------------------------------------
- // Purpose:
- //-----------------------------------------------------------------------------
- void CP3WeaponGlock17::ItemPreFrame( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
- {
- UpdatePenaltyTime();
- BaseClass::ItemPreFrame();
- }
- //-----------------------------------------------------------------------------
- // Purpose:
- //-----------------------------------------------------------------------------
- void CP3WeaponGlock17::ItemBusyFrame( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
- {
- UpdatePenaltyTime();
- BaseClass::ItemBusyFrame();
- }
- //-----------------------------------------------------------------------------
- // Purpose: Allows firing as fast as button is pressed
- //-----------------------------------------------------------------------------
- void CP3WeaponGlock17::ItemPostFrame( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
- {
- BaseClass::ItemPostFrame();
- if ( m_bInReload )
- return;
- CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
- if ( pOwner == NULL )
- return;
- //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();
- }
- }
- //-----------------------------------------------------------------------------
- // Purpose:
- // Output : int
- //-----------------------------------------------------------------------------
- Activity CP3WeaponGlock17::GetPrimaryAttackActivity( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
- {
- if ( m_nNumShotsFired < 1 )
- return ACT_VM_PRIMARYATTACK;
- if ( m_nNumShotsFired < 2 )
- return ACT_VM_RECOIL1;
- if ( m_nNumShotsFired < 3 )
- return ACT_VM_RECOIL2;
- return ACT_VM_RECOIL3;
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- bool CP3WeaponGlock17::Reload( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
- {
- bool fRet = DefaultReload( GetMaxClip1(), GetMaxClip2(), ACT_VM_RELOAD );
- if ( fRet )
- {
- WeaponSound( RELOAD );
- m_flAccuracyPenalty = 0.0f;
- }
- return fRet;
- }
- //-----------------------------------------------------------------------------
- // Purpose:
- //-----------------------------------------------------------------------------
- void CP3WeaponGlock17::AddViewKick( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
- {
- CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
- if ( pPlayer == NULL )
- return;
- 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 );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement