]> icculus.org git repositories - taylor/freespace2.git/blob - src/menuui/playermenu.cpp
const-char warning fixes
[taylor/freespace2.git] / src / menuui / playermenu.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/MenuUI/PlayerMenu.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Code to drive the Player Select initial screen
16  *
17  * $Log$
18  * Revision 1.9  2005/03/29 02:18:47  taylor
19  * Various 64-bit platform fixes
20  * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too
21  * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions)
22  * Streaming audio support (big thanks to Pierre Willenbrock!!)
23  * Removed dependance on strings.tbl for FS1 since we don't actually need it now
24  *
25  * Revision 1.8  2004/09/20 01:31:44  theoddone33
26  * GCC 3.4 fixes.
27  *
28  * Revision 1.7  2003/08/09 03:18:03  taylor
29  * fix tips popup not having any tips
30  *
31  * Revision 1.6  2003/06/11 18:30:32  taylor
32  * plug memory leaks
33  *
34  * Revision 1.5  2003/05/25 02:30:42  taylor
35  * Freespace 1 support
36  *
37  * Revision 1.4  2003/05/22 16:13:35  taylor
38  * fix missed German build option for auto-lang
39  *
40  * Revision 1.3  2002/06/09 04:41:22  relnev
41  * added copyright header
42  *
43  * Revision 1.2  2002/05/07 03:16:46  theoddone33
44  * The Great Newline Fix
45  *
46  * Revision 1.1.1.1  2002/05/03 03:28:09  root
47  * Initial import.
48  * 
49  * 
50  * 43    11/02/99 11:42a Jefff
51  * fixed copyright symbol in german fonts
52  * 
53  * 42    10/27/99 12:27a Jefff
54  * localized tips correctly
55  * 
56  * 41    9/13/99 4:52p Dave
57  * RESPAWN FIX
58  * 
59  * 40    9/02/99 11:10a Jefff
60  * fixed 1024 list display bug - was only showing 8 pilots at a time
61  * 
62  * 39    8/26/99 8:51p Dave
63  * Gave multiplayer TvT messaging a heavy dose of sanity. Cheat codes.
64  * 
65  * 38    8/26/99 9:45a Dave
66  * First pass at easter eggs and cheats.
67  * 
68  * 37    8/16/99 6:39p Jefff
69  * 
70  * 36    8/16/99 6:37p Jefff
71  * minor string alterations
72  * 
73  * 35    8/05/99 4:17p Dave
74  * Tweaks to client interpolation.
75  * 
76  * 34    8/05/99 11:29a Mikek
77  * Jacked up number of comments from 20 to 40, thereby doubling the
78  * quality of our game.
79  * 
80  * 33    8/04/99 10:53a Dave
81  * Added title to the user tips popup.
82  * 
83  * 32    8/03/99 3:21p Jefff
84  * 
85  * 31    8/03/99 10:32a Jefff
86  * raised location of bottom_text to not interfere w/ logo.  changed
87  * "please enter callsign" to "type callsign and press enter"
88  * 
89  * 30    8/02/99 9:13p Dave
90  * Added popup tips.
91  * 
92  * 29    7/30/99 10:29a Jefff
93  * fixed colors of bottom display texts
94  * 
95  * 28    7/27/99 7:17p Jefff
96  * Replaced some art text with XSTR() text.
97  * 
98  * 27    7/19/99 2:06p Jasons
99  * Remove all palette stuff from player select menu.
100  * 
101  * 26    7/15/99 9:20a Andsager
102  * FS2_DEMO initial checkin
103  * 
104  * 25    7/09/99 9:51a Dave
105  * Added thick polyline code.
106  * 
107  * 24    6/11/99 11:13a Dave
108  * last minute changes before press tour build.
109  * 
110  * 23    5/21/99 6:45p Dave
111  * Sped up ui loading a bit. Sped up localization disk access stuff. Multi
112  * start game screen, multi password, and multi pxo-help screen.
113  * 
114  * 22    4/25/99 3:02p Dave
115  * Build defines for the E3 build.
116  * 
117  * 21    3/25/99 2:31p Neilk
118  * Coordinate changes to handle new artwork
119  * 
120  * 20    2/25/99 4:19p Dave
121  * Added multiplayer_beta defines. Added cd_check define. Fixed a few
122  * release build warnings. Added more data to the squad war request and
123  * response packets.
124  * 
125  * 19    2/01/99 5:55p Dave
126  * Removed the idea of explicit bitmaps for buttons. Fixed text
127  * highlighting for disabled gadgets.
128  * 
129  * 18    1/30/99 5:08p Dave
130  * More new hi-res stuff.Support for nice D3D textures.
131  * 
132  * 17    1/30/99 1:53a Dave
133  * Fix some harcoded coords.
134  * 
135  * 16    1/30/99 1:28a Dave
136  * 1024x768 full support.
137  * 
138  * 15    1/29/99 1:25p Dave
139  * New code for choose pilot screen.
140  * 
141  * 14    1/29/99 12:47a Dave
142  * Put in sounds for beam weapon. A bunch of interface screens (tech
143  * database stuff).
144  * 
145  * 13    1/12/99 12:53a Dave
146  * More work on beam weapons - made collision detection very efficient -
147  * collide against all object types properly - made 3 movement types
148  * smooth. Put in test code to check for possible non-darkening pixels on
149  * object textures.
150  * 
151  * 12    12/18/98 1:13a Dave
152  * Rough 1024x768 support for Direct3D. Proper detection and usage through
153  * the launcher.
154  * 
155  * 11    12/06/98 2:36p Dave
156  * Drastically improved nebula fogging.
157  * 
158  * 10    12/01/98 6:20p Dave
159  * Removed tga test bitmap code.
160  * 
161  * 9     12/01/98 4:46p Dave
162  * Put in targa bitmap support (16 bit).
163  * 
164  * 8     11/30/98 1:07p Dave
165  * 16 bit conversion, first run.
166  * 
167  * 7     11/20/98 11:16a Dave
168  * Fixed up IPX support a bit. Making sure that switching modes and
169  * loading/saving pilot files maintains proper state.
170  * 
171  * 6     11/19/98 4:19p Dave
172  * Put IPX sockets back in psnet. Consolidated all multiplayer config
173  * files into one.
174  * 
175  * 5     11/05/98 4:18p Dave
176  * First run nebula support. Beefed up localization a bit. Removed all
177  * conditional compiles for foreign versions. Modified mission file
178  * format.
179  * 
180  * 4     10/13/98 9:28a Dave
181  * Started neatening up freespace.h. Many variables renamed and
182  * reorganized. Added AlphaColors.[h,cpp]
183  * 
184  * 3     10/09/98 2:57p Dave
185  * Starting splitting up OS stuff.
186  * 
187  * 2     10/07/98 10:53a Dave
188  * Initial checkin.
189  * 
190  * 1     10/07/98 10:49a Dave
191  * 
192  *
193  * $NoKeywords: $
194  *
195  */
196
197 #include <ctype.h>
198
199 #include "playermenu.h"
200 #include "2d.h"
201 #include "ui.h"
202 #include "gamesnd.h"
203 #include "player.h"
204 #include "cfile.h"
205 #include "key.h"
206 #include "managepilot.h"
207 #include "missionscreencommon.h"
208 #include "bmpman.h"
209 #include "freespace.h"
210 #include "parselo.h"
211 #include "gamesequence.h"
212 #include "timer.h"
213 #include "cmdline.h"
214 #include "osregistry.h"
215 #include "palman.h"
216 #include "mainhallmenu.h"
217 #include "multi.h"
218 #include "popup.h"
219 #include "mouse.h"
220 #include "alphacolors.h"
221 #include "localize.h"
222
223 // --------------------------------------------------------------------------------------------------------
224 // Demo title screen
225 #if defined(FS2_DEMO) || defined(FS1_DEMO)
226 static int Demo_title_active = 0;
227 static int Demo_title_bitmap = -1;
228 static int Demo_title_expire_timestamp = 0;
229 static int Demo_title_need_fade_in = 1;
230 static const char *Demo_title_bitmap_filename = NOX("DemoTitle1");
231 #endif
232
233 // --------------------------------------------------------------------------------------------------------
234 // PLAYER SELECT defines
235 //
236
237 //#define MAX_PLAYER_SELECT_LINES               8                                                       // max # of pilots displayed at once
238 int Player_select_max_lines[GR_NUM_RESOLUTIONS] = {                     // max # of pilots displayed at once
239         8,                      // GR_640
240         15                      // GR_1024
241 };
242
243 // button control defines
244 #define NUM_PLAYER_SELECT_BUTTONS       8                                                       // button control defines
245
246 #define CREATE_PILOT_BUTTON                     0                                                       //      
247 #define CLONE_BUTTON                                            1                                                       //
248 #define DELETE_BUTTON                                   2                                                       //
249 #define SCROLL_LIST_UP_BUTTON                   3                                                       //
250 #define SCROLL_LIST_DOWN_BUTTON         4                                                       //
251 #define ACCEPT_BUTTON                                   5                                                       //
252 #define SINGLE_BUTTON                                   6                                                       //
253 #define MULTI_BUTTON                                            7                                                       //
254
255 // list text display area
256 int Choose_list_coords[GR_NUM_RESOLUTIONS][4] = {
257         { // GR_640
258 #ifdef MAKE_FS1
259                 130, 140, 379, 68
260 #else
261                 114, 117, 400, 87
262 #endif
263         },
264         { // GR_1024
265                 183, 186, 640, 139
266         }
267 };
268
269 const char *Player_select_background_bitmap_name[GR_NUM_RESOLUTIONS] = {
270         "ChoosePilot",
271         "2_ChoosePilot"
272 };
273 const char *Player_select_background_mask_bitmap[GR_NUM_RESOLUTIONS] = {
274         "ChoosePilot-m",
275         "2_ChoosePilot-m"
276 };
277 // #define PLAYER_SELECT_PALETTE                                                        NOX("ChoosePilotPalette")       // palette for the screen       
278
279 #define PLAYER_SELECT_MAIN_HALL_OVERLAY         NOX("MainHall1")                                // main hall help overlay
280
281 // convenient struct for handling all button controls
282 struct barracks_buttons {
283         const char *filename;
284         int x, y, xt, yt;
285         int hotspot;
286         UI_BUTTON button;  // because we have a class inside this struct, we need the constructor below..
287
288         barracks_buttons(const char *name, int x1, int y1, int xt1, int yt1, int h) : filename(name), x(x1), y(y1), xt(xt1), yt(yt1), hotspot(h) {}
289 };
290
291 static barracks_buttons Player_select_buttons[GR_NUM_RESOLUTIONS][NUM_PLAYER_SELECT_BUTTONS] = {        
292         { // GR_640
293 #ifdef MAKE_FS1
294                 barracks_buttons("CHP_00",              126,    211,    -1,     -1,     0),     // create
295                 barracks_buttons("CHP_13",              181,    211,    -1,     -1,     13),    // clone
296                 barracks_buttons("CHP_11",              228,    211,    -1,     -1, 11),        // delete
297                 barracks_buttons("CHP_01",              423,    232,    -1,     -1,     1),     // scroll up
298                 barracks_buttons("CHP_02",              452,    232,    -1,     -1,     2),     // scroll down
299                 barracks_buttons("CHP_12",              475,    213,    -1,     -1,     12),    // accept
300                 barracks_buttons("CHP_14",              438,    104,    -1,     -1,     14),    // single
301                 barracks_buttons("CHP_15",              485,    104,    -1,     -1,     15)     // multi
302 #else
303                 // create, clone and delete (respectively)
304                 barracks_buttons("CPB_00",              114,    205,    117,    240,    0),
305                 barracks_buttons("CPB_01",              172,    205,    175,    240,    1),
306                 barracks_buttons("CPB_02",              226,    205,    229,    240,    2),
307
308                 // scroll up, scroll down,      and accept (respectively)
309                 barracks_buttons("CPB_03",              429,    213,    -1,     -1,     3),
310                 barracks_buttons("CPB_04",              456,    213,    -1,     -1,     4),
311                 barracks_buttons("CPB_05",              481,  207,      484,    246,    5),     
312                 
313                 // single player select and multiplayer select, respectively
314                 barracks_buttons("CPB_06",              428,    82,     430,    108,    6),
315                 barracks_buttons("CPB_07",              477,    82,     481,    108,    7)
316 #endif
317         }, 
318         { // GR_1024
319                 // create, clone and delete (respectively)
320                 barracks_buttons("2_CPB_00",    182,  328,      199,    384,    0),
321                 barracks_buttons("2_CPB_01",    275,    328,    292,    384,    1),
322                 barracks_buttons("2_CPB_02",    361,    328,    379,    384,    2),
323
324                 // scroll up, scroll down, and accept (respectively)
325                 barracks_buttons("2_CPB_03",    686,    341,    -1,     -1,     3),
326                 barracks_buttons("2_CPB_04",    729,    341,    -1,     -1,     4),
327                 barracks_buttons("2_CPB_05",    770,  332,      787,    394,    5),     
328                 
329                 // single player select and multiplayer select, respectively
330                 barracks_buttons("2_CPB_06",    685,    132,    700,    173,    6),
331                 barracks_buttons("2_CPB_07",    764,    132,    782,    173,    7)
332         }
333 };
334
335 // FIXME add to strings.tbl
336 #ifndef MAKE_FS1
337 #define PLAYER_SELECT_NUM_TEXT                  1
338
339 UI_XSTR Player_select_text[GR_NUM_RESOLUTIONS][PLAYER_SELECT_NUM_TEXT] = {
340         { // GR_640
341                 { "Choose Pilot",               1436,           122,    90,     UI_XSTR_COLOR_GREEN, -1, NULL }
342         }, 
343         { // GR_1024
344                 { "Choose Pilot",               1436,           195,    143,    UI_XSTR_COLOR_GREEN, -1, NULL }
345         }
346 };
347 #endif
348
349 UI_WINDOW Player_select_window;                                                         // ui window for this screen
350 UI_BUTTON Player_select_list_region;                                            // button for detecting mouse clicks on this screen
351 UI_INPUTBOX Player_select_input_box;                                            // input box for adding new pilot names                         
352
353 // #define PLAYER_SELECT_PALETTE_FNAME                                  NOX("InterfacePalette")
354 int Player_select_background_bitmap;                                            // bitmap for this screen
355 // int Player_select_palette;                                                                           // palette bitmap for this screen
356 int Player_select_autoaccept = 0;
357 // int Player_select_palette_set = 0;
358
359 // flag indicating if this is the absolute first pilot created and selected. Used to determine
360 // if the main hall should display the help overlay screen
361 int Player_select_very_first_pilot = 0;                 
362 int Player_select_initial_count = 0;
363 char Player_select_very_first_pilot_callsign[CALLSIGN_LEN + 2];
364
365 extern int Main_hall_bitmap;                                                                    // bitmap handle to the main hall bitmap
366
367 int Player_select_mode;                                                                                 // single or multiplayer - never set directly. use player_select_init_player_stuff()
368 int Player_select_num_pilots;                                                                   // # of pilots on the list
369 int Player_select_list_start;                                                                   // index of first list item to start displaying in the box
370 int Player_select_pilot;                                                                            // index into the Pilot array of which is selected as the active pilot
371 int Player_select_input_mode;                                                                   // 0 if the player _isn't_ typing a callsign, 1 if he is
372 char Pilots_arr[MAX_PILOTS][MAX_FILENAME_LEN];          
373 char *Pilots[MAX_PILOTS];
374 int Player_select_clone_flag;                                                                   // clone the currently selected pilot
375 char Player_select_last_pilot[CALLSIGN_LEN + 10];               // callsign of the last used pilot, or none if there wasn't one
376 int Player_select_last_is_multi;
377
378 int Player_select_force_bastion = 0;
379
380 // notification text areas
381
382 static int Player_select_bottom_text_y[GR_NUM_RESOLUTIONS] = {
383 #ifdef MAKE_FS1
384         280,
385 #else
386         314,    // GR_640
387 #endif
388         502     // GR_1024
389 };
390
391 static int Player_select_middle_text_y[GR_NUM_RESOLUTIONS] = {
392 #ifdef MAKE_FS1
393         280,
394 #else
395         253,    // GR_640
396 #endif
397         404     // GR_1024
398 };
399
400 char Player_select_bottom_text[150] = "";
401 char Player_select_middle_text[150] = "";
402 void player_select_set_bottom_text(const char *txt);
403 void player_select_set_middle_text(const char *txt);
404
405
406 // FORWARD DECLARATIONS
407 void player_select_init_player_stuff(int mode);                 // switch between single and multiplayer modes
408 void player_select_set_input_mode(int n);                                       
409 void player_select_button_pressed(int n);
410 void player_select_scroll_list_up();
411 void player_select_scroll_list_down();
412 int player_select_create_new_pilot();
413 void player_select_delete_pilot();
414 void player_select_display_all_text();
415 void player_select_display_copyright();
416 void player_select_set_controls(int gray);
417 void player_select_draw_list();
418 void player_select_process_noninput(int k);
419 void player_select_process_input(int k);
420 int player_select_pilot_file_filter(const char *filename);
421 int player_select_get_last_pilot_info();
422 void player_select_eval_very_first_pilot();
423 void player_select_commit();
424 void player_select_cancel_create();
425
426
427 // basically, gray out all controls (gray == 1), or ungray the controls (gray == 0) 
428 void player_select_set_controls(int gray)
429 {
430         int idx;
431         
432         for(idx=0;idx<NUM_PLAYER_SELECT_BUTTONS;idx++){
433                 if(gray){
434                         Player_select_buttons[gr_screen.res][idx].button.disable();
435                 } else {
436                         Player_select_buttons[gr_screen.res][idx].button.enable();
437                 }
438         }
439 }
440
441 // functions for selecting single/multiplayer pilots at the very beginning of Freespace
442 void player_select_init()
443 {                       
444         int i;
445         barracks_buttons *b;   
446 #ifndef MAKE_FS1
447         UI_WINDOW *w;
448 #endif
449
450         // start a looping ambient sound
451         main_hall_start_ambient();
452
453         Player_select_force_bastion = 0;
454
455 #ifdef FS2_DEMO
456         /*
457         Demo_title_bitmap = bm_load(Demo_title_bitmap_filename);
458         if ( Demo_title_bitmap >= 0 ) {
459 #ifndef HARDWARE_ONLY
460                 palette_use_bm_palette(Demo_title_bitmap);
461 #endif
462                 Demo_title_active = 1;
463                 Demo_title_expire_timestamp = timestamp(5000);
464         } else {
465                 Demo_title_active = 0;
466         }
467         */
468         Demo_title_active = 0;
469 #endif
470
471         // create the UI window
472         Player_select_window.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);
473         Player_select_window.set_mask_bmap(Player_select_background_mask_bitmap[gr_screen.res]);
474
475 #ifdef MAKE_FS1
476         common_set_interface_palette("ChoosePilotPalette");
477 #endif
478
479         // initialize the control buttons
480         for (i=0; i<NUM_PLAYER_SELECT_BUTTONS; i++) {
481                 b = &Player_select_buttons[gr_screen.res][i];
482
483                 // create the button
484                 if ( (i == SCROLL_LIST_UP_BUTTON) || (i == SCROLL_LIST_DOWN_BUTTON) )
485                         b->button.create(&Player_select_window, NULL, b->x, b->y, 60, 30, 1, 1);
486                 else
487                         b->button.create(&Player_select_window, NULL, b->x, b->y, 60, 30, 1, 1);
488
489                 // set its highlight action
490                 b->button.set_highlight_action(common_play_highlight_sound);
491
492                 // set its animation bitmaps
493                 b->button.set_bmaps(b->filename);
494
495                 // link the mask hotspot
496                 b->button.link_hotspot(b->hotspot);
497         }               
498
499 #ifndef MAKE_FS1
500         // add some text
501         w = &Player_select_window;      
502         w->add_XSTR("Create", 1034, Player_select_buttons[gr_screen.res][CREATE_PILOT_BUTTON].xt, Player_select_buttons[gr_screen.res][CREATE_PILOT_BUTTON].yt, &Player_select_buttons[gr_screen.res][CREATE_PILOT_BUTTON].button, UI_XSTR_COLOR_GREEN);        
503         w->add_XSTR("Clone", 1040, Player_select_buttons[gr_screen.res][CLONE_BUTTON].xt, Player_select_buttons[gr_screen.res][CLONE_BUTTON].yt, &Player_select_buttons[gr_screen.res][CLONE_BUTTON].button, UI_XSTR_COLOR_GREEN);      
504         w->add_XSTR("Remove", 1038, Player_select_buttons[gr_screen.res][DELETE_BUTTON].xt, Player_select_buttons[gr_screen.res][DELETE_BUTTON].yt, &Player_select_buttons[gr_screen.res][DELETE_BUTTON].button, UI_XSTR_COLOR_GREEN);  
505         
506         w->add_XSTR("Select", 1039, Player_select_buttons[gr_screen.res][ACCEPT_BUTTON].xt, Player_select_buttons[gr_screen.res][ACCEPT_BUTTON].yt, &Player_select_buttons[gr_screen.res][ACCEPT_BUTTON].button, UI_XSTR_COLOR_PINK);   
507         w->add_XSTR("Single", 1041, Player_select_buttons[gr_screen.res][SINGLE_BUTTON].xt, Player_select_buttons[gr_screen.res][SINGLE_BUTTON].yt, &Player_select_buttons[gr_screen.res][SINGLE_BUTTON].button, UI_XSTR_COLOR_GREEN);  
508         w->add_XSTR("Multi", 1042, Player_select_buttons[gr_screen.res][MULTI_BUTTON].xt, Player_select_buttons[gr_screen.res][MULTI_BUTTON].yt, &Player_select_buttons[gr_screen.res][MULTI_BUTTON].button, UI_XSTR_COLOR_GREEN);      
509         for(i=0; i<PLAYER_SELECT_NUM_TEXT; i++) {
510                 w->add_XSTR(&Player_select_text[gr_screen.res][i]);
511         }
512 #endif
513
514         // create the list button text select region
515         Player_select_list_region.create(&Player_select_window, "", Choose_list_coords[gr_screen.res][0], Choose_list_coords[gr_screen.res][1], Choose_list_coords[gr_screen.res][2], Choose_list_coords[gr_screen.res][3], 0, 1);
516         Player_select_list_region.hide();
517
518         // create the pilot callsign input box
519         Player_select_input_box.create(&Player_select_window, Choose_list_coords[gr_screen.res][0], Choose_list_coords[gr_screen.res][1], Choose_list_coords[gr_screen.res][2] , CALLSIGN_LEN - 1, "", UI_INPUTBOX_FLAG_INVIS | UI_INPUTBOX_FLAG_KEYTHRU | UI_INPUTBOX_FLAG_LETTER_FIRST);
520         Player_select_input_box.set_valid_chars(VALID_PILOT_CHARS);
521         Player_select_input_box.hide();
522         Player_select_input_box.disable();
523         
524         // not currently entering any text
525         Player_select_input_mode = 0;   
526
527         // set up hotkeys for buttons so we draw the correct animation frame when a key is pressed
528         Player_select_buttons[gr_screen.res][SCROLL_LIST_UP_BUTTON].button.set_hotkey(KEY_UP);
529         Player_select_buttons[gr_screen.res][SCROLL_LIST_DOWN_BUTTON].button.set_hotkey(KEY_DOWN);
530         Player_select_buttons[gr_screen.res][ACCEPT_BUTTON].button.set_hotkey(KEY_ENTER);
531         Player_select_buttons[gr_screen.res][CREATE_PILOT_BUTTON].button.set_hotkey(KEY_C);
532
533         // disable the single player button in the multiplayer beta
534 #ifdef MULTIPLAYER_BETA_BUILD
535         Player_select_buttons[gr_screen.res][SINGLE_BUTTON].button.hide();
536         Player_select_buttons[gr_screen.res][SINGLE_BUTTON].button.disable();
537 #elif defined(E3_BUILD) || defined(PRESS_TOUR_BUILD)
538         Player_select_buttons[gr_screen.res][MULTI_BUTTON].button.hide();
539         Player_select_buttons[gr_screen.res][MULTI_BUTTON].button.disable();
540 #endif
541
542
543         // attempt to load in the background bitmap
544         Player_select_background_bitmap = bm_load(Player_select_background_bitmap_name[gr_screen.res]);                         
545         Assert(Player_select_background_bitmap >= 0);   
546
547         // load in the palette for the screen
548         // Player_select_palette = bm_load(PLAYER_SELECT_PALETTE);
549         // Player_select_palette_set = 0;
550
551         // unset the very first pilot data
552         Player_select_very_first_pilot = 0;
553         Player_select_initial_count = -1;
554         memset(Player_select_very_first_pilot_callsign, 0, CALLSIGN_LEN + 2);   
555
556 //      if(Player_select_num_pilots == 0){
557 //              Player_select_autoaccept = 1;
558 //      }
559                 
560         // if we found a pilot
561 #if defined(DEMO) || defined(OEM_BUILD) || defined(E3_BUILD) || defined(PRESS_TOUR_BUILD) // not for FS2_DEMO
562         player_select_init_player_stuff(PLAYER_SELECT_MODE_SINGLE);     
563 #elif defined(MULTIPLAYER_BETA_BUILD)
564         player_select_init_player_stuff(PLAYER_SELECT_MODE_MULTI);      
565 #else
566         if (player_select_get_last_pilot_info()) {
567                 if (Player_select_last_is_multi) {
568                         player_select_init_player_stuff(PLAYER_SELECT_MODE_MULTI);
569                 } else {
570                         player_select_init_player_stuff(PLAYER_SELECT_MODE_SINGLE);
571                 }
572         } 
573         // otherwise go to the single player mode by default
574         else {
575                 player_select_init_player_stuff(PLAYER_SELECT_MODE_SINGLE);
576         }
577 #endif  
578
579         if((Player_select_num_pilots == 1) && Player_select_input_mode){
580                 Player_select_autoaccept = 1;
581         }       
582 }
583
584 #if defined(FS2_DEMO) || defined(FS1_DEMO)
585 // Display the demo title screen
586 void demo_title_blit()
587 {
588         int k;
589
590         Mouse_hidden = 1;
591
592         if ( timestamp_elapsed(Demo_title_expire_timestamp) ) {
593                 Demo_title_active = 0;
594         }
595
596         k = game_poll();
597         if ( k > 0 ) {
598                 Demo_title_active = 0;
599         }
600
601         if ( Demo_title_need_fade_in ) {
602                 gr_fade_out(0);
603         }
604         
605         gr_set_bitmap(Demo_title_bitmap);
606         gr_bitmap(0,0);
607
608         gr_flip();
609
610         if ( Demo_title_need_fade_in ) {
611                 gr_fade_in(0);
612                 Demo_title_need_fade_in = 0;
613         }
614
615         if ( !Demo_title_active ) {
616                 gr_fade_out(0);
617                 Mouse_hidden = 0;
618         }
619 }
620
621 #endif
622
623 void player_select_do()
624 {
625         int k;
626
627 #ifdef FS2_DEMO
628         if ( Demo_title_active ) {
629                 // demo_title_blit();
630                 return;
631         }
632 #endif
633
634         //if ( !Player_select_palette_set ) {
635         //      Assert(Player_select_palette >= 0);
636 //#ifndef HARDWARE_ONLY
637 //              palette_use_bm_palette(Player_select_palette);
638 //#endif
639 //              Player_select_palette_set = 1;
640 //      }
641                 
642         // set the input box at the "virtual" line 0 to be active so the player can enter a callsign
643         if (Player_select_input_mode){
644                 Player_select_input_box.set_focus();
645         }
646
647         // process any ui window stuff
648         k = Player_select_window.process();
649         if(k){
650                 extern void game_process_cheats(int k);
651                 game_process_cheats(k);
652         }
653         switch(k){
654         // switch between single and multiplayer modes
655         case KEY_TAB : 
656 #if defined(DEMO) || defined(OEM_BUILD) // not for FS2_DEMO
657                 break;
658 #else
659
660                 if(Player_select_input_mode){
661                         gamesnd_play_iface(SND_GENERAL_FAIL);
662                         break;
663                 }
664                 // play a little sound
665                 gamesnd_play_iface(SND_USER_SELECT);
666                 if(Player_select_mode == PLAYER_SELECT_MODE_MULTI){                                     
667 #ifdef MAKE_FS1
668                         player_select_set_bottom_text(XSTR( "Single Player Mode", 376));
669 #else
670                         player_select_set_bottom_text(XSTR( "Single-Player Mode", 376));
671 #endif
672                                 
673                         // reinitialize as single player mode
674                         player_select_init_player_stuff(PLAYER_SELECT_MODE_SINGLE);
675                 } else if(Player_select_mode == PLAYER_SELECT_MODE_SINGLE){                                                                             
676                         player_select_set_bottom_text(XSTR( "Multiplayer Mode", 377));
677                                 
678                         // reinitialize as multiplayer mode
679                         player_select_init_player_stuff(PLAYER_SELECT_MODE_MULTI);
680                 }
681                 break;  
682 #endif
683         }       
684
685         // draw the player select pseudo-dialog over it
686         gr_set_bitmap(Player_select_background_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
687         gr_bitmap(0,0);
688
689         // press the accept button
690         if (Player_select_autoaccept) {
691                 Player_select_buttons[gr_screen.res][ACCEPT_BUTTON].button.press_button();
692         }
693         
694         // draw any ui window stuf
695         Player_select_window.draw();
696
697         // light up the correct mode button (single or multi)
698         if (Player_select_mode == PLAYER_SELECT_MODE_SINGLE){
699                 Player_select_buttons[gr_screen.res][SINGLE_BUTTON].button.draw_forced(2);
700         } else {
701                 Player_select_buttons[gr_screen.res][MULTI_BUTTON].button.draw_forced(2);
702         }
703
704         // draw the pilot list text
705         player_select_draw_list();      
706
707         // draw copyright message on the bottom on the screen
708         player_select_display_copyright();
709
710         if (!Player_select_input_mode) {
711                 player_select_process_noninput(k);
712         } else {
713                 player_select_process_input(k);
714         }
715         
716         // draw any pending messages on the bottom or middle of the screen
717         player_select_display_all_text();       
718
719 #ifndef RELEASE_REAL
720         // gr_set_color_fast(&Color_bright_green);
721         // gr_string(0x8000, 10, "Development version - DO NOT RELEASE");
722 #endif
723         
724         /*
725         gr_set_color(255, 0, 0);
726         vector whee[5];
727         vector *arr[5] = {&whee[0], &whee[1], &whee[2], &whee[3], &whee[4]};
728         whee[0].x = 10; whee[0].y = 10; whee[0].z = 0.0f;
729         whee[1].x = 50; whee[1].y = 50; whee[1].z = 0.0f;
730         whee[2].x = 50; whee[2].y = 90; whee[2].z = 0.0f;
731         whee[3].x = 90; whee[3].y = 130; whee[3].z = 0.0f;
732         whee[4].x = 180; whee[4].y = 130; whee[4].z = 0.0f;
733         gr_pline_special(arr, 5, 2);
734         */
735         
736
737         gr_flip();
738 }
739
740 void player_select_close()
741 {
742         // destroy the player select window
743         Player_select_window.destroy();
744
745         // if we're in input mode - we should undo the pilot create reqeust
746         if(Player_select_input_mode){
747                 player_select_cancel_create();
748         }
749         
750         // actually set up the Player struct here       
751         if((Player_select_pilot == -1) || (Player_select_num_pilots == 0)){
752                 nprintf(("General","WARNING! No pilot selected! We should be exiting the game now!\n"));
753                 return;
754         }
755
756         // unload all bitmaps
757         if(Player_select_background_bitmap >= 0){
758                 bm_release(Player_select_background_bitmap);
759                 Player_select_background_bitmap = -1;
760         } 
761         // if(Player_select_palette >= 0){
762         //      bm_release(Player_select_palette);
763                 //Player_select_palette = -1;
764         // }
765
766 #ifdef MAKE_FS1
767         common_free_interface_palette();
768 #endif
769                         
770         // setup the player  struct
771         Player_num = 0;
772         Player = &Players[0];
773         Player->flags |= PLAYER_FLAGS_STRUCTURE_IN_USE;
774                 
775         // now read in a the pilot data
776         if (read_pilot_file(Pilots[Player_select_pilot], !Player_select_mode, Player) != 0) {
777                 Error(LOCATION,"Couldn't load pilot file, bailing");
778                 Player = NULL;
779         }               
780
781         if (Player_select_force_bastion) {
782                 Player->on_bastion = 1;
783         }
784 }
785
786 void player_select_set_input_mode(int n)
787 {
788         int i;
789
790         // set the input mode
791         Player_select_input_mode = n;   
792         
793         // enable all the player select buttons
794         for (i=0; i<NUM_PLAYER_SELECT_BUTTONS; i++){
795                 Player_select_buttons[gr_screen.res][i].button.enable(!n);
796         }
797
798         Player_select_buttons[gr_screen.res][ACCEPT_BUTTON].button.set_hotkey(n ? -1 : KEY_ENTER);
799         Player_select_buttons[gr_screen.res][CREATE_PILOT_BUTTON].button.set_hotkey(n ? -1 : KEY_C);
800
801         // enable the player select input box
802         if(Player_select_input_mode){
803                 Player_select_input_box.enable();
804                 Player_select_input_box.unhide();
805         } else {
806                 Player_select_input_box.hide();
807                 Player_select_input_box.disable();
808         }
809 }
810
811 void player_select_button_pressed(int n)
812 {
813         int ret;
814
815         switch (n) {
816         case SCROLL_LIST_UP_BUTTON:
817                 player_select_set_bottom_text("");
818
819                 player_select_scroll_list_up();
820                 break;
821
822         case SCROLL_LIST_DOWN_BUTTON:
823                 player_select_set_bottom_text("");
824
825                 player_select_scroll_list_down();
826                 break;
827
828         case ACCEPT_BUTTON:
829                 // make sure he has a valid pilot selected
830                 if (Player_select_pilot < 0) {                                                          
831                         popup(PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR( "You must select a valid pilot first", 378));
832                 } else {
833                         player_select_commit();                         
834                 }
835                 break;
836
837         case CLONE_BUTTON:
838                 // if we're at max-pilots, don't allow another to be added
839                 if (Player_select_num_pilots >= MAX_PILOTS) {
840                         player_select_set_bottom_text(XSTR( "You already have the maximum # of pilots!", 379));
841                         
842                         gamesnd_play_iface(SND_GENERAL_FAIL);
843                         break;
844                 }
845
846                 if (Player_select_pilot >= 0) {                                         
847                         // first we have to make sure this guy is actually loaded for when we create the clone
848                         if (Player == NULL) {
849                                 Player = &Players[0];
850                                 Player->flags |= PLAYER_FLAGS_STRUCTURE_IN_USE;
851                         }                               
852
853                         // attempt to read in the pilot file of the guy to be cloned
854                         if (read_pilot_file(Pilots[Player_select_pilot], !Player_select_mode, Player) != 0) {
855                                 Error(LOCATION,"Couldn't load pilot file, bailing");
856                                 Player = NULL;
857                                 Int3();
858                         }                               
859
860                         // set the clone flag
861                         Player_select_clone_flag = 1;
862
863                         // create the new pilot (will be cloned with Player_select_clone_flag_set)
864                         if (!player_select_create_new_pilot()) {                                        
865                                 player_select_set_bottom_text(XSTR( "Error creating new pilot file!", 380));
866                                 Player_select_clone_flag = 0;
867                                 memset(Player,0,sizeof(player));
868                                 Player = NULL;
869                                 break;
870                         }                               
871
872                         // clear the player out
873                         // JH: What the hell?  How do you clone a pilot if you clear out the source you are copying
874                         // from?  These next 2 lines are pure stupidity, so I commented them out!
875 //                      memset(Player,0,sizeof(player));
876 //                      Player = NULL;
877                                 
878                         // display some text on the bottom of the dialog
879                         player_select_set_bottom_text(XSTR( "Type Callsign and Press Enter", 381));                             
880                         
881                         // gray out all controls in the dialog
882                         player_select_set_controls(1);                                  
883                 }
884                 break;
885
886         case CREATE_PILOT_BUTTON:
887                 // if we're at max-pilots, don't allow another to be added
888                 if(Player_select_num_pilots >= MAX_PILOTS){
889                         player_select_set_bottom_text(XSTR( "You already have the maximum # of pilots!", 379));
890
891                         gamesnd_play_iface(SND_GENERAL_FAIL);
892                         break;
893                 }
894
895                 // create a new pilot
896                 if (!player_select_create_new_pilot()) {
897                         player_select_set_bottom_text(XSTR( "Type Callsign and Press Enter", 381));
898                 }
899
900                 // don't clone anyone
901                 Player_select_clone_flag = 0;
902                         
903                 // display some text on the bottom of the dialog                        
904                 player_select_set_bottom_text(XSTR( "Type Callsign and Press Enter", 381));
905                         
906                 // gray out all controls
907                 player_select_set_controls(1);                                          
908                 break;
909
910         case DELETE_BUTTON:
911                 player_select_set_bottom_text("");
912
913                 if (Player_select_pilot >= 0) {
914                         // display a popup requesting confirmation
915                         ret = popup(PF_TITLE_BIG | PF_TITLE_RED, 2, POPUP_NO, POPUP_YES, XSTR( "Warning!\n\nAre you sure you wish to delete this pilot?", 382));
916
917                         // delete the pilot
918                         if(ret == 1){
919                                 player_select_delete_pilot();
920                         } 
921                 }
922                 break;
923
924         case SINGLE_BUTTON:
925                 player_select_set_bottom_text("");
926
927                 Player_select_autoaccept = 0;
928                 // switch to single player mode
929                 if (Player_select_mode != PLAYER_SELECT_MODE_SINGLE) {
930                         // play a little sound
931                         gamesnd_play_iface(SND_USER_SELECT);
932                                 
933                         player_select_set_bottom_text(XSTR( "Single Player Mode", 376));
934                                 
935                         // reinitialize as single player mode
936                         player_select_init_player_stuff(PLAYER_SELECT_MODE_SINGLE);
937                 } else {
938                         gamesnd_play_iface(SND_GENERAL_FAIL);
939                 }
940                 break;
941
942         case MULTI_BUTTON:
943                 player_select_set_bottom_text("");
944
945                 Player_select_autoaccept = 0;
946 #if defined(DEMO) || defined(OEM_BUILD) // not for FS2_DEMO
947                 game_feature_not_in_demo_popup();
948 #else
949                 // switch to multiplayer mode
950                 if (Player_select_mode != PLAYER_SELECT_MODE_MULTI) {
951                         // play a little sound
952                         gamesnd_play_iface(SND_USER_SELECT);
953                         
954                         player_select_set_bottom_text(XSTR( "Multiplayer Mode", 377));
955                                 
956                         // reinitialize as multiplayer mode
957                         player_select_init_player_stuff(PLAYER_SELECT_MODE_MULTI);
958                 } else {
959                         gamesnd_play_iface(SND_GENERAL_FAIL);
960                 }
961 #endif
962                 break;
963         }
964 }
965
966 int player_select_create_new_pilot()
967 {
968         int idx;
969
970         // make sure we haven't reached the max
971         if (Player_select_num_pilots >= MAX_PILOTS) {
972                 gamesnd_play_iface(SND_GENERAL_FAIL);
973                 return 0;
974         }
975
976         int play_scroll_sound = 1;
977
978 #if defined(FS2_DEMO) || defined(FS1_DEMO)
979         if ( Demo_title_active ) {
980                 play_scroll_sound = 0;
981         }
982 #endif
983
984         if ( play_scroll_sound ) {
985                 gamesnd_play_iface(SND_SCROLL);
986         }
987
988         idx = Player_select_num_pilots; 
989         
990         // move all the pilots in the list up
991         while (idx--) {
992                 strcpy(Pilots[idx + 1], Pilots[idx]);           
993         }       
994
995         // by default, set the default netgame protocol to be VMT
996         Multi_options_g.protocol = NET_TCP;     
997
998         // select the beginning of the list
999         Player_select_pilot = 0;
1000         Player_select_num_pilots++;
1001         Pilots[Player_select_pilot][0] = 0;
1002         Player_select_list_start= 0;
1003
1004         // set us to be in input mode
1005         player_select_set_input_mode(1);
1006         
1007         // set the input box to have focus
1008         Player_select_input_box.set_focus();
1009         Player_select_input_box.set_text("");
1010         Player_select_input_box.update_dimensions(Choose_list_coords[gr_screen.res][0], Choose_list_coords[gr_screen.res][1], Choose_list_coords[gr_screen.res][2], gr_get_font_height());      
1011
1012         return 1;
1013 }
1014
1015 void player_select_delete_pilot()
1016 {
1017         char filename[MAX_PATH_LEN + 1];
1018         int i, deleted_cur_pilot;
1019
1020         deleted_cur_pilot = 0;
1021
1022         // tack on the full path and the pilot file extension
1023         // build up the path name length
1024         // make sure we do this based upon whether we're in single or multiplayer mode
1025         strcpy( filename, Pilots[Player_select_pilot] );
1026         strcat( filename, NOX(".plr") );
1027
1028         // attempt to delete the pilot
1029         if (Player_select_mode == PLAYER_SELECT_MODE_SINGLE) {
1030                 cf_delete( filename, CF_TYPE_SINGLE_PLAYERS );
1031         } else {
1032                 cf_delete( filename, CF_TYPE_MULTI_PLAYERS );
1033         }
1034
1035         // delete all the campaign save files for this pilot.
1036         mission_campaign_delete_all_savefiles( Pilots[Player_select_pilot], (Player_select_mode != PLAYER_SELECT_MODE_SINGLE) );
1037
1038         // move all the players down
1039         for (i=Player_select_pilot; i<Player_select_num_pilots-1; i++){
1040                 strcpy(Pilots[i], Pilots[i + 1]);               
1041         }               
1042
1043         // correcly set the # of pilots and the currently selected pilot
1044         Player_select_num_pilots--;
1045         if (Player_select_pilot >= Player_select_num_pilots) {
1046                 Player_select_pilot = Player_select_num_pilots - 1;             
1047         }               
1048
1049 }
1050
1051 // scroll the list of players up
1052 void player_select_scroll_list_up()
1053 {
1054         if (Player_select_pilot == -1)
1055                 return;
1056
1057         // change the pilot selected index and play the appropriate sound
1058         if (Player_select_pilot) {
1059                 Player_select_pilot--;
1060                 gamesnd_play_iface(SND_SCROLL);
1061         } else {
1062                 gamesnd_play_iface(SND_GENERAL_FAIL);
1063         }
1064                 
1065         if (Player_select_pilot < Player_select_list_start){
1066                 Player_select_list_start = Player_select_pilot;
1067         }
1068 }
1069
1070 // scroll the list of players down
1071 void player_select_scroll_list_down()
1072 {       
1073         // change the pilot selected index and play the appropriate sound
1074         if (Player_select_pilot < Player_select_num_pilots - 1) {
1075                 Player_select_pilot++;
1076                 gamesnd_play_iface(SND_SCROLL);
1077         } else {
1078                 gamesnd_play_iface(SND_GENERAL_FAIL);
1079         }
1080                 
1081         if (Player_select_pilot >= (Player_select_list_start + Player_select_max_lines[gr_screen.res])){
1082                 Player_select_list_start++;
1083         }
1084 }
1085
1086 // fill in the data on the last played pilot (callsign and is_multi or not)
1087 int player_select_get_last_pilot_info()
1088 {
1089         const char *last_player;
1090
1091         last_player = os_config_read_string( NULL, "LastPlayer", NULL);
1092         
1093         if(last_player == NULL){
1094                 return 0;               
1095         } else {
1096                 strcpy(Player_select_last_pilot,last_player);
1097         }
1098
1099         // determine if he was a single or multi-player based upon the last character in his callsign
1100         Player_select_last_is_multi = Player_select_last_pilot[strlen(Player_select_last_pilot)-1] == 'M' ? 1 : 0;
1101         Player_select_last_pilot[strlen(Player_select_last_pilot)-1]='\0';
1102
1103         return 1;       
1104 }
1105
1106 int player_select_get_last_pilot()
1107 {
1108         // if the player has the Cmdline_use_last_pilot command line option set, try and drop out quickly
1109         if(Cmdline_use_last_pilot){                     
1110                 int idx;                                
1111
1112                 if(!player_select_get_last_pilot_info()){
1113                         return 0;
1114                 }
1115
1116                 if(Player_select_last_is_multi){
1117                         Player_select_num_pilots = cf_get_file_list_preallocated(MAX_PILOTS, Pilots_arr, Pilots, CF_TYPE_MULTI_PLAYERS, NOX("*.plr"), CF_SORT_TIME);                            
1118                 } else {
1119                         Player_select_num_pilots = cf_get_file_list_preallocated(MAX_PILOTS, Pilots_arr, Pilots, CF_TYPE_SINGLE_PLAYERS, NOX("*.plr"), CF_SORT_TIME);                                           
1120                 }
1121
1122                 Player_select_pilot = -1;
1123                 idx = 0;
1124                 // pick the last player         
1125                 for(idx=0;idx<Player_select_num_pilots;idx++){
1126                         if(strcmp(Player_select_last_pilot,Pilots_arr[idx])==0){
1127                                 Player_select_pilot = idx;
1128                                 break;
1129                         }
1130                 }               
1131
1132                 // set this so that we don't incorrectly create a "blank" pilot - .plr
1133                 // in the player_select_close() function
1134                 Player_select_num_pilots = 0;
1135
1136                 // if we've actually found a valid pilot, load him up           
1137                 if(Player_select_pilot != -1){
1138                         Player = &Players[0];                   
1139                         read_pilot_file(Pilots_arr[idx],!Player_select_last_is_multi,Player);
1140                         Player->flags |= PLAYER_FLAGS_STRUCTURE_IN_USE;
1141                         return 1;               
1142                 }                       
1143         } 
1144
1145         return 0;
1146 }
1147
1148 void player_select_init_player_stuff(int mode)
1149 {                       
1150         Player_select_list_start = 0;   
1151
1152         // set the select mode to single player for default
1153         Player_select_mode = mode;
1154
1155         // load up the list of players based upon the Player_select_mode (single or multiplayer)
1156         Get_file_list_filter = player_select_pilot_file_filter;
1157         if (mode == PLAYER_SELECT_MODE_SINGLE){
1158                 Player_select_num_pilots = cf_get_file_list_preallocated(MAX_PILOTS, Pilots_arr, Pilots, CF_TYPE_SINGLE_PLAYERS, NOX("*.plr"), CF_SORT_TIME);
1159         } else {
1160                 Player_select_num_pilots = cf_get_file_list_preallocated(MAX_PILOTS, Pilots_arr, Pilots, CF_TYPE_MULTI_PLAYERS, NOX("*.plr"), CF_SORT_TIME);
1161         }
1162
1163         Player = NULL;  
1164
1165         // if this value is -1, it means we should set it to the num pilots count
1166         if(Player_select_initial_count == -1){
1167                 Player_select_initial_count = Player_select_num_pilots;
1168         }
1169                 
1170         // select the first pilot if any exist, otherwise set to -1
1171         if (Player_select_num_pilots == 0) {            
1172                 Player_select_pilot = -1;               
1173                 player_select_set_middle_text(XSTR( "Type Callsign and Press Enter", 381));
1174                 player_select_set_controls(1);          // gray out the controls
1175                 player_select_create_new_pilot();
1176         } else {
1177                 Player_select_pilot = 0;        
1178         }
1179 }
1180
1181 void player_select_draw_list()
1182 {
1183         int idx;
1184
1185         for (idx=0; idx<Player_select_max_lines[gr_screen.res]; idx++) {
1186                 // only draw as many pilots as we have
1187                 if ((idx + Player_select_list_start) == Player_select_num_pilots)
1188                         break;
1189
1190                 // if the currently selected pilot is this line, draw it highlighted
1191                 if ( (idx + Player_select_list_start) == Player_select_pilot) {
1192                         // if he's the active pilot and is also the current selection, super-highlight him                                                                      
1193                         gr_set_color_fast(&Color_text_active);
1194                 }
1195                 // otherwise draw him normally
1196                 else {
1197                         gr_set_color_fast(&Color_text_normal);
1198                 }
1199                 
1200                 // draw the actual callsign
1201                 gr_printf(Choose_list_coords[gr_screen.res][0], Choose_list_coords[gr_screen.res][1] + (idx * gr_get_font_height()), Pilots[idx + Player_select_list_start]);
1202         }
1203 }
1204
1205 void player_select_process_noninput(int k)
1206 {
1207         int idx;
1208         
1209         // check for pressed buttons
1210         for (idx=0; idx<NUM_PLAYER_SELECT_BUTTONS; idx++) {
1211                 if (Player_select_buttons[gr_screen.res][idx].button.pressed()) {
1212                         player_select_button_pressed(idx);
1213                 }
1214         }       
1215
1216         // check for keypresses
1217         switch (k) {                    
1218         // quit the game entirely
1219         case KEY_ESC:
1220                 gameseq_post_event(GS_EVENT_QUIT_GAME);
1221                 break;
1222
1223         case KEY_ENTER | KEY_CTRLED:
1224                 player_select_button_pressed(ACCEPT_BUTTON);
1225                 break;
1226
1227         // delete the currently highlighted pilot
1228         case KEY_DELETE:
1229                 if (Player_select_pilot >= 0) {
1230                         int ret;
1231
1232                         // display a popup requesting confirmation
1233                         ret = popup(PF_USE_AFFIRMATIVE_ICON | PF_USE_NEGATIVE_ICON,2,POPUP_NO,POPUP_YES,XSTR( "Are you sure you want to delete this pilot?", 383));                                                                             
1234
1235                         // delete the pilot
1236                         if(ret == 1){
1237                                 player_select_delete_pilot();
1238                         } 
1239                 }
1240                 break;  
1241         }
1242
1243         // check to see if the user has clicked on the "list region" button
1244         // and change the selected pilot appropriately
1245         if (Player_select_list_region.pressed()) {
1246                 int click_y;
1247                 // get the mouse position
1248                 Player_select_list_region.get_mouse_pos(NULL, &click_y);
1249                 
1250                 // determine what index to select
1251                 //idx = (click_y+5) / 10;
1252                 idx = click_y / gr_get_font_height();
1253
1254
1255                 // if he selected a valid item
1256                 if(((idx + Player_select_list_start) < Player_select_num_pilots) && (idx >= 0)){
1257                         Player_select_pilot = idx + Player_select_list_start;                   
1258                 }
1259         }
1260
1261         // if the player has double clicked on a valid pilot, choose it and hit the accept button
1262         if (Player_select_list_region.double_clicked()) {
1263                 if ((Player_select_pilot >= 0) && (Player_select_pilot < Player_select_num_pilots)) {
1264                         player_select_button_pressed(ACCEPT_BUTTON);
1265                 }
1266         }
1267 }
1268
1269 void player_select_process_input(int k)
1270 {
1271         char buf[CALLSIGN_LEN + 1];
1272         int idx,z;
1273         
1274         // if the player is in the process of typing in a new pilot name...
1275         switch (k) {
1276         // cancel create pilot
1277         case KEY_ESC:
1278                 player_select_cancel_create();          
1279                 break;
1280
1281         // accept a new pilot name
1282         case KEY_ENTER:
1283                 Player_select_input_box.get_text(buf);
1284                 drop_white_space(buf);
1285                 z = 0;
1286                 if (!isalpha(*buf)) {
1287                         z = 1;
1288                 } else {
1289                         for (idx=1; buf[idx]; idx++) {
1290                                 if (!isalpha(buf[idx]) && !isdigit(buf[idx]) && !strchr(VALID_PILOT_CHARS, buf[idx])) {
1291                                         z = 1;
1292                                         break;
1293                                 }
1294                         }
1295                 }
1296
1297                 for (idx=1; idx<Player_select_num_pilots; idx++) {
1298                         if (!stricmp(buf, Pilots[idx])) {
1299                                 // verify if it is ok to overwrite the file
1300                                 if (pilot_verify_overwrite() == 1) {
1301                                         // delete the pilot and select the beginning of the list
1302                                         Player_select_pilot = idx;
1303                                         player_select_delete_pilot();
1304                                         Player_select_pilot = 0;
1305                                         idx = Player_select_num_pilots;
1306                                         z = 0;
1307
1308                                 } else
1309                                         z = 1;
1310
1311                                 break;
1312                         }
1313                 }
1314
1315                 if (!*buf || (idx < Player_select_num_pilots)) {
1316                         z = 1;
1317                 }
1318
1319                 if (z) {
1320                         gamesnd_play_iface(SND_GENERAL_FAIL);
1321                         break;
1322                 }               
1323
1324                 // Create the new pilot, and write out his file
1325                 strcpy(Pilots[0], buf);
1326
1327                 // if this is the first guy, we should set the Player struct
1328                 if (Player == NULL) {
1329                         Player = &Players[0];
1330                         memset(Player, 0, sizeof(player));
1331                         Player->flags |= PLAYER_FLAGS_STRUCTURE_IN_USE;
1332                 }
1333
1334                 strcpy(Player->callsign, buf);
1335                 init_new_pilot(Player, !Player_select_clone_flag);
1336
1337                 // set him as being a multiplayer pilot if we're in the correct mode
1338                 if (Player_select_mode == PLAYER_SELECT_MODE_MULTI) {
1339                         Player->flags |= PLAYER_FLAGS_IS_MULTI;
1340                         Player->stats.flags |= STATS_FLAG_MULTIPLAYER;
1341                 }
1342
1343                 // create his pilot file
1344                 write_pilot_file(Player);
1345
1346                 // unset the player
1347                 memset(Player, 0, sizeof(player));
1348                 Player = NULL;
1349
1350                 // make this guy the selected pilot and put him first on the list
1351                 Player_select_pilot = 0;
1352                                 
1353                 // unset the input mode
1354                 player_select_set_input_mode(0);
1355
1356                 // clear any pending bottom text
1357                 player_select_set_bottom_text("");              
1358
1359                 // clear any pending middle text
1360                 player_select_set_middle_text("");
1361                                 
1362                 // ungray all the controls
1363                 player_select_set_controls(0);
1364
1365                 // evaluate whether or not this is the very first pilot
1366                 player_select_eval_very_first_pilot();
1367                 break;
1368
1369         case 0:
1370                 break;
1371
1372         // always kill middle text when a char is pressed in input mode
1373         default:
1374                 player_select_set_middle_text("");
1375                 break;
1376         }
1377 }
1378     
1379 // draw copyright message on the bottom on the screen
1380 void player_select_display_copyright()
1381 {
1382         int     sx, sy, w;
1383         char    Copyright_msg1[256], Copyright_msg2[256];
1384
1385 #ifdef MAKE_FS1
1386         gr_set_color_fast(&Color_bright);
1387
1388         if (Lcl_gr) {
1389                 sprintf(Copyright_msg1, XSTR("Descent: FreeSpace - The Great War, Copyright %c 1998, Volition, Inc.", 384), '\xA8');
1390         } else {
1391                 sprintf(Copyright_msg1, XSTR("Descent: FreeSpace - The Great War, Copyright %c 1998, Volition, Inc.", 384), '\x83');
1392         }
1393         sprintf(Copyright_msg2, XSTR("All Rights Reserved", 385));
1394 #else
1395         gr_set_color_fast(&Color_white);
1396
1397         sprintf(Copyright_msg1, NOX("FreeSpace 2"));
1398         if (Lcl_gr) {
1399                 sprintf(Copyright_msg2, XSTR("Copyright %c 1999, Volition, Inc.  All rights reserved.", 385), '\xA8');
1400         } else {
1401                 sprintf(Copyright_msg2, XSTR("Copyright %c 1999, Volition, Inc.  All rights reserved.", 385), '\x83');
1402         }
1403 #endif // MAKE_FS1
1404
1405         gr_get_string_size(&w, NULL, Copyright_msg1);
1406         sx = fl2i((gr_screen.max_w / 2) - w/2.0f + 0.5f);
1407         sy = (gr_screen.max_h - 2) - 2*gr_get_font_height();
1408         gr_string(sx, sy, Copyright_msg1);
1409
1410         gr_get_string_size(&w, NULL, Copyright_msg2);
1411         sx = fl2i((gr_screen.max_w / 2) - w/2.0f + 0.5f);
1412         sy = (gr_screen.max_h - 2) - gr_get_font_height();
1413         gr_string(sx, sy, Copyright_msg2);
1414 }
1415
1416 void player_select_display_all_text()
1417 {
1418         int w, h;
1419
1420         // only draw if we actually have a valid string
1421         if (strlen(Player_select_bottom_text)) {
1422                 gr_get_string_size(&w, &h, Player_select_bottom_text);
1423         
1424                 w = (gr_screen.max_w - w) / 2;
1425 #ifdef MAKE_FS1
1426                 gr_set_color_fast(&Color_bright);
1427 #else
1428                 gr_set_color_fast(&Color_bright_white);
1429 #endif
1430                 gr_printf(w, Player_select_bottom_text_y[gr_screen.res], Player_select_bottom_text);
1431         }
1432
1433         // only draw if we actually have a valid string
1434         if (strlen(Player_select_middle_text)) {
1435                 gr_get_string_size(&w, &h, Player_select_middle_text);
1436         
1437                 w = (gr_screen.max_w - w) / 2;
1438                 gr_set_color_fast(&Color_bright_white);
1439                 gr_printf(w, Player_select_middle_text_y[gr_screen.res], Player_select_middle_text);
1440         }
1441 }
1442
1443 int player_select_pilot_file_filter(const char *filename)
1444 {
1445         return !verify_pilot_file(filename, Player_select_mode == PLAYER_SELECT_MODE_SINGLE);
1446 }
1447
1448 void player_select_set_bottom_text(const char *txt)
1449 {
1450         if (txt) {
1451                 strncpy(Player_select_bottom_text, txt, 149);
1452         }
1453 }
1454
1455 void player_select_set_middle_text(const char *txt)
1456 {
1457         if (txt) {
1458                 strncpy(Player_select_middle_text, txt, 149);
1459         }
1460 }
1461
1462 void player_select_eval_very_first_pilot()
1463 {       
1464         // never bring up the initial main hall help overlay
1465         // Player_select_very_first_pilot = 0;
1466
1467         // if we already have this flag set, check to see if our callsigns match
1468         if(Player_select_very_first_pilot){
1469                 // if the callsign has changed, unset the flag
1470                 if(strcmp(Player_select_very_first_pilot_callsign,Pilots[Player_select_pilot])){
1471                         Player_select_very_first_pilot = 0;
1472                 }
1473         }
1474         // otherwise check to see if there is only 1 pilot
1475         else {
1476                 if((Player_select_num_pilots == 1) && (Player_select_initial_count == 0)){
1477                         // set up the data
1478                         Player_select_very_first_pilot = 1;
1479                         strcpy(Player_select_very_first_pilot_callsign,Pilots[Player_select_pilot]);
1480                 }
1481         }
1482 }
1483
1484 void player_select_commit()
1485 {
1486         // if we've gotten to this point, we should have ensured this was the case
1487         Assert(Player_select_num_pilots > 0);
1488         
1489         gameseq_post_event(GS_EVENT_MAIN_MENU);
1490         gamesnd_play_iface(SND_COMMIT_PRESSED);
1491
1492         // evaluate if this is the _very_ first pilot
1493         player_select_eval_very_first_pilot();
1494
1495
1496 void player_select_cancel_create()
1497 {
1498         int idx;
1499
1500         Player_select_num_pilots--;
1501
1502         // make sure we correct the Selected_pilot index to account for the cancelled action
1503         if (Player_select_num_pilots == 0) {
1504                 Player_select_pilot = -1;
1505         }
1506
1507         // move all pilots down
1508         for (idx=0; idx<Player_select_num_pilots; idx++) {
1509                 strcpy(Pilots[idx], Pilots[idx + 1]);
1510         }
1511
1512         // unset the input mode
1513         player_select_set_input_mode(0);
1514
1515         // clear any bottom text
1516         player_select_set_bottom_text("");
1517
1518         // clear any middle text
1519         player_select_set_middle_text("");
1520
1521         // ungray all controls
1522         player_select_set_controls(0);
1523
1524         // disable the autoaccept
1525         Player_select_autoaccept = 0;
1526 }
1527
1528 DCF(bastion,"Sets the player to be on the bastion")
1529 {
1530         if(gameseq_get_state() == GS_STATE_INITIAL_PLAYER_SELECT){
1531                 Player_select_force_bastion = 1;
1532                 dc_printf("Player is now in the Bastion\n");
1533         }
1534 }
1535
1536 #define MAX_PLAYER_TIPS                 40
1537
1538 char *Player_tips[MAX_PLAYER_TIPS];
1539 int Num_player_tips;
1540 int Player_tips_shown = 0;
1541
1542 // tooltips
1543 void player_tips_init()
1544 {
1545 #ifndef MAKE_FS1
1546         Num_player_tips = 0;
1547
1548         // begin external localization stuff
1549         lcl_ext_open();
1550
1551         read_file_text("tips.tbl");
1552         reset_parse();
1553
1554         while(!optional_string("#end")){
1555                 required_string("+Tip:");
1556
1557                 if(Num_player_tips >= MAX_PLAYER_TIPS){
1558                         break;
1559                 }
1560                 Player_tips[Num_player_tips++] = stuff_and_malloc_string(F_NAME, NULL, 1024);                           
1561         }
1562
1563         // stop externalizing, homey
1564         lcl_ext_close();
1565 #endif
1566 }
1567
1568 void player_tips_close()
1569 {
1570 #ifndef MAKE_FS1
1571         int i;
1572         
1573         for (i=0; i<MAX_PLAYER_TIPS; i++) {
1574                 if (Player_tips[i]) {
1575                         free(Player_tips[i]);
1576                         Player_tips[i] = NULL;
1577                 }
1578         }
1579 #endif
1580 }
1581
1582 void player_tips_popup()
1583 {
1584 #ifndef MAKE_FS1
1585         int tip, ret;   
1586         
1587         // player has disabled tips
1588         if((Player != NULL) && !Player->tips){
1589                 return;
1590         }
1591         // only show tips once per instance of Freespace
1592         if(Player_tips_shown == 1){
1593                 return;
1594         }
1595         Player_tips_shown = 1;
1596
1597         // randomly pick one
1598         tip = (int)frand_range(0.0f, (float)Num_player_tips - 1.0f);
1599
1600         char all_txt[2048];     
1601
1602         do {
1603                 sprintf(all_txt, XSTR("NEW USER TIP\n\n%s", 1565), Player_tips[tip]);
1604                 ret = popup(PF_NO_SPECIAL_BUTTONS | PF_TITLE | PF_TITLE_WHITE, 3, XSTR("&Ok", 669), XSTR("&Next", 1444), XSTR("Don't show me this again", 1443), all_txt);
1605                 
1606                 // now what?
1607                 switch(ret){
1608                 // next
1609                 case 1:
1610                         if(tip >= Num_player_tips - 1){
1611                                 tip = 0;
1612                         } else {
1613                                 tip++;
1614                         }
1615                         break;
1616
1617                 // don't show me this again
1618                 case 2:
1619                         ret = 0;
1620                         Player->tips = 0;
1621                         write_pilot_file(Player);
1622                         break;
1623                 }
1624         } while(ret > 0);
1625 #endif
1626 }