bool CWeaponShotgun::Reload() { CSDKPlayer *pPlayer = GetPlayerOwner(); if (pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0 || m_iClip1 == GetMaxClip1()) return true; // don't reload until recoil is done if (m_flNextPrimaryAttack > gpGlobals->curtime) return true; // check to see if we're ready to reload if (m_fInSpecialReload == 0) { pPlayer->SetAnimation( PLAYER_RELOAD ); SendWeaponAnim( ACT_SHOTGUN_RELOAD_START ); m_fInSpecialReload = 1; pPlayer->m_flNextAttack = gpGlobals->curtime + 0.5; m_flNextPrimaryAttack = gpGlobals->curtime + 0.5; m_flNextSecondaryAttack = gpGlobals->curtime + 0.5; SetWeaponIdleTime( gpGlobals->curtime + 0.5 ); return true; } else if (m_fInSpecialReload == 1) { if (m_flTimeWeaponIdle > gpGlobals->curtime) return true; // was waiting for gun to move to side m_fInSpecialReload = 2; SendWeaponAnim( ACT_VM_RELOAD ); SetWeaponIdleTime( gpGlobals->curtime + 0.45 ); } else { // Add them to the clip m_iClip1 += 1; #ifdef GAME_DLL SendReloadEvents(); #endif CSDKPlayer *pPlayer = GetPlayerOwner(); if ( pPlayer ) pPlayer->RemoveAmmo( 1, m_iPrimaryAmmoType ); m_fInSpecialReload = 1; } return true; }
bool CASW_Weapon::ASWReload( int iClipSize1, int iClipSize2, int iActivity ) { if ( m_bInReload ) // we're already reloading! { Msg("ASWReload already reloading\n"); Assert(false); return true; } CASW_Marine *pMarine = GetMarine(); if ( !pMarine || !ASWGameRules() ) return false; bool bReload = false; if ( m_bIsFiring ) { OnStoppedFiring(); } // 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, pMarine->GetAmmoCount( m_iPrimaryAmmoType ) ); if ( primary != 0 ) { bReload = true; } else { // check if we have an ammo bag we can take a clip from instead CASW_Weapon_Ammo_Bag* pAmmoBag = dynamic_cast<CASW_Weapon_Ammo_Bag*>( pMarine->GetASWWeapon( 0 ) ); if ( !pAmmoBag ) { pAmmoBag = dynamic_cast<CASW_Weapon_Ammo_Bag*>( pMarine->GetASWWeapon( 1 ) ); } if ( pAmmoBag && pAmmoBag->CanGiveAmmoToWeapon( this ) ) { #ifdef CLIENT_DLL bReload = true; #else pAmmoBag->GiveClipTo(pMarine, m_iPrimaryAmmoType, true); // now we've given a clip, check if we can reload primary = MIN(iClipSize1 - m_iClip1, pMarine->GetAmmoCount(m_iPrimaryAmmoType)); if ( primary != 0 ) { bReload = true; } #endif } } } if ( UsesClipsForAmmo2() ) { // need to reload secondary clip? int secondary = MIN( iClipSize2 - m_iClip2, pMarine->GetAmmoCount( m_iSecondaryAmmoType ) ); if ( secondary != 0 ) { bReload = true; } } if ( !bReload ) return false; m_bFastReloadSuccess = false; m_bFastReloadFailure = false; #ifndef CLIENT_DLL if ( GetMaxClip1() > 1 ) { // Fire event when a player reloads a weapon with more than a bullet per clip IGameEvent * event = gameeventmanager->CreateEvent( "weapon_reload" ); if ( event ) { CASW_Player *pPlayer = NULL; pPlayer = pMarine->GetCommander(); int nClipSize = GetMaxClip1(); int nClips = pMarine->GetAmmoCount( m_iPrimaryAmmoType ) / nClipSize; CASW_Weapon_Ammo_Bag *pAmmoBag = dynamic_cast< CASW_Weapon_Ammo_Bag* >( pMarine->GetASWWeapon( 0 ) ); if ( !pAmmoBag ) { pAmmoBag = dynamic_cast< CASW_Weapon_Ammo_Bag* >( pMarine->GetASWWeapon( 1 ) ); } if ( pAmmoBag && this != pAmmoBag ) { nClips += pAmmoBag->NumClipsForWeapon( this ); } event->SetInt( "userid", ( pPlayer ? pPlayer->GetUserID() : 0 ) ); event->SetInt( "marine", pMarine->entindex() ); event->SetInt( "lost", m_iClip1 ); event->SetInt( "clipsize", nClipSize ); event->SetInt( "clipsremaining", nClips - 1 ); event->SetInt( "clipsmax", GetAmmoDef()->MaxCarry( m_iPrimaryAmmoType, pMarine ) / nClipSize ); gameeventmanager->FireEvent( event ); } } #endif m_fReloadClearFiringTime = gpGlobals->curtime + GetFireRate(); float fReloadTime = GetReloadTime(); float flSequenceEndTime = gpGlobals->curtime + fReloadTime; pMarine->SetNextAttack( flSequenceEndTime ); m_flNextPrimaryAttack = m_flNextSecondaryAttack = flSequenceEndTime; //Msg(" Setting nextprimary attack time to %f from aswreload\n", m_flNextPrimaryAttack); m_bInReload = true; // set fast reload timings // assuming 2.8 base reload time // ~0.29 RandomSeed( CBaseEntity::GetPredictionRandomSeed() & 255 ); float flStartFraction = random->RandomFloat( 0.29f, 0.35f ); // set width by difficulty float flFastReloadWidth = 0.12f; switch( ASWGameRules()->GetSkillLevel() ) { default: case 1: case 2: flFastReloadWidth = random->RandomFloat( 0.10f, 0.1f ); break; // easy/normal case 3: flFastReloadWidth = random->RandomFloat( 0.08f, 0.12f ); break; // hard case 4: flFastReloadWidth = random->RandomFloat( 0.06f, 0.10f ); break; // insane case 5: flFastReloadWidth = random->RandomFloat( 0.055f, 0.09f ); break; // imba } // scale by marine skills flFastReloadWidth *= MarineSkills()->GetSkillBasedValueByMarine( pMarine, ASW_MARINE_SKILL_RELOADING, ASW_MARINE_SUBSKILL_RELOADING_FAST_WIDTH_SCALE ); m_fReloadStart = gpGlobals->curtime; m_fFastReloadStart = gpGlobals->curtime + flStartFraction * fReloadTime; m_fFastReloadEnd = m_fFastReloadStart + flFastReloadWidth * fReloadTime; SendReloadEvents(); #ifdef GAME_DLL pMarine->RemoveWeaponPowerup( this ); #endif return true; }