]> icculus.org git repositories - taylor/freespace2.git/blob - src/stats/medals.cpp
plug memory leaks
[taylor/freespace2.git] / src / stats / medals.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Stats/Medals.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  * 
15  * $Log$
16  * Revision 1.10  2003/06/11 18:30:33  taylor
17  * plug memory leaks
18  *
19  * Revision 1.9  2003/06/03 04:00:40  taylor
20  * Polish language support (Janusz Dziemidowicz)
21  *
22  * Revision 1.8  2003/05/25 02:30:44  taylor
23  * Freespace 1 support
24  *
25  * Revision 1.7  2002/06/09 04:41:27  relnev
26  * added copyright header
27  *
28  * Revision 1.6  2002/06/09 03:16:05  relnev
29  * added _splitpath.
30  *
31  * removed unneeded asm, old sdl 2d setup.
32  *
33  * fixed crash caused by opengl_get_region.
34  *
35  * Revision 1.5  2002/05/28 08:52:03  relnev
36  * implemented two assembly stubs.
37  *
38  * cleaned up a few warnings.
39  *
40  * added a little demo hackery to make it progress a little farther.
41  *
42  * Revision 1.4  2002/05/28 04:56:51  theoddone33
43  * runs a little bit now
44  *
45  * Revision 1.3  2002/05/26 20:22:48  theoddone33
46  * Most of network/ works
47  *
48  * Revision 1.2  2002/05/04 04:36:56  theoddone33
49  * More changes, took out a lot of the sound stuff which will bite later but
50  * I don't care.
51  *
52  * Revision 1.1.1.1  2002/05/03 03:28:11  root
53  * Initial import.
54  *
55  * 
56  * 12    10/29/99 10:40p Jefff
57  * hack to make german medal names display without actually changing them
58  * 
59  * 11    9/02/99 3:41p Jefff
60  * changed badge voice handling to be similar to promotion voice handling
61  * 
62  * 10    8/26/99 8:49p Jefff
63  * Updated medals screen and about everything that ever touches medals in
64  * one way or another.  Sheesh.
65  * 
66  * 9     7/16/99 1:50p Dave
67  * 8 bit aabitmaps. yay.
68  * 
69  * 8     3/19/99 9:51a Dave
70  * Checkin to repair massive source safe crash. Also added support for
71  * pof-style nebulae, and some new weapons code.
72  * 
73  * 8     3/15/99 10:29a Neilk
74  * 
75  * 7     1/30/99 5:08p Dave
76  * More new hi-res stuff.Support for nice D3D textures.
77  * 
78  * 6     12/18/98 1:13a Dave
79  * Rough 1024x768 support for Direct3D. Proper detection and usage through
80  * the launcher.
81  * 
82  * 5     11/30/98 1:07p Dave
83  * 16 bit conversion, first run.
84  * 
85  * 4     10/23/98 3:51p Dave
86  * Full support for tstrings.tbl and foreign languages. All that remains
87  * is to make it active in Fred.
88  * 
89  * 3     10/13/98 9:29a Dave
90  * Started neatening up freespace.h. Many variables renamed and
91  * reorganized. Added AlphaColors.[h,cpp]
92  * 
93  * 2     10/07/98 10:54a Dave
94  * Initial checkin.
95  * 
96  * 1     10/07/98 10:51a Dave
97  * 
98  * 26    6/13/98 3:18p Hoffoss
99  * NOX()ed out a bunch of strings that shouldn't be translated.
100  * 
101  * 25    6/01/98 11:43a John
102  * JAS & MK:  Classified all strings for localization.
103  * 
104  * 24    5/01/98 12:34p John
105  * Added code to force FreeSpace to run in the same dir as exe and made
106  * all the parse error messages a little nicer.
107  * 
108  * 23    4/27/98 3:13p Allender
109  * make ctrl-enter work on medals screen
110  * 
111  * 22    4/23/98 8:27p Allender
112  * basic support for cutscene playback.  Into movie code in place.  Tech
113  * room can view cutscenes stored in CDROM_dir variable
114  * 
115  * 21    4/12/98 8:30p Allender
116  * minor medal changes to show number of medals if > 1
117  * 
118  * 20    4/10/98 4:51p Hoffoss
119  * Made several changes related to tooltips.
120  * 
121  * 19    3/18/98 12:03p John
122  * Marked all the new strings as externalized or not.
123  * 
124  * 18    3/11/98 5:02p Dave
125  * Put in code to support new medals artwork. Assorted multiplayer bug
126  * fixes.
127  * 
128  * 17    3/07/98 5:44p Dave
129  * Finished player info popup. Ironed out a few todo bugs.
130  * 
131  * 16    3/05/98 5:11p Allender
132  * fix up medals screen (again).  Don't do state transition when viewing
133  * medals from debriefing screen.
134  * 
135  * 15    3/05/98 2:32p Hoffoss
136  * Renamed Rank_bitmap to Rank_bm so it isn't named the same as the
137  * variable in the debrief screen which confuses the debugger.
138  * 
139  * 14    2/22/98 2:48p John
140  * More String Externalization Classification
141  * 
142  * 13    2/09/98 5:21p Hoffoss
143  * Made exit from medals screen to previous screen (instead of assuming
144  * it's the barracks) work.
145  * 
146  * 12    1/27/98 4:23p Allender
147  * enhanced internal scoring mechanisms.
148  * 
149  * 11    11/12/97 4:40p Dave
150  * Put in multiplayer campaign support parsing, loading and saving. Made
151  * command-line variables better named. Changed some things on the initial
152  * pilot select screen.
153  * 
154  * 10    11/12/97 9:30a Dave
155  * Fixed rank insignia tooltip not showing up.
156  * 
157  * 9     11/06/97 4:39p Allender
158  * a ton of medal work.  Removed an uneeded elemen in the scoring
159  * structure.  Fix up medals screen to apprioriate display medals (after
160  * mask was changed).  Fix Fred to only display medals which may actually
161  * be granted.  Added image_filename to player struct for Jason Hoffoss
162  * 
163  * 8     11/05/97 4:43p Allender
164  * reworked medal/rank system to read all data from tables.  Made Fred
165  * read medals.tbl.  Changed ai-warp to ai-warp-out which doesn't require
166  * waypoint for activation
167  *
168  * $NoKeywords: $
169  */
170
171
172 #include "medals.h"
173 #include "2d.h"
174 #include "snazzyui.h"
175 #include "bmpman.h"
176 #include "gamesequence.h"
177 #include "animplay.h"
178 #include "mouse.h"
179 #include "freespace.h"
180 #include "scoring.h"
181 #include "player.h"
182 #include "palman.h"
183 #include "ui.h"
184 #include "key.h"
185 #include "cmdline.h"
186 #include "gamesnd.h"
187 #include "alphacolors.h"
188 #include "localize.h"
189 #include "missionscreencommon.h"  // for common_set_interface_palette
190
191 //#define MAX_MEDAL_TYPES 63 // the # of medals which exist so far
192
193 /*
194 #define CALLSIGN_X 198
195 #define CALLSIGN_Y 80
196 #define CALLSIGN_W (439-CALLSIGN_X)
197 #define CALLSIGN_H (116-CALLSIGN_Y)
198 */
199
200 // define for the medal information
201 medal_stuff Medals[NUM_MEDALS];
202 badge_stuff Badge_info[MAX_BADGES];
203
204 // holds indices into Medals array of the badges for # kills
205 int Badge_index[MAX_BADGES];
206
207 // the rank section of the screen
208 #ifdef MAKE_FS1
209         // not in Medal_coords but needs to be set
210         // to not interfere with other medals
211         #define RANK_MEDAL_REGION               16                      // region number of the rank medal
212 #else
213         #define RANK_MEDAL_REGION               12                      // region number of the rank medal
214 #endif
215
216 #warning Find real FS2_DEMO spot for medals
217 // coords for indiv medal bitmaps
218 int Medal_coords[GR_NUM_RESOLUTIONS][NUM_MEDALS][2] = {
219         {                               // GR_640
220 #ifdef MAKE_FS1
221                 { 108, 74 },                            // Conspicuous Gallantry
222                 { 473, 73 },                            // Vasudan Alliance
223                 { 146, 150 },                           // Distinguished Flying Cross
224                 { 219, 152 },                           // Commendation Medal
225                 { 360, 150 },                           // Galatea Survivor
226                 { 432, 150 },                           // Legion of Merit
227                 { 88, 243 },                            // Meritorious Unit
228                 { 168, 243 },                           // Medal of Honor
229                 { 248, 250 },                           // Galactic Service
230                 { 328, 250 },                           // Military Defense
231                 { 406, 244 },                           // Good Conduct
232                 { 483, 243 },                           // Distinguished Service Cross
233                 { 340, 109 },                           // Ace
234                 { 373, 109 },                           // Double Ace
235 #ifndef FS1_DEMO
236                 { 403, 109 },                           // Triple Ace
237 #endif // FS1_DEMO
238                 { 287, 186 },                           // Wings
239 #else
240                 { 89, 47 },                                     // eps. peg. lib
241                 { 486, 47 },                            // imp. order o' vasuda
242                 { 129, 130 },                           // dist flying cross
243                 { 208, 132 },                           // soc service
244                 { 361, 131 },                           // dist intel cross
245                 { 439, 130 },                           // order of galatea
246                 { 64, 234 },                            // meritorious unit comm.
247                 { 153, 234 },                           // medal of valor
248                 { 239, 241 },                           // gtva leg of honor
249                 { 326, 240 },                           // allied defense citation
250                 { 411, 234 },                           // neb campaign victory
251                 { 494, 234 },                           // ntf campaign victory
252                 { 189, 80 },                            // rank
253                 { 283, 91 },                            // wings
254                 { 372, 76 },                            // bronze kills badge
255                 { 403, 76 },                            // silver kills badge
256 #ifndef FS2_DEMO
257                 { 435, 76 },                            // gold kills badge
258                 { 300, 152 },                           // SOC unit crest
259 #endif  // !FS2_DEMO
260 #endif  // MAKE_FS1
261         },
262         {                               // GR_1024
263                 { 143, 75 },                            // eps. peg. lib
264                 { 777, 75 },                            // imp. order o' vasuda
265                 { 206, 208 },                           // dist flying cross
266                 { 333, 212 },                           // soc service
267                 { 578, 210 },                           // dist intel cross
268                 { 703, 208 },                           // order of galatea
269                 { 103, 374 },                           // meritorious unit comm.
270                 { 245, 374 },                           // medal of valor
271                 { 383, 386 },                           // gtva leg of honor
272                 { 522, 384 },                           // allied defense citation
273                 { 658, 374 },                           // neb campaign victory
274                 { 790, 374 },                           // ntf campaign victory
275                 { 302, 128 },                           // rank
276                 { 453, 146 },                           // wings
277                 { 595, 121 },                           // bronze kills badge
278                 { 646, 121 },                           // silver kills badge
279 #if !(defined(FS2_DEMO) || defined(MAKE_FS1))
280                 { 696, 121 },                           // gold kills badge
281                 { 480, 244 },                           // SOC unit crest
282 #endif
283         }
284 };
285
286 #ifdef MAKE_FS1
287 // coords for the medal/rank title
288 static int Rank_label_coords[2] = {
289         240, 126                                // Rank
290 };
291
292 static int Rank_coords[2] = {
293         208, 113                                // Rank
294 };
295
296 // I couldn't think of a better way to do this so define 
297 // the base center point for each medal to center the label on
298 //
299 // x = the horizontal center point of the bitmap
300 // y = the base of the medal bitmap itself
301 static int Medals_label_coords[NUM_MEDALS][2] = {
302         // x, y
303         { 137, 158 },                           // Conspicuous Gallantry
304         { 502, 154 },                           // Vasudan Alliance
305         { 176, 238 },                           // Distinguished Flying Cross
306         { 249, 244 },                           // Commendation Medal
307         { 390, 238 },                           // Galatea Survivor
308         { 462, 237 },                           // Legion of Merit
309         { 121, 345 },                           // Meritorious Unit
310         { 199, 346 },                           // Medal of Honor
311         { 280, 349 },                           // Galactic Service
312         { 360, 350 },                           // Military Defense
313         { 438, 349 },                           // Good Conduct
314         { 517, 353 },                           // Distinguished Service Cross
315         { 352, 129 },                           // Ace
316         { 385, 129 },                           // Double Ace
317 #ifndef FS1_DEMO
318         { 415, 129 },                           // Triple Ace
319 #endif
320         { 319, 216 },                           // Wings
321 };
322 #else
323 // coords for the medal title
324 static int Medals_label_coords[GR_NUM_RESOLUTIONS][3] = {
325         { 241, 458, 300 },                      // GR_640 x, y, w
326         { 386, 734, 480 }                               // GR_1024 x, y, w
327 };
328 #endif
329
330 #define MEDALS_NUM_BUTTONS                      1
331 #define MEDALS_EXIT                                     0       
332 ui_button_info Medals_buttons[GR_NUM_RESOLUTIONS][MEDALS_NUM_BUTTONS] = {
333         { // GR_640
334 #ifdef MAKE_FS1
335                 ui_button_info("MX_17", 561,    411,    -1,     -1,     17),
336 #else
337                 ui_button_info("MEB_18",        574,    432,    -1,     -1,     18),
338 #endif
339         },
340         { // GR_1024
341                 ui_button_info("2_MEB_18",      919,    691,    -1,     -1,     18),
342         }
343 };
344
345 #ifdef MAKE_FS1
346         #define MEDALS_NUM_TEXT                         0
347 #else
348         #define MEDALS_NUM_TEXT                         1
349 #endif
350 UI_XSTR Medals_text[GR_NUM_RESOLUTIONS][MEDALS_NUM_TEXT] = {
351         {       // GR_640
352                 // not needed for FS1
353 #ifndef MAKE_FS1
354                 {"Exit",                1466,           587,    416,    UI_XSTR_COLOR_PINK, -1, &Medals_buttons[GR_640][MEDALS_EXIT].button },
355 #endif
356         },
357         {       // GR_1024
358                 // not needed for FS1
359 #ifndef MAKE_FS1
360                 {"Exit",                1466,           943,    673,    UI_XSTR_COLOR_PINK, -1, &Medals_buttons[GR_1024][MEDALS_EXIT].button },
361 #endif
362         },
363 };
364
365 static char* Medals_background_filename[GR_NUM_RESOLUTIONS] = {
366         "MedalsDisplayEmpty",
367         "2_MedalsDisplayEmpty"
368 };
369
370 static char* Medals_mask_filename[GR_NUM_RESOLUTIONS] = {
371         "Medals-m",
372         "2_Medals-m"
373 };
374
375 static int Medals_callsign_y[GR_NUM_RESOLUTIONS] = {
376 #ifdef MAKE_FS1
377         79, 89
378 #else
379         54, 89
380 #endif
381 };
382
383 scoring_struct *Player_score=NULL;
384
385 int Medals_mode;
386 player *Medals_player;
387
388 // -----------------------------------------------------------------------------
389 // Main medals screen state
390 //
391 #define NUM_MEDAL_REGIONS                       NUM_MEDALS + 1                          // the extra one is for the rank medal
392
393 static bitmap *Medals_mask;
394 int Medals_mask_w, Medals_mask_h;
395 static int Medal_palette;              // Medal palette bitmap
396 static int Medals_bitmap_mask;         // the mask for the medal case
397 static int Medals_bitmap;              // the medal case itself
398 static int Medal_bitmaps[NUM_MEDALS];  // bitmaps for the individual medals
399 static int Rank_bm;                                                     // bitmap for the rank medal
400
401 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
402
403 static UI_WINDOW Medals_window;
404
405 //#define MAX_MEDALS_BUTTONS                                            1
406 //#define MEDAL_BUTTON_EXIT                                             0
407 //static UI_BUTTON Medal_buttons[MAX_MEDALS_BUTTONS];
408
409 /*static char *Medal_button_names[MAX_MEDALS_BUTTONS] = {
410 //XSTR:OFF
411         "MX_17"
412 //XSTR:ON
413 };
414 */
415 /*
416 static int Medal_button_coords[MAX_MEDALS_BUTTONS][2] = {
417         {561,411}
418 };
419 static int Medal_button_masks[MAX_MEDALS_BUTTONS] = {
420         17
421 };
422 */
423
424
425 #define MEDAL_BITMAP_INIT (1<<0)
426 #define MASK_BITMAP_INIT  (1<<1)
427 int Init_flags;
428
429 void parse_medal_tbl()
430 {
431         int rval, num_medals, i, bi;
432
433         if ((rval = setjmp(parse_abort)) != 0) {
434                 Error(LOCATION, "Error parsing 'medals.tbl'\r\nError code = %i.\r\n", rval);
435         } 
436
437         // open localization
438         lcl_ext_open();
439
440         read_file_text("medals.tbl");
441
442         reset_parse();
443
444         // parse in all the rank names
445         num_medals = 0;
446         bi = 0;
447         required_string("#Medals");
448         while ( required_string_either("#End", "$Name:") ) {
449                 Assert ( num_medals < NUM_MEDALS);
450                 required_string("$Name:");
451                 stuff_string( Medals[num_medals].name, F_NAME, NULL );
452                 required_string("$Bitmap:");
453                 stuff_string( Medals[num_medals].bitmap, F_NAME, NULL );
454                 required_string("$Num mods:");
455                 stuff_int( &Medals[num_medals].num_versions);
456
457                 // some medals are based on kill counts.  When string +Num Kills: is present, we know that
458                 // this medal is a badge and should be treated specially
459                 Medals[num_medals].kills_needed = 0;
460                 if ( optional_string("+Num Kills:") ) {
461                         char buf[MULTITEXT_LENGTH + 1];
462
463                         Assert( bi < MAX_BADGES );
464                         stuff_int( &Medals[num_medals].kills_needed );
465                         Badge_index[bi] = num_medals;
466 #ifdef MAKE_FS1
467                         required_string("$Wavefile 1:");
468                         stuff_string(Badge_info[bi].voice_base, F_NAME, NULL, MAX_FILENAME_LEN);
469                         required_string("$Wavefile 2:");
470                         stuff_string(Badge_info[bi].voice_base2, F_NAME, NULL, MAX_FILENAME_LEN);
471 #elif FS2_DEMO
472 #warning FS2_DEMO HACK: Wavefile 1/2: wave1? wave2?
473                         required_string("$Wavefile 1:");
474                         stuff_string(Badge_info[bi].voice_base, F_NAME, NULL, MAX_FILENAME_LEN);
475                         required_string("$Wavefile 2:");
476                         stuff_string(Badge_info[bi].voice_base, F_NAME, NULL, MAX_FILENAME_LEN);
477                         //stuff_string(Badge_info[bi].wave2, F_NAME, NULL, MAX_FILENAME_LEN);
478 #else
479                         required_string("$Wavefile Base:");
480                         stuff_string(Badge_info[bi].voice_base, F_NAME, NULL, MAX_FILENAME_LEN);
481 #endif                  
482
483                         required_string("$Promotion Text:");
484                         stuff_string(buf, F_MULTITEXT, NULL);
485                         Badge_info[bi].promotion_text = strdup(buf);
486
487                         bi++;
488                 }
489
490                 num_medals++;
491         }
492
493         required_string("#End");
494         Assert( num_medals == NUM_MEDALS );
495
496         // be sure that the badges kill numbers show up in order
497         for (i = 0; i < MAX_BADGES-1; i++ ) {
498                 if ( Medals[Badge_index[i]].kills_needed >= Medals[Badge_index[i+1]].kills_needed ){
499                         Error(LOCATION, "Badges must appear sorted by lowest kill # first in medals.tbl\nFind Allender for most information.");
500                 }
501         }
502
503         // close localization
504         lcl_ext_close();
505 }
506
507 void medal_main_init(player *pl, int mode)
508 {
509         int idx;
510
511         Assert(pl != NULL);
512         Medals_player = pl;
513
514    Player_score = &Medals_player->stats;
515
516 #ifndef NDEBUG
517         if(Cmdline_gimme_all_medals){
518                 //int idx;
519                 for(idx=0; idx < NUM_MEDALS; idx++){
520                         Medals_player->stats.medals[idx] = 1;           
521                 }
522         }
523 #endif
524
525         Medals_mode = mode;
526
527         snazzy_menu_init();
528         Medals_window.create( 0, 0, gr_screen.max_w, gr_screen.max_h, 0 );      
529
530         // create the interface buttons
531         for (idx=0; idx<MEDALS_NUM_BUTTONS; idx++) {
532                 // create the object
533                 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);
534
535                 // set the sound to play when highlighted
536                 Medals_buttons[gr_screen.res][idx].button.set_highlight_action(common_play_highlight_sound);
537
538                 // set the ani for the button
539                 Medals_buttons[gr_screen.res][idx].button.set_bmaps(Medals_buttons[gr_screen.res][idx].filename);
540
541                 // set the hotspot
542                 Medals_buttons[gr_screen.res][idx].button.link_hotspot(Medals_buttons[gr_screen.res][idx].hotspot);
543         }       
544
545         // add all xstrs
546         for (idx=0; idx<MEDALS_NUM_TEXT; idx++) {
547                 Medals_window.add_XSTR(&Medals_text[gr_screen.res][idx]);
548         }
549
550
551         Init_flags = 0; 
552
553         //init_medal_palette();
554 #ifdef MAKE_FS1
555         common_set_interface_palette("MedalsPalette");
556 #endif
557         
558         Medals_bitmap = bm_load(Medals_background_filename[gr_screen.res]);
559         if (Medals_bitmap < 0) {
560            Error(LOCATION, "Error loading medal background bitmap %s", Medals_background_filename[gr_screen.res]);
561         } else {
562                 Init_flags |= MEDAL_BITMAP_INIT;
563         }
564
565         Medals_mask_w = -1;
566         Medals_mask_h = -1;
567       
568         Medals_bitmap_mask = bm_load(Medals_mask_filename[gr_screen.res]);
569         if(Medals_bitmap_mask < 0){
570                 Error(LOCATION, "Error loading medal mask file %s", Medals_mask_filename[gr_screen.res]);
571         } else {
572                 Init_flags |= MASK_BITMAP_INIT;
573                 Medals_mask = bm_lock(Medals_bitmap_mask, 8, BMP_AABITMAP);
574                 bm_get_info(Medals_bitmap_mask, &Medals_mask_w, &Medals_mask_h);
575         }
576         init_medal_bitmaps();
577         init_snazzy_regions();
578
579         gr_set_color_fast(&Color_normal);
580
581         Medals_window.set_mask_bmap(Medals_mask_filename[gr_screen.res]);
582 }
583
584 // this is just a hack to display translated names without actually changing the names, 
585 // which would break stuff
586 void medals_translate_name(char *name, int max_len)
587 {
588 #ifdef MAKE_FS1
589         if (!strcmp(name, "Conspicuous Gallantry")) {
590                 strncpy(name, "Tapferkeitsmedaille", max_len);
591
592         } else if (!strcmp(name, "Vasudan Alliance")) {
593                 strncpy(name, "Vasudanischen Allianz", max_len);
594
595         } else if (!strcmp(name, "Distinguished Flying Cross")) {
596                 strncpy(name, "Kreuz f\x81r Fliegerleistungen", max_len);
597
598         } else if (!strcmp(name, "Commendation Medal")) {
599                 strncpy(name, "Anerkennungsmedaille", max_len);
600
601         } else if (!strcmp(name, "Galatea Survivor")) {
602                 strncpy(name, "Galatea-\x9A""berlebender", max_len);
603
604         } else if (!strcmp(name, "Legion of Merit")) {
605                 strncpy(name, "Verdienstlegion", max_len);
606
607         } else if (!strcmp(name, "Meritorious Unit")) {
608                 strncpy(name, "Verdienstmedaille", max_len);
609
610         } else if (!strcmp(name, "Medal of Honor")) {
611                 strncpy(name, "Ehrenmedaille", max_len);
612
613         } else if (!strcmp(name, "Galactic Service")) {
614                 strncpy(name, "Galaktischer Dienst", max_len);
615
616         } else if (!strcmp(name, "Military Defense")) {
617                 strncpy(name, "Verteidigungsmedaille", max_len);
618
619         } else if (!strcmp(name, "Good Conduct")) {
620                 strncpy(name, "Medaille f\x81r gute F\x81hrung", max_len);
621
622         } else if (!strcmp(name, "Distinguished Service Cross")) {
623                 strncpy(name, "Kreuz f\x81r Einsatz", max_len);
624
625         } else if (!strcmp(name, "Ace")) {
626                 strncpy(name, "Bronzener Stern", max_len);
627
628         } else if (!strcmp(name, "Double Ace")) {
629                 strncpy(name, "Silberner Stern", max_len);
630
631         } else if (!strcmp(name, "Triple Ace")) {
632                 strncpy(name, "Goldener Stern", max_len);
633
634         } else if (!strcmp(name, "Wings")) {
635                 strncpy(name, "Pilotenabzeichen", max_len);
636
637         } else if (!strcmp(name, "Rank")) {
638                 strncpy(name, "Dienstgrad", max_len);
639         }
640 #else
641         if (!strcmp(name, "Epsilon Pegasi Liberation")) {
642                 strncpy(name, "Epsilon Pegasi Befreiungsmedaille", max_len);
643
644         } else if (!strcmp(name, "Imperial Order of Vasuda")) {
645                 strncpy(name, "Imperialer Orden von Vasuda ", max_len);
646
647         } else if (!strcmp(name, "Distinguished Flying Cross")) {
648                 strncpy(name, "Fliegerkreuz Erster Klasse", max_len);
649
650         } else if (!strcmp(name, "SOC Service Medallion")) {
651                 strncpy(name, "SEK-Dienstmedaille ", max_len);
652
653         } else if (!strcmp(name, "Intelligence Cross")) {
654                 strncpy(name, "Geheimdienstkreuz am Bande", max_len);
655
656         } else if (!strcmp(name, "Order of Galatea")) {
657                 strncpy(name, "Orden von Galatea ", max_len);
658
659         } else if (!strcmp(name, "Meritorious Unit Commendation")) {
660                 strncpy(name, "Ehrenspange der Allianz", max_len);
661
662         } else if (!strcmp(name, "Medal of Valor")) {
663                 strncpy(name, "Tapferkeitsmedaille ", max_len);
664
665         } else if (!strcmp(name, "GTVA Legion of Honor")) {
666                 strncpy(name, "Orden der GTVA-Ehrenlegion", max_len);
667
668         } else if (!strcmp(name, "Allied Defense Citation")) {
669                 strncpy(name, "Alliierte Abwehrspange ", max_len);
670
671         } else if (!strcmp(name, "Nebula Campaign Victory Star")) {
672                 strncpy(name, "Nebel-Siegesstern", max_len);
673
674         } else if (!strcmp(name, "NTF Campaign Victory Star")) {
675                 strncpy(name, "NTF-Siegesstern ", max_len);
676
677         } else if (!strcmp(name, "Rank")) {
678                 strncpy(name, "Dienstgrad", max_len);
679
680         } else if (!strcmp(name, "Wings")) {
681                 strncpy(name, "Fliegerspange", max_len);
682
683         } else if (!strcmp(name, "Ace")) {
684                 strncpy(name, "Flieger-As", max_len);
685
686         } else if (!strcmp(name, "Double Ace")) {
687                 strncpy(name, "Doppel-As ", max_len);
688
689         } else if (!strcmp(name, "Triple Ace")) {
690                 strncpy(name, "Dreifach-As ", max_len);
691
692         } else if (!strcmp(name, "SOC Unit Crest")) {
693                 strncpy(name, "SEK-Abzeichen ", max_len);
694         }
695 #endif
696 }
697
698 // this is just a hack to display translated names without actually changing the names, 
699 // which would break stuff
700 void medals_translate_name_pl(char *name, int max_len)
701 {
702         if (!strcmp(name, "Epsilon Pegasi Liberation")) {
703                 strncpy(name, "Order Wyzwolenia Epsilon Pegasi", max_len);
704
705         } else if (!strcmp(name, "Imperial Order of Vasuda")) {
706                 strncpy(name, "Imperialny Order Vasudy", max_len);
707
708         } else if (!strcmp(name, "Distinguished Flying Cross")) {
709                 strncpy(name, "Krzy\xBF Wybitnego Pilota", max_len);
710
711         } else if (!strcmp(name, "SOC Service Medallion")) {
712                 strncpy(name, "Krzy\xBF S\xB3u\xBF\x62 Specjalnych", max_len);
713
714         } else if (!strcmp(name, "Intelligence Cross")) {
715                 strncpy(name, "Krzy\xBF Wywiadu", max_len);
716
717         } else if (!strcmp(name, "Order of Galatea")) {
718                 strncpy(name, "Order Galatei", max_len);
719
720         } else if (!strcmp(name, "Meritorious Unit Commendation")) {
721                 strncpy(name, "Medal Pochwalny", max_len);
722
723         } else if (!strcmp(name, "Medal of Valor")) {
724                 strncpy(name, "Medal za Odwag\xEA", max_len);
725
726         } else if (!strcmp(name, "GTVA Legion of Honor")) {
727                 strncpy(name, "Legia Honorowa GTVA", max_len);
728
729         } else if (!strcmp(name, "Allied Defense Citation")) {
730                 strncpy(name, "Order za Obron\xEA Sojuszu", max_len);
731
732         } else if (!strcmp(name, "Nebula Campaign Victory Star")) {
733                 strncpy(name, "Gwiazda Wiktorii Kampanii w Mg\xB3\x61wicy", max_len);
734
735         } else if (!strcmp(name, "NTF Campaign Victory Star")) {
736                 strncpy(name, "Gwiazda Wiktorii Kampanii NTF", max_len);
737
738         } else if (!strcmp(name, "Rank")) {
739                 strncpy(name, "Ranga", max_len);
740
741         } else if (!strcmp(name, "Wings")) {
742                 strncpy(name, "Skrzyd\xB3\x61", max_len);
743
744         } else if (!strcmp(name, "Ace")) {
745                 strncpy(name, "As", max_len);   
746
747         } else if (!strcmp(name, "Double Ace")) {
748                 strncpy(name, "Podw\xF3jny As", max_len);
749
750         } else if (!strcmp(name, "Triple Ace")) {
751                 strncpy(name, "Potr\xF3jny As", max_len);
752                 
753         } else if (!strcmp(name, "SOC Unit Crest")) {
754                 strncpy(name, "Tarcza S\xB3u\xBF\x62 Specjalnych", max_len);    
755         }
756 }
757
758 #ifdef MAKE_FS1
759 void blit_label(char *label, int *coordsx, int *coordsy, int num)
760 #else
761 void blit_label(char *label, int *coords, int num)
762 #endif
763 {
764         int x, y, sw;
765         char text[256];
766
767         gr_set_color_fast(&Color_bright);
768
769         // translate medal names before displaying
770         // cant translate in table cuz the names are used in comparisons
771         if (Lcl_gr) {
772                 char translated_label[256];
773                 strncpy(translated_label, label, 256);
774                 medals_translate_name(translated_label, 256);
775
776                 // set correct string
777                 if ( num > 1 ) {
778                         sprintf( text, NOX("%s (%d)"), translated_label, num );
779                 } else {
780                         sprintf( text, "%s", translated_label );
781                 }
782         } else if(Lcl_pl) {
783                 char translated_label[256];
784                 strncpy(translated_label, label, 256);
785                 medals_translate_name_pl(translated_label, 256);
786
787                 // set correct string
788                 if ( num > 1 ) {
789                         sprintf( text, NOX("%s (%d)"), translated_label, num );
790                 } else {
791                         sprintf( text, "%s", translated_label );
792                 }
793         } else {
794                 // set correct string
795                 if ( num > 1 ) {
796                         sprintf( text, NOX("%s (%d)"), label, num );
797                 } else {
798                         sprintf( text, "%s", label );
799                 }
800         }
801
802         // find correct coords
803         gr_get_string_size(&sw, NULL, text);
804 #ifdef MAKE_FS1
805         x = *coordsx - sw / 2;
806         y = *coordsy + 8;
807 #else
808         x = Medals_label_coords[gr_screen.res][0] + (Medals_label_coords[gr_screen.res][2] - sw) / 2;
809         y = Medals_label_coords[gr_screen.res][1];
810 #endif
811
812         // do it
813         gr_string(x, y, text);
814 }
815
816 void blit_callsign()
817 {
818 #ifdef MAKE_FS1
819         gr_set_color_fast(&Color_bright_blue);
820 #else
821         gr_set_color_fast(&Color_normal);
822 #endif
823
824         // nothing special, just do it.
825         gr_string(0x8000, Medals_callsign_y[gr_screen.res], Medals_player->callsign);
826 }
827
828 int medal_main_do()
829 {
830    int region,selected, k;
831
832         k = Medals_window.process();    
833
834         // process an exit command
835         if ((k == KEY_ESC) && (Medals_mode == MM_NORMAL)) {
836                 gameseq_post_event(GS_EVENT_PREVIOUS_STATE);
837         }
838
839         // draw the background medal display case
840         gr_reset_clip();
841         GR_MAYBE_CLEAR_RES(Medals_bitmap);
842         if(Medals_bitmap != -1){
843                 gr_set_bitmap(Medals_bitmap);
844                 gr_bitmap(0,0);
845         }
846
847         // check to see if a button was pressed
848         if( (k == (KEY_CTRLED|KEY_ENTER)) || (Medals_buttons[gr_screen.res][MEDALS_EXIT].button.pressed()) ) {  
849                 gamesnd_play_iface(SND_COMMIT_PRESSED);
850                 if(Medals_mode == MM_NORMAL){
851                         gameseq_post_event(GS_EVENT_PREVIOUS_STATE);
852                 } else {
853                         // any calling popup function will know to close the screen down
854                         return 0;
855                 }               
856         }
857
858         // blit medals also takes care of blitting the rank insignia
859         blit_medals(); 
860         blit_callsign();        
861         
862         region = snazzy_menu_do((ubyte*)Medals_mask->data, Medals_mask_w, Medals_mask_h, NUM_MEDAL_REGIONS, Medal_regions, &selected);
863         switch (region) {
864                 case ESC_PRESSED:
865                         if (Medals_mode == MM_NORMAL) {
866                                 gameseq_post_event(GS_EVENT_PREVIOUS_STATE);
867                         } else {
868                                 // any calling popup function will know to close the screen down
869                                 return 0;
870                         }
871                         break;
872
873                 case RANK_MEDAL_REGION :
874 #ifdef MAKE_FS1
875                         blit_label(Ranks[Player_score->rank].name, &Rank_label_coords[0], &Rank_label_coords[1], 1);
876 #else
877                         blit_label(Ranks[Player_score->rank].name, &Medal_coords[gr_screen.res][region][0], 1);
878 #endif
879                         break;
880
881                 case -1:
882                         break;
883
884                 default :
885         if (Player_score->medals[region] > 0){
886 #ifdef MAKE_FS1
887                                 blit_label(Medals[region].name, &Medals_label_coords[region][0], &Medals_label_coords[region][1], Player_score->medals[region] );
888 #else
889                                 blit_label(Medals[region].name, &Medal_coords[gr_screen.res][region][0], Player_score->medals[region] );
890 #endif
891                         }
892                         break;
893         } // end switch
894
895         Medals_window.draw();
896
897         gr_flip();
898
899         return 1;
900 }
901
902 void medal_main_close()
903 {
904         int idx;
905         if (Init_flags & MEDAL_BITMAP_INIT)
906                 bm_unload(Medals_bitmap);
907
908         if (Init_flags & MASK_BITMAP_INIT) {
909                 bm_unlock(Medals_bitmap_mask);
910                 bm_unload(Medals_bitmap_mask);
911         }
912
913    for (idx=0; idx < NUM_MEDALS; idx++) {
914                 if (Medal_bitmaps[idx] > -1){
915                         bm_unload(Medal_bitmaps[idx]);
916                 }
917         }
918
919    Player_score = NULL;
920         Medals_window.destroy();
921
922 #ifdef MAKE_FS1
923         common_free_interface_palette();
924 #endif
925
926         snazzy_menu_close();
927         palette_restore_palette();
928 }
929
930 // free up memory from table parsing
931 void medal_tbl_close()
932 {
933         int i;
934         
935         for (i=0; i<MAX_BADGES; i++) {
936                 if (Badge_info[i].promotion_text) {
937                         free(Badge_info[i].promotion_text);
938                         Badge_info[i].promotion_text = NULL;
939                 }
940         }
941 }
942
943 /*
944 void init_medal_palette()
945 {
946         Medal_palette = bm_load("MedalsPalette.pcx");
947         if(Medal_palette > -1){
948 #ifndef HARDWARE_ONLY
949                 palette_use_bm_palette(Medal_palette);
950 #endif
951         }
952 }
953 */
954
955 // function to load in the medals for this player.  It loads medals that the player has (known
956 // by whether or not a non-zero number is present in the player's medal array), then loads the
957 // rank bitmap
958
959 void init_medal_bitmaps()
960 {
961         int idx;
962         Assert(Player_score);
963
964         for (idx=0; idx<NUM_MEDALS; idx++) {
965                 Medal_bitmaps[idx] = -1;
966                 if (Player_score->medals[idx] > 0) {
967                         int num_medals;
968                         char filename[NAME_LENGTH], base[NAME_LENGTH];
969                         
970                         // possibly load a different filename that is specified by the bitmap filename
971                         // for this medal.  if the player has > 1 of these types of medals, then determien
972                         // which of the possible version to use based on the player's count of this medal
973                         strcpy( filename, Medals[idx].bitmap );
974
975                         _splitpath( filename, NULL, NULL, base, NULL );
976
977                         num_medals = Player_score->medals[idx];
978
979                         // can't display more than the maximum number of version for this medal
980                         if ( num_medals > Medals[idx].num_versions )
981                                 num_medals = Medals[idx].num_versions;
982
983                         if ( num_medals > 1 ) {
984                                 // append the proper character onto the end of the medal filename.  Base version
985                                 // has no character. next version is a, then b, etc.
986                                 sprintf( base, "%s%c", base, (num_medals-2)+'a');
987                         }
988         
989                         // hi-res support
990                         if (gr_screen.res == GR_1024) {
991                                 sprintf( filename, "2_%s", base );
992                         }
993
994                         // base now contains the actual medal bitmap filename needed to load
995                         // we don't need to pass extension to bm_load anymore, so just use the basename
996                         // as is.
997          Medal_bitmaps[idx] = bm_load( filename );
998                         Assert( Medal_bitmaps[idx] != -1 );
999                 }
1000         }
1001
1002         // load up rank insignia
1003         if (gr_screen.res == GR_1024) {
1004                 char filename[NAME_LENGTH];
1005                 sprintf(filename, "2_%s", Ranks[Player_score->rank].bitmap);
1006                 Rank_bm = bm_load(filename);
1007         } else {
1008                 Rank_bm = bm_load(Ranks[Player_score->rank].bitmap);
1009         }
1010 }
1011
1012 void init_snazzy_regions()
1013 {
1014         int idx;
1015
1016         // snazzy regions for the medals/ranks, etc.
1017         for (idx=0; idx<NUM_MEDALS; idx++) {
1018                 if (idx == RANK_MEDAL_REGION) 
1019                         continue;
1020
1021                 snazzy_menu_add_region(&Medal_regions[idx], "", idx, 0);
1022         }
1023
1024         // add the rank medal region
1025         snazzy_menu_add_region(&Medal_regions[RANK_MEDAL_REGION], "", RANK_MEDAL_REGION,0);
1026 }
1027
1028
1029 // blit the medals -- this includes the rank insignia
1030 void blit_medals()
1031 {
1032         int idx;
1033
1034         for (idx=0; idx<NUM_MEDALS; idx++) {
1035                 if (Player_score->medals[idx] > 0) {
1036                         gr_set_bitmap(Medal_bitmaps[idx]);
1037                         gr_bitmap(Medal_coords[gr_screen.res][idx][0], Medal_coords[gr_screen.res][idx][1]);
1038                 }
1039         }
1040
1041         // now blit rank, since that "medal" doesnt get loaded (or drawn) the normal way
1042         gr_set_bitmap(Rank_bm);
1043 #ifdef MAKE_FS1
1044         gr_bitmap(Rank_coords[0], Rank_coords[1]);
1045 #else
1046         gr_bitmap(Medal_coords[gr_screen.res][RANK_MEDAL_REGION][0], Medal_coords[gr_screen.res][RANK_MEDAL_REGION][1]);
1047 #endif
1048 }