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.

255 lines
7.3 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. #include "tf_gamestats.h"
  19. #include "tf_projectile_energy_ring.h"
  20. #endif
  21. //============================
  22. IMPLEMENT_NETWORKCLASS_ALIASED( TFRaygun, DT_WeaponRaygun )
  23. BEGIN_NETWORK_TABLE( CTFRaygun, DT_WeaponRaygun )
  24. #ifdef GAME_DLL
  25. SendPropBool( SENDINFO( m_bUseNewProjectileCode ) ),
  26. #else
  27. RecvPropBool( RECVINFO( m_bUseNewProjectileCode ) ),
  28. #endif
  29. END_NETWORK_TABLE()
  30. BEGIN_PREDICTION_DATA( CTFRaygun )
  31. END_PREDICTION_DATA()
  32. LINK_ENTITY_TO_CLASS( tf_weapon_raygun, CTFRaygun );
  33. PRECACHE_WEAPON_REGISTER( tf_weapon_raygun );
  34. //============================
  35. IMPLEMENT_NETWORKCLASS_ALIASED( TFDRGPomson, DT_WeaponDRGPomson )
  36. BEGIN_NETWORK_TABLE( CTFDRGPomson, DT_WeaponDRGPomson )
  37. END_NETWORK_TABLE()
  38. BEGIN_PREDICTION_DATA( CTFDRGPomson )
  39. END_PREDICTION_DATA()
  40. LINK_ENTITY_TO_CLASS( tf_weapon_drg_pomson, CTFDRGPomson );
  41. PRECACHE_WEAPON_REGISTER( tf_weapon_drg_pomson );
  42. //-----------------------------------------------------------------------------
  43. // Purpose:
  44. //-----------------------------------------------------------------------------
  45. CTFRaygun::CTFRaygun()
  46. {
  47. m_bUseNewProjectileCode = false;
  48. #ifdef GAME_DLL
  49. // Goofyness to preserve demos. Old demos wont have this set on the client
  50. // so we'll know to use the old code path.
  51. m_bUseNewProjectileCode = true;
  52. #endif
  53. m_flIrradiateTime = 0.f;
  54. m_bEffectsThinking = false;
  55. }
  56. //-----------------------------------------------------------------------------
  57. // Purpose:
  58. //-----------------------------------------------------------------------------
  59. void CTFRaygun::Precache()
  60. {
  61. PrecacheParticleSystem( "drg_bison_impact" );
  62. PrecacheParticleSystem( "drg_bison_idle" );
  63. PrecacheParticleSystem( "drg_bison_muzzleflash" );
  64. BaseClass::Precache();
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose:
  68. //-----------------------------------------------------------------------------
  69. const char *CTFRaygun::GetMuzzleFlashParticleEffect( void )
  70. {
  71. return "drg_bison_muzzleflash";
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Purpose:
  75. //-----------------------------------------------------------------------------
  76. void CTFRaygun::PrimaryAttack( void )
  77. {
  78. if ( !Energy_HasEnergy() )
  79. return;
  80. BaseClass::PrimaryAttack();
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Purpose:
  84. //-----------------------------------------------------------------------------
  85. void CTFRaygun::ModifyProjectile( CBaseEntity* pProj )
  86. {
  87. #ifdef GAME_DLL
  88. /*
  89. CTFProjectile_EnergyRing* pEnergyBall = dynamic_cast<CTFProjectile_EnergyRing*>( pProj );
  90. if ( pEnergyBall == NULL )
  91. return;
  92. pEnergyBall->SetColor( 1, GetParticleColor( 1 ) );
  93. pEnergyBall->SetColor( 2, GetParticleColor( 2 ) );
  94. */
  95. #endif
  96. Energy_DrainEnergy();
  97. }
  98. //-----------------------------------------------------------------------------
  99. // Purpose:
  100. //-----------------------------------------------------------------------------
  101. float CTFRaygun::GetProgress( void )
  102. {
  103. return Energy_GetEnergy() / Energy_GetMaxEnergy();
  104. }
  105. #ifdef CLIENT_DLL
  106. //-----------------------------------------------------------------------------
  107. // Purpose:
  108. //-----------------------------------------------------------------------------
  109. void CTFRaygun::DispatchMuzzleFlash( const char* effectName, C_BaseEntity* pAttachEnt )
  110. {
  111. DispatchParticleEffect( effectName, PATTACH_POINT_FOLLOW, pAttachEnt, "muzzle", GetParticleColor( 1 ), GetParticleColor( 2 ) );
  112. }
  113. #endif
  114. //-----------------------------------------------------------------------------
  115. // Purpose:
  116. //-----------------------------------------------------------------------------
  117. bool CTFRaygun::Holster( CBaseCombatWeapon *pSwitchingTo )
  118. {
  119. #ifdef CLIENT_DLL
  120. m_bEffectsThinking = false;
  121. #endif
  122. return BaseClass::Holster( pSwitchingTo );
  123. }
  124. //-----------------------------------------------------------------------------
  125. // Purpose:
  126. //-----------------------------------------------------------------------------
  127. bool CTFRaygun::Deploy( void )
  128. {
  129. #ifdef CLIENT_DLL
  130. m_bEffectsThinking = true;
  131. SetContextThink( &CTFRaygun::ClientEffectsThink, gpGlobals->curtime + rand() % 5, "EFFECTS_THINK" );
  132. #endif
  133. return BaseClass::Deploy();
  134. }
  135. //-----------------------------------------------------------------------------
  136. // Purpose:
  137. //-----------------------------------------------------------------------------
  138. void CTFRaygun::ItemPostFrame( void )
  139. {
  140. BaseClass::ItemPostFrame();
  141. #ifdef CLIENT_DLL
  142. if ( !m_bEffectsThinking )
  143. {
  144. m_bEffectsThinking = true;
  145. SetContextThink( &CTFRaygun::ClientEffectsThink, gpGlobals->curtime + rand() % 5, "EFFECTS_THINK" );
  146. }
  147. #endif
  148. }
  149. #ifdef CLIENT_DLL
  150. //-----------------------------------------------------------------------------
  151. // Purpose:
  152. //-----------------------------------------------------------------------------
  153. void CTFRaygun::ClientEffectsThink( void )
  154. {
  155. CTFPlayer *pPlayer = GetTFPlayerOwner();
  156. if ( !pPlayer )
  157. return;
  158. if ( !pPlayer->IsLocalPlayer() )
  159. return;
  160. if ( !pPlayer->GetViewModel() )
  161. return;
  162. if ( !m_bEffectsThinking )
  163. return;
  164. SetContextThink( &CTFRaygun::ClientEffectsThink, gpGlobals->curtime + 2 + rand() % 5, "EFFECTS_THINK" );
  165. ParticleProp()->Init( this );
  166. CNewParticleEffect* pEffect = ParticleProp()->Create( GetIdleParticleEffect(), PATTACH_POINT_FOLLOW, "muzzle" );
  167. if ( pEffect )
  168. {
  169. pEffect->SetControlPoint( CUSTOM_COLOR_CP1, GetParticleColor( 1 ) );
  170. pEffect->SetControlPoint( CUSTOM_COLOR_CP2, GetParticleColor( 2 ) );
  171. }
  172. }
  173. #endif
  174. //-----------------------------------------------------------------------------
  175. // Purpose:
  176. //-----------------------------------------------------------------------------
  177. float CTFRaygun::GetProjectileSpeed( void )
  178. {
  179. return 1200.f;
  180. }
  181. //-----------------------------------------------------------------------------
  182. // Purpose:
  183. //-----------------------------------------------------------------------------
  184. float CTFRaygun::GetProjectileGravity( void )
  185. {
  186. return 0.f;
  187. }
  188. //-----------------------------------------------------------------------------
  189. // Purpose:
  190. //-----------------------------------------------------------------------------
  191. bool CTFRaygun::IsViewModelFlipped( void )
  192. {
  193. return !BaseClass::IsViewModelFlipped();
  194. }
  195. void CTFDRGPomson::Precache()
  196. {
  197. BaseClass::Precache();
  198. PrecacheParticleSystem( "drg_pomson_idle" );
  199. PrecacheParticleSystem( "drg_pomson_impact_drain" );
  200. PrecacheParticleSystem( "drg_pomson_projectile" );
  201. PrecacheParticleSystem( "drg_pomson_muzzleflash" );
  202. }
  203. //-----------------------------------------------------------------------------
  204. // Purpose:
  205. //-----------------------------------------------------------------------------
  206. void CTFDRGPomson::GetProjectileFireSetup( CTFPlayer *pPlayer, Vector vecOffset, Vector *vecSrc, QAngle *angForward, bool bHitTeammates, float flEndDist )
  207. {
  208. BaseClass::GetProjectileFireSetup( pPlayer, vecOffset, vecSrc, angForward, bHitTeammates, flEndDist );
  209. // adjust to line up with the weapon muzzle
  210. vecSrc->z -= 13.0f;
  211. }