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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// TF Rocket Launcher
//
//=============================================================================
#include "cbase.h"
#include "tf_weapon_particle_cannon.h"
#include "tf_fx_shared.h"
#include "in_buttons.h"
// Client specific.
#ifdef CLIENT_DLL
#include "c_tf_player.h"
#include <vgui_controls/Panel.h>
#include <vgui/ISurface.h>
#include "soundenvelope.h"
#include "particle_property.h"
#include "c_tf_gamestats.h"
// Server specific.
#else
#include "tf_gamestats.h"
#include "tf_player.h"
#include "tf_projectile_energy_ball.h"
#endif
//=============================================================================
//
// Particle cannon tables.
//
IMPLEMENT_NETWORKCLASS_ALIASED( TFParticleCannon, DT_ParticleCannon )
BEGIN_NETWORK_TABLE( CTFParticleCannon, DT_ParticleCannon )
#ifdef CLIENT_DLL
RecvPropFloat( RECVINFO( m_flChargeBeginTime ) ),
RecvPropInt( RECVINFO( m_iChargeEffect ) )
#else
SendPropFloat( SENDINFO( m_flChargeBeginTime ) ),
SendPropInt( SENDINFO( m_iChargeEffect ) )
#endif
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CTFParticleCannon )
END_PREDICTION_DATA()
LINK_ENTITY_TO_CLASS( tf_weapon_particle_cannon, CTFParticleCannon );
PRECACHE_WEAPON_REGISTER( tf_weapon_particle_cannon );
// Server specific.
#ifndef CLIENT_DLL
BEGIN_DATADESC( CTFParticleCannon )
END_DATADESC()
#endif
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CTFParticleCannon::CTFParticleCannon() : CTFRocketLauncher()
{
#ifdef CLIENT_DLL
m_bEffectsThinking = false;
m_iChargeEffectBase = 0;
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
float CTFParticleCannon::GetProjectileSpeed( void )
{
return 1100.f;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
float CTFParticleCannon::GetProjectileGravity( void )
{
return 0.f;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFParticleCannon::IsViewModelFlipped( void )
{
return !BaseClass::IsViewModelFlipped(); // Invert because arrows are backwards by default.
}
//-----------------------------------------------------------------------------
// Purpose: Reset the charge when we holster
//-----------------------------------------------------------------------------
bool CTFParticleCannon::Holster( CBaseCombatWeapon *pSwitchingTo )
{
CTFPlayer *pPlayer = ToTFPlayer( GetPlayerOwner() );
if ( pPlayer && pPlayer->m_Shared.InCond( TF_COND_AIMING ) )
return false;
m_flChargeBeginTime = 0;
#ifdef CLIENT_DLL
ParticleProp()->Init( this );
ParticleProp()->StopParticlesNamed( "drg_cowmangler_idle", true );
m_bEffectsThinking = false;
#endif
StopSound( "Weapon_CowMangler.Charging" );
return BaseClass::Holster( pSwitchingTo );
}
//-----------------------------------------------------------------------------
// Purpose: Reset the charge when we deploy
//-----------------------------------------------------------------------------
bool CTFParticleCannon::Deploy( void )
{
m_flChargeBeginTime = 0;
#ifdef CLIENT_DLL
m_bEffectsThinking = true;
SetContextThink( &CTFParticleCannon::ClientEffectsThink, gpGlobals->curtime + rand() % 5, "PC_EFFECTS_THINK" );
#endif
return BaseClass::Deploy();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFParticleCannon::WeaponReset( void )
{
BaseClass::WeaponReset();
m_flChargeBeginTime = 0.0f;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFParticleCannon::ItemPostFrame( void )
{
BaseClass::ItemPostFrame();
if ( m_flChargeBeginTime > 0 )
{
CTFPlayer *pPlayer = ToTFPlayer( GetPlayerOwner() );
if ( !pPlayer )
return;
// If we're not holding down the attack button, launch our grenade
float flTotalChargeTime = gpGlobals->curtime - m_flChargeBeginTime;
if ( flTotalChargeTime >= GetChargeForceReleaseTime() )
{
FireChargedShot();
}
}
#ifdef CLIENT_DLL
if ( !m_bEffectsThinking )
{
m_bEffectsThinking = true;
SetContextThink( &CTFParticleCannon::ClientEffectsThink, gpGlobals->curtime + rand() % 5, "PC_EFFECTS_THINK" );
}
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFParticleCannon::PrimaryAttack( void )
{
if ( m_flChargeBeginTime > 0 )
return;
if ( !Energy_HasEnergy() )
return;
m_bChargedShot = false;
BaseClass::PrimaryAttack();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFParticleCannon::SecondaryAttack( void )
{
// Check for ammunition.
if ( !Energy_FullyCharged() )
{
Reload();
return;
}
// Are we capable of firing again?
if ( m_flNextPrimaryAttack > gpGlobals->curtime )
return;
if ( m_flChargeBeginTime > 0 )
return;
if ( !CanAttack() )
{
m_flChargeBeginTime = 0;
return;
}
m_bChargedShot = true;
// Set the weapon mode.
m_iWeaponMode = TF_WEAPON_PRIMARY_MODE;
// save that we had the attack button down
m_flChargeBeginTime = gpGlobals->curtime;
CTFPlayer *pPlayer = ToTFPlayer( GetPlayerOwner() );
if ( pPlayer )
{
SendWeaponAnim( ACT_PRIMARY_VM_PRIMARYATTACK_3 );
pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY_SUPER );
}
WeaponSound( SPECIAL1 );
pPlayer->m_Shared.AddCond( TF_COND_AIMING );
pPlayer->TeamFortress_SetSpeed();
m_iChargeEffect++;
}
#ifdef CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFParticleCannon::CreateChargeEffect()
{
CTFPlayer *pPlayer = ToTFPlayer( GetPlayerOwner() );
if ( pPlayer )
{
DispatchParticleEffect( "drg_cowmangler_muzzleflash_chargeup", PATTACH_POINT_FOLLOW, GetAppropriateWorldOrViewModel(), "muzzle", GetParticleColor( 1 ), GetParticleColor( 2 ) );
}
}
#endif
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFParticleCannon::FireChargedShot()
{
CTFPlayer *pPlayer = ToTFPlayer( GetPlayerOwner() );
if ( !pPlayer )
return;
if ( !pPlayer->IsAlive() )
return;
pPlayer->m_Shared.RemoveCond( TF_COND_AIMING );
pPlayer->TeamFortress_SetSpeed();
#ifndef CLIENT_DLL
CTF_GameStats.Event_PlayerFiredWeapon( pPlayer, false );
#else
C_CTF_GameStats.Event_PlayerFiredWeapon( pPlayer, false );
#endif
// SendWeaponAnim( ACT_VM_PRIMARYATTACK );
// pPlayer->SetAnimation( PLAYER_ATTACK1 );
CBaseEntity* pProj = FireProjectile( pPlayer );
ModifyProjectile( pProj );
float flFireDelay = ApplyFireDelay( m_pWeaponInfo->GetWeaponData( m_iWeaponMode ).m_flTimeFireDelay );
m_flNextPrimaryAttack = gpGlobals->curtime + flFireDelay;
SetWeaponIdleTime( gpGlobals->curtime + SequenceDuration() );
m_iReloadMode.Set( TF_RELOAD_START );
m_flChargeBeginTime = 0.0f;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFParticleCannon::ModifyProjectile( CBaseEntity* pProj )
{
#ifdef GAME_DLL
CTFProjectile_EnergyBall* pEnergyBall = dynamic_cast<CTFProjectile_EnergyBall*>( pProj );
if ( pEnergyBall == NULL )
return;
pEnergyBall->SetChargedShot( m_bChargedShot );
pEnergyBall->SetColor( 1, GetParticleColor( 1 ) );
pEnergyBall->SetColor( 2, GetParticleColor( 2 ) );
#endif
if ( m_bChargedShot )
{
Energy_DrainEnergy( Energy_GetMaxEnergy() );
}
else
{
Energy_DrainEnergy();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
float CTFParticleCannon::GetProgress( void )
{
return Energy_GetEnergy() / Energy_GetMaxEnergy();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
const char *CTFParticleCannon::GetMuzzleFlashParticleEffect( void )
{
if ( m_bChargedShot )
{
return ( GetTeamNumber() == TF_TEAM_RED ) ? "drg_cow_muzzleflash_charged" : "drg_cow_muzzleflash_charged_blue";
}
else
{
return ( GetTeamNumber() == TF_TEAM_RED ) ? "drg_cow_muzzleflash_normal" : "drg_cow_muzzleflash_normal_blue";
}
}
#ifndef CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFParticleCannon::Precache()
{
BaseClass::Precache();
PrecacheParticleSystem( "drg_cow_explosioncore_charged" );
PrecacheParticleSystem( "drg_cow_explosioncore_charged_blue" );
PrecacheParticleSystem( "drg_cow_explosioncore_normal" );
PrecacheParticleSystem( "drg_cow_explosioncore_normal_blue" );
PrecacheParticleSystem( "drg_cow_muzzleflash_charged" );
PrecacheParticleSystem( "drg_cow_muzzleflash_charged_blue" );
PrecacheParticleSystem( "drg_cow_muzzleflash_normal" );
PrecacheParticleSystem( "drg_cow_muzzleflash_normal_blue" );
PrecacheParticleSystem( "drg_cow_idle" );
PrecacheScriptSound( "Weapon_CowMangler.ReloadFinal" );
}
#endif
#ifdef CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFParticleCannon::OnDataChanged( DataUpdateType_t updateType )
{
BaseClass::OnDataChanged( updateType );
if ( IsCarrierAlive() && ( WeaponState() == WEAPON_IS_ACTIVE ) )
{
if ( m_iChargeEffect != m_iChargeEffectBase )
{
CreateChargeEffect();
m_iChargeEffectBase = m_iChargeEffect;
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFParticleCannon::ClientEffectsThink( void )
{
CTFPlayer *pPlayer = GetTFPlayerOwner();
if ( !pPlayer )
return;
if ( !pPlayer->IsLocalPlayer() )
return;
if ( !pPlayer->GetViewModel() )
return;
if ( !m_bEffectsThinking )
return;
SetContextThink( &CTFParticleCannon::ClientEffectsThink, gpGlobals->curtime + 2 + rand() % 5, "PC_EFFECTS_THINK" );
if ( pPlayer->m_Shared.InCond( TF_COND_TAUNTING ) )
return;
const char* mounts[4] =
{
"crit_frontspark1",
"crit_frontspark2",
"crit_frontspark3",
"crit_frontspark4"
};
int iPoint = rand() % 4;
ParticleProp()->Init( this );
const char *pszIdleParticle = ( GetTeamNumber() == TF_TEAM_RED ) ? "drg_cow_idle" : "drg_cow_idle_blue";
CNewParticleEffect* pEffect = ParticleProp()->Create( pszIdleParticle, PATTACH_POINT_FOLLOW, mounts[iPoint] );
if ( pEffect )
{
pEffect->SetControlPoint( CUSTOM_COLOR_CP1, GetParticleColor( 1 ) );
pEffect->SetControlPoint( CUSTOM_COLOR_CP2, GetParticleColor( 2 ) );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFParticleCannon::DispatchMuzzleFlash( const char* effectName, C_BaseEntity* pAttachEnt )
{
DispatchParticleEffect( effectName, PATTACH_POINT_FOLLOW, pAttachEnt, "muzzle", GetParticleColor( 1 ), GetParticleColor( 2 ) );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFParticleCannon::CreateMuzzleFlashEffects( C_BaseEntity *pAttachEnt, int nIndex )
{
// Don't call direct parent. We don't want back blast effects.
CTFWeaponBaseGun::CreateMuzzleFlashEffects( pAttachEnt, nIndex );
}
#endif
//-----------------------------------------------------------------------------
// Purpose: Utility function for default colors.
//-----------------------------------------------------------------------------
Vector GetParticleColorForTeam( int iTeam, int iColor )
{
if ( iColor == 1 )
{
if ( iTeam == TF_TEAM_RED )
return TF_PARTICLE_WEAPON_RED_1;
else
return TF_PARTICLE_WEAPON_BLUE_1;
}
else
{
if ( iTeam == TF_TEAM_RED )
return TF_PARTICLE_WEAPON_RED_2;
else
return TF_PARTICLE_WEAPON_BLUE_2;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFParticleCannon::PlayWeaponShootSound( void )
{
if ( m_bChargedShot )
{
// WeaponSound( BURST );
}
else
{
WeaponSound( SINGLE );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
char const *CTFParticleCannon::GetShootSound( int iIndex ) const
{
if ( iIndex == RELOAD )
{
bool bLastReload = (Energy_GetEnergy()+Energy_GetRechargeCost()) == Energy_GetMaxEnergy();
if ( bLastReload )
{
return "Weapon_CowMangler.ReloadFinal";
}
}
return BaseClass::GetShootSound(iIndex);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFParticleCannon::OwnerCanTaunt( void )
{
if ( m_flChargeBeginTime > 0 )
{
return false;
}
else
{
return true;
}
}
|