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.

166 lines
4.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "cbase.h"
  8. #include "hud.h"
  9. #include "in_buttons.h"
  10. #include "beamdraw.h"
  11. #include "c_weapon__stubs.h"
  12. #include "clienteffectprecachesystem.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. CLIENTEFFECT_REGISTER_BEGIN( PrecacheEffectGravityGun )
  16. CLIENTEFFECT_MATERIAL( "sprites/physbeam" )
  17. CLIENTEFFECT_REGISTER_END()
  18. class C_BeamQuadratic : public CDefaultClientRenderable
  19. {
  20. public:
  21. C_BeamQuadratic();
  22. void Update( C_BaseEntity *pOwner );
  23. // IClientRenderable
  24. virtual const Vector& GetRenderOrigin( void ) { return m_worldPosition; }
  25. virtual const QAngle& GetRenderAngles( void ) { return vec3_angle; }
  26. virtual bool ShouldDraw( void ) { return true; }
  27. virtual bool IsTransparent( void ) { return true; }
  28. virtual bool ShouldReceiveProjectedTextures( int flags ) { return false; }
  29. virtual int DrawModel( int flags );
  30. // Returns the bounds relative to the origin (render bounds)
  31. virtual void GetRenderBounds( Vector& mins, Vector& maxs )
  32. {
  33. // bogus. But it should draw if you can see the end point
  34. mins.Init(-32,-32,-32);
  35. maxs.Init(32,32,32);
  36. }
  37. C_BaseEntity *m_pOwner;
  38. Vector m_targetPosition;
  39. Vector m_worldPosition;
  40. int m_active;
  41. int m_glueTouching;
  42. int m_viewModelIndex;
  43. };
  44. class C_WeaponGravityGun : public C_BaseCombatWeapon
  45. {
  46. DECLARE_CLASS( C_WeaponGravityGun, C_BaseCombatWeapon );
  47. public:
  48. C_WeaponGravityGun() {}
  49. DECLARE_CLIENTCLASS();
  50. DECLARE_PREDICTABLE();
  51. int KeyInput( int down, ButtonCode_t keynum, const char *pszCurrentBinding )
  52. {
  53. if ( gHUD.m_iKeyBits & IN_ATTACK )
  54. {
  55. switch ( keynum )
  56. {
  57. case MOUSE_WHEEL_UP:
  58. gHUD.m_iKeyBits |= IN_WEAPON1;
  59. return 0;
  60. case MOUSE_WHEEL_DOWN:
  61. gHUD.m_iKeyBits |= IN_WEAPON2;
  62. return 0;
  63. }
  64. }
  65. // Allow engine to process
  66. return BaseClass::KeyInput( down, keynum, pszCurrentBinding );
  67. }
  68. void OnDataChanged( DataUpdateType_t updateType )
  69. {
  70. BaseClass::OnDataChanged( updateType );
  71. m_beam.Update( this );
  72. }
  73. private:
  74. C_WeaponGravityGun( const C_WeaponGravityGun & );
  75. C_BeamQuadratic m_beam;
  76. };
  77. STUB_WEAPON_CLASS_IMPLEMENT( weapon_physgun, C_WeaponGravityGun );
  78. IMPLEMENT_CLIENTCLASS_DT( C_WeaponGravityGun, DT_WeaponGravityGun, CWeaponGravityGun )
  79. RecvPropVector( RECVINFO_NAME(m_beam.m_targetPosition,m_targetPosition) ),
  80. RecvPropVector( RECVINFO_NAME(m_beam.m_worldPosition, m_worldPosition) ),
  81. RecvPropInt( RECVINFO_NAME(m_beam.m_active, m_active) ),
  82. RecvPropInt( RECVINFO_NAME(m_beam.m_glueTouching, m_glueTouching) ),
  83. RecvPropInt( RECVINFO_NAME(m_beam.m_viewModelIndex, m_viewModelIndex) ),
  84. END_RECV_TABLE()
  85. C_BeamQuadratic::C_BeamQuadratic()
  86. {
  87. m_pOwner = NULL;
  88. }
  89. void C_BeamQuadratic::Update( C_BaseEntity *pOwner )
  90. {
  91. m_pOwner = pOwner;
  92. if ( m_active )
  93. {
  94. if ( m_hRenderHandle == INVALID_CLIENT_RENDER_HANDLE )
  95. {
  96. ClientLeafSystem()->AddRenderable( this, RENDER_GROUP_TRANSLUCENT_ENTITY );
  97. }
  98. else
  99. {
  100. ClientLeafSystem()->RenderableChanged( m_hRenderHandle );
  101. }
  102. }
  103. else if ( !m_active && m_hRenderHandle != INVALID_CLIENT_RENDER_HANDLE )
  104. {
  105. ClientLeafSystem()->RemoveRenderable( m_hRenderHandle );
  106. }
  107. }
  108. int C_BeamQuadratic::DrawModel( int )
  109. {
  110. Vector points[3];
  111. QAngle tmpAngle;
  112. if ( !m_active )
  113. return 0;
  114. C_BaseEntity *pEnt = cl_entitylist->GetEnt( m_viewModelIndex );
  115. if ( !pEnt )
  116. return 0;
  117. pEnt->GetAttachment( 1, points[0], tmpAngle );
  118. points[1] = 0.5 * (m_targetPosition + points[0]);
  119. // a little noise 11t & 13t should be somewhat non-periodic looking
  120. //points[1].z += 4*sin( gpGlobals->curtime*11 ) + 5*cos( gpGlobals->curtime*13 );
  121. points[2] = m_worldPosition;
  122. IMaterial *pMat = materials->FindMaterial( "sprites/physbeam", TEXTURE_GROUP_CLIENT_EFFECTS );
  123. Vector color;
  124. if ( m_glueTouching )
  125. {
  126. color.Init(1,0,0);
  127. }
  128. else
  129. {
  130. color.Init(1,1,1);
  131. }
  132. float scrollOffset = gpGlobals->curtime - (int)gpGlobals->curtime;
  133. materials->Bind( pMat );
  134. DrawBeamQuadratic( points[0], points[1], points[2], 13, color, scrollOffset );
  135. return 1;
  136. }