Debian Codegraph @

Descent3/pilot_class.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/main/pilot_class.cpp $
21 * $Revision: 30 $
22 * $Date: 3/20/00 12:19p $
23 * $Author: Matt $
24 *
25 * Pilot class and access functions
26 *
27 * $Log: /DescentIII/main/pilot_class.cpp $
28 *
29 * 30 3/20/00 12:19p Matt
30 * Merge of Duane's post-1.3 changes.
31 * Default to full-screen mode on Mac.
32 * Mouse sensitivity change (Mac only)
33 *
34 * 29 10/21/99 9:28p Jeff
35 * B.A. Macintosh code merge
36 *
37 * 28 8/10/99 5:12p Jeff
38 * fixed compiler warnings
39 *
40 * 27 8/06/99 4:25p Samir
41 * set key ramping speed globally when loading pilot file.
42 *
43 * 26 7/20/99 1:18p Samir
44 * save state of rearviews between game through the pilot file.
45 *
46 * 25 5/21/99 10:42p Jeff
47 * init pilot ship to Pyro-GL for dedicated server needs
48 *
49 * 24 5/09/99 1:48a Jeff
50 * default rookie
51 *
52 * 23 5/02/99 12:56a Jeff
53 * save ship permissions at highest level achieved and use that on restore
54 * to a level previously played
55 *
56 * 22 5/01/99 1:36a Samir
57 * oops forgot to update pilot version number!
58 *
59 * 21 4/30/99 1:29p Samir
60 * added save for key ramping
61 *
62 * 20 4/27/99 4:18p Jeff
63 * fixed crash
64 *
65 * 19 4/27/99 3:58p Jeff
66 * added kiddie settings
67 *
68 * 18 4/27/99 1:56p Jeff
69 * audio taunts stuff in pilot menu, added stringtables
70 *
71 * 17 4/25/99 2:32a Jeff
72 * fixed bug trying to read pilot files that are too new
73 *
74 * 16 4/24/99 8:40p Samir
75 * added toggle to pilot for ship sounds.
76 *
77 * 15 4/20/99 7:28p Jeff
78 * added guidebot name
79 *
80 * 14 4/17/99 8:25p Samir
81 * took out graphical option for inventory display. no time.
82 *
83 * 13 4/15/99 2:55p Samir
84 * added UI for mouselook.
85 *
86 * 12 4/05/99 5:13p Samir
87 * added game toggles.
88 *
89 * 11 4/03/99 2:18a Jeff
90 * added profanity filter stuff
91 *
92 * 10 3/22/99 6:22p Jeff
93 * added 2 more audio taunts. a mulitplayer event when someone plays an
94 * audio taunt. option to disable audio taunts.
95 *
96 * 9 3/15/99 9:24p Gwar
97 *
98 * 8 3/05/99 2:44p Samir
99 * needs to be cleaned up later, but mouse and joystick sensitivities are
100 * read in always, and set by the controller system. A cancel method
101 * needs to be implemented for these functions.
102 *
103 * 7 3/03/99 5:09p Samir
104 * default to graphical hud!
105 *
106 * 6 2/25/99 8:55p Jeff
107 * Inventory supports level change persistant items. Inventory supports
108 * time-out objects. Inventory Reset changed (takes a level of reset
109 * now). Quad lasers stay across level change (single player). Guidebot
110 * bug fixed (now back in ship on level start). Quads time out when
111 * spewed. Invulnerability and cloak powerups no longer use game
112 * event/callbacks, so they can be saved in game saves (moved to
113 * MakePlayerInvulnerable and MakeObjectInvisible)
114 *
115 * 5 2/24/99 12:55p Samir
116 * refresh weapon select info in pilot_class when writing out pilot file.
117 *
118 * 4 2/18/99 5:55p Jeff
119 * added weapon select data
120 *
121 * 3 2/16/99 12:00p Samir
122 * added new video resolution swtich test.
123 *
124 * 2 2/15/99 7:50p Jeff
125 * new pilot file class and read/write system checked in...should be more
126 * robust than old
127 *
128 * 1 2/15/99 3:18a Jeff
129 * initial creation
130 *
131 * $NoKeywords: $
132 */
133
134 #include "pilot_class.h"
135 #include "ddio.h"
136 #include "hud.h"
137 #include "mem.h"
138 #include "pserror.h"
139 #include "mono.h"
140 #include "config.h"
141 #include "ship.h"
142 #include <string.h>
143 #include <stdlib.h>
144
145 #include "application.h"
146 #include "appdatabase.h"
147
148 #include "stringtable.h"
149
150 #define __PILOT_H_ // don't want to include pilot.h right now
151 #include "difficulty.h"
152 #include "audiotaunts.h"
153
154 #include <algorithm>
155
156 extern void grtext_SetProfanityFilter(bool enabled);
157
158 extern float Key_ramp_speed;
159
160 #define PLT_FILE_VERSION 0x2B // pilot file version
161
162 // pilot file version history
163 #define PFV_REARVIEWINFO 0x2B // (SAMIR) save current state of rear small view.
164 #define PFV_SHIPPERMISSIONS 0x2A // (JEFF) save highest level ship permission in mission data
165 #define PFV_KEYRAMPING 0x29 // (SAMIR) added save of keyboard ramping value.
166 #define PFV_AUDIOTAUNTS 0x28 // (JEFF) added audiotaunts
167 #define PFV_GUIDEBOTNAME 0x26 // (JEFF) added guidebot name
168 #define PFV_MOUSELOOK 0x25 // (SAMIR) added mouselook option to pilot.
169 #define PFV_GAMETOGGLES 0x24 // (SAMIR) gameplay toggles
170 #define PFV_PROFANITY 0x23 // (JEFF) added profanity filter
171 #define PFV_AUDIOTAUNT3N4 0x22 // (JEFF) added saving of audio taunts 3 & 4 (and save/restore count for mission data)
172 #define PFV_WEAPONSELECT 0x21 // (JEFF) added saving weapon select
173
174 pilot::~pilot() { clean(false); }
175
176 pilot::pilot() {
177 write_pending = false;
178 initialize();
179 }
180
181 pilot::pilot(pilot *copy) {
182 write_pending = true;
183 initialize();
184 }
185
186 pilot::pilot(char *fname) {
187 write_pending = true;
188 initialize();
189 }
190
191 // initializes all the data (for constructors)
192 void pilot::initialize(void) {
193 int i;
194
195 filename = NULL;
196 name = NULL;
197 ship_model = mem_strdup("Pyro-GL");
198 ship_logo = NULL;
199 audio1_file = NULL;
200 audio2_file = NULL;
201 audio3_file = NULL;
202 audio4_file = NULL;
203 guidebot_name = mem_strdup("GB");
204 picture_id = PPIC_INVALID_ID;
205 difficulty = DIFFICULTY_ROOKIE;
206 hud_mode = (uint8_t)HUD_COCKPIT;
207 hud_stat = 0;
208 hud_graphical_stat = STAT_STANDARD;
209 game_window_w = Video_res_list[Game_video_resolution].width;
210 game_window_h = Video_res_list[Game_video_resolution].height;
211 num_missions_flown = 0;
212 mission_data = NULL;
213 mouselook_control = false;
214 key_ramping = 0.35f;
215 lrearview_enabled = false;
216 rrearview_enabled = false;
217
218 bool kiddie_settings = true;
219
220 if (Database) {
221 Database->read("ProfanityPrevention", &kiddie_settings);
222 }
223
224 if (kiddie_settings) {
225 profanity_filter_on = true;
226 audiotaunts = false;
227 } else {
228 profanity_filter_on = false;
229 audiotaunts = true;
230 }
231
232 gameplay_toggles.guided_mainview = false;
233 gameplay_toggles.show_reticle = true;
234 gameplay_toggles.ship_noises = true;
235
236 // Copy taunts
237 for (i = 0; i < MAX_PILOT_TAUNTS; i++) {
238 strcpy(taunts[i], TXT(TXT_TAUNT_TEXT + i));
239 }
240
241 read_controller = READF_MOUSE + READF_JOY;
242
243 if (Controller) {
244 for (i = 0; i < NUM_CONTROLLER_FUNCTIONS; i++) {
245 Controller->get_controller_function(Controller_needs[i].id, controls[i].type, &controls[i].value,
246 controls[i].flags);
247 controls[i].id = Controller_needs[i].id;
248 }
249 } else {
250 for (i = 0; i < NUM_CONTROLLER_FUNCTIONS; i++) {
251 memset(&controls[i], 0, sizeof(cntrldata));
252 }
253 }
254
255 for (i = 0; i < N_MOUSE_AXIS; i++) {
256 mouse_sensitivity[i] = 1.0f;
257 }
258
259 for (i = 0; i < N_JOY_AXIS; i++) {
260 joy_sensitivity[i] = 1.0f;
261 }
262
263 for (i = 0; i < MAX_PRIMARY_WEAPONS; i++)
264 PrimarySelectList[i] = DefaultPrimarySelectList[i];
265
266 for (i = 0; i < MAX_SECONDARY_WEAPONS; i++)
267 SecondarySelectList[i] = DefaultSecondarySelectList[i];
268 }
269
270 // This function guts the data so it's virgin (fresh for reading)
271 // frees any memory that needs to be freed, etc.
272 void pilot::clean(bool reset) {
273 if (filename) {
274 mem_free(filename);
275 filename = NULL;
276 }
277
278 if (name) {
279 mem_free(name);
280 name = NULL;
281 }
282
283 if (ship_model) {
284 mem_free(ship_model);
285 ship_model = NULL;
286 }
287
288 if (ship_logo) {
289 mem_free(ship_logo);
290 ship_logo = NULL;
291 }
292
293 if (audio1_file) {
294 mem_free(audio1_file);
295 audio1_file = NULL;
296 }
297
298 if (audio2_file) {
299 mem_free(audio2_file);
300 audio2_file = NULL;
301 }
302
303 if (audio3_file) {
304 mem_free(audio3_file);
305 audio3_file = NULL;
306 }
307
308 if (audio4_file) {
309 mem_free(audio4_file);
310 audio4_file = NULL;
311 }
312
313 if (mission_data) {
314 mem_free(mission_data);
315 mission_data = NULL;
316 }
317
318 if (guidebot_name) {
319 mem_free(guidebot_name);
320 guidebot_name = NULL;
321 }
322
323 if (reset)
324 initialize();
325 }
326
327 // This function verifies all the pilot data, making sure nothing is out of whack
328 // It will correct any messed data.
329 void pilot::verify(void) {
330 int i;
331 for (i = 0; i < MAX_PRIMARY_WEAPONS; i++) {
332 PrimarySelectList[i] = GetAutoSelectPrimaryWpnIdx(i);
333 }
334 for (i = 0; i < MAX_SECONDARY_WEAPONS; i++) {
335 SecondarySelectList[i] = GetAutoSelectSecondaryWpnIdx(i);
336 }
337
338 gameplay_toggles.guided_mainview = Game_toggles.guided_mainview;
339 gameplay_toggles.show_reticle = Game_toggles.show_reticle;
340 gameplay_toggles.ship_noises = Game_toggles.ship_noises;
341
342 // kill graphical stat for inventory and reset to text version
343 if (hud_graphical_stat & STAT_INVENTORY) {
344 hud_graphical_stat = hud_graphical_stat & (~STAT_INVENTORY);
345 hud_stat = hud_stat | STAT_INVENTORY;
346 }
347
348 key_ramping = Key_ramp_speed;
349
350 /*
351 bool had_to_change = false;
352
353 //first check the ship mode
354 bool found_model = false;
355 for(int i=0;i<MAX_SHIPS;i++){
356 if(Ships[i].used && !stricmp(Ships[i].name,Pilot->ship_model) ){
357 found_model = true;
358 break;
359 }
360 }
361
362 if(!found_model){
363 //we couldn't find the ship model
364 had_to_change = true;
365 strcpy(Pilot->ship_model,DEFAULT_SHIP);
366 }
367
368 //check the custom texture
369 if(Pilot->ship_logo[0]!='\0'){
370 if(cfexist(Pilot->ship_logo)==CF_NOT_FOUND){
371 //couldn't find the custom texture
372 Pilot->ship_logo[0] = '\0';
373 had_to_change = true;
374 }
375 }
376
377 //check audio files
378 if(Pilot->audio1_file[0]!='\0'){
379 if(cfexist(Pilot->audio1_file)==CF_NOT_FOUND){
380 //couldn't find the custom texture
381 Pilot->audio1_file[0] = '\0';
382 had_to_change = true;
383 }
384 }
385
386 if(Pilot->audio2_file[0]!='\0'){
387 if(cfexist(Pilot->audio2_file)==CF_NOT_FOUND){
388 //couldn't find the custom texture
389 Pilot->audio2_file[0] = '\0';
390 had_to_change = true;
391 }
392 }
393
394 char temp_buffer[PILOT_STRING_SIZE];
395 if(Pilot->picture_id!=PPIC_INVALID_ID && !PPic_GetPilot(Pilot->picture_id,temp_buffer,PILOT_STRING_SIZE)){
396 //the pilot picture id is invalid
397 Pilot->picture_id = PPIC_INVALID_ID;
398 had_to_change = true;
399 }
400
401 return had_to_change;
402 */
403 }
404
405 // This function makes the pilot file so it's write pending, meaning that
406 // on the next call to flush, it will actually write out the data. There is
407 // no need to constantly do file access unless it's really needed
408 void pilot::write(void) { write_pending = true; }
409
410 // This function makes certain that the pilot data is up to date with the
411 // actual pilot file, writing if needed.
412 int pilot::flush(bool new_file) {
413 if (!write_pending)
414 return PLTW_NO_ERROR; // no need to write, data hasn't changed
415
416 if (!filename) {
417 Int3();
418 return PLTW_NO_FILENAME; // no filename was given
419 }
420
421 CFILE *file;
422 char real_filename[_MAX_PATH];
423
424 // open and process file
425 ddio_MakePath(real_filename, Base_directory_write, filename, NULL);
426
427 if (new_file && cfexist(real_filename)) {
428 // the file already exists, we can't write out
429 mprintf(0, "PLTW: File (%s) exists, can't create\n", real_filename);
430 return PLTW_FILE_EXISTS;
431 }
432
433 try {
434 verify();
435
436 file = cfopen(real_filename, "wb");
437 if (!file) {
438 mprintf(0, "PLTW: File (%s) can't be opened\n", real_filename);
439 return PLTW_FILE_CANTOPEN;
440 }
441
442 // Write out our fileversion
443 file_version = PLT_FILE_VERSION;
444 cf_WriteInt(file, file_version);
445
446 write_name(file);
447 write_ship_info(file);
448 write_custom_multiplayer_data(file);
449 write_difficulty(file);
450 write_profanity_filter(file);
451 write_audiotaunts(file);
452 write_hud_data(file);
453 write_mission_data(file);
454 write_taunts(file);
455 write_weapon_select(file);
456 write_gameplay_toggles(file); // version 0x24 PFV_GAMETOGGLES
457 write_guidebot_name(file);
458 write_controls(file);
459
460 cfclose(file);
461
462 } catch (cfile_error) {
463 // catch and handle CFILE errors
464 mprintf(0, "PLTW: CFILE Exception writing data\n");
465 Int3();
466 try {
467 cfclose(file);
468 } catch (...) {
469 mprintf(0, "PLTW: Unable to close file due to exception\n");
470 }
471 return PLTW_CFILE_FATAL;
472 } catch (...) {
473 // catch all errors
474 mprintf(0, "PLTW: Unknown exception writing data\n");
475 Int3();
476 try {
477 cfclose(file);
478 } catch (...) {
479 mprintf(0, "PLTW: Unable to close file due to exception\n");
480 }
481 return PLTW_UNKNOWN_FATAL;
482 }
483
484 write_pending = false;
485
486 return PLTW_NO_ERROR;
487 }
488
489 // This function sets the filename that is associated with this pilot
490 void pilot::set_filename(char *fname) {
491 if (filename) {
492 mem_free(filename);
493 filename = NULL;
494 }
495
496 filename = mem_strdup(fname);
497 }
498
499 void pilot::get_filename(char *fname) {
500 if (filename) {
501 strcpy(fname, filename);
502 } else {
503 *fname = '\0';
504 }
505 }
506
507 // This function reads in the data from file (from the filename associated)
508 // into the pilot data.
509 int pilot::read(bool skip_config, bool skip_mission_data) {
510 if (!filename) {
511 Int3();
512 return PLTR_NO_FILENAME; // no filename was given
513 }
514
515 CFILE *file;
516 char real_filename[_MAX_PATH];
517
518 // open and process file
519 ddio_MakePath(real_filename, Base_directory_write, filename, NULL);
520
521 if (!cfexist(real_filename)) {
522 // the file already exists, we can't write out
523 mprintf(0, "PLTR: File (%s) does not exist\n", real_filename);
524 return PLTR_FILE_NOEXIST;
525 }
526
527 try {
528 file = cfopen(real_filename, "rb");
529 if (!file) {
530 mprintf(0, "PLTR: File (%s) can't be opened\n", real_filename);
531 return PLTR_FILE_CANTOPEN;
532 }
533
534 // Write out our fileversion
535 file_version = cf_ReadInt(file);
536
537 if (file_version > PLT_FILE_VERSION) {
538 // too new!!
539 cfclose(file);
540 return PLTR_TOO_NEW;
541 }
542
543 //////////////////////////////////////////////
544 read_name(file, false);
545 read_ship_info(file, false);
546 read_custom_multiplayer_data(file, false);
547 read_difficulty(file, false);
548 if (file_version >= PFV_PROFANITY) {
549 read_profanity_filter(file, false);
550 }
551 if (file_version >= PFV_AUDIOTAUNTS) {
552 read_audiotaunts(file, false);
553 }
554
555 read_hud_data(file, false);
556 read_mission_data(file, skip_mission_data);
557 read_taunts(file, false);
558
559 if (file_version >= PFV_WEAPONSELECT) {
560 read_weapon_select(file);
561 }
562
563 if (file_version >= PFV_GAMETOGGLES) {
564 read_gameplay_toggles(file, false);
565 }
566
567 if (file_version >= PFV_GUIDEBOTNAME) {
568 read_guidebot_name(file, false);
569 }
570
571 read_controls(file, skip_config);
572
573 //////////////////////////////////////////////
574 int wpn;
575 for (wpn = 0; wpn < MAX_PRIMARY_WEAPONS; wpn++) {
576 SetAutoSelectPrimaryWpnIdx(wpn, PrimarySelectList[wpn]);
577 }
578 for (wpn = 0; wpn < MAX_SECONDARY_WEAPONS; wpn++) {
579 SetAutoSelectSecondaryWpnIdx(wpn, SecondarySelectList[wpn]);
580 }
581
582 Game_toggles.guided_mainview = gameplay_toggles.guided_mainview;
583 Game_toggles.show_reticle = gameplay_toggles.show_reticle;
584 Game_toggles.ship_noises = gameplay_toggles.ship_noises;
585
586 Key_ramp_speed = key_ramping;
587
588 cfclose(file);
589 } catch (cfile_error) {
590 // catch and handle CFILE errors
591 mprintf(0, "PLTR: CFILE Exception reading data\n");
592 Int3();
593 try {
594 cfclose(file);
595 } catch (...) {
596 mprintf(0, "PLTR: Unable to close file due to exception\n");
597 }
598 verify();
599 return PLTR_CFILE_FATAL;
600 } catch (...) {
601 // catch all errors
602 mprintf(0, "PLTR: Unknown exception reading data\n");
603 Int3();
604 try {
605 cfclose(file);
606 } catch (...) {
607 mprintf(0, "PLTR: Unable to close file due to exception\n");
608 }
609 verify();
610 return PLTR_UNKNOWN_FATAL;
611 }
612
613 verify();
614 return PLTR_NO_ERROR;
615 }
616
617 void pilot::set_name(const char *n) {
618 if (name) {
619 mem_free(name);
620 name = NULL;
621 }
622 if (n) {
623 int length = strlen(n);
624 int size = std::min(PILOT_STRING_SIZE - 1, length);
625 name = (char *)mem_malloc(size + 1);
626 if (name) {
627 strncpy(name, n, size);
628 name[size] = '\0';
629 }
630 }
631 write_pending = true;
632 }
633 void pilot::get_name(char *n) {
634 if (n) {
635 if (name) {
636 strcpy(n, name);
637 } else {
638 *n = '\0';
639 }
640 }
641 }
642
643 void pilot::set_ship(const char *ship) {
644 if (ship_model) {
645 mem_free(ship_model);
646 ship_model = NULL;
647 }
648 if (ship) {
649 int length = strlen(ship);
650 int size = std::min(PAGENAME_LEN - 1, length);
651 ship_model = (char *)mem_malloc(size + 1);
652 if (ship_model) {
653 strncpy(ship_model, ship, size);
654 ship_model[size] = '\0';
655 }
656 }
657 write_pending = true;
658 }
659 void pilot::get_ship(char *ship) {
660 if (ship) {
661 if (ship_model) {
662 strcpy(ship, ship_model);
663 } else {
664 *ship = '\0';
665 }
666 }
667 }
668
669 void pilot::set_multiplayer_data(const char *logo, const char *audio1, const char *audio2, const uint16_t *ppic, const char *audio3, const char *audio4) {
670 if (logo) {
671 if (ship_logo) {
672 mem_free(ship_logo);
673 ship_logo = NULL;
674 }
675 ship_logo = mem_strdup(logo);
676 if (ship_logo) {
677 int len = strlen(ship_logo);
678 if (len >= PAGENAME_LEN) {
679 ship_logo[PAGENAME_LEN - 1] = '\0';
680 }
681 }
682 write_pending = true;
683 }
684 ////////////
685 if (audio1) {
686 if (audio1_file) {
687 mem_free(audio1_file);
688 audio1_file = NULL;
689 }
690 audio1_file = mem_strdup(audio1);
691 if (audio1_file) {
692 int len = strlen(audio1_file);
693 if (len >= PAGENAME_LEN) {
694 audio1_file[PAGENAME_LEN - 1] = '\0';
695 }
696 }
697 write_pending = true;
698 }
699 ////////////
700 if (audio2) {
701 if (audio2_file) {
702 mem_free(audio2_file);
703 audio2_file = NULL;
704 }
705 audio2_file = mem_strdup(audio2);
706 if (audio2_file) {
707 int len = strlen(audio2_file);
708 if (len >= PAGENAME_LEN) {
709 audio2_file[PAGENAME_LEN - 1] = '\0';
710 }
711 }
712 write_pending = true;
713 }
714 ////////////
715 if (ppic) {
716 picture_id = *ppic;
717 write_pending = true;
718 }
719 ////////////
720 if (audio3) {
721 if (audio3_file) {
722 mem_free(audio3_file);
723 audio3_file = NULL;
724 }
725 audio3_file = mem_strdup(audio3);
726 if (audio3_file) {
727 int len = strlen(audio3_file);
728 if (len >= PAGENAME_LEN) {
729 audio3_file[PAGENAME_LEN - 1] = '\0';
730 }
731 }
732 write_pending = true;
733 }
734 ////////////
735 if (audio4) {
736 if (audio4_file) {
737 mem_free(audio4_file);
738 audio4_file = NULL;
739 }
740 audio4_file = mem_strdup(audio4);
741 if (audio4_file) {
742 int len = strlen(audio4_file);
743 if (len >= PAGENAME_LEN) {
744 audio4_file[PAGENAME_LEN - 1] = '\0';
745 }
746 }
747 write_pending = true;
748 }
749 }
750 void pilot::get_multiplayer_data(char *logo, char *audio1, char *audio2, uint16_t *ppic, char *audio3, char *audio4) {
751 if (logo) {
752 if (ship_logo) {
753 strcpy(logo, ship_logo);
754 } else {
755 *logo = '\0';
756 }
757 }
758
759 if (audio1) {
760 if (audio1_file) {
761 strcpy(audio1, audio1_file);
762 } else {
763 *audio1 = '\0';
764 }
765 }
766
767 if (audio2) {
768 if (audio2_file) {
769 strcpy(audio2, audio2_file);
770 } else {
771 *audio2 = '\0';
772 }
773 }
774
775 if (audio3) {
776 if (audio3_file) {
777 strcpy(audio3, audio3_file);
778 } else {
779 *audio3 = '\0';
780 }
781 }
782
783 if (audio4) {
784 if (audio4_file) {
785 strcpy(audio4, audio4_file);
786 } else {
787 *audio4 = '\0';
788 }
789 }
790
791 if (ppic) {
792 *ppic = picture_id;
793 }
794 }
795
796 void pilot::set_difficulty(uint8_t diff) {
797 difficulty = diff;
798 write_pending = true;
799 }
800 void pilot::get_difficulty(uint8_t *diff) {
801 if (diff) {
802 *diff = difficulty;
803 }
804 }
805
806 void pilot::set_profanity_filter(bool enable) {
807 profanity_filter_on = enable;
808 write_pending = true;
809 grtext_SetProfanityFilter(enable);
810 }
811
812 void pilot::get_profanity_filter(bool *enabled) {
813 if (enabled) {
814 *enabled = profanity_filter_on;
815 }
816 }
817
818 void pilot::set_audiotaunts(bool enable) {
819 audiotaunts = enable;
820 write_pending = true;
821 taunt_Enable(enable);
822 }
823
824 void pilot::get_audiotaunts(bool *enabled) {
825 if (enabled) {
826 *enabled = audiotaunts;
827 }
828 }
829
830 void pilot::set_guidebot_name(char *name) {
831 if (guidebot_name) {
832 mem_free(guidebot_name);
833 guidebot_name = NULL;
834 }
835
836 if (name) {
837 guidebot_name = mem_strdup(name);
838 } else {
839 guidebot_name = mem_strdup("GB");
840 }
841 }
842
843 void pilot::get_guidebot_name(char *name) {
844 if (guidebot_name) {
845 strcpy(name, guidebot_name);
846 } else {
847 strcpy(name, "GB");
848 }
849 }
850
851 void pilot::set_hud_data(uint8_t *hmode, uint16_t *hstat, uint16_t *hgraphicalstat, int *gw_w, int *gw_h) {
852 if (hmode) {
853 // should do checking here
854 switch (*hmode) {
855 case HUD_COCKPIT:
856 case HUD_FULLSCREEN:
857 hud_mode = *hmode;
858 write_pending = true;
859 break;
860 default:
861 mprintf(0, "PILOT: Trying to set hode mode to invalid mode (%d)\n", *hmode);
862 }
863 }
864
865 if (hstat) {
866 hud_stat = *hstat;
867 write_pending = true;
868 }
869
870 if (hgraphicalstat) {
871 hud_graphical_stat = *hgraphicalstat;
872 write_pending = true;
873 }
874
875 if (gw_w) {
876 game_window_w = *gw_w;
877 write_pending = true;
878 }
879
880 if (gw_h) {
881 game_window_h = *gw_h;
882 write_pending = true;
883 }
884 }
885 void pilot::get_hud_data(uint8_t *hmode, uint16_t *hstat, uint16_t *hgraphicalstat, int *gw_w, int *gw_h) {
886 if (hmode) {
887 *hmode = hud_mode;
888 }
889
890 if (hstat) {
891 *hstat = hud_stat;
892 }
893
894 if (hgraphicalstat) {
895 *hgraphicalstat = hud_graphical_stat;
896 }
897
898 if (gw_w) {
899 *gw_w = game_window_w;
900 }
901
902 if (gw_h) {
903 *gw_h = game_window_h;
904 }
905 }
906
907 void pilot::add_mission_data(tMissionData *mdata) {
908 if (!mdata) {
909 Int3();
910 return;
911 }
912
913 if (find_mission_data(mdata->mission_name) != -1) {
914 Int3();
915 mprintf(0, "Mission already exists\n");
916 return;
917 }
918
919 mprintf(0, "Adding new mission data for (%s)\n", mdata->mission_name);
920
921 tMissionData *new_data = (tMissionData *)mem_malloc((num_missions_flown + 1) * sizeof(tMissionData));
922 if (!new_data) {
923 mprintf(0, "Out of memory\n");
924 return;
925 }
926
927 ASSERT(num_missions_flown >= 0);
928
929 if (mission_data && num_missions_flown > 0) {
930 memcpy(new_data, mission_data, sizeof(tMissionData) * num_missions_flown);
931 mem_free(mission_data);
932 }
933
934 mission_data = new_data;
935
936 memcpy(&mission_data[num_missions_flown], mdata, sizeof(tMissionData));
937
938 num_missions_flown++;
939 }
940 void pilot::edit_mission_data(int index, tMissionData *mdata) {
941 if (index < 0 || index >= num_missions_flown) {
942 mprintf(0, "Invalid mission index\n");
943 Int3();
944 return;
945 }
946
947 if (!mission_data) {
948 Int3();
949 mprintf(0, "No mission data\n");
950 return;
951 }
952
953 if (!mdata) {
954 Int3();
955 return;
956 }
957
958 memcpy(&mission_data[index], mdata, sizeof(tMissionData));
959 }
960
961 void pilot::get_mission_data(int index, tMissionData *mdata) {
962 if (index < 0 || index >= num_missions_flown) {
963 mprintf(0, "Invalid mission index\n");
964 Int3();
965 return;
966 }
967
968 if (!mission_data) {
969 Int3();
970 mprintf(0, "No mission data\n");
971 return;
972 }
973
974 if (!mdata) {
975 Int3();
976 return;
977 }
978
979 memcpy(mdata, &mission_data[index], sizeof(tMissionData));
980 }
981
982 int pilot::find_mission_data(const char *mission_name) {
983 if (num_missions_flown <= 0) {
984 ASSERT(num_missions_flown == 0);
985 return -1;
986 }
987
988 ASSERT(mission_data);
989 if (!mission_data)
990 return -1;
991
992 for (int i = 0; i < num_missions_flown; i++) {
993 if (!stricmp(mission_data[i].mission_name, mission_name)) {
994 return i;
995 }
996 }
997
998 return -1;
999 }
1000
1001 // internal file access functions
1002 // for the read functions, skip is true if the data should actually
1003 // just be skipped and not processed
1004
1005 void pilot::write_name(CFILE *file) {
1006 if (!name) {
1007 // write out a dummy name
1008 cf_WriteString(file, "No Name");
1009 return;
1010 }
1011
1012 cf_WriteString(file, name);
1013 }
1014
1015 void pilot::read_name(CFILE *file, bool skip) {
1016 char buffer[PILOT_STRING_SIZE];
1017
1018 cf_ReadString(buffer, PILOT_STRING_SIZE, file);
1019
1020 if (!skip) {
1021 if (name) {
1022 mem_free(name);
1023 name = NULL;
1024 }
1025 name = mem_strdup(buffer);
1026 }
1027 }
1028
1029 void pilot::write_ship_info(CFILE *file) {
1030 if (ship_model) {
1031 cf_WriteString(file, ship_model);
1032 } else {
1033 cf_WriteString(file, DEFAULT_SHIP);
1034 }
1035 }
1036
1037 void pilot::read_ship_info(CFILE *file, bool skip) {
1038 char buffer[PAGENAME_LEN];
1039
1040 cf_ReadString(buffer, PAGENAME_LEN, file);
1041
1042 if (!skip) {
1043 if (ship_model) {
1044 mem_free(ship_model);
1045 ship_model = NULL;
1046 }
1047 ship_model = mem_strdup(buffer);
1048 }
1049 }
1050
1051 void pilot::write_custom_multiplayer_data(CFILE *file) {
1052 if (ship_logo) {
1053 cf_WriteString(file, ship_logo);
1054 } else {
1055 cf_WriteString(file, "");
1056 }
1057
1058 if (audio1_file) {
1059 cf_WriteString(file, audio1_file);
1060 } else {
1061 cf_WriteString(file, "");
1062 }
1063
1064 if (audio2_file) {
1065 cf_WriteString(file, audio2_file);
1066 } else {
1067 cf_WriteString(file, "");
1068 }
1069
1070 if (audio3_file) {
1071 cf_WriteString(file, audio3_file);
1072 } else {
1073 cf_WriteString(file, "");
1074 }
1075
1076 if (audio4_file) {
1077 cf_WriteString(file, audio4_file);
1078 } else {
1079 cf_WriteString(file, "");
1080 }
1081
1082 cf_WriteShort(file, picture_id);
1083 }
1084
1085 void pilot::read_custom_multiplayer_data(CFILE *file, bool skip) {
1086 char buffer[PAGENAME_LEN];
1087 uint16_t temp;
1088
1089 cf_ReadString(buffer, PAGENAME_LEN, file);
1090 if (!skip) {
1091 if (ship_logo) {
1092 mem_free(ship_logo);
1093 ship_logo = NULL;
1094 }
1095 ship_logo = mem_strdup(buffer);
1096 }
1097
1098 cf_ReadString(buffer, PAGENAME_LEN, file);
1099 if (!skip) {
1100 if (audio1_file) {
1101 mem_free(audio1_file);
1102 audio1_file = NULL;
1103 }
1104 audio1_file = mem_strdup(buffer);
1105 }
1106
1107 cf_ReadString(buffer, PAGENAME_LEN, file);
1108 if (!skip) {
1109 if (audio2_file) {
1110 mem_free(audio2_file);
1111 audio2_file = NULL;
1112 }
1113 audio2_file = mem_strdup(buffer);
1114 }
1115
1116 if (file_version >= PFV_AUDIOTAUNT3N4) {
1117 cf_ReadString(buffer, PAGENAME_LEN, file);
1118 if (!skip) {
1119 if (audio3_file) {
1120 mem_free(audio3_file);
1121 audio3_file = NULL;
1122 }
1123 audio3_file = mem_strdup(buffer);
1124 }
1125
1126 cf_ReadString(buffer, PAGENAME_LEN, file);
1127 if (!skip) {
1128 if (audio4_file) {
1129 mem_free(audio4_file);
1130 audio4_file = NULL;
1131 }
1132 audio4_file = mem_strdup(buffer);
1133 }
1134 }
1135
1136 temp = cf_ReadShort(file);
1137 if (!skip) {
1138 picture_id = temp;
1139 }
1140 }
1141
1142 void pilot::write_difficulty(CFILE *file) { cf_WriteByte(file, difficulty); }
1143
1144 void pilot::read_difficulty(CFILE *file, bool skip) {
1145 uint8_t temp;
1146
1147 temp = cf_ReadByte(file);
1148 if (!skip) {
1149 difficulty = temp;
1150 }
1151 }
1152
1153 void pilot::write_profanity_filter(CFILE *file) { cf_WriteByte(file, (profanity_filter_on) ? 1 : 0); }
1154
1155 void pilot::read_profanity_filter(CFILE *file, bool skip) {
1156 bool temp;
1157
1158 temp = cf_ReadByte(file) ? true : false;
1159 if (!skip) {
1160 profanity_filter_on = temp;
1161 grtext_SetProfanityFilter(profanity_filter_on);
1162 }
1163 }
1164
1165 void pilot::write_audiotaunts(CFILE *file) { cf_WriteByte(file, (audiotaunts) ? 1 : 0); }
1166
1167 void pilot::read_audiotaunts(CFILE *file, bool skip) {
1168 bool temp;
1169
1170 temp = cf_ReadByte(file) ? true : false;
1171 if (!skip) {
1172 audiotaunts = temp;
1173 taunt_Enable(audiotaunts);
1174 }
1175 }
1176
1177 void pilot::write_guidebot_name(CFILE *file) {
1178 if (guidebot_name) {
1179 cf_WriteByte(file, 1);
1180 cf_WriteString(file, guidebot_name);
1181 } else {
1182 cf_WriteByte(file, 0);
1183 }
1184 }
1185
1186 void pilot::read_guidebot_name(CFILE *file, bool skip) {
1187 if (guidebot_name) {
1188 mem_free(guidebot_name);
1189 guidebot_name = NULL;
1190 }
1191
1192 int len = cf_ReadByte(file);
1193 char buffer[256];
1194
1195 if (len) {
1196 cf_ReadString(buffer, 256, file);
1197 guidebot_name = mem_strdup(buffer);
1198 } else {
1199 guidebot_name = mem_strdup("GB");
1200 }
1201 }
1202
1203 void pilot::write_hud_data(CFILE *file) {
1204 cf_WriteByte(file, hud_mode);
1205 cf_WriteShort(file, hud_stat);
1206 cf_WriteShort(file, hud_graphical_stat);
1207 cf_WriteInt(file, game_window_w);
1208 cf_WriteInt(file, game_window_h);
1209
1210 // PFV_REARVIEWINFO
1211 cf_WriteByte(file, (int8_t)lrearview_enabled);
1212 cf_WriteByte(file, (int8_t)rrearview_enabled);
1213 }
1214
1215 void pilot::read_hud_data(CFILE *file, bool skip) {
1216 uint8_t temp_b;
1217 uint16_t temp_s;
1218 int temp_i;
1219
1220 temp_b = cf_ReadByte(file);
1221 if (!skip) {
1222 hud_mode = temp_b;
1223 }
1224
1225 temp_s = cf_ReadShort(file);
1226 if (!skip) {
1227 hud_stat = temp_s;
1228 }
1229
1230 temp_s = cf_ReadShort(file);
1231 if (!skip) {
1232 hud_graphical_stat = temp_s;
1233 }
1234
1235 temp_i = cf_ReadInt(file);
1236 if (!skip) {
1237 game_window_w = temp_i;
1238 }
1239
1240 temp_i = cf_ReadInt(file);
1241 if (!skip) {
1242 game_window_h = temp_i;
1243 }
1244
1245 // kill graphical stat for inventory and reset to text version
1246 if (!skip) {
1247 if (hud_graphical_stat & STAT_INVENTORY) {
1248 hud_graphical_stat = hud_graphical_stat & (~STAT_INVENTORY);
1249 hud_stat = hud_stat | STAT_INVENTORY;
1250 }
1251 }
1252
1253 // read smallview state
1254 if (file_version >= PFV_REARVIEWINFO) {
1255 lrearview_enabled = (bool)(cf_ReadByte(file) != 0);
1256 rrearview_enabled = (bool)(cf_ReadByte(file) != 0);
1257 } else {
1258 lrearview_enabled = false;
1259 rrearview_enabled = false;
1260 }
1261 }
1262
1263 void pilot::write_mission_data(CFILE *file) {
1264 int i;
1265 cf_WriteInt(file, num_missions_flown);
1266
1267 for (i = 0; i < num_missions_flown; i++) {
1268 cf_WriteByte(file, mission_data[i].highest_level);
1269 cf_WriteByte(file, mission_data[i].finished);
1270 cf_WriteString(file, mission_data[i].mission_name);
1271 cf_WriteInt(file, mission_data[i].num_restores);
1272 cf_WriteInt(file, mission_data[i].num_saves);
1273 cf_WriteInt(file, mission_data[i].ship_permissions);
1274 }
1275 }
1276
1277 void pilot::read_mission_data(CFILE *file, bool skip) {
1278 int temp_i, i, temp_perm;
1279 uint8_t temp_b1, temp_b2;
1280 int temp_restores = 0, temp_saves = 0;
1281 char temp_s[MSN_NAMELEN];
1282
1283 skip = false; // hard code it so we always read this
1284
1285 temp_i = cf_ReadInt(file);
1286 if (!skip) {
1287 num_missions_flown = temp_i;
1288 }
1289
1290 if (temp_i <= 0) {
1291 // no more data to read
1292 return;
1293 }
1294
1295 if (!skip) {
1296 // allocate needed memory
1297 if (mission_data) {
1298 mem_free(mission_data);
1299 mission_data = NULL;
1300 }
1301 mission_data = (tMissionData *)mem_malloc(sizeof(tMissionData) * num_missions_flown);
1302 if (!mission_data) {
1303 // out of memory
1304 num_missions_flown = 0;
1305 skip = true;
1306 }
1307 }
1308
1309 for (i = 0; i < temp_i; i++) {
1310 temp_b1 = cf_ReadByte(file);
1311 temp_b2 = cf_ReadByte(file);
1312 cf_ReadString(temp_s, MSN_NAMELEN, file);
1313
1314 if (file_version >= PFV_AUDIOTAUNT3N4) {
1315 temp_restores = cf_ReadInt(file);
1316 temp_saves = cf_ReadInt(file);
1317 } else {
1318 temp_restores = temp_saves = 0;
1319 }
1320
1321 if (file_version >= PFV_SHIPPERMISSIONS) {
1322 temp_perm = cf_ReadInt(file);
1323 } else {
1324 temp_perm = Default_ship_permission;
1325 }
1326
1327 if (!skip) {
1328 mission_data[i].highest_level = temp_b1;
1329 mission_data[i].ship_permissions = temp_perm;
1330 mission_data[i].finished = (temp_b2) ? true : false;
1331 mission_data[i].num_restores = temp_restores;
1332 mission_data[i].num_saves = temp_saves;
1333 strcpy(mission_data[i].mission_name, temp_s);
1334 }
1335 }
1336 }
1337
1338 void pilot::write_taunts(CFILE *file) {
1339 int i;
1340 cf_WriteByte(file, MAX_PILOT_TAUNTS);
1341
1342 for (i = 0; i < MAX_PILOT_TAUNTS; i++) {
1343 cf_WriteString(file, taunts[i]);
1344 }
1345 }
1346
1347 void pilot::read_taunts(CFILE *file, bool skip) {
1348 int i;
1349 int num_taunts_in_file = cf_ReadByte(file);
1350
1351 if (!skip) {
1352 for (i = 0; i < num_taunts_in_file; i++) {
1353 cf_ReadString(taunts[i], PILOT_TAUNT_SIZE, file);
1354 }
1355
1356 // blank any remaining taunts
1357 for (; i < MAX_PILOT_TAUNTS; i++) {
1358 taunts[i][0] = '\0';
1359 }
1360
1361 } else {
1362 char buffer[PILOT_TAUNT_SIZE];
1363 for (i = 0; i < num_taunts_in_file; i++) {
1364 cf_ReadString(buffer, PILOT_TAUNT_SIZE, file);
1365 }
1366 }
1367 }
1368
1369 void pilot::write_controls(CFILE *file) {
1370 int i;
1371
1372 cf_WriteByte(file, read_controller);
1373 cf_WriteByte(file, NUM_CONTROLLER_FUNCTIONS);
1374
1375 for (i = 0; i < NUM_CONTROLLER_FUNCTIONS; i++) {
1376 cf_WriteInt(file, (int)controls[i].id);
1377 cf_WriteInt(file, (int)controls[i].type[0]);
1378 cf_WriteInt(file, (int)controls[i].type[1]);
1379 cf_WriteInt(file, (int)controls[i].value);
1380 cf_WriteByte(file, (int8_t)controls[i].flags[0]);
1381 cf_WriteByte(file, (int8_t)controls[i].flags[1]);
1382 }
1383
1384 cf_WriteByte(file, N_MOUSE_AXIS);
1385 for (i = 0; i < N_MOUSE_AXIS; i++) {
1386 cf_WriteFloat(file, mouse_sensitivity[i]);
1387 mprintf(0, "pilot mousesens[%d]=%f\n", i, mouse_sensitivity[i]);
1388 }
1389
1390 cf_WriteByte(file, N_JOY_AXIS);
1391 for (i = 0; i < N_JOY_AXIS; i++) {
1392 cf_WriteFloat(file, joy_sensitivity[i]);
1393 }
1394 cf_WriteFloat(file, key_ramping); // 0x29- keyramping
1395
1396 cf_WriteByte(file, (mouselook_control ? 1 : 0)); // version 0x25 - mouselook
1397 }
1398
1399 void pilot::read_controls(CFILE *file, bool skip) {
1400 float temp_f;
1401 uint8_t temp_b;
1402 int i;
1403
1404 // Controller data
1405 temp_b = cf_ReadByte(file);
1406
1407 // alway read this?
1408 read_controller = temp_b;
1409
1410 temp_b = cf_ReadByte(file);
1411
1412 for (i = 0; i < temp_b; i++) {
1413 int id, y;
1414 ct_type type[2];
1415 ct_config_data value;
1416
1417 id = cf_ReadInt(file);
1418 type[0] = (ct_type)cf_ReadInt(file);
1419 type[1] = (ct_type)cf_ReadInt(file);
1420 value = (ct_config_data)cf_ReadInt(file);
1421
1422 for (y = 0; y < temp_b; y++) {
1423 if (Controller_needs[y].id == id) {
1424 if (type[0] == ctNone) // do this if there are new functions that don't have ctNone.
1425 type[0] = Controller_needs[y].ctype[0];
1426 if (type[1] == ctNone) // do this if there are new functions that don't have ctNone.
1427 type[1] = Controller_needs[y].ctype[1];
1428 break;
1429 }
1430 }
1431
1432 controls[y].id = id;
1433 controls[y].type[0] = type[0];
1434 controls[y].type[1] = type[1];
1435 controls[y].value = value;
1436 controls[y].flags[0] = (uint8_t)cf_ReadByte(file);
1437 controls[y].flags[1] = (uint8_t)cf_ReadByte(file);
1438
1439 if (!skip)
1440 Controller->set_controller_function(controls[y].id, controls[y].type, controls[y].value, controls[y].flags);
1441 }
1442
1443 // fill in remainder of pilot controls array.
1444 for (; i < NUM_CONTROLLER_FUNCTIONS; i++) {
1445 Controller->get_controller_function(Controller_needs[i].id, controls[i].type, &controls[i].value,
1446 controls[i].flags);
1447 }
1448
1449 // Set controller enabled masks
1450 if (!skip && Controller) {
1451 Controller->mask_controllers((read_controller & READF_JOY) ? true : false,
1452 (read_controller & READF_MOUSE) ? true : false);
1453 }
1454
1455 // mouse sensitivity
1456 temp_b = cf_ReadByte(file);
1457 for (i = 0; i < temp_b; i++) {
1458 temp_f = cf_ReadFloat(file);
1459 mouse_sensitivity[i] = temp_f;
1460 mprintf(0, "pilot mousesens[%d]=%f\n", i, mouse_sensitivity[i]);
1461 }
1462 for (; i < N_MOUSE_AXIS; i++) {
1463 mouse_sensitivity[i] = 1.0f;
1464 }
1465
1466 // joystick sensitivity
1467 temp_b = cf_ReadByte(file);
1468 for (i = 0; i < temp_b; i++) {
1469 temp_f = cf_ReadFloat(file);
1470 joy_sensitivity[i] = temp_f;
1471 }
1472 for (; i < N_JOY_AXIS; i++) {
1473 joy_sensitivity[i] = 1.0f;
1474 }
1475
1476 if (file_version >= PFV_KEYRAMPING) {
1477 temp_f = cf_ReadFloat(file);
1478 key_ramping = temp_f;
1479 }
1480 if (file_version >= PFV_MOUSELOOK) {
1481 temp_b = cf_ReadByte(file);
1482 mouselook_control = temp_b ? true : false;
1483 }
1484 }
1485
1486 void pilot::write_weapon_select(CFILE *file) {
1487 int i;
1488
1489 cf_WriteShort(file, MAX_PRIMARY_WEAPONS);
1490 for (i = 0; i < MAX_PRIMARY_WEAPONS; i++) {
1491 cf_WriteShort(file, PrimarySelectList[i]);
1492 }
1493
1494 cf_WriteShort(file, MAX_SECONDARY_WEAPONS);
1495 for (i = 0; i < MAX_SECONDARY_WEAPONS; i++) {
1496 cf_WriteShort(file, SecondarySelectList[i]);
1497 }
1498 }
1499
1500 void pilot::read_weapon_select(CFILE *file) {
1501 int i;
1502 int count;
1503
1504 count = cf_ReadShort(file);
1505 for (i = 0; i < count; i++) {
1506 PrimarySelectList[i] = cf_ReadShort(file);
1507 }
1508 for (; i < MAX_PRIMARY_WEAPONS; i++) {
1509 // PrimarySelectList[i] = 0;
1510 }
1511
1512 count = cf_ReadShort(file);
1513 for (i = 0; i < count; i++) {
1514 SecondarySelectList[i] = cf_ReadShort(file);
1515 }
1516 for (; i < MAX_SECONDARY_WEAPONS; i++) {
1517 // SecondarySelectList[i] = 0;
1518 }
1519 }
1520
1521 void pilot::read_gameplay_toggles(CFILE *file, bool skip) {
1522 uint8_t count, i;
1523 bool toggles[16];
1524
1525 for (i = 0; i < 16; i++)
1526 toggles[i] = false;
1527
1528 count = (uint8_t)cf_ReadByte(file);
1529 if (count > 16) {
1530 Int3();
1531 count = 16;
1532 } // bad, very bad.
1533
1534 for (i = 0; i < count; i++) {
1535 toggles[i] = (bool)(cf_ReadByte(file) ? true : false);
1536 }
1537
1538 // define toggles.
1539 if (!skip) {
1540 gameplay_toggles.guided_mainview = toggles[0];
1541 gameplay_toggles.show_reticle = toggles[1];
1542
1543 // verify that we are setting values correctly, if new toggles are added to pilot.
1544 gameplay_toggles.ship_noises = (count < 3) ? true : toggles[2];
1545 }
1546 }
1547
1548 void pilot::write_gameplay_toggles(CFILE *file) {
1549 // number of toggles to write out!
1550 cf_WriteByte(file, 3);
1551
1552 cf_WriteByte(file, (int8_t)gameplay_toggles.guided_mainview);
1553 cf_WriteByte(file, (int8_t)gameplay_toggles.show_reticle);
1554 cf_WriteByte(file, (int8_t)gameplay_toggles.ship_noises);
1555 }