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.

238 lines
6.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "fx.h"
  8. #include "c_te_effect_dispatch.h"
  9. #include "c_te_legacytempents.h"
  10. #include "tempent.h"
  11. #include "c_te_basebeam.h"
  12. #include "iviewrender_beams.h"
  13. #include "c_baseplayer.h"
  14. #include "beam_shared.h"
  15. #define GAUSS_GLOW_SPRITE "sprites/hotglow.vmt"
  16. #define GAUSS_BEAM_SPRITE "sprites/smoke.vmt"
  17. int m_nGlowIndex;
  18. int m_nBeamIndex;
  19. void PrecacheGaussEffects(void *pUser)
  20. {
  21. m_nGlowIndex = modelinfo->GetModelIndex( GAUSS_GLOW_SPRITE );
  22. m_nBeamIndex = modelinfo->GetModelIndex( GAUSS_BEAM_SPRITE );
  23. }
  24. PRECACHE_REGISTER_FN(PrecacheGaussEffects);
  25. void HL1GaussBeam( const CEffectData &data )
  26. {
  27. // beam expects ent + attach to be encoded in the entity index (legacy system)
  28. int nStartEntity = data.entindex() | ((1 & 0xF)<<12);
  29. C_BaseEntity * pEnt = cl_entitylist->GetEnt( BEAMENT_ENTITY(nStartEntity) );
  30. if ( !pEnt->IsPlayer() )
  31. return;
  32. C_BasePlayer * pPlayer = static_cast<C_BasePlayer*>(pEnt);
  33. int nStartAttachment = -1;
  34. if ( pPlayer->IsLocalPlayer() )
  35. {
  36. nStartEntity = pPlayer->GetViewModel()->entindex();
  37. }
  38. else
  39. {
  40. if ( !pPlayer->GetActiveWeapon() ) // TODO : make sure we have the gauss gun
  41. return;
  42. nStartEntity = pPlayer->GetActiveWeapon()->entindex();
  43. nStartAttachment = 2;
  44. }
  45. nStartEntity |= ((1 & 0xF)<<12);
  46. Vector vecEndPoint = data.m_vOrigin;
  47. bool fIsPrimaryFire = data.m_fFlags;
  48. float flStartWidth;
  49. float flEndWidth;
  50. color32 beamColor;
  51. if ( fIsPrimaryFire ) // primary attack
  52. {
  53. flStartWidth = 1.0;
  54. flEndWidth = 1.0;
  55. beamColor.r = 255;
  56. beamColor.g = 255;
  57. beamColor.b = 0;
  58. beamColor.a = 255;
  59. }
  60. else // secondary
  61. {
  62. flStartWidth = 2.5;
  63. flEndWidth = 2.5;
  64. beamColor.r = 255;
  65. beamColor.g = 255;
  66. beamColor.b = 255;
  67. beamColor.a = 255;
  68. }
  69. beams->CreateBeamEntPoint(
  70. nStartEntity, // start ent
  71. NULL, // start pos
  72. 0, // end ent
  73. &vecEndPoint, // end pos
  74. m_nBeamIndex, // model index
  75. NULL, // halo index
  76. 0.0, // halo scale
  77. 0.1, // life
  78. flStartWidth, // startwidth
  79. flEndWidth, // endwidth
  80. 0.0, // fade length
  81. 0, // amplitude
  82. beamColor.a, // brightness
  83. 0, // speed
  84. 0, // startframe
  85. 0, // framerate
  86. beamColor.r, // R
  87. beamColor.g, // G
  88. beamColor.b // B
  89. );
  90. //ADRIANHL1MP
  91. }
  92. DECLARE_CLIENT_EFFECT( "HL1GaussBeam", HL1GaussBeam );
  93. void HL1GaussBeamReflect( const CEffectData &data )
  94. {
  95. Vector vecStartPoint = data.m_vStart;
  96. Vector vecEndPoint = data.m_vOrigin;
  97. bool fIsPrimaryFire = data.m_fFlags;
  98. float flStartWidth;
  99. float flEndWidth;
  100. color32 beamColor;
  101. if ( fIsPrimaryFire ) // primary attack
  102. {
  103. flStartWidth = 1.0;
  104. flEndWidth = 1.0;
  105. beamColor.r = 255;
  106. beamColor.g = 255;
  107. beamColor.b = 0;
  108. beamColor.a = 255;
  109. }
  110. else // secondary
  111. {
  112. flStartWidth = 2.5;
  113. flEndWidth = 2.5;
  114. beamColor.r = 255;
  115. beamColor.g = 255;
  116. beamColor.b = 255;
  117. beamColor.a = 255;
  118. }
  119. beams->CreateBeamPoints(
  120. vecStartPoint, // start pos
  121. vecEndPoint, // end pos
  122. m_nBeamIndex, // model index
  123. NULL, // halo index
  124. 0.0, // halo scale
  125. 0.1, // life
  126. flStartWidth, // startwidth
  127. flEndWidth, // endwidth
  128. 0.0, // fade length
  129. 0, // amplitude
  130. beamColor.a, // brightness
  131. 0, // speed
  132. 0, // startframe
  133. 0, // framerate
  134. beamColor.r, // R
  135. beamColor.g, // G
  136. beamColor.b // B
  137. );
  138. }
  139. DECLARE_CLIENT_EFFECT( "HL1GaussBeamReflect", HL1GaussBeamReflect );
  140. void HL1GaussReflect( const CEffectData &data )
  141. {
  142. Vector vecStart = data.m_vOrigin;
  143. Vector vecNormal = data.m_vNormal;
  144. float flMagnitude = data.m_flMagnitude;
  145. tempents->TempSprite( vecStart, vec3_origin, 0.2, m_nGlowIndex, kRenderGlow, kRenderFxNoDissipation, flMagnitude / 255.0, flMagnitude * 0.05, FTENT_FADEOUT );
  146. Vector vecForward;
  147. VectorAdd( vecStart, vecNormal, vecForward );
  148. tempents->Sprite_Trail( vecStart, vecForward, m_nGlowIndex, 3, 0.1, random->RandomFloat( 0.1, 0.2 ), 100, 255, 100 );
  149. }
  150. DECLARE_CLIENT_EFFECT( "HL1GaussReflect", HL1GaussReflect );
  151. void HL1GaussWallPunchEnter( const CEffectData &data )
  152. {
  153. Vector vecStart = data.m_vOrigin;
  154. Vector vecNormal = data.m_vNormal;
  155. Vector vecForward;
  156. VectorSubtract( vecStart, vecNormal, vecForward );
  157. tempents->Sprite_Trail( vecStart, vecForward, m_nGlowIndex, 3, 0.1, random->RandomFloat( 0.1, 0.2 ), 100, 255, 100 );
  158. }
  159. DECLARE_CLIENT_EFFECT( "HL1GaussWallPunchEnter", HL1GaussWallPunchEnter );
  160. void HL1GaussWallPunchExit( const CEffectData &data )
  161. {
  162. Vector vecStart = data.m_vOrigin;
  163. Vector vecNormal = data.m_vNormal;
  164. float flMagnitude = data.m_flMagnitude;
  165. tempents->TempSprite( vecStart, vec3_origin, 0.1, m_nGlowIndex, kRenderGlow, kRenderFxNoDissipation, flMagnitude * 1.2 / 255.0, 6.0, FTENT_FADEOUT );
  166. Vector vecForward;
  167. VectorSubtract( vecStart, vecNormal, vecForward );
  168. tempents->Sprite_Trail( vecStart, vecForward, m_nGlowIndex, flMagnitude * 0.3, 0.1, random->RandomFloat( 0.1, 0.2 ), 200, 255, 40 );
  169. }
  170. DECLARE_CLIENT_EFFECT( "HL1GaussWallPunchExit", HL1GaussWallPunchExit );
  171. void HL1GaussWallImpact1( const CEffectData &data )
  172. {
  173. Vector vecStart = data.m_vOrigin;
  174. float flMagnitude = data.m_flMagnitude;
  175. tempents->TempSprite( vecStart, vec3_origin, 1, m_nGlowIndex, kRenderGlow, kRenderFxNoDissipation, flMagnitude / 255.0, 6.0, FTENT_FADEOUT );
  176. }
  177. DECLARE_CLIENT_EFFECT( "HL1GaussWallImpact1", HL1GaussWallImpact1 );
  178. void HL1GaussWallImpact2( const CEffectData &data )
  179. {
  180. Vector vecStart = data.m_vOrigin;
  181. Vector vecNormal = data.m_vNormal;
  182. tempents->TempSprite( vecStart, vec3_origin, 0.2, m_nGlowIndex, kRenderGlow, kRenderFxNoDissipation, 240.0 / 255.0, 0.3, FTENT_FADEOUT );
  183. Vector vecForward;
  184. VectorAdd( vecStart, vecNormal, vecForward );
  185. tempents->Sprite_Trail( vecStart, vecForward, m_nGlowIndex, 8, 0.6, random->RandomFloat( 0.1, 0.2 ), 100, 255, 200 );
  186. }
  187. DECLARE_CLIENT_EFFECT( "HL1GaussWallImpact2", HL1GaussWallImpact2 );