]> icculus.org git repositories - taylor/freespace2.git/blob - src/stats/medals.cpp
added _splitpath.
[taylor/freespace2.git] / src / stats / medals.cpp
1 /*
2  * $Logfile: /Freespace2/code/Stats/Medals.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  * 
7  * $Log$
8  * Revision 1.6  2002/06/09 03:16:05  relnev
9  * added _splitpath.
10  *
11  * removed unneeded asm, old sdl 2d setup.
12  *
13  * fixed crash caused by opengl_get_region.
14  *
15  * Revision 1.5  2002/05/28 08:52:03  relnev
16  * implemented two assembly stubs.
17  *
18  * cleaned up a few warnings.
19  *
20  * added a little demo hackery to make it progress a little farther.
21  *
22  * Revision 1.4  2002/05/28 04:56:51  theoddone33
23  * runs a little bit now
24  *
25  * Revision 1.3  2002/05/26 20:22:48  theoddone33
26  * Most of network/ works
27  *
28  * Revision 1.2  2002/05/04 04:36:56  theoddone33
29  * More changes, took out a lot of the sound stuff which will bite later but
30  * I don't care.
31  *
32  * Revision 1.1.1.1  2002/05/03 03:28:11  root
33  * Initial import.
34  *
35  * 
36  * 12    10/29/99 10:40p Jefff
37  * hack to make german medal names display without actually changing them
38  * 
39  * 11    9/02/99 3:41p Jefff
40  * changed badge voice handling to be similar to promotion voice handling
41  * 
42  * 10    8/26/99 8:49p Jefff
43  * Updated medals screen and about everything that ever touches medals in
44  * one way or another.  Sheesh.
45  * 
46  * 9     7/16/99 1:50p Dave
47  * 8 bit aabitmaps. yay.
48  * 
49  * 8     3/19/99 9:51a Dave
50  * Checkin to repair massive source safe crash. Also added support for
51  * pof-style nebulae, and some new weapons code.
52  * 
53  * 8     3/15/99 10:29a Neilk
54  * 
55  * 7     1/30/99 5:08p Dave
56  * More new hi-res stuff.Support for nice D3D textures.
57  * 
58  * 6     12/18/98 1:13a Dave
59  * Rough 1024x768 support for Direct3D. Proper detection and usage through
60  * the launcher.
61  * 
62  * 5     11/30/98 1:07p Dave
63  * 16 bit conversion, first run.
64  * 
65  * 4     10/23/98 3:51p Dave
66  * Full support for tstrings.tbl and foreign languages. All that remains
67  * is to make it active in Fred.
68  * 
69  * 3     10/13/98 9:29a Dave
70  * Started neatening up freespace.h. Many variables renamed and
71  * reorganized. Added AlphaColors.[h,cpp]
72  * 
73  * 2     10/07/98 10:54a Dave
74  * Initial checkin.
75  * 
76  * 1     10/07/98 10:51a Dave
77  * 
78  * 26    6/13/98 3:18p Hoffoss
79  * NOX()ed out a bunch of strings that shouldn't be translated.
80  * 
81  * 25    6/01/98 11:43a John
82  * JAS & MK:  Classified all strings for localization.
83  * 
84  * 24    5/01/98 12:34p John
85  * Added code to force FreeSpace to run in the same dir as exe and made
86  * all the parse error messages a little nicer.
87  * 
88  * 23    4/27/98 3:13p Allender
89  * make ctrl-enter work on medals screen
90  * 
91  * 22    4/23/98 8:27p Allender
92  * basic support for cutscene playback.  Into movie code in place.  Tech
93  * room can view cutscenes stored in CDROM_dir variable
94  * 
95  * 21    4/12/98 8:30p Allender
96  * minor medal changes to show number of medals if > 1
97  * 
98  * 20    4/10/98 4:51p Hoffoss
99  * Made several changes related to tooltips.
100  * 
101  * 19    3/18/98 12:03p John
102  * Marked all the new strings as externalized or not.
103  * 
104  * 18    3/11/98 5:02p Dave
105  * Put in code to support new medals artwork. Assorted multiplayer bug
106  * fixes.
107  * 
108  * 17    3/07/98 5:44p Dave
109  * Finished player info popup. Ironed out a few todo bugs.
110  * 
111  * 16    3/05/98 5:11p Allender
112  * fix up medals screen (again).  Don't do state transition when viewing
113  * medals from debriefing screen.
114  * 
115  * 15    3/05/98 2:32p Hoffoss
116  * Renamed Rank_bitmap to Rank_bm so it isn't named the same as the
117  * variable in the debrief screen which confuses the debugger.
118  * 
119  * 14    2/22/98 2:48p John
120  * More String Externalization Classification
121  * 
122  * 13    2/09/98 5:21p Hoffoss
123  * Made exit from medals screen to previous screen (instead of assuming
124  * it's the barracks) work.
125  * 
126  * 12    1/27/98 4:23p Allender
127  * enhanced internal scoring mechanisms.
128  * 
129  * 11    11/12/97 4:40p Dave
130  * Put in multiplayer campaign support parsing, loading and saving. Made
131  * command-line variables better named. Changed some things on the initial
132  * pilot select screen.
133  * 
134  * 10    11/12/97 9:30a Dave
135  * Fixed rank insignia tooltip not showing up.
136  * 
137  * 9     11/06/97 4:39p Allender
138  * a ton of medal work.  Removed an uneeded elemen in the scoring
139  * structure.  Fix up medals screen to apprioriate display medals (after
140  * mask was changed).  Fix Fred to only display medals which may actually
141  * be granted.  Added image_filename to player struct for Jason Hoffoss
142  * 
143  * 8     11/05/97 4:43p Allender
144  * reworked medal/rank system to read all data from tables.  Made Fred
145  * read medals.tbl.  Changed ai-warp to ai-warp-out which doesn't require
146  * waypoint for activation
147  *
148  * $NoKeywords: $
149  */
150
151
152 #include "medals.h"
153 #include "2d.h"
154 #include "snazzyui.h"
155 #include "bmpman.h"
156 #include "gamesequence.h"
157 #include "animplay.h"
158 #include "mouse.h"
159 #include "freespace.h"
160 #include "scoring.h"
161 #include "player.h"
162 #include "palman.h"
163 #include "ui.h"
164 #include "key.h"
165 #include "cmdline.h"
166 #include "gamesnd.h"
167 #include "alphacolors.h"
168 #include "localize.h"
169
170 //#define MAX_MEDAL_TYPES 63 // the # of medals which exist so far
171
172 /*
173 #define CALLSIGN_X 198
174 #define CALLSIGN_Y 80
175 #define CALLSIGN_W (439-CALLSIGN_X)
176 #define CALLSIGN_H (116-CALLSIGN_Y)
177 */
178
179 // define for the medal information
180 medal_stuff Medals[NUM_MEDALS];
181 badge_stuff Badge_info[MAX_BADGES];
182
183 // holds indices into Medals array of the badges for # kills
184 int Badge_index[MAX_BADGES];
185
186 // the rank section of the screen
187 #define RANK_MEDAL_REGION               12                      // region number of the rank medal
188
189 #warning Find real FS2_DEMO spot for medals
190 // coords for indiv medal bitmaps
191 int Medal_coords[GR_NUM_RESOLUTIONS][NUM_MEDALS][2] = {
192         {                               // GR_640
193                 { 89, 47 },                                     // eps. peg. lib
194                 { 486, 47 },                            // imp. order o' vasuda
195                 { 129, 130 },                           // dist flying cross
196                 { 208, 132 },                           // soc service
197                 { 361, 131 },                           // dist intel cross
198                 { 439, 130 },                           // order of galatea
199                 { 64, 234 },                            // meritorious unit comm.
200                 { 153, 234 },                           // medal of valor
201                 { 239, 241 },                           // gtva leg of honor
202                 { 326, 240 },                           // allied defense citation
203                 { 411, 234 },                           // neb campaign victory
204                 { 494, 234 },                           // ntf campaign victory
205                 { 189, 80 },                            // rank
206                 { 283, 91 },                            // wings
207                 { 372, 76 },                            // bronze kills badge
208                 { 403, 76 },                            // silver kills badge
209 #ifndef FS2_DEMO
210                 { 435, 76 },                            // gold kills badge
211                 { 300, 152 },                           // SOC unit crest
212 #endif
213         },
214         {                               // GR_1024
215                 { 143, 75 },                            // eps. peg. lib
216                 { 777, 75 },                            // imp. order o' vasuda
217                 { 206, 208 },                           // dist flying cross
218                 { 333, 212 },                           // soc service
219                 { 578, 210 },                           // dist intel cross
220                 { 703, 208 },                           // order of galatea
221                 { 103, 374 },                           // meritorious unit comm.
222                 { 245, 374 },                           // medal of valor
223                 { 383, 386 },                           // gtva leg of honor
224                 { 522, 384 },                           // allied defense citation
225                 { 658, 374 },                           // neb campaign victory
226                 { 790, 374 },                           // ntf campaign victory
227                 { 302, 128 },                           // rank
228                 { 453, 146 },                           // wings
229                 { 595, 121 },                           // bronze kills badge
230                 { 646, 121 },                           // silver kills badge
231 #ifndef FS2_DEMO
232                 { 696, 121 },                           // gold kills badge
233                 { 480, 244 },                           // SOC unit crest
234 #endif
235         }
236 };
237
238 // coords for the medal title
239 static int Medals_label_coords[GR_NUM_RESOLUTIONS][3] = {
240         { 241, 458, 300 },                      // GR_640 x, y, w
241         { 386, 734, 480 }                               // GR_1024 x, y, w
242 };
243
244 #define MEDALS_NUM_BUTTONS                      1
245 #define MEDALS_EXIT                                     0       
246 ui_button_info Medals_buttons[GR_NUM_RESOLUTIONS][MEDALS_NUM_BUTTONS] = {
247         { // GR_640
248                 ui_button_info("MEB_18",        574,    432,    -1,     -1,     18),
249         },
250         { // GR_1024
251                 ui_button_info("2_MEB_18",      919,    691,    -1,     -1,     18),
252         }
253 };
254
255 #define MEDALS_NUM_TEXT                         1
256 UI_XSTR Medals_text[GR_NUM_RESOLUTIONS][MEDALS_NUM_TEXT] = {
257         {       // GR_640
258                 {"Exit",                1466,           587,    416,    UI_XSTR_COLOR_PINK, -1, &Medals_buttons[GR_640][MEDALS_EXIT].button },
259         },
260         {       // GR_1024
261                 {"Exit",                1466,           943,    673,    UI_XSTR_COLOR_PINK, -1, &Medals_buttons[GR_1024][MEDALS_EXIT].button },
262         },
263 };
264
265 static char* Medals_background_filename[GR_NUM_RESOLUTIONS] = {
266         "MedalsDisplayEmpty",
267         "2_MedalsDisplayEmpty"
268 };
269
270 static char* Medals_mask_filename[GR_NUM_RESOLUTIONS] = {
271         "Medals-m",
272         "2_Medals-m"
273 };
274
275 static int Medals_callsign_y[GR_NUM_RESOLUTIONS] = {
276         54, 89
277 };
278
279 scoring_struct *Player_score=NULL;
280
281 int Medals_mode;
282 player *Medals_player;
283
284 // -----------------------------------------------------------------------------
285 // Main medals screen state
286 //
287 #define NUM_MEDAL_REGIONS                       NUM_MEDALS + 1                          // the extra one is for the rank medal
288
289 static bitmap *Medals_mask;
290 int Medals_mask_w, Medals_mask_h;
291 static int Medal_palette;              // Medal palette bitmap
292 static int Medals_bitmap_mask;         // the mask for the medal case
293 static int Medals_bitmap;              // the medal case itself
294 static int Medal_bitmaps[NUM_MEDALS];  // bitmaps for the individual medals
295 static int Rank_bm;                                                     // bitmap for the rank medal
296
297 static MENU_REGION Medal_regions[NUM_MEDAL_REGIONS]; // a semi-hack for now because we only have 4 medals, but we also include the close button
298
299 static UI_WINDOW Medals_window;
300
301 //#define MAX_MEDALS_BUTTONS                                            1
302 //#define MEDAL_BUTTON_EXIT                                             0
303 //static UI_BUTTON Medal_buttons[MAX_MEDALS_BUTTONS];
304
305 /*static char *Medal_button_names[MAX_MEDALS_BUTTONS] = {
306 //XSTR:OFF
307         "MX_17"
308 //XSTR:ON
309 };
310 */
311 /*
312 static int Medal_button_coords[MAX_MEDALS_BUTTONS][2] = {
313         {561,411}
314 };
315 static int Medal_button_masks[MAX_MEDALS_BUTTONS] = {
316         17
317 };
318 */
319
320
321 #define MEDAL_BITMAP_INIT (1<<0)
322 #define MASK_BITMAP_INIT  (1<<1)
323 int Init_flags;
324
325 void parse_medal_tbl()
326 {
327         int rval, num_medals, i, bi;
328
329         if ((rval = setjmp(parse_abort)) != 0) {
330                 Error(LOCATION, "Error parsing 'medals.tbl'\r\nError code = %i.\r\n", rval);
331         } 
332
333         // open localization
334         lcl_ext_open();
335
336         read_file_text("medals.tbl");
337
338         reset_parse();
339
340         // parse in all the rank names
341         num_medals = 0;
342         bi = 0;
343         required_string("#Medals");
344         while ( required_string_either("#End", "$Name:") ) {
345                 Assert ( num_medals < NUM_MEDALS);
346                 required_string("$Name:");
347                 stuff_string( Medals[num_medals].name, F_NAME, NULL );
348                 required_string("$Bitmap:");
349                 stuff_string( Medals[num_medals].bitmap, F_NAME, NULL );
350                 required_string("$Num mods:");
351                 stuff_int( &Medals[num_medals].num_versions);
352
353                 // some medals are based on kill counts.  When string +Num Kills: is present, we know that
354                 // this medal is a badge and should be treated specially
355                 Medals[num_medals].kills_needed = 0;
356                 if ( optional_string("+Num Kills:") ) {
357                         char buf[MULTITEXT_LENGTH + 1];
358
359                         Assert( bi < MAX_BADGES );
360                         stuff_int( &Medals[num_medals].kills_needed );
361                         Badge_index[bi] = num_medals;
362 #ifdef FS2_DEMO
363 #warning FS2_DEMO HACK: Wavefile 1/2: wave1? wave2?
364                         required_string("$Wavefile 1:");
365                         stuff_string(Badge_info[bi].voice_base, F_NAME, NULL, MAX_FILENAME_LEN);
366                         required_string("$Wavefile 2:");
367                         stuff_string(Badge_info[bi].voice_base, F_NAME, NULL, MAX_FILENAME_LEN);
368                         //stuff_string(Badge_info[bi].wave2, F_NAME, NULL, MAX_FILENAME_LEN);
369 #else
370                         required_string("$Wavefile Base:");
371                         stuff_string(Badge_info[bi].voice_base, F_NAME, NULL, MAX_FILENAME_LEN);
372 #endif                  
373
374                         required_string("$Promotion Text:");
375                         stuff_string(buf, F_MULTITEXT, NULL);
376                         Badge_info[bi].promotion_text = strdup(buf);
377
378                         bi++;
379                 }
380
381                 num_medals++;
382         }
383
384         required_string("#End");
385         Assert( num_medals == NUM_MEDALS );
386
387         // be sure that the badges kill numbers show up in order
388         for (i = 0; i < MAX_BADGES-1; i++ ) {
389                 if ( Medals[Badge_index[i]].kills_needed >= Medals[Badge_index[i+1]].kills_needed ){
390                         Error(LOCATION, "Badges must appear sorted by lowest kill # first in medals.tbl\nFind Allender for most information.");
391                 }
392         }
393
394         // close localization
395         lcl_ext_close();
396 }
397
398 void medal_main_init(player *pl, int mode)
399 {
400         int idx;
401
402         Assert(pl != NULL);
403         Medals_player = pl;
404
405    Player_score = &Medals_player->stats;
406
407         #ifndef NDEBUG
408         if(Cmdline_gimme_all_medals){
409                 //int idx;
410                 for(idx=0; idx < NUM_MEDALS; idx++){
411                         Medals_player->stats.medals[idx] = 1;           
412                 }
413         }
414         #endif
415
416         Medals_mode = mode;
417
418         snazzy_menu_init();
419         Medals_window.create( 0, 0, gr_screen.max_w, gr_screen.max_h, 0 );      
420
421         // create the interface buttons
422         for (idx=0; idx<MEDALS_NUM_BUTTONS; idx++) {
423                 // create the object
424                 Medals_buttons[gr_screen.res][idx].button.create(&Medals_window, "", Medals_buttons[gr_screen.res][idx].x, Medals_buttons[gr_screen.res][idx].y, 1, 1, 0, 1);
425
426                 // set the sound to play when highlighted
427                 Medals_buttons[gr_screen.res][idx].button.set_highlight_action(common_play_highlight_sound);
428
429                 // set the ani for the button
430                 Medals_buttons[gr_screen.res][idx].button.set_bmaps(Medals_buttons[gr_screen.res][idx].filename);
431
432                 // set the hotspot
433                 Medals_buttons[gr_screen.res][idx].button.link_hotspot(Medals_buttons[gr_screen.res][idx].hotspot);
434         }       
435
436         // add all xstrs
437         for (idx=0; idx<MEDALS_NUM_TEXT; idx++) {
438                 Medals_window.add_XSTR(&Medals_text[gr_screen.res][idx]);
439         }
440
441
442         Init_flags = 0; 
443
444         //init_medal_palette();
445         
446         Medals_bitmap = bm_load(Medals_background_filename[gr_screen.res]);
447         if (Medals_bitmap < 0) {
448            Error(LOCATION, "Error loading medal background bitmap %s", Medals_background_filename[gr_screen.res]);
449         } else {
450                 Init_flags |= MEDAL_BITMAP_INIT;
451         }
452
453         Medals_mask_w = -1;
454         Medals_mask_h = -1;
455       
456         Medals_bitmap_mask = bm_load(Medals_mask_filename[gr_screen.res]);
457         if(Medals_bitmap_mask < 0){
458                 Error(LOCATION, "Error loading medal mask file %s", Medals_mask_filename[gr_screen.res]);
459         } else {
460                 Init_flags |= MASK_BITMAP_INIT;
461                 Medals_mask = bm_lock(Medals_bitmap_mask, 8, BMP_AABITMAP);
462                 bm_get_info(Medals_bitmap_mask, &Medals_mask_w, &Medals_mask_h);
463         }
464         init_medal_bitmaps();
465         init_snazzy_regions();
466
467         gr_set_color_fast(&Color_normal);
468
469         Medals_window.set_mask_bmap(Medals_mask_filename[gr_screen.res]);
470 }
471
472 // this is just a hack to display translated names without actually changing the names, 
473 // which would break stuff
474 void medals_translate_name(char *name, int max_len)
475 {
476         if (!strcmp(name, "Epsilon Pegasi Liberation")) {
477                 strncpy(name, "Epsilon Pegasi Befreiungsmedaille", max_len);
478
479         } else if (!strcmp(name, "Imperial Order of Vasuda")) {
480                 strncpy(name, "Imperialer Orden von Vasuda ", max_len);
481
482         } else if (!strcmp(name, "Distinguished Flying Cross")) {
483                 strncpy(name, "Fliegerkreuz Erster Klasse", max_len);
484
485         } else if (!strcmp(name, "SOC Service Medallion")) {
486                 strncpy(name, "SEK-Dienstmedaille ", max_len);
487
488         } else if (!strcmp(name, "Intelligence Cross")) {
489                 strncpy(name, "Geheimdienstkreuz am Bande", max_len);
490
491         } else if (!strcmp(name, "Order of Galatea")) {
492                 strncpy(name, "Orden von Galatea ", max_len);
493
494         } else if (!strcmp(name, "Meritorious Unit Commendation")) {
495                 strncpy(name, "Ehrenspange der Allianz", max_len);
496
497         } else if (!strcmp(name, "Medal of Valor")) {
498                 strncpy(name, "Tapferkeitsmedaille ", max_len);
499
500         } else if (!strcmp(name, "GTVA Legion of Honor")) {
501                 strncpy(name, "Orden der GTVA-Ehrenlegion", max_len);
502
503         } else if (!strcmp(name, "Allied Defense Citation")) {
504                 strncpy(name, "Alliierte Abwehrspange ", max_len);
505
506         } else if (!strcmp(name, "Nebula Campaign Victory Star")) {
507                 strncpy(name, "Nebel-Siegesstern", max_len);
508
509         } else if (!strcmp(name, "NTF Campaign Victory Star")) {
510                 strncpy(name, "NTF-Siegesstern ", max_len);
511
512         } else if (!strcmp(name, "Rank")) {
513                 strncpy(name, "Dienstgrad", max_len);
514
515         } else if (!strcmp(name, "Wings")) {
516                 strncpy(name, "Fliegerspange", max_len);
517
518         } else if (!strcmp(name, "Ace")) {
519                 strncpy(name, "Flieger-As", max_len);   
520
521         } else if (!strcmp(name, "Double Ace")) {
522                 strncpy(name, "Doppel-As ", max_len);
523
524         } else if (!strcmp(name, "Triple Ace")) {
525                 strncpy(name, "Dreifach-As ", max_len);
526                 
527         } else if (!strcmp(name, "SOC Unit Crest")) {
528                 strncpy(name, "SEK-Abzeichen ", max_len);       
529         }
530 }
531
532 void blit_label(char *label, int *coords, int num)
533 {
534         int x, y, sw;
535         char text[256];
536
537         gr_set_color_fast(&Color_bright);
538
539         // translate medal names before displaying
540         // cant translate in table cuz the names are used in comparisons
541         if (Lcl_gr) {
542                 char translated_label[256];
543                 strncpy(translated_label, label, 256);
544                 medals_translate_name(translated_label, 256);
545
546                 // set correct string
547                 if ( num > 1 ) {
548                         sprintf( text, NOX("%s (%d)"), translated_label, num );
549                 } else {
550                         sprintf( text, "%s", translated_label );
551                 }               
552         } else {
553                 // set correct string
554                 if ( num > 1 ) {
555                         sprintf( text, NOX("%s (%d)"), label, num );
556                 } else {
557                         sprintf( text, "%s", label );
558                 }
559         }
560
561         // find correct coords
562         gr_get_string_size(&sw, NULL, text);
563         x = Medals_label_coords[gr_screen.res][0] + (Medals_label_coords[gr_screen.res][2] - sw) / 2;
564         y = Medals_label_coords[gr_screen.res][1];
565
566         // do it
567         gr_string(x, y, text);
568 }
569
570 void blit_callsign()
571 {
572         gr_set_color_fast(&Color_normal);
573
574         // nothing special, just do it.
575         gr_string(0x8000, Medals_callsign_y[gr_screen.res], Medals_player->callsign);
576 }
577
578 int medal_main_do()
579 {
580    int region,selected, k;
581
582         k = Medals_window.process();    
583
584         // process an exit command
585         if ((k == KEY_ESC) && (Medals_mode == MM_NORMAL)) {
586                 gameseq_post_event(GS_EVENT_PREVIOUS_STATE);
587         }
588
589         // draw the background medal display case
590         gr_reset_clip();
591         GR_MAYBE_CLEAR_RES(Medals_bitmap);
592         if(Medals_bitmap != -1){
593                 gr_set_bitmap(Medals_bitmap);
594                 gr_bitmap(0,0);
595         }
596
597         // check to see if a button was pressed
598         if( (k == (KEY_CTRLED|KEY_ENTER)) || (Medals_buttons[gr_screen.res][MEDALS_EXIT].button.pressed()) ) {  
599                 gamesnd_play_iface(SND_COMMIT_PRESSED);
600                 if(Medals_mode == MM_NORMAL){
601                         gameseq_post_event(GS_EVENT_PREVIOUS_STATE);
602                 } else {
603                         // any calling popup function will know to close the screen down
604                         return 0;
605                 }               
606         }
607
608         // blit medals also takes care of blitting the rank insignia
609         blit_medals(); 
610         blit_callsign();        
611         
612         region = snazzy_menu_do((ubyte*)Medals_mask->data, Medals_mask_w, Medals_mask_h, NUM_MEDAL_REGIONS, Medal_regions, &selected);
613         switch (region) {
614                 case ESC_PRESSED:
615                         if (Medals_mode == MM_NORMAL) {
616                                 gameseq_post_event(GS_EVENT_PREVIOUS_STATE);
617                         } else {
618                                 // any calling popup function will know to close the screen down
619                                 return 0;
620                         }
621                         break;
622
623                 case RANK_MEDAL_REGION :
624                         blit_label(Ranks[Player_score->rank].name, &Medal_coords[gr_screen.res][region][0], 1);
625                         break;
626
627                 case -1:
628                         break;
629
630                 default :
631         if (Player_score->medals[region] > 0){
632                                 blit_label(Medals[region].name, &Medal_coords[gr_screen.res][region][0], Player_score->medals[region] );
633                         }
634                         break;
635         } // end switch
636
637         Medals_window.draw();
638
639         gr_flip();
640
641         return 1;
642 }
643
644 void medal_main_close()
645 {
646         int idx;
647         if (Init_flags & MEDAL_BITMAP_INIT)
648                 bm_unload(Medals_bitmap);
649
650         if (Init_flags & MASK_BITMAP_INIT) {
651                 bm_unlock(Medals_bitmap_mask);
652                 bm_unload(Medals_bitmap_mask);
653         }
654
655    for (idx=0; idx < NUM_MEDALS; idx++) {
656                 if (Medal_bitmaps[idx] > -1){
657                         bm_unload(Medal_bitmaps[idx]);
658                 }
659         }
660
661    Player_score = NULL;
662         Medals_window.destroy();
663         snazzy_menu_close();
664         palette_restore_palette();
665 }
666
667 /*
668 void init_medal_palette()
669 {
670         Medal_palette = bm_load("MedalsPalette.pcx");
671         if(Medal_palette > -1){
672 #ifndef HARDWARE_ONLY
673                 palette_use_bm_palette(Medal_palette);
674 #endif
675         }
676 }
677 */
678
679 // function to load in the medals for this player.  It loads medals that the player has (known
680 // by whether or not a non-zero number is present in the player's medal array), then loads the
681 // rank bitmap
682
683 void init_medal_bitmaps()
684 {
685         int idx;
686         Assert(Player_score);
687
688         for (idx=0; idx<NUM_MEDALS; idx++) {
689                 Medal_bitmaps[idx] = -1;
690                 if (Player_score->medals[idx] > 0) {
691                         int num_medals;
692                         char filename[NAME_LENGTH], base[NAME_LENGTH];
693                         
694                         // possibly load a different filename that is specified by the bitmap filename
695                         // for this medal.  if the player has > 1 of these types of medals, then determien
696                         // which of the possible version to use based on the player's count of this medal
697                         strcpy( filename, Medals[idx].bitmap );
698
699                         _splitpath( filename, NULL, NULL, base, NULL );
700
701                         num_medals = Player_score->medals[idx];
702
703                         // can't display more than the maximum number of version for this medal
704                         if ( num_medals > Medals[idx].num_versions )
705                                 num_medals = Medals[idx].num_versions;
706
707                         if ( num_medals > 1 ) {
708                                 // append the proper character onto the end of the medal filename.  Base version
709                                 // has no character. next version is a, then b, etc.
710                                 sprintf( base, "%s%c", base, (num_medals-2)+'a');
711                         }
712         
713                         // hi-res support
714                         if (gr_screen.res == GR_1024) {
715                                 sprintf( filename, "2_%s", base );
716                         }
717
718                         // base now contains the actual medal bitmap filename needed to load
719                         // we don't need to pass extension to bm_load anymore, so just use the basename
720                         // as is.
721          Medal_bitmaps[idx] = bm_load( filename );
722                         Assert( Medal_bitmaps[idx] != -1 );
723                 }
724         }
725
726         // load up rank insignia
727         if (gr_screen.res == GR_1024) {
728                 char filename[NAME_LENGTH];
729                 sprintf(filename, "2_%s", Ranks[Player_score->rank].bitmap);
730                 Rank_bm = bm_load(filename);
731         } else {
732                 Rank_bm = bm_load(Ranks[Player_score->rank].bitmap);
733         }
734 }
735
736 void init_snazzy_regions()
737 {
738         int idx;
739
740         // snazzy regions for the medals/ranks, etc.
741         for (idx=0; idx<NUM_MEDALS; idx++) {
742                 if (idx == RANK_MEDAL_REGION) 
743                         continue;
744
745                 snazzy_menu_add_region(&Medal_regions[idx], "", idx, 0);
746         }
747
748         // add the rank medal region
749         snazzy_menu_add_region(&Medal_regions[RANK_MEDAL_REGION], "", RANK_MEDAL_REGION,0);
750 }
751
752
753 // blit the medals -- this includes the rank insignia
754 void blit_medals()
755 {
756         int idx;
757
758         for (idx=0; idx<NUM_MEDALS; idx++) {
759                 if (Player_score->medals[idx] > 0) {
760                         gr_set_bitmap(Medal_bitmaps[idx]);
761                         gr_bitmap(Medal_coords[gr_screen.res][idx][0], Medal_coords[gr_screen.res][idx][1]);
762                 }
763         }
764
765         // now blit rank, since that "medal" doesnt get loaded (or drawn) the normal way
766         gr_set_bitmap(Rank_bm);
767         gr_bitmap(Medal_coords[gr_screen.res][RANK_MEDAL_REGION][0], Medal_coords[gr_screen.res][RANK_MEDAL_REGION][1]);
768 }
769