//----------------------------------------------------------------------------- // Purpose: sets the specified component bit # if it is not already. // If it does get set, evaluate if this satisfies an achievement //----------------------------------------------------------------------------- void CBaseAchievement::EnsureComponentBitSetAndEvaluate( int iBitNumber ) { Assert( iBitNumber < 64 ); // this is bit #, not a bit mask if ( IsAchieved() ) return; // calculate which bit this component corresponds to uint64 iBitMask = ( (uint64) 1 ) << iBitNumber; // see if we already have gotten this component if ( 0 == ( iBitMask & m_iComponentBits ) ) { if ( !AlwaysEnabled() && !m_pAchievementMgr->CheckAchievementsEnabled() ) { Msg( "Achievements disabled, ignoring achievement component for %s\n", GetName() ); return; } // new component, set the bit and increment the count SetComponentBits( m_iComponentBits | iBitMask ); if ( m_iCount != m_iGoal ) { // save our state at the next good opportunity m_pAchievementMgr->SetDirty( true ); if ( cc_achievement_debug.GetInt() ) { Msg( "Component %d for achievement %s found\n", iBitNumber, GetName() ); } ShowProgressNotification(); } } else { if ( cc_achievement_debug.GetInt() ) { Msg( "Component %d for achievement %s found, but already had that component\n", iBitNumber, GetName() ); } } // Check to see if we've achieved our goal even if the bit is already set // (this fixes some older achievements that are stuck in the 9/9 state and could never be evaluated) Assert( m_iCount <= m_iGoal ); if ( m_iCount == m_iGoal ) { // all components found, award the achievement (and save state) AwardAchievement(); } }
void CBaseAchievement::HandleProgressUpdate() { // if we've hit the right # of progress steps to show a progress notification, show it if ( ( m_iProgressMsgIncrement > 0 ) && m_iCount >= m_iProgressMsgMinimum && ( 0 == ( m_iCount % m_iProgressMsgIncrement ) ) ) { // which notification is this int iProgress = m_iCount / m_iProgressMsgIncrement; // if we haven't already shown this progress step, show it if ( iProgress > m_iProgressShown ) { ShowProgressNotification(); // remember progress step shown so we don't show it again if the player loads an earlier save game // and gets past this point again m_iProgressShown = iProgress; m_pAchievementMgr->SetDirty( true ); } } }