Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.27 KB | None | 0 0
  1. //         ========= Whackjob Interactive - Pseudonym_Tim ============         //
  2. //                                                                             //
  3. // GLOCK17 WEAPON REFERENCE                                                    //
  4. // Business Related Inquiries/Contact Info: Mute2673@gmail.com                 //
  5. //=============================================================================//
  6.  
  7. /* NOTE: Not sure if I needed to change these to different headers that may be in your source build,
  8. but I did change some anyway to what I'm pretty sure they are. Fix them if they are incorrect. */
  9. #include "cbase.h"
  10. #include "npcevent.h"
  11. #include "baseweapon.h"     // "basehlcombatweapon" Changed to presumed counterpart "baseweapon"...
  12. #include "basecombatcharacter.h"
  13. #include "ai_basenpc.h"
  14. #include "player.h"
  15. #include "p3gamerules.h"    // "gamerules" Changed to presumed counterpart "p3gamerules"...
  16. #include "in_buttons.h"
  17. #include "soundent.h"
  18. #include "game.h"
  19. #include "vstdlib/random.h"
  20. #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
  21.  
  22. // memdbgon must be the last include file in a .cpp file!!!
  23. #include "tier0/memdbgon.h"
  24.  
  25. #define GLOCK17_FASTEST_REFIRE_TIME     0.2f
  26. #define GLOCK17_FASTEST_DRY_REFIRE_TIME 0.2f
  27.  
  28. #define GLOCK17_ACCURACY_SHOT_PENALTY_TIME      0.2f    // Applied amount of time each shot adds to the time we must recover from
  29. #define GLOCK17_ACCURACY_MAXIMUM_PENALTY_TIME   1.5f    // Maximum penalty to deal out
  30.  
  31. ConVar  glock17_use_new_accuracy( "glock17_use_new_accuracy", "1" );
  32.  
  33. //-----------------------------------------------------------------------------
  34. // CWeaponGlock17
  35. //-----------------------------------------------------------------------------
  36.  
  37. /* 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
  38. with the information from the .dll files. Fix them if they are incorrect. */
  39.  
  40. class CP3WeaponGlock17 : public CBaseWeapon // public "CBaseHLCombatWeapon" Changed to presumed counterpart "CBaseWeapon", And class "CWeaponGlock17" changed to presumed counterpart "CP3WeaponGlock17"
  41. {
  42.     DECLARE_DATADESC();
  43.  
  44. public:
  45.     DECLARE_CLASS( CP3WeaponGlock17, CBaseWeapon ); // "CBaseHLCombatWeapon" Changed to presumed counterpart "CBaseWeapon", And class "CWeaponGlock17" changed to presumed counterpart "CP3WeaponGlock17"
  46. {
  47.  
  48.     CP3WeaponGlock17(void); // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
  49.  
  50.     DECLARE_SERVERCLASS();
  51.  
  52.     void    Precache( void );
  53.     void    ItemPostFrame( void );
  54.     void    ItemPreFrame( void );
  55.     void    ItemBusyFrame( void );
  56.     void    PrimaryAttack( void );
  57.     void    AddViewKick( void );
  58.     void    DryFire( void );
  59.     void    Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ); // Not sure if CBaseCombatCharacter needed to be changed.
  60.  
  61.     void    UpdatePenaltyTime( void );
  62.  
  63.     int     CapabilitiesGet( void ) { return bits_CAP_WEAPON_RANGE_ATTACK1; }
  64.     Activity    GetPrimaryAttackActivity( void );
  65.  
  66.     virtual bool Reload( void );
  67.  
  68.     virtual const Vector& GetBulletSpread( void )
  69.     {      
  70.         // Handle NPCs first
  71.         static Vector npcCone = VECTOR_CONE_5DEGREES;
  72.         if ( GetOwner() && GetOwner()->IsNPC() )
  73.             return npcCone;
  74.            
  75.         static Vector cone;
  76.  
  77.         if ( glock17_use_new_accuracy.GetBool() )
  78.         {
  79.             float ramp = RemapValClamped(   m_flAccuracyPenalty,
  80.                                             0.0f,
  81.                                             GLOCK17_ACCURACY_MAXIMUM_PENALTY_TIME,
  82.                                             0.0f,
  83.                                             1.0f );
  84.  
  85.             // We lerp from very accurate to inaccurate over time
  86.             VectorLerp( VECTOR_CONE_1DEGREES, VECTOR_CONE_6DEGREES, ramp, cone );
  87.         }
  88.         else
  89.         {
  90.             // Old value
  91.             // *Cough...*
  92.             cone = VECTOR_CONE_4DEGREES;
  93.         }
  94.  
  95.         return cone;
  96.     }
  97.    
  98.     virtual int GetMinBurst()
  99.     {
  100.         return 1;
  101.     }
  102.  
  103.     virtual int GetMaxBurst()
  104.     {
  105.         return 3;
  106.     }
  107.  
  108.     virtual float GetFireRate( void )
  109.     {
  110.         return 0.2f;
  111.     }
  112.  
  113.     DECLARE_ACTTABLE();
  114.  
  115. private:
  116.     float   m_flSoonestPrimaryAttack;
  117.     float   m_flLastAttackTime;
  118.     float   m_flAccuracyPenalty;
  119.     int     m_nNumShotsFired;
  120. };
  121.  
  122.  
  123. IMPLEMENT_SERVERCLASS_ST(CP3WeaponGlock17, DT_P3_WeaponGlock17) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17", And changed "DT_WeaponGlock17" to presumed counterpart "DT_P3_WeaponGlock17"...
  124. END_SEND_TABLE()
  125.  
  126. LINK_ENTITY_TO_CLASS( p3_weapon_glock17, CP3WeaponGlock17 ); // "weapon_glock17" changed to presumed counterpart "p3_weapon_glock17", And "CWeaponGlock17" changed to presumed counterpart "CP3WeaponGlock17"...
  127. PRECACHE_WEAPON_REGISTER( p3_weapon_glock17 );  // "weapon_glock17" changed to presumed counterpart "p3_weapon_glock17"...
  128.  
  129. BEGIN_DATADESC( CP3WeaponGlock17 ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
  130.  
  131.     DEFINE_FIELD( m_flSoonestPrimaryAttack, FIELD_TIME ),
  132.     DEFINE_FIELD( m_flLastAttackTime,       FIELD_TIME ),
  133.     DEFINE_FIELD( m_flAccuracyPenalty,      FIELD_FLOAT ), //NOTE: This is NOT tracking game time
  134.     DEFINE_FIELD( m_nNumShotsFired,         FIELD_INTEGER ),
  135.  
  136. END_DATADESC()
  137.  
  138. // 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...
  139. acttable_t  CP3WeaponGlock17::m_acttable[] =  // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
  140. {
  141.     { ACT_IDLE,                     ACT_IDLE_GLOCK17,               true },
  142.     { ACT_IDLE_ANGRY,               ACT_IDLE_ANGRY_GLOCK17,         true },
  143.     { ACT_RANGE_ATTACK1,            ACT_RANGE_ATTACK_GLOCK17,       true },
  144.     { ACT_RELOAD,                   ACT_RELOAD_GLOCK17,             true },
  145.     { ACT_WALK_AIM,                 ACT_WALK_AIM_GLOCK17,           true },
  146.     { ACT_RUN_AIM,                  ACT_RUN_AIM_GLOCK17,                true },
  147.     { ACT_GESTURE_RANGE_ATTACK1,    ACT_GESTURE_RANGE_ATTACK_GLOCK17,true },
  148.     { ACT_RELOAD_LOW,               ACT_RELOAD_GLOCK17_LOW,         false }, // Nope
  149.     { ACT_RANGE_ATTACK1_LOW,        ACT_RANGE_ATTACK_GLOCK17_LOW,   false }, // Nope
  150.     { ACT_COVER_LOW,                ACT_COVER_GLOCK17_LOW,          false }, // Nope
  151.     { ACT_RANGE_AIM_LOW,            ACT_RANGE_AIM_GLOCK17_LOW,      false }, // Nope
  152.     { ACT_GESTURE_RELOAD,           ACT_GESTURE_RELOAD_GLOCK17,     false }, // Nope
  153.     { ACT_WALK,                     ACT_WALK_GLOCK17,               false }, // Nope
  154.     { ACT_RUN,                      ACT_RUN_GLOCK17,                    false }, // Nope
  155. };
  156.  
  157.  
  158. IMPLEMENT_ACTTABLE( CP3WeaponGlock17 ); // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
  159.  
  160. //-----------------------------------------------------------------------------
  161. // Purpose: Constructor
  162. //-----------------------------------------------------------------------------
  163. CP3WeaponGlock17::CP3WeaponGlock17( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
  164. {
  165.     m_flSoonestPrimaryAttack = gpGlobals->curtime;
  166.     m_flAccuracyPenalty = 0.0f;
  167.  
  168.     m_fMinRange1        = 24;
  169.     m_fMaxRange1        = 1500;
  170.     m_fMinRange2        = 24;
  171.     m_fMaxRange2        = 200;
  172.  
  173.     m_bFiresUnderwater  = true; // Doesn't really matter I guess, because the player will never be able to go underwater, but ehh... why not?...
  174. }
  175.  
  176. //-----------------------------------------------------------------------------
  177. // Purpose:
  178. //-----------------------------------------------------------------------------
  179. void CP3WeaponGlock17::Precache( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
  180. {
  181.     BaseClass::Precache();
  182. }
  183.  
  184. //-----------------------------------------------------------------------------
  185. // Purpose:
  186. // Input  :
  187. // Output :
  188. //-----------------------------------------------------------------------------
  189. void CP3WeaponGlock17::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ) // "CWeaponGlock17" changed to presumed counterpart "CP3WeaponGlock17", And CBaseCombatCharacter I didn't change
  190. {
  191.     switch( pEvent->event )
  192.     {
  193.         case EVENT_WEAPON_GLOCK17_FIRE:
  194.         {
  195.             Vector vecShootOrigin, vecShootDir;
  196.             vecShootOrigin = pOperator->Weapon_ShootPosition();
  197.  
  198.             CAI_BaseNPC *npc = pOperator->MyNPCPointer();
  199.             ASSERT( npc != NULL );
  200.  
  201.             vecShootDir = npc->GetActualShootTrajectory( vecShootOrigin );
  202.  
  203.             CSoundEnt::InsertSound( SOUND_COMBAT|SOUND_CONTEXT_GUNFIRE, pOperator->GetAbsOrigin(), SOUNDENT_VOLUME_GLOCK17, 0.2, pOperator, SOUNDENT_CHANNEL_WEAPON, pOperator->GetEnemy() );
  204.  
  205.             WeaponSound( SINGLE_NPC );
  206.             pOperator->FireBullets( 1, vecShootOrigin, vecShootDir, VECTOR_CONE_PRECALCULATED, MAX_TRACE_LENGTH, m_iPrimaryAmmoType, 2 );
  207.             pOperator->DoMuzzleFlash();
  208.             m_iClip1 = m_iClip1 - 1;
  209.         }
  210.         break;
  211.         default:
  212.             BaseClass::Operator_HandleAnimEvent( pEvent, pOperator );
  213.             break;
  214.     }
  215. }
  216.  
  217. //-----------------------------------------------------------------------------
  218. // Purpose:
  219. //-----------------------------------------------------------------------------
  220. void CP3WeaponGlock17::DryFire( void ) // Changed "CPWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
  221. {
  222.     WeaponSound( EMPTY );
  223.     SendWeaponAnim( ACT_VM_DRYFIRE );
  224.    
  225.     m_flSoonestPrimaryAttack    = gpGlobals->curtime + GLOCK17_FASTEST_DRY_REFIRE_TIME;
  226.     m_flNextPrimaryAttack       = gpGlobals->curtime + SequenceDuration();
  227. }
  228.  
  229. //-----------------------------------------------------------------------------
  230. // Purpose:
  231. //-----------------------------------------------------------------------------
  232. void CP3WeaponGlock17::PrimaryAttack( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
  233. {
  234.     if ( ( gpGlobals->curtime - m_flLastAttackTime ) > 0.5f )
  235.     {
  236.         m_nNumShotsFired = 0;
  237.     }
  238.     else
  239.     {
  240.         m_nNumShotsFired++;
  241.     }
  242.  
  243.     m_flLastAttackTime = gpGlobals->curtime;
  244.     m_flSoonestPrimaryAttack = gpGlobals->curtime + GLOCK17_FASTEST_REFIRE_TIME;
  245.     CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), SOUNDENT_VOLUME_GLOCK17, 0.2, GetOwner() );
  246.  
  247.     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.
  248.  
  249.     if( pOwner )
  250.     {
  251.         // Each time the player fires the glock17, it reset the view punch. This prevents
  252.         // the aim from 'drifting off' when the player fires very quickly. This may
  253.         // not be the ideal way to achieve this, but it's cheap and it works, which is
  254.         // great for a feature we're evaluating. (sjb)
  255.         pOwner->ViewPunchReset();
  256.     }
  257.  
  258.     BaseClass::PrimaryAttack();
  259.  
  260.     // Add an accuracy penalty which can move past our maximum penalty time if we're really spastic
  261.     m_flAccuracyPenalty += GLOCK17_ACCURACY_SHOT_PENALTY_TIME;
  262.  
  263.     m_iPrimaryAttacks++;
  264.     gamestats->Event_WeaponFired( pOwner, true, GetClassname() );
  265. }
  266.  
  267. //-----------------------------------------------------------------------------
  268. // Purpose:
  269. //-----------------------------------------------------------------------------
  270. void CP3WeaponGlock17::UpdatePenaltyTime( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
  271. {
  272.     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.
  273.  
  274.     if ( pOwner == NULL )
  275.         return;
  276.  
  277.     // Check our penalty time decay
  278.     if ( ( ( pOwner->m_nButtons & IN_ATTACK ) == false ) && ( m_flSoonestPrimaryAttack < gpGlobals->curtime ) )
  279.     {
  280.         m_flAccuracyPenalty -= gpGlobals->frametime;
  281.         m_flAccuracyPenalty = clamp( m_flAccuracyPenalty, 0.0f, GLOCK17_ACCURACY_MAXIMUM_PENALTY_TIME );
  282.     }
  283. }
  284.  
  285. //-----------------------------------------------------------------------------
  286. // Purpose:
  287. //-----------------------------------------------------------------------------
  288. void CP3WeaponGlock17::ItemPreFrame( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
  289. {
  290.     UpdatePenaltyTime();
  291.  
  292.     BaseClass::ItemPreFrame();
  293. }
  294.  
  295. //-----------------------------------------------------------------------------
  296. // Purpose:
  297. //-----------------------------------------------------------------------------
  298. void CP3WeaponGlock17::ItemBusyFrame( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
  299. {
  300.     UpdatePenaltyTime();
  301.  
  302.     BaseClass::ItemBusyFrame();
  303. }
  304.  
  305. //-----------------------------------------------------------------------------
  306. // Purpose: Allows firing as fast as button is pressed
  307. //-----------------------------------------------------------------------------
  308. void CP3WeaponGlock17::ItemPostFrame( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
  309. {
  310.     BaseClass::ItemPostFrame();
  311.  
  312.     if ( m_bInReload )
  313.         return;
  314.    
  315.     CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
  316.  
  317.     if ( pOwner == NULL )
  318.         return;
  319.  
  320.     //Allow a refire as fast as the player can click
  321.     if ( ( ( pOwner->m_nButtons & IN_ATTACK ) == false ) && ( m_flSoonestPrimaryAttack < gpGlobals->curtime ) )
  322.     {
  323.         m_flNextPrimaryAttack = gpGlobals->curtime - 0.1f;
  324.     }
  325.     else if ( ( pOwner->m_nButtons & IN_ATTACK ) && ( m_flNextPrimaryAttack < gpGlobals->curtime ) && ( m_iClip1 <= 0 ) )
  326.     {
  327.         DryFire();
  328.     }
  329. }
  330.  
  331. //-----------------------------------------------------------------------------
  332. // Purpose:
  333. // Output : int
  334. //-----------------------------------------------------------------------------
  335. Activity CP3WeaponGlock17::GetPrimaryAttackActivity( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
  336. {
  337.     if ( m_nNumShotsFired < 1 )
  338.         return ACT_VM_PRIMARYATTACK;
  339.  
  340.     if ( m_nNumShotsFired < 2 )
  341.         return ACT_VM_RECOIL1;
  342.  
  343.     if ( m_nNumShotsFired < 3 )
  344.         return ACT_VM_RECOIL2;
  345.  
  346.     return ACT_VM_RECOIL3;
  347. }
  348.  
  349. //-----------------------------------------------------------------------------
  350. //-----------------------------------------------------------------------------
  351. bool CP3WeaponGlock17::Reload( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
  352. {
  353.     bool fRet = DefaultReload( GetMaxClip1(), GetMaxClip2(), ACT_VM_RELOAD );
  354.     if ( fRet )
  355.     {
  356.         WeaponSound( RELOAD );
  357.         m_flAccuracyPenalty = 0.0f;
  358.     }
  359.     return fRet;
  360. }
  361.  
  362. //-----------------------------------------------------------------------------
  363. // Purpose:
  364. //-----------------------------------------------------------------------------
  365. void CP3WeaponGlock17::AddViewKick( void ) // Changed "CWeaponGlock17" to presumed counterpart "CP3WeaponGlock17"...
  366. {
  367.     CBasePlayer *pPlayer  = ToBasePlayer( GetOwner() );
  368.    
  369.     if ( pPlayer == NULL )
  370.         return;
  371.  
  372.     QAngle  viewPunch;
  373.  
  374.     viewPunch.x = random->RandomFloat( 0.25f, 0.5f );
  375.     viewPunch.y = random->RandomFloat( -.6f, .6f );
  376.     viewPunch.z = 0.0f;
  377.  
  378.     //Add it to the view punch
  379.     pPlayer->ViewPunch( viewPunch );
  380. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement