//----------------------------------------------------------------------------- int CHLSelectFireMachineGun::WeaponRangeAttack2Condition( float flDot, float flDist ) { return COND_NONE; // FIXME: disabled for now // m_iClip2 == -1 when no secondary clip is used if ( m_iClip2 == 0 && UsesSecondaryAmmo() ) { return COND_NO_SECONDARY_AMMO; } else if ( flDist < m_fMinRange2 ) { // Don't return COND_TOO_CLOSE_TO_ATTACK only for primary attack return COND_NONE; } else if (flDist > m_fMaxRange2 ) { // Don't return COND_TOO_FAR_TO_ATTACK only for primary attack return COND_NONE; } else if ( flDot < 0.5 ) // UNDONE: Why check this here? Isn't the AI checking this already? { return COND_NOT_FACING_ATTACK; } return COND_CAN_RANGE_ATTACK2; }
// check player or marine commander's buttons for firing/reload/etc void CASW_Weapon::ItemPostFrame( void ) { //CBasePlayer *pOwner = GetCommander(); CASW_Marine* pOwner = GetMarine(); if (!pOwner) return; bool bThisActive = ( pOwner && pOwner->GetActiveWeapon() == this ); bool bAttack1, bAttack2, bReload, bOldReload, bOldAttack1; GetButtons(bAttack1, bAttack2, bReload, bOldReload, bOldAttack1 ); if ( pOwner->IsHacking() ) { bThisActive = bAttack1 = bAttack2 = bReload = false; } // check for clearing our weapon switching bool if (m_bSwitchingWeapons && gpGlobals->curtime > m_flNextPrimaryAttack) { m_bSwitchingWeapons = false; } // check for clearing our firing bool from reloading if (m_bInReload && gpGlobals->curtime > m_fReloadClearFiringTime) { ClearIsFiring(); } if ( m_bShotDelayed && gpGlobals->curtime > m_flDelayedFire ) { DelayedAttack(); } if ( UsesClipsForAmmo1() ) { CheckReload(); } bool bFired = false; if ( bThisActive ) { //Track the duration of the fire //FIXME: Check for IN_ATTACK2 as well? //FIXME: What if we're calling ItemBusyFrame? m_fFireDuration = bAttack1 ? ( m_fFireDuration + gpGlobals->frametime ) : 0.0f; if (bAttack2 && (m_flNextSecondaryAttack <= gpGlobals->curtime) && gpGlobals->curtime > pOwner->m_fFFGuardTime) { if ( SecondaryAttackUsesPrimaryAmmo() ) { if ( !IsMeleeWeapon() && (( UsesClipsForAmmo1() && !(this->PrimaryAmmoLoaded())) || ( !UsesClipsForAmmo1() && pOwner->GetAmmoCount(m_iPrimaryAmmoType)<=0 )) ) { HandleFireOnEmpty(); } else { bFired = true; SecondaryAttack(); #ifndef CLIENT_DLL if ( pOwner->IsInhabited() ) { IGameEvent * event = gameeventmanager->CreateEvent( "player_alt_fire" ); if ( event ) { CASW_Player *pPlayer = pOwner->GetCommander(); event->SetInt( "userid", ( pPlayer ? pPlayer->GetUserID() : 0 ) ); gameeventmanager->FireEvent( event ); } } #endif } } else if ( UsesSecondaryAmmo() && ( ( UsesClipsForAmmo2() && m_iClip2 <= 0 ) || ( !UsesClipsForAmmo2() && pOwner->GetAmmoCount( m_iSecondaryAmmoType ) <= 0 ) ) ) { if ( m_flNextEmptySoundTime < gpGlobals->curtime ) { WeaponSound( EMPTY ); m_flNextSecondaryAttack = m_flNextEmptySoundTime = gpGlobals->curtime + 0.5; } } else { bFired = true; SecondaryAttack(); #ifndef CLIENT_DLL if ( pOwner->IsInhabited() ) { IGameEvent * event = gameeventmanager->CreateEvent( "player_alt_fire" ); if ( event ) { CASW_Player *pPlayer = pOwner->GetCommander(); event->SetInt( "userid", ( pPlayer ? pPlayer->GetUserID() : 0 ) ); gameeventmanager->FireEvent( event ); } } #endif // Secondary ammo doesn't have a reload animation // this code makes secondary ammo come from nowhere! /* if ( UsesClipsForAmmo2() ) { // reload clip2 if empty if (m_iClip2 < 1) { pOwner->RemoveAmmo( 1, m_iSecondaryAmmoType ); m_iClip2 = m_iClip2 + 1; } }*/ } } if ( !bFired && bAttack1 && (m_flNextPrimaryAttack <= gpGlobals->curtime) && gpGlobals->curtime > pOwner->m_fFFGuardTime) { // Clip empty? Or out of ammo on a no-clip weapon? if ( !IsMeleeWeapon() && (( UsesClipsForAmmo1() && !(this->PrimaryAmmoLoaded())) || ( !UsesClipsForAmmo1() && pOwner->GetAmmoCount(m_iPrimaryAmmoType)<=0 )) ) { HandleFireOnEmpty(); } else if (pOwner->GetWaterLevel() == 3 && m_bFiresUnderwater == false) { // This weapon doesn't fire underwater WeaponSound(EMPTY); m_flNextPrimaryAttack = gpGlobals->curtime + 0.2; return; } else { //NOTENOTE: There is a bug with this code with regards to the way machine guns catch the leading edge trigger // on the player hitting the attack key. It relies on the gun catching that case in the same frame. // However, because the player can also be doing a secondary attack, the edge trigger may be missed. // We really need to hold onto the edge trigger and only clear the condition when the gun has fired its // first shot. Right now that's too much of an architecture change -- jdw // If the firing button was just pressed, reset the firing time if ( pOwner && bAttack1 ) { #ifdef CLIENT_DLL //Msg("[Client] setting nextprimaryattack to now %f\n", gpGlobals->curtime); #else //Msg("[Server] setting nextprimaryattack to now %f\n", gpGlobals->curtime); #endif m_flNextPrimaryAttack = gpGlobals->curtime; } PrimaryAttack(); } } } if (!bAttack1) // clear our firing var if we don't have the attack button held down (not totally accurate since firing could continue for some time after pulling the trigger, but it's good enough for our purposes) { m_bIsFiring = false; // NOTE: Only want to clear primary fire IsFiring bool here (i.e. don't call ClearIsFiring as that'll clear secondary fire too, in subclasses that have it) if ( bOldAttack1 ) { OnStoppedFiring(); } } // ----------------------- // Reload pressed / Clip Empty // ----------------------- if ( bReload && UsesClipsForAmmo1()) { if ( m_bInReload ) { // todo: check for a fast reload //Msg("Check for fast reload\n"); } else { // reload when reload is pressed, or if no buttons are down and weapon is empty. Reload(); m_fFireDuration = 0.0f; } } // ----------------------- // No buttons down // ----------------------- if (!(bAttack1 || bAttack2 || bReload)) { // no fire buttons down or reloading if ( !ReloadOrSwitchWeapons() && ( m_bInReload == false ) ) { WeaponIdle(); } } }
void CASW_Weapon_Assault_Shotgun::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; //Must have ammo 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; } BaseClass::WeaponSound( SPECIAL1 ); #ifndef CLIENT_DLL pMarine->GetMarineSpeech()->Chatter(CHATTER_GRENADE); Vector vecSrc = pMarine->Weapon_ShootPosition(); Vector vecThrow; // check for turning on lag compensation if (pPlayer && pMarine->IsInhabited()) { CASW_Lag_Compensation::RequestLagCompensation( pPlayer, pPlayer->GetCurrentUserCommand() ); } vecThrow = UTIL_LaunchVector(vecSrc, pPlayer->GetCrosshairTracePos(), asw_vindicator_grenade_gravity.GetFloat()) * 8.0f * asw_vindicator_grenade_velocity.GetFloat(); QAngle angAiming = pPlayer->EyeAnglesWithCursorRoll(); float fGrenadeDamage = MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_GRENADES, ASW_MARINE_SUBSKILL_GRENADE_INCENDIARY_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); } // check the grenade fits where we want to spawn it Ray_t ray; trace_t pm; ray.Init( pMarine->WorldSpaceCenter(), vecSrc, -Vector(4,4,4), Vector(4,4,4) ); UTIL_TraceRay( ray, MASK_SOLID, pMarine, COLLISION_GROUP_PROJECTILE, &pm ); if (pm.fraction < 1.0f) vecSrc = pm.endpos; CASW_Grenade_Vindicator::Vindicator_Grenade_Create( fGrenadeDamage, fGrenadeRadius, vecSrc, angAiming, vecThrow, AngularImpulse(0,0,0), pMarine, this ); pMarine->OnWeaponFired( this, 1, true ); #endif SendWeaponAnim( GetPrimaryAttackActivity() ); pMarine->DoAnimationEvent( PLAYERANIMEVENT_FIRE_GUN_PRIMARY ); // Decrease ammo if ( bUsesClips ) { m_iClip2 -= 1; } else { pMarine->RemoveAmmo( 1, m_iSecondaryAmmoType ); } #ifndef CLIENT_DLL ASWFailAdvice()->OnMarineUsedSecondary(); CEffectData data; data.m_vOrigin = GetAbsOrigin(); //data.m_vNormal = dir; //data.m_flScale = (float)amount; CPASFilter filter( data.m_vOrigin ); filter.SetIgnorePredictionCull(true); DispatchParticleEffect( "muzzleflash_grenadelauncher_main", PATTACH_POINT_FOLLOW, this, "muzzle", false, -1, &filter ); #endif // 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; }