@@ -799,7 +799,7 @@ void pilotfile::csg_write_stats()
799799
800800void pilotfile::csg_read_redalert ()
801801{
802- int idx, i, j, list_size = 0 ;
802+ int idx, i, j, ship_list_size = 0 , wing_list_size = 0 ;
803803 int count;
804804 char t_string[MAX_FILENAME_LEN+NAME_LENGTH+1 ] = { ' \0 ' };
805805 float hit;
@@ -809,17 +809,17 @@ void pilotfile::csg_read_redalert()
809809 throw " RedAlert before Info!" ;
810810 }
811811
812- list_size = cfread_int (cfp);
812+ ship_list_size = cfread_int (cfp);
813813
814- if (list_size <= 0 ) {
814+ if (ship_list_size <= 0 ) {
815815 return ;
816816 }
817817
818818 cfread_string_len (t_string, MAX_FILENAME_LEN, cfp);
819819
820820 Red_alert_precursor_mission = t_string;
821821
822- for (idx = 0 ; idx < list_size ; idx++) {
822+ for (idx = 0 ; idx < ship_list_size ; idx++) {
823823 red_alert_ship_status ras;
824824
825825 cfread_string_len (t_string, NAME_LENGTH, cfp);
@@ -888,28 +888,57 @@ void pilotfile::csg_read_redalert()
888888
889889 // this is quite likely a *bad* thing if it doesn't happen
890890 if (ras.ship_class >= RED_ALERT_LOWEST_VALID_SHIP_CLASS) {
891- Red_alert_wingman_status .push_back ( ras );
891+ Red_alert_ship_status .push_back ( ras );
892892 }
893893 }
894+
895+
896+ // old versions of CSG files do not store wing status
897+ if (csg_ver < 8 ) {
898+ return ;
899+ }
900+
901+
902+ wing_list_size = cfread_int (cfp);
903+
904+ if (wing_list_size <= 0 ) {
905+ return ;
906+ }
907+
908+ for (idx = 0 ; idx < wing_list_size; idx++) {
909+ red_alert_wing_status rws;
910+
911+ cfread_string_len (t_string, NAME_LENGTH, cfp);
912+ rws.name = t_string;
913+
914+ rws.latest_wave = cfread_int (cfp);
915+
916+ rws.wave_count = cfread_int (cfp);
917+ rws.total_arrived_count = cfread_int (cfp);
918+ rws.total_departed = cfread_int (cfp);
919+ rws.total_destroyed = cfread_int (cfp);
920+ rws.total_vanished = cfread_int (cfp);
921+
922+ Red_alert_wing_status.push_back (rws);
923+ }
894924}
895925
896926void pilotfile::csg_write_redalert ()
897927{
898- int idx, j, list_size = 0 ;
928+ int idx, j, ship_list_size = 0 , wing_list_size = 0 ;
899929 int count;
900- red_alert_ship_status *ras;
901930
902931 startSection (Section::RedAlert);
903932
904- list_size = (int )Red_alert_wingman_status .size ();
933+ ship_list_size = (int )Red_alert_ship_status .size ();
905934
906- cfwrite_int (list_size , cfp);
935+ cfwrite_int (ship_list_size , cfp);
907936
908- if (list_size ) {
937+ if (ship_list_size ) {
909938 cfwrite_string_len (Red_alert_precursor_mission.c_str (), cfp);
910939
911- for (idx = 0 ; idx < list_size ; idx++) {
912- ras = &Red_alert_wingman_status [idx];
940+ for (idx = 0 ; idx < ship_list_size ; idx++) {
941+ auto ras = &Red_alert_ship_status [idx];
913942
914943 cfwrite_string_len (ras->name .c_str (), cfp);
915944
@@ -954,6 +983,26 @@ void pilotfile::csg_write_redalert()
954983 }
955984 }
956985
986+ wing_list_size = (int )Red_alert_wing_status.size ();
987+
988+ cfwrite_int (wing_list_size, cfp);
989+
990+ if (wing_list_size) {
991+ for (idx = 0 ; idx < wing_list_size; idx++) {
992+ auto rws = &Red_alert_wing_status[idx];
993+
994+ cfwrite_string_len (rws->name .c_str (), cfp);
995+
996+ cfwrite_int (rws->latest_wave , cfp);
997+
998+ cfwrite_int (rws->wave_count , cfp);
999+ cfwrite_int (rws->total_arrived_count , cfp);
1000+ cfwrite_int (rws->total_departed , cfp);
1001+ cfwrite_int (rws->total_destroyed , cfp);
1002+ cfwrite_int (rws->total_vanished , cfp);
1003+ }
1004+ }
1005+
9571006 endSection ();
9581007}
9591008
@@ -1516,7 +1565,8 @@ void pilotfile::csg_reset_data()
15161565 Campaign.red_alert_containers .clear ();
15171566
15181567 // clear red alert data
1519- Red_alert_wingman_status.clear ();
1568+ Red_alert_ship_status.clear ();
1569+ Red_alert_wing_status.clear ();
15201570
15211571 // clear out mission stuff
15221572 for (idx = 0 ; idx < MAX_CAMPAIGN_MISSIONS; idx++) {
@@ -1768,7 +1818,8 @@ bool pilotfile::save_savefile()
17681818 // assertion before writing so that we don't corrupt the .csg by asserting halfway through writing
17691819 // assertion should also prevent loss of major campaign progress
17701820 // i.e. lose one mission, not several missions worth (in theory)
1771- Assertion (Red_alert_wingman_status.size () <= MAX_SHIPS, " Invalid number of Red_alert_wingman_status entries: " SIZE_T_ARG " \n " , Red_alert_wingman_status.size ());
1821+ Assertion (Red_alert_ship_status.size () <= MAX_SHIPS, " Invalid number of Red_alert_ship_status entries: " SIZE_T_ARG " \n " , Red_alert_ship_status.size ());
1822+ Assertion (Red_alert_wing_status.size () <= MAX_WINGS, " Invalid number of Red_alert_wing_status entries: " SIZE_T_ARG " \n " , Red_alert_wing_status.size ());
17721823
17731824 // open it, hopefully...
17741825 cfp = cfopen (filename.c_str (), " wb" , CFILE_NORMAL, CF_TYPE_PLAYERS, false ,
0 commit comments