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/Playerman/ManagePilot.cpp $
15 * ManagePilot.cpp has code to load and save pilot files, and to select and
19 * Revision 1.6 2004/07/04 11:41:24 taylor
20 * warning fixes, cross platform pilot compat with OSX-Linux-Windows
22 * Revision 1.5 2003/05/25 02:30:43 taylor
25 * Revision 1.4 2002/06/09 04:41:25 relnev
26 * added copyright header
28 * Revision 1.3 2002/06/09 03:16:05 relnev
31 * removed unneeded asm, old sdl 2d setup.
33 * fixed crash caused by opengl_get_region.
35 * Revision 1.2 2002/05/07 03:16:50 theoddone33
36 * The Great Newline Fix
38 * Revision 1.1.1.1 2002/05/03 03:28:11 root
42 * 41 9/13/99 4:52p Dave
45 * 40 9/01/99 10:09a Dave
48 * 39 8/26/99 8:49p Jefff
49 * old player file compatibility with new medal stuff
51 * 38 8/22/99 5:53p Dave
52 * Scoring fixes. Added self destruct key. Put callsigns in the logfile
53 * instead of ship designations for multiplayer players.
55 * 37 8/16/99 4:06p Dave
56 * Big honking checkin.
58 * 36 8/11/99 11:36a Jefff
59 * added compatibility w/ fs2 demo plr version
61 * 35 8/10/99 3:46p Jefff
62 * changes for Intelligence section of new tech room
64 * 34 8/04/99 11:38p Andsager
65 * make new pilot detail level match registry info.
67 * 33 8/02/99 9:55p Dave
68 * Hardcode a nice hud color config for the demo.
70 * 32 8/02/99 9:13p Dave
73 * 31 8/01/99 12:39p Dave
74 * Added HUD contrast control key (for nebula).
76 * 30 7/30/99 10:31p Dave
77 * Added comm menu to the configurable hud files.
79 * 29 7/29/99 10:47p Dave
80 * Standardized D3D fogging using vertex fog. Shook out Savage 4 bugs.
82 * 28 7/29/99 12:05a Dave
83 * Nebula speed optimizations.
85 * 27 7/24/99 1:54p Dave
86 * Hud text flash gauge. Reworked dead popup to use 4 buttons in red-alert
89 * 26 6/22/99 7:03p Dave
90 * New detail options screen.
92 * 25 6/16/99 4:06p Dave
93 * New pilot info popup. Added new draw-bitmap-as-poly function.
95 * 24 6/11/99 11:13a Dave
96 * last minute changes before press tour build.
98 * 23 6/08/99 1:14a Dave
99 * Multi colored hud test.
101 * 22 5/03/99 8:33p Dave
102 * New version of multi host options screen.
104 * 21 3/24/99 4:05p Dave
105 * Put in support for assigning the player to a specific squadron with a
106 * specific logo. Preliminary work for doing pos/orient checksumming in
107 * multiplayer to reduce bandwidth.
109 * 20 1/30/99 1:29a Dave
110 * Fixed nebula thumbnail problem. Full support for 1024x768 choose pilot
111 * screen. Fixed beam weapon death messages.
113 * 19 1/29/99 2:08a Dave
114 * Fixed beam weapon collisions with players. Reduced size of scoring
115 * struct for multiplayer. Disabled PXO.
117 * 18 1/21/99 2:06p Dave
118 * Final checkin for multiplayer testing.
120 * 17 1/15/99 2:49p Dave
121 * Fixed creation of pilots.
123 * 16 1/14/99 6:06p Dave
124 * 100% full squad logo support for single player and multiplayer.
126 * 15 1/12/99 3:15a Dave
127 * Barracks screen support for selecting squad logos. We need real artwork
130 * 14 1/06/99 2:24p Dave
131 * Stubs and release build fixes.
133 * 13 12/14/98 12:13p Dave
134 * Spiffed up xfer system a bit. Put in support for squad logo file xfer.
137 * 12 11/20/98 11:16a Dave
138 * Fixed up IPX support a bit. Making sure that switching modes and
139 * loading/saving pilot files maintains proper state.
141 * 11 11/19/98 4:51p Dave
142 * Ignore multiplayer protocol settings in the pilot file for now.
144 * 10 11/19/98 4:19p Dave
145 * Put IPX sockets back in psnet. Consolidated all multiplayer config
148 * 9 10/13/98 2:47p Andsager
149 * Remove reference to Tech_shivan_species_avail
151 * 8 10/13/98 9:29a Dave
152 * Started neatening up freespace.h. Many variables renamed and
153 * reorganized. Added AlphaColors.[h,cpp]
155 * 7 10/12/98 9:30a Andsager
156 * Clean up barracks.cpp. Remove unneeded ".h" files from ManagePilot
158 * 6 10/09/98 5:17p Andsager
159 * move barracks screen into barracks.cpp
161 * 5 10/09/98 2:57p Dave
162 * Starting splitting up OS stuff.
164 * 4 10/08/98 9:19a Andsager
165 * Clean up pilot player read and write, starting with new version.
167 * 3 10/07/98 6:27p Dave
168 * Globalized mission and campaign file extensions. Removed Silent Threat
169 * special code. Moved \cache \players and \multidata into the \data
172 * 2 10/07/98 10:53a Dave
175 * 1 10/07/98 10:50a Dave
177 * 279 9/21/98 10:02p Dave
178 * Last minute changes to techroom weapon/ship/species stuff.
180 * 278 9/08/98 12:10p Andsager
181 * Fixed a bug with saving ship and weapon info techroom flags.
183 * 277 9/01/98 4:25p Dave
184 * Put in total (I think) backwards compatibility between mission disk
185 * freespace and non mission disk freespace, including pilot files and
186 * campaign savefiles.
188 * 276 6/09/98 10:31a Hoffoss
189 * Created index numbers for all xstr() references. Any new xstr() stuff
190 * added from here on out should be added to the end if the list. The
191 * current list count can be found in FreeSpace.cpp (search for
194 * 275 6/05/98 9:49a Lawrance
197 * 274 6/01/98 11:43a John
198 * JAS & MK: Classified all strings for localization.
200 * 273 5/26/98 11:53a Allender
201 * fix multiplayer problems and sexpression crash
203 * 272 5/24/98 2:46p Lawrance
204 * Fix bug where skill level would be reset to default when switching
207 * 271 5/23/98 4:02p Allender
210 * 270 5/23/98 2:41p Mike
211 * Make Easy the default skill level and prevent old pilot's skill level
212 * from carrying into new pilot.
217 #include "managepilot.h"
219 #include "freespace.h"
220 #include "hudsquadmsg.h"
223 #include "eventmusic.h"
224 #include "audiostr.h"
225 #include "osregistry.h"
227 #include "playermenu.h"
228 #include "missionshipchoice.h"
229 #include "hudconfig.h"
231 #include "redalert.h"
232 #include "techmenu.h"
235 #include "cutscenes.h"
239 // update this when altering data that is read/written to .PLR file
241 #define CURRENT_PLAYER_FILE_VERSION 140
243 // 99: original retail release (version 1.00)
244 // 100: retail mission pack update (version 1.04)
245 #define CURRENT_PLAYER_FILE_VERSION 100
246 #define PREVIOUS_PLAYER_FILE_VERSION 99
248 #define FS2_DEMO_PLAYER_FILE_VERSION 135
250 #define LOWEST_COMPATIBLE_PLAYER_FILE_VERSION CURRENT_PLAYER_FILE_VERSION // demo plr files should work in final
252 #define LOWEST_COMPATIBLE_PLAYER_FILE_VERSION PREVIOUS_PLAYER_FILE_VERSION
255 // keep track of pilot file changes here
256 // version 2 : Added squad logo filename
257 // version 3 : Changed size of scoring struct. use ushort instead of ints for storing alltime kills by ship type
258 // version 4/5 : Added squadron name field
259 // version 6 : changed max length on a multiplayer options field
260 // version 130 : changed size of hud config struct
261 // version 133 : misc changes. new hud gauge
262 // version 134 : added HUD contrast toggle key
263 // version 135 : added tips flag (THIS IS THE DEMO VERSION - RETAIN COMPATIBILITY FROM HERE ON OUT)
264 // version 136 : added intelligence flags to tech room visibility data
265 // version 137 : 2 new HUD gauges.
266 // version 138 : new multiplayer config
267 // version 139 : # medals increased - added compatibility with old plr file versions
268 // version 140 : ships table reordered. clear out old pilot files
269 // search for PLAYER INIT for new pilot initialization stuff. I _think_ its in the right spot for now
270 #define PLR_FILE_ID 0x46505346 // FPSF, unique signiture to identify a .PLR file (FreeSpace Player File) // FPSF appears as FSPF in file.
273 #define PLR_MAX_SHIP_TYPES_OLD 75
274 #define PLR_MAX_WEAPON_TYPES_OLD 44
276 extern void hud_config_set_color(int color);
279 // Current content of a .PLR file
285 // pilot pic image list stuff ( call pilot_load_pic_list() to make these valid )
286 char Pilot_images_arr[MAX_PILOT_IMAGES][MAX_FILENAME_LEN];
287 char *Pilot_image_names[MAX_PILOT_IMAGES];
288 int Num_pilot_images = 0;
290 // squad logo list stuff (call pilot_load_squad_pic_list() to make these valid )
291 char Pilot_squad_images_arr[MAX_PILOT_IMAGES][MAX_FILENAME_LEN];
292 char *Pilot_squad_image_names[MAX_PILOT_IMAGES];
293 int Num_pilot_squad_images = 0;
295 static uint Player_file_version;
297 // forward declarations
298 void read_detail_settings(CFILE *file, int Player_file_version);
299 void write_detail_settings(CFILE *file);
300 void read_stats_block(CFILE *file, int Player_file_version, scoring_struct *stats);
301 void write_stats_block(CFILE *file, scoring_struct *stats);
302 void read_multiplayer_options(player *p,CFILE *file);
303 void write_multiplayer_options(player *p,CFILE *file);
305 static SDL_Keycode keycode_translate_from(short keycode);
306 static short keycode_translate_to(SDL_Keycode keycode);
308 // internal function to delete a player file. Called after a pilot is obsoleted, and when a pilot is deleted
309 // used in barracks and player_select
310 void delete_pilot_file( const char *pilot_name, int single )
312 char filename[MAX_FILENAME_LEN];
313 char basename[MAX_FILENAME_LEN];
315 // get the player file.
317 base_filename(pilot_name, basename, SDL_arraysize(basename));
319 SDL_strlcpy( filename, basename, SDL_arraysize(filename) );
320 SDL_strlcat(filename, NOX(".plr"), SDL_arraysize(filename) );
321 if (Player_sel_mode == PLAYER_SELECT_MODE_SINGLE){
322 cf_delete(filename, CF_TYPE_SINGLE_PLAYERS);
324 cf_delete(filename, CF_TYPE_MULTI_PLAYERS);
327 // we must try and delete the campaign save files for a pilot as well.
328 mission_campaign_delete_all_savefiles( basename, !single );
331 // check if a pilot file is valid or not (i.e. is usable, not out of date, etc)
332 // used in barracks and player_select
333 int verify_pilot_file(const char *filename, int single, int *rank)
336 uint id, file_version;
339 filename = cf_add_ext(filename, NOX(".plr"));
342 file = cfopen(filename, "rb", CFILE_NORMAL, CF_TYPE_SINGLE_PLAYERS);
344 file = cfopen(filename, "rb", CFILE_NORMAL, CF_TYPE_MULTI_PLAYERS);
351 id = cfread_uint(file);
352 if (id != PLR_FILE_ID) {
353 nprintf(("Warning", "Player file has invalid signature\n"));
355 delete_pilot_file( filename, single );
359 // check for compatibility here
360 file_version = cfread_uint(file);
361 /* if (file_version < INITIAL_RELEASE_FILE_VERSION) { */
362 // if (file_version != CURRENT_PLAYER_FILE_VERSION) {
363 if (file_version < LOWEST_COMPATIBLE_PLAYER_FILE_VERSION) {
364 nprintf(("Warning", "WARNING => Player file is outdated and not compatible...\n"));
366 delete_pilot_file( filename, single );
370 type = !cfread_ubyte(file);
376 *rank = cfread_int(file);
389 void pilot_write_techroom_data(CFILE *file)
394 // write the ship and weapon count
395 cfwrite_int(Num_ship_types, file);
396 cfwrite_int(Num_weapon_types, file);
398 cfwrite_int(Intel_info_size, file);
401 // write all ship flags out
402 for (idx=0; idx<Num_ship_types; idx++) {
403 out = (Ship_info[idx].flags & SIF_IN_TECH_DATABASE) ? (ubyte)1 : (ubyte)0;
404 cfwrite_ubyte(out, file);
407 // write all weapon types out
408 for (idx=0; idx<Num_weapon_types; idx++) {
409 out = (Weapon_info[idx].wi_flags & WIF_IN_TECH_DATABASE) ? (ubyte)1 : (ubyte)0;
410 cfwrite_ubyte(out, file);
414 // write all intel entry flags out
415 for (idx=0; idx<Intel_info_size; idx++) {
416 cfwrite_ubyte((ubyte)Intel_info[idx].in_tech_db, file);
419 // whether shivans are visible or not
420 int shivans = Intel_info[2].in_tech_db ? 1 : 0;
421 cfwrite_int(shivans, file);
427 void pilot_read_techroom_data(CFILE *file)
430 int ship_count, weapon_count, shivans;
433 if (Player_file_version < 100) {
436 // first set of ships visible
437 vflags = cfread_int(file);
439 for (idx = 0; idx < 32; idx++) {
440 if ( (vflags & (1<<idx)) && (idx < Num_ship_types) ) {
441 Ship_info[idx].flags |= SIF_IN_TECH_DATABASE | SIF_IN_TECH_DATABASE_M;
442 } else if (idx < Num_ship_types) {
443 Ship_info[idx].flags &= ~SIF_IN_TECH_DATABASE;
447 // second set of ships visible
448 vflags = cfread_int(file);
450 for (idx = 0; idx < 32; idx++) {
451 if ( (vflags & (1<<idx)) && ((idx+32) < Num_ship_types) ) {
452 Ship_info[idx+32].flags |= SIF_IN_TECH_DATABASE | SIF_IN_TECH_DATABASE_M;
453 } else if ((idx+32) < Num_ship_types) {
454 Ship_info[idx+32].flags &= ~SIF_IN_TECH_DATABASE;
458 // last set of ships visible
459 vflags = cfread_int(file);
461 for (idx = 0; idx < 32; idx++) {
462 if ( (vflags & (1<<idx)) && ((idx+64) < Num_ship_types) ) {
463 Ship_info[idx+64].flags |= SIF_IN_TECH_DATABASE | SIF_IN_TECH_DATABASE_M;
464 } else if ((idx+64) < Num_ship_types) {
465 Ship_info[idx+64].flags &= ~SIF_IN_TECH_DATABASE;
469 // first set of weapons visible
470 vflags = cfread_int(file);
472 for (idx = 0; idx < 32; idx++) {
473 if ( (vflags & (1<<idx)) && (idx < Num_weapon_types) ) {
474 Weapon_info[idx].wi_flags |= WIF_IN_TECH_DATABASE;
475 } else if (idx < Num_ship_types) {
476 Weapon_info[idx].wi_flags &= ~WIF_IN_TECH_DATABASE;
480 // last set of weapons visible
481 vflags = cfread_int(file);
483 for (idx = 0; idx < 32; idx++) {
484 if ( (vflags & (1<<idx)) && ((idx+32) < Num_weapon_types) ) {
485 Weapon_info[idx+32].wi_flags |= WIF_IN_TECH_DATABASE;
486 } else if ((idx+32) < Num_ship_types) {
487 Weapon_info[idx+32].wi_flags &= ~WIF_IN_TECH_DATABASE;
492 shivans = cfread_int(file);
495 Intel_info[2].in_tech_db = 1;
497 Intel_info[2].in_tech_db = 0;
500 // read in ship and weapon counts
501 ship_count = cfread_int(file);
502 weapon_count = cfread_int(file);
503 SDL_assert(ship_count <= MAX_SHIP_TYPES);
504 SDL_assert(weapon_count <= MAX_WEAPON_TYPES);
507 for (idx=0; idx<ship_count; idx++) {
508 in = cfread_ubyte(file);
510 Ship_info[idx].flags |= SIF_IN_TECH_DATABASE | SIF_IN_TECH_DATABASE_M;
512 Ship_info[idx].flags &= ~SIF_IN_TECH_DATABASE;
516 // read all weapons in
517 for (idx=0; idx<weapon_count; idx++) {
518 in = cfread_ubyte(file);
520 Weapon_info[idx].wi_flags |= WIF_IN_TECH_DATABASE;
522 Weapon_info[idx].wi_flags &= ~WIF_IN_TECH_DATABASE;
527 shivans = cfread_int(file);
530 Intel_info[2].in_tech_db = 1;
532 Intel_info[2].in_tech_db = 0;
537 void pilot_read_techroom_data(CFILE *file)
540 int ship_count, weapon_count, intel_count;
543 // read in ship and weapon counts
544 ship_count = cfread_int(file);
545 weapon_count = cfread_int(file);
546 SDL_assert(ship_count <= MAX_SHIP_TYPES);
547 SDL_assert(weapon_count <= MAX_WEAPON_TYPES);
549 // maintain compatibility w/ demo version
550 if (Player_file_version < 136) {
551 // skip over all this data, because the lack of tech room in the demo
552 // left this all hosed in the demo .plr files
553 // this will all get initialized as if this fella was a new pilot
554 for (idx=0; idx<ship_count+weapon_count; idx++) {
560 intel_count = cfread_int(file);
561 SDL_assert(intel_count <= MAX_INTEL_ENTRIES);
564 for (idx=0; idx<ship_count; idx++) {
565 in = cfread_ubyte(file);
567 Ship_info[idx].flags |= SIF_IN_TECH_DATABASE | SIF_IN_TECH_DATABASE_M;
569 Ship_info[idx].flags &= ~SIF_IN_TECH_DATABASE;
573 // read all weapons in
574 for (idx=0; idx<weapon_count; idx++) {
575 in = cfread_ubyte(file);
577 Weapon_info[idx].wi_flags |= WIF_IN_TECH_DATABASE;
579 Weapon_info[idx].wi_flags &= ~WIF_IN_TECH_DATABASE;
583 // read all intel entries in
584 for (idx=0; idx<intel_count; idx++) {
585 in = cfread_ubyte(file);
587 Intel_info[idx].in_tech_db = 1;
589 Intel_info[idx].in_tech_db = 0;
596 // write out the player ship selection
597 void pilot_write_loadout(CFILE *file)
602 cfwrite_string_len(Player_loadout.filename, file);
603 cfwrite_string_len(Player_loadout.last_modified, file);
605 // write ship and weapon counts
606 cfwrite_int(Num_ship_types, file);
607 cfwrite_int(Num_weapon_types, file);
610 for ( i = 0; i < Num_ship_types; i++ ) {
611 cfwrite_int(Player_loadout.ship_pool[i], file);
614 // write weapons pool
615 for ( i = 0; i < Num_weapon_types; i++ ) {
616 cfwrite_int(Player_loadout.weapon_pool[i], file);
619 // write ship loadouts
620 for ( i = 0; i < MAX_WSS_SLOTS; i++ ) {
621 slot = &Player_loadout.unit_data[i];
622 cfwrite_int(slot->ship_class, file);
623 for ( j = 0; j < MAX_WL_WEAPONS; j++ ) {
624 cfwrite_int(slot->wep[j], file);
625 cfwrite_int(slot->wep_count[j], file);
630 // read in the ship selection for the pilot
631 void pilot_read_loadout(CFILE *file)
635 int ship_count, weapon_count;
637 memset(Player_loadout.filename, 0, MAX_FILENAME_LEN);
638 cfread_string_len(Player_loadout.filename, MAX_FILENAME_LEN, file);
640 memset(Player_loadout.last_modified, 0, DATE_TIME_LENGTH);
641 cfread_string_len(Player_loadout.last_modified, DATE_TIME_LENGTH, file);
643 // read in ship and weapon counts
645 ship_count = cfread_int(file);
646 weapon_count = cfread_int(file);
648 if (Player_file_version < 100) {
649 ship_count = PLR_MAX_SHIP_TYPES_OLD;
650 weapon_count = PLR_MAX_WEAPON_TYPES_OLD;
652 ship_count = cfread_int(file);
653 weapon_count = cfread_int(file);
657 SDL_assert(ship_count <= MAX_SHIP_TYPES);
658 SDL_assert(weapon_count <= MAX_WEAPON_TYPES);
661 for ( i = 0; i < ship_count; i++ ) {
662 Player_loadout.ship_pool[i] = cfread_int(file);
665 // read in weapons pool
666 for ( i = 0; i < weapon_count; i++ ) {
667 Player_loadout.weapon_pool[i] = cfread_int(file);
670 // read in loadout info
671 for ( i = 0; i < MAX_WSS_SLOTS; i++ ) {
672 slot = &Player_loadout.unit_data[i];
673 slot->ship_class = cfread_int(file);
674 for ( j = 0; j < MAX_WL_WEAPONS; j++ ) {
675 slot->wep[j] = cfread_int(file);
676 slot->wep_count[j] = cfread_int(file);
683 // returns 0 - file read in correctly
684 // -1 - .PLR file doesn't exist or file not compatible
685 // >0 - errno from fopen error
686 // if single == 1, look for players in the single players directory, otherwise look in the
687 // multiplayers directory
688 int read_pilot_file(const char *callsign, int single, player *p)
692 char filename[MAX_FILENAME_LEN], ship_name[NAME_LENGTH];
698 SDL_assert((Player_num >= 0) && (Player_num < MAX_PLAYERS));
699 p = &Players[Player_num];
702 //sprintf(filename, "%-.8s.plr",Players[Player_num].callsign);
703 SDL_assert(strlen(callsign) < MAX_FILENAME_LEN - 4); // ensure we won't overrun the buffer
704 SDL_strlcpy( filename, callsign, SDL_arraysize(filename) );
705 SDL_strlcat( filename, NOX(".plr"), SDL_arraysize(filename) );
707 // if we're a standalone server in multiplayer, just fill in some bogus values since we don't have a pilot file
708 if ((Game_mode & GM_MULTIPLAYER) && (Game_mode & GM_STANDALONE_SERVER)) {
709 memset(Player, 0, sizeof(player));
710 SDL_strlcpy(Player->callsign, NOX("Standalone"), SDL_arraysize(Player->callsign));
711 SDL_strlcpy(Player->short_callsign, NOX("Standalone"), SDL_arraysize(Player->short_callsign));
715 // see comments at the beginning of function
717 file = cfopen(filename, "rb", CFILE_NORMAL, CF_TYPE_SINGLE_PLAYERS);
719 file = cfopen(filename, "rb", CFILE_NORMAL, CF_TYPE_MULTI_PLAYERS);
726 id = cfread_uint(file);
727 if (id != PLR_FILE_ID) {
728 Warning(LOCATION, "Player file has invalid signature");
733 // check for compatibility here
734 Player_file_version = cfread_uint(file);
735 cf_set_version( file, Player_file_version );
737 if (Player_file_version < LOWEST_COMPATIBLE_PLAYER_FILE_VERSION) {
738 nprintf(("Warning", "WARNING => Player file is outdated and not compatible...\n"));
740 delete_pilot_file( filename, single );
744 // read in whether he's a multiplayer or not
745 is_multi = cfread_ubyte(file);
747 p->flags |= PLAYER_FLAGS_IS_MULTI;
749 p->flags &= ~PLAYER_FLAGS_IS_MULTI; // this takes care of unsetting any leftover bits from a (possibly) previously selected pilot
755 // get player location
756 p->on_bastion = cfread_ubyte(file);
760 p->tips = cfread_int(file);
763 // write out the image file name
764 cfread_string_len(p->image_filename, MAX_FILENAME_LEN - 1, file);
766 // write out the image file name
767 p->insignia_texture = -1;
769 cfread_string_len(p->squad_name, NAME_LENGTH, file);
770 cfread_string_len(p->squad_filename, MAX_FILENAME_LEN - 1, file);
771 player_set_squad_bitmap(p, p->squad_filename);
774 // deal with campaign stuff. The way we store the information in the file is to first store the
775 // name of the current campaign that the player is playing. Next we store the info regarding the campaigns
776 // that the player is currently playing
777 memset(p->current_campaign, 0, MAX_FILENAME_LEN);
778 cfread_string_len(p->current_campaign, MAX_FILENAME_LEN, file);
780 // read in the ship name for last ship flown by the player
781 memset(ship_name, 0, NAME_LENGTH);
782 cfread_string_len(ship_name, NAME_LENGTH, file);
783 p->last_ship_flown_si_index = ship_info_lookup(ship_name);
784 if ( p->last_ship_flown_si_index < 0 ) {
785 nprintf(("Warning","WARNING => Ship class %s not located in Ship_info[] in player file\n",ship_name));
786 p->last_ship_flown_si_index = ship_info_lookup(default_player_ship);
789 // set all the entries in the control config arrays to -1 (undefined)
790 control_config_clear();
792 // ---------------------------------------------
793 // read in the keyboard/joystick mapping
794 // ---------------------------------------------
795 num_ctrls = cfread_ubyte(file);
796 for (i=0; i<num_ctrls; i++) {
797 key_value = cfread_short(file);
798 // NOTE: next two lines are only here for transitioning from 255 to -1 as undefined key items
799 if (key_value == 255)
802 Control_config[i].key_id = keycode_translate_from((short)key_value);
804 key_value = cfread_short(file);
805 // NOTE: next two lines are only here for transitioning from 255 to -1 as undefined key items
806 if (key_value == 255)
809 Control_config[i].joy_id = (short) key_value;
812 HUD_config.show_flags = cfread_int(file);
813 HUD_config.show_flags2 = cfread_int(file);
815 HUD_config.popup_flags = cfread_int(file);
816 HUD_config.popup_flags2 = cfread_int(file);
818 HUD_config.num_msg_window_lines = cfread_ubyte(file);
819 HUD_config.rp_flags = cfread_int(file);
820 HUD_config.rp_dist = cfread_int(file);
823 HUD_config.main_color = cfread_int(file);
824 HUD_color_alpha = cfread_int(file);
826 if ( HUD_color_alpha < HUD_COLOR_ALPHA_USER_MIN ) {
827 HUD_color_alpha = HUD_COLOR_ALPHA_DEFAULT;
830 hud_config_set_color(HUD_config.main_color);
832 // added 2 gauges with version 137
833 if(Player_file_version < 137){
834 for(i=0; i<NUM_HUD_GAUGES-2; i++){
835 cfread(&HUD_config.clr[i], sizeof(color), 1, file);
838 // set the 2 new gauges to be radar color
839 memcpy(&HUD_config.clr[NUM_HUD_GAUGES-2], &HUD_config.clr[HUD_RADAR], sizeof(color));
840 memcpy(&HUD_config.clr[NUM_HUD_GAUGES-1], &HUD_config.clr[HUD_RADAR], sizeof(color));
842 for(i=0; i<NUM_HUD_GAUGES; i++){
843 cfread(&HUD_config.clr[i], sizeof(color), 1, file);
848 // read in the cutscenes which have been viewed
849 Cutscenes_viewable = cfread_int(file);
851 Master_sound_volume = cfread_float(file);
852 Master_event_music_volume = cfread_float(file);
853 Master_voice_volume = cfread_float(file);
855 audiostream_set_volume_all(Master_voice_volume, ASF_VOICE);
856 audiostream_set_volume_all(Master_event_music_volume, ASF_EVENTMUSIC);
858 if ( Master_event_music_volume > 0.0f ) {
859 Event_music_enabled = 1;
861 Event_music_enabled = 0;
864 read_detail_settings(file, Player_file_version);
866 // restore list of most recently played missions
867 Num_recent_missions = cfread_int( file );
868 SDL_assert(Num_recent_missions <= MAX_RECENT_MISSIONS);
869 for ( i = 0; i < Num_recent_missions; i++ ) {
872 cfread_string_len( Recent_missions[i], MAX_FILENAME_LEN, file);
873 // Remove the extension
874 p = SDL_strchr(Recent_missions[i], '.');
879 // use this block of stats from now on
880 read_stats_block(file, Player_file_version, &p->stats);
882 Game_skill_level = cfread_int(file);
884 for (i=0; i<NUM_JOY_AXIS_ACTIONS; i++) {
885 Axis_map_to[i] = cfread_int(file);
886 Invert_axis[i] = cfread_int(file);
889 // restore some player flags
890 Player[Player_num].save_flags = cfread_int(file);
892 // restore the most recent ship selection
893 pilot_read_loadout(file);
895 // read in multiplayer options
896 read_multiplayer_options(p,file);
898 p->readyroom_listing_mode = cfread_int(file);
899 Briefing_voice_enabled = cfread_int(file);
901 // restore the default netgame protocol mode
902 int protocol_temp = cfread_int(file);
903 switch(protocol_temp){
906 Multi_options_g.pxo = 1;
907 Multi_options_g.protocol = NET_TCP;
912 Multi_options_g.protocol = NET_TCP;
915 // in case of IPX, which is deprecated
917 Multi_options_g.protocol = NET_TCP;
921 // restore wingman status used by red alert missions
922 red_alert_read_wingman_status(file, Player_file_version);
924 // read techroom data
925 pilot_read_techroom_data(file);
927 // restore auto-advance pref
928 Player->auto_advance = cfread_int(file);
930 Use_mouse_to_fly = cfread_int(file);
931 Mouse_sensitivity = cfread_int(file);
932 Joy_sensitivity = cfread_int(file);
933 Dead_zone_size = cfread_int(file);
938 // restore the callsign into the Player structure
939 SDL_strlcpy(p->callsign, callsign, SDL_arraysize(p->callsign));
941 // restore the truncated callsign into Player structure
942 pilot_set_short_callsign(p, SHORT_CALLSIGN_PIXEL_W);
944 // when we store the LastPlayer key, we have to mark it as being single or multiplayer, so we know where to look for him
945 // (since we could have a single and a multiplayer pilot with the same callsign)
946 // 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
949 SDL_strlcpy(cat, p->callsign, SDL_arraysize(cat));
951 SDL_strlcat(cat, NOX("M"), SDL_arraysize(cat));
953 SDL_strlcat(cat, NOX("S"), SDL_arraysize(cat));
955 os_config_write_string( NULL, "LastPlayer", cat );
957 // if he's not a multiplayer pilot, then load in the campaign file at this point!
959 if (mission_campaign_load_by_name(campaign_fname)) {
960 strcpy(campaign_fname, BUILTIN_CAMPAIGN);
961 if (mission_campaign_load_by_name(campaign_fname))
965 //Campaign.current_mission = mission_num;*/
967 hud_squadmsg_save_keys(); // when new pilot read in, must save info for squadmate messaging
972 void read_stats_block(CFILE *file, int Player_file_version, scoring_struct *stats)
976 init_scoring_element(stats);
977 stats->score = cfread_int(file);
978 stats->rank = cfread_int(file);
979 stats->assists = cfread_int(file);
982 if (Player_file_version < 139) {
983 // support for FS2_DEMO pilots that still have FS1 medal info in the .plr files
984 for (i=0; i < NUM_MEDALS_FS1; i++) {
985 cfread_int(file); // dummy read
988 // read the usual way
989 for (i=0; i < NUM_MEDALS; i++) {
990 stats->medals[i] = cfread_int(file);
994 for (i = 0; i < NUM_MEDALS; i++) {
995 stats->medals[i] = cfread_int(file);
999 total = cfread_int(file);
1000 if (total > MAX_SHIP_TYPES){
1001 Warning(LOCATION, "Some ship kill information will be lost due to MAX_SHIP_TYPES decrease");
1004 for (i=0; i<total && i<MAX_SHIP_TYPES; i++){
1006 stats->kills[i] = cfread_ushort(file);
1008 stats->kills[i] = cfread_int(file);
1012 stats->kill_count = cfread_int(file);
1013 stats->kill_count_ok = cfread_int(file);
1015 stats->p_shots_fired = cfread_uint(file);
1016 stats->s_shots_fired = cfread_uint(file);
1017 stats->p_shots_hit = cfread_uint(file);
1018 stats->s_shots_hit = cfread_uint(file);
1020 stats->p_bonehead_hits = cfread_uint(file);
1021 stats->s_bonehead_hits = cfread_uint(file);
1022 stats->bonehead_kills = cfread_uint(file);
1025 // grab the various detail settings
1026 void read_detail_settings(CFILE *file, int pfile_version)
1028 detail_level_set(NUM_DEFAULT_DETAIL_LEVELS-1);
1031 Detail.setting = cfread_int(file);
1033 Detail.nebula_detail = cfread_int(file);
1034 Detail.detail_distance = cfread_int(file);
1036 Detail.weapon_detail = cfread_int(file);
1038 Detail.hardware_textures = cfread_int(file);
1039 Detail.num_small_debris = cfread_int(file);
1040 Detail.num_particles = cfread_int(file);
1041 Detail.num_stars = cfread_int(file);
1042 Detail.shield_effects = cfread_int(file);
1043 Detail.lighting = cfread_int(file);
1045 Detail.unknown_slider = cfread_int(file);
1049 Detail.targetview_model = cfread_int(file);
1050 Detail.planets_suns = cfread_int(file);
1052 Detail.unknown_boolean1 = cfread_int(file);
1053 Detail.unknown_boolean2 = cfread_int(file);
1054 Detail.engine_glows = cfread_int(file);
1055 Detail.alpha_effects = cfread_int(file);
1057 Detail.weapon_extras = cfread_int(file);
1061 // Will write the pilot file in the most current format
1063 // if single == 1, save into the single players directory, else save into the multiplayers directory
1064 int write_pilot_file_core(player *p)
1066 char filename[MAX_FILENAME_LEN + 1];
1071 // never save a pilot file for the standalone server in multiplayer
1072 if ((Game_mode & GM_MULTIPLAYER) && (Game_mode & GM_STANDALONE_SERVER)) {
1077 SDL_assert((Player_num >= 0) && (Player_num < MAX_PLAYERS));
1078 p = &Players[Player_num];
1081 i = strlen(p->callsign);
1083 return 0; // This means there is no player, probably meaning he was deleted and game exited from same screen.
1085 SDL_assert((i > 0) && (i <= MAX_FILENAME_LEN - 4)); // ensure we won't overrun the buffer
1086 SDL_strlcpy( filename, p->callsign, SDL_arraysize(filename));
1087 SDL_strlcat( filename, NOX(".plr"), SDL_arraysize(filename) );
1089 // determine if this pilot is a multiplayer pilot or not
1090 if (p->flags & PLAYER_FLAGS_IS_MULTI){
1098 file = cfopen(filename, "wb", CFILE_NORMAL, CF_TYPE_SINGLE_PLAYERS);
1100 file = cfopen(filename, "wb", CFILE_NORMAL, CF_TYPE_MULTI_PLAYERS);
1107 // Write out player's info
1108 cfwrite_uint(PLR_FILE_ID, file);
1109 cfwrite_uint(CURRENT_PLAYER_FILE_VERSION, file);
1111 cfwrite_ubyte(is_multi, file);
1112 cfwrite_int(p->stats.rank, file);
1113 cfwrite_ubyte((ubyte) p->on_bastion, file);
1116 cfwrite_int(p->tips, file);
1119 // write out the image file name
1120 cfwrite_string_len(p->image_filename, file);
1123 // write out the image file name
1124 cfwrite_string_len(p->squad_name, file);
1125 cfwrite_string_len(p->squad_filename, file);
1128 // write out the name of the player's active campaign.
1129 cfwrite_string_len(p->current_campaign, file);
1131 // write the ship name for last ship flown by the player
1132 si_index = p->last_ship_flown_si_index;
1133 if((si_index < 0) || (si_index >= Num_ship_types)){
1137 cfwrite_string_len(Ship_info[si_index].name, file);
1139 // ---------------------------------------------
1140 // write the keyboard/joystick configuration
1141 // ---------------------------------------------
1143 cfwrite_ubyte( CCFG_MAX, file );
1144 for (i=0; i<CCFG_MAX; i++) {
1145 key_id = keycode_translate_to(Control_config[i].key_id);
1146 cfwrite_short( key_id, file );
1147 cfwrite_short( Control_config[i].joy_id, file );
1150 // if this hud is an observer, the player ended the last mission as an observer, so we should
1151 // restore his "real" ship HUD.
1152 HUD_CONFIG_TYPE hc_temp;
1153 hc_temp.show_flags = 0;
1154 int stored_observer = 0;
1155 if ( HUD_config.is_observer ){
1156 // if we're in mission, copy the HUD we're currently using
1157 if(Game_mode & GM_IN_MISSION){
1158 memcpy(&hc_temp,&HUD_config,sizeof(HUD_CONFIG_TYPE));
1159 stored_observer = 1;
1162 hud_config_restore();
1165 // write the hud configuration
1166 cfwrite_int(HUD_config.show_flags, file);
1167 cfwrite_int(HUD_config.show_flags2, file);
1168 cfwrite_int(HUD_config.popup_flags, file);
1169 cfwrite_int(HUD_config.popup_flags2, file);
1170 cfwrite_ubyte( (ubyte) HUD_config.num_msg_window_lines, file );
1171 cfwrite_int( HUD_config.rp_flags, file );
1172 cfwrite_int( HUD_config.rp_dist, file );
1175 cfwrite_int( HUD_config.main_color, file );
1176 cfwrite_int( HUD_color_alpha, file );
1178 for(i=0; i<NUM_HUD_GAUGES; i++){
1179 cfwrite(&HUD_config.clr[i], sizeof(color), 1, file);
1183 // restore the HUD we backed up
1184 if( (Game_mode & GM_IN_MISSION) && stored_observer ){
1185 memcpy(&HUD_config,&hc_temp,sizeof(HUD_CONFIG_TYPE));
1188 // write the cutscenes which have been viewed
1189 cfwrite_int(Cutscenes_viewable, file);
1191 // store the digital sound fx volume, and music volume
1192 cfwrite_float(Master_sound_volume, file);
1193 cfwrite_float(Master_event_music_volume, file);
1194 cfwrite_float(Master_voice_volume, file);
1197 //cfwrite( &Detail, sizeof(detail_levels), 1, file );
1198 write_detail_settings(file);
1200 // store list of most recently played missions
1201 cfwrite_int(Num_recent_missions, file);
1202 for (i=0; i<Num_recent_missions; i++) {
1203 cfwrite_string_len(Recent_missions[i], file);
1206 // write the player stats
1207 write_stats_block(file, &p->stats);
1208 cfwrite_int(Game_skill_level, file);
1210 for (i=0; i<NUM_JOY_AXIS_ACTIONS; i++) {
1211 cfwrite_int(Axis_map_to[i], file);
1212 cfwrite_int(Invert_axis[i], file);
1215 // store some player flags
1216 cfwrite_int(Player->save_flags, file);
1218 // store ship selection for most recent mission
1219 pilot_write_loadout(file);
1221 // read in multiplayer options
1222 write_multiplayer_options(p, file);
1224 cfwrite_int(p->readyroom_listing_mode, file);
1225 cfwrite_int(Briefing_voice_enabled, file);
1227 // store the default netgame protocol mode for this pilot
1228 SDL_assert(Multi_options_g.protocol == NET_TCP);
1229 if (Multi_options_g.pxo == 1) {
1230 cfwrite_int(NET_VMT, file);
1232 cfwrite_int(NET_TCP, file);
1235 red_alert_write_wingman_status(file);
1236 pilot_write_techroom_data(file);
1238 // store auto-advance pref
1239 cfwrite_int(Player->auto_advance, file);
1241 cfwrite_int(Use_mouse_to_fly, file);
1242 cfwrite_int(Mouse_sensitivity, file);
1243 cfwrite_int(Joy_sensitivity, file);
1244 cfwrite_int(Dead_zone_size, file);
1252 int write_pilot_file(player *the_player)
1254 int pilot_write_rval;
1256 // write_pilot_file_core returns 0 if ok, non-zero for error
1257 pilot_write_rval = write_pilot_file_core(the_player);
1259 // check with user if write not successful
1260 if (pilot_write_rval) {
1261 int popup_rval = popup(PF_TITLE_RED | PF_TITLE_BIG, 3, XSTR( "&Retry", 41), XSTR( "&Ignore", 42), XSTR( "&Quit Game", 43),
1262 XSTR( "Warning\nFailed to save pilot file. You may be out of disk space. If so, you should press Alt-Tab, free up some disk space, then come back and choose retry.\n", 44) );
1264 // quit game popup return value (2)
1265 if (popup_rval == 2) {
1269 // _ignore_ popup return value (1) - don't save the file
1271 return pilot_write_rval;
1274 // retry popup return value (0) - try again
1277 } while (pilot_write_rval);
1283 void write_stats_block(CFILE *file,scoring_struct *stats)
1288 cfwrite_int(stats->score, file);
1289 cfwrite_int(stats->rank, file);
1290 cfwrite_int(stats->assists, file);
1291 for (i=0; i<NUM_MEDALS; i++){
1292 cfwrite_int(stats->medals[i], file);
1295 total = MAX_SHIP_TYPES;
1296 while (total && !stats->kills[total - 1]){ // find last used element
1300 cfwrite_int(total, file);
1301 for (i=0; i<total; i++){
1303 cfwrite_ushort(stats->kills[i], file);
1305 cfwrite_int(stats->kills[i], file);
1309 cfwrite_int(stats->kill_count,file);
1310 cfwrite_int(stats->kill_count_ok,file);
1312 cfwrite_uint(stats->p_shots_fired,file);
1313 cfwrite_uint(stats->s_shots_fired,file);
1314 cfwrite_uint(stats->p_shots_hit,file);
1315 cfwrite_uint(stats->s_shots_hit,file);
1316 cfwrite_uint(stats->p_bonehead_hits,file);
1317 cfwrite_uint(stats->s_bonehead_hits,file);
1318 cfwrite_uint(stats->bonehead_kills,file);
1321 // write the various detail settings
1322 void write_detail_settings(CFILE *file)
1324 cfwrite_int(Detail.setting, file);
1326 cfwrite_int(Detail.nebula_detail, file);
1327 cfwrite_int(Detail.detail_distance, file);
1329 cfwrite_int(Detail.weapon_detail, file);
1331 cfwrite_int(Detail.hardware_textures, file);
1332 cfwrite_int(Detail.num_small_debris, file);
1333 cfwrite_int(Detail.num_particles, file);
1334 cfwrite_int(Detail.num_stars, file);
1335 cfwrite_int(Detail.shield_effects, file);
1336 cfwrite_int(Detail.lighting, file);
1338 cfwrite_int(Detail.unknown_slider, file);
1341 cfwrite_int(Detail.targetview_model, file);
1342 cfwrite_int(Detail.planets_suns, file);
1344 cfwrite_int(Detail.unknown_boolean1, file);
1345 cfwrite_int(Detail.unknown_boolean2, file);
1346 cfwrite_int(Detail.engine_glows, file);
1347 cfwrite_int(Detail.alpha_effects, file);
1349 cfwrite_int(Detail.weapon_extras, file);
1353 // write multiplayer information
1354 void write_multiplayer_options(player *p,CFILE *file)
1356 // write the netgame options
1357 cfwrite_ubyte(p->m_server_options.squad_set,file);
1358 cfwrite_ubyte(p->m_server_options.endgame_set,file);
1359 cfwrite_int(p->m_server_options.flags,file);
1360 cfwrite_uint(p->m_server_options.respawn,file);
1361 cfwrite_ubyte(p->m_server_options.max_observers,file);
1362 cfwrite_ubyte(p->m_server_options.skill_level,file);
1363 cfwrite_ubyte(p->m_server_options.voice_qos,file);
1364 cfwrite_int(p->m_server_options.voice_token_wait,file);
1365 cfwrite_int(p->m_server_options.voice_record_time,file);
1366 cfwrite(&p->m_server_options.mission_time_limit,sizeof(fix),1,file);
1367 cfwrite_int(p->m_server_options.kill_limit,file);
1369 // write the local options
1370 cfwrite_int(p->m_local_options.flags,file);
1371 cfwrite_int(p->m_local_options.obj_update_level,file);
1374 // read multiplayer options
1375 void read_multiplayer_options(player *p,CFILE *file)
1377 // read the netgame options
1378 p->m_server_options.squad_set = cfread_ubyte(file);
1379 p->m_server_options.endgame_set = cfread_ubyte(file);
1380 p->m_server_options.flags = cfread_int(file);
1381 p->m_server_options.respawn = cfread_uint(file);
1382 p->m_server_options.max_observers = cfread_ubyte(file);
1383 p->m_server_options.skill_level = cfread_ubyte(file);
1384 p->m_server_options.voice_qos = cfread_ubyte(file);
1385 p->m_server_options.voice_token_wait = cfread_int(file);
1386 p->m_server_options.voice_record_time = cfread_int(file);
1387 cfread(&p->m_server_options.mission_time_limit,sizeof(fix),1,file);
1388 p->m_server_options.kill_limit = cfread_int(file);
1390 // read the local options
1391 p->m_local_options.flags = cfread_int(file);
1392 p->m_local_options.obj_update_level = cfread_int(file);
1395 // run thorough an open file (at the beginning) and see if this pilot is a multiplayer pilot
1396 int is_pilot_multi(CFILE *fp)
1398 uint id,file_version;
1401 id = cfread_uint(fp);
1402 if (id != PLR_FILE_ID) {
1403 Warning(LOCATION, "Player file has invalid signature");
1408 // check for compatibility here
1409 file_version = cfread_uint(fp);
1410 if (file_version < LOWEST_COMPATIBLE_PLAYER_FILE_VERSION) {
1411 nprintf(("Warning", "WARNING => Player file is outdated and not compatible...\n"));
1416 // read in whether he's a multiplayer or not
1417 is_multi = cfread_ubyte(fp);
1424 int is_pilot_multi(player *p)
1426 return (p->flags & PLAYER_FLAGS_IS_MULTI) ? 1 : 0;
1429 // this works on barracks and player_select interface screens
1430 void init_new_pilot(player *p, int reset)
1435 hud_set_default_hud_config(p); // use a default hud config
1438 // in the demo, load up the hardcoded hcf file
1440 hud_config_color_load("hud_1.hcf");
1442 hud_config_color_load("hud_3.hcf");
1445 hud_config_set_color(HUD_COLOR_GREEN);
1448 control_config_reset_defaults(); // get a default keyboard config
1449 player_set_pilot_defaults(p); // set up any player struct defaults
1451 cur_speed = os_config_read_uint(NULL, NOX("ComputerSpeed"), 2 );
1452 if ( cur_speed < 0 ) {
1454 } else if ( cur_speed >= NUM_DEFAULT_DETAIL_LEVELS ) {
1455 cur_speed = NUM_DEFAULT_DETAIL_LEVELS-1;
1457 // always set to high
1458 // DKA: 8/4/99 USE speed from registry
1459 // cur_speed = NUM_DEFAULT_DETAIL_LEVELS-2;
1461 #if NUM_DEFAULT_DETAIL_LEVELS != 4
1462 #error Code in ManagePilot assumes NUM_DEFAULT_DETAIL_LEVELS = 4
1465 detail_level_set(cur_speed);
1467 Game_skill_level = game_get_default_skill_level();
1469 mprintf(( "Setting detail level to %d because of new pilot\n", cur_speed ));
1470 Use_mouse_to_fly = 0;
1471 Mouse_sensitivity = 4;
1472 Joy_sensitivity = 9;
1473 Dead_zone_size = 10;
1476 // unassigned squadron
1477 SDL_strlcpy(p->squad_name, XSTR("Unassigned", 1255), SDL_arraysize(p->squad_name));
1478 SDL_strlcpy(p->squad_filename, "", SDL_arraysize(p->squad_filename));
1480 // set him to be a single player pilot by default (the actual creation routines will change this if necessary)
1481 p->flags &= ~PLAYER_FLAGS_IS_MULTI;
1483 // effectively sets the length return by strlen() to 0
1484 Campaign.filename[0] = 0;
1487 // pick a random pilot image for this guy
1489 pilot_set_random_pic(p);
1490 p->insignia_texture = -1;
1491 pilot_set_random_squad_pic(p);
1494 init_scoring_element(&p->stats);
1497 p->stats.rank = RANK_ENSIGN;
1505 Multi_options_g.protocol = NET_TCP;
1507 // initialize default multiplayer options
1508 multi_options_set_netgame_defaults(&p->m_server_options);
1509 multi_options_set_local_defaults(&p->m_local_options);
1511 Player_loadout.filename[0] = 0;
1513 // reset the cutscenes which can be viewed
1515 Cutscenes_viewable = INTRO_CUTSCENE_FLAG;
1519 void pilot_set_short_callsign(player *p, int max_width)
1521 SDL_strlcpy(p->short_callsign, p->callsign, SDL_arraysize(p->short_callsign));
1523 gr_force_fit_string(p->short_callsign, CALLSIGN_LEN - 1, max_width);
1524 gr_get_string_size( &(p->short_callsign_width), NULL, p->short_callsign );
1527 // pick a random image for the passed player
1528 void pilot_set_random_pic(player *p)
1530 // if there are no available pilot pics, set the image filename to null
1531 if (Num_pilot_images <= 0) {
1532 SDL_strlcpy(p->image_filename, "", SDL_arraysize(p->image_filename));
1534 // pick a random name from the list
1535 int random_index = rand() % Num_pilot_images;
1536 SDL_assert((random_index >= 0) && (random_index < Num_pilot_images));
1537 SDL_strlcpy(p->image_filename, Pilot_images_arr[random_index], SDL_arraysize(p->image_filename));
1541 // pick a random image for the passed player
1542 void pilot_set_random_squad_pic(player *p)
1544 // if there are no available pilot pics, set the image filename to null
1545 if (Num_pilot_squad_images <= 0) {
1546 player_set_squad_bitmap(p, "");
1547 // strcpy(p->squad_filename, "");
1549 // pick a random name from the list
1550 int random_index = rand() % Num_pilot_squad_images;
1551 SDL_assert((random_index >= 0) && (random_index < Num_pilot_squad_images));
1552 player_set_squad_bitmap(p, Pilot_squad_images_arr[random_index]);
1553 // strcpy(p->squad_filename, Pilot_squad_images_arr[random_index]);
1557 // format a pilot's callsign into a "personal" form - ie, adding a 's or just an ' as appropriate
1558 void pilot_format_callsign_personal(const char *in_callsign, char *out_callsign, const int out_size)
1560 // don't do anything if we've got invalid strings
1561 if((in_callsign == NULL) || (out_callsign == NULL)){
1565 // copy the original string
1566 SDL_strlcpy(out_callsign, in_callsign, out_size);
1568 // tack on the appropriate postfix
1569 if(in_callsign[strlen(in_callsign) - 1] == 's'){
1570 SDL_strlcat(out_callsign,XSTR( "\'", 45), out_size);
1572 SDL_strlcat(out_callsign,XSTR( "\'s", 46), out_size);
1576 // throw up a popup asking the user to verify the overwrite of an existing pilot name
1577 // 1 == ok to overwrite, 0 == not ok
1578 int pilot_verify_overwrite()
1580 return popup(PF_USE_AFFIRMATIVE_ICON | PF_USE_NEGATIVE_ICON | PF_TITLE_RED | PF_TITLE_BIG, 2, XSTR( "&No", 47), XSTR( "&Yes", 48), XSTR( "Warning\nA duplicate pilot exists\nOverwrite?", 49));
1583 extern int Skip_packfile_search; // located in CFileList.cpp
1586 // load up the list of pilot image filenames (do this at game startup as well as barracks startup)
1587 void pilot_load_pic_list()
1589 Num_pilot_images = 0;
1591 // load pilot images from the player images directory
1592 Num_pilot_images = cf_get_file_list_preallocated(MAX_PILOT_IMAGES, Pilot_images_arr, Pilot_image_names, CF_TYPE_PLAYER_IMAGES_MAIN, NOX("*.pcx"));
1594 // sort all filenames
1595 cf_sort_filenames(Num_pilot_images, Pilot_image_names, CF_SORT_NAME);
1598 // load up the list of pilot squad filenames
1599 void pilot_load_squad_pic_list()
1601 Num_pilot_squad_images = 0;
1603 // load pilot images from the player images directory
1604 Num_pilot_squad_images = cf_get_file_list_preallocated(MAX_PILOT_IMAGES, Pilot_squad_images_arr, Pilot_squad_image_names, CF_TYPE_SQUAD_IMAGES_MAIN, NOX("*.pcx"));
1606 // sort all filenames
1607 cf_sort_filenames(Num_pilot_squad_images, Pilot_squad_image_names, CF_SORT_NAME);
1610 // will attempt to load an insignia bitmap and set it as active for the player
1611 void player_set_squad_bitmap(player *p, const char *fname)
1618 // if he has another bitmap already - unload it
1619 if(p->insignia_texture >= 0){
1620 bm_unload(p->insignia_texture);
1623 p->insignia_texture = -1;
1625 // try and set the new one
1626 if (fname != p->squad_filename) {
1627 SDL_strlcpy(p->squad_filename, fname, SDL_arraysize(p->squad_filename));
1630 if(strlen(p->squad_filename) > 0){
1631 p->insignia_texture = bm_load_duplicate(fname);
1633 // lock is as a transparent texture
1634 if(p->insignia_texture != -1){
1635 bm_lock(p->insignia_texture, 16, BMP_TEX_XPARENT);
1636 bm_unlock(p->insignia_texture);
1641 flen = strlen(filename);
1643 SDL_assert(flen < MAX_PATH_LEN);
1644 strcpy(path, filename);
1645 if ((flen < 4) || SDL_strcasecmp(path + flen - elen, ext)) {
1646 SDL_assert(flen + elen < MAX_PATH_LEN);
1653 void player_set_squad(player *p, const char *squad_name)
1660 SDL_strlcpy(p->squad_name, squad_name, SDL_arraysize(p->squad_name));
1663 DCF(pilot,"Changes pilot stats. (Like reset campaign)" )
1666 dc_get_arg(ARG_STRING);
1667 if (!strcmp(Dc_arg, NOX("reset"))) {
1668 if (strlen(Campaign.filename)) {
1669 mission_campaign_savefile_delete(Campaign.filename);
1670 mission_campaign_load(Campaign.filename);
1674 Dc_help = 1; // print usage, not stats
1679 dc_printf( "Usage: pilot keyword\nWhere keyword can be in the following forms:\n" );
1680 dc_printf( "pilot reset Resets campaign stats.\n" );
1681 Dc_status = 0; // don't print status if help is printed. Too messy.
1689 struct fs_keycode_t {
1691 SDL_Keycode sdl_code;
1694 static const fs_keycode_t keycode_lookup[] = {
1695 { /* KEY_0 */ 0x0B, SDLK_0 },
1696 { /* KEY_1 */ 0x02, SDLK_1 },
1697 { /* KEY_2 */ 0x03, SDLK_2 },
1698 { /* KEY_3 */ 0x04, SDLK_3 },
1699 { /* KEY_4 */ 0x05, SDLK_4 },
1700 { /* KEY_5 */ 0x06, SDLK_5 },
1701 { /* KEY_6 */ 0x07, SDLK_6 },
1702 { /* KEY_7 */ 0x08, SDLK_7 },
1703 { /* KEY_8 */ 0x09, SDLK_8 },
1704 { /* KEY_9 */ 0x0A, SDLK_9 },
1705 { /* KEY_A */ 0x1E, SDLK_a },
1706 { /* KEY_B */ 0x30, SDLK_b },
1707 { /* KEY_C */ 0x2E, SDLK_c },
1708 { /* KEY_D */ 0x20, SDLK_d },
1709 { /* KEY_E */ 0x12, SDLK_e },
1710 { /* KEY_F */ 0x21, SDLK_f },
1711 { /* KEY_G */ 0x22, SDLK_g },
1712 { /* KEY_H */ 0x23, SDLK_h },
1713 { /* KEY_I */ 0x17, SDLK_i },
1714 { /* KEY_J */ 0x24, SDLK_j },
1715 { /* KEY_K */ 0x25, SDLK_k },
1716 { /* KEY_L */ 0x26, SDLK_l },
1717 { /* KEY_M */ 0x32, SDLK_m },
1718 { /* KEY_N */ 0x31, SDLK_n },
1719 { /* KEY_O */ 0x18, SDLK_o },
1720 { /* KEY_P */ 0x19, SDLK_p },
1721 { /* KEY_Q */ 0x10, SDLK_q },
1722 { /* KEY_R */ 0x13, SDLK_r },
1723 { /* KEY_S */ 0x1F, SDLK_s },
1724 { /* KEY_T */ 0x14, SDLK_t },
1725 { /* KEY_U */ 0x16, SDLK_u },
1726 { /* KEY_V */ 0x2F, SDLK_v },
1727 { /* KEY_W */ 0x11, SDLK_w },
1728 { /* KEY_X */ 0x2D, SDLK_x },
1729 { /* KEY_Y */ 0x15, SDLK_y },
1730 { /* KEY_Z */ 0x2C, SDLK_z },
1731 { /* KEY_MINUS */ 0x0C, SDLK_MINUS },
1732 { /* KEY_EQUAL */ 0x0D, SDLK_EQUALS },
1733 { /* KEY_DIVIDE */ 0x35, SDLK_SLASH },
1734 { /* KEY_SLASH */ 0x2B, SDLK_BACKSLASH },
1735 { /* KEY_SLASH_UK */ 0x56, SDLK_BACKSLASH },
1736 { /* KEY_COMMA */ 0x33, SDLK_COMMA },
1737 { /* KEY_PERIOD */ 0x34, SDLK_PERIOD },
1738 { /* KEY_SEMICOL */ 0x27, SDLK_SEMICOLON },
1739 { /* KEY_LBRACKET */ 0x1A, SDLK_LEFTBRACKET },
1740 { /* KEY_RBRACKET */ 0x1B, SDLK_RIGHTBRACKET },
1741 { /* KEY_RAPOSTRO */ 0x28, SDLK_QUOTE },
1742 { /* KEY_LAPOSTRO */ 0x29, SDLK_BACKQUOTE },
1743 { /* KEY_ESC */ 0x01, SDLK_ESCAPE },
1744 { /* KEY_ENTER */ 0x1C, SDLK_RETURN },
1745 { /* KEY_BACKSP */ 0x0E, SDLK_BACKSPACE },
1746 { /* KEY_TAB */ 0x0F, SDLK_TAB },
1747 { /* KEY_SPACEBAR */ 0x39, SDLK_SPACE },
1748 { /* KEY_NUMLOCK */ 0x61, SDLK_NUMLOCKCLEAR },
1749 { /* KEY_SCROLLOCK */ 0x46, SDLK_SCROLLLOCK },
1750 { /* KEY_CAPSLOCK */ 0x3A, SDLK_CAPSLOCK },
1751 { /* KEY_LSHIFT */ 0x2A, SDLK_LSHIFT },
1752 { /* KEY_RSHIFT */ 0x36, SDLK_RSHIFT },
1753 { /* KEY_LALT */ 0x38, SDLK_LALT },
1754 { /* KEY_RALT */ 0xB8, SDLK_RALT },
1755 { /* KEY_LCTRL */ 0x1D, SDLK_LCTRL },
1756 { /* KEY_RCTRL */ 0x9D, SDLK_RCTRL },
1757 { /* KEY_F1 */ 0x3B, SDLK_F1 },
1758 { /* KEY_F2 */ 0x3C, SDLK_F2 },
1759 { /* KEY_F3 */ 0x3D, SDLK_F3 },
1760 { /* KEY_F4 */ 0x3E, SDLK_F4 },
1761 { /* KEY_F5 */ 0x3F, SDLK_F5 },
1762 { /* KEY_F6 */ 0x40, SDLK_F6 },
1763 { /* KEY_F7 */ 0x41, SDLK_F7 },
1764 { /* KEY_F8 */ 0x42, SDLK_F8 },
1765 { /* KEY_F9 */ 0x43, SDLK_F9 },
1766 { /* KEY_F10 */ 0x44, SDLK_F10 },
1767 { /* KEY_F11 */ 0x57, SDLK_F11 },
1768 { /* KEY_F12 */ 0x58, SDLK_F12 },
1769 { /* KEY_PAD0 */ 0x52, SDLK_KP_0 },
1770 { /* KEY_PAD1 */ 0x4F, SDLK_KP_1 },
1771 { /* KEY_PAD2 */ 0x50, SDLK_KP_2 },
1772 { /* KEY_PAD3 */ 0x51, SDLK_KP_3 },
1773 { /* KEY_PAD4 */ 0x4B, SDLK_KP_4 },
1774 { /* KEY_PAD5 */ 0x4C, SDLK_KP_5 },
1775 { /* KEY_PAD6 */ 0x4D, SDLK_KP_6 },
1776 { /* KEY_PAD7 */ 0x47, SDLK_KP_7 },
1777 { /* KEY_PAD8 */ 0x48, SDLK_KP_8 },
1778 { /* KEY_PAD9 */ 0x49, SDLK_KP_9 },
1779 { /* KEY_PADMINUS */ 0x4A, SDLK_KP_MINUS },
1780 { /* KEY_PADPLUS */ 0x4E, SDLK_KP_PLUS },
1781 { /* KEY_PADPERIOD */ 0x53, SDLK_KP_PERIOD },
1782 { /* KEY_PADDIVIDE */ 0xB5, SDLK_KP_DIVIDE },
1783 { /* KEY_PADMULTIPLY */ 0x37, SDLK_KP_MULTIPLY },
1784 { /* KEY_PADENTER */ 0x9C, SDLK_KP_ENTER },
1785 { /* KEY_INSERT */ 0xD2, SDLK_INSERT },
1786 { /* KEY_HOME */ 0xC7, SDLK_HOME },
1787 { /* KEY_PAGEUP */ 0xC9, SDLK_PAGEUP },
1788 { /* KEY_DELETE */ 0xd3, SDLK_DELETE },
1789 { /* KEY_END */ 0xCF, SDLK_END },
1790 { /* KEY_PAGEDOWN */ 0xD1, SDLK_PAGEDOWN },
1791 { /* KEY_UP */ 0xC8, SDLK_UP },
1792 { /* KEY_DOWN */ 0xD0, SDLK_DOWN },
1793 { /* KEY_LEFT */ 0xCB, SDLK_LEFT },
1794 { /* KEY_RIGHT */ 0xCD, SDLK_RIGHT },
1795 { /* KEY_PRINT_SCRN */ 0xB7, SDLK_PRINTSCREEN },
1796 { /* KEY_PAUSE */ 0x45, SDLK_PAUSE },
1797 { /* KEY_BREAK */ 0xc6, SDLK_PAUSE }
1800 static SDL_Keycode keycode_translate_from(short keycode)
1802 const int tbl_size = sizeof(keycode_lookup) / sizeof(fs_keycode_t);
1808 int mods = keycode & 0xf900;
1809 keycode &= KEY_MASK;
1811 for (int i = 0; i < tbl_size; i++) {
1812 if (keycode_lookup[i].fs_code == keycode) {
1813 return (SDL_Keycode)(keycode_lookup[i].sdl_code | mods);
1820 static short keycode_translate_to(SDL_Keycode keycode)
1822 const int tbl_size = sizeof(keycode_lookup) / sizeof(fs_keycode_t);
1828 int mods = keycode & 0xf900;
1829 keycode &= KEY_MASK;
1831 for (int i = 0; i < tbl_size; i++) {
1832 if (keycode_lookup[i].sdl_code == keycode) {
1833 return (short)(keycode_lookup[i].fs_code | mods);