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.

282 lines
6.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "util.h"
  8. #include "weapon_tfc_minigun.h"
  9. #include "decals.h"
  10. #include "in_buttons.h"
  11. #if defined( CLIENT_DLL )
  12. #include "c_tfc_player.h"
  13. #else
  14. #include "tfc_player.h"
  15. #endif
  16. // ----------------------------------------------------------------------------- //
  17. // CTFCMinigun tables.
  18. // ----------------------------------------------------------------------------- //
  19. IMPLEMENT_NETWORKCLASS_ALIASED( TFCMinigun, DT_WeaponMinigun )
  20. BEGIN_NETWORK_TABLE( CTFCMinigun, DT_WeaponMinigun )
  21. END_NETWORK_TABLE()
  22. BEGIN_PREDICTION_DATA( CTFCMinigun )
  23. END_PREDICTION_DATA()
  24. LINK_ENTITY_TO_CLASS( weapon_minigun, CTFCMinigun );
  25. PRECACHE_WEAPON_REGISTER( weapon_minigun );
  26. #ifndef CLIENT_DLL
  27. BEGIN_DATADESC( CTFCMinigun )
  28. END_DATADESC()
  29. #endif
  30. // ----------------------------------------------------------------------------- //
  31. // CTFCMinigun implementation.
  32. // ----------------------------------------------------------------------------- //
  33. CTFCMinigun::CTFCMinigun()
  34. {
  35. m_iWeaponState = AC_STATE_IDLE;
  36. }
  37. bool CTFCMinigun::HasPrimaryAmmo()
  38. {
  39. return true;
  40. }
  41. bool CTFCMinigun::CanBeSelected()
  42. {
  43. return true;
  44. }
  45. void CTFCMinigun::Precache()
  46. {
  47. BaseClass::Precache();
  48. PrecacheScriptSound( "Weapon_Minigun.Deploy" );
  49. }
  50. bool CTFCMinigun::Deploy()
  51. {
  52. CPASAttenuationFilter filter( this );
  53. filter.UsePredictionRules();
  54. EmitSound( filter, entindex(), "Weapon_Minigun.Deploy" );
  55. return BaseClass::Deploy();
  56. }
  57. TFCWeaponID CTFCMinigun::GetWeaponID( void ) const
  58. {
  59. return WEAPON_MINIGUN;
  60. }
  61. void CTFCMinigun::WindUp( )
  62. {
  63. CTFCPlayer *pOwner = GetPlayerOwner();
  64. if ( !pOwner )
  65. return;
  66. if ( !(pOwner->m_nButtons & IN_ATTACK) )
  67. return;
  68. WeaponSound( SPECIAL1 ); // "special1" = wind up
  69. m_iWeaponState = AC_STATE_STARTFIRING;
  70. pOwner->m_Shared.AddStateFlags( TFSTATE_AIMING );
  71. // Play the "spin down" animation.
  72. SendWeaponAnim( ACT_VM_PULLBACK_HIGH );
  73. #ifdef GAME_DLL
  74. pOwner->TeamFortress_SetSpeed();
  75. #endif
  76. }
  77. void CTFCMinigun::WindDown( bool bFromHolster )
  78. {
  79. CTFCPlayer *pOwner = GetPlayerOwner();
  80. if ( !pOwner )
  81. return;
  82. WeaponSound( SPECIAL2 );
  83. m_iWeaponState = AC_STATE_IDLE;
  84. pOwner->m_Shared.RemoveStateFlags( TFSTATE_AIMING );
  85. m_flTimeWeaponIdle = gpGlobals->curtime + 2.0;
  86. // Play the "spin down" animation.
  87. SendWeaponAnim( ACT_VM_PULLBACK_LOW );
  88. #ifdef GAME_DLL
  89. pOwner->TeamFortress_SetSpeed();
  90. #endif
  91. }
  92. void CTFCMinigun::Spin()
  93. {
  94. CTFCPlayer *pOwner = GetPlayerOwner();
  95. if ( !pOwner )
  96. return;
  97. WeaponSound( SPECIAL3 ); // "special3" = spin
  98. pOwner->DoAnimationEvent( PLAYERANIMEVENT_FIRE_GUN );
  99. }
  100. void CTFCMinigun::Fire()
  101. {
  102. if ( m_flNextPrimaryAttack > gpGlobals->curtime )
  103. return;
  104. CTFCPlayer *pOwner = GetPlayerOwner();
  105. if ( !pOwner )
  106. return;
  107. pOwner->DoAnimationEvent( PLAYERANIMEVENT_FIRE_GUN );
  108. BaseClass::PrimaryAttack(); // Use the base HL2 system to fire.
  109. }
  110. void CTFCMinigun::StartSpin()
  111. {
  112. CTFCPlayer *pOwner = GetPlayerOwner();
  113. if ( !pOwner )
  114. return;
  115. WeaponSound( SPECIAL1 ); // "special1" = wind up
  116. // Rotate barrel without firing for fun
  117. m_iWeaponState = AC_STATE_SPINNING;
  118. pOwner->DoAnimationEvent( PLAYERANIMEVENT_FIRE_GUN );
  119. }
  120. void CTFCMinigun::PrimaryAttack()
  121. {
  122. CTFCPlayer *pOwner = GetPlayerOwner();
  123. if ( !pOwner )
  124. return;
  125. switch ( m_iWeaponState )
  126. {
  127. default:
  128. case AC_STATE_IDLE:
  129. // Removed the need for cells to powerup the AC
  130. WindUp();
  131. m_flNextPrimaryAttack = gpGlobals->curtime + 0.5;
  132. m_flTimeWeaponIdle = gpGlobals->curtime + 0.6;
  133. break;
  134. case AC_STATE_STARTFIRING:
  135. // Start playing the looping fire sound
  136. if ( m_flNextPrimaryAttack <= gpGlobals->curtime )
  137. {
  138. WeaponSound( SINGLE ); // "single" = the looping fire sound
  139. m_iWeaponState = AC_STATE_FIRING;
  140. m_flNextPrimaryAttack = m_flTimeWeaponIdle = gpGlobals->curtime + 0.1;
  141. }
  142. break;
  143. case AC_STATE_FIRING:
  144. Fire();
  145. m_flNextPrimaryAttack = m_flTimeWeaponIdle = gpGlobals->curtime + 0.1;
  146. break;
  147. }
  148. }
  149. void CTFCMinigun::HandleFireOnEmpty()
  150. {
  151. if ( m_iWeaponState == AC_STATE_FIRING )
  152. {
  153. StartSpin();
  154. m_flNextPrimaryAttack = m_flTimeWeaponIdle = gpGlobals->curtime + 0.1;
  155. }
  156. else if ( m_iWeaponState == AC_STATE_SPINNING )
  157. {
  158. if ( HasPrimaryAmmo() )
  159. Spin();
  160. else
  161. m_iWeaponState = AC_STATE_STARTFIRING;
  162. m_flNextPrimaryAttack = m_flTimeWeaponIdle = gpGlobals->curtime + 0.1;
  163. }
  164. else
  165. {
  166. BaseClass::HandleFireOnEmpty();
  167. }
  168. }
  169. void CTFCMinigun::WeaponIdle()
  170. {
  171. //ResetEmptySound( );
  172. if ( gpGlobals->curtime < m_flTimeWeaponIdle )
  173. return;
  174. // Always wind down if we've hit here, because it only happens when the player has stopped firing/spinning
  175. if ( m_iWeaponState != AC_STATE_IDLE )// && !(m_pPlayer->pev->button & IN_ATTACK) )
  176. {
  177. WindDown( FALSE );
  178. return;
  179. }
  180. SendWeaponAnim( ACT_IDLE );
  181. m_flTimeWeaponIdle = gpGlobals->curtime + 12.5;// how long till we do this again.
  182. }
  183. bool CTFCMinigun::SendWeaponAnim( int iActivity )
  184. {
  185. if ( GetActivity() == ACT_VM_PRIMARYATTACK && iActivity == ACT_VM_PRIMARYATTACK )
  186. {
  187. // The minigun's fire animation loops, so we don't want it to reset each time
  188. // they fire a bullet.
  189. return true;
  190. }
  191. else
  192. {
  193. return BaseClass::SendWeaponAnim( iActivity );
  194. }
  195. }
  196. #ifdef CLIENT_DLL
  197. // ------------------------------------------------------------------------------------------------ //
  198. // ------------------------------------------------------------------------------------------------ //
  199. // CLIENT DLL SPECIFIC CODE
  200. // ------------------------------------------------------------------------------------------------ //
  201. // ------------------------------------------------------------------------------------------------ //
  202. #else
  203. // ------------------------------------------------------------------------------------------------ //
  204. // ------------------------------------------------------------------------------------------------ //
  205. // GAME DLL SPECIFIC CODE
  206. // ------------------------------------------------------------------------------------------------ //
  207. // ------------------------------------------------------------------------------------------------ //
  208. #endif