Wazanator

weapon_CCG_equipmentbase.cpp

Jun 7th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.11 KB | None | 0 0
  1. //========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6.  
  7. #include "cbase.h"
  8.  
  9. #if defined( CLIENT_DLL )
  10.     #include "c_hl2mp_player.h"
  11. #else
  12.     #include "hl2mp_player.h"
  13. #endif
  14.  
  15. #include "weapon_CCG_equipmentbase.h"
  16. #include "in_buttons.h"
  17.  
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include "tier0/memdbgon.h"
  20.  
  21. IMPLEMENT_NETWORKCLASS_ALIASED( EquipCard, DT_EquipCard )
  22.  
  23. BEGIN_NETWORK_TABLE( CEquipCard, DT_EquipCard )
  24. END_NETWORK_TABLE()
  25.  
  26. BEGIN_PREDICTION_DATA( CEquipCard )
  27. END_PREDICTION_DATA()
  28.  
  29. //=========================================================
  30. //  >> CHLSelectFireMachineGun
  31. //=========================================================
  32. BEGIN_DATADESC( CEquipCard )
  33.  
  34.     DEFINE_FIELD( m_nShotsFired,    FIELD_INTEGER ),
  35.     DEFINE_FIELD( m_flNextSoundTime, FIELD_TIME ),
  36.  
  37. END_DATADESC()
  38.  
  39.  
  40. //-----------------------------------------------------------------------------
  41. // Purpose:
  42. //-----------------------------------------------------------------------------
  43. CEquipCard::CEquipCard( void )
  44. {
  45. }
  46.  
  47. const Vector &CEquipCard::GetBulletSpread( void )
  48. {
  49.     static Vector cone = VECTOR_CONE_3DEGREES;
  50.     return cone;
  51. }
  52.  
  53. //-----------------------------------------------------------------------------
  54. // Purpose:
  55. //
  56. //
  57. //-----------------------------------------------------------------------------
  58. void CEquipCard::PrimaryAttack( void )
  59. {
  60.     // Only the player fires this way so we can cast
  61.     CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
  62.     if (!pPlayer)
  63.         return;
  64.    
  65.     // Abort here to handle burst and auto fire modes
  66.     if ( (UsesClipsForAmmo1() && m_iClip1 == 0) || ( !UsesClipsForAmmo1() && !pPlayer->GetAmmoCount(m_iPrimaryAmmoType) ) )
  67.         return;
  68.  
  69.     m_nShotsFired++;
  70.  
  71.     pPlayer->DoMuzzleFlash();
  72.  
  73.     // To make the firing framerate independent, we may have to fire more than one bullet here on low-framerate systems,
  74.     // especially if the weapon we're firing has a really fast rate of fire.
  75.     int iBulletsToFire = 0;
  76.     float fireRate = GetFireRate();
  77.  
  78.     while ( m_flNextPrimaryAttack <= gpGlobals->curtime )
  79.     {
  80.         // MUST call sound before removing a round from the clip of a CHLMachineGun
  81.         WeaponSound(SINGLE, m_flNextPrimaryAttack);
  82.         m_flNextPrimaryAttack = m_flNextPrimaryAttack + fireRate;
  83.         iBulletsToFire++;
  84.     }
  85.  
  86.     // Make sure we don't fire more than the amount in the clip, if this weapon uses clips
  87.     if ( UsesClipsForAmmo1() )
  88.     {
  89.         if ( iBulletsToFire > m_iClip1 )
  90.             iBulletsToFire = m_iClip1;
  91.         m_iClip1 -= iBulletsToFire;
  92.     }
  93.  
  94.     CHL2MP_Player *pHL2MPPlayer = ToHL2MPPlayer( pPlayer );
  95.  
  96.         // Fire the bullets
  97.     FireBulletsInfo_t info;
  98.     info.m_iShots = iBulletsToFire;
  99.     info.m_vecSrc = pHL2MPPlayer->Weapon_ShootPosition( );
  100.     info.m_vecDirShooting = pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
  101.     info.m_vecSpread = pHL2MPPlayer->GetAttackSpread( this );
  102.     info.m_flDistance = MAX_TRACE_LENGTH;
  103.     info.m_iAmmoType = m_iPrimaryAmmoType;
  104.     info.m_iTracerFreq = 2;
  105.     FireBullets( info );
  106.  
  107.     //Factor in the view kick
  108.     AddViewKick();
  109.    
  110.     if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0)
  111.     {
  112.         // HEV suit - indicate out of ammo condition
  113.         pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0);
  114.     }
  115.  
  116.     SendWeaponAnim( GetPrimaryAttackActivity() );
  117.     pPlayer->SetAnimation( PLAYER_ATTACK1 );
  118.     ToHL2MPPlayer(pPlayer)->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
  119.  
  120. }
  121.  
  122. //-----------------------------------------------------------------------------
  123. // Purpose:
  124. // Input  : &info -
  125. //-----------------------------------------------------------------------------
  126. void CEquipCard::FireBullets( const FireBulletsInfo_t &info )
  127. {
  128.     if(CBasePlayer *pPlayer = ToBasePlayer ( GetOwner() ) )
  129.     {
  130.         pPlayer->FireBullets(info);
  131.     }
  132. }
  133.  
  134. //-----------------------------------------------------------------------------
  135. // Purpose:
  136. //-----------------------------------------------------------------------------
  137. void CEquipCard::DoMachineGunKick( CBasePlayer *pPlayer, float dampEasy, float maxVerticleKickAngle, float fireDurationTime, float slideLimitTime )
  138. {
  139.     #define KICK_MIN_X          0.2f    //Degrees
  140.     #define KICK_MIN_Y          0.2f    //Degrees
  141.     #define KICK_MIN_Z          0.1f    //Degrees
  142.  
  143.     QAngle vecScratch;
  144.     int iSeed = CBaseEntity::GetPredictionRandomSeed() & 255;
  145.    
  146.     //Find how far into our accuracy degradation we are
  147.     float duration  = ( fireDurationTime > slideLimitTime ) ? slideLimitTime : fireDurationTime;
  148.     float kickPerc = duration / slideLimitTime;
  149.  
  150.     // do this to get a hard discontinuity, clear out anything under 10 degrees punch
  151.     pPlayer->ViewPunchReset( 10 );
  152.  
  153.     //Apply this to the view angles as well
  154.     vecScratch.x = -( KICK_MIN_X + ( maxVerticleKickAngle * kickPerc ) );
  155.     vecScratch.y = -( KICK_MIN_Y + ( maxVerticleKickAngle * kickPerc ) ) / 3;
  156.     vecScratch.z = KICK_MIN_Z + ( maxVerticleKickAngle * kickPerc ) / 8;
  157.  
  158.     RandomSeed( iSeed );
  159.  
  160.     //Wibble left and right
  161.     if ( RandomInt( -1, 1 ) >= 0 )
  162.         vecScratch.y *= -1;
  163.  
  164.     iSeed++;
  165.  
  166.     //Wobble up and down
  167.     if ( RandomInt( -1, 1 ) >= 0 )
  168.         vecScratch.z *= -1;
  169.  
  170.     //Clip this to our desired min/max
  171.     UTIL_ClipPunchAngleOffset( vecScratch, pPlayer->m_Local.m_vecPunchAngle, QAngle( 24.0f, 3.0f, 1.0f ) );
  172.  
  173.     //Add it to the view punch
  174.     // NOTE: 0.5 is just tuned to match the old effect before the punch became simulated
  175.     pPlayer->ViewPunch( vecScratch * 0.5 );
  176. }
  177.  
  178. //-----------------------------------------------------------------------------
  179. // Purpose: Reset our shots fired
  180. //-----------------------------------------------------------------------------
  181. bool CEquipCard::Deploy( void )
  182. {
  183.     m_nShotsFired = 0;
  184.  
  185.     return BaseClass::Deploy();
  186. }
  187.  
  188.  
  189.  
  190. //-----------------------------------------------------------------------------
  191. // Purpose: Make enough sound events to fill the estimated think interval
  192. // returns: number of shots needed
  193. //-----------------------------------------------------------------------------
  194. int CEquipCard::WeaponSoundRealtime( WeaponSound_t shoot_type )
  195. {
  196.     int numBullets = 0;
  197.  
  198.     // ran out of time, clamp to current
  199.     if (m_flNextSoundTime < gpGlobals->curtime)
  200.     {
  201.         m_flNextSoundTime = gpGlobals->curtime;
  202.     }
  203.  
  204.     // make enough sound events to fill up the next estimated think interval
  205.     float dt = clamp( m_flAnimTime - m_flPrevAnimTime, 0, 0.2 );
  206.     if (m_flNextSoundTime < gpGlobals->curtime + dt)
  207.     {
  208.         WeaponSound( SINGLE_NPC, m_flNextSoundTime );
  209.         m_flNextSoundTime += GetFireRate();
  210.         numBullets++;
  211.     }
  212.     if (m_flNextSoundTime < gpGlobals->curtime + dt)
  213.     {
  214.         WeaponSound( SINGLE_NPC, m_flNextSoundTime );
  215.         m_flNextSoundTime += GetFireRate();
  216.         numBullets++;
  217.     }
  218.  
  219.     return numBullets;
  220. }
  221.  
  222.  
  223.  
  224.  
  225. //-----------------------------------------------------------------------------
  226. // Purpose:
  227. //-----------------------------------------------------------------------------
  228. void CEquipCard::ItemPostFrame( void )
  229. {
  230.     CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
  231.    
  232.     if ( pOwner == NULL )
  233.         return;
  234.  
  235.     // Debounce the recoiling counter
  236.     if ( ( pOwner->m_nButtons & IN_ATTACK ) == false )
  237.     {
  238.         m_nShotsFired = 0;
  239.     }
  240.  
  241.     BaseClass::ItemPostFrame();
  242. }
Advertisement
Add Comment
Please, Sign In to add comment