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.

211 lines
4.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "fx_dod_shared.h"
  8. #include "weapon_dodfireselect.h"
  9. #ifdef CLIENT_DLL
  10. #include "prediction.h"
  11. #endif
  12. IMPLEMENT_NETWORKCLASS_ALIASED( DODFireSelectWeapon, DT_FireSelectWeapon )
  13. BEGIN_NETWORK_TABLE( CDODFireSelectWeapon, DT_FireSelectWeapon )
  14. #ifdef CLIENT_DLL
  15. RecvPropBool( RECVINFO( m_bSemiAuto ) )
  16. #else
  17. SendPropBool( SENDINFO( m_bSemiAuto ) )
  18. #endif
  19. END_NETWORK_TABLE()
  20. BEGIN_PREDICTION_DATA( CDODFireSelectWeapon )
  21. END_PREDICTION_DATA()
  22. CDODFireSelectWeapon::CDODFireSelectWeapon()
  23. {
  24. }
  25. void CDODFireSelectWeapon::Spawn( void )
  26. {
  27. m_bSemiAuto = false;
  28. #ifdef CLIENT_DLL
  29. ResetViewModelAnimDir();
  30. #endif
  31. m_iAltFireHint = HINT_USE_SEMI_AUTO;
  32. BaseClass::Spawn();
  33. }
  34. void CDODFireSelectWeapon::PrimaryAttack( void )
  35. {
  36. if ( IsSemiAuto() )
  37. {
  38. // If semi auto, set this flag which will prevent us from
  39. // attacking again until the button is released.
  40. m_bInAttack = true;
  41. }
  42. BaseClass::PrimaryAttack();
  43. }
  44. float CDODFireSelectWeapon::GetFireDelay( void )
  45. {
  46. if ( IsSemiAuto() )
  47. {
  48. return m_pWeaponInfo->m_flSecondaryFireDelay;
  49. }
  50. else
  51. {
  52. return m_pWeaponInfo->m_flFireDelay;
  53. }
  54. }
  55. void CDODFireSelectWeapon::SecondaryAttack( void )
  56. {
  57. // toggle fire mode ( full auto, semi auto )
  58. m_bSemiAuto = !m_bSemiAuto;
  59. #ifndef CLIENT_DLL
  60. CDODPlayer *pPlayer = GetDODPlayerOwner();
  61. if ( pPlayer )
  62. {
  63. pPlayer->RemoveHintTimer( m_iAltFireHint );
  64. }
  65. #endif
  66. if ( m_bSemiAuto )
  67. {
  68. #ifdef CLIENT_DLL
  69. if ( prediction->IsFirstTimePredicted() )
  70. {
  71. m_flPosChangeTimer = gpGlobals->curtime;
  72. m_bAnimToSemiAuto = false;
  73. }
  74. #endif
  75. SendWeaponAnim( ACT_VM_UNDEPLOY );
  76. }
  77. else
  78. {
  79. #ifdef CLIENT_DLL
  80. if ( prediction->IsFirstTimePredicted() )
  81. {
  82. m_flPosChangeTimer = gpGlobals->curtime;
  83. m_bAnimToSemiAuto = true;
  84. }
  85. #endif
  86. SendWeaponAnim( ACT_VM_DEPLOY );
  87. }
  88. #ifdef CLIENT_DLL
  89. if ( prediction->IsFirstTimePredicted() )
  90. {
  91. m_flPosChangeTimer = gpGlobals->curtime;
  92. }
  93. #endif
  94. m_flNextSecondaryAttack = gpGlobals->curtime + SequenceDuration();
  95. m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration();
  96. }
  97. bool CDODFireSelectWeapon::IsSemiAuto( void )
  98. {
  99. return m_bSemiAuto;
  100. }
  101. float CDODFireSelectWeapon::GetWeaponAccuracy( float flPlayerSpeed )
  102. {
  103. float flSpread;
  104. if ( IsSemiAuto() )
  105. flSpread = m_pWeaponInfo->m_flSecondaryAccuracy;
  106. else
  107. flSpread = m_pWeaponInfo->m_flAccuracy;
  108. if( flPlayerSpeed > 45 )
  109. flSpread += m_pWeaponInfo->m_flAccuracyMovePenalty;
  110. return flSpread;
  111. }
  112. Activity CDODFireSelectWeapon::GetIdleActivity( void )
  113. {
  114. if ( !IsSemiAuto() )
  115. return ACT_VM_IDLE_DEPLOYED;
  116. return BaseClass::GetIdleActivity();
  117. }
  118. Activity CDODFireSelectWeapon::GetPrimaryAttackActivity( void )
  119. {
  120. if ( !IsSemiAuto() )
  121. return ACT_VM_PRIMARYATTACK_DEPLOYED;
  122. return BaseClass::GetPrimaryAttackActivity();
  123. }
  124. Activity CDODFireSelectWeapon::GetReloadActivity( void )
  125. {
  126. if ( !IsSemiAuto() )
  127. return ACT_VM_RELOAD_DEPLOYED;
  128. return BaseClass::GetReloadActivity();
  129. }
  130. Activity CDODFireSelectWeapon::GetDrawActivity( void )
  131. {
  132. if ( !IsSemiAuto() )
  133. return ACT_VM_DRAW_DEPLOYED;
  134. return BaseClass::GetDrawActivity();
  135. }
  136. void CDODFireSelectWeapon::Drop( const Vector &vecVelocity )
  137. {
  138. // always full auto when you pick up a weapon
  139. m_bSemiAuto = false;
  140. return BaseClass::Drop( vecVelocity );
  141. }
  142. #ifdef CLIENT_DLL
  143. Vector CDODFireSelectWeapon::GetDesiredViewModelOffset( C_DODPlayer *pOwner )
  144. {
  145. Vector viewOffset = pOwner->GetViewOffset();
  146. float flPercent = ( viewOffset.z - VEC_PRONE_VIEW_SCALED( pOwner ).z ) / ( VEC_VIEW_SCALED( pOwner ).z - VEC_PRONE_VIEW_SCALED( pOwner ).z );
  147. Vector offset = ( flPercent * GetDODWpnData().m_vecViewNormalOffset +
  148. ( 1.0 - flPercent ) * GetDODWpnData().m_vecViewProneOffset );
  149. static float flLastPercent = 0;
  150. if ( prediction->InPrediction() )
  151. {
  152. return ( flLastPercent * offset +
  153. ( 1.0 - flLastPercent ) * GetDODWpnData().m_vecViewProneOffset );
  154. }
  155. float timer = gpGlobals->curtime - m_flPosChangeTimer;
  156. // how long since we changed iron sight mode
  157. float flPosChangePercent = clamp( ( timer / ( 0.3 ) ), 0.0, 1.0 );
  158. float flZoomPercent = ( m_bAnimToSemiAuto ? ( 1.0 - flPosChangePercent ) : flPosChangePercent );
  159. // store this value to use when called in prediction
  160. flLastPercent = flZoomPercent;
  161. return ( flZoomPercent * GetDODWpnData().m_vecIronSightOffset +
  162. ( 1.0 - flZoomPercent ) * offset );
  163. }
  164. #endif