2828IMPLEMENT_SERVERCLASS_ST ( CBaseHLBludgeonWeapon, DT_BaseHLBludgeonWeapon )
2929END_SEND_TABLE()
3030
31+ #ifdef MAPBASE
32+ BEGIN_DATADESC (CBaseHLBludgeonWeapon)
33+
34+ DEFINE_FIELD(m_flDelayedFire, FIELD_TIME),
35+ DEFINE_FIELD(m_bShotDelayed, FIELD_BOOLEAN),
36+
37+ END_DATADESC()
38+ #endif // MAPBASE
39+
3140#define BLUDGEON_HULL_DIM 16
3241
3342static const Vector g_bludgeonMins (-BLUDGEON_HULL_DIM,-BLUDGEON_HULL_DIM,-BLUDGEON_HULL_DIM);
@@ -39,6 +48,9 @@ static const Vector g_bludgeonMaxs(BLUDGEON_HULL_DIM,BLUDGEON_HULL_DIM,BLUDGEON_
3948CBaseHLBludgeonWeapon::CBaseHLBludgeonWeapon ()
4049{
4150 m_bFiresUnderwater = true ;
51+ #ifdef MAPBASE
52+ m_bShotDelayed = false ;
53+ #endif // MAPBASE
4254}
4355
4456// -----------------------------------------------------------------------------
@@ -96,11 +108,19 @@ void CBaseHLBludgeonWeapon::ItemPostFrame( void )
96108#ifdef MAPBASE
97109 if (pOwner->HasSpawnFlags ( SF_PLAYER_SUPPRESS_FIRING ))
98110 {
111+ m_bShotDelayed = false ;
99112 WeaponIdle ();
100113 return ;
101114 }
102- #endif
103115
116+ // See if we need to fire off our secondary round
117+ if (m_bShotDelayed)
118+ {
119+ if (gpGlobals->curtime > m_flDelayedFire)
120+ DelayedAttack ();
121+ }
122+ else
123+ #endif
104124 if ( (pOwner->m_nButtons & IN_ATTACK) && (m_flNextPrimaryAttack <= gpGlobals->curtime ) )
105125 {
106126 PrimaryAttack ();
@@ -162,7 +182,12 @@ void CBaseHLBludgeonWeapon::Hit( trace_t &traceHit, Activity nHitActivity, bool
162182 pPlayer->EyeVectors ( &hitDirection, NULL , NULL );
163183 VectorNormalize ( hitDirection );
164184
165- CTakeDamageInfo info ( GetOwner (), GetOwner (), GetDamageForActivity ( nHitActivity ), DMG_CLUB );
185+ #ifdef MAPBASE
186+ CTakeDamageInfo info (GetOwner (), GetOwner (), GetDamageForActivity (nHitActivity), GetDamageType ());
187+ #else
188+ CTakeDamageInfo info (GetOwner (), GetOwner (), GetDamageForActivity (nHitActivity), DMG_CLUB);
189+ #endif // MAPBASE
190+
166191
167192 if ( pPlayer && pHitEntity->IsNPC () )
168193 {
@@ -234,7 +259,7 @@ Activity CBaseHLBludgeonWeapon::ChooseIntersectionPointAndActivity( trace_t &hit
234259 }
235260
236261
237- return ACT_VM_HITCENTER ;
262+ return GetPrimaryAttackActivity () ;
238263}
239264
240265// -----------------------------------------------------------------------------
@@ -292,7 +317,6 @@ void CBaseHLBludgeonWeapon::ImpactEffect( trace_t &traceHit )
292317 UTIL_ImpactTrace ( &traceHit, DMG_CLUB );
293318}
294319
295-
296320// ------------------------------------------------------------------------------
297321// Purpose : Starts the swing of the weapon and determines the animation
298322// Input : bIsSecondary - is this a secondary attack?
@@ -315,10 +339,14 @@ void CBaseHLBludgeonWeapon::Swing( int bIsSecondary )
315339
316340 Vector swingEnd = swingStart + forward * GetRange ();
317341 UTIL_TraceLine ( swingStart, swingEnd, MASK_SHOT_HULL, pOwner, COLLISION_GROUP_NONE, &traceHit );
318- Activity nHitActivity = ACT_VM_HITCENTER ;
342+ Activity nHitActivity = GetPrimaryAttackActivity () ;
319343
320344 // Like bullets, bludgeon traces have to trace against triggers.
321- CTakeDamageInfo triggerInfo ( GetOwner (), GetOwner (), GetDamageForActivity ( nHitActivity ), DMG_CLUB );
345+ #ifdef MAPBASE
346+ CTakeDamageInfo triggerInfo (GetOwner (), GetOwner (), GetDamageForActivity (nHitActivity), GetDamageType ());
347+ #else
348+ CTakeDamageInfo triggerInfo (GetOwner (), GetOwner (), GetDamageForActivity (nHitActivity), DMG_CLUB);
349+ #endif // MAPBASE
322350 triggerInfo.SetDamagePosition ( traceHit.startpos );
323351 triggerInfo.SetDamageForce ( forward );
324352 TraceAttackToTriggers ( triggerInfo, traceHit.startpos , traceHit.endpos , forward );
@@ -369,31 +397,20 @@ void CBaseHLBludgeonWeapon::Swing( int bIsSecondary )
369397 {
370398 nHitActivity = bIsSecondary ? ACT_VM_MISSCENTER2 : ACT_VM_MISSCENTER;
371399
400+ #ifndef MAPBASE
372401 // We want to test the first swing again
373402 Vector testEnd = swingStart + forward * GetRange ();
374403
375- #ifdef MAPBASE
376- // Sound has been moved here since we're using the other melee sounds now
377- WeaponSound ( SINGLE );
378- #endif
379-
380404 // See if we happened to hit water
381- ImpactWater ( swingStart, testEnd );
405+ ImpactWater (swingStart, testEnd);
406+ #endif // !MAPBASE
382407 }
408+ #ifndef MAPBASE
383409 else
384410 {
385- #ifdef MAPBASE
386- // Other melee sounds
387- if (traceHit.m_pEnt && traceHit.m_pEnt ->IsWorld ())
388- WeaponSound (MELEE_HIT_WORLD);
389- else if (traceHit.m_pEnt && !traceHit.m_pEnt ->PassesDamageFilter (triggerInfo))
390- WeaponSound (MELEE_MISS);
391- else
392- WeaponSound (MELEE_HIT);
393- #endif
394-
395411 Hit ( traceHit, nHitActivity, bIsSecondary ? true : false );
396412 }
413+ #endif
397414
398415 // Send the anim
399416 SendWeaponAnim ( nHitActivity );
@@ -409,5 +426,125 @@ void CBaseHLBludgeonWeapon::Swing( int bIsSecondary )
409426
410427#ifdef MAPBASE
411428 pOwner->SetAnimation ( PLAYER_ATTACK1 );
429+
430+ if (GetHitDelay () > 0 .f )
431+ {
432+ // Play swing sound
433+ WeaponSound (SINGLE);
434+
435+ m_flDelayedFire = gpGlobals->curtime + GetHitDelay ();
436+ m_bShotDelayed = true ;
437+ }
438+ else
439+ {
440+ if (traceHit.fraction == 1 .0f )
441+ {
442+ // We want to test the first swing again
443+ Vector testEnd = swingStart + forward * GetRange ();
444+
445+ // Play swing sound
446+ WeaponSound (SINGLE);
447+
448+ // See if we happened to hit water
449+ ImpactWater (swingStart, testEnd);
450+ }
451+ else
452+ {
453+ // Other melee sounds
454+ if (traceHit.m_pEnt && traceHit.m_pEnt ->IsWorld ())
455+ WeaponSound (MELEE_HIT_WORLD);
456+ else if (traceHit.m_pEnt && !traceHit.m_pEnt ->PassesDamageFilter (triggerInfo))
457+ WeaponSound (MELEE_MISS);
458+ else
459+ WeaponSound (MELEE_HIT);
460+
461+ Hit (traceHit, nHitActivity, bIsSecondary ? true : false );
462+ }
463+ }
412464#endif
413465}
466+
467+ #ifdef MAPBASE
468+ void CBaseHLBludgeonWeapon::DelayedAttack (void )
469+ {
470+ m_bShotDelayed = false ;
471+
472+ trace_t traceHit;
473+
474+ // Try a ray
475+ CBasePlayer* pOwner = ToBasePlayer (GetOwner ());
476+ if (!pOwner)
477+ return ;
478+
479+ pOwner->RumbleEffect (RUMBLE_CROWBAR_SWING, 0 , RUMBLE_FLAG_RESTART);
480+
481+ Vector swingStart = pOwner->Weapon_ShootPosition ();
482+ Vector forward;
483+
484+ forward = pOwner->GetAutoaimVector (AUTOAIM_SCALE_DEFAULT, GetRange ());
485+
486+ Vector swingEnd = swingStart + forward * GetRange ();
487+ UTIL_TraceLine (swingStart, swingEnd, MASK_SHOT_HULL, pOwner, COLLISION_GROUP_NONE, &traceHit);
488+
489+ if (traceHit.fraction == 1.0 )
490+ {
491+ float bludgeonHullRadius = 1 .732f * BLUDGEON_HULL_DIM; // hull is +/- 16, so use cuberoot of 2 to determine how big the hull is from center to the corner point
492+
493+ // Back off by hull "radius"
494+ swingEnd -= forward * bludgeonHullRadius;
495+
496+ UTIL_TraceHull (swingStart, swingEnd, g_bludgeonMins, g_bludgeonMaxs, MASK_SHOT_HULL, pOwner, COLLISION_GROUP_NONE, &traceHit);
497+ if (traceHit.fraction < 1.0 && traceHit.m_pEnt )
498+ {
499+ Vector vecToTarget = traceHit.m_pEnt ->GetAbsOrigin () - swingStart;
500+ VectorNormalize (vecToTarget);
501+
502+ float dot = vecToTarget.Dot (forward);
503+
504+ // YWB: Make sure they are sort of facing the guy at least...
505+ if (dot < 0 .70721f )
506+ {
507+ // Force amiss
508+ traceHit.fraction = 1 .0f ;
509+ }
510+ else
511+ {
512+ ChooseIntersectionPointAndActivity (traceHit, g_bludgeonMins, g_bludgeonMaxs, pOwner);
513+ }
514+ }
515+ }
516+
517+ if (traceHit.fraction == 1 .0f )
518+ {
519+ // We want to test the first swing again
520+ Vector testEnd = swingStart + forward * GetRange ();
521+
522+ // See if we happened to hit water
523+ ImpactWater (swingStart, testEnd);
524+ }
525+ else
526+ {
527+ CTakeDamageInfo triggerInfo (GetOwner (), GetOwner (), GetDamageForActivity (GetActivity ()), GetDamageType ());
528+ triggerInfo.SetDamagePosition (traceHit.startpos );
529+ triggerInfo.SetDamageForce (forward);
530+
531+ // Other melee sounds
532+ if (traceHit.m_pEnt && traceHit.m_pEnt ->IsWorld ())
533+ WeaponSound (MELEE_HIT_WORLD);
534+ else if (traceHit.m_pEnt && !traceHit.m_pEnt ->PassesDamageFilter (triggerInfo))
535+ WeaponSound (MELEE_MISS);
536+ else
537+ WeaponSound (MELEE_HIT);
538+
539+ Hit (traceHit, GetActivity (), false );
540+ }
541+ }
542+
543+ bool CBaseHLBludgeonWeapon::CanHolster (void )
544+ {
545+ if (m_bShotDelayed)
546+ return false ;
547+
548+ return BaseClass::CanHolster ();
549+ }
550+ #endif // MAPBASE
0 commit comments