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