70 static const size_t SCORING_SIZE = 1808;
122 static const size_t SCORING_INF_SIZE = 3248;
145 void pilotfile_convert::csg_import_ships_weapons()
155 for (idx = 0; idx < ship_count; idx++) {
164 if (ilist.
index < 0) {
165 std::ostringstream error_msg;
166 error_msg <<
"Data mismatch (ship lookup: " << ilist.
name <<
")!";
167 throw std::runtime_error(error_msg.str().c_str());
173 for (idx = 0; idx < weap_count; idx++) {
182 if (ilist.
index < 0) {
183 std::ostringstream error_msg;
184 error_msg <<
"Data mismatch (weapon lookup: " << ilist.
name <<
")!";
185 throw std::runtime_error(error_msg.str().c_str());
192 for (idx = 0; idx < ship_count; idx++) {
200 std::ostringstream error_msg;
202 throw std::runtime_error(error_msg.str().c_str());
208 for (idx = 0; idx < list_size; idx++) {
218 for (idx = 0; idx < list_size; idx++) {
226 void pilotfile_convert::csg_import_missions(
bool inferno)
231 int list_size = 0, k;
242 csg->
missions.reserve(num_missions);
244 for (idx = 0; idx < num_missions; idx++) {
253 miss.
goals.reserve(count);
255 for (j = 0; j <
count; j++) {
256 memset(&n_goal, 0,
sizeof(
mgoal));
261 miss.
goals.push_back( n_goal );
271 miss.
events.reserve(count);
273 for (j = 0; j <
count; j++) {
274 memset(&n_event, 0,
sizeof(
mevent));
279 miss.
events.push_back( n_event );
291 for (j = 0; j <
count; j++) {
309 for (j = 0; j < ship_list_size; j++) {
326 for (j = 0; j < 18; j++) {
332 for (j = 0; j < ship_list_size; j++) {
349 for (j = 0; j < 18; j++) {
363 for (idx = 0; idx < num_missions; idx++) {
366 for (j = 0; j <
count; j++) {
371 for (k = 0; k < list_size; k++) {
386 void pilotfile_convert::csg_import_red_alert()
390 char t_string[35] = {
'\0' };
408 for (idx = 0; idx <
count; idx++) {
409 red_alert_ship_status ras;
418 if (ras.ship_class >= ship_list_size) {
419 throw std::runtime_error(
"Data failure (RedAlert-ship)!");
423 ras.subsys_current_hits.reserve(64);
425 for (j = 0; j < 64; j++) {
427 ras.subsys_current_hits.push_back( val );
430 ras.subsys_aggregate_current_hits.reserve(12);
432 for (j = 0; j < 12; j++) {
434 ras.subsys_aggregate_current_hits.push_back( val );
438 ras.primary_weapons.reserve(3);
440 for (j = 0; j < 3; j++) {
443 if (i >= weapon_list_size || i < -1) {
444 throw std::runtime_error(
"Data check failure (RedAlert-weapon)!");
453 if (weapons.
index >= 0) {
454 ras.primary_weapons.push_back( weapons );
458 ras.secondary_weapons.reserve(4);
460 for (j = 0; j < 4; j++) {
463 if (i >= weapon_list_size || i < -1) {
464 throw std::runtime_error(
"Data check failure (RedAlert-weapon)!");
473 if (weapons.
index >= 0) {
474 ras.secondary_weapons.push_back( weapons );
483 void pilotfile_convert::csg_import_techroom()
485 int idx, list_size = 0;
487 unsigned char in = 0;
499 for (idx = 0; idx < list_size; idx++) {
503 throw std::runtime_error(
"Data check failure (techroom-ship)!");
506 visible = (in == 1) ?
true :
false;
514 for (idx = 0; idx < list_size; idx++) {
518 throw std::runtime_error(
"Data check failure (techroom-weapon)!");
521 visible = (in == 1) ?
true :
false;
527 list_size = intel_count;
529 for (idx = 0; idx < list_size; idx++) {
533 throw std::runtime_error(
"Data check failure (techroom-intel)!");
536 visible = (in == 1) ?
true :
false;
542 void pilotfile_convert::csg_import_loadout()
545 int list_size = 0,
count;
546 char t_string[50] = {
'\0' };
559 for (idx = 0; idx < list_size; idx++) {
568 for (idx = 0; idx < list_size; idx++) {
574 for (idx = 0; idx < MAX_WSS_SLOTS_CONV; idx++) {
577 for (j = 0; j < MAX_SHIP_WEAPONS_CONV; j++) {
584 void pilotfile_convert::csg_import_stats()
597 for (idx = 0; idx < list_size; idx++) {
607 throw std::runtime_error(
"Data check failure (kills size)!");
610 for (idx = 0; idx < list_size; idx++) {
627 void pilotfile_convert::csg_import(
bool inferno)
635 if (csg_id != 0xbeefcafe) {
636 throw std::runtime_error(
"Invalid file signature!");
642 throw std::runtime_error(
"Unsupported file version!");
656 csg_import_ships_weapons();
658 csg_import_missions(inferno);
662 csg_import_red_alert();
664 csg_import_techroom();
666 csg_import_loadout();
674 throw std::runtime_error(
"Data check failure (ship size)!");
676 throw std::runtime_error(
"Data check failure (ship size)!");
678 throw std::runtime_error(
"Data check failure (weapon size)!");
680 throw std::runtime_error(
"Data check failure (weapon size)!");
682 throw std::runtime_error(
"Data check failure (intel size)!");
689 void pilotfile_convert::csg_export_flags()
691 startSection(Section::Flags);
702 void pilotfile_convert::csg_export_info()
708 startSection(Section::Info);
714 for (idx = 0; idx < list_size; idx++) {
722 for (idx = 0; idx < list_size; idx++) {
730 for (idx = 0; idx < list_size; idx++) {
738 for (idx = 0; idx < list_size; idx++) {
759 for (idx = 0; idx < list_size; idx++) {
766 for (idx = 0; idx < list_size; idx++) {
778 void pilotfile_convert::csg_export_missions()
784 startSection(Section::Missions);
788 for (idx = 0; idx < list_size; idx++) {
798 for (j = 0; j <
count; j++) {
807 for (j = 0; j <
count; j++) {
816 for (j = 0; j <
count; j++) {
839 count = (
int)csg->
missions[idx].stats.ship_kills.size();
841 for (j = 0; j <
count; j++) {
846 count = (
int)csg->
missions[idx].stats.medals_earned.size();
848 for (j = 0; j <
count; j++) {
856 void pilotfile_convert::csg_export_techroom()
862 startSection(Section::Techroom);
867 for (idx = 0; idx < list_size; idx++) {
875 for (idx = 0; idx < list_size; idx++) {
883 for (idx = 0; idx < list_size; idx++) {
891 void pilotfile_convert::csg_export_loadout()
896 startSection(Section::Loadout);
905 for (idx = 0; idx < list_size; idx++) {
912 for (idx = 0; idx < list_size; idx++) {
919 for (idx = 0; idx < 12; idx++) {
926 for (j = 0; j < 3; j++) {
934 for (j = 0; j < 4; j++) {
943 void pilotfile_convert::csg_export_stats()
948 startSection(Section::Scoring);
973 for (idx = 0; idx < list_size; idx++) {
979 for (idx = 0; idx < list_size; idx++) {
986 void pilotfile_convert::csg_export_redalert()
988 int idx, j, list_size = 0;
990 red_alert_ship_status *ras;
992 startSection(Section::RedAlert);
1001 for (idx = 0; idx < list_size; idx++) {
1012 count = (
int)ras->subsys_current_hits.size();
1015 for (j = 0; j <
count; j++) {
1020 count = (
int)ras->subsys_aggregate_current_hits.size();
1023 for (j = 0; j <
count; j++) {
1028 count = (
int)ras->primary_weapons.size();
1031 for (j = 0; j <
count; j++) {
1037 count = (
int)ras->secondary_weapons.size();
1040 for (j = 0; j <
count; j++) {
1041 cfwrite_int(ras->secondary_weapons[j].index, cfp);
1042 cfwrite_int(ras->secondary_weapons[j].count, cfp);
1050 void pilotfile_convert::csg_export_hud()
1054 startSection(Section::HUD);
1076 for (idx = 0; idx < 39; idx++) {
1086 void pilotfile_convert::csg_export_variables()
1091 startSection(Section::Variables);
1097 for (idx = 0; idx < list_size; idx++) {
1106 void pilotfile_convert::csg_export_cutscenes() {
1115 size_t viewableScenes = 0;
1116 for (
size_t j=0; j<size && j<32; ++j) {
1134 void pilotfile_convert::csg_export()
1147 csg_export_missions();
1148 csg_export_techroom();
1149 csg_export_loadout();
1151 csg_export_redalert();
1153 csg_export_variables();
1154 csg_export_cutscenes();
1174 filename.reserve(200);
1182 filename.append(fname);
1183 filename.append(
".cs2");
1185 mprintf((
" CS2 => Converting '%s'...\n", filename.c_str()));
1190 mprintf((
" CS2 => Unable to open '%s' for import!\n", fname));
1198 csg_import(inferno);
1199 }
catch (
const std::exception& err) {
1200 mprintf((
" CS2 => Import ERROR: %s\n", err.what()));
1214 filename.assign(fname);
1215 filename.append(
".csg");
1220 mprintf((
" CSG => Unable to open '%s' for export!\n", fname));
1226 }
catch (
const char *err) {
1227 mprintf((
" CSG => Export ERROR: %s\n", err));
1238 mprintf((
" CSG => Conversion complete!\n"));
unsigned int s_bonehead_hits
SCP_vector< mevent > events
unsigned int s_shots_fired
int cfwrite_ushort(ushort s, CFILE *file)
int ship_info_lookup(const char *token)
SCP_vector< medal_stuff > Medals
#define CF_TYPE_SINGLE_PLAYERS
unsigned int missions_flown
bool csg_convert(const char *fname, bool inferno)
SCP_vector< index_list_t > medals_earned
SCP_vector< cutscene_info > Cutscenes
int cfread(void *buf, int elsize, int nelem, CFILE *fp)
int cfwrite_ubyte(ubyte b, CFILE *file)
int cfwrite_uint(uint i, CFILE *file)
SCP_string precursor_mission
int weapon_info_lookup(const char *name=NULL)
SCP_vector< bool > weapons_allowed
unsigned int p_shots_fired
SCP_vector< sexp_variable > variables
void cfread_string(char *buf, int n, CFILE *file)
SCP_vector< index_list_t > intel_list
SCP_vector< sexp_variable > variables
unsigned int mp_shots_hit
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
int cf_create_default_path_string(char *path, uint path_max, int pathtype, const char *filename, bool localize)
unsigned char hud_colors[39][4]
unsigned int ms_shots_fired
unsigned int mp_bonehead_hits
unsigned int s_bonehead_hits
int cfwrite_char(char b, CFILE *file)
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
unsigned int mp_shots_hit
SCP_vector< cmission_conv_t > missions
SCP_vector< index_list_t > weapon_list
int cfwrite_float(float f, CFILE *file)
#define DIR_SEPARATOR_STR
SCP_vector< index_list_t > ship_kills
SCP_vector< red_alert_ship_status > wingman_status
unsigned int p_bonehead_hits
unsigned int s_shots_fired
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...
unsigned int p_shots_fired
unsigned int p_shots_fired
SCP_vector< int > weapon_pool
unsigned int missions_flown
SCP_vector< int > ship_pool
SCP_vector< index_list_t > medals_list
int cfwrite_int(int i, CFILE *file)
unsigned int p_bonehead_hits
unsigned int s_shots_fired
int last_ship_flown_index
struct scoring_conv_INF_t scoring_conv_INF_t
unsigned int p_bonehead_hits
ubyte cfread_ubyte(CFILE *file, int ver, ubyte deflt)
unsigned int ms_bonehead_hits
GLuint const GLchar * name
unsigned int s_bonehead_hits
SCP_vector< bool > ships_techroom
char cfread_char(CFILE *file, int ver, char deflt)
SCP_vector< bool > intel_techroom
unsigned int ms_bonehead_hits
unsigned int missions_flown
ushort cfread_ushort(CFILE *file, int ver, ushort deflt)
SCP_vector< bool > weapons_techroom
int cfread_int(CFILE *file, int ver, int deflt)
float cfread_float(CFILE *file, int ver, float deflt)
char variable_name[TOKEN_LENGTH]
SCP_vector< bool > ships_allowed
int wep_count[MAX_SHIP_WEAPONS_CONV]
struct scoring_conv_t scoring_conv_t
unsigned int mp_shots_fired
unsigned int ms_shots_hit
unsigned int ms_shots_fired
int cfclose(CFILE *cfile)
unsigned int ms_shots_hit
SCP_vector< index_list_t > ship_list
wss_unit_conv_t slot[MAX_WSS_SLOTS_CONV]
unsigned char hud_num_lines
unsigned int mp_shots_fired
unsigned int mp_bonehead_hits
SCP_vector< mgoal > goals
uint cfread_uint(CFILE *file, int ver, uint deflt)
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 wep[MAX_SHIP_WEAPONS_CONV]