//----------------------------------------------------------------------------- // Purpose: called when an event that counts toward an achievement occurs //----------------------------------------------------------------------------- void CBaseAchievement::IncrementCount() { if ( !IsAchieved() ) { if ( !m_pAchievementMgr->CheckAchievementsEnabled() ) { Msg( "Achievements disabled, ignoring achievement progress for %s\n", GetName() ); return; } // on client, where the count is kept, increment count m_iCount++; // if this achievement gets saved w/global state, flag our global state as dirty if ( GetFlags() & ACH_SAVE_GLOBAL ) { m_pAchievementMgr->SetDirty( true ); } if ( cc_achievement_debug.GetInt() ) { Msg( "Achievement count increased for %s: %d/%d\n", GetName(), m_iCount, m_iGoal ); } // if this achievement's progress should be stored in Steam, set the steam stat for it if ( StoreProgressInSteam() && steamapicontext->SteamUserStats() ) { // Set the Steam stat with the same name as the achievement. Only cached locally until we upload it. char pszProgressName[1024]; Q_snprintf( pszProgressName, 1024, "%s_STAT", GetName() ); bool bRet = steamapicontext->SteamUserStats()->SetStat( CGameID( engine->GetAppID() ), pszProgressName, m_iCount ); if ( !bRet ) { DevMsg( "ISteamUserStats::GetStat failed to set progress value in Steam for achievement %s\n", pszProgressName ); } // Upload user data to commit the change to Steam so if the client crashes, progress isn't lost. // Only upload if we haven't uploaded recently, to keep us from spamming Steam with uploads. If we don't // upload now, it will get uploaded no later than level shutdown. if ( ( m_pAchievementMgr->GetTimeLastUpload() == 0 ) || ( Plat_FloatTime() - m_pAchievementMgr->GetTimeLastUpload() > 60 * 15 ) ) { m_pAchievementMgr->UploadUserData(); } } // if we've hit goal, award the achievement if ( m_iGoal > 0 ) { if ( m_iCount >= m_iGoal ) { AwardAchievement(); } else { HandleProgressUpdate(); } } } }
//----------------------------------------------------------------------------- // Purpose: called when an event that counts toward an achievement occurs //----------------------------------------------------------------------------- void CBaseAchievement::IncrementCount( int iOptIncrement ) { if ( !IsAchieved() && LocalPlayerCanEarn() ) { if ( !AlwaysEnabled() && !m_pAchievementMgr->CheckAchievementsEnabled() ) { Msg( "Achievements disabled, ignoring achievement progress for %s\n", GetName() ); return; } // on client, where the count is kept, increment count if ( iOptIncrement > 0 ) { // user specified that we want to increase by more than one. m_iCount += iOptIncrement; if ( m_iCount > m_iGoal ) { m_iCount = m_iGoal; } } else { m_iCount++; } // if this achievement gets saved w/global state, flag our global state as dirty if ( GetFlags() & ACH_SAVE_GLOBAL ) { m_pAchievementMgr->SetDirty( true ); } if ( cc_achievement_debug.GetInt() ) { Msg( "Achievement count increased for %s: %d/%d\n", GetName(), m_iCount, m_iGoal ); } #ifndef NO_STEAM // if this achievement's progress should be stored in Steam, set the steam stat for it if ( StoreProgressInSteam() && steamapicontext->SteamUserStats() ) { // Set the Steam stat with the same name as the achievement. Only cached locally until we upload it. char pszProgressName[1024]; Q_snprintf( pszProgressName, 1024, "%s_STAT", GetStat() ); bool bRet = steamapicontext->SteamUserStats()->SetStat( pszProgressName, m_iCount ); if ( !bRet ) { DevMsg( "ISteamUserStats::GetStat failed to set progress value in Steam for achievement %s\n", pszProgressName ); } m_pAchievementMgr->SetDirty( true ); } #endif // if we've hit goal, award the achievement if ( m_iGoal > 0 ) { if ( m_iCount >= m_iGoal ) { AwardAchievement(); } else { HandleProgressUpdate(); } } } }