20 #define REDALERT_INTERNAL
28 void pilotfile::csg_read_flags()
39 void pilotfile::csg_write_flags()
41 startSection(Section::Flags);
52 void pilotfile::csg_read_info()
56 int idx, list_size = 0;
59 if ( !m_have_flags ) {
60 throw "Info before Flags!";
71 for (idx = 0; idx < list_size; idx++) {
74 ilist.
name = t_string;
77 ship_list.push_back(ilist);
83 for (idx = 0; idx < list_size; idx++) {
86 ilist.
name = t_string;
89 weapon_list.push_back(ilist);
95 for (idx = 0; idx < list_size; idx++) {
98 ilist.
name = t_string;
101 intel_list.push_back(ilist);
107 for (idx = 0; idx < list_size; idx++) {
110 ilist.
name = t_string;
113 medals_list.push_back(ilist);
120 Assertion ((idx < (
int)ship_list.size()),
"Campaign file contains an incorrect value for the last flown ship class. No data in ship_list for ship number %d.", idx);
121 if (idx >= (
int)ship_list.size())
124 p->last_ship_flown_si_index = ship_list[
idx].index;
126 p->last_ship_flown_si_index = -1;
140 list_size = (
int)ship_list.size();
141 for (idx = 0; idx < list_size; idx++) {
145 if (ship_list[idx].
index >= 0) {
148 m_data_invalid =
true;
154 list_size = (
int)weapon_list.size();
155 for (idx = 0; idx < list_size; idx++) {
159 if (weapon_list[idx].
index >= 0) {
162 m_data_invalid =
true;
174 if (m_data_invalid) {
175 throw "Invalid data for CSG!";
179 void pilotfile::csg_write_info()
183 startSection(Section::Info);
228 for (idx = 0; idx < static_cast<int>(
Ship_info.size()); idx++) {
244 void pilotfile::csg_read_missions()
246 int i, j,
idx, list_size;
249 if ( !m_have_info ) {
250 throw "Missions before Info!";
271 for (j = 0; j < missionp->
num_goals; j++) {
325 list_size = (
int)ship_list.size();
326 for (j = 0; j < list_size; j++) {
329 if (ship_list[j].
index >= 0) {
335 list_size = (
int)medals_list.size();
336 for (j = 0; j < list_size; j++) {
339 if (medals_list[j].
index >= 0) {
346 void pilotfile::csg_write_missions()
351 startSection(Section::Missions);
365 for (j = 0; j < missionp->
num_goals; j++) {
404 for (j = 0; j < static_cast<int>(
Ship_info.size()); j++) {
418 void pilotfile::csg_read_techroom()
420 int idx, list_size = 0;
423 if ( !m_have_info ) {
424 throw "Techroom before Info!";
428 list_size = (
int)ship_list.size();
429 for (idx = 0; idx < list_size; idx++) {
433 if (ship_list[idx].
index >= 0) {
436 m_data_invalid =
true;
442 list_size = (
int)weapon_list.size();
443 for (idx = 0; idx < list_size; idx++) {
447 if (weapon_list[idx].
index >= 0) {
450 m_data_invalid =
true;
456 list_size = (
int)intel_list.size();
457 for (idx = 0; idx < list_size; idx++) {
461 if (intel_list[idx].
index >= 0) {
464 m_data_invalid =
true;
470 if (m_data_invalid) {
471 throw "Invalid data for CSG!";
475 void pilotfile::csg_write_techroom()
480 startSection(Section::Techroom);
521 void pilotfile::csg_read_loadout()
523 int j,
count, ship_idx = -1, wep_idx = -1;
526 if ( !m_have_info ) {
527 throw "Loadout before Info!";
535 list_size = ship_list.size();
536 for (idx = 0; idx < list_size; idx++) {
539 if (ship_list[idx].
index >= 0) {
545 list_size = weapon_list.size();
546 for (idx = 0; idx < list_size; idx++) {
549 if (weapon_list[idx].
index >= 0) {
556 for (
uint i = 0; i < list_size; i++) {
566 if ( (ship_idx >= (
int)ship_list.size()) || (ship_idx < -1) ) {
567 mprintf((
"CSG => Parse Warning: Invalid value for ship index (%d), emptying slot.\n", ship_idx));
572 if (ship_idx == -1) {
582 for (j = 0; j <
count; j++) {
585 if ( (wep_idx >= (
int)weapon_list.size()) || (wep_idx < -1) ) {
586 mprintf((
"CSG => Parse Warning: Invalid value for primary weapon index (%d), emptying slot.\n", wep_idx));
595 slot->
wep[j] = weapon_list[wep_idx].index;
609 for (j = 0; j <
count; j++) {
612 if ( (wep_idx >= (
int)weapon_list.size()) || (wep_idx < -1) ) {
613 mprintf((
"CSG => Parse Warning: Invalid value for secondary weapon index (%d), emptying slot.\n", wep_idx));
634 void pilotfile::csg_write_loadout()
638 startSection(Section::Loadout);
645 for (idx = 0; idx < static_cast<int>(
Ship_info.size()); idx++) {
683 void pilotfile::csg_read_stats()
685 int idx, list_size = 0;
688 if ( !m_have_info ) {
689 throw "Stats before Info!";
714 list_size = (
int)ship_list.size();
715 for (idx = 0; idx < list_size; idx++) {
718 if (ship_list[idx].
index >= 0) {
719 p->stats.kills[ship_list[
idx].index] =
count;
724 list_size = (
int)medals_list.size();
725 for (idx = 0; idx < list_size; idx++) {
728 if (medals_list[idx].
index >= 0) {
729 p->stats.medal_counts[medals_list[
idx].index] =
count;
734 void pilotfile::csg_write_stats()
738 startSection(Section::Scoring);
762 for (idx = 0; idx < static_cast<int>(
Ship_info.size()); idx++) {
774 void pilotfile::csg_read_redalert()
776 int idx,
i, j, list_size = 0;
782 if ( !m_have_info ) {
783 throw "RedAlert before Info!";
788 if (list_size <= 0) {
796 for (idx = 0; idx < list_size; idx++) {
797 red_alert_ship_status ras;
806 if ( (i >= (
int)ship_list.size()) || (i < RED_ALERT_LOWEST_VALID_SHIP_CLASS) ) {
807 mprintf((
"CSG => Parse Warning: Invalid value for red alert ship index (%d), emptying slot.\n", i));
808 ras.ship_class = RED_ALERT_DESTROYED_SHIP_CLASS;
809 }
else if ( (i < 0 ) && (i >= RED_ALERT_LOWEST_VALID_SHIP_CLASS) ) {
812 ras.ship_class = ship_list[
i].index;
818 for (j = 0; j <
count; j++) {
820 ras.subsys_current_hits.push_back( hit );
826 for (j = 0; j <
count; j++) {
828 ras.subsys_aggregate_current_hits.push_back( hit );
834 for (j = 0; j <
count; j++) {
836 weapons.
index = weapon_list[
i].index;
840 if (weapons.
index < 0) {
844 ras.primary_weapons.push_back( weapons );
850 for (j = 0; j <
count; j++) {
852 weapons.
index = weapon_list[
i].index;
856 if (weapons.
index < 0) {
860 ras.secondary_weapons.push_back( weapons );
864 if (ras.ship_class >= RED_ALERT_LOWEST_VALID_SHIP_CLASS) {
870 void pilotfile::csg_write_redalert()
872 int idx, j, list_size = 0;
874 red_alert_ship_status *ras;
876 startSection(Section::RedAlert);
885 for (idx = 0; idx < list_size; idx++) {
896 count = (
int)ras->subsys_current_hits.size();
899 for (j = 0; j <
count; j++) {
904 count = (
int)ras->subsys_aggregate_current_hits.size();
907 for (j = 0; j <
count; j++) {
912 count = (
int)ras->primary_weapons.size();
915 for (j = 0; j <
count; j++) {
921 count = (
int)ras->secondary_weapons.size();
924 for (j = 0; j <
count; j++) {
934 void pilotfile::csg_read_hud()
964 for (idx = 0; idx < num_gauges; idx++) {
981 void pilotfile::csg_write_hud()
985 startSection(Section::HUD);
1017 void pilotfile::csg_read_variables()
1060 void pilotfile::csg_write_variables()
1064 startSection(Section::Variables);
1085 void pilotfile::csg_read_settings()
1129 void pilotfile::csg_write_settings()
1131 startSection(Section::Settings);
1152 void pilotfile::csg_read_controls()
1159 for (idx = 0; idx < list_size; idx++) {
1171 void pilotfile::csg_write_controls()
1175 startSection(Section::Controls);
1179 for (idx = 0; idx <
CCFG_MAX; idx++) {
1189 void pilotfile::csg_read_cutscenes() {
1192 for(
size_t i = 0; i < list_size; i++) {
1200 void pilotfile::csg_write_cutscenes() {
1205 size_t viewableScenes = 0;
1223 void pilotfile::csg_read_lastmissions()
1245 void pilotfile::csg_write_lastmissions()
1249 startSection(Section::LastMissions);
1260 void pilotfile::csg_reset_data()
1266 m_have_flags =
false;
1267 m_have_info =
false;
1269 m_data_invalid =
false;
1306 if (missionp->
goals) {
1309 missionp->
goals = NULL;
1328 void pilotfile::csg_close()
1339 weapon_list.clear();
1341 medals_list.clear();
1343 m_have_flags =
false;
1344 m_have_info =
false;
1350 std::ostringstream
buf;
1356 if ( (campaign == NULL) || !strlen(campaign) ) {
1365 _splitpath((
char*)campaign, NULL, NULL, base, NULL);
1367 buf <<
p->callsign <<
"." << base <<
".csg";
1369 filename = buf.str().c_str();
1375 mprintf((
"CSG => Unable to find campaign file '%s'!\n", buf.str().c_str()));
1380 m_data_invalid =
false;
1386 mprintf((
"CSG => Unable to open '%s' for reading!\n", filename.c_str()));
1392 if (csg_id != CSG_FILE_ID) {
1393 mprintf((
"CSG => Invalid header id for '%s'!\n", filename.c_str()));
1401 mprintf((
"CSG => Loading '%s' with version %d...\n", filename.c_str(), (
int)csg_ver));
1406 while ( !
cfeof(cfp) ) {
1410 size_t start_pos =
cftell(cfp);
1416 switch (section_id) {
1417 case Section::Flags:
1418 mprintf((
"CSG => Parsing: Flags...\n"));
1419 m_have_flags =
true;
1424 mprintf((
"CSG => Parsing: Info...\n"));
1429 case Section::Variables:
1430 mprintf((
"CSG => Parsing: Variables...\n"));
1431 csg_read_variables();
1435 mprintf((
"CSG => Parsing: HUD...\n"));
1439 case Section::RedAlert:
1440 mprintf((
"CSG => Parsing: RedAlert...\n"));
1441 csg_read_redalert();
1444 case Section::Scoring:
1445 mprintf((
"CSG => Parsing: Scoring...\n"));
1449 case Section::Loadout:
1450 mprintf((
"CSG => Parsing: Loadout...\n"));
1454 case Section::Techroom:
1455 mprintf((
"CSG => Parsing: Techroom...\n"));
1456 csg_read_techroom();
1459 case Section::Missions:
1460 mprintf((
"CSG => Parsing: Missions...\n"));
1461 csg_read_missions();
1464 case Section::Settings:
1465 mprintf((
"CSG => Parsing: Settings...\n"));
1466 csg_read_settings();
1469 case Section::Controls:
1470 mprintf((
"CSG => Parsing: Controls...\n"));
1471 csg_read_controls();
1475 mprintf((
"CSG => Parsing: Cutscenes...\n"));
1476 csg_read_cutscenes();
1479 case Section::LastMissions:
1480 mprintf((
"CSG => Parsing: Last Missions...\n"));
1481 csg_read_lastmissions();
1485 mprintf((
"CSG => Skipping unknown section 0x%04x!\n", section_id));
1491 mprintf((
"CSG => Warning: (0x%04x) %s\n", section_id, msg.
what()));
1492 }
catch (
const char *err) {
1493 mprintf((
"CSG => ERROR: %s\n", err));
1502 size_t offset_pos = (start_pos + section_size) -
cftell(cfp);
1505 mprintf((
"CSG => Warning: (0x%04x) Short read, information may have been lost!\n", section_id));
1511 if (
p->s_squad_filename[0] ==
'\0') {
1512 strcpy_s(
p->s_squad_filename,
p->m_squad_filename);
1516 mprintf((
"CSG => Loading complete!\n"));
1527 std::ostringstream
buf;
1544 buf <<
p->callsign <<
"." << base <<
".csg";
1546 filename = buf.str().c_str();
1549 if (m_data_invalid) {
1550 mprintf((
"CSG => Skipping save of '%s' due to invalid data check!\n", filename.c_str()));
1564 mprintf((
"CSG => Unable to open '%s' for saving!\n", filename.c_str()));
1572 mprintf((
"CSG => Saving '%s' with version %d...\n", filename.c_str(), (
int)CSG_VERSION));
1575 mprintf((
"CSG => Saving: Flags...\n"));
1577 mprintf((
"CSG => Saving: Info...\n"));
1581 mprintf((
"CSG => Saving: Missions...\n"));
1582 csg_write_missions();
1583 mprintf((
"CSG => Saving: Techroom...\n"));
1584 csg_write_techroom();
1585 mprintf((
"CSG => Saving: Loadout...\n"));
1586 csg_write_loadout();
1587 mprintf((
"CSG => Saving: Scoring...\n"));
1589 mprintf((
"CSG => Saving: RedAlert...\n"));
1590 csg_write_redalert();
1591 mprintf((
"CSG => Saving: HUD...\n"));
1593 mprintf((
"CSG => Saving: Variables...\n"));
1594 csg_write_variables();
1595 mprintf((
"CSG => Saving: Settings...\n"));
1596 csg_write_settings();
1597 mprintf((
"CSG => Saving: Controls...\n"));
1598 csg_write_controls();
1599 mprintf((
"CSG => Saving: Cutscenes...\n"));
1600 csg_write_cutscenes();
1601 mprintf((
"CSG => Saving: Last Missions...\n"));
1602 csg_write_lastmissions();
1605 mprintf((
"CSG => Saving complete!\n"));
1616 bool pilotfile::get_csg_rank(
int *rank)
1627 mprintf((
"CSG => Unable to open '%s'!\n", filename.c_str()));
1633 if (csg_id != CSG_FILE_ID) {
1634 mprintf((
"CSG => Invalid header id for '%s'!\n", filename.c_str()));
1642 mprintf((
"CSG => Get Rank from '%s' with version %d...\n", filename.c_str(), (
int)csg_ver));
1645 while ( !m_have_flags && !
cfeof(cfp) ) {
1649 size_t start_pos =
cftell(cfp);
1656 switch (section_id) {
1657 case Section::Flags:
1658 mprintf((
"CSG => Parsing: Flags...\n"));
1659 m_have_flags =
true;
1669 mprintf((
"CSG => (0x%04x) %s\n", section_id, msg.
what()));
1670 }
catch (
const char *err) {
1671 mprintf((
"CSG => ERROR: %s\n", err));
1680 offset_pos = (start_pos + section_size) -
cftell(cfp);
1683 mprintf((
"CSG => Warning: (0x%04x) Short read, information may have been lost!\n", section_id));
1689 *rank =
p->stats.rank;
1691 mprintf((
"CSG => Get Rank complete!\n"));
int cfwrite_ushort(ushort s, CFILE *file)
int ship_info_lookup(const char *token)
SCP_vector< medal_stuff > Medals
int Briefing_voice_enabled
void audiostream_set_volume_all(float volume, int type)
#define MAX_SHIP_PRIMARY_BANKS
#define HUD_COLOR_ALPHA_DEFAULT
SCP_vector< cutscene_info > Cutscenes
int kills[MAX_SHIP_CLASSES]
void player_set_squad_bitmap(player *p, char *fname, bool ismulti)
void cf_set_max_read_len(CFILE *cfile, size_t len)
char Recent_missions[MAX_RECENT_MISSIONS][MAX_FILENAME_LEN]
short key_id
actual key bound to action
weapon_info Weapon_info[MAX_WEAPON_TYPES]
int medals_info_lookup(const char *name)
int cfwrite_ubyte(ubyte b, CFILE *file)
int cfwrite_uint(uint i, CFILE *file)
int weapon_info_lookup(const char *name=NULL)
virtual const char * what() const
#define WIF2_DEFAULT_IN_TECH_DATABASE
char filename[MAX_FILENAME_LEN]
SCP_string Red_alert_precursor_mission
int weapon_pool[MAX_WEAPON_TYPES]
color clr[NUM_HUD_GAUGES]
#define Assertion(expr, msg,...)
SCP_vector< red_alert_ship_status > Red_alert_wingman_status
ubyte ships_allowed[MAX_SHIP_CLASSES]
unsigned int s_shots_fired
void hud_config_record_color(int in_color)
GLenum GLuint GLenum GLsizei const GLchar * buf
short joy_id
joystick button bound to action
config_item Control_config[]
Stores the keyboard configuration.
int wep_count[MAX_SHIP_WEAPONS]
sexp_variable * redalert_variables
#define SIF2_DEFAULT_IN_TECH_DATABASE
player Players[MAX_PLAYERS]
#define FS_CAMPAIGN_FILE_EXT
int cfwrite_char(char b, CFILE *file)
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
#define MAX_SHIP_SECONDARY_BANKS
#define HUD_COLOR_ALPHA_USER_MIN
float Master_sound_volume
#define WIF_IN_TECH_DATABASE
ubyte weapons_allowed[MAX_WEAPON_TYPES]
int cfwrite_float(float f, CFILE *file)
unsigned int p_shots_fired
int cf_exists_full(const char *filename, int dir_type)
wss_unit unit_data[MAX_WSS_SLOTS]
int cfwrite_string_len(const char *buf, CFILE *file)
Write a fixed length string (not including its null terminator), with the length stored in file...
GLsizei const GLchar ** string
SCP_vector< int > medal_counts
short cfread_short(CFILE *file, int ver, short deflt)
#define SIF_IN_TECH_DATABASE
int cfwrite_int(int i, CFILE *file)
sexp_variable * variables
void _splitpath(char *path, char *drive, char *dir, char *fname, char *ext)
ubyte cfread_ubyte(CFILE *file, int ver, ubyte deflt)
GLuint const GLchar * name
ubyte num_msg_window_lines
bool load_savefile(const char *campaign)
char cfread_char(CFILE *file, int ver, char deflt)
int wep[MAX_SHIP_WEAPONS]
loadout_data Player_loadout
int cfwrite_short(short s, CFILE *file)
unsigned int p_bonehead_hits
HUD_CONFIG_TYPE HUD_config
SCP_vector< ship_info > Ship_info
float Master_event_music_volume
The total number of defined control actions (or last define + 1)
ushort cfread_ushort(CFILE *file, int ver, ushort deflt)
int cfread_int(CFILE *file, int ver, int deflt)
float cfread_float(CFILE *file, int ver, float deflt)
#define MAX_CAMPAIGN_MISSIONS
void cutscene_mark_viewable(char *filename)
char variable_name[TOKEN_LENGTH]
char filename[MAX_FILENAME_LEN]
int cfclose(CFILE *cfile)
#define MAX_RECENT_MISSIONS
GLclampf GLclampf GLclampf alpha
int num_missions_completed
sexp_variable * variables
int ship_pool[MAX_SHIP_CLASSES]
unsigned int s_bonehead_hits
float Master_voice_volume
cmission missions[MAX_CAMPAIGN_MISSIONS]
uint cfread_uint(CFILE *file, int ver, uint deflt)
int redalert_num_variables
char last_modified[DATE_TIME_LENGTH]
void cfread_string_len(char *buf, int n, CFILE *file)
Read a fixed length string that is not null-terminated, with the length stored in file...
int cfseek(CFILE *fp, int offset, int where)