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.

221 lines
6.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //
  4. //=============================================================================
  5. #include "cbase.h"
  6. #include "tf_weapon_raygun.h"
  7. #include "tf_fx_shared.h"
  8. #include "in_buttons.h"
  9. // Client specific.
  10. #ifdef CLIENT_DLL
  11. #include "c_tf_player.h"
  12. #include "particle_property.h"
  13. #else
  14. #include "tf_player.h"
  15. #include "ndebugoverlay.h"
  16. #include "particle_parse.h"
  17. #include "tf_fx.h"
  18. #endif
  19. //============================
  20. IMPLEMENT_NETWORKCLASS_ALIASED( TFDRGPomson, DT_WeaponDRGPomson )
  21. BEGIN_NETWORK_TABLE( CTFDRGPomson, DT_WeaponDRGPomson )
  22. END_NETWORK_TABLE()
  23. BEGIN_PREDICTION_DATA( CTFDRGPomson )
  24. END_PREDICTION_DATA()
  25. LINK_ENTITY_TO_CLASS( tf_weapon_drg_pomson, CTFDRGPomson );
  26. PRECACHE_WEAPON_REGISTER( tf_weapon_drg_pomson );
  27. //============================
  28. IMPLEMENT_NETWORKCLASS_ALIASED( TFRaygun, DT_WeaponRaygun )
  29. BEGIN_NETWORK_TABLE( CTFRaygun, DT_WeaponRaygun )
  30. END_NETWORK_TABLE()
  31. BEGIN_PREDICTION_DATA( CTFRaygun )
  32. END_PREDICTION_DATA()
  33. LINK_ENTITY_TO_CLASS( tf_weapon_raygun, CTFRaygun );
  34. PRECACHE_WEAPON_REGISTER( tf_weapon_raygun );
  35. //-----------------------------------------------------------------------------
  36. // Purpose:
  37. //-----------------------------------------------------------------------------
  38. CTFRaygun::CTFRaygun()
  39. {
  40. m_flIrradiateTime = 0.f;
  41. m_bEffectsThinking = false;
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose:
  45. //-----------------------------------------------------------------------------
  46. void CTFRaygun::Precache()
  47. {
  48. PrecacheParticleSystem( "drg_bison_impact" );
  49. PrecacheParticleSystem( "drg_bison_idle" );
  50. PrecacheParticleSystem( "drg_bison_muzzleflash" );
  51. BaseClass::Precache();
  52. }
  53. //-----------------------------------------------------------------------------
  54. // Purpose:
  55. //-----------------------------------------------------------------------------
  56. const char *CTFRaygun::GetMuzzleFlashParticleEffect( void )
  57. {
  58. return "drg_bison_muzzleflash";
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose:
  62. //-----------------------------------------------------------------------------
  63. void CTFRaygun::PrimaryAttack( void )
  64. {
  65. if ( !Energy_HasEnergy() )
  66. return;
  67. BaseClass::PrimaryAttack();
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Purpose:
  71. //-----------------------------------------------------------------------------
  72. void CTFRaygun::ModifyProjectile( CBaseEntity* pProj )
  73. {
  74. #ifdef GAME_DLL
  75. /*
  76. CTFProjectile_EnergyRing* pEnergyBall = dynamic_cast<CTFProjectile_EnergyRing*>( pProj );
  77. if ( pEnergyBall == NULL )
  78. return;
  79. pEnergyBall->SetColor( 1, GetParticleColor( 1 ) );
  80. pEnergyBall->SetColor( 2, GetParticleColor( 2 ) );
  81. */
  82. #endif
  83. Energy_DrainEnergy();
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Purpose:
  87. //-----------------------------------------------------------------------------
  88. float CTFRaygun::GetProgress( void )
  89. {
  90. return Energy_GetEnergy() / ENERGY_WEAPON_MAX_CHARGE;
  91. }
  92. #ifdef CLIENT_DLL
  93. //-----------------------------------------------------------------------------
  94. // Purpose:
  95. //-----------------------------------------------------------------------------
  96. void CTFRaygun::DispatchMuzzleFlash( const char* effectName, C_BaseEntity* pAttachEnt )
  97. {
  98. DispatchParticleEffect( effectName, PATTACH_POINT_FOLLOW, pAttachEnt, "muzzle", GetParticleColor( 1 ), GetParticleColor( 2 ) );
  99. }
  100. #endif
  101. //-----------------------------------------------------------------------------
  102. // Purpose:
  103. //-----------------------------------------------------------------------------
  104. bool CTFRaygun::Holster( CBaseCombatWeapon *pSwitchingTo )
  105. {
  106. #ifdef CLIENT_DLL
  107. m_bEffectsThinking = false;
  108. #endif
  109. return BaseClass::Holster( pSwitchingTo );
  110. }
  111. //-----------------------------------------------------------------------------
  112. // Purpose:
  113. //-----------------------------------------------------------------------------
  114. bool CTFRaygun::Deploy( void )
  115. {
  116. #ifdef CLIENT_DLL
  117. m_bEffectsThinking = true;
  118. SetContextThink( &CTFRaygun::ClientEffectsThink, gpGlobals->curtime + rand() % 5, "EFFECTS_THINK" );
  119. #endif
  120. return BaseClass::Deploy();
  121. }
  122. //-----------------------------------------------------------------------------
  123. // Purpose:
  124. //-----------------------------------------------------------------------------
  125. void CTFRaygun::ItemPostFrame( void )
  126. {
  127. BaseClass::ItemPostFrame();
  128. #ifdef CLIENT_DLL
  129. if ( !m_bEffectsThinking )
  130. {
  131. m_bEffectsThinking = true;
  132. SetContextThink( &CTFRaygun::ClientEffectsThink, gpGlobals->curtime + rand() % 5, "EFFECTS_THINK" );
  133. }
  134. #endif
  135. }
  136. #ifdef CLIENT_DLL
  137. //-----------------------------------------------------------------------------
  138. // Purpose:
  139. //-----------------------------------------------------------------------------
  140. void CTFRaygun::ClientEffectsThink( void )
  141. {
  142. CTFPlayer *pPlayer = GetTFPlayerOwner();
  143. if ( !pPlayer )
  144. return;
  145. if ( !pPlayer->IsLocalPlayer() )
  146. return;
  147. if ( !pPlayer->GetViewModel() )
  148. return;
  149. if ( !m_bEffectsThinking )
  150. return;
  151. SetContextThink( &CTFRaygun::ClientEffectsThink, gpGlobals->curtime + 2 + rand() % 5, "EFFECTS_THINK" );
  152. ParticleProp()->Init( this );
  153. CNewParticleEffect* pEffect = ParticleProp()->Create( "drg_bison_idle", PATTACH_POINT_FOLLOW, "muzzle" );
  154. if ( pEffect )
  155. {
  156. pEffect->SetControlPoint( CUSTOM_COLOR_CP1, GetParticleColor( 1 ) );
  157. pEffect->SetControlPoint( CUSTOM_COLOR_CP2, GetParticleColor( 2 ) );
  158. }
  159. }
  160. #endif
  161. //-----------------------------------------------------------------------------
  162. // Purpose:
  163. //-----------------------------------------------------------------------------
  164. float CTFRaygun::GetProjectileSpeed( void )
  165. {
  166. return 1200.f;
  167. }
  168. //-----------------------------------------------------------------------------
  169. // Purpose:
  170. //-----------------------------------------------------------------------------
  171. float CTFRaygun::GetProjectileGravity( void )
  172. {
  173. return 0.f;
  174. }
  175. //-----------------------------------------------------------------------------
  176. // Purpose:
  177. //-----------------------------------------------------------------------------
  178. bool CTFRaygun::IsViewModelFlipped( void )
  179. {
  180. return !BaseClass::IsViewModelFlipped();
  181. }