Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.9 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #if !defined ( ACHIEVEMENTS_CS_H )
  7. #define ACHIEVEMENTS_CS_H
  8. #include "cbase.h"
  9. #include "cs_gamestats_shared.h"
  10. #include "baseachievement.h"
  11. #ifdef _PS3
  12. #include "steam/steam_api.h"
  13. #endif
  14. #ifdef CLIENT_DLL
  15. bool CheckWinNoEnemyCaps( IGameEvent *event, int iRole );
  16. bool IsLocalCSPlayerClass( int iClass );
  17. bool GameRulesAllowsAchievements( void );
  18. //----------------------------------------------------------------------------------------------------------------
  19. // Base class for all CS achievements
  20. class CCSBaseAchievement : public CBaseAchievement
  21. {
  22. DECLARE_CLASS( CCSBaseAchievement, CBaseAchievement );
  23. public:
  24. CCSBaseAchievement();
  25. virtual void GetSettings( KeyValues* pNodeOut ); // serialize
  26. virtual void ApplySettings( /* const */ KeyValues* pNodeIn ); // unserialize
  27. // [dwenger] Necessary for sorting achievements by award time
  28. virtual void OnAchieved();
  29. bool GetAwardTime( int& year, int& month, int& day, int& hour, int& minute, int& second );
  30. int64 GetSortKey() const { return GetUnlockTime(); }
  31. };
  32. //----------------------------------------------------------------------------------------------------------------
  33. // Helper class for achievements that check that the player was playing on a game team for the full round
  34. class CCSBaseAchievementFullRound : public CCSBaseAchievement
  35. {
  36. DECLARE_CLASS( CCSBaseAchievementFullRound, CCSBaseAchievement );
  37. public:
  38. virtual void Init() ;
  39. virtual void ListenForEvents();
  40. void FireGameEvent_Internal( IGameEvent *event );
  41. bool PlayerWasInEntireRound( float flRoundTime );
  42. virtual void Event_OnRoundComplete( float flRoundTime, IGameEvent *event ) = 0 ;
  43. };
  44. //----------------------------------------------------------------------------------------------------------------
  45. // Helper class for achievements based on other achievements
  46. class CAchievement_Meta : public CCSBaseAchievement
  47. {
  48. DECLARE_CLASS( CAchievement_Meta, CCSBaseAchievement );
  49. public:
  50. CAchievement_Meta();
  51. virtual void Init();
  52. #if !defined(NO_STEAM)
  53. STEAM_CALLBACK( CAchievement_Meta, Steam_OnUserAchievementStored, UserAchievementStored_t, m_CallbackUserAchievement );
  54. #endif
  55. protected:
  56. void AddRequirement( int nAchievementId );
  57. private:
  58. CUtlVector<int> m_requirements;
  59. };
  60. //Base class for all achievements to kill x players with a given weapon
  61. class CAchievement_StatGoal: public CCSBaseAchievement
  62. {
  63. public:
  64. void SetStatId(CSStatType_t stat)
  65. {
  66. m_StatId = stat;
  67. }
  68. CSStatType_t GetStatId(void)
  69. {
  70. return m_StatId;
  71. }
  72. private:
  73. virtual void Init()
  74. {
  75. SetFlags( ACH_SAVE_GLOBAL );
  76. }
  77. void OnPlayerStatsUpdate( int nUserSlot );
  78. CSStatType_t m_StatId;
  79. };
  80. #if defined (_X360)
  81. static const int NumXboxMappedAchievements = 11; // number of xbox achievements that have a one to one correspondence with a medal
  82. static const int MedalToXBox[NumXboxMappedAchievements][2] = { { CSEnemyKillsHigh, ACHIEVEMENT_KILL_ENEMY_HIGH },
  83. { CSGiveDamageLow, ACHIEVEMENT_GIVE_DAMAGE_LOW },
  84. { CSMoneyEarnedLow, ACHIEVEMENT_EARN_MONEY_LOW },
  85. { CSGunGameProgressiveRampage, ACHIEVEMENT_GUN_GAME_RAMPAGE },
  86. { CSHeadshots, ACHIEVEMENT_HEADSHOTS },
  87. { CSFlawlessVictory, ACHIEVEMENT_FLAWLESS_VICTORY },
  88. { CSDominationsLow, ACHIEVEMENT_DOMINATIONS_LOW },
  89. { CSKillWithEveryWeapon, ACHIEVEMENT_KILL_WITH_EVERY_WEAPON },
  90. { CSKillEnemyLastBullet, ACHIEVEMENT_KILL_ENEMY_LAST_BULLET },
  91. { CSKillEnemyTerrTeamBeforeBombPlant, ACHIEVEMENT_GUN_GAME_FIRST_THING_FIRST },
  92. { CSGGRoundsHigh, ACHIEVEMENT_GUN_GAME_ROUNDS_HIGH }};
  93. class CAchievementListener : public CAutoGameSystem, public CGameEventListener
  94. {
  95. public:
  96. CAchievementListener();
  97. virtual bool Init();
  98. protected:
  99. void FireGameEvent( IGameEvent *event );
  100. };
  101. #endif
  102. extern CAchievementMgr g_AchievementMgrCS; // global achievement mgr for CS
  103. #endif // CLIENT_DLL
  104. #endif // ACHIEVEMENTS_CS_H