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