Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

235 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "decals.h"
  8. #include "cbase.h"
  9. #include "shake.h"
  10. #include "weapon_csbase.h"
  11. #include "fx_cs_shared.h"
  12. #if defined( CLIENT_DLL )
  13. #define CDEagle C_DEagle
  14. #include "c_cs_player.h"
  15. #else
  16. #include "cs_player.h"
  17. #endif
  18. #define DEAGLE_WEIGHT 7
  19. #define DEAGLE_MAX_CLIP 7
  20. enum deagle_e {
  21. DEAGLE_IDLE1 = 0,
  22. DEAGLE_SHOOT1,
  23. DEAGLE_SHOOT2,
  24. DEAGLE_SHOOT_EMPTY,
  25. DEAGLE_RELOAD,
  26. DEAGLE_DRAW,
  27. };
  28. class CDEagle : public CWeaponCSBase
  29. {
  30. public:
  31. DECLARE_CLASS( CDEagle, CWeaponCSBase );
  32. DECLARE_NETWORKCLASS();
  33. DECLARE_PREDICTABLE();
  34. CDEagle();
  35. void Spawn();
  36. void PrimaryAttack();
  37. virtual bool Deploy();
  38. bool Reload();
  39. void WeaponIdle();
  40. void MakeBeam ();
  41. void BeamUpdate ();
  42. virtual bool UseDecrement() {return true;};
  43. virtual float GetInaccuracy() const;
  44. virtual CSWeaponID GetWeaponID( void ) const { return WEAPON_DEAGLE; }
  45. public:
  46. float m_flLastFire;
  47. private:
  48. CDEagle( const CDEagle & );
  49. };
  50. IMPLEMENT_NETWORKCLASS_ALIASED( DEagle, DT_WeaponDEagle )
  51. BEGIN_NETWORK_TABLE( CDEagle, DT_WeaponDEagle )
  52. END_NETWORK_TABLE()
  53. #if defined CLIENT_DLL
  54. BEGIN_PREDICTION_DATA( CDEagle )
  55. DEFINE_FIELD( m_flLastFire, FIELD_FLOAT ),
  56. END_PREDICTION_DATA()
  57. #endif
  58. LINK_ENTITY_TO_CLASS( weapon_deagle, CDEagle );
  59. PRECACHE_WEAPON_REGISTER( weapon_deagle );
  60. CDEagle::CDEagle()
  61. {
  62. m_flLastFire = gpGlobals->curtime;
  63. }
  64. void CDEagle::Spawn()
  65. {
  66. BaseClass::Spawn();
  67. m_flAccuracy = 0.9;
  68. }
  69. bool CDEagle::Deploy()
  70. {
  71. m_flAccuracy = 0.9;
  72. return BaseClass::Deploy();
  73. }
  74. float CDEagle::GetInaccuracy() const
  75. {
  76. if ( weapon_accuracy_model.GetInt() == 1 )
  77. {
  78. CCSPlayer *pPlayer = GetPlayerOwner();
  79. if ( !pPlayer )
  80. return 0.0f;
  81. if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) )
  82. return 1.5f * (1 - m_flAccuracy);
  83. else if (pPlayer->GetAbsVelocity().Length2D() > 5)
  84. return 0.25f * (1 - m_flAccuracy);
  85. else if ( FBitSet( pPlayer->GetFlags(), FL_DUCKING ) )
  86. return 0.115f * (1 - m_flAccuracy);
  87. else
  88. return 0.13f * (1 - m_flAccuracy);
  89. }
  90. else
  91. return BaseClass::GetInaccuracy();
  92. }
  93. void CDEagle::PrimaryAttack()
  94. {
  95. CCSPlayer *pPlayer = GetPlayerOwner();
  96. if ( !pPlayer )
  97. return;
  98. // Mark the time of this shot and determine the accuracy modifier based on the last shot fired...
  99. m_flAccuracy -= (0.35)*(0.4 - ( gpGlobals->curtime - m_flLastFire ) );
  100. if (m_flAccuracy > 0.9)
  101. m_flAccuracy = 0.9;
  102. else if (m_flAccuracy < 0.55)
  103. m_flAccuracy = 0.55;
  104. m_flLastFire = gpGlobals->curtime;
  105. if (m_iClip1 <= 0)
  106. {
  107. if ( m_bFireOnEmpty )
  108. {
  109. PlayEmptySound();
  110. m_flNextPrimaryAttack = gpGlobals->curtime + 0.1f;
  111. m_bFireOnEmpty = false;
  112. }
  113. return;
  114. }
  115. pPlayer->m_iShotsFired++;
  116. m_iClip1--;
  117. pPlayer->DoMuzzleFlash();
  118. if( m_iClip1 > 0 )
  119. SendWeaponAnim( ACT_VM_PRIMARYATTACK );
  120. else
  121. SendWeaponAnim( ACT_VM_DRYFIRE );
  122. //SetPlayerShieldAnim();
  123. // player "shoot" animation
  124. pPlayer->SetAnimation( PLAYER_ATTACK1 );
  125. //pPlayer->m_iWeaponVolume = BIG_EXPLOSION_VOLUME;
  126. //pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH;
  127. FX_FireBullets(
  128. pPlayer->entindex(),
  129. pPlayer->Weapon_ShootPosition(),
  130. pPlayer->EyeAngles() + 2.0f * pPlayer->GetPunchAngle(),
  131. GetWeaponID(),
  132. Primary_Mode,
  133. CBaseEntity::GetPredictionRandomSeed() & 255,
  134. GetInaccuracy(),
  135. GetSpread());
  136. m_flNextPrimaryAttack = gpGlobals->curtime + GetCSWpnData().m_flCycleTime;
  137. if ( !m_iClip1 && pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0 )
  138. {
  139. // HEV suit - indicate out of ammo condition
  140. pPlayer->SetSuitUpdate("!HEV_AMO0", false, 0);
  141. }
  142. SetWeaponIdleTime( gpGlobals->curtime + 1.8 );
  143. // update accuracy
  144. m_fAccuracyPenalty += GetCSWpnData().m_fInaccuracyImpulseFire[Primary_Mode];
  145. QAngle punchAngle = pPlayer->GetPunchAngle();
  146. punchAngle.x -= 2;
  147. pPlayer->SetPunchAngle( punchAngle );
  148. //ResetPlayerShieldAnim();
  149. }
  150. bool CDEagle::Reload()
  151. {
  152. if ( !DefaultPistolReload() )
  153. return false;
  154. m_flAccuracy = 0.9;
  155. return true;
  156. }
  157. void CDEagle::WeaponIdle()
  158. {
  159. if ( m_flTimeWeaponIdle > gpGlobals->curtime )
  160. return;
  161. SetWeaponIdleTime( gpGlobals->curtime + 20 );
  162. if (m_iClip1 != 0)
  163. {
  164. SendWeaponAnim( ACT_VM_IDLE );
  165. }
  166. //if ( FBitSet(m_iWeaponState, WPNSTATE_SHIELD_DRAWN) )
  167. // SendWeaponAnim( SHIELDGUN_DRAWN_IDLE, UseDecrement() ? 1:0 );
  168. }