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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "basetfplayer_shared.h"
#include "in_buttons.h"
#include "tf_gamerules.h"
#include "weapon_combatshield.h"
#if defined( CLIENT_DLL )
#include "particles_simple.h"
#include "fx.h"
#include "fx_quad.h"
#include "clienteffectprecachesystem.h"
#define CWeaponArcWelder C_WeaponArcWelder
#else
#endif
#include "weapon_repairgun.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
// Buff ranges
ConVar weapon_arcwelder_target_range( "weapon_arcwelder_target_range", "90", FCVAR_REPLICATED, "The farthest away you can be for the arcwelder to initially lock onto a target." );
ConVar weapon_arcwelder_stick_range( "weapon_arcwelder_stick_range", "100", FCVAR_REPLICATED, "How far away the arcwelder can stay locked onto someone." );
ConVar weapon_arcwelder_rate( "weapon_arcwelder_rate", "15", FCVAR_REPLICATED );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CWeaponArcWelder : public CWeaponRepairGun
{
DECLARE_CLASS( CWeaponArcWelder, CWeaponRepairGun );
public:
DECLARE_NETWORKCLASS();
DECLARE_PREDICTABLE();
CWeaponArcWelder( void );
virtual void Precache();
virtual float GetTargetRange( void );
virtual float GetStickRange( void );
virtual float GetHealRate( void );
virtual bool AppliesModifier( void ) { return false; }
virtual bool TargetsPlayers( void ) { return false; }
virtual CBaseEntity *GetTargetToHeal( CBaseEntity *pCurHealing );
// All predicted weapons need to implement and return true
virtual bool IsPredicted( void ) const
{
return true;
}
#if defined( CLIENT_DLL )
virtual void ClientThink( void );
virtual bool OnFireEvent( C_BaseViewModel *pViewModel, const Vector& origin, const QAngle& angles, int event, const char *options );
virtual void ViewModelDrawn( C_BaseViewModel *pViewModel );
virtual bool ShouldPredict( void )
{
if ( GetOwner() == C_BasePlayer::GetLocalPlayer() )
return true;
return BaseClass::ShouldPredict();
}
#endif
private:
bool m_bWelding;
#if defined( CLIENT_DLL )
float m_flNextEffectTime;
#endif
private:
CWeaponArcWelder( const CWeaponArcWelder & );
};
LINK_ENTITY_TO_CLASS( weapon_arcwelder, CWeaponArcWelder );
PRECACHE_WEAPON_REGISTER( weapon_arcwelder );
IMPLEMENT_NETWORKCLASS_ALIASED( WeaponArcWelder, DT_WeaponArcWelder )
BEGIN_NETWORK_TABLE( CWeaponArcWelder, DT_WeaponArcWelder )
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CWeaponArcWelder )
END_PREDICTION_DATA()
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CWeaponArcWelder::CWeaponArcWelder()
{
SetPredictionEligible( true );
m_bWelding = false;
#ifdef CLIENT_DLL
m_flNextEffectTime = 0;
#endif
}
void CWeaponArcWelder::Precache()
{
BaseClass::Precache();
PrecacheScriptSound( "WeaponRepairGun.Healing" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
float CWeaponArcWelder::GetTargetRange( void )
{
return weapon_arcwelder_target_range.GetFloat();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
float CWeaponArcWelder::GetStickRange( void )
{
return weapon_arcwelder_target_range.GetFloat();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
float CWeaponArcWelder::GetHealRate( void )
{
return weapon_arcwelder_rate.GetFloat();
}
//-----------------------------------------------------------------------------
// Purpose: Returns a pointer to a healable target
//-----------------------------------------------------------------------------
CBaseEntity *CWeaponArcWelder::GetTargetToHeal( CBaseEntity *pCurHealing )
{
CBaseEntity *pTarget = BaseClass::GetTargetToHeal(pCurHealing);
if ( !pTarget )
return pTarget;
// Make sure the target is within our field of view
CBaseTFPlayer *pOwner = ToBaseTFPlayer( GetOwner() );
if ( !pOwner )
return NULL;
Vector vecAiming;
pOwner->EyeVectors( &vecAiming );
// Find a player in range of this player, and make sure they're healable.
Vector vecSrc = pOwner->Weapon_ShootPosition( );
Vector vecEnd = vecSrc + vecAiming * GetTargetRange();
trace_t tr;
// Use WeaponTraceLine so shields are tested...
TFGameRules()->WeaponTraceLine( vecSrc, vecEnd, (MASK_SHOT & ~CONTENTS_HITBOX), pOwner, DMG_PROBE, &tr );
if ( tr.fraction != 1.0 && tr.m_pEnt == pTarget )
return pTarget;
return NULL;
}
#ifdef CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponArcWelder::ClientThink( void )
{
CBasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
if ( !pPlayer )
return;
if ( m_hHealingTarget == NULL )
return;
// Don't show it while the player is dead. Ideally, we'd respond to m_bHealing in OnDataChanged,
// but it stops sending the weapon when it's holstered, and it gets holstered when the player dies.
C_BasePlayer *pFiringPlayer = dynamic_cast< C_BasePlayer* >( GetOwner() );
if ( !pFiringPlayer || pFiringPlayer->IsPlayerDead() )
{
ClientThinkList()->SetNextClientThink( GetClientHandle(), CLIENT_THINK_NEVER );
m_bPlayingSound = false;
StopRepairSound();
return;
}
// Start playing the heal sound, if we're not already
if ( !m_bPlayingSound )
{
m_bPlayingSound = true;
CLocalPlayerFilter filter;
EmitSound( filter, entindex(), "WeaponRepairGun.Healing" );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CWeaponArcWelder::OnFireEvent( C_BaseViewModel *pViewModel, const Vector& origin, const QAngle& angles, int event, const char *options )
{
CBaseTFPlayer *pPlayer = static_cast<CBaseTFPlayer*>( GetOwner() );
if ( !pPlayer )
return true;
switch ( event )
{
case 7001:
m_bWelding = true;
return true;
case 7002:
m_bWelding = false;
return true;
default:
break;
};
return BaseClass::OnFireEvent( pViewModel, origin, angles, event, options );
}
CLIENTEFFECT_REGISTER_BEGIN( PrecacheArcWelderEffect )
CLIENTEFFECT_MATERIAL( "particle/smoke_arcwelder" )
CLIENTEFFECT_MATERIAL( "effects/spark2" )
CLIENTEFFECT_MATERIAL( "effects/blueflare" )
CLIENTEFFECT_MATERIAL( "effects/blueflare2" )
CLIENTEFFECT_REGISTER_END()
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponArcWelder::ViewModelDrawn( C_BaseViewModel *pViewModel )
{
if ( !m_bWelding || !m_hHealingTarget.Get() )
return;
if ( m_flNextEffectTime > gpGlobals->curtime )
return;
m_flNextEffectTime = gpGlobals->curtime + 0.1;
// Get our weldpoint
Vector attachOrigin;
QAngle attachAngles;
pViewModel->GetAttachment( pViewModel->LookupAttachment("muzzle"), attachOrigin, attachAngles );
Vector vecEnd = m_hHealingTarget->WorldSpaceCenter();
trace_t tr;
// Use WeaponTraceLine so shields are tested...
TFGameRules()->WeaponTraceLine( attachOrigin, vecEnd, (MASK_SHOT & ~CONTENTS_HITBOX), GetOwner(), DMG_PROBE, &tr );
// Smoke
unsigned char color[3];
int iColOff = random->RandomInt(-16,16);
color[0] = 120 + iColOff;
color[1] = 230 + iColOff;
color[2] = 235 + iColOff;
/*
// Pull out from the target a bit
Vector vecOrigin = vecEnd;
Vector vecFromTarget = (vecEnd - attachOrigin);
VectorNormalize( vecFromTarget );
vecOrigin -= (vecFromTarget * 24);
*/
Vector vecOrigin = attachOrigin;
// Velocity
Vector vecVelocity = tr.plane.normal;
vecVelocity.z += random->RandomFloat( 8, 12 );
// Add it
CSmartPtr<CSimpleEmitter> pSimple = FX_Smoke( vecOrigin, vecVelocity,
random->RandomFloat( 4, 8 ), // Scale
1,
random->RandomFloat( 0.5, 3.0 ), // Dietime
color,
random->RandomInt( 64, 200 ), // Alpha
"particle/smoke_arcwelder",
random->RandomInt(0,255), // Roll
0 ); // Rolldelta
// Sparks
FX_Sparks( vecOrigin, 1, 4, tr.plane.normal, 2.5, 8, 64, "effects/spark2" );
// Bright Glow
SimpleParticle *sParticle;
sParticle = (SimpleParticle *) pSimple->AddParticle( sizeof( SimpleParticle ), pSimple->GetPMaterial( "effects/blueflare" ), vecOrigin );
if ( sParticle == NULL )
return;
sParticle->m_flLifetime = 0.0f;
sParticle->m_flDieTime = 0.5f;
sParticle->m_vecVelocity.Init();
sParticle->m_uchColor[0] = 255;
sParticle->m_uchColor[1] = 255;
sParticle->m_uchColor[2] = 255;
sParticle->m_uchStartSize = random->RandomInt(5,7);
sParticle->m_uchEndSize = sParticle->m_uchStartSize;
sParticle->m_flRoll = random->RandomInt(0,360);
sParticle->m_flRollDelta = 0;
// Dull Glow
sParticle = (SimpleParticle *) pSimple->AddParticle( sizeof( SimpleParticle ), pSimple->GetPMaterial( "effects/blueflare2" ), vecOrigin );
if ( sParticle == NULL )
return;
sParticle->m_flLifetime = 0.0f;
sParticle->m_flDieTime = 0.2f;
sParticle->m_vecVelocity.Init();
sParticle->m_uchColor[0] = 255;
sParticle->m_uchColor[1] = 255;
sParticle->m_uchColor[2] = 255;
sParticle->m_uchStartSize = random->RandomInt(15,20);
sParticle->m_uchEndSize = sParticle->m_uchStartSize;
sParticle->m_flRoll = random->RandomInt(0,360);
sParticle->m_flRollDelta = 0;
}
#endif
|