//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFHunterRifle::ItemPostFrame( void ) { // If we're lowered, we're not allowed to fire if ( m_bLowered ) return; // Get the owning player. CTFPlayer *pPlayer = ToTFPlayer( GetOwner() ); if ( !pPlayer ) return; CheckReload(); if ( !CanAttack() ) { if ( IsZoomed() ) { ToggleZoom(); } return; } HandleZooms(); if ( m_flNextSecondaryAttack <= gpGlobals->curtime ) { // Don't start charging in the time just after a shot before we unzoom to play rack anim. if ( pPlayer->m_Shared.InCond( TF_COND_AIMING ) && !m_bRezoomAfterShot ) { m_flChargedSpread = max(m_flChargedSpread - gpGlobals->frametime * TF_WEAPON_HUNTERRIFLE_CHARGE_PER_SEC, TF_WEAPON_HUNTERRIFLE_SPREAD_MIN); } else { m_flChargedSpread = min(TF_WEAPON_HUNTERRIFLE_SPREAD_MAX, m_flChargedSpread + gpGlobals->frametime * TF_WEAPON_HUNTERRIFLE_UNCHARGE_PER_SEC); } } // Fire. if ( pPlayer->m_nButtons & IN_ATTACK ) { Fire( pPlayer ); } // Reload pressed / Clip Empty if ( ( pPlayer->m_nButtons & IN_RELOAD ) && !m_bInReload ) { // reload when reload is pressed, or if no buttons are down and weapon is empty. Reload(); } // Idle. if ( !( ( pPlayer->m_nButtons & IN_ATTACK) || ( pPlayer->m_nButtons & IN_ATTACK2 ) ) ) { // No fire buttons down or reloading if ( !ReloadOrSwitchWeapons() && ( m_bInReload == false ) ) { WeaponIdle(); } } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFFlameThrower::ItemPostFrame() { if ( m_bLowered ) return; // Get the player owning the weapon. CTFPlayer *pOwner = ToTFPlayer( GetPlayerOwner() ); if ( !pOwner ) return; int iAmmo = pOwner->GetAmmoCount( m_iPrimaryAmmoType ); bool bFired = false; if ( ( pOwner->m_nButtons & IN_ATTACK2 ) && m_flNextSecondaryAttack <= gpGlobals->curtime ) { float flAmmoPerSecondaryAttack = TF_FLAMETHROWER_AMMO_PER_SECONDARY_ATTACK; CALL_ATTRIB_HOOK_FLOAT( flAmmoPerSecondaryAttack, mult_airblast_cost ); if ( iAmmo >= flAmmoPerSecondaryAttack ) { SecondaryAttack(); bFired = true; } } else if ( ( pOwner->m_nButtons & IN_ATTACK ) && iAmmo > 0 && m_iWeaponState != FT_STATE_AIRBLASTING ) { PrimaryAttack(); bFired = true; } if ( !bFired ) { if ( m_iWeaponState > FT_STATE_IDLE ) { SendWeaponAnim( ACT_MP_ATTACK_STAND_POSTFIRE ); pOwner->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_POST ); m_iWeaponState = FT_STATE_IDLE; m_bCritFire = false; m_bHitTarget = false; } if ( !ReloadOrSwitchWeapons() ) { WeaponIdle(); } } //BaseClass::ItemPostFrame(); }
// simplified version of the one in CASW_Weapon, don't worry about ammo or clips for the welder void CASW_Weapon_Welder::BaseItemPostFrame() { //CBasePlayer *pOwner = GetCommander(); CASW_Marine* pOwner = GetMarine(); if (!pOwner) return; bool bAttack1, bAttack2, bReload, bOldReload, bOldAttack1; GetButtons(bAttack1, bAttack2, bReload, bOldReload, bOldAttack1 ); // check for automatic welding if ( m_bShotDelayed ) { if ( m_iAutomaticWeldDirection > 0 ) { bAttack1 = true; //Msg( "doing automatic attack1 since bShotDelayed\n" ); } else if ( m_iAutomaticWeldDirection < 0 ) { bAttack2 = true; //Msg( "doing automatic attack2 since bShotDelayed\n" ); } } //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 ( UsesClipsForAmmo1() ) { CheckReload(); } bool bFired = false; if ( bAttack2 && m_flNextSecondaryAttack <= gpGlobals->curtime ) { bFired = true; SecondaryAttack(); } if ( !bFired && bAttack1 && m_flNextPrimaryAttack <= gpGlobals->curtime ) { // If the firing button was just pressed, reset the firing time if ( pOwner && bAttack1 ) { m_flNextPrimaryAttack = gpGlobals->curtime; } PrimaryAttack(); } if ( !bAttack1 && !bAttack2 ) m_bIsFiring = false; // ----------------------- // No buttons down // ----------------------- if (!(bAttack1 || bAttack2 || bReload)) { // no fire buttons down or reloading if ( !ReloadOrSwitchWeapons() && !m_bInReload ) { WeaponIdle(); } } }
// 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(); } } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFSniperRifle::ItemPostFrame( void ) { // If we're lowered, we're not allowed to fire if ( m_bLowered ) return; // Get the owning player. CTFPlayer *pPlayer = ToTFPlayer( GetOwner() ); if ( !pPlayer ) return; if ( !CanAttack() ) { if ( IsZoomed() ) { ToggleZoom(); } return; } HandleZooms(); #ifdef GAME_DLL // Update the sniper dot position if we have one if ( m_hSniperDot ) { UpdateSniperDot(); } #endif // Start charging when we're zoomed in, and allowed to fire if ( pPlayer->m_Shared.IsJumping() ) { // Unzoom if we're jumping if ( IsZoomed() ) { ToggleZoom(); } m_flChargedDamage = 0.0f; m_bRezoomAfterShot = false; } else if ( m_flNextSecondaryAttack <= gpGlobals->curtime ) { // Don't start charging in the time just after a shot before we unzoom to play rack anim. if ( pPlayer->m_Shared.InCond( TF_COND_AIMING ) && !m_bRezoomAfterShot ) { m_flChargedDamage = min( m_flChargedDamage + gpGlobals->frametime * TF_WEAPON_SNIPERRIFLE_CHARGE_PER_SEC, TF_WEAPON_SNIPERRIFLE_DAMAGE_MAX ); } else { m_flChargedDamage = max( 0, m_flChargedDamage - gpGlobals->frametime * TF_WEAPON_SNIPERRIFLE_UNCHARGE_PER_SEC ); } } // Fire. if ( pPlayer->m_nButtons & IN_ATTACK ) { Fire( pPlayer ); } // Idle. if ( !( ( pPlayer->m_nButtons & IN_ATTACK) || ( pPlayer->m_nButtons & IN_ATTACK2 ) ) ) { // No fire buttons down or reloading if ( !ReloadOrSwitchWeapons() && ( m_bInReload == false ) ) { WeaponIdle(); } } }