2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
10 * $Logfile: /Freespace2/code/MenuUI/Barracks.cpp $
15 * C file for implementing barracks section
18 * Revision 1.5 2004/09/20 01:31:44 theoddone33
21 * Revision 1.4 2003/05/25 02:30:42 taylor
24 * Revision 1.3 2002/06/09 04:41:22 relnev
25 * added copyright header
27 * Revision 1.2 2002/05/07 03:16:46 theoddone33
28 * The Great Newline Fix
30 * Revision 1.1.1.1 2002/05/03 03:28:09 root
34 * 42 10/25/99 5:47p Jefff
35 * reassigned some xstr ids
37 * 41 9/14/99 11:01p Jefff
38 * stats area coord fix
40 * 40 9/09/99 11:24a Jefff
42 * 39 9/02/99 11:26a Jefff
43 * fixed incorrect pilot list dimensions
45 * 38 8/17/99 2:24p Dave
46 * Fixed wacky squad color stuff.
48 * 37 8/16/99 4:27p Jefff
49 * fix button position on squad change error popup
51 * 36 8/11/99 3:58p Jefff
52 * fixed player list box coord bug
54 * 35 8/05/99 2:46p Jefff
55 * added popup to the disabled squad selection buttons in single player
57 * 34 8/02/99 11:02p Dave
58 * Fixed up squad filename and squad name copying when converting a pilot
59 * between single and multiplayer.
61 * 33 7/27/99 7:17p Jefff
62 * Replaced some art text with XSTR() text.
64 * 32 7/15/99 9:20a Andsager
65 * FS2_DEMO initial checkin
67 * 31 6/29/99 7:39p Dave
68 * Lots of small bug fixes.
70 * 30 6/16/99 4:06p Dave
71 * New pilot info popup. Added new draw-bitmap-as-poly function.
73 * 29 6/11/99 11:13a Dave
74 * last minute changes before press tour build.
76 * 28 4/25/99 7:43p Dave
77 * Misc small bug fixes. Made sun draw properly.
79 * 27 4/25/99 3:02p Dave
80 * Build defines for the E3 build.
82 * 26 3/24/99 4:05p Dave
83 * Put in support for assigning the player to a specific squadron with a
84 * specific logo. Preliminary work for doing pos/orient checksumming in
85 * multiplayer to reduce bandwidth.
87 * 25 2/25/99 4:19p Dave
88 * Added multiplayer_beta defines. Added cd_check define. Fixed a few
89 * release build warnings. Added more data to the squad war request and
92 * 24 2/02/99 12:09p Neilk
93 * Fixed text coords, centered pilot and squad pics in 1024x768, added vss
100 #include "managepilot.h"
107 #include "playermenu.h"
108 #include "gamesequence.h"
109 #include "contexthelp.h"
112 #include "freespace.h"
113 #include "systemvars.h"
116 #include "osregistry.h"
117 #include "alphacolors.h"
119 void delete_pilot_file( char *pilot_name, int single ); // manage_pilot.cpp
122 #define NUM_STAT_LINES 85
123 #define STAT_COLUMN1_W 40
124 #define STAT_COLUMN2_W 10
126 static int Stat_column1_w[GR_NUM_RESOLUTIONS] =
132 static int Stat_column2_w[GR_NUM_RESOLUTIONS] =
138 // constants for coordinate lookup
139 #define BARRACKS_X_COORD 0
140 #define BARRACKS_Y_COORD 1
141 #define BARRACKS_W_COORD 2
142 #define BARRACKS_H_COORD 3
146 // pilot selection field
147 static int Barracks_list_coords[GR_NUM_RESOLUTIONS][4] = {
161 static int Barracks_stats_coords[GR_NUM_RESOLUTIONS][4] = {
174 static int Barracks_stats2_coords[GR_NUM_RESOLUTIONS][3] = {
176 276, 212, 81 // X2, , W2
179 286, 351, 81 // X2, , W2
183 // pilot picture field
184 static int Barracks_image_coords[GR_NUM_RESOLUTIONS][4] = {
197 // pilot picture # of # location
198 static int Barracks_image_number_coords[GR_NUM_RESOLUTIONS][2] = {
215 // pilot squad logo field
216 int Barracks_squad_coords[GR_NUM_RESOLUTIONS][4] = {
225 // pilot squad # of # location
226 int Barracks_squad_number_coords[GR_NUM_RESOLUTIONS][2] = {
237 #define BARRACKS_NUM_BUTTONS 17
239 #define BARRACKS_NUM_BUTTONS 19
242 // pilot selection buttons
243 #define B_PILOT_CREATE_BOTTON 0 // B_PILOT_CREATE_BOTTON
244 #define B_PILOT_SCROLL_UP_BUTTON 1 // B_PILOT_SCROLL_UP_BUTTON
245 #define B_PILOT_SCROLL_DOWN_BUTTON 2 // B_PILOT_SCROLL_DOWN_BUTTON
246 #define B_PILOT_DELETE_BUTTON 11 // B_PILOT_B_PILOT_DELETE_BUTTON
247 #define B_PILOT_SET_ACTIVE_BUTTON 12 // B_PILOT_B_PILOT_SET_ACTIVE_BUTTON
248 #define B_PILOT_CLONE_BUTTON 13 // B_PILOT_B_PILOT_CLONE_BUTTON
249 #define B_PILOT_SINGLE_MODE_BUTTON 14 // B_PILOT_SINGLE_MODE_BUTTON
250 #define B_PILOT_MULTI_MODE_BUTTON 15 // B_PILOT_MULTI_MODE_BUTTON
251 #define B_PILOT_CONVERT_BUTTON 16 // B_PILOT_B_PILOT_CONVERT_BUTTON
254 // squad logo picture buttons
255 #define B_SQUAD_PREV_BUTTON 17
256 #define B_SQUAD_NEXT_BUTTON 18
259 // pilot picture buttons
260 #define B_PIC_PREV_PILOT_BUTTON 3 // B_PILOT_B_PIC_PREV_PILOT_BUTTON
261 #define B_PIC_NEXT_PILOT_BUTTON 4 // B_PILOT_B_PIC_NEXT_PILOT_BUTTON
263 // pilot stat buttons
264 #define B_STATS_MEDAL_BUTTON 8 // B_STATS_MEDAL_BUTTON
265 #define B_STATS_SCROLL_DOWN_BUTTON 9 // B_STATS_SCROLL_DOWN_BUTTON
266 #define B_STATS_SCROLL_UP_BUTTON 10 // B_STATS_SCROLL_UP_BUTTON
269 #define B_ACCEPT_BUTTON 5 // B_B_ACCEPT_BUTTON
270 #define B_HELP_BUTTON 6 // B_B_HELP_BUTTON
271 #define B_OPTION_BUTTON 7 // B_OPTION_BUTTON
275 static char *Barracks_bitmap_fname[GR_NUM_RESOLUTIONS] = {
276 "Barracks", // GR_640
277 "2_Barracks" // GR_1024
280 static char *Barracks_bitmap_mask_fname[GR_NUM_RESOLUTIONS] = {
281 "Barracks-M", // GR_640
282 "2_Barracks-M" // GR_1024
287 #define BARRACKS_IMAGE_NOT_LOADED -2
289 struct barracks_bitmaps {
295 struct barracks_buttons {
298 int text_x, text_y; // this is where the text label is
301 UI_BUTTON button; // because we have a class inside this struct, we need the constructor below..
303 barracks_buttons(char *name, int x1, int y1, int x2, int y2, int h, int r = 0) : filename(name), x(x1), y(y1), text_x(x2), text_y(y2), hotspot(h), repeat(r) {}
306 #if defined(MAKE_FS1) && !defined(FS1_DEMO)
307 static int Background_bitmap;
308 static int PilotWin01 = -1;
309 static int PilotWin02 = -1;
310 static int PilotWin03 = -1;
311 static int PilotWin04 = -1;
313 static int Background_bitmap = -1;
315 static UI_WINDOW Ui_window;
316 static UI_BUTTON List_region;
317 static UI_INPUTBOX Inputbox;
319 static barracks_buttons Buttons[GR_NUM_RESOLUTIONS][BARRACKS_NUM_BUTTONS] = {
323 barracks_buttons("BAB_00", 12, 121, -1, -1, 0), // create
324 barracks_buttons("BAB_01", 322, 137, -1, -1, 1, 1), // barracks - arrow up
325 barracks_buttons("BAB_02", 347, 137, -1, -1, 2, 1), // barracks - arrow down
327 barracks_buttons("BAB_03", 570, 140, -1, -1, 3, 1), // pilot window - arrow left
328 barracks_buttons("BAB_04", 591, 140, -1, -1, 4, 1), // pilot window - arrow right
330 barracks_buttons("BAB_03", 570, 157, -1, -1, 3, 1), // pilot window - arrow left
331 barracks_buttons("BAB_04", 591, 157, -1, -1, 4, 1), // pilot window - arrow right
333 barracks_buttons("BAB_05", 562, 410, -1, -1, 5), // accept
334 barracks_buttons("BAB_06", 469, 427, -1, -1, 6), // help
335 barracks_buttons("BAB_07", 447, 452, -1, -1, 7), // options
336 barracks_buttons("BAB_08", 365, 415, -1, -1, 8), // medals
337 barracks_buttons("BAB_09", 0, 225, -1, -1, 9, 1), // pilot stats - arrows down
338 barracks_buttons("BAB_10", 0, 185, -1, -1, 10, 1), // pilot stats - arrows up
339 barracks_buttons("BAB_11", 124, 121, -1, -1, 11), // remove
340 barracks_buttons("BAB_12", 374, 127, -1, -1, 12), // barracks - accept
341 barracks_buttons("BAB_13", 70, 121, -1, -1, 13), // clone
342 barracks_buttons("BAB_14", 329, 13, -1, -1, 14), // single
343 barracks_buttons("BAB_15", 380, 13, -1, -1, 15), // multi
344 barracks_buttons("BAB_16", 183, 121, -1, -1, 16) // convert
346 barracks_buttons("BAB_00", 8, 122, 11, 157, 0),
347 barracks_buttons("BAB_01", 323, 130, 0, 0, 1, 1),
348 barracks_buttons("BAB_02", 350, 130, 0, 0, 2, 1),
349 barracks_buttons("BAB_03", 559, 143, 0, 0, 3, 1),
350 barracks_buttons("BAB_04", 598, 143, 0, 0, 4, 1),
351 barracks_buttons("BAB_05", 571, 425, 578, 413, 5),
352 barracks_buttons("BAB_06", 533, 425, 500, 438, 6),
353 barracks_buttons("BAB_07", 533, 453, 481, 465, 7),
354 barracks_buttons("BAB_08", 361, 425, 401, 465, 8),
355 barracks_buttons("BAB_09", 0, 267, 0, 0, 9, 1),
356 barracks_buttons("BAB_10", 0, 224, 0, 0, 10,1),
357 barracks_buttons("BAB_11", 120, 122, 123, 157, 11),
358 barracks_buttons("BAB_12", 376, 124, 378, 163, 12),
359 barracks_buttons("BAB_13", 66, 122, 69, 157, 13),
360 barracks_buttons("BAB_14", 323, 0, 324, 25, 14),
361 barracks_buttons("BAB_15", 372, 0, 374, 25, 15),
362 barracks_buttons("BAB_16", 180, 122, 182, 157, 16),
363 barracks_buttons("BAB_17", 559, 306, 0, 0, 17),
364 barracks_buttons("BAB_18", 598, 306, 0, 0, 18)
368 barracks_buttons("2_BAB_00", 14, 196, 35, 252, 0),
369 barracks_buttons("2_BAB_01", 518, 209, 0, 0, 1, 1),
370 barracks_buttons("2_BAB_02", 561, 209, 0, 0, 2, 1),
371 barracks_buttons("2_BAB_03", 896, 229, 0, 0, 3, 1),
372 barracks_buttons("2_BAB_04", 958, 229, 0, 0, 4, 1),
373 barracks_buttons("2_BAB_05", 914, 681, 932, 665, 5),
374 barracks_buttons("2_BAB_06", 854, 681, 800, 704, 6),
375 barracks_buttons("2_BAB_07", 854, 724, 778, 743, 7),
376 barracks_buttons("2_BAB_08", 579, 681, 641, 743, 8),
377 barracks_buttons("2_BAB_09", 0, 428, 0, 0, 9, 1),
378 barracks_buttons("2_BAB_10", 0, 360, 0, 0, 10,1),
379 barracks_buttons("2_BAB_11", 193, 196, 214, 252, 11),
380 barracks_buttons("2_BAB_12", 602, 200, 617, 262, 12),
381 barracks_buttons("2_BAB_13", 107, 196, 128, 252, 13),
382 barracks_buttons("2_BAB_14", 517, 0, 532, 40, 14),
383 barracks_buttons("2_BAB_15", 596, 0, 614, 40, 15),
384 barracks_buttons("2_BAB_16", 289, 196, 309, 252, 16),
386 barracks_buttons("2_BAB_17", 896, 491, 0, 0, 17),
387 barracks_buttons("2_BAB_18", 958, 491, 0, 0, 18)
394 // FIXME add to strings.tbl, set correct coords
396 #define BARRACKS_NUM_TEXT 0
398 #define BARRACKS_NUM_TEXT 2
400 UI_XSTR Barracks_text[GR_NUM_RESOLUTIONS][BARRACKS_NUM_TEXT] = {
406 { "Barracks", 1434, 17, 7, UI_XSTR_COLOR_GREEN, -1, NULL },
407 { "Pilot Stats", 1435, 17, 180, UI_XSTR_COLOR_GREEN, -1, NULL }
415 { "Barracks", 1434, 27, 11, UI_XSTR_COLOR_GREEN, -1, NULL },
416 { "Pilot Stats", 1435, 27, 288, UI_XSTR_COLOR_GREEN, -1, NULL }
422 static int Num_stat_lines;
423 static char Stat_labels[NUM_STAT_LINES][STAT_COLUMN1_W];
424 static char Stats[NUM_STAT_LINES][STAT_COLUMN2_W];
426 extern int Player_sel_mode;
428 static player *Cur_pilot;
429 static int Num_pilots;
430 static int Selected_line;
431 static char Pilots_arr[MAX_PILOTS][MAX_FILENAME_LEN];
432 static char *Pilots[MAX_PILOTS];
433 static int Pic_number;
434 static int Pic_squad_number;
435 static bool Barracks_callsign_enter_mode;
436 static int Pilot_ranks[MAX_PILOTS];
437 static int List_scroll_offset;
438 static int Stats_scroll_offset;
439 static int Clone_flag;
440 static int Pilot_images[MAX_PILOT_IMAGES];
441 static int Pilot_squad_images[MAX_PILOT_IMAGES];
442 static int Rank_pips_bitmaps;
443 static int Rank_pips_count;
445 void barracks_squad_change_popup();
448 // -------------------------------------------------------------------------------------------------
453 #define STRCPY1(a, b) do { \
454 Assert(strlen(b) < STAT_COLUMN1_W); \
458 void barracks_init_stats(scoring_struct *stats)
465 STRCPY1(Stat_labels[Num_stat_lines], XSTR( "*All Time Stats", 50));
466 Stats[Num_stat_lines][0] = 0;
469 Assert(Num_stat_lines < NUM_STAT_LINES);
470 Stat_labels[Num_stat_lines][0] = 0;
471 Stats[Num_stat_lines][0] = 0;
474 Assert(Num_stat_lines < NUM_STAT_LINES);
475 STRCPY1(Stat_labels[Num_stat_lines], XSTR( "Primary weapon shots:", 51));
476 sprintf(Stats[Num_stat_lines], "%d", stats->p_shots_fired);
479 Assert(Num_stat_lines < NUM_STAT_LINES);
480 STRCPY1(Stat_labels[Num_stat_lines], XSTR( "Primary weapon hits:", 52));
481 sprintf(Stats[Num_stat_lines], "%d", stats->p_shots_hit);
484 Assert(Num_stat_lines < NUM_STAT_LINES);
485 STRCPY1(Stat_labels[Num_stat_lines], XSTR( "Primary friendly hits:", 53));
486 sprintf(Stats[Num_stat_lines], "%d", stats->p_bonehead_hits);
489 Assert(Num_stat_lines < NUM_STAT_LINES);
490 STRCPY1(Stat_labels[Num_stat_lines], XSTR( "Primary hit %:", 54));
491 if (stats->p_shots_fired > 0) {
492 f = (float) stats->p_shots_hit * 100.0f / (float) stats->p_shots_fired;
496 sprintf(Stats[Num_stat_lines], XSTR( "%.1f%%", 55), f);
499 Assert(Num_stat_lines < NUM_STAT_LINES);
500 STRCPY1(Stat_labels[Num_stat_lines], XSTR( "Primary friendly hit %:", 56));
501 if (stats->p_bonehead_hits > 0) {
502 f = (float) stats->p_bonehead_hits * 100.0f / (float) stats->p_shots_fired;
506 sprintf(Stats[Num_stat_lines], XSTR( "%.1f%%", 55), f);
509 Assert(Num_stat_lines < NUM_STAT_LINES);
510 Stat_labels[Num_stat_lines][0] = 0;
511 Stats[Num_stat_lines][0] = 0;
514 Assert(Num_stat_lines < NUM_STAT_LINES);
515 STRCPY1(Stat_labels[Num_stat_lines], XSTR( "Secondary weapon shots:", 57));
516 sprintf(Stats[Num_stat_lines], "%d", stats->s_shots_fired);
519 Assert(Num_stat_lines < NUM_STAT_LINES);
520 STRCPY1(Stat_labels[Num_stat_lines], XSTR( "Secondary weapon hits:", 58));
521 sprintf(Stats[Num_stat_lines], "%d", stats->s_shots_hit);
524 Assert(Num_stat_lines < NUM_STAT_LINES);
525 STRCPY1(Stat_labels[Num_stat_lines], XSTR( "Secondary friendly hits:", 59));
526 sprintf(Stats[Num_stat_lines], "%d", stats->s_bonehead_hits);
529 Assert(Num_stat_lines < NUM_STAT_LINES);
530 STRCPY1(Stat_labels[Num_stat_lines], XSTR( "Secondary hit %:", 60));
531 if (stats->s_shots_fired > 0) {
532 f = (float) stats->s_shots_hit * 100.0f / (float) stats->s_shots_fired;
536 sprintf(Stats[Num_stat_lines], XSTR( "%.1f%%", 55), f);
539 Assert(Num_stat_lines < NUM_STAT_LINES);
540 STRCPY1(Stat_labels[Num_stat_lines], XSTR( "Secondary friendly hit %:", 61));
541 if (stats->s_bonehead_hits > 0) {
542 f = (float) stats->s_bonehead_hits * 100.0f / (float) stats->s_shots_fired;
546 sprintf(Stats[Num_stat_lines], XSTR( "%.1f%%", 55), f);
549 Assert(Num_stat_lines < NUM_STAT_LINES);
550 Stat_labels[Num_stat_lines][0] = 0;
551 Stats[Num_stat_lines][0] = 0;
554 Assert(Num_stat_lines < NUM_STAT_LINES);
555 STRCPY1(Stat_labels[Num_stat_lines], XSTR( "Total kills:", 62));
556 sprintf(Stats[Num_stat_lines], "%d", stats->kill_count_ok);
559 Assert(Num_stat_lines < NUM_STAT_LINES);
560 STRCPY1(Stat_labels[Num_stat_lines], XSTR( "Assists:", 63));
561 sprintf(Stats[Num_stat_lines], "%d", stats->assists);
564 Assert(Num_stat_lines < NUM_STAT_LINES);
565 Stat_labels[Num_stat_lines][0] = 0;
566 Stats[Num_stat_lines][0] = 0;
569 Assert(Num_stat_lines < NUM_STAT_LINES);
570 Stat_labels[Num_stat_lines][0] = 0;
571 Stats[Num_stat_lines][0] = 0;
574 STRCPY1(Stat_labels[Num_stat_lines], XSTR( "*Kills by Ship Type", 64));
575 Stats[Num_stat_lines][0] = 0;
578 Assert(Num_stat_lines < NUM_STAT_LINES);
579 Stat_labels[Num_stat_lines][0] = 0;
580 Stats[Num_stat_lines][0] = 0;
583 for (i=0; i<Num_ship_types; i++) {
584 if (stats->kills[i]) {
585 Assert(Num_stat_lines < NUM_STAT_LINES);
586 Assert(strlen(Ship_info[i].name) + 1 < STAT_COLUMN1_W);
587 sprintf(Stat_labels[Num_stat_lines], NOX("%s:"), Ship_info[i].name);
588 sprintf(Stats[Num_stat_lines], "%d", stats->kills[i]);
593 for (i=0; i<Num_stat_lines; i++) {
594 gr_force_fit_string(Stat_labels[i], Stat_column1_w[gr_screen.res], Barracks_stats_coords[gr_screen.res][BARRACKS_W_COORD]);
595 gr_force_fit_string(Stats[i], Stat_column2_w[gr_screen.res], Barracks_stats2_coords[gr_screen.res][BARRACKS_W_COORD]);
599 // sets or clears hotkeys for pilot selection.
600 void barracks_set_hotkeys(bool pilot_text_enter_mode)
602 Buttons[gr_screen.res][B_PILOT_SCROLL_UP_BUTTON].button.set_hotkey(pilot_text_enter_mode ? KEY_UP : -1);
603 Buttons[gr_screen.res][B_PILOT_SCROLL_DOWN_BUTTON].button.set_hotkey(pilot_text_enter_mode ? KEY_DOWN : -1);
605 Buttons[gr_screen.res][B_PILOT_CREATE_BOTTON].button.set_hotkey(pilot_text_enter_mode ? KEY_C : -1);
606 Buttons[gr_screen.res][B_PILOT_SET_ACTIVE_BUTTON].button.set_hotkey(pilot_text_enter_mode ? KEY_ENTER : -1);
607 Buttons[gr_screen.res][B_PILOT_DELETE_BUTTON].button.set_hotkey(pilot_text_enter_mode ? KEY_DELETE : -1);
609 Buttons[gr_screen.res][B_PIC_PREV_PILOT_BUTTON].button.set_hotkey(pilot_text_enter_mode ? KEY_LEFT : -1);
610 Buttons[gr_screen.res][B_PIC_NEXT_PILOT_BUTTON].button.set_hotkey(pilot_text_enter_mode ? KEY_RIGHT : -1);
612 Buttons[gr_screen.res][B_ACCEPT_BUTTON].button.set_hotkey(pilot_text_enter_mode ? KEY_CTRLED | KEY_ENTER : -1);
615 // strip the possible .pcx extension off a filename
616 void barracks_strip_pcx(char *str)
618 int flen = strlen(str);
620 if ((flen > 4) && !stricmp(str + flen - elen, ".pcx")) {
621 str[flen - elen] = '\0';
625 // new pilot name has focus, so update stats/pic to that pilot
626 int barracks_new_pilot_selected()
628 char stripped[MAX_FILENAME_LEN+1] = "";
630 // save the previous pilot first, so changes to it are kept
631 if (strlen(Cur_pilot->callsign)) {
635 // check if we have a valid pilot hilighted. If so, attempt to active it
636 if ((Num_pilots < 1) || (Selected_line < 0) || (Selected_line >= Num_pilots)) {
637 Cur_pilot->callsign[0] = 0; // this indicates no pilot active
641 if (read_pilot_file(Pilots[Selected_line], !Player_sel_mode, Cur_pilot)) {
642 Cur_pilot->callsign[0] = 0; // this indicates no pilot active
646 // init stuff to reflect new pilot
648 barracks_init_stats(&Cur_pilot->stats);
649 for (i=0; i<Num_pilot_images; i++) {
650 strcpy(stripped, Cur_pilot->image_filename);
651 barracks_strip_pcx(stripped);
652 if (!stricmp(stripped, Pilot_image_names[i])) {
657 for ( i=0; i<Num_pilot_squad_images; i++) {
658 strcpy(stripped, Cur_pilot->squad_filename);
659 barracks_strip_pcx(stripped);
660 if (!stricmp(stripped, Pilot_squad_image_names[i])) {
664 Pic_squad_number = i;
669 void barracks_set_callsign_enter_mode(bool set_callsign_enter_mode)
671 // set global mode variable
672 Barracks_callsign_enter_mode = set_callsign_enter_mode;
674 // disable/enable all buttons
675 for (int idx=0; idx<BARRACKS_NUM_BUTTONS; idx++) {
676 // don't ever mess with the prev and next squad logo buttons
678 Buttons[gr_screen.res][idx].button.enable(!set_callsign_enter_mode);
680 if((idx != B_SQUAD_PREV_BUTTON) && (idx != B_SQUAD_NEXT_BUTTON)){
681 Buttons[gr_screen.res][idx].button.enable(!set_callsign_enter_mode);
686 // enable/disable hotkeys
687 barracks_set_hotkeys(!set_callsign_enter_mode);
688 // disable/enable inputbox
689 Inputbox.enable(set_callsign_enter_mode);
690 // hide/unhide inputbox
691 Inputbox.hide(!set_callsign_enter_mode);
694 // creates a new pilot file
695 void barracks_create_new_pilot()
697 // check if too many pilots
698 if (Num_pilots >= MAX_PILOTS) {
699 gamesnd_play_iface(SND_GENERAL_FAIL);
703 // play sound for pilot creation
704 gamesnd_play_iface(SND_SCROLL);
706 // only write pilot file if there is an active pilot
707 if (strlen(Player->callsign)) {
711 // move other pilot names and ranks down to make room for the new one
712 int idx = Num_pilots;
713 Assert(Num_pilots >= 0);
715 strcpy(Pilots[idx + 1], Pilots[idx]);
716 Pilot_ranks[idx + 1] = Pilot_ranks[idx];
721 Pilots[Selected_line][0] = 0;
722 Pilot_ranks[Selected_line] = 0;
723 List_scroll_offset = 0;
725 // set mode to accept pilot name text
726 barracks_set_callsign_enter_mode(true);
727 // set focus to input box
728 Inputbox.set_focus();
729 // set initial pilot name to ""
730 Inputbox.set_text("");
731 // reset size of input box to only 1 line
732 Inputbox.update_dimensions(Barracks_list_coords[gr_screen.res][BARRACKS_X_COORD], Barracks_list_coords[gr_screen.res][BARRACKS_Y_COORD], Barracks_list_coords[gr_screen.res][BARRACKS_W_COORD], gr_get_font_height());
735 // exiting screen without canceling, so load in the new pilot selected here
736 int barracks_pilot_accepted()
738 char str[CALLSIGN_LEN + 1];
740 // check if pilot active. If not, don't allow accept.
741 if (!Cur_pilot->callsign[0]){
746 player_set_squad_bitmap(Cur_pilot, Cur_pilot->squad_filename);
748 // Skill_level = get_default_skill_level();
750 // MWA -- I think that we should be writing Cur_pilot here.
751 //write_pilot_file(!is_pilot_multi(Cur_pilot));
752 write_pilot_file( Cur_pilot );
754 // when we store the LastPlayer key, we have to mark it as being single or multiplayer, so we know where to look for him
755 // (since we could have a single and a multiplayer pilot with the same callsign)
756 // we'll distinguish them by putting an M and the end of the multiplayer callsign and a P at the end of a single player
757 strcpy(str, Cur_pilot->callsign);
758 strcat(str, is_pilot_multi(Cur_pilot) ? NOX("M") : NOX("S"));
759 os_config_write_string( NULL, "LastPlayer", str );
763 // scroll up barracks pilot list one line
764 void barracks_scroll_callsign_up()
766 if (Selected_line > 0) {
768 gamesnd_play_iface(SND_SCROLL);
770 gamesnd_play_iface(SND_GENERAL_FAIL);
773 if ((Selected_line >= 0) && (Selected_line < List_scroll_offset)) {
774 List_scroll_offset = Selected_line;
778 // scroll down barracks pilot list one line
779 void barracks_scroll_callsign_down()
781 if (Selected_line < Num_pilots - 1) {
783 gamesnd_play_iface(SND_SCROLL);
785 gamesnd_play_iface(SND_GENERAL_FAIL);
788 // num_pilots_to_fill_height is the number of pilots that can fit in given height
789 int num_pilots_to_fill_height = Barracks_list_coords[gr_screen.res][BARRACKS_H_COORD] / gr_get_font_height();
790 if (Selected_line >= List_scroll_offset + num_pilots_to_fill_height) {
791 List_scroll_offset++;
795 // scroll up barracks stats list one line
796 void barracks_scroll_stats_up()
798 if (Stats_scroll_offset > 0) {
799 Stats_scroll_offset--;
800 gamesnd_play_iface(SND_SCROLL);
802 gamesnd_play_iface(SND_GENERAL_FAIL);
806 // scroll down barracks stats list one line
807 void barracks_scroll_stats_down()
809 int font_height = gr_get_font_height();
811 if (Stats_scroll_offset + Barracks_stats_coords[gr_screen.res][BARRACKS_H_COORD] / font_height < Num_stat_lines) {
812 Stats_scroll_offset++;
813 gamesnd_play_iface(SND_SCROLL);
815 gamesnd_play_iface(SND_GENERAL_FAIL);
819 // show previous pilot pic
820 void barracks_prev_pic()
822 // check if no pilot images or no pilot selected
823 if ((Num_pilot_images == 0) || (Cur_pilot->callsign[0] == '\0')) {
824 gamesnd_play_iface(SND_GENERAL_FAIL);
828 // reset pilot pic number
830 if (Pic_number < 0) {
831 Pic_number = Num_pilot_images - 1;
834 // copy pilot pic filename into pilot struct
835 if ((Pic_number >= 0) && (Pic_number < Num_pilot_images)) {
836 strcpy(Cur_pilot->image_filename, Pilot_image_names[Pic_number]);
840 gamesnd_play_iface(SND_SCROLL);
843 // show next pilot pic
844 void barracks_next_pic()
846 // check if no pilot images or no pilot selected
847 if ((Num_pilot_images == 0) || (Cur_pilot->callsign[0] == '\0')) {
848 gamesnd_play_iface(SND_GENERAL_FAIL);
852 // reset pilot pic number
854 if (Pic_number >= Num_pilot_images){
858 // copy pilot pic filename into pilot struct
859 if ((Pic_number >= 0) && (Pic_number < Num_pilot_images)){
860 strcpy(Cur_pilot->image_filename, Pilot_image_names[Pic_number]);
864 gamesnd_play_iface(SND_SCROLL);
867 // show previous squad pic
868 void barracks_prev_squad_pic()
870 // check if no pilot images or no pilot selected
871 if ((Num_pilot_squad_images == 0) || (Cur_pilot->callsign[0] == '\0')) {
872 gamesnd_play_iface(SND_GENERAL_FAIL);
876 // reset pilot pic number
878 if (Pic_squad_number < 0) {
879 Pic_squad_number = Num_pilot_squad_images - 1;
882 // copy pilot pic filename into pilot struct
883 if ((Pic_squad_number >= 0) && (Pic_squad_number < Num_pilot_squad_images)) {
884 strcpy(Cur_pilot->squad_filename, Pilot_squad_image_names[Pic_squad_number]);
888 gamesnd_play_iface(SND_SCROLL);
891 // show next pilot pic
892 void barracks_next_squad_pic()
894 // check if no pilot images or no pilot selected
895 if ((Num_pilot_squad_images == 0) || (Cur_pilot->callsign[0] == '\0')) {
896 gamesnd_play_iface(SND_GENERAL_FAIL);
900 // reset pilot pic number
902 if (Pic_squad_number >= Num_pilot_squad_images){
903 Pic_squad_number = 0;
906 // copy pilot pic filename into pilot struct
907 if ((Pic_squad_number >= 0) && (Pic_squad_number < Num_pilot_squad_images)){
908 strcpy(Cur_pilot->squad_filename, Pilot_squad_image_names[Pic_squad_number]);
912 gamesnd_play_iface(SND_SCROLL);
915 void barracks_delete_pilot()
917 char buf[MAX_FILENAME_LEN];
921 gamesnd_play_iface(SND_GENERAL_FAIL);
925 int popup_rval = popup(PF_TITLE_BIG | PF_TITLE_RED, 2, POPUP_NO, POPUP_YES, XSTR( "Warning!\n\nAre you sure you wish to delete this pilot?", 65));
926 if (popup_rval != 1) {
930 if (!stricmp(Pilots[Selected_line], Cur_pilot->callsign)) {
934 strcpy(buf, Pilots[Selected_line]);
935 for (int i=Selected_line; i<Num_pilots-1; i++) {
936 strcpy(Pilots[i], Pilots[i + 1]);
937 Pilot_ranks[i] = Pilot_ranks[i + 1];
941 if (Selected_line >= Num_pilots) {
942 Selected_line = Num_pilots - 1;
946 if (Selected_line >= 0) {
947 barracks_new_pilot_selected();
949 Cur_pilot->callsign[0] = 0;
953 delete_pilot_file(buf, Player_sel_mode == PLAYER_SELECT_MODE_SINGLE ? 1 : 0);
954 gamesnd_play_iface(SND_USER_SELECT);
957 // Filter out pilots of wrong type (which shouldn't be in the directory we are checking, but just to be safe..)
958 int barracks_pilot_filter(char *filename)
962 r = verify_pilot_file(filename, Player_sel_mode == PLAYER_SELECT_MODE_SINGLE, &rank);
963 if (rank >= Rank_pips_count)
964 rank = Rank_pips_count - 1;
967 Pilot_ranks[Num_pilots++] = rank;
973 // callback handler for the squadon selection buttons when they are disabled (in single player)
974 void barracks_squad_change_popup()
977 popup( PF_USE_AFFIRMATIVE_ICON | PF_NO_NETWORKING, 1, POPUP_OK, XSTR("You cannot change your squadron in Single Player mode.", 1445));
981 void barracks_init_player_stuff(int mode)
983 // determine if we should be looking for single or multiplayers at the outset
984 Player_sel_mode = mode;
986 // get the list of pilots based upon whether we're in single or multiplayer mode
988 Get_file_list_filter = barracks_pilot_filter;
990 // single player specific stuff
991 if (mode == PLAYER_SELECT_MODE_SINGLE) {
992 Num_pilots = cf_get_file_list_preallocated(MAX_PILOTS, Pilots_arr, Pilots, CF_TYPE_SINGLE_PLAYERS, NOX("*.plr"), CF_SORT_TIME);
995 // disable squad logo switching
996 Buttons[gr_screen.res][B_SQUAD_PREV_BUTTON].button.hide();
997 Buttons[gr_screen.res][B_SQUAD_PREV_BUTTON].button.disable();
998 Buttons[gr_screen.res][B_SQUAD_PREV_BUTTON].button.set_disabled_action(barracks_squad_change_popup);
999 Buttons[gr_screen.res][B_SQUAD_NEXT_BUTTON].button.hide();
1000 Buttons[gr_screen.res][B_SQUAD_NEXT_BUTTON].button.disable();
1001 Buttons[gr_screen.res][B_SQUAD_NEXT_BUTTON].button.set_disabled_action(barracks_squad_change_popup);
1004 // multiplayer specific stuff
1006 Num_pilots = cf_get_file_list_preallocated(MAX_PILOTS, Pilots_arr, Pilots, CF_TYPE_MULTI_PLAYERS, NOX("*.plr"), CF_SORT_TIME);
1009 // enable squad logo switching
1010 Buttons[gr_screen.res][B_SQUAD_PREV_BUTTON].button.enable();
1011 Buttons[gr_screen.res][B_SQUAD_PREV_BUTTON].button.unhide();
1012 Buttons[gr_screen.res][B_SQUAD_NEXT_BUTTON].button.enable();
1013 Buttons[gr_screen.res][B_SQUAD_NEXT_BUTTON].button.unhide();
1017 int ranks[MAX_PILOTS];
1019 for (int i=0; i<Num_pilots; i++) {
1021 for (j=0; j<Num_pilots; j++) {
1022 if (!strcmp(Pilots[i], Pilots_arr[j])) {
1023 ranks[i] = Pilot_ranks[j];
1027 Assert(j < Num_pilots); // Pilot not found? How is that possible?
1030 for (int i=0; i<Num_pilots; i++) {
1031 Pilot_ranks[i] = ranks[i];
1034 Selected_line = List_scroll_offset = 0;
1035 barracks_new_pilot_selected();
1039 void barracks_button_pressed(int n)
1042 case B_PILOT_SCROLL_UP_BUTTON:
1043 barracks_scroll_callsign_up();
1046 case B_PILOT_SCROLL_DOWN_BUTTON:
1047 barracks_scroll_callsign_down();
1050 case B_STATS_SCROLL_UP_BUTTON:
1051 barracks_scroll_stats_up();
1054 case B_STATS_SCROLL_DOWN_BUTTON:
1055 barracks_scroll_stats_down();
1058 case B_PIC_PREV_PILOT_BUTTON:
1059 barracks_prev_pic();
1062 case B_PIC_NEXT_PILOT_BUTTON:
1063 barracks_next_pic();
1067 case B_SQUAD_PREV_BUTTON:
1068 barracks_prev_squad_pic();
1071 case B_SQUAD_NEXT_BUTTON:
1072 barracks_next_squad_pic();
1076 case B_PILOT_SET_ACTIVE_BUTTON:
1077 if (barracks_new_pilot_selected()){
1078 gamesnd_play_iface(SND_GENERAL_FAIL);
1080 // throw up a popup telling the player that he should create a pilot first
1081 if(Player_sel_mode == PLAYER_SELECT_MODE_SINGLE){
1082 popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR( "You must create a single player pilot.", 66));
1084 popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR( "You must create a multi player pilot.", 67));
1087 gamesnd_play_iface(SND_SCROLL);
1091 case B_ACCEPT_BUTTON:
1092 if (Num_pilots && !barracks_pilot_accepted()) {
1093 gamesnd_play_iface(SND_COMMIT_PRESSED);
1094 gameseq_post_event(GS_EVENT_MAIN_MENU);
1096 gamesnd_play_iface(SND_GENERAL_FAIL);
1098 // throw up a popup telling the player that he should create a pilot first
1099 if(Player_sel_mode == PLAYER_SELECT_MODE_SINGLE){
1100 popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR( "You must create a single player pilot.", 66));
1102 popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR( "You must create a multi player pilot.", 67));
1107 case B_PILOT_CLONE_BUTTON:
1108 if (Num_pilots < 1) {
1109 gamesnd_play_error_beep();
1114 barracks_create_new_pilot();
1117 case B_PILOT_CONVERT_BUTTON: {
1118 #if defined(DEMO) || defined(OEM_BUILD)
1119 game_feature_not_in_demo_popup();
1121 char temp[256], *str;
1122 char old_pic[256] = "";
1123 char old_squad_pic[256] = "";
1124 char old_squad[256] = "";
1127 if (!barracks_new_pilot_selected()) {
1128 if (Player_sel_mode == PLAYER_SELECT_MODE_SINGLE)
1129 str = XSTR( "multiplayer", 68);
1131 str = XSTR( "single player", 69);
1133 sprintf(temp, XSTR( "This will overwrite your %s pilot. Proceed?", 70), str);
1134 if (!verify_pilot_file(Cur_pilot->callsign, Player_sel_mode == PLAYER_SELECT_MODE_MULTI)) {
1135 z = popup(0, 2, POPUP_CANCEL, POPUP_OK, temp);
1140 strcpy(old_pic, Cur_pilot->image_filename);
1141 strcpy(old_squad_pic, Cur_pilot->squad_filename);
1142 strcpy(old_squad, Cur_pilot->squad_name);
1143 init_new_pilot(Cur_pilot, 0);
1144 strcpy(Cur_pilot->image_filename, old_pic);
1145 strcpy(Cur_pilot->squad_filename, old_squad_pic);
1146 strcpy(Cur_pilot->squad_name, old_squad);
1147 if (Player_sel_mode == PLAYER_SELECT_MODE_SINGLE) {
1148 Cur_pilot->flags |= PLAYER_FLAGS_IS_MULTI;
1150 barracks_init_player_stuff(PLAYER_SELECT_MODE_MULTI);
1154 barracks_init_player_stuff(PLAYER_SELECT_MODE_SINGLE);
1157 gamesnd_play_iface(SND_USER_SELECT);
1160 gamesnd_play_iface(SND_GENERAL_FAIL);
1166 case B_PILOT_CREATE_BOTTON:
1168 barracks_create_new_pilot();
1172 launch_context_help();
1173 gamesnd_play_iface(SND_HELP_PRESSED);
1176 case B_OPTION_BUTTON:
1177 gamesnd_play_iface(SND_SWITCH_SCREENS);
1178 gameseq_post_event(GS_EVENT_OPTIONS_MENU);
1181 case B_STATS_MEDAL_BUTTON:
1182 #if defined(FS2_DEMO) || defined(FS1_DEMO)
1183 game_feature_not_in_demo_popup();
1185 gamesnd_play_iface(SND_SWITCH_SCREENS);
1186 gameseq_post_event(GS_EVENT_VIEW_MEDALS);
1190 case B_PILOT_DELETE_BUTTON:
1191 barracks_delete_pilot();
1194 case B_PILOT_SINGLE_MODE_BUTTON:
1195 if (Player_sel_mode != PLAYER_SELECT_MODE_SINGLE) {
1196 gamesnd_play_iface(SND_USER_SELECT);
1197 barracks_init_player_stuff(PLAYER_SELECT_MODE_SINGLE);
1201 case B_PILOT_MULTI_MODE_BUTTON:
1202 #if defined(DEMO) || defined(OEM_BUILD) // not for FS2_DEMO
1203 game_feature_not_in_demo_popup();
1205 if (Player_sel_mode != PLAYER_SELECT_MODE_MULTI) {
1206 gamesnd_play_iface(SND_USER_SELECT);
1207 barracks_init_player_stuff(PLAYER_SELECT_MODE_MULTI);
1215 void barracks_display_pilot_callsigns(int prospective_pilot)
1218 int cur_pilot_idx = List_scroll_offset;
1221 if (Player_sel_mode == PLAYER_SELECT_MODE_MULTI) {
1225 int font_height = gr_get_font_height();
1226 while (y + font_height <= Barracks_list_coords[gr_screen.res][BARRACKS_H_COORD]) {
1227 if (cur_pilot_idx >= Num_pilots)
1230 if (!stricmp(Cur_pilot->callsign, Pilots[cur_pilot_idx]) && (is_pilot_multi(Cur_pilot) == multi)) {
1231 if ((cur_pilot_idx == Selected_line) || (cur_pilot_idx == prospective_pilot)) {
1232 gr_set_color_fast(&Color_text_active_hi);
1234 gr_set_color_fast(&Color_text_active);
1237 if (cur_pilot_idx == Selected_line) {
1238 gr_set_color_fast(&Color_text_selected);
1239 } else if (cur_pilot_idx == prospective_pilot) {
1240 gr_set_color_fast(&Color_text_subselected);
1242 gr_set_color_fast(&Color_text_normal);
1246 gr_printf(Barracks_list_coords[gr_screen.res][BARRACKS_X_COORD], Barracks_list_coords[gr_screen.res][BARRACKS_Y_COORD] + y, Pilots[cur_pilot_idx]);
1248 gr_set_bitmap(Rank_pips_bitmaps + Pilot_ranks[cur_pilot_idx], GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
1249 gr_bitmap(Barracks_list_coords[gr_screen.res][BARRACKS_X_COORD] - 34, Barracks_list_coords[gr_screen.res][BARRACKS_Y_COORD] + y);
1259 void barracks_display_pilot_stats()
1262 int z = Stats_scroll_offset;
1263 int font_height = gr_get_font_height();
1266 while (y + font_height <= Barracks_stats_coords[gr_screen.res][BARRACKS_H_COORD]) {
1267 if (z >= Num_stat_lines) {
1271 str = Stat_labels[z];
1273 gr_set_color_fast(&Color_text_heading);
1276 gr_get_string_size(&w, &h, str);
1277 i = Barracks_stats_coords[gr_screen.res][BARRACKS_Y_COORD] + y + h / 2 - 1;
1278 gr_line(Barracks_stats_coords[gr_screen.res][BARRACKS_X_COORD], i, Barracks_stats_coords[gr_screen.res][BARRACKS_X_COORD] + Barracks_stats_coords[gr_screen.res][BARRACKS_W_COORD] - w - 2, i);
1279 gr_line(Barracks_stats_coords[gr_screen.res][BARRACKS_X_COORD] + Barracks_stats_coords[gr_screen.res][BARRACKS_W_COORD] + 1, i, Barracks_stats2_coords[gr_screen.res][BARRACKS_X_COORD] + Barracks_stats2_coords[gr_screen.res][BARRACKS_W_COORD], i);
1282 gr_set_color_fast(&Color_text_normal);
1285 gr_get_string_size(&w, NULL, str);
1286 gr_printf(Barracks_stats_coords[gr_screen.res][BARRACKS_X_COORD] + Barracks_stats_coords[gr_screen.res][BARRACKS_W_COORD] - w, Barracks_stats_coords[gr_screen.res][BARRACKS_Y_COORD] + y, "%s", str);
1289 gr_printf(Barracks_stats2_coords[gr_screen.res][BARRACKS_X_COORD], Barracks_stats_coords[gr_screen.res][BARRACKS_Y_COORD] + y, "%s", str);
1298 // process pilot callsign
1299 void barracks_accept_new_pilot_callsign()
1301 char buf[CALLSIGN_LEN + 1];
1302 char name[MAX_FILENAME_LEN];
1306 Inputbox.get_text(buf);
1307 drop_white_space(buf);
1309 if (!isalpha(*buf)) {
1312 for (i=1; buf[i]; i++) {
1313 if (!isalpha(buf[i]) && !isdigit(buf[i]) && !strchr(VALID_PILOT_CHARS, buf[i])) {
1320 for (i=1; i<Num_pilots; i++) {
1321 if (!stricmp(buf, Pilots[i])) {
1323 if (pilot_verify_overwrite() == 1) {
1324 strcpy(name, Pilots[Selected_line]);
1325 for (z=i; z<Num_pilots-1; z++) {
1326 strcpy(Pilots[z], Pilots[z + 1]);
1327 Pilot_ranks[z] = Pilot_ranks[z + 1];
1331 delete_pilot_file(name, Player_sel_mode == PLAYER_SELECT_MODE_SINGLE ? 1 : 0);
1338 if (!*buf || (i < Num_pilots)) { // duplicate name, alert user
1343 gamesnd_play_iface(SND_GENERAL_FAIL);
1347 strcpy(Pilots[0], buf);
1348 strcpy(Cur_pilot->callsign, buf);
1349 init_new_pilot(Cur_pilot, !Clone_flag);
1351 // again, make sure we set his flags correctly to ensure that he gets saved to the proper directory and gets
1352 // displayed correctly
1353 if (Player_sel_mode == PLAYER_SELECT_MODE_SINGLE) {
1354 Cur_pilot->flags &= ~(PLAYER_FLAGS_IS_MULTI);
1356 Cur_pilot->flags |= PLAYER_FLAGS_IS_MULTI;
1357 Cur_pilot->stats.flags |= STATS_FLAG_MULTIPLAYER;
1360 if ( !(Game_mode & GM_STANDALONE_SERVER) ) {
1361 write_pilot_file(Cur_pilot);
1365 barracks_new_pilot_selected();
1366 barracks_set_callsign_enter_mode(false);
1370 // draw pilot image and clean up afterwards
1371 void barracks_draw_pilot_pic()
1374 if (Cur_pilot->callsign[0] && (Pic_number >= 0) && (Pic_number < Num_pilot_images)) {
1375 if (Pilot_images[Pic_number] >= 0) {
1376 // JAS: This code is hacked to allow the animation to use all 256 colors
1377 extern int Palman_allow_any_color;
1378 Palman_allow_any_color = 1;
1379 gr_set_bitmap(Pilot_images[Pic_number], GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
1380 gr_bitmap(Barracks_image_coords[gr_screen.res][BARRACKS_X_COORD], Barracks_image_coords[gr_screen.res][BARRACKS_Y_COORD]);
1381 Palman_allow_any_color = 0;
1383 // print number of the current pic
1385 sprintf(buf, XSTR( "%d of %d", 71), Pic_number + 1, Num_pilot_images);
1386 gr_printf(Barracks_image_number_coords[gr_screen.res][BARRACKS_X_COORD], Barracks_image_number_coords[gr_screen.res][BARRACKS_Y_COORD], buf);
1393 // draw squad image and clean up afterwards
1394 void barracks_draw_squad_pic()
1399 if (Cur_pilot->callsign[0] && (Pic_squad_number >= 0) && (Pic_squad_number < Num_pilot_squad_images)) {
1400 if (Pilot_squad_images[Pic_squad_number] >= 0) {
1401 // JAS: This code is hacked to allow the animation to use all 256 colors
1402 extern int Palman_allow_any_color;
1403 Palman_allow_any_color = 1;
1404 gr_set_bitmap(Pilot_squad_images[Pic_squad_number], GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
1405 gr_bitmap(Barracks_squad_coords[gr_screen.res][BARRACKS_X_COORD], Barracks_squad_coords[gr_screen.res][BARRACKS_Y_COORD]);
1406 Palman_allow_any_color = 0;
1408 // print number of current squad pic
1409 if(Player_sel_mode != PLAYER_SELECT_MODE_SINGLE){
1410 sprintf(buf,XSTR( "%d of %d", 71), Pic_squad_number+1, Num_pilot_squad_images);
1411 gr_printf(Barracks_squad_number_coords[gr_screen.res][BARRACKS_X_COORD], Barracks_squad_number_coords[gr_screen.res][BARRACKS_Y_COORD], buf);
1415 Pic_squad_number = -1;
1419 // -----------------------------------------------------------------------------
1420 void barracks_init()
1423 UI_WINDOW *w = &Ui_window;
1426 // save current pilot file, so we don't possibly loose it.
1430 Ui_window.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);
1431 Ui_window.set_mask_bmap(Barracks_bitmap_mask_fname[gr_screen.res]);
1433 // load background bitmap
1434 Background_bitmap = bm_load(Barracks_bitmap_fname[gr_screen.res]);
1435 if(Background_bitmap < 0){
1436 // we failed to load the bitmap - this is very bad
1441 for (int i=0; i<BARRACKS_NUM_BUTTONS; i++) {
1442 // create the object
1443 Buttons[gr_screen.res][i].button.create(&Ui_window, "", Buttons[gr_screen.res][i].x, Buttons[gr_screen.res][i].y, 60, 30, Buttons[gr_screen.res][i].repeat, 1);
1445 // set the sound to play when highlighted
1446 Buttons[gr_screen.res][i].button.set_highlight_action(common_play_highlight_sound);
1448 // set the ani for the button
1449 Buttons[gr_screen.res][i].button.set_bmaps(Buttons[gr_screen.res][i].filename);
1452 Buttons[gr_screen.res][i].button.link_hotspot(Buttons[gr_screen.res][i].hotspot);
1457 w->add_XSTR("Create", 1034, Buttons[gr_screen.res][0].text_x, Buttons[gr_screen.res][0].text_y, &Buttons[gr_screen.res][0].button, UI_XSTR_COLOR_GREEN);
1458 w->add_XSTR("Accept", 1035, Buttons[gr_screen.res][5].text_x, Buttons[gr_screen.res][5].text_y, &Buttons[gr_screen.res][5].button, UI_XSTR_COLOR_PINK);
1459 w->add_XSTR("Help", 928, Buttons[gr_screen.res][6].text_x, Buttons[gr_screen.res][6].text_y, &Buttons[gr_screen.res][6].button, UI_XSTR_COLOR_GREEN);
1460 w->add_XSTR("Options",1036, Buttons[gr_screen.res][7].text_x, Buttons[gr_screen.res][7].text_y, &Buttons[gr_screen.res][7].button, UI_XSTR_COLOR_GREEN);
1461 w->add_XSTR("Medals", 1037, Buttons[gr_screen.res][8].text_x, Buttons[gr_screen.res][8].text_y, &Buttons[gr_screen.res][8].button, UI_XSTR_COLOR_GREEN);
1462 w->add_XSTR("Remove", 1038, Buttons[gr_screen.res][11].text_x, Buttons[gr_screen.res][11].text_y, &Buttons[gr_screen.res][11].button, UI_XSTR_COLOR_GREEN);
1463 w->add_XSTR("Select", 1552, Buttons[gr_screen.res][12].text_x, Buttons[gr_screen.res][12].text_y, &Buttons[gr_screen.res][12].button, UI_XSTR_COLOR_GREEN);
1464 w->add_XSTR("Clone", 1040, Buttons[gr_screen.res][13].text_x, Buttons[gr_screen.res][13].text_y, &Buttons[gr_screen.res][13].button, UI_XSTR_COLOR_GREEN);
1465 w->add_XSTR("Single", 1041, Buttons[gr_screen.res][14].text_x, Buttons[gr_screen.res][14].text_y, &Buttons[gr_screen.res][14].button, UI_XSTR_COLOR_GREEN);
1466 w->add_XSTR("Multi", 1042, Buttons[gr_screen.res][15].text_x, Buttons[gr_screen.res][15].text_y, &Buttons[gr_screen.res][15].button, UI_XSTR_COLOR_GREEN);
1467 w->add_XSTR("Convert",1043, Buttons[gr_screen.res][16].text_x, Buttons[gr_screen.res][16].text_y, &Buttons[gr_screen.res][16].button, UI_XSTR_COLOR_GREEN);
1468 for(int i=0; i<BARRACKS_NUM_TEXT; i++) {
1469 w->add_XSTR(&Barracks_text[gr_screen.res][i]);
1473 // button for selecting pilot
1474 List_region.create(&Ui_window, "", Barracks_list_coords[gr_screen.res][BARRACKS_X_COORD], Barracks_list_coords[gr_screen.res][BARRACKS_Y_COORD], Barracks_list_coords[gr_screen.res][BARRACKS_W_COORD], Barracks_list_coords[gr_screen.res][BARRACKS_H_COORD], 0, 1);
1477 // create input box (for new pilot)
1478 Inputbox.create(&Ui_window, Barracks_list_coords[gr_screen.res][BARRACKS_X_COORD], Barracks_list_coords[gr_screen.res][BARRACKS_Y_COORD], Barracks_list_coords[gr_screen.res][BARRACKS_W_COORD], CALLSIGN_LEN - 1, "", UI_INPUTBOX_FLAG_INVIS | UI_INPUTBOX_FLAG_KEYTHRU | UI_INPUTBOX_FLAG_LETTER_FIRST);
1479 Inputbox.set_valid_chars(VALID_PILOT_CHARS);
1483 // load in help overlay bitmap
1484 help_overlay_load(BARRACKS_OVERLAY);
1485 help_overlay_set_state(BARRACKS_OVERLAY,0);
1488 Barracks_callsign_enter_mode = 0;
1489 List_scroll_offset = Stats_scroll_offset = Pic_number = Pic_squad_number = Selected_line = 0;
1490 Cur_pilot = &Players[Player_num];
1492 // disable squad logo selection buttons in single player
1494 if(!(Cur_pilot->flags & PLAYER_FLAGS_IS_MULTI)){
1495 // squad logo picture buttons
1496 Buttons[gr_screen.res][B_SQUAD_PREV_BUTTON].button.hide();
1497 Buttons[gr_screen.res][B_SQUAD_PREV_BUTTON].button.disable();
1498 Buttons[gr_screen.res][B_SQUAD_NEXT_BUTTON].button.hide();
1499 Buttons[gr_screen.res][B_SQUAD_NEXT_BUTTON].button.disable();
1501 // squad logo picture buttons
1502 Buttons[gr_screen.res][B_SQUAD_PREV_BUTTON].button.enable();
1503 Buttons[gr_screen.res][B_SQUAD_PREV_BUTTON].button.unhide();
1504 Buttons[gr_screen.res][B_SQUAD_NEXT_BUTTON].button.enable();
1505 Buttons[gr_screen.res][B_SQUAD_NEXT_BUTTON].button.unhide();
1509 // set up hotkeys for buttons so we draw the correct animation frame when a key is pressed
1510 barracks_set_hotkeys(1);
1514 Rank_pips_bitmaps = bm_load_animation("IconRankMini.ani", &Rank_pips_count);
1517 // load up the pilot pic list
1518 pilot_load_pic_list();
1519 pilot_load_squad_pic_list();
1521 // don't load pilot images yet
1522 for (int i=0; i<MAX_PILOT_IMAGES; i++) {
1523 Pilot_images[i] = BARRACKS_IMAGE_NOT_LOADED; // while -1 is can't load
1524 Pilot_squad_images[i] = BARRACKS_IMAGE_NOT_LOADED;
1528 barracks_init_stats(&Cur_pilot->stats);
1530 // disable some buttons for the multiplayer beta and e3 build
1531 #if defined(MULTIPLAYER_BETA_BUILD) || defined(E3_BUILD) || defined(PRESS_TOUR_BUILD)
1532 Buttons[gr_screen.res][B_PILOT_CLONE_BUTTON].button.hide();
1533 Buttons[gr_screen.res][B_PILOT_CONVERT_BUTTON].button.hide();
1534 Buttons[gr_screen.res][B_PILOT_CLONE_BUTTON].button.disable();
1535 Buttons[gr_screen.res][B_PILOT_CONVERT_BUTTON].button.disable();
1538 // multiplayer beta build
1539 #ifdef MULTIPLAYER_BETA_BUILD
1540 Buttons[gr_screen.res][B_PILOT_SINGLE_MODE_BUTTON].button.hide();
1541 Buttons[gr_screen.res][B_PILOT_SINGLE_MODE_BUTTON].button.disable();
1545 #if defined(E3_BUILD) || defined(PRESS_TOUR_BUILD)
1546 Buttons[gr_screen.res][B_PILOT_MULTI_MODE_BUTTON].button.hide();
1547 Buttons[gr_screen.res][B_PILOT_MULTI_MODE_BUTTON].button.disable();
1550 // base the mode we're in (single or multi) on the status of the currently selected pilot
1551 #ifdef MULTIPLAYER_BETA_BUILD
1552 barracks_init_player_stuff(1);
1553 #elif defined(E3_BUILD) || defined(PRESS_TOUR_BUILD)
1554 barracks_init_player_stuff(0);
1556 barracks_init_player_stuff(is_pilot_multi(Player));
1559 #if defined(MAKE_FS1) && !defined(FS1_DEMO)
1560 PilotWin01 = bm_load(NOX("PilotWin01"));
1561 PilotWin02 = bm_load(NOX("PilotWin02"));
1562 PilotWin03 = bm_load(NOX("PilotWin03"));
1563 PilotWin04 = bm_load(NOX("PilotWin04"));
1567 // -----------------------------------------------------------------------------
1568 void barracks_do_frame(float frametime)
1570 int k = Ui_window.process();
1573 if ( help_overlay_active(BARRACKS_OVERLAY) ) {
1574 help_overlay_set_state(BARRACKS_OVERLAY,0);
1579 // pilot that mouse is over
1580 int prospective_pilot = -1;
1583 // Entering pilot callsign
1584 if (Barracks_callsign_enter_mode) {
1585 // set focus to inputbox
1586 Inputbox.set_focus();
1590 // cancel create pilot
1592 for (i=0; i<Num_pilots; i++) {
1593 strcpy(Pilots[i], Pilots[i + 1]);
1594 Pilot_ranks[i] = Pilot_ranks[i + 1];
1597 barracks_set_callsign_enter_mode(false);
1601 barracks_accept_new_pilot_callsign();
1605 // not entering pilot callsign
1608 if (barracks_new_pilot_selected()) {
1609 gamesnd_play_iface(SND_GENERAL_FAIL);
1611 gamesnd_play_iface(SND_USER_SELECT);
1615 case KEY_ESC: // cancel
1616 if (!help_overlay_active(BARRACKS_OVERLAY)) {
1617 if (Num_pilots && !barracks_pilot_accepted()) {
1618 gameseq_post_event(GS_EVENT_MAIN_MENU);
1620 gamesnd_play_iface(SND_GENERAL_FAIL);
1624 help_overlay_set_state(BARRACKS_OVERLAY,0);
1628 case KEY_TAB: // switch mode (simgle/multi)
1629 #if defined(DEMO) || defined(OEM_BUILD) // not for FS2_DEMO
1630 game_feature_not_in_demo_popup();
1632 if (Player_sel_mode == PLAYER_SELECT_MODE_SINGLE) {
1633 barracks_init_player_stuff(PLAYER_SELECT_MODE_MULTI);
1635 barracks_init_player_stuff(PLAYER_SELECT_MODE_SINGLE);
1638 gamesnd_play_iface(SND_USER_SELECT);
1642 case KEY_F1: // show help overlay
1643 gamesnd_play_iface(SND_HELP_PRESSED);
1646 case KEY_F2: // goto options screen
1647 gamesnd_play_iface(SND_SWITCH_SCREENS);
1648 gameseq_post_event(GS_EVENT_OPTIONS_MENU);
1653 for (i=0; i<BARRACKS_NUM_BUTTONS; i++) {
1654 if (Buttons[gr_screen.res][i].button.pressed()) {
1655 barracks_button_pressed(i);
1659 // if mouse is over a pilot, find index into Pilots array
1660 if (List_region.is_mouse_on()) {
1662 List_region.get_mouse_pos(NULL, &y);
1663 int pilot_index = List_scroll_offset + (y / gr_get_font_height());
1664 if ((pilot_index >= 0) && (pilot_index < Num_pilots)) {
1665 prospective_pilot = pilot_index;
1669 // if mouse clicked in list region, find index into Pilots array
1670 if (List_region.pressed()) {
1671 if (prospective_pilot != -1) {
1672 Selected_line = prospective_pilot;
1673 gamesnd_play_iface(SND_USER_SELECT);
1678 // check mouse over help
1679 if (mouse_down(MOUSE_LEFT_BUTTON)) {
1680 help_overlay_set_state(BARRACKS_OVERLAY, 0);
1683 // do pilot pic stuff
1684 if ((Pic_number >= 0) && (Pic_number < Num_pilot_images)) {
1685 if (Pilot_images[Pic_number] == BARRACKS_IMAGE_NOT_LOADED) { // haven't tried loading it yet
1686 Pilot_images[Pic_number] = bm_load(Pilot_image_names[Pic_number]);
1687 if (Pilot_images[Pic_number] >= 0) {
1690 bm_get_info(Pilot_images[Pic_number], &w, &h, NULL);
1691 // check for invalid pilot pic file
1692 if ((w != PLAYER_PILOT_PIC_W) || (h != PLAYER_PILOT_PIC_H)) {
1693 bm_unload(Pilot_images[Pic_number]);
1694 Pilot_images[Pic_number] = -1;
1702 // do squad pic stuff
1703 if ((Pic_squad_number >= 0) && (Pic_squad_number < Num_pilot_squad_images)) {
1704 if (Pilot_squad_images[Pic_squad_number] == BARRACKS_IMAGE_NOT_LOADED) { // haven't tried loading it yet
1705 Pilot_squad_images[Pic_squad_number] = bm_load_duplicate(Pilot_squad_image_names[Pic_squad_number]);
1706 if (Pilot_squad_images[Pic_squad_number] >= 0) {
1709 bm_get_info(Pilot_squad_images[Pic_squad_number], &w, &h, NULL);
1710 // check for invalid pilot pic file
1711 if ((w != PLAYER_SQUAD_PIC_W) || (h != PLAYER_SQUAD_PIC_H)) {
1712 bm_unload(Pilot_squad_images[Pic_squad_number]);
1713 Pilot_squad_images[Pic_squad_number] = -1;
1718 Pic_squad_number = -1;
1721 // draw the background, etc
1723 GR_MAYBE_CLEAR_RES(Background_bitmap);
1724 if (Background_bitmap >= 0) {
1725 gr_set_bitmap(Background_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
1729 // draw pilot image and clean up afterwards
1730 barracks_draw_pilot_pic();
1731 barracks_draw_squad_pic();
1733 #if defined(MAKE_FS1) && !defined(FS1_DEMO)
1734 if (PilotWin01 != -1) {
1735 gr_set_bitmap(PilotWin01);
1739 if (PilotWin02 != -1) {
1740 gr_set_bitmap(PilotWin02);
1744 if (PilotWin03 != -1) {
1745 gr_set_bitmap(PilotWin03);
1746 gr_bitmap(447, 137);
1749 if (PilotWin04 != -1) {
1750 gr_set_bitmap(PilotWin04);
1759 // light up the correct mode button (single or multi)
1760 if (Player_sel_mode == PLAYER_SELECT_MODE_SINGLE) {
1761 Buttons[gr_screen.res][B_PILOT_SINGLE_MODE_BUTTON].button.draw_forced(2);
1763 Buttons[gr_screen.res][B_PILOT_MULTI_MODE_BUTTON].button.draw_forced(2);
1766 // write out pilot call signs
1767 barracks_display_pilot_callsigns(prospective_pilot);
1769 // write out current pilot stats
1770 barracks_display_pilot_stats();
1772 // blit help overlay if active
1773 help_overlay_maybe_blit(BARRACKS_OVERLAY);
1779 // -----------------------------------------------------------------------------
1780 void barracks_close()
1782 #if defined(MAKE_FS1) && !defined(FS1_DEMO)
1783 if (PilotWin01 != -1){
1784 bm_unload(PilotWin01);
1787 if (PilotWin02 != -1){
1788 bm_unload(PilotWin02);
1791 if (PilotWin03 != -1){
1792 bm_unload(PilotWin03);
1795 if (PilotWin04 != -1){
1796 bm_unload(PilotWin04);
1802 Ui_window.destroy();
1804 // release background bitmap
1805 if (Background_bitmap >= 0) {
1806 bm_unload(Background_bitmap);
1809 // release rank pip bitmaps
1810 for (int i=0; i<Rank_pips_count; i++) {
1811 bm_release(Rank_pips_bitmaps + i);
1814 // release pilot pic bitmaps
1815 for (int i=0; i<Num_pilot_images; i++) {
1816 if (Pilot_images[i] >= 0) {
1817 bm_unload(Pilot_images[i]);
1821 // unload the overlay bitmap
1822 help_overlay_unload(BARRACKS_OVERLAY);