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
726
727
728
729
730
731
732
733
734
735
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Harpoon
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "basetfplayer_shared.h"
#include "basetfcombatweapon_shared.h"
#include "in_buttons.h"
#include "engine/IEngineSound.h"
#if defined( CLIENT_DLL )
#define CWeaponHarpoon C_WeaponHarpoon
#endif
class CHarpoon;
// Fist defines
#define FIST_RANGE 90
#if !defined( CLIENT_DLL )
ConVar weapon_harpoon_damage( "weapon_harpoon_damage","40", FCVAR_NONE, "Harpoon impale damage" );
ConVar weapon_fist_damage( "weapon_fist_damage","50", FCVAR_NONE, "Fist damage to everything other than objects" );
ConVar weapon_fist_damage_objects( "weapon_fist_damage_objects","150", FCVAR_NONE, "Fist damage to objects" );
#include "rope.h"
#include "rope_shared.h"
//-----------------------------------------------------------------------------
// Purpose: Harpoon thrown by the harpoon weapon
//-----------------------------------------------------------------------------
class CHarpoon : public CBaseAnimating
{
DECLARE_CLASS( CHarpoon, CBaseAnimating );
public:
DECLARE_DATADESC();
DECLARE_SERVERCLASS();
CHarpoon( void );
virtual void Spawn( void );
virtual void Precache( void );
void SetHarpoonAngles( void );
void FlyThink( void );
void ConstrainThink( void );
void HarpoonTouch( CBaseEntity *pOther );
static CHarpoon *Create( const Vector &vecOrigin, const Vector &vecForward, CBasePlayer *pOwner );
CRopeKeyframe *GetRope( void ) { return m_hRope; }
void SetRope( CRopeKeyframe *pRope ) { m_hRope = pRope; }
CBaseEntity *GetImpaledTarget( void ) { return m_hImpaledTarget; }
void SetLinkedHarpoon( CHarpoon *pLinkedHarpoon ) { m_hLinkedHarpoon = pLinkedHarpoon; }
void CheckLinkedHarpoon( void );
void ImpaleTarget( CBaseEntity *pOther );
private:
// Impaling
CNetworkVector( m_vecOffset );
CNetworkQAngle( m_angOffset );
float m_flConstrainLength;
CHandle< CRopeKeyframe > m_hRope;
EHANDLE m_hImpaledTarget;
CHandle< CHarpoon > m_hLinkedHarpoon;
};
LINK_ENTITY_TO_CLASS( harpoon, CHarpoon );
PRECACHE_REGISTER(harpoon);
IMPLEMENT_SERVERCLASS_ST(CHarpoon, DT_Harpoon)
SendPropVector( SENDINFO(m_vecOffset), -1, SPROP_COORD ),
SendPropVector( SENDINFO(m_angOffset), -1, SPROP_COORD ),
END_SEND_TABLE()
BEGIN_DATADESC( CHarpoon )
// Function Pointers
DEFINE_FUNCTION( HarpoonTouch ),
DEFINE_FUNCTION( FlyThink ),
DEFINE_FUNCTION( ConstrainThink ),
END_DATADESC()
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CHarpoon::CHarpoon( void )
{
UseClientSideAnimation();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHarpoon::Spawn( void )
{
Precache();
SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_CUSTOM );
SetSolid( SOLID_BBOX );
//m_flGravity = 1.0;
SetFriction( 0.75 );
SetModel( "models/weapons/w_harpoon.mdl" );
UTIL_SetSize(this, Vector( -4, -4, -4), Vector(4, 4, 4));
SetCollisionGroup( TFCOLLISION_GROUP_GRENADE );
SetTouch( HarpoonTouch );
SetThink( FlyThink );
SetNextThink( gpGlobals->curtime + 0.1f );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHarpoon::Precache( void )
{
PrecacheModel( "models/weapons/w_harpoon.mdl" );
PrecacheScriptSound( "Harpoon.Impact" );
PrecacheScriptSound( "Harpoon.Impale" );
PrecacheScriptSound( "Harpoon.HitFlesh" );
PrecacheScriptSound( "Harpoon.HitMetal" );
PrecacheScriptSound( "Harpoon.Yank" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHarpoon::SetHarpoonAngles( void )
{
QAngle angles;
VectorAngles( GetAbsVelocity(), angles );
SetLocalAngles( angles );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHarpoon::HarpoonTouch( CBaseEntity *pOther )
{
// If we've stuck something, freeze. Make sure we hit it along our velocity.
if ( pOther->GetCollisionGroup() != TFCOLLISION_GROUP_SHIELD )
{
// Perform the collision response...
const trace_t &tr = CBaseEntity::GetTouchTrace( );
Vector vecNewVelocity;
PhysicsClipVelocity (GetAbsVelocity(), tr.plane.normal, vecNewVelocity, 2.0 - GetFriction());
SetAbsVelocity( vecNewVelocity );
}
else
{
// Move away from the shield...
// Fling it out a little extra along the plane normal
Vector vecCenter;
AngleVectors( pOther->GetAbsAngles(), &vecCenter );
Vector vecNewVelocity;
VectorMultiply( vecCenter, 400.0f, vecNewVelocity );
SetAbsVelocity( vecNewVelocity );
}
if ( !pOther->IsBSPModel() && !pOther->GetBaseAnimating() )
return;
// At this point, it shouldn't affect player movement
SetCollisionGroup( COLLISION_GROUP_DEBRIS );
// Remove myself soon
SetThink( SUB_Remove );
SetNextThink( gpGlobals->curtime + 30.0 );
m_hImpaledTarget = pOther;
// Should I impale something?
if ( pOther->GetBaseAnimating() )
{
CheckLinkedHarpoon();
if ( pOther->GetMoveType() != MOVETYPE_NONE )
{
ImpaleTarget( pOther );
return;
}
}
CheckLinkedHarpoon();
EmitSound( "Harpoon.Impact" );
// Stop moving
SetMoveType( MOVETYPE_NONE );
}
//-----------------------------------------------------------------------------
// Purpose: Check to see if we've got a linked harpoon, and see if we should constrain something
//-----------------------------------------------------------------------------
void CHarpoon::CheckLinkedHarpoon( void )
{
if ( m_hLinkedHarpoon )
{
CHarpoon *pPlayerHarpoon = NULL;
CHarpoon *pNonMovingHarpoon = NULL;
// Find out if either of us has impaled something
if ( GetImpaledTarget() && m_hLinkedHarpoon->GetImpaledTarget() )
{
// Only care about players for now. One of the targets must be a player.
CBaseTFPlayer *pPlayer = NULL;
CBaseEntity *pOtherTarget = NULL;
if ( GetImpaledTarget()->IsPlayer() )
{
pPlayer = (CBaseTFPlayer*)GetImpaledTarget();
pPlayerHarpoon = this;
pNonMovingHarpoon = m_hLinkedHarpoon;
}
else if ( m_hLinkedHarpoon->GetImpaledTarget()->IsPlayer() )
{
pPlayer = (CBaseTFPlayer*)m_hLinkedHarpoon->GetImpaledTarget();
pNonMovingHarpoon = this;
pPlayerHarpoon = m_hLinkedHarpoon;
}
// Found a player?
if ( pPlayer )
{
pOtherTarget = pNonMovingHarpoon->GetImpaledTarget();
// For now, we have to be linked to a non-moving target. Eventually we could support linked moving targets.
// pOtherTarget == NULL means the harpoon's buried in the world.
if ( pOtherTarget->IsBSPModel() || pOtherTarget->GetMoveType() == MOVETYPE_NONE )
{
// Add a little slack
m_flConstrainLength = ( m_hLinkedHarpoon->GetAbsOrigin() - GetAbsOrigin() ).Length() + 150;
pPlayer->ActivateMovementConstraint( NULL, pNonMovingHarpoon->GetAbsOrigin(), m_flConstrainLength, 150.0f, 0.1f );
// Square it for later checking
m_flConstrainLength *= m_flConstrainLength;
// Start checking the length
pPlayerHarpoon->m_flConstrainLength = m_flConstrainLength;
pPlayerHarpoon->SetThink( ConstrainThink );
pPlayerHarpoon->SetNextThink( gpGlobals->curtime + 0.1f );
// Make the rope taught, and prevent it resizing
if ( m_hRope )
{
m_hRope->m_RopeFlags &= ~ROPE_RESIZE;
m_hRope->RecalculateLength();
}
}
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHarpoon::ImpaleTarget( CBaseEntity *pOther )
{
// Impale!
EmitSound( "Harpoon.Impale" );
// Calculate our impale offset
m_vecOffset = (pOther->GetAbsOrigin() - GetAbsOrigin());
m_angOffset = (pOther->GetAbsAngles() - GetAbsAngles());
FollowEntity( pOther );
// Do some damage to the target
if ( pOther->m_takedamage )
{
CBaseTFPlayer *pOwner = ToBaseTFPlayer( GetOwnerEntity() );
if ( !pOwner )
return;
pOther->TakeDamage( CTakeDamageInfo( this, pOwner, weapon_harpoon_damage.GetFloat(), DMG_GENERIC ) );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHarpoon::FlyThink( void )
{
SetHarpoonAngles();
SetNextThink( gpGlobals->curtime + 0.1f );
}
//-----------------------------------------------------------------------------
// Purpose: Check to see if our target has moved beyond our length
//-----------------------------------------------------------------------------
void CHarpoon::ConstrainThink( void )
{
if ( !GetImpaledTarget() || !m_hLinkedHarpoon.Get() )
return;
// Moved too far away?
float flDistSq = m_hLinkedHarpoon->GetAbsOrigin().DistToSqr( GetImpaledTarget()->GetAbsOrigin() );
if ( flDistSq > m_flConstrainLength )
{
// Break the rope
if ( m_hRope )
{
m_hRope->DetachPoint(1);
m_hRope->DieAtNextRest();
m_hRope = NULL;
}
// If we're impaling a player, remove his movement constraint
if ( GetImpaledTarget()->IsPlayer() )
{
CBaseTFPlayer *pPlayer = (CBaseTFPlayer *)GetImpaledTarget();
pPlayer->DeactivateMovementConstraint();
}
SetThink( NULL );
}
else
{
SetNextThink( gpGlobals->curtime + 0.1f );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CHarpoon *CHarpoon::Create( const Vector &vecOrigin, const Vector &vecForward, CBasePlayer *pOwner )
{
CHarpoon *pHarpoon = (CHarpoon*)CreateEntityByName("harpoon");
UTIL_SetOrigin( pHarpoon, vecOrigin );
pHarpoon->Spawn();
pHarpoon->ChangeTeam( pOwner->GetTeamNumber() );
pHarpoon->SetOwnerEntity( pOwner );
pHarpoon->SetAbsVelocity( vecForward );
pHarpoon->SetHarpoonAngles();
return pHarpoon;
}
#endif
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CWeaponHarpoon : public CBaseTFCombatWeapon
{
DECLARE_CLASS( CWeaponHarpoon, CBaseTFCombatWeapon );
public:
CWeaponHarpoon();
DECLARE_NETWORKCLASS();
DECLARE_PREDICTABLE();
virtual void ItemPostFrame( void );
virtual void PrimaryAttack( void );
virtual void SecondaryAttack( void );
virtual float GetFireRate( void );
virtual void ThrowGrenade( void );
virtual void DetachRope( void );
virtual void YankHarpoon( void );
// Custom grenade types
virtual CHarpoon *CreateHarpoon( const Vector &vecOrigin, const Vector &vecAngles, CBasePlayer *pOwner );
/*
// All predicted weapons need to implement and return true
virtual bool IsPredicted( void ) const
{
return true;
}
#if defined( CLIENT_DLL )
virtual bool ShouldPredict( void )
{
if ( GetOwner() == C_BasePlayer::GetLocalPlayer() )
return true;
return BaseClass::ShouldPredict();
}
#endif
*/
public:
CNetworkVar( float, m_flStartedThrowAt );
float m_flCantThrowUntil;
float m_flSecondaryAttackAt;
bool m_bActiveHarpoon;
#if !defined( CLIENT_DLL )
CHandle< CRopeKeyframe > m_hRope;
CHandle< CHarpoon > m_hHarpoon;
#endif
private:
CWeaponHarpoon( const CWeaponHarpoon & );
};
LINK_ENTITY_TO_CLASS( weapon_harpoon, CWeaponHarpoon );
IMPLEMENT_NETWORKCLASS_ALIASED( WeaponHarpoon, DT_WeaponHarpoon )
BEGIN_NETWORK_TABLE( CWeaponHarpoon, DT_WeaponHarpoon )
#if !defined( CLIENT_DLL )
SendPropTime( SENDINFO( m_flStartedThrowAt ) ),
#else
RecvPropTime( RECVINFO( m_flStartedThrowAt ) ),
#endif
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CWeaponHarpoon )
DEFINE_PRED_FIELD_TOL( m_flStartedThrowAt, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, TD_MSECTOLERANCE ),
END_PREDICTION_DATA()
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CWeaponHarpoon::CWeaponHarpoon( void )
{
m_flStartedThrowAt = 0;
m_flCantThrowUntil = 0;
m_flSecondaryAttackAt = 0;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
float CWeaponHarpoon::GetFireRate( void )
{
return 2.0;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponHarpoon::ItemPostFrame( void )
{
CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
if (!pOwner)
return;
// Look for button downs
if ( (pOwner->m_afButtonPressed & IN_ATTACK) && !m_flStartedThrowAt && (m_flNextPrimaryAttack <= gpGlobals->curtime) )
{
// If we don't have a harpoon, throw one out. Otherwise, yank it back.
if ( m_bActiveHarpoon )
{
YankHarpoon();
}
else
{
m_bActiveHarpoon = true;
m_flStartedThrowAt = gpGlobals->curtime;
PlayAttackAnimation( ACT_VM_PULLBACK );
m_flCantThrowUntil = gpGlobals->curtime + SequenceDuration();
}
}
else if ( m_flCantThrowUntil && m_bActiveHarpoon && !(pOwner->m_nButtons & IN_ATTACK) && (m_flNextPrimaryAttack <= gpGlobals->curtime) && (m_flCantThrowUntil <= gpGlobals->curtime) )
{
m_flNextPrimaryAttack = gpGlobals->curtime;
PrimaryAttack();
m_flStartedThrowAt = 0;
m_flCantThrowUntil = 0;
}
else if ( (pOwner->m_nButtons & IN_ATTACK2) && (m_flNextPrimaryAttack <= gpGlobals->curtime) )
{
PlayAttackAnimation( ACT_VM_SECONDARYATTACK );
m_flSecondaryAttackAt = gpGlobals->curtime + SequenceDuration() * 0.3;
m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration();
}
else if ( m_flSecondaryAttackAt && m_flSecondaryAttackAt < gpGlobals->curtime )
{
SecondaryAttack();
m_flSecondaryAttackAt = 0;
}
// No buttons down?
if ( !((pOwner->m_nButtons & IN_ATTACK) || (pOwner->m_nButtons & IN_ATTACK2) || (pOwner->m_nButtons & IN_RELOAD)) )
{
WeaponIdle( );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponHarpoon::PrimaryAttack( void )
{
CBasePlayer *pPlayer = dynamic_cast<CBasePlayer*>( GetOwner() );
if ( !pPlayer )
return;
if ( !ComputeEMPFireState() )
return;
ThrowGrenade();
// Setup for refire
m_flNextPrimaryAttack = gpGlobals->curtime + 1.0;
CheckRemoveDisguise();
// If I'm now out of ammo, switch away
if ( !HasPrimaryAmmo() )
{
pPlayer->SelectLastItem();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponHarpoon::SecondaryAttack( void )
{
CBasePlayer *pPlayer = dynamic_cast<CBasePlayer*>( GetOwner() );
if ( !pPlayer )
return;
// Slap things in front of me
Vector vecForward;
Vector vecBox = Vector( FIST_RANGE,FIST_RANGE,FIST_RANGE * 1.5 ) * 0.5;
pPlayer->EyeVectors( &vecForward );
Vector vecSrc = pPlayer->Weapon_ShootPosition( );
Vector vecCenter = vecSrc + (FIST_RANGE * 0.5 * vecForward);
#if !defined( CLIENT_DLL )
//NDebugOverlay::Box( vecCenter, -Vector(2,2,2), Vector(2,2,2), 255,0,0,20,2.0);
//NDebugOverlay::Box( vecCenter, -vecBox, vecBox, 255,255,255,20,2.0);
bool bHitMetal = false;
bool bHitPlayer = false;
CBaseEntity *pList[100];
int count = UTIL_EntitiesInBox( pList, 100, vecSrc - vecBox, vecSrc + vecBox, FL_CLIENT|FL_NPC|FL_OBJECT );
for ( int i = 0; i < count; i++ )
{
CBaseEntity *pEntity = pList[i];
if ( !pEntity->m_takedamage )
continue;
if ( pEntity->InSameTeam( this ) )
continue;
//NDebugOverlay::EntityBounds( pEntity, 0,255,0,20,2.0);
if ( pEntity->IsPlayer() )
{
bHitPlayer = true;
CTakeDamageInfo info( this, pPlayer, weapon_fist_damage.GetFloat(), DMG_CLUB );
CalculateMeleeDamageForce( &info, (pEntity->GetAbsOrigin() - vecCenter), pEntity->GetAbsOrigin() );
pEntity->TakeDamage( info );
}
else if ( pEntity->Classify() == CLASS_MILITARY )
{
bHitMetal = true;
CTakeDamageInfo info( this, pPlayer, weapon_fist_damage_objects.GetFloat(), DMG_CLUB );
CalculateMeleeDamageForce( &info, (pEntity->GetAbsOrigin() - vecCenter), pEntity->GetAbsOrigin() );
pEntity->TakeDamage( info );
}
else
{
bHitMetal = true;
CTakeDamageInfo info( this, pPlayer, weapon_fist_damage.GetFloat(), DMG_CLUB );
CalculateMeleeDamageForce( &info, (pEntity->GetAbsOrigin() - vecCenter), pEntity->GetAbsOrigin() );
pEntity->TakeDamage( info );
}
}
// Play the right sound
if ( bHitPlayer )
{
EmitSound( "Harpoon.HitFlesh" );
}
else if ( bHitMetal )
{
EmitSound( "Harpoon.HitMetal" );
}
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponHarpoon::ThrowGrenade( void )
{
CBasePlayer *pPlayer = dynamic_cast<CBasePlayer*>( GetOwner() );
if ( !pPlayer )
return;
BaseClass::WeaponSound(WPN_DOUBLE);
// Calculate launch velocity (3 seconds for max distance)
float flThrowTime = MIN( (gpGlobals->curtime - m_flStartedThrowAt), 3.0 );
float flSpeed = 1000 + (200 * flThrowTime);
PlayAttackAnimation( ACT_VM_PRIMARYATTACK );
// If the player's crouched, roll the grenade
if ( pPlayer->GetFlags() & FL_DUCKING )
{
// Launch the grenade
Vector vecForward;
QAngle vecAngles = pPlayer->EyeAngles();
// Throw it up just a tad
vecAngles.x = -1;
AngleVectors( vecAngles, &vecForward, NULL, NULL);
Vector vecOrigin;
VectorLerp( pPlayer->EyePosition(), pPlayer->GetAbsOrigin(), 0.25f, vecOrigin );
vecOrigin += (vecForward * 16);
vecForward = vecForward * flSpeed;
CreateHarpoon(vecOrigin, vecForward, pPlayer );
}
else
{
// Launch the grenade
Vector vecForward;
QAngle vecAngles = pPlayer->EyeAngles();
AngleVectors( vecAngles, &vecForward, NULL, NULL);
Vector vecOrigin = pPlayer->EyePosition();
vecOrigin += (vecForward * 16);
vecForward = vecForward * flSpeed;
CreateHarpoon(vecOrigin, vecForward, pPlayer );
}
pPlayer->RemoveAmmo( 1, m_iPrimaryAmmoType );
}
//-----------------------------------------------------------------------------
// Purpose: Give the harpoon a yank
//-----------------------------------------------------------------------------
void CWeaponHarpoon::YankHarpoon( void )
{
CBasePlayer *pPlayer = dynamic_cast<CBasePlayer*>( GetOwner() );
if ( !pPlayer )
return;
#if !defined( CLIENT_DLL )
if ( m_bActiveHarpoon && m_hHarpoon.Get() )
{
// If the harpoon's impaled something, pull it towards me
CBaseEntity *pTarget = m_hHarpoon->GetImpaledTarget();
if ( pTarget )
{
if ( !pTarget->IsBSPModel() && pTarget->GetMoveType() != MOVETYPE_NONE )
{
// Bring him to me!
EmitSound( "Harpoon.Yank" );
// Get a yank vector, and raise it a little to get them off the ground if they're on it
Vector vecOverHere = ( pPlayer->GetAbsOrigin() - pTarget->GetAbsOrigin() );
VectorNormalize( vecOverHere );
if ( pTarget->GetFlags() & FL_ONGROUND )
{
pTarget->SetGroundEntity( NULL );
vecOverHere.z = 0.5;
}
pTarget->ApplyAbsVelocityImpulse( vecOverHere * 500 );
PlayAttackAnimation( ACT_VM_HAULBACK );
}
}
m_hHarpoon->SetThink( SUB_Remove );
m_hHarpoon->SetNextThink( gpGlobals->curtime + 5.0 );
m_hHarpoon = NULL;
m_bActiveHarpoon = false;
}
DetachRope();
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponHarpoon::DetachRope( void )
{
#if !defined( CLIENT_DLL )
if ( m_hRope )
{
m_hRope->DetachPoint(1);
m_hRope->DieAtNextRest();
m_hRope = NULL;
}
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CHarpoon *CWeaponHarpoon::CreateHarpoon( const Vector &vecOrigin, const Vector &vecAngles, CBasePlayer *pOwner )
{
#if !defined( CLIENT_DLL )
CHarpoon *pHarpoon = CHarpoon::Create(vecOrigin, vecAngles, pOwner );
if ( pHarpoon )
{
// Create the rope on first throw. Otherwise attach our existing rope.
if ( !m_hRope )
{
CRopeKeyframe *pRope = CRopeKeyframe::Create( pHarpoon, pOwner, 0, 0 );
if ( pRope )
{
pRope->m_RopeLength = 1.0;
pRope->m_Slack = 50.0f;
pRope->m_Width = 2;
pRope->m_nSegments = ROPE_MAX_SEGMENTS;
pRope->m_RopeFlags |= ROPE_RESIZE | ROPE_COLLIDE;
}
m_hRope = pRope;
pHarpoon->SetRope( m_hRope );
}
else
{
m_hRope->SetEndPoint( pHarpoon, 0 );
pHarpoon->SetRope( m_hRope );
m_hRope = NULL;
}
// Do we already have a harpoon out?
CHarpoon *pOldHarpoon = m_hHarpoon;
m_hHarpoon = pHarpoon;
if ( pOldHarpoon )
{
pOldHarpoon->SetLinkedHarpoon( m_hHarpoon );
pHarpoon->SetLinkedHarpoon( pOldHarpoon );
m_hHarpoon = NULL;
}
}
return pHarpoon;
#else
return NULL;
#endif
}
|