sys_achievements.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __SYS_ACHIEVEMENTS_H__
  21. #define __SYS_ACHIEVEMENTS_H__
  22. class idLocalUser;
  23. // data structure for online achievement entry descriptions
  24. // this is used for testing purposes to make sure that the consoles
  25. // achievement settings match the game's decls
  26. struct achievementDescription_t {
  27. void Clear() {
  28. name[0] = '\0';
  29. description[0] = '\0';
  30. hidden = false;
  31. };
  32. char name[500];
  33. char description[1000];
  34. bool hidden;
  35. };
  36. /*
  37. ================================================
  38. idAchievementSystem
  39. ================================================
  40. */
  41. class idAchievementSystem {
  42. public:
  43. static const int MAX_ACHIEVEMENTS = 128; // This matches the max number of achievements bits in the profile
  44. virtual ~idAchievementSystem() {}
  45. // PC and PS3 initialize for the system, not for a particular controller
  46. virtual void Init() {}
  47. // PS3 has to wait to install the .TRP file until *after* we determine there's enough space, for consistent user messaging
  48. virtual void Start() {}
  49. // Do any necessary cleanup
  50. virtual void Shutdown() {}
  51. // Is the achievement system ready for requests
  52. virtual bool IsInitialized() { return false; }
  53. // Add a local user to the system
  54. virtual void RegisterLocalUser( idLocalUser * user ) {}
  55. // This is only necessary on the 360 right now, we need this because the 360 maintains a buffer of pending actions
  56. // per user. If a user is removed from the system, we need to inform the system so it can cancel it's in flight actions
  57. // and allow the buffers to be reused
  58. virtual void RemoveLocalUser( idLocalUser * user ) {}
  59. // Unlocks the achievement, all platforms silently fail if the achievement has already been unlocked
  60. virtual void AchievementUnlock( idLocalUser * user, const int achievementID ) = 0;
  61. // Puts the achievement back to its original state, platform implementation may not allow this
  62. virtual void AchievementLock( idLocalUser * user, const int achievementID ) {}
  63. // Puts alls achievements back to their original state, platform implementation may not allow this
  64. virtual void AchievementLockAll( idLocalUser * user, const int maxId ) {}
  65. // Should be done every frame
  66. virtual void Pump() = 0;
  67. // Cancels all in-flight achievements for all users if NULL, resets the system so a Init() must be re-issued
  68. virtual void Reset( idLocalUser * user = NULL ) {}
  69. // Cancels all in-flight achievements, not very useful on PC
  70. virtual void Cancel( idLocalUser * user ) {}
  71. // Retrieves textual information about a given achievement
  72. // returns false if there was an error
  73. virtual bool GetAchievementDescription( idLocalUser * user, const int id, achievementDescription_t & data ) const { return false; }
  74. // How much storage is required
  75. // returns false if there was an error
  76. virtual bool GetRequiredStorage( uint64 & requiredSizeTrophiesBytes ) { requiredSizeTrophiesBytes = 0; return true; }
  77. // Retrieves state about of all achievements cached locally (may not be online yet)
  78. // returns false if there was an error
  79. virtual bool GetAchievementState( idLocalUser * user, idArray< bool, idAchievementSystem::MAX_ACHIEVEMENTS > & achievements ) const { return false; }
  80. // Sets state of all the achievements within list (for debug purposes only)
  81. // returns false if there was an error
  82. virtual bool SetAchievementState( idLocalUser * user, idArray< bool, idAchievementSystem::MAX_ACHIEVEMENTS > & achievements ) { return false; }
  83. // You want to get the server's cached achievement status into the user because the profile may not have been
  84. // saved with the achievement bits after an achievement was granted.
  85. void SyncAchievementBits( idLocalUser * user );
  86. protected:
  87. // Retrieves the index from the local user list
  88. int GetLocalUserIndex( idLocalUser * user ) const { return users.FindIndex( user ); }
  89. idStaticList< idLocalUser *, MAX_LOCAL_PLAYERS > users;
  90. };
  91. #endif // __SYS_ACHIEVEMENTS_H__