Skip to content

Commit 7f4d78f

Browse files
authored
Merge pull request #5639 from Goober5000/red_alert_wing_status
add wing status to red-alert system
2 parents 10f484a + c2d0eaf commit 7f4d78f

File tree

8 files changed

+297
-216
lines changed

8 files changed

+297
-216
lines changed

code/missionui/redalert.cpp

Lines changed: 203 additions & 194 deletions
Large diffs are not rendered by default.

code/missionui/redalert.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ void red_alert_invalidate_timestamp();
2626
int red_alert_in_progress();
2727
void red_alert_maybe_move_to_next_mission();
2828

29-
void red_alert_store_wingman_status();
30-
void red_alert_bash_wingman_status();
29+
void red_alert_store_ship_status();
30+
void red_alert_bash_ship_status();
3131
void red_alert_clear();
3232

3333
void red_alert_voice_pause();
@@ -52,7 +52,20 @@ typedef struct red_alert_ship_status {
5252
SCP_vector<wep_t> secondary_weapons;
5353
} red_alert_ship_status;
5454

55-
extern SCP_vector<red_alert_ship_status> Red_alert_wingman_status;
55+
typedef struct red_alert_wing_status {
56+
SCP_string name;
57+
int latest_wave = 0;
58+
59+
// these aren't currently used but might be needed in the future
60+
int wave_count = 0;
61+
int total_arrived_count = 0;
62+
int total_departed = 0;
63+
int total_destroyed = 0;
64+
int total_vanished = 0;
65+
} red_alert_wing_status;
66+
67+
extern SCP_vector<red_alert_ship_status> Red_alert_ship_status;
68+
extern SCP_vector<red_alert_wing_status> Red_alert_wing_status;
5669
extern SCP_string Red_alert_precursor_mission;
5770
#endif
5871

code/pilotfile/csg.cpp

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ void pilotfile::csg_write_stats()
799799

800800
void 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

896926
void 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,

code/pilotfile/pilotfile.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct sexp_container;
1616
// current pilot constants
1717
static const unsigned int PLR_FILE_ID = 0x5f524c50; // "PLR_" in file
1818
static const unsigned int CSG_FILE_ID = 0x5f475343; // "CSG_" in file
19+
1920
// NOTE: Version should be bumped only for adding/removing sections or section
2021
// content. It should *NOT* be bumped for limit bumps or anything of
2122
// that sort!
@@ -26,6 +27,7 @@ static const unsigned int CSG_FILE_ID = 0x5f475343; // "CSG_" in file
2627
// 3 - Add SEXP containers
2728
// 4 Controls are removed, and instead a preset name is saved/loaded
2829
static const ubyte PLR_VERSION = 4;
30+
2931
// 0 - initial version
3032
// 1 - re-add recent missions
3133
// 2 - separate single/multi squad name & pic
@@ -34,7 +36,8 @@ static const ubyte PLR_VERSION = 4;
3436
// 5 - save rank to flags for quick access
3537
// 6 - add SEXP containers
3638
// 7 - Controls are removed, and instead a preset name is saved/loaded.
37-
static const ubyte CSG_VERSION = 7;
39+
// 8 - red-alert wing status
40+
static const ubyte CSG_VERSION = 8;
3841

3942
// pilotfile::version and pilotfile::csg_version value when a file isn't loaded (or was just closed)
4043
static const ubyte PLR_VERSION_INVALID = 0xFF;

code/ship/ship.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6237,11 +6237,15 @@ void ship_add_exited_ship( ship *sp, Ship::Exit_Flags reason )
62376237
entry.obj_signature = Objects[sp->objnum].signature;
62386238
entry.ship_class = sp->ship_info_index;
62396239
entry.team = sp->team;
6240+
entry.wingnum = sp->wingnum;
62406241
entry.flags += reason;
6241-
// if ship is red alert, flag as such
6242+
// copy some flags
62426243
if (sp->flags[Ship_Flags::Red_alert_store_status]) {
62436244
entry.flags.set(Ship::Exit_Flags::Red_alert_carry);
62446245
}
6246+
if (sp->flags[Ship_Flags::From_player_wing]) {
6247+
entry.flags.set(Ship::Exit_Flags::From_player_wing);
6248+
}
62456249
entry.time = Missiontime;
62466250
entry.hull_strength = int(Objects[sp->objnum].hull_strength);
62476251

@@ -6473,7 +6477,6 @@ vec3d get_submodel_offset(int model, int submodel){
64736477
// Reset all ship values to empty/unused.
64746478
void ship::clear()
64756479
{
6476-
64776480
objnum = -1;
64786481
ai_index = -1;
64796482
ship_info_index = -1;

code/ship/ship.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ typedef struct exited_ship {
881881
int obj_signature;
882882
int ship_class;
883883
int team;
884+
int wingnum;
884885
flagset<Ship::Exit_Flags> flags;
885886
fix time;
886887
int hull_strength;

code/ship/ship_flags.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ namespace Ship {
149149
Player_deleted,
150150
Been_tagged,
151151
Red_alert_carry,
152+
From_player_wing,
152153

153154
NUM_VALUES
154155
};

freespace2/freespace.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,9 +1351,9 @@ void game_post_level_init()
13511351
(The_mission.ambient_light_level >> 8) & 0xff,
13521352
(The_mission.ambient_light_level >> 16) & 0xff);
13531353

1354-
// If this is a red alert mission in campaign mode, bash wingman status
1354+
// If this is a red alert mission in campaign mode, bash status
13551355
if ( (Game_mode & GM_CAMPAIGN_MODE) && red_alert_mission() ) {
1356-
red_alert_bash_wingman_status();
1356+
red_alert_bash_ship_status();
13571357
}
13581358

13591359
freespace_mission_load_stuff();

0 commit comments

Comments
 (0)