void Weapon::Reload() { SPADES_MARK_FUNCTION(); if(reloading) return; if(ammo == GetClipSize()) return; if(stock == 0) return; reloading = true; shooting = false; reloadStartTime = time; reloadEndTime = time + GetReloadTime(); if(world->GetListener()) world->GetListener()->PlayerReloadingWeapon(owner); }
HS_BOOL8 CHSMTube::Reload() { if (!m_pWeaponData) { return false; } // Check to see if we're reloading. If not, then begin it. if (!m_reloading) { // Are we already loaded? if (m_loaded) { return false; } // Pull a missile from storage .. or try to. if (!m_missile_bay) { return false; } if (!m_missile_bay->GetMissile(m_pWeaponData->TypeID())) { return false; } m_reloading = true; m_time_to_reload = GetReloadTime(); } else { m_time_to_reload--; if (m_time_to_reload <= 0) { m_change = STAT_READY; m_reloading = false; m_loaded = true; } } return true; }
void Weapon::Reload(bool manual) { SPADES_MARK_FUNCTION(); if (reloading) return; if (ammo >= GetClipSize()) return; if (stock == 0) return; if (IsReloadSlow() && ammo > 0 && shooting) return; if (manual) slowReloadLeftCount = stock - std::max(0, stock - GetClipSize() + ammo); reloading = true; shooting = false; reloadStartTime = time; reloadEndTime = time + GetReloadTime(); if (world->GetListener()) world->GetListener()->PlayerReloadingWeapon(owner); }
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; }