DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

DoomLeaderboards.cpp (4975B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 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.
     23 
     24 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.
     25 
     26 ===========================================================================
     27 */
     28 
     29 #include "DoomLeaderboards.h"
     30 #include "tech5/engine/framework/precompiled.h"
     31 #include "tech5\engine\sys\sys_stats.h"
     32 #include "../doomengine/source/doomdef.h"
     33 
     34 #include <map>
     35 
     36 static columnDef_t columnDefTime[] = { 
     37 	{ "Time", 64, AGGREGATE_MIN, STATS_COLUMN_DISPLAY_TIME_MILLISECONDS }
     38 };
     39 
     40 const static int NUMLEVELS_ULTIMATE_DOOM		= 36;						
     41 const static int NUMLEVELS_DOOM2_HELL_ON_EARTH	= 32;
     42 const static int NUMLEVELS_FINALDOOM_TNT		= 32;
     43 const static int NUMLEVELS_FINALDOOM_PLUTONIA	= 32;
     44 const static int NUMLEVELS_DOOM2_MASTER_LEVELS	= 21;
     45 const static int NUMLEVELS_DOOM2_NERVE			= 9;
     46 
     47 
     48 const static int NUM_LEVEL_LIST[] = {
     49 	NUMLEVELS_ULTIMATE_DOOM,
     50 	NUMLEVELS_DOOM2_HELL_ON_EARTH,
     51 	NUMLEVELS_FINALDOOM_TNT,
     52 	NUMLEVELS_FINALDOOM_PLUTONIA,
     53 	NUMLEVELS_DOOM2_MASTER_LEVELS,
     54 	NUMLEVELS_DOOM2_NERVE
     55 };
     56 
     57 /*
     58 ========================
     59 GenerateLeaderboard ID
     60 Generates a Leaderboard ID based on current Expansion + episode + map + skill + Type 
     61 
     62 Expansion is the base value that the leaderboard ID comes from
     63 
     64 ========================
     65 */
     66 const int GenerateLeaderboardID( int expansion, int episode, int map, int skill ) {
     67 	
     68 	int realMapNumber = ( episode * map - 1 );
     69 
     70 	if( common->GetGameSKU() == GAME_SKU_DOOM1_BFG  ) {
     71 
     72 		// Doom levels start at 620 .. yeah.. hack.
     73 		int block = 615;
     74 		int mapAndSkill = ( realMapNumber * ( (int)sk_nightmare + 1 ) )  + skill ;
     75 
     76 		return block + mapAndSkill;
     77 	} else if( common->GetGameSKU() == GAME_SKU_DOOM2_BFG ) {
     78 
     79 		if( expansion == 1 ) {
     80 			// Doom 2 Levels start at 800.. Yep.. another hack.
     81 			int block = 795;
     82 			int mapAndSkill = ( realMapNumber * ( (int)sk_nightmare + 1 ) )  + skill ;
     83 
     84 			return block + mapAndSkill;
     85 		} else {
     86 			// Nerve Levels start at 960... another hack!
     87 			int block = 955;
     88 			int mapAndSkill = ( realMapNumber * ( (int)sk_nightmare + 1 ) )  + skill ;
     89 
     90 			return block + mapAndSkill;
     91 		}
     92 
     93 	} else {
     94 
     95 		// DCC Content
     96 		int block = 0;
     97 		if( expansion  > 0 ){
     98 			for( int expi = 0; expi < expansion; expi++ ) {
     99 				block += NUM_LEVEL_LIST[ expi ] * ( (int)sk_nightmare + 1);
    100 			}
    101 		}
    102 		int mapAndSkill = ( realMapNumber * ( (int)sk_nightmare + 1 ) )  + skill ;
    103 		return block + mapAndSkill;
    104 	}
    105 }
    106 
    107 /*
    108 ========================
    109 InitLeaderboards
    110 
    111 Generates all the possible leaderboard definitions
    112 and stores into an STL Map, with leaderboard ID as the Hash/key value.
    113 
    114 ========================
    115 */
    116 void InitLeaderboards() {
    117 
    118 	for( int expi = 0; expi < ARRAY_COUNT( NUM_LEVEL_LIST ); expi++ ) {
    119 	
    120 		for( int udi = 1; udi <= NUM_LEVEL_LIST[expi] ; udi++ ) {
    121 
    122 			for( int skilli = 0; skilli <= sk_nightmare; skilli++ ) {
    123 
    124 				// Create the Time Trial leaderboard for each level.
    125 				int timeTrial_leaderboardID = GenerateLeaderboardID( expi, 1, udi, skilli ); 
    126 				leaderboardDefinition_t * timeTrial_Leaderboard = new leaderboardDefinition_t( timeTrial_leaderboardID,	ARRAY_COUNT( columnDefTime ), columnDefTime, RANK_LEAST_FIRST,	false, true );
    127 
    128 			}
    129 		}	
    130 	}
    131 }
    132 
    133 /*
    134 ========================
    135 GenerateLeaderboard
    136 Generates a Leaderboard based on current Expansion + episode + map + skill + Type 
    137 
    138 Expansion is the base value that the leaderboard ID comes from
    139 
    140 ========================
    141 */
    142 const leaderboardDefinition_t * GetLeaderboard( int expansion, int episode, int map, int skill ) {
    143 
    144 	int leaderboardID = GenerateLeaderboardID( expansion, episode, map, skill );
    145 
    146 	return Sys_FindLeaderboardDef( leaderboardID );;
    147 }