void CASW_Weapon::ApplyWeaponSwitchTime() { // play weaponswitch sound if (ASWGameRules() && ASWGameRules()->GetGameState() >= ASW_GS_INGAME) { WeaponSound(SPECIAL3); } float flSequenceEndTime = gpGlobals->curtime + ASW_WEAPON_SWITCH_TIME; CBaseCombatCharacter *pOwner = GetOwner(); if (pOwner) pOwner->SetNextAttack( flSequenceEndTime ); m_flNextPrimaryAttack = m_flNextSecondaryAttack = flSequenceEndTime; m_bSwitchingWeapons = true; }
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 }
bool CWeaponDODBase::DefaultReload( int iClipSize1, int iClipSize2, int iActivity ) { CBaseCombatCharacter *pOwner = GetOwner(); if (!pOwner) return false; // If I don't have any spare ammo, I can't reload if ( pOwner->GetAmmoCount(m_iPrimaryAmmoType) <= 0 ) return false; bool bReload = false; // If you don't have clips, then don't try to reload them. if ( UsesClipsForAmmo1() ) { // need to reload primary clip? int primary = min(iClipSize1 - m_iClip1, pOwner->GetAmmoCount(m_iPrimaryAmmoType)); if ( primary != 0 ) { bReload = true; } } if ( UsesClipsForAmmo2() ) { // need to reload secondary clip? int secondary = min(iClipSize2 - m_iClip2, pOwner->GetAmmoCount(m_iSecondaryAmmoType)); if ( secondary != 0 ) { bReload = true; } } if ( !bReload ) return false; CDODPlayer *pPlayer = GetDODPlayerOwner(); if ( pPlayer ) { #ifdef CLIENT_DLL PlayWorldReloadSound( pPlayer ); #else pPlayer->DoAnimationEvent( PLAYERANIMEVENT_RELOAD ); #endif } SendWeaponAnim( iActivity ); // Play the player's reload animation if ( pOwner->IsPlayer() ) { ( ( CBasePlayer * )pOwner)->SetAnimation( PLAYER_RELOAD ); } float flSequenceEndTime = gpGlobals->curtime + SequenceDuration(); pOwner->SetNextAttack( flSequenceEndTime ); m_flNextPrimaryAttack = m_flNextSecondaryAttack = flSequenceEndTime; m_bInReload = true; return true; }