1 /*
2 Copyright (C) 2004 Parallel Realities
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 */
20 
21 #include "highscores.h"
22 
getHighScorePosition(unsigned int score)23 int getHighScorePosition(unsigned int score)
24 {
25 	for (int i = 0 ; i < 10 ; i++)
26 	{
27 		if (score > gameData.highScore[gameData.skill][i].score)
28 		{
29 			presentPlayerMedal("VK_Highscore");
30 			return i;
31 		}
32 	}
33 
34 	return -1;
35 }
36 
showHighScores(int skill,int startY)37 void showHighScores(int skill, int startY)
38 {
39 	graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
40 	graphics.setFontSize(2);
41 	graphics.drawString(400, startY, TXT_CENTERED, graphics.screen, "Highscores - %s Mode", gameModes[skill]);
42 	graphics.setFontSize(1);
43 
44 	startY += 60;
45 
46 	graphics.drawString(175, startY, TXT_LEFT, graphics.screen, "Name");
47 	graphics.drawString(375, startY, TXT_LEFT, graphics.screen, "Score");
48 	graphics.drawString(475, startY, TXT_LEFT, graphics.screen, "Kills");
49 	graphics.drawString(575, startY, TXT_LEFT, graphics.screen, "Level");
50 
51 	startY += 40;
52 
53 	for (int i = 0 ; i < 10 ; i++)
54 	{
55 		graphics.drawString(175, startY + (25 * i), TXT_LEFT, graphics.screen, "%s", gameData.highScore[skill][i].name);
56 		graphics.drawString(375, startY + (25 * i), TXT_LEFT, graphics.screen, "%.8d", gameData.highScore[skill][i].score);
57 		graphics.drawString(475, startY + (25 * i), TXT_LEFT, graphics.screen, "%.5d", gameData.highScore[skill][i].kills);
58 		graphics.drawString(575, startY + (25 * i), TXT_LEFT, graphics.screen, "%.3d", gameData.highScore[skill][i].level);
59 	}
60 }
61 
addHighScore()62 int addHighScore()
63 {
64 	if (gameData.score < 0)
65 		return SECTION_TITLE;
66 
67 	int position = getHighScorePosition(gameData.score);
68 
69 	if (position == -1)
70 		return SECTION_TITLE;
71 
72 	audio.loadMusic("music/Highscore.mod");
73 
74 	addTitleViruses();
75 
76 	graphics.clearScreen(graphics.black);
77 	graphics.delay(500);
78 
79 	char place[5];
80 
81 	switch (position + 1)
82 	{
83 		case 1:
84 			strcpy(place, "1st");
85 			break;
86 		case 2:
87 			strcpy(place, "2nd");
88 			break;
89 		case 3:
90 			strcpy(place, "3rd");
91 			break;
92 		default:
93 			sprintf(place, "%dth", position + 1);
94 			break;
95 	}
96 
97 	strcpy(engine.lastInput, "");
98 
99 	engine.resetTimeDifference();
100 
101 	graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
102 
103 	audio.playMusic();
104 
105 	while (true)
106 	{
107 		engine.doTimeDifference();
108 
109 		engine.getInput();
110 
111 		if ((engine.keyState[SDLK_RETURN]) || (engine.keyState[SDLK_ESCAPE]))
112 			break;
113 
114 		graphics.updateScreen();
115 		graphics.clearScreen(graphics.black);
116 
117 		doTitleViruses();
118 
119 		graphics.setFontSize(2);
120 
121 		graphics.drawString(400, 80, TXT_CENTERED, graphics.screen, "!! Congratulations !!");
122 
123 		graphics.setFontSize(1);
124 
125 		graphics.drawString(400, 150, TXT_CENTERED, graphics.screen, "Even though your system has been completely destroyed and viruses are");
126 		graphics.drawString(400, 175, TXT_CENTERED, graphics.screen, "now spreading all your personal information around the internet via MSN,");
127 		graphics.drawString(400, 200, TXT_CENTERED, graphics.screen, "you scored enough points to make it to the highscore board!", gameData.score);
128 
129 		graphics.setFontSize(2);
130 
131 		graphics.drawString(400, 250, TXT_CENTERED, graphics.screen, "%s Place with %d Points!!", place, gameData.score);
132 
133 		graphics.drawString(400, 325, TXT_CENTERED, graphics.screen, "Please Enter Your Name");
134 
135 		if (strlen(engine.lastInput) > 0)
136 			graphics.drawString(400, 375, TXT_CENTERED, graphics.screen, "%s_", engine.lastInput);
137 		else
138 			graphics.drawString(400, 375, TXT_CENTERED, graphics.screen, "_");
139 	}
140 
141 	graphics.clearScreen(graphics.black);
142 	graphics.delay(500);
143 
144 	for (int i = 8 ; i != (position - 1) ; i--)
145 	{
146 		debug(("Replacing %s with %s\n", gameData.highScore[gameData.skill][i + 1].name, gameData.highScore[gameData.skill][i].name));
147 		gameData.highScore[gameData.skill][i + 1] = gameData.highScore[gameData.skill][i];
148 	}
149 
150 	if (strlen(engine.lastInput) == 0)
151 		strcpy(engine.lastInput, "Anonymous");
152 
153 	gameData.highScore[gameData.skill][position].set(engine.lastInput, gameData.score, gameData.virusesKilled, gameData.level);
154 
155 	engine.clearInput();
156 	engine.flushInput();
157 	engine.resetTimeDifference();
158 
159 	graphics.setFontSize(1);
160 
161 	while (true)
162 	{
163 		engine.doTimeDifference();
164 
165 		engine.getInput();
166 
167 		if (engine.userAccepts())
168 			break;
169 
170 		graphics.updateScreen();
171 		graphics.clearScreen(graphics.black);
172 
173 		doTitleViruses();
174 
175 		showHighScores(gameData.skill, 100);
176 	}
177 
178 	audio.stopMusic();
179 	gameData.clear();
180 
181 	graphics.clearScreen(graphics.black);
182 	graphics.delay(500);
183 
184 	return SECTION_TITLE;
185 }
186