bool CASW_Weapon::Holster( CBaseCombatWeapon *pSwitchingTo ) { if ( m_bIsFiring ) { OnStoppedFiring(); } ClearIsFiring(); /* UNDONE: This was causing trouble in the offhand welder. It seems like this was to enforce the grenade toss animation completes, but it's probably better that pressing the offhand key guarantees item use rather than having it misfire because of an rare condition. CASW_Marine* pMarine = dynamic_cast<CASW_Marine*>(GetOwner()); // check if our offhand item is doing an offhand delayed attack, cancel it if so if (pMarine && pMarine->GetASWWeapon(2) && pMarine->GetASWWeapon(2)->m_bShotDelayed) // cancel throwing if we're switching out { pMarine->GetASWWeapon(2)->m_bShotDelayed = false; } */ return BaseClass::Holster( pSwitchingTo ); m_bFastReloadSuccess = false; m_bFastReloadFailure = false; }
void CASW_Weapon_Chainsaw::EndAttack( void ) { if ( m_fireState != FIRE_OFF ) { StartAttackOffSound(); #ifdef CLIENT_DLL DispatchParticleEffect( "mining_laser_exhaust", PATTACH_POINT_FOLLOW, this, "eject1" ); #endif } StopChainsawSound(); SetWeaponIdleTime( gpGlobals->curtime + 2.0 ); m_flNextPrimaryAttack = gpGlobals->curtime + GetWeaponInfo()->m_flFireRate; m_flNextSecondaryAttack = gpGlobals->curtime + GetWeaponInfo()->m_flFireRate; SetFiringState(FIRE_OFF); ClearIsFiring(); DestroyEffect(); }
//----------------------------------------------------------------------------- // Purpose: If the current weapon has more ammo, reload it. Otherwise, switch // to the next best weapon we've got. Returns true if it took any action. //----------------------------------------------------------------------------- bool CASW_Weapon::ReloadOrSwitchWeapons( void ) { CASW_Player *pPlayer = NULL; CASW_Marine *pMarine = NULL; bool bAutoReload = true; pMarine = dynamic_cast<CASW_Marine*>(GetOwner()); if (pMarine) { if (pMarine->GetCommander() && pMarine->IsInhabited()) { pPlayer = pMarine->GetCommander(); bAutoReload = pPlayer->ShouldAutoReload(); } } // if (HasAnyAmmo()) // asw add later! m_bFireOnEmpty = false; if ( UsesClipsForAmmo1() && (m_iClip1 == 0) && (GetWeaponFlags() & ITEM_FLAG_NOAUTORELOAD) == false && bAutoReload && m_flNextPrimaryAttack < gpGlobals->curtime && m_flNextSecondaryAttack < gpGlobals->curtime && !m_bInReload) { // if we're successfully reloading, we're done if ( Reload() ) { return true; } else { ClearIsFiring(); } } return false; }
// 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::ItemBusyFrame( void ) { CASW_Marine* pMarine = GetMarine(); if ( !pMarine ) return; bool bAttack1, bAttack2, bReload, bOldReload, bOldAttack1; GetButtons(bAttack1, bAttack2, bReload, bOldReload, bOldAttack1 ); // 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 ( (bReload && !bOldReload) && UsesClipsForAmmo1() && asw_fast_reload_enabled.GetBool() ) { if ( m_bInReload ) { // check for a fast reload //Msg("%f Check for fast reload while busy\n", gpGlobals->curtime); if (gpGlobals->curtime >= m_fFastReloadStart && gpGlobals->curtime <= m_fFastReloadEnd) { // todo: reduce next attack time m_fFastReloadEnd = 0; m_fFastReloadStart = 0; CBaseCombatCharacter *pOwner = GetOwner(); if ( pOwner ) { float flSucceedDelay = gpGlobals->curtime + 0.5f; pOwner->SetNextAttack( flSucceedDelay ); m_flNextPrimaryAttack = m_flNextSecondaryAttack = flSucceedDelay; } // TODO: hook up anim //pMarine->DoAnimationEvent( PLAYERANIMEVENT_RELOAD_SUCCEED ); DispatchParticleEffect( "fast_reload", PATTACH_POINT_FOLLOW, this, "muzzle" ); pMarine->m_flPreventLaserSightTime = gpGlobals->curtime + 2.5f; #ifdef GAME_DLL pMarine->m_nFastReloadsInARow++; IGameEvent * event = gameeventmanager->CreateEvent( "fast_reload" ); if ( event ) { event->SetInt( "marine", pMarine->entindex() ); event->SetInt( "reloads", pMarine->m_nFastReloadsInARow ); gameeventmanager->FireEvent( event ); } if ( pMarine->m_nFastReloadsInARow >= 4 && pMarine->IsInhabited() ) { if ( pMarine->GetMarineResource() ) { pMarine->GetMarineResource()->m_bDidFastReloadsInARow = true; } if ( pMarine->GetCommander() ) { pMarine->GetCommander()->AwardAchievement( ACHIEVEMENT_ASW_FAST_RELOADS_IN_A_ROW ); } } #endif CSoundParameters params; if ( !GetParametersForSound( "FastReload.Success", params, NULL ) ) return; EmitSound_t playparams(params); playparams.m_nPitch = params.pitch; CASW_Player *pPlayer = GetCommander(); if ( pPlayer ) { CSingleUserRecipientFilter filter( pMarine->GetCommander() ); if ( IsPredicted() && CBaseEntity::GetPredictionPlayer() ) { filter.UsePredictionRules(); } EmitSound(filter, entindex(), playparams); } //Msg("%f RELOAD SUCCESS! - bAttack1 = %d, bOldAttack1 = %d\n", gpGlobals->curtime, bAttack1, bOldAttack1 ); //Msg( "S: %f - %f - %f RELOAD SUCCESS! -- Progress = %f\n", gpGlobals->curtime, fFastStart, fFastEnd, flProgress ); #ifdef GAME_DLL pMarine->GetMarineSpeech()->PersonalChatter(CHATTER_SELECTION); #endif m_bFastReloadSuccess = true; m_bFastReloadFailure = false; } else if (m_fFastReloadStart != 0) { CSoundParameters params; if ( !GetParametersForSound( "FastReload.Miss", params, NULL ) ) return; EmitSound_t playparams(params); playparams.m_nPitch = params.pitch; CASW_Player *pPlayer = GetCommander(); if ( pPlayer ) { CSingleUserRecipientFilter filter( pMarine->GetCommander() ); if ( IsPredicted() && CBaseEntity::GetPredictionPlayer() ) { filter.UsePredictionRules(); } EmitSound(filter, entindex(), playparams); } //Msg("%f RELOAD MISSED! - bAttack1 = %d, bOldAttack1 = %d\n", gpGlobals->curtime, bAttack1, bOldAttack1 ); //Msg( "S: %f - %f - %f RELOAD MISSED! -- Progress = %f\n", gpGlobals->curtime, fFastStart, fFastEnd, flProgress ); m_fFastReloadEnd = 0; m_fFastReloadStart = 0; CBaseCombatCharacter *pOwner = GetOwner(); if ( pOwner ) { float flMissDelay = MAX( gpGlobals->curtime + 2.0f, m_flNextPrimaryAttack + 1.0f ); pOwner->SetNextAttack( flMissDelay ); m_flNextPrimaryAttack = m_flNextSecondaryAttack = flMissDelay; m_flReloadFailTime = m_flNextPrimaryAttack - gpGlobals->curtime; } // TODO: hook up anim //pMarine->DoAnimationEvent( PLAYERANIMEVENT_RELOAD_FAIL ); #ifdef GAME_DLL pMarine->m_nFastReloadsInARow = 0; #endif DispatchParticleEffect( "reload_fail", PATTACH_POINT_FOLLOW, this, "muzzle" ); #ifdef GAME_DLL pMarine->GetMarineSpeech()->PersonalChatter(CHATTER_PAIN_SMALL); #endif m_bFastReloadSuccess = false; m_bFastReloadFailure = true; } } } #ifdef CLIENT_DLL if ( m_bInReload ) { float fStart = m_fReloadStart; float fNext = MAX( m_flNextPrimaryAttack, GetOwner() ? GetOwner()->GetNextAttack() : 0 ); float fTotalTime = fNext - fStart; if (fTotalTime <= 0) fTotalTime = 0.1f; m_fReloadProgress = (gpGlobals->curtime - fStart) / fTotalTime; } else { m_fReloadProgress = 0; } //Msg( "S: %f Reload Progress = %f\n", gpGlobals->curtime, m_fReloadProgress ); #endif //CLIENT_DLL }
void CASW_Weapon::MarineDropped(CASW_Marine* pMarine) { ClearIsFiring(); }