DoomLeaderboards.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. #include "DoomLeaderboards.h"
  21. #include "tech5/engine/framework/precompiled.h"
  22. #include "tech5\engine\sys\sys_stats.h"
  23. #include "../doomengine/source/doomdef.h"
  24. #include <map>
  25. static columnDef_t columnDefTime[] = {
  26. { "Time", 64, AGGREGATE_MIN, STATS_COLUMN_DISPLAY_TIME_MILLISECONDS }
  27. };
  28. const static int NUMLEVELS_ULTIMATE_DOOM = 36;
  29. const static int NUMLEVELS_DOOM2_HELL_ON_EARTH = 32;
  30. const static int NUMLEVELS_FINALDOOM_TNT = 32;
  31. const static int NUMLEVELS_FINALDOOM_PLUTONIA = 32;
  32. const static int NUMLEVELS_DOOM2_MASTER_LEVELS = 21;
  33. const static int NUMLEVELS_DOOM2_NERVE = 9;
  34. const static int NUM_LEVEL_LIST[] = {
  35. NUMLEVELS_ULTIMATE_DOOM,
  36. NUMLEVELS_DOOM2_HELL_ON_EARTH,
  37. NUMLEVELS_FINALDOOM_TNT,
  38. NUMLEVELS_FINALDOOM_PLUTONIA,
  39. NUMLEVELS_DOOM2_MASTER_LEVELS,
  40. NUMLEVELS_DOOM2_NERVE
  41. };
  42. /*
  43. ========================
  44. GenerateLeaderboard ID
  45. Generates a Leaderboard ID based on current Expansion + episode + map + skill + Type
  46. Expansion is the base value that the leaderboard ID comes from
  47. ========================
  48. */
  49. const int GenerateLeaderboardID( int expansion, int episode, int map, int skill ) {
  50. int realMapNumber = ( episode * map - 1 );
  51. if( common->GetGameSKU() == GAME_SKU_DOOM1_BFG ) {
  52. // Doom levels start at 620 .. yeah.. hack.
  53. int block = 615;
  54. int mapAndSkill = ( realMapNumber * ( (int)sk_nightmare + 1 ) ) + skill ;
  55. return block + mapAndSkill;
  56. } else if( common->GetGameSKU() == GAME_SKU_DOOM2_BFG ) {
  57. if( expansion == 1 ) {
  58. // Doom 2 Levels start at 800.. Yep.. another hack.
  59. int block = 795;
  60. int mapAndSkill = ( realMapNumber * ( (int)sk_nightmare + 1 ) ) + skill ;
  61. return block + mapAndSkill;
  62. } else {
  63. // Nerve Levels start at 960... another hack!
  64. int block = 955;
  65. int mapAndSkill = ( realMapNumber * ( (int)sk_nightmare + 1 ) ) + skill ;
  66. return block + mapAndSkill;
  67. }
  68. } else {
  69. // DCC Content
  70. int block = 0;
  71. if( expansion > 0 ){
  72. for( int expi = 0; expi < expansion; expi++ ) {
  73. block += NUM_LEVEL_LIST[ expi ] * ( (int)sk_nightmare + 1);
  74. }
  75. }
  76. int mapAndSkill = ( realMapNumber * ( (int)sk_nightmare + 1 ) ) + skill ;
  77. return block + mapAndSkill;
  78. }
  79. }
  80. /*
  81. ========================
  82. InitLeaderboards
  83. Generates all the possible leaderboard definitions
  84. and stores into an STL Map, with leaderboard ID as the Hash/key value.
  85. ========================
  86. */
  87. void InitLeaderboards() {
  88. for( int expi = 0; expi < ARRAY_COUNT( NUM_LEVEL_LIST ); expi++ ) {
  89. for( int udi = 1; udi <= NUM_LEVEL_LIST[expi] ; udi++ ) {
  90. for( int skilli = 0; skilli <= sk_nightmare; skilli++ ) {
  91. // Create the Time Trial leaderboard for each level.
  92. int timeTrial_leaderboardID = GenerateLeaderboardID( expi, 1, udi, skilli );
  93. leaderboardDefinition_t * timeTrial_Leaderboard = new leaderboardDefinition_t( timeTrial_leaderboardID, ARRAY_COUNT( columnDefTime ), columnDefTime, RANK_LEAST_FIRST, false, true );
  94. }
  95. }
  96. }
  97. }
  98. /*
  99. ========================
  100. GenerateLeaderboard
  101. Generates a Leaderboard based on current Expansion + episode + map + skill + Type
  102. Expansion is the base value that the leaderboard ID comes from
  103. ========================
  104. */
  105. const leaderboardDefinition_t * GetLeaderboard( int expansion, int episode, int map, int skill ) {
  106. int leaderboardID = GenerateLeaderboardID( expansion, episode, map, skill );
  107. return Sys_FindLeaderboardDef( leaderboardID );;
  108. }