Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CClientWeapon::ChangeAmmoWithReload( uint8 nNewAmmoId, bool bForce /*=false*/ )
- {
- // Update the player's stats...
- if ( ( W_RELOADING == GetState() ) && !bForce )
- {
- return;
- }
- if ( CanChangeToAmmo( nNewAmmoId ) && ( nNewAmmoId != m_nAmmoId ) )
- {
- ASSERT( 0 != g_pWeaponMgr );
- m_nAmmoId = nNewAmmoId;
- m_pAmmo = g_pWeaponMgr->GetAmmo( m_nAmmoId );
- // Make sure we reset the anis (the ammo may override the
- // weapon animations)...
- InitAnimations( true );
- if ( m_pAmmo->pAniOverrides )
- {
- // If we're not using the defaults play the new select ani...
- Select();
- }
- else
- {
- // Do normal reload...
- ReloadClip( true, -1, true, true );
- // Add a message so the user knows he switched ammo (sometimes it
- // isn't that obvious)...
- if (strlen(m_pAmmo->szShortName))
- {
- char szMsg[128];
- FormatString(IDS_CHANGING_AMMO, szMsg, sizeof(szMsg), m_pAmmo->szShortName);
- std::string icon = m_pAmmo->GetNormalIcon();
- g_pPickupMsgs->AddMessage(szMsg, icon.c_str());
- }
- }
- }
- }
- // ----------------------------------------------------------------------- //
- //
- // ROUTINE: CClientWeapon::ChangeAmmoImmediate()
- //
- // PURPOSE: Change to the specified ammo type
- //
- // ----------------------------------------------------------------------- //
- void CClientWeapon::ChangeAmmoImmediate( uint8 nNewAmmoId, int nAmmoAmount /*=-1*/, bool bForce /*=false*/ )
- {
- // Update the player's stats...
- if ( ( W_RELOADING == GetState() ) && !bForce )
- {
- return;
- }
- if ( CanChangeToAmmo( nNewAmmoId ) && ( nNewAmmoId != m_nAmmoId ) )
- {
- ASSERT( 0 != g_pWeaponMgr );
- m_nAmmoId = nNewAmmoId;
- m_pAmmo = g_pWeaponMgr->GetAmmo( m_nAmmoId );
- // Make sure we reset the anis (the ammo may override the
- // weapon animations)...
- InitAnimations( true );
- if ( m_pAmmo->pAniOverrides )
- {
- // If we're not using the defaults play the new select ani...
- Select();
- }
- else
- {
- // Do normal reload...
- ReloadClip( false, nAmmoAmount /*-1*/, true, true );
- }
- }
- else
- {
- // Update the hud to reflect the new ammo amount...
- g_pPlayerStats->UpdateAmmo( m_nWeaponId, m_nAmmoId, nAmmoAmount );
- g_pPlayerStats->UpdatePlayerWeapon( m_nWeaponId, m_nAmmoId );
- }
- }
- // ----------------------------------------------------------------------- //
- //
- // ROUTINE: CWeapon::ReloadClip
- //
- // PURPOSE: Fill the clip
- //
- // ----------------------------------------------------------------------- //
- void CClientWeapon::ReloadClip( bool bPlayReload /*=true*/,
- int nNewAmmo /*=-1*/,
- bool bForce /*=false*/,
- bool bNotifyServer /*=false*/)
- {
- // Can't reload clip while deselecting the weapon...
- if ( W_DESELECT == GetState() ) return;
- // get all the ammo the player possesses
- int nAmmoCount = g_pPlayerStats->GetAmmoCount( m_nAmmoId );
- // Get an intermediate amount of ammo. If the nNewAmmo has
- // been specified, use that value. Otherwise use the total
- // amount of ammo on the player.
- int nAmmo = nNewAmmo >= 0 ? nNewAmmo : nAmmoCount;
- // Get how many shots are in a clip.
- int nShotsPerClip = m_pWeapon->nShotsPerClip;
- // Update the player's stats...
- // note: the ammo amount we pass may be too much but
- // these functions figure out what the max really is,
- // and then we do the same thing later
- // UpdateAmmo does a lot of stuff, one of those is passing in
- // how much ammo you have. If you specify an amount that is
- // more or less, it will consider this the new amount of
- // ammo that you have on you and adjust things accordingly.
- g_pPlayerStats->UpdateAmmo( m_nWeaponId, m_nAmmoId, nAmmo );
- // This will set the player stats to the specified weapon and
- // ammo id. In this case, use the current ones.
- g_pPlayerStats->UpdatePlayerWeapon( m_nWeaponId, m_nAmmoId );
- // Make sure we can reload the clip...
- if ( !bForce )
- {
- // Already reloading...
- if ( m_hObject && ( W_RELOADING == GetState() ) )
- {
- return;
- }
- // Clip is full...
- if ( ( m_nAmmoInClip == nShotsPerClip ) || ( m_nAmmoInClip == nAmmoCount ) )
- {
- return;
- }
- }
- if ( ( nAmmo > 0 ) && ( nShotsPerClip > 0 ) )
- {
- // The amount of ammo we give the player due
- // of the reload is tracked with m_nNewAmmoInClip.
- // Set the new ammo to the lesser vaule of
- // either the max clip size of the amount of ammo
- // on the player.
- if ( nAmmo < nShotsPerClip )
- {
- m_nNewAmmoInClip = nAmmo;
- }
- else
- {
- m_nNewAmmoInClip = nShotsPerClip;
- }
- if( bNotifyServer )
- {
- // Let the server know we are reloading the clip...
- CAutoMessage cMsg;
- cMsg.Writeuint8( MID_WEAPON_RELOAD );
- cMsg.Writeuint8( m_nAmmoId ); // We maybe switching ammo
- g_pLTClient->SendToServer( cMsg.Read(), MESSAGE_GUARANTEED );
- }
- // check for a valid reload animation
- if ( bPlayReload && ( INVALID_ANI != GetReloadAni() ) )
- {
- // setting the state will "queue" the animation to
- // start playing on the next update
- SetState( W_RELOADING );
- return;
- }
- else
- {
- // there is no reload animation, so just put
- // the right amount in the clip directly
- m_nAmmoInClip = m_nNewAmmoInClip;
- }
- }
- }
- // ----------------------------------------------------------------------- //
- //
- // ROUTINE: CClientWeapon::DecrementAmmo
- //
- // PURPOSE: Decrement the weapon's ammo count
- //
- // ----------------------------------------------------------------------- //
- void CClientWeapon::DecrementAmmo()
- {
- // Hide the necessary pieces...
- SpecialShowPieces(false);
- int nAmmo;
- bool bInfiniteAmmo = ( g_bInfiniteAmmo || ( !!( m_pWeapon->bInfiniteAmmo ) ) );
- if ( bInfiniteAmmo )
- {
- nAmmo = INFINITE_AMMO_AMOUNT;
- }
- else
- {
- nAmmo = g_pPlayerStats->GetAmmoCount( m_nAmmoId );
- }
- int nShotsPerClip = m_pWeapon->nShotsPerClip;
- if ( 0 < m_nAmmoInClip )
- {
- if ( 0 < nShotsPerClip )
- {
- // decrease the ammo in the clip only if the clip
- // is non-zero
- --m_nAmmoInClip;
- }
- if ( !bInfiniteAmmo )
- {
- // we are not using infinite ammo, update the current amount
- --nAmmo;
- // Update our stats. This will ensure that our stats are always
- // accurate (even in multiplayer)...
- g_pPlayerStats->UpdateAmmo( m_nWeaponId, m_nAmmoId, nAmmo, LTFALSE, LTFALSE );
- }
- }
- // Check to see if we need to reload...
- if ( 0 < nShotsPerClip )
- {
- if ( 0 >= m_nAmmoInClip )
- {
- ReloadClip( true, nAmmo );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement