2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
43 #define VERSION_NUMBER 1
44 #define SCORES_FILENAME "DESCENT.HI"
45 #define COOL_MESSAGE_LEN 50
46 #define MAX_HIGH_SCORES 10
48 typedef struct stats_info {
49 char name[CALLSIGN_LEN+1];
54 short kill_ratio; // 0-100
55 short hostage_ratio; //
56 int seconds; // How long it took in seconds...
59 typedef struct all_scores {
60 char signature[3]; // DHS
61 byte version; // version
62 char cool_saying[COOL_MESSAGE_LEN];
63 stats_info stats[MAX_HIGH_SCORES];
66 static all_scores Scores;
70 char scores_filename[128];
75 #define LHX(x) ((x)*(MenuHires?2:1))
76 #define LHY(y) ((y)*(MenuHires?2.4:1))
78 void scores_view(int citem);
81 char * get_scores_filename()
84 // Only use the MINER variable for internal developement
88 sprintf( scores_filename, "%s\\game\\%s", p, SCORES_FILENAME );
89 Assert(strlen(scores_filename) < 128);
90 return scores_filename;
93 #ifdef MACINTOSH // put the high scores into the data folder
94 sprintf( scores_filename, ":Data:%s", SCORES_FILENAME );
96 sprintf( scores_filename, "%s", SCORES_FILENAME );
98 return scores_filename;
102 #define COOL_SAYING TXT_REGISTER_DESCENT
104 #define COOL_SAYING "Get all 30 levels of D2 from 1-800-INTERPLAY"
112 // clear score array...
113 memset( &Scores, 0, sizeof(all_scores) );
115 fp = fopen( get_scores_filename(), "rb" );
119 // No error message needed, code will work without a scores file
120 sprintf( Scores.cool_saying, COOL_SAYING );
121 sprintf( Scores.stats[0].name, "Parallax" );
122 sprintf( Scores.stats[1].name, "Matt" );
123 sprintf( Scores.stats[2].name, "Mike" );
124 sprintf( Scores.stats[3].name, "Adam" );
125 sprintf( Scores.stats[4].name, "Mark" );
126 sprintf( Scores.stats[5].name, "Jasen" );
127 sprintf( Scores.stats[6].name, "Samir" );
128 sprintf( Scores.stats[7].name, "Doug" );
129 sprintf( Scores.stats[8].name, "Dan" );
130 sprintf( Scores.stats[9].name, "Jason" );
133 Scores.stats[i].score = (10-i)*1000;
137 fsize = filelength( fileno( fp ));
139 if ( fsize != sizeof(all_scores) ) {
144 fread( &Scores, sizeof(all_scores),1, fp );
147 if ( (Scores.version!=VERSION_NUMBER)||(Scores.signature[0]!='D')||(Scores.signature[1]!='H')||(Scores.signature[2]!='S') ) {
148 memset( &Scores, 0, sizeof(all_scores) );
157 fp = fopen( get_scores_filename(), "wb" );
159 nm_messagebox( TXT_WARNING, 1, TXT_OK, "%s\n'%s'", TXT_UNABLE_TO_OPEN, get_scores_filename() );
163 Scores.signature[0]='D';
164 Scores.signature[1]='H';
165 Scores.signature[2]='S';
166 Scores.version = VERSION_NUMBER;
167 fwrite( &Scores,sizeof(all_scores),1, fp );
171 void int_to_string( int number, char *dest )
176 sprintf( buffer, "%d", number );
180 // Don't bother with less than 3 digits
181 sprintf( dest, "%d", number );
187 for (i=l-1; i>=0; i-- ) {
199 void scores_fill_struct(stats_info * stats)
201 strcpy( stats->name, Players[Player_num].callsign );
202 stats->score = Players[Player_num].score;
203 stats->ending_level = Players[Player_num].level;
204 if (Players[Player_num].num_robots_total > 0 )
205 stats->kill_ratio = (Players[Player_num].num_kills_total*100)/Players[Player_num].num_robots_total;
207 stats->kill_ratio = 0;
209 if (Players[Player_num].hostages_total > 0 )
210 stats->hostage_ratio = (Players[Player_num].hostages_rescued_total*100)/Players[Player_num].hostages_total;
212 stats->hostage_ratio = 0;
214 stats->seconds = f2i(Players[Player_num].time_total)+(Players[Player_num].hours_total*3600);
216 stats->diff_level = Difficulty_level;
217 stats->starting_level = Players[Player_num].starting_level;
220 //char * score_placement[10] = { TXT_1ST, TXT_2ND, TXT_3RD, TXT_4TH, TXT_5TH, TXT_6TH, TXT_7TH, TXT_8TH, TXT_9TH, TXT_10TH };
222 void scores_maybe_add_player(int abort_flag)
224 char text1[COOL_MESSAGE_LEN+10];
228 #ifdef APPLE_DEMO // no high scores in apple oem version
232 if ((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP))
237 position = MAX_HIGH_SCORES;
238 for (i=0; i<MAX_HIGH_SCORES; i++ ) {
239 if ( Players[Player_num].score > Scores.stats[i].score ) {
245 if ( position == MAX_HIGH_SCORES ) {
248 scores_fill_struct( &Last_game );
250 //-- if ( Difficulty_level < 1 ) {
251 //-- nm_messagebox( "GRADUATION TIME!", 1, "Ok", "If you would had been\nplaying at a higher difficulty\nlevel, you would have placed\n#%d on the high score list.", position+1 );
257 m[0].type = NM_TYPE_TEXT; m[0].text = TXT_COOL_SAYING;
258 m[1].type = NM_TYPE_INPUT; m[1].text = text1; m[1].text_len = COOL_MESSAGE_LEN-5;
259 newmenu_do( TXT_HIGH_SCORE, TXT_YOU_PLACED_1ST, 2, m, NULL );
260 strncpy( Scores.cool_saying, text1, COOL_MESSAGE_LEN );
261 if (strlen(Scores.cool_saying)<1)
262 sprintf( Scores.cool_saying, "No Comment" );
264 nm_messagebox( TXT_HIGH_SCORE, 1, TXT_OK, "%s %s!", TXT_YOU_PLACED, *(&TXT_1ST + position) );
267 // move everyone down...
268 for ( i=MAX_HIGH_SCORES-1; i>position; i-- ) {
269 Scores.stats[i] = Scores.stats[i-1];
272 scores_fill_struct( &Scores.stats[position] );
277 scores_view(position);
280 void scores_rprintf(int x, int y, char * format, ... )
287 va_start(args, format );
288 vsprintf(buffer,format,args);
291 //replace the digit '1' with special wider 1
292 for (p=buffer;*p;p++)
295 gr_get_string_size(buffer, &w, &h, &aw );
297 gr_string( LHX(x)-w, LHY(y), buffer );
301 void scores_draw_item( int i, stats_info * stats )
307 WIN(DDGRLOCK(dd_grd_curcanv));
312 if ( i==MAX_HIGH_SCORES ) {
314 //scores_rprintf( 17+33+XX, y+YY, "" );
316 scores_rprintf( 17+33+XX, y+YY, "%d.", i+1 );
319 if (strlen(stats->name)==0) {
320 gr_printf( LHX(26+33+XX), LHY(y+YY), TXT_EMPTY );
321 WIN(DDGRUNLOCK(dd_grd_curcanv));
324 gr_printf( LHX(26+33+XX), LHY(y+YY), "%s", stats->name );
325 int_to_string(stats->score, buffer);
326 scores_rprintf( 109+33+XX, y+YY, "%s", buffer );
328 gr_printf( LHX(125+33+XX), LHY(y+YY), "%s", MENU_DIFFICULTY_TEXT(stats->diff_level) );
330 if ( (stats->starting_level > 0 ) && (stats->ending_level > 0 ))
331 scores_rprintf( 192+33+XX, y+YY, "%d-%d", stats->starting_level, stats->ending_level );
332 else if ( (stats->starting_level < 0 ) && (stats->ending_level > 0 ))
333 scores_rprintf( 192+33+XX, y+YY, "S%d-%d", -stats->starting_level, stats->ending_level );
334 else if ( (stats->starting_level < 0 ) && (stats->ending_level < 0 ))
335 scores_rprintf( 192+33+XX, y+YY, "S%d-S%d", -stats->starting_level, -stats->ending_level );
336 else if ( (stats->starting_level > 0 ) && (stats->ending_level < 0 ))
337 scores_rprintf( 192+33+XX, y+YY, "%d-S%d", stats->starting_level, -stats->ending_level );
341 h = stats->seconds/3600;
342 s = stats->seconds%3600;
345 scores_rprintf( 311-42+XX, y+YY, "%d:%02d:%02d", h, m, s );
347 WIN(DDGRUNLOCK(dd_grd_curcanv));
350 void scores_view(int citem)
355 byte fades[64] = { 1,1,1,2,2,3,4,4,5,6,8,9,10,12,13,15,16,17,19,20,22,23,24,26,27,28,28,29,30,30,31,31,31,31,31,30,30,29,28,28,27,26,24,23,22,20,19,17,16,15,13,12,10,9,8,6,5,4,4,3,2,2,1,1 };
360 set_screen_mode(SCREEN_MENU);
362 WINDOS( dd_gr_set_current_canvas(NULL),
363 gr_set_current_canvas(NULL)
366 nm_draw_background(0,0,grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h );
368 grd_curcanv->cv_font = MEDIUM3_FONT;
370 WIN(DDGRLOCK(dd_grd_curcanv));
371 gr_string( 0x8000, LHY(15), TXT_HIGH_SCORES );
373 grd_curcanv->cv_font = SMALL_FONT;
375 gr_set_fontcolor( BM_XRGB(31,26,5), -1 );
376 gr_string( LHX(31+33+XX), LHY(46+7+YY), TXT_NAME );
377 gr_string( LHX(82+33+XX), LHY(46+7+YY), TXT_SCORE );
378 gr_string( LHX(127+33+XX), LHY(46+7+YY), TXT_SKILL );
379 gr_string( LHX(170+33+XX), LHY(46+7+YY), TXT_LEVELS );
380 // gr_string( 202, 46, "Kills" );
381 // gr_string( 234, 46, "Rescues" );
382 gr_string( LHX(288-42+XX), LHY(46+7+YY), TXT_TIME );
385 gr_string( 0x8000, LHY(175), TXT_PRESS_CTRL_R );
387 gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
389 gr_printf( 0x8000, LHY(31), "%c%s%c - %s", 34, Scores.cool_saying, 34, Scores.stats[0].name );
390 WIN(DDGRUNLOCK(dd_grd_curcanv));
392 for (i=0; i<MAX_HIGH_SCORES; i++ ) {
394 //@@ gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
396 //@@ gr_set_fontcolor( gr_fade_table[BM_XRGB(28,28,28)+((28-i*2)*256)], -1 );
399 gr_set_fontcolor( BM_XRGB(28-i*2,28-i*2,28-i*2), -1 );
400 scores_draw_item( i, &Scores.stats[i] );
403 gr_palette_fade_in( gr_palette,32, 0);
413 t1 = timer_get_fixed_seconds();
414 while ( timer_get_fixed_seconds() < t1+F1_0/128 );
416 //@@gr_set_fontcolor( gr_fade_table[fades[looper]*256+BM_XRGB(28,28,28)], -1 );
417 gr_set_fontcolor( BM_XRGB(7+fades[looper],7+fades[looper],7+fades[looper]), -1 );
419 if (looper>63) looper=0;
420 if ( citem == MAX_HIGH_SCORES )
421 scores_draw_item( MAX_HIGH_SCORES, &Last_game );
423 scores_draw_item( citem, &Scores.stats[citem] );
427 if (joy_get_button_down_cnt(i)>0) done=1;
429 if (mouse_button_down_count(i)>0) done=1;
431 //see if redbook song needs to be restarted
432 songs_check_redbook_repeat();
438 DoMessageStuff(&msg);
441 _RedrawScreen = FALSE;
451 case KEY_CTRLED+KEY_R:
454 if ( nm_messagebox( NULL, 2, TXT_NO, TXT_YES, TXT_RESET_HIGH_SCORES )==1 ) {
455 remove( get_scores_filename() );
456 gr_palette_fade_out( gr_palette, 32, 0 );
461 case KEY_BACKSP: Int3(); k = 0; break;
462 case KEY_PRINT_SCREEN: save_screen_shot(0); k = 0; break;
472 // Restore background and exit
473 gr_palette_fade_out( gr_palette, 32, 0 );
479 WINDOS( dd_gr_set_current_canvas(NULL),
480 gr_set_current_canvas(NULL)