-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathasw_weapon_railgun_shared.cpp
More file actions
725 lines (615 loc) · 21.4 KB
/
asw_weapon_railgun_shared.cpp
File metadata and controls
725 lines (615 loc) · 21.4 KB
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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
#include "cbase.h"
#include "asw_weapon_railgun_shared.h"
#include "in_buttons.h"
#ifdef CLIENT_DLL
#define CASW_Weapon C_ASW_Weapon
#define CASW_Marine C_ASW_Marine
#define CBasePlayer C_BasePlayer
#include "c_asw_player.h"
#include "c_asw_weapon.h"
#include "c_asw_marine.h"
#include "c_asw_railgun_beam.h"
#include "iviewrender_beams.h"
#include "c_asw_marine_resource.h"
#include "precache_register.h"
#include "c_te_effect_dispatch.h"
#else
#include "asw_deathmatch_mode.h"
#include "asw_lag_compensation.h"
#include "asw_marine.h"
#include "asw_player.h"
#include "asw_weapon.h"
#include "npcevent.h"
#include "shot_manipulator.h"
#include "te_effect_dispatch.h"
#include "asw_marine_resource.h"
#include "asw_marine_speech.h"
#include "decals.h"
#include "ammodef.h"
#include "asw_weapon_ammo_bag_shared.h"
#include "asw_rocket.h"
#endif
#include "asw_marine_skills.h"
#include "asw_weapon_parse.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//#define ASW_RAILGUN_SWEEP_STYLE 1 // makes railgun do hull sweep style damage
//#define ASW_RAILGUN_WIDE_SWEEP 1 // makes railgun do a wide low damage sweep in addition to the above
#define ASW_RAILGUN_BURST_COUNT 3 // how many bullets are fired in each burst
#define ASW_RAILGUN_BURST_INTERVAL 0.12f // time between each bullet in a burst
IMPLEMENT_NETWORKCLASS_ALIASED( ASW_Weapon_Railgun, DT_ASW_Weapon_Railgun )
BEGIN_NETWORK_TABLE( CASW_Weapon_Railgun, DT_ASW_Weapon_Railgun )
#ifdef CLIENT_DLL
// recvprops
RecvPropTime( RECVINFO( m_fSlowTime ) ),
RecvPropInt(RECVINFO(m_iRailBurst)),
#else
// sendprops
SendPropTime( SENDINFO( m_fSlowTime ) ),
SendPropInt( SENDINFO(m_iRailBurst), Q_log2( ASW_RAILGUN_BURST_COUNT ) + 1, SPROP_UNSIGNED ),
#endif
END_NETWORK_TABLE()
#ifdef CLIENT_DLL
BEGIN_PREDICTION_DATA( CASW_Weapon_Railgun )
DEFINE_PRED_FIELD_TOL( m_fSlowTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, TD_MSECTOLERANCE ),
DEFINE_PRED_FIELD( m_iRailBurst, FIELD_INTEGER, FTYPEDESC_INSENDTABLE )
END_PREDICTION_DATA()
#endif
LINK_ENTITY_TO_CLASS( asw_weapon_railgun, CASW_Weapon_Railgun );
PRECACHE_WEAPON_REGISTER(asw_weapon_railgun);
extern ConVar asw_weapon_max_shooting_distance;
ConVar asw_railgun_force_scale("asw_railgun_force_scale", "60.0f", FCVAR_REPLICATED, "Force of railgun shots");
#ifndef CLIENT_DLL
extern ConVar asw_debug_marine_damage;
//---------------------------------------------------------
// Save/Restore
//---------------------------------------------------------
BEGIN_DATADESC( CASW_Weapon_Railgun )
END_DATADESC()
#else
//Precache the effects
PRECACHE_REGISTER_BEGIN( GLOBAL, ASWPrecacheEffectRailgun )
PRECACHE( MATERIAL, "swarm/effects/railgun" )
PRECACHE_REGISTER_END()
#endif /* not client */
CASW_Weapon_Railgun::CASW_Weapon_Railgun()
{
m_fSlowTime = 0;
m_iRailBurst = 0;
}
CASW_Weapon_Railgun::~CASW_Weapon_Railgun()
{
}
void CASW_Weapon_Railgun::Precache()
{
PrecacheModel("swarm/effects/railgun.vmt");
PrecacheScriptSound("ASW_Railgun.Single");
BaseClass::Precache();
}
#define MAX_GLASS_PENETRATION_DEPTH 16.0f
//extern int g_sModelIndexFireball; // (in combatweapon.cpp) holds the index for the smoke cloud
void CASW_Weapon_Railgun::PrimaryAttack()
{
// If my clip is empty (and I use clips) start reload
if ( UsesClipsForAmmo1() && !m_iClip1 )
{
Reload();
return;
}
CASW_Player *pPlayer = GetCommander();
CASW_Marine *pMarine = GetMarine();
if (!pMarine) // firing from a marine
return;
#ifndef CLIENT_DLL
//Msg("[S] Railgun PrimaryAttack time=%f\n", gpGlobals->curtime);
#else
//Msg("[C] Railgun PrimaryAttack time=%f\n", gpGlobals->curtime);
#endif
m_iRailBurst = 1; // disable burst firing..
//if (m_iRailBurst <= 0)
//m_iRailBurst = ASW_RAILGUN_BURST_COUNT;
// MUST call sound before removing a round from the clip of a CMachineGun
WeaponSound(SINGLE);
m_bIsFiring = true;
// tell the marine to tell its weapon to draw the muzzle flash
pMarine->DoMuzzleFlash();
// sets the animation on the weapon model iteself
SendWeaponAnim( GetPrimaryAttackActivity() );
// sets the animation on the marine holding this weapon
//pMarine->SetAnimation( PLAYER_ATTACK1 );
#ifdef GAME_DLL // check for turning on lag compensation
if (pPlayer && pMarine->IsInhabited())
{
CASW_Lag_Compensation::RequestLagCompensation( pPlayer, pPlayer->GetCurrentUserCommand() );
}
#endif
FireBulletsInfo_t info;
info.m_vecSrc = pMarine->Weapon_ShootPosition( );
if ( pPlayer && pMarine->IsInhabited() )
{
info.m_vecDirShooting = pPlayer->GetAutoaimVectorForMarine(pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount()); // 45 degrees = 0.707106781187
}
else
{
#ifdef CLIENT_DLL
Msg("Error, clientside firing of a weapon that's being controlled by an AI marine\n");
#else
info.m_vecDirShooting = pMarine->GetActualShootTrajectory( info.m_vecSrc );
#endif
}
// To make the firing framerate independent, we may have to fire more than one bullet here on low-framerate systems,
// especially if the weapon we're firing has a really fast rate of fire.
info.m_iShots = 0;
float fireRate = GetFireRate();
if (m_iRailBurst > 1)
fireRate = ASW_RAILGUN_BURST_INTERVAL;
//float current_attack_time = m_flNextPrimaryAttack;
//float attack_delta = gpGlobals->curtime - current_attack_time;
while ( m_flNextPrimaryAttack <= gpGlobals->curtime )
{
if (m_iRailBurst == 0) // this loop could fire all our burst rounds in one go, se chcek for resetting it up
m_iRailBurst = ASW_RAILGUN_BURST_COUNT;
m_flNextPrimaryAttack = m_flNextPrimaryAttack + fireRate;
#ifndef CLIENT_DLL
//Msg("[S] Set m_flNextPrimaryAttack to %f Firerate=%f curtime=%f\n", m_flNextPrimaryAttack.Get(), fireRate, gpGlobals->curtime);
#else
//Msg("[C] Set m_flNextPrimaryAttack to %f Firerate=%f curtime=%f\n", m_flNextPrimaryAttack.Get(), fireRate, gpGlobals->curtime);
#endif
info.m_iShots++;
m_iRailBurst--;
// recalc the fire rate as our burst var can change it
fireRate = GetFireRate();
if (m_iRailBurst > 1)
fireRate = ASW_RAILGUN_BURST_INTERVAL;
if ( !fireRate )
break;
}
// Make sure we don't fire more than the amount in the clip
if ( UsesClipsForAmmo1() )
{
info.m_iShots = MIN( info.m_iShots, m_iClip1 );
m_iClip1 -= info.m_iShots;
NotifyIfNoneClip1Ammo( pMarine );
}
else
{
info.m_iShots = MIN( info.m_iShots, pMarine->GetAmmoCount( m_iPrimaryAmmoType ) );
pMarine->RemoveAmmo( info.m_iShots, m_iPrimaryAmmoType );
}
info.m_flDistance = asw_weapon_max_shooting_distance.GetFloat();
info.m_iAmmoType = m_iPrimaryAmmoType;
info.m_iTracerFreq = 1;
info.m_flDamage = GetWeaponDamage();
#ifndef CLIENT_DLL
if (asw_debug_marine_damage.GetBool())
Msg("Weapon dmg = %f\n", info.m_flDamage);
pMarine->GetMarineResource()->OnFired_ScaleDamage( info );
#endif
info.m_vecSpread = GetBulletSpread();
info.m_flDamageForceScale = asw_railgun_force_scale.GetFloat();
//float max_dist = asw_weapon_max_shooting_distance.GetFloat();
//inline void UTIL_TraceLine( const Vector& vecAbsStart, const Vector& vecAbsEnd, unsigned int mask,
//const IHandleEntity *ignore, int collisionGroup, trace_t *ptr )
// find impact point of the RG shot
#ifdef ASW_RAILGUN_SWEEP_STYLE
trace_t tr;
UTIL_TraceLine(info.m_vecSrc, info.m_vecSrc + info.m_vecDirShooting * max_dist, MASK_SOLID_BRUSHONLY, pMarine, COLLISION_GROUP_NONE, &tr);
if (!tr.startsolid)
{
#ifndef CLIENT_DLL
bool bHitGlass = false;
if ( tr.m_pEnt != NULL )
{
Msg("trace hit something\n");
surfacedata_t *psurf = physprops->GetSurfaceData( tr.surface.surfaceProps );
if (psurf != NULL)
{
Msg("psurf isn't null. mat = %d glass = %d class = %s match = %d\n", psurf->game.material, CHAR_TEX_GLASS, tr.m_pEnt->GetClassname(), tr.m_pEnt->ClassMatches( "CBreakableSurface" ));
}
if ( ( psurf != NULL ) && ( psurf->game.material == CHAR_TEX_GLASS ) && ( tr.m_pEnt->ClassMatches( "CBreakableSurface" ) ) )
{
Msg("so this is a glass hit\n");
bHitGlass = true;
}
}
int glassCount = 10;
while (bHitGlass && glassCount > 0)
{
Msg("hit glass\n");
bHitGlass = false;
glassCount--;
// Move through the glass until we're at the other side
Vector testPos = tr.endpos + ( info.m_vecDirShooting * MAX_GLASS_PENETRATION_DEPTH );
CEffectData data;
data.m_vNormal = tr.plane.normal;
data.m_vOrigin = tr.endpos;
DispatchEffect( "GlassImpact", data );
trace_t penetrationTrace;
UTIL_TraceLine(testPos, tr.endpos, MASK_SHOT, pMarine, COLLISION_GROUP_NONE, &penetrationTrace);
// See if we found the surface again
if ( !penetrationTrace.startsolid && tr.fraction != 0.0f && penetrationTrace.fraction != 1.0f )
{
// Impact the other side (will look like an exit effect)
DoImpactEffect( penetrationTrace, GetAmmoDef()->DamageType(info.m_iAmmoType) );
data.m_vNormal = penetrationTrace.plane.normal;
data.m_vOrigin = penetrationTrace.endpos;
DispatchEffect( "GlassImpact", data );
// continue trace past the glass
UTIL_TraceLine(penetrationTrace.endpos, penetrationTrace.endpos + info.m_vecDirShooting * max_dist, MASK_SOLID_BRUSHONLY, pMarine, COLLISION_GROUP_NONE, &tr);
if ( tr.m_pEnt != NULL )
{
surfacedata_t *psurf = physprops->GetSurfaceData( tr.surface.surfaceProps );
if ( ( psurf != NULL ) && ( psurf->game.material == CHAR_TEX_GLASS ) && ( tr.m_pEnt->ClassMatches( "func_breakable" ) ) )
{
bHitGlass = true;
}
}
}
}
Vector vecEndPos = tr.endpos;
trace_t ptr;
//CTakeDamageInfo( CBaseEntity *pInflictor, CBaseEntity *pAttacker, float flDamage, int bitsDamageType, int iKillType = 0 );
//CTakeDamageInfo( CBaseEntity *pInflictor, CBaseEntity *pAttacker, const Vector &damageForce, const Vector &damagePosition, float flDamage, int bitsDamageType, int iKillType = 0, Vector *reportedPosition = NULL );
// do close high damage FF damaging trace
CTakeDamageInfo dmg(this, pMarine, Vector(0,0,0), GetAbsOrigin(), GetWeaponDamage(), DMG_SONIC); // | DMG_ALWAYSGIB
CTraceFilterRG traceFilter( pMarine, COLLISION_GROUP_NONE, &dmg, true );
Vector vecMin(-3, -3, -3);
Vector vecMax(3, 3, 3);
UTIL_TraceHull( info.m_vecSrc, vecEndPos, vecMin, vecMax,
CONTENTS_MONSTER, &traceFilter, &ptr );
// do wide less damaging sweep
#ifdef ASW_RAILGUN_WIDE_SWEEP
CTakeDamageInfo wdmg(this, pMarine, Vector(0,0,0), GetAbsOrigin(), GetWeaponDamage() * 0.33f, DMG_SONIC); // | DMG_ALWAYSGIB
CTraceFilterRG wtraceFilter( pMarine, COLLISION_GROUP_NONE, &wdmg, false );
Vector vecWMin(-15, -15, -15);
Vector vecWMax(15, 15, 15);
UTIL_TraceHull( info.m_vecSrc, vecEndPos, vecWMin, vecWMax,
CONTENTS_MONSTER, &wtraceFilter, &ptr );
#endif // ASW_RAILGUN_WIDE_SWEEP
#endif // CLIENT_DLL
//CreateRailgunBeam(GetAbsOrigin(), tr.endpos);
}
#else
//trace_t tr;
//UTIL_TraceLine(info.m_vecSrc, info.m_vecSrc + info.m_vecDirShooting * max_dist, MASK_SHOT, pMarine, COLLISION_GROUP_NONE, &tr);
//Vector vecExplosionPos = tr.endpos;
//CPASFilter filter( vecExplosionPos );
/*te->Explosion( filter, 0.1, // IRecipientFilter& filter, float delay
&vecExplosionPos, // pos
g_sModelIndexFireball, // modelindex
0.1, // scale
1, // framerate
TE_EXPLFLAG_NONE, // flags
0.5, // radius
0.5 ); // magnitude
*/
pMarine->FirePenetratingBullets( info, 10, 1.0f, 0, true, NULL, false );
//pMarine->FireBullets( info );
#endif // ASW_RAILGUN_SWEEP_STYLE
// increment shooting stats
#ifndef CLIENT_DLL
if ( pMarine->GetMarineResource() )
{
pMarine->GetMarineResource()->UsedWeapon(this, info.m_iShots);
pMarine->OnWeaponFired( this, info.m_iShots );
}
#endif
//Mad Orange. Suit is unused in ASW
/*
if (!m_iClip1 && pMarine->GetAmmoCount(m_iPrimaryAmmoType) <= 0)
{
// HEV suit - indicate out of ammo condition
if (pPlayer)
pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0);
}
*/
m_fSlowTime = gpGlobals->curtime + 0.1f;
}
// creates a translucent beam effect coming out from the gun
void CASW_Weapon_Railgun::CreateRailgunBeam( const Vector &vecStartPoint, const Vector &vecEndPoint )
{
//Vector vecEndPoint = info.m_vecSrc + info.m_vecDirShooting * 1000;
//Vector vecStartPoint = GetAbsOrigin();
CASW_Marine* pOwner = GetMarine();
if (!pOwner)
return;
CEffectData data;
data.m_vStart = vecStartPoint;
data.m_vOrigin = vecEndPoint;
data.m_fFlags |= TRACER_FLAG_USEATTACHMENT;
data.m_nAttachmentIndex = LookupAttachment("muzzle");
#ifdef CLIENT_DLL
data.m_hEntity = this;
#else
data.m_nEntIndex = entindex();
#endif
CPASFilter filter( data.m_vOrigin );
#ifndef CLIENT_DLL
if (gpGlobals->maxClients > 1 && pOwner->IsInhabited() && pOwner->GetCommander())
{
// multiplayer game, where this marine is currently being controlled by a client, who will spawn his own effect
// so just make the beam effect for all other clients
filter.RemoveRecipient(pOwner->GetCommander());
}
#endif
DispatchEffect(filter, 0.0, "RailgunBeam", data );
return;
/*
#ifdef CLIENT_DLL
QAngle muzzleAngles;
GetAttachment( LookupAttachment("muzzle"), vecStartPoint, muzzleAngles );
// create a railgun beam (it'll fade out and kill itself after a short period)
C_ASW_Railgun_Beam *pBeam = new C_ASW_Railgun_Beam();
if (pBeam)
{
if (pBeam->InitializeAsClientEntity( NULL, false ))
{
pBeam->InitBeam(vecStartPoint, vecEndPoint);
}
else
{
pBeam->Release();
}
}*/
/*
// Draw a beam
BeamInfo_t beamInfo;
beamInfo.m_pStartEnt = this;
beamInfo.m_nStartAttachment = 1;
beamInfo.m_pEndEnt = NULL;
beamInfo.m_nEndAttachment = -1;
beamInfo.m_vecStart = vec3_origin;
beamInfo.m_vecEnd = vecEndPoint;
beamInfo.m_pszModelName = "swarm/effects/railgun.vmt";
beamInfo.m_flHaloScale = 0.0f;
beamInfo.m_flLife = 0.1f;
beamInfo.m_flWidth = 12.0f;
beamInfo.m_flEndWidth = 4.0f;
beamInfo.m_flFadeLength = 0.0f;
beamInfo.m_flAmplitude = 0;
beamInfo.m_flBrightness = 255.0;
beamInfo.m_flSpeed = 0.0f;
beamInfo.m_nStartFrame = 0.0;
beamInfo.m_flFrameRate = 0.0;
beamInfo.m_flRed = 255.0;
beamInfo.m_flGreen = 255.0;
beamInfo.m_flBlue = 255.0;
beamInfo.m_nSegments = 16;
beamInfo.m_bRenderable = true;
beamInfo.m_nFlags = FBEAM_ONLYNOISEONCE | FBEAM_SOLID;
beams->CreateBeamEntPoint( beamInfo );
*/
/*
#else
CASW_Marine* pOwner = GetMarine();
if (!pOwner)
return;
CEffectData data;
data.m_vStart = vecStartPoint;
data.m_vOrigin = vecEndPoint;
data.m_fFlags |= TRACER_FLAG_USEATTACHMENT;
data.m_nAttachmentIndex = LookupAttachment("muzzle");
data.m_nEntIndex = entindex();
CPASFilter filter( data.m_vOrigin );
if (gpGlobals->maxClients > 1 && pOwner->IsInhabited() && pOwner->GetCommander())
{
// multiplayer game, where this marine is currently being controlled by a client, who will spawn his own effect
// so just make the beam effect for all other clients
filter.RemoveRecipient(pOwner->GetCommander());
}
te->DispatchEffect( filter, 0.0, data.m_vOrigin, "RailgunBeam", data );
#endif*/
}
bool CASW_Weapon_Railgun::ShouldMarineMoveSlow()
{
return BaseClass::ShouldMarineMoveSlow();
//return m_fSlowTime > gpGlobals->curtime;
}
float CASW_Weapon_Railgun::GetMovementScale()
{
return ShouldMarineMoveSlow() ? 0.75f : 1.0f;
}
bool CASW_Weapon_Railgun::Reload()
{
m_iRailBurst = 0;
bool bReloaded = ASWReload( GetMaxClip1(), GetMaxClip2(), ACT_VM_RELOAD );
// skip reload chatter on the railgun, since it reloads after every shot
/*
if (bReloaded)
{
#ifdef GAME_DLL
CASW_Marine *pMarine = GetMarine();
if (pMarine)
{
if (pMarine->IsAlienNear())
{
//Msg("potentially reload chattering as there is an alien near\n");
pMarine->GetMarineSpeech()->Chatter(CHATTER_RELOADING);
}
else
{
//Msg("Not reload chattering as there's no aliens near\n");
}
}
#endif
}
*/
return bReloaded;
}
bool CASW_Weapon_Railgun::Holster( CBaseCombatWeapon *pSwitchingTo )
{
m_iRailBurst = 0;
return BaseClass::Holster( pSwitchingTo );
}
void CASW_Weapon_Railgun::GetButtons(bool& bAttack1, bool& bAttack2, bool& bReload, bool& bOldReload, bool& bOldAttack1 )
{
BaseClass::GetButtons(bAttack1, bAttack2, bReload, bOldReload, bOldAttack1 );
// make sure the fire button stays held down until our burst is clear
CASW_Marine *pMarine = GetMarine();
if (m_iRailBurst > 0 && !(pMarine && pMarine->GetFlags() & FL_FROZEN))
bAttack1 = true;
}
bool CASW_Weapon_Railgun::SupportsBayonet()
{
return true;
}
float CASW_Weapon_Railgun::GetWeaponBaseDamageOverride()
{
// Railgun must kill with one shot for Instagib game mode
if ( ASWDeathmatchMode() && ASWDeathmatchMode()->IsInstagibEnabled() )
return 1000;
extern ConVar rd_railgun_dmg_base;
return rd_railgun_dmg_base.GetFloat();
}
int CASW_Weapon_Railgun::GetWeaponSkillId()
{
return ASW_MARINE_SKILL_ACCURACY;
}
int CASW_Weapon_Railgun::GetWeaponSubSkillId()
{
return ASW_MARINE_SUBSKILL_ACCURACY_RAILGUN_DMG;
}
int CASW_Weapon_Railgun::ASW_SelectWeaponActivity(int idealActivity)
{
switch( idealActivity )
{
case ACT_WALK: idealActivity = ACT_WALK_AIM_RIFLE; break;
case ACT_RUN: idealActivity = ACT_RUN_AIM_RIFLE; break;
case ACT_IDLE: idealActivity = ACT_IDLE_RIFLE; break;
case ACT_RELOAD: idealActivity = ACT_RELOAD; break;
default: break;
}
return idealActivity;
}
#ifndef CLIENT_DLL
bool CTraceFilterRG::ShouldHitEntity( IHandleEntity *pHandleEntity, int contentsMask )
{
if ( !StandardFilterRules( pHandleEntity, contentsMask ) )
return false;
if ( !PassServerEntityFilter( pHandleEntity, m_pPassEnt ) )
return false;
// Don't test if the game code tells us we should ignore this collision...
CBaseEntity *pEntity = EntityFromEntityHandle( pHandleEntity );
if ( pEntity )
{
if ( !pEntity->ShouldCollide( m_collisionGroup, contentsMask ) )
return false;
if ( !g_pGameRules->ShouldCollide( m_collisionGroup, pEntity->GetCollisionGroup() ) )
return false;
if ( pEntity->m_takedamage == DAMAGE_NO )
return false;
Vector attackDir = pEntity->WorldSpaceCenter() - m_dmgInfo->GetAttacker()->WorldSpaceCenter();
VectorNormalize( attackDir );
CTakeDamageInfo info = (*m_dmgInfo);
CalculateMeleeDamageForce( &info, attackDir, info.GetAttacker()->WorldSpaceCenter(), 1.0f );
CBaseCombatCharacter *pBCC = info.GetAttacker()->MyCombatCharacterPointer();
CBaseCombatCharacter *pVictimBCC = pEntity->MyCombatCharacterPointer();
// Only do these comparisons between NPCs
if ( pBCC && pVictimBCC )
{
// Can only damage other NPCs that we hate
if ( m_bFFDamage || pBCC->IRelationType( pEntity ) == D_HT )
{
if ( info.GetDamage() )
{
pEntity->TakeDamage( info );
}
// Put a combat sound in
CSoundEnt::InsertSound( SOUND_COMBAT, info.GetDamagePosition(), 200, 0.2f, info.GetAttacker() );
m_pHit = pEntity;
return true;
}
}
else
{
// Make sure if the player is holding this, he drops it
Pickup_ForcePlayerToDropThisObject( pEntity );
// Otherwise just damage passive objects in our way
if ( info.GetDamage() )
{
pEntity->TakeDamage( info );
}
}
}
return false;
}
#endif
void CASW_Weapon_Railgun::SecondaryAttack()
{
// Only the player fires this way so we can cast
CASW_Player *pPlayer = GetCommander();
if (!pPlayer)
return;
CASW_Marine *pMarine = GetMarine();
if (!pMarine)
return;
// dry fire - no secondary enabled on RG (below rocket stuff is an experiment)
SendWeaponAnim( ACT_VM_DRYFIRE );
BaseClass::WeaponSound( EMPTY );
m_flNextSecondaryAttack = gpGlobals->curtime + 0.5f;
return;
//Must have ammo - temp comment
//bool bUsesSecondary = UsesSecondaryAmmo();
bool bUsesClips = UsesClipsForAmmo2();
//int iAmmoCount = pMarine->GetAmmoCount(m_iSecondaryAmmoType);
//bool bInWater = ( pMarine->GetWaterLevel() == 3 );
/*
if ( (bUsesSecondary &&
( ( bUsesClips && m_iClip2 <= 0) ||
( !bUsesClips && iAmmoCount<=0 )
) )
|| bInWater || m_bInReload )
{
SendWeaponAnim( ACT_VM_DRYFIRE );
BaseClass::WeaponSound( EMPTY );
m_flNextSecondaryAttack = gpGlobals->curtime + 0.5f;
return;
}
*/
// MUST call sound before removing a round from the clip of a CMachineGun
BaseClass::WeaponSound( SPECIAL1 );
//Vector vecSrc = pMarine->Weapon_ShootPosition();
Vector vecThrow;
// Don't autoaim on grenade tosses
vecThrow = pPlayer->GetAutoaimVectorForMarine(pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount()); // 45 degrees = 0.707106781187
QAngle angGrenFacing;
VectorAngles(vecThrow, angGrenFacing);
VectorScale( vecThrow, 1000.0f, vecThrow );
#ifndef CLIENT_DLL
//Create the grenade
/*
float fGrenadeDamage = MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_GRENADES, ASW_MARINE_SUBSKILL_GRENADE_DMG);
float fGrenadeRadius = MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_GRENADES, ASW_MARINE_SUBSKILL_GRENADE_RADIUS);
if (asw_debug_marine_damage.GetBool())
{
Msg("Grenade damage = %f radius = %f\n", fGrenadeDamage, fGrenadeRadius);
}
CASW_Grenade_PRifle::PRifle_Grenade_Create(
fGrenadeDamage,
fGrenadeRadius,
vecSrc, angGrenFacing, vecThrow, AngularImpulse(0,0,0), pMarine );
*/
const int num_rockets = 5;
const int fan_spread = 90;
for (int i=0;i<num_rockets;i++)
{
int angle = (-fan_spread * 0.5f) + float(fan_spread) * (float(i) / float(num_rockets));
QAngle vecRocketAngle = angGrenFacing;
vecRocketAngle[YAW] += angle;
//CASW_Rocket::Create(vecSrc, vecRocketAngle, GetMarine());
}
#endif
SendWeaponAnim( ACT_VM_SECONDARYATTACK );
if ( bUsesClips )
{
m_iClip2 -= 1;
}
else
{
pMarine->RemoveAmmo( 1, m_iSecondaryAmmoType );
}
// Can shoot again immediately
m_flNextPrimaryAttack = gpGlobals->curtime + 0.5f;
// Can blow up after a short delay (so have time to release mouse button)
m_flNextSecondaryAttack = gpGlobals->curtime + 1.0f;
}