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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "iefx.h"
#include "dlight.h"
#include "engine/IEngineSound.h"
#include "view.h"
#include "beamdraw.h"
#include "clienteffectprecachesystem.h"
#include "weapon_combat_usedwithshieldbase.h"
#include "c_weapon__stubs.h"
#include <vgui/ISurface.h>
#define BALL_GROW_TIME 1.5
// Precache the effects
CLIENTEFFECT_REGISTER_BEGIN( PrecacheWeaponCombat_ChargeablePlasma )
CLIENTEFFECT_MATERIAL( "sprites/chargeball_team1" )
CLIENTEFFECT_MATERIAL( "sprites/chargeball_team2" )
CLIENTEFFECT_REGISTER_END()
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class C_WeaponCombat_ChargeablePlasma : public C_WeaponCombatUsedWithShieldBase
{
DECLARE_CLASS( C_WeaponCombat_ChargeablePlasma, C_WeaponCombatUsedWithShieldBase );
public:
DECLARE_CLIENTCLASS();
DECLARE_PREDICTABLE();
C_WeaponCombat_ChargeablePlasma( void );
~C_WeaponCombat_ChargeablePlasma( void );
virtual void PreDataUpdate( DataUpdateType_t updateType );
virtual void OnDataChanged( DataUpdateType_t updateType );
virtual bool Holster( CBaseCombatWeapon *pSwitchingTo = NULL );
virtual void DrawCrosshair( void );
virtual void ClientThink( );
virtual int DrawModel( int flags );
virtual void ViewModelDrawn( C_BaseViewModel *pBaseViewModel );
virtual void NotifyShouldTransmit( ShouldTransmitState_t state );
virtual bool IsTransparent( );
private:
void StartCharging();
void StopCharging();
void DrawChargingEffect( float flSize, C_BaseAnimating *pAttachedEnt );
private:
bool m_bCharging;
bool m_bLastCharging;
float m_flPower;
float m_flChargeStartTime;
CMaterialReference m_hMaterial;
private:
C_WeaponCombat_ChargeablePlasma( const C_WeaponCombat_ChargeablePlasma & );
};
STUB_WEAPON_CLASS_IMPLEMENT( weapon_combat_chargeableplasma, C_WeaponCombat_ChargeablePlasma );
IMPLEMENT_CLIENTCLASS_DT( C_WeaponCombat_ChargeablePlasma, DT_WeaponCombat_ChargeablePlasma, CWeaponCombat_ChargeablePlasma )
RecvPropInt( RECVINFO(m_bCharging) ),
END_RECV_TABLE()
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
C_WeaponCombat_ChargeablePlasma::C_WeaponCombat_ChargeablePlasma( void )
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
C_WeaponCombat_ChargeablePlasma::~C_WeaponCombat_ChargeablePlasma( void )
{
Holster( NULL );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_WeaponCombat_ChargeablePlasma::PreDataUpdate( DataUpdateType_t updateType )
{
BaseClass::PreDataUpdate( updateType );
m_bLastCharging = m_bCharging;
}
void C_WeaponCombat_ChargeablePlasma::NotifyShouldTransmit( ShouldTransmitState_t state )
{
BaseClass::NotifyShouldTransmit(state);
if (state == SHOULDTRANSMIT_START)
{
if (m_bCharging)
StartCharging();
}
else if (state == SHOULDTRANSMIT_END)
{
if (m_bCharging)
StopCharging();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_WeaponCombat_ChargeablePlasma::OnDataChanged( DataUpdateType_t updateType )
{
BaseClass::OnDataChanged( updateType );
switch( updateType )
{
case DATA_UPDATE_CREATED:
// So we can update our lights
if ( GetTeamNumber() == 1 )
m_hMaterial.Init( "sprites/chargeball_team1" );
else
m_hMaterial.Init( "sprites/chargeball_team2" );
break;
case DATA_UPDATE_DATATABLE_CHANGED:
if ( m_bCharging != m_bLastCharging )
{
if ( m_bCharging )
{
StartCharging();
}
else
{
StopCharging();
}
}
break;
};
if (WeaponState() == WEAPON_IS_ACTIVE)
{
// Start thinking so we can manipulate the light
SetNextClientThink( CLIENT_THINK_ALWAYS );
}
else
{
SetNextClientThink( CLIENT_THINK_NEVER );
}
}
//-----------------------------------------------------------------------------
// Deal with dynamic lighting
//-----------------------------------------------------------------------------
void C_WeaponCombat_ChargeablePlasma::ClientThink( )
{
BaseClass::ClientThink();
C_BaseTFPlayer *pPlayer = (C_BaseTFPlayer *)GetOwner();
if ( !pPlayer || (pPlayer->GetHealth() <= 0))
{
SetNextClientThink( CLIENT_THINK_NEVER );
return;
}
if (!m_bCharging)
return;
// Determine the ball size...
m_flPower = (gpGlobals->curtime - m_flChargeStartTime) / BALL_GROW_TIME;
m_flPower = clamp( m_flPower, 0, 1 );
// FIXME: dl->origin should be based on the attachment point
dlight_t *dl = effects->CL_AllocDlight( entindex() );
dl->origin = GetRenderOrigin();
if (GetTeamNumber() == 1)
{
dl->color.r = 40;
dl->color.g = 60;
dl->color.b = 250;
}
else
{
dl->color.r = 250;
dl->color.g = 60;
dl->color.b = 40;
}
dl->color.exponent = 5;
dl->radius = 20 * m_flPower + 10;
dl->die = gpGlobals->curtime + 0.01;
}
//-----------------------------------------------------------------------------
// Purpose: Remove the ball if we're switching away
//-----------------------------------------------------------------------------
bool C_WeaponCombat_ChargeablePlasma::Holster( C_BaseCombatWeapon *pSwitchingTo )
{
StopCharging();
return BaseClass::Holster( pSwitchingTo );
}
void C_WeaponCombat_ChargeablePlasma::StartCharging()
{
CLocalPlayerFilter filter;
EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, "WeaponCombat_ChargeablePlasma.Charging" );
m_flChargeStartTime = gpGlobals->curtime;
}
void C_WeaponCombat_ChargeablePlasma::StopCharging()
{
StopSound( SOUND_FROM_LOCAL_PLAYER, "WeaponCombat_ChargeablePlasma.Charging" );
m_bCharging = false;
}
//-----------------------------------------------------------------------------
// We're transparent because we draw a transparent charging effect
//-----------------------------------------------------------------------------
bool C_WeaponCombat_ChargeablePlasma::IsTransparent( )
{
if (m_bCharging)
return true;
return BaseClass::IsTransparent();
}
//-----------------------------------------------------------------------------
// Purpose: Draws the charging effect
//-----------------------------------------------------------------------------
void C_WeaponCombat_ChargeablePlasma::DrawChargingEffect( float flSize, C_BaseAnimating *pAttachedEnt )
{
if (!pAttachedEnt)
return;
Vector vecOrigin;
QAngle vecAngles;
int iAttachment = pAttachedEnt->LookupAttachment( "muzzle" );
if ( pAttachedEnt->GetAttachment( iAttachment, vecOrigin, vecAngles ) )
{
color32 color = { 255, 255, 255, 255 };
materials->Bind( m_hMaterial, (IClientRenderable*)this );
DrawSprite( vecOrigin, flSize, flSize, color );
}
}
//-----------------------------------------------------------------------------
// Purpose: Draws the model
//-----------------------------------------------------------------------------
int C_WeaponCombat_ChargeablePlasma::DrawModel( int flags )
{
int retval = BaseClass::DrawModel( flags );
if (retval == 0)
return 0;
if (m_bCharging && IsCarrierAlive())
{
// Draw the charging effect
float flSize = 20 * m_flPower + 10;
DrawChargingEffect( flSize, this );
}
return retval;
}
//-----------------------------------------------------------------------------
// Purpose: Draws the model
//-----------------------------------------------------------------------------
void C_WeaponCombat_ChargeablePlasma::ViewModelDrawn( C_BaseViewModel *pBaseViewModel )
{
if (!m_bCharging)
return;
// Draw the charging effect
float flSize = 12 * m_flPower + 6;
if ( m_iClip1 > 0 )
{
DrawChargingEffect( flSize, pBaseViewModel );
}
}
//-----------------------------------------------------------------------------
// Purpose: Draw targeting reticle
//-----------------------------------------------------------------------------
void C_WeaponCombat_ChargeablePlasma::DrawCrosshair( void )
{
BaseClass::DrawCrosshair();
// Find enemy players in front of me
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
if ( !pPlayer )
return;
trace_t tr;
Vector vecStart, vecEnd;
VectorMA( CurrentViewOrigin(), 1500, CurrentViewForward(), vecEnd );
VectorMA( CurrentViewOrigin(), 48, CurrentViewForward(), vecStart );
UTIL_TraceLine( vecStart, vecEnd, MASK_SOLID, NULL, COLLISION_GROUP_NONE, &tr );
if ( tr.DidHitNonWorldEntity() )
{
C_BaseEntity *pEntity = tr.m_pEnt;
if ( pEntity && pEntity->IsPlayer() && !pPlayer->InSameTeam( pEntity ) )
{
// Draw a reticle
vgui::Color clr = gHUD.m_clrYellowish;
clr[3] = 128;
// Calculate circle size
int iRatio = 30;
// Draw the circle
int iDegrees = 0;
Vector vecPoint, vecLastPoint(0,0,0);
vecPoint.z = 0.0f;
for ( int i = 0; i < 360; i++ )
{
float flRadians = DEG2RAD( iDegrees );
iDegrees += (360 / 360);
float ca = cos( flRadians );
float sa = sin( flRadians );
// Rotate it around the circle
vecPoint.x = (int)((ScreenWidth() / 2) + (iRatio * sa));
vecPoint.y = (int)((ScreenHeight() / 2) - (iRatio * ca));
// Draw the point, if it's not on the previous point, to avoid smaller circles being brighter
if ( vecLastPoint != vecPoint )
{
vgui::surface()->DrawSetColor( clr );
vgui::surface()->DrawFilledRect( vecPoint.x, vecPoint.y, vecPoint.x + 1, vecPoint.y + 1 );
}
vecLastPoint = vecPoint;
}
}
}
}
|