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.

187 lines
4.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "c_basehlcombatweapon.h"
  8. #include "iviewrender_beams.h"
  9. #include "beam_shared.h"
  10. #include "c_weapon__stubs.h"
  11. #include "materialsystem/imaterial.h"
  12. #include "clienteffectprecachesystem.h"
  13. #include "beamdraw.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. CLIENTEFFECT_REGISTER_BEGIN( PrecacheEffectStunstick )
  17. CLIENTEFFECT_MATERIAL( "effects/stunstick" )
  18. CLIENTEFFECT_REGISTER_END()
  19. class C_WeaponStunStick : public C_BaseHLBludgeonWeapon
  20. {
  21. DECLARE_CLASS( C_WeaponStunStick, C_BaseHLBludgeonWeapon );
  22. public:
  23. DECLARE_CLIENTCLASS();
  24. DECLARE_PREDICTABLE();
  25. int DrawModel( int flags )
  26. {
  27. //FIXME: This sucks, but I can't easily create temp ents...
  28. if ( m_bActive )
  29. {
  30. Vector vecOrigin;
  31. QAngle vecAngles;
  32. float color[3];
  33. color[0] = color[1] = color[2] = random->RandomFloat( 0.1f, 0.2f );
  34. GetAttachment( 1, vecOrigin, vecAngles );
  35. Vector vForward;
  36. AngleVectors( vecAngles, &vForward );
  37. Vector vEnd = vecOrigin - vForward * 1.0f;
  38. IMaterial *pMaterial = materials->FindMaterial( "effects/stunstick", NULL, false );
  39. CMatRenderContextPtr pRenderContext( materials );
  40. pRenderContext->Bind( pMaterial );
  41. DrawHalo( pMaterial, vEnd, random->RandomFloat( 4.0f, 6.0f ), color );
  42. color[0] = color[1] = color[2] = random->RandomFloat( 0.9f, 1.0f );
  43. DrawHalo( pMaterial, vEnd, random->RandomFloat( 2.0f, 3.0f ), color );
  44. }
  45. return BaseClass::DrawModel( flags );
  46. }
  47. // Do part of our effect
  48. void ClientThink( void )
  49. {
  50. // Update our effects
  51. if ( m_bActive &&
  52. gpGlobals->frametime != 0.0f &&
  53. ( random->RandomInt( 0, 5 ) == 0 ) )
  54. {
  55. Vector vecOrigin;
  56. QAngle vecAngles;
  57. GetAttachment( 1, vecOrigin, vecAngles );
  58. Vector vForward;
  59. AngleVectors( vecAngles, &vForward );
  60. Vector vEnd = vecOrigin - vForward * 1.0f;
  61. // Inner beams
  62. BeamInfo_t beamInfo;
  63. beamInfo.m_vecStart = vEnd;
  64. Vector offset = RandomVector( -6, 2 );
  65. offset += Vector(2,2,2);
  66. beamInfo.m_vecEnd = vecOrigin + offset;
  67. beamInfo.m_pStartEnt= cl_entitylist->GetEnt( BEAMENT_ENTITY( entindex() ) );
  68. beamInfo.m_pEndEnt = cl_entitylist->GetEnt( BEAMENT_ENTITY( entindex() ) );
  69. beamInfo.m_nStartAttachment = 1;
  70. beamInfo.m_nEndAttachment = 2;
  71. beamInfo.m_nType = TE_BEAMTESLA;
  72. beamInfo.m_pszModelName = "sprites/physbeam.vmt";
  73. beamInfo.m_flHaloScale = 0.0f;
  74. beamInfo.m_flLife = 0.01f;
  75. beamInfo.m_flWidth = random->RandomFloat( 0.5f, 2.0f );
  76. beamInfo.m_flEndWidth = 0;
  77. beamInfo.m_flFadeLength = 0.0f;
  78. beamInfo.m_flAmplitude = random->RandomFloat( 1, 2 );
  79. beamInfo.m_flBrightness = 255.0;
  80. beamInfo.m_flSpeed = 0.0;
  81. beamInfo.m_nStartFrame = 0.0;
  82. beamInfo.m_flFrameRate = 1.0f;
  83. beamInfo.m_flRed = 255.0f;;
  84. beamInfo.m_flGreen = 255.0f;
  85. beamInfo.m_flBlue = 255.0f;
  86. beamInfo.m_nSegments = 8;
  87. beamInfo.m_bRenderable = true;
  88. beamInfo.m_nFlags = (FBEAM_ONLYNOISEONCE|FBEAM_SHADEOUT);
  89. beams->CreateBeamPoints( beamInfo );
  90. }
  91. }
  92. void OnDataChanged( DataUpdateType_t updateType )
  93. {
  94. BaseClass::OnDataChanged( updateType );
  95. if ( updateType == DATA_UPDATE_CREATED )
  96. {
  97. SetNextClientThink( CLIENT_THINK_ALWAYS );
  98. }
  99. }
  100. //-----------------------------------------------------------------------------
  101. // Purpose:
  102. //-----------------------------------------------------------------------------
  103. void StartStunEffect( void )
  104. {
  105. //TODO: Play startup sound
  106. }
  107. //-----------------------------------------------------------------------------
  108. // Purpose:
  109. //-----------------------------------------------------------------------------
  110. void StopStunEffect( void )
  111. {
  112. //TODO: Play shutdown sound
  113. }
  114. //-----------------------------------------------------------------------------
  115. // Purpose:
  116. // Output : RenderGroup_t
  117. //-----------------------------------------------------------------------------
  118. RenderGroup_t GetRenderGroup( void )
  119. {
  120. return RENDER_GROUP_TRANSLUCENT_ENTITY;
  121. }
  122. private:
  123. CNetworkVar( bool, m_bActive );
  124. };
  125. //-----------------------------------------------------------------------------
  126. // Purpose:
  127. // Input : *pData -
  128. // *pStruct -
  129. // *pOut -
  130. //-----------------------------------------------------------------------------
  131. void RecvProxy_StunActive( const CRecvProxyData *pData, void *pStruct, void *pOut )
  132. {
  133. bool state = *((bool *)&pData->m_Value.m_Int);
  134. C_WeaponStunStick *pWeapon = (C_WeaponStunStick *) pStruct;
  135. if ( state )
  136. {
  137. // Turn on the effect
  138. pWeapon->StartStunEffect();
  139. }
  140. else
  141. {
  142. // Turn off the effect
  143. pWeapon->StopStunEffect();
  144. }
  145. *(bool *)pOut = state;
  146. }
  147. STUB_WEAPON_CLASS_IMPLEMENT( weapon_stunstick, C_WeaponStunStick );
  148. IMPLEMENT_CLIENTCLASS_DT( C_WeaponStunStick, DT_WeaponStunStick, CWeaponStunStick )
  149. RecvPropInt( RECVINFO(m_bActive), 0, RecvProxy_StunActive ),
  150. END_RECV_TABLE()