Skip to content

Commit

Permalink
Merge pull request #5639 from Goober5000/red_alert_wing_status
Browse files Browse the repository at this point in the history
add wing status to red-alert system
  • Loading branch information
TRBlount authored Oct 4, 2023
2 parents 10f484a + c2d0eaf commit 7f4d78f
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 216 deletions.
397 changes: 203 additions & 194 deletions code/missionui/redalert.cpp

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions code/missionui/redalert.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ void red_alert_invalidate_timestamp();
int red_alert_in_progress();
void red_alert_maybe_move_to_next_mission();

void red_alert_store_wingman_status();
void red_alert_bash_wingman_status();
void red_alert_store_ship_status();
void red_alert_bash_ship_status();
void red_alert_clear();

void red_alert_voice_pause();
Expand All @@ -52,7 +52,20 @@ typedef struct red_alert_ship_status {
SCP_vector<wep_t> secondary_weapons;
} red_alert_ship_status;

extern SCP_vector<red_alert_ship_status> Red_alert_wingman_status;
typedef struct red_alert_wing_status {
SCP_string name;
int latest_wave = 0;

// these aren't currently used but might be needed in the future
int wave_count = 0;
int total_arrived_count = 0;
int total_departed = 0;
int total_destroyed = 0;
int total_vanished = 0;
} red_alert_wing_status;

extern SCP_vector<red_alert_ship_status> Red_alert_ship_status;
extern SCP_vector<red_alert_wing_status> Red_alert_wing_status;
extern SCP_string Red_alert_precursor_mission;
#endif

Expand Down
79 changes: 65 additions & 14 deletions code/pilotfile/csg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ void pilotfile::csg_write_stats()

void pilotfile::csg_read_redalert()
{
int idx, i, j, list_size = 0;
int idx, i, j, ship_list_size = 0, wing_list_size = 0;
int count;
char t_string[MAX_FILENAME_LEN+NAME_LENGTH+1] = { '\0' };
float hit;
Expand All @@ -809,17 +809,17 @@ void pilotfile::csg_read_redalert()
throw "RedAlert before Info!";
}

list_size = cfread_int(cfp);
ship_list_size = cfread_int(cfp);

if (list_size <= 0) {
if (ship_list_size <= 0) {
return;
}

cfread_string_len(t_string, MAX_FILENAME_LEN, cfp);

Red_alert_precursor_mission = t_string;

for (idx = 0; idx < list_size; idx++) {
for (idx = 0; idx < ship_list_size; idx++) {
red_alert_ship_status ras;

cfread_string_len(t_string, NAME_LENGTH, cfp);
Expand Down Expand Up @@ -888,28 +888,57 @@ void pilotfile::csg_read_redalert()

// this is quite likely a *bad* thing if it doesn't happen
if (ras.ship_class >= RED_ALERT_LOWEST_VALID_SHIP_CLASS) {
Red_alert_wingman_status.push_back( ras );
Red_alert_ship_status.push_back( ras );
}
}


// old versions of CSG files do not store wing status
if (csg_ver < 8) {
return;
}


wing_list_size = cfread_int(cfp);

if (wing_list_size <= 0) {
return;
}

for (idx = 0; idx < wing_list_size; idx++) {
red_alert_wing_status rws;

cfread_string_len(t_string, NAME_LENGTH, cfp);
rws.name = t_string;

rws.latest_wave = cfread_int(cfp);

rws.wave_count = cfread_int(cfp);
rws.total_arrived_count = cfread_int(cfp);
rws.total_departed = cfread_int(cfp);
rws.total_destroyed = cfread_int(cfp);
rws.total_vanished = cfread_int(cfp);

Red_alert_wing_status.push_back(rws);
}
}

void pilotfile::csg_write_redalert()
{
int idx, j, list_size = 0;
int idx, j, ship_list_size = 0, wing_list_size = 0;
int count;
red_alert_ship_status *ras;

startSection(Section::RedAlert);

list_size = (int)Red_alert_wingman_status.size();
ship_list_size = (int)Red_alert_ship_status.size();

cfwrite_int(list_size, cfp);
cfwrite_int(ship_list_size, cfp);

if (list_size) {
if (ship_list_size) {
cfwrite_string_len(Red_alert_precursor_mission.c_str(), cfp);

for (idx = 0; idx < list_size; idx++) {
ras = &Red_alert_wingman_status[idx];
for (idx = 0; idx < ship_list_size; idx++) {
auto ras = &Red_alert_ship_status[idx];

cfwrite_string_len(ras->name.c_str(), cfp);

Expand Down Expand Up @@ -954,6 +983,26 @@ void pilotfile::csg_write_redalert()
}
}

wing_list_size = (int)Red_alert_wing_status.size();

cfwrite_int(wing_list_size, cfp);

if (wing_list_size) {
for (idx = 0; idx < wing_list_size; idx++) {
auto rws = &Red_alert_wing_status[idx];

cfwrite_string_len(rws->name.c_str(), cfp);

cfwrite_int(rws->latest_wave, cfp);

cfwrite_int(rws->wave_count, cfp);
cfwrite_int(rws->total_arrived_count, cfp);
cfwrite_int(rws->total_departed, cfp);
cfwrite_int(rws->total_destroyed, cfp);
cfwrite_int(rws->total_vanished, cfp);
}
}

endSection();
}

Expand Down Expand Up @@ -1516,7 +1565,8 @@ void pilotfile::csg_reset_data()
Campaign.red_alert_containers.clear();

// clear red alert data
Red_alert_wingman_status.clear();
Red_alert_ship_status.clear();
Red_alert_wing_status.clear();

// clear out mission stuff
for (idx = 0; idx < MAX_CAMPAIGN_MISSIONS; idx++) {
Expand Down Expand Up @@ -1768,7 +1818,8 @@ bool pilotfile::save_savefile()
// assertion before writing so that we don't corrupt the .csg by asserting halfway through writing
// assertion should also prevent loss of major campaign progress
// i.e. lose one mission, not several missions worth (in theory)
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());
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());
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());

// open it, hopefully...
cfp = cfopen(filename.c_str(), "wb", CFILE_NORMAL, CF_TYPE_PLAYERS, false,
Expand Down
5 changes: 4 additions & 1 deletion code/pilotfile/pilotfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct sexp_container;
// current pilot constants
static const unsigned int PLR_FILE_ID = 0x5f524c50; // "PLR_" in file
static const unsigned int CSG_FILE_ID = 0x5f475343; // "CSG_" in file

// NOTE: Version should be bumped only for adding/removing sections or section
// content. It should *NOT* be bumped for limit bumps or anything of
// that sort!
Expand All @@ -26,6 +27,7 @@ static const unsigned int CSG_FILE_ID = 0x5f475343; // "CSG_" in file
// 3 - Add SEXP containers
// 4 Controls are removed, and instead a preset name is saved/loaded
static const ubyte PLR_VERSION = 4;

// 0 - initial version
// 1 - re-add recent missions
// 2 - separate single/multi squad name & pic
Expand All @@ -34,7 +36,8 @@ static const ubyte PLR_VERSION = 4;
// 5 - save rank to flags for quick access
// 6 - add SEXP containers
// 7 - Controls are removed, and instead a preset name is saved/loaded.
static const ubyte CSG_VERSION = 7;
// 8 - red-alert wing status
static const ubyte CSG_VERSION = 8;

// pilotfile::version and pilotfile::csg_version value when a file isn't loaded (or was just closed)
static const ubyte PLR_VERSION_INVALID = 0xFF;
Expand Down
7 changes: 5 additions & 2 deletions code/ship/ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6237,11 +6237,15 @@ void ship_add_exited_ship( ship *sp, Ship::Exit_Flags reason )
entry.obj_signature = Objects[sp->objnum].signature;
entry.ship_class = sp->ship_info_index;
entry.team = sp->team;
entry.wingnum = sp->wingnum;
entry.flags += reason;
// if ship is red alert, flag as such
// copy some flags
if (sp->flags[Ship_Flags::Red_alert_store_status]) {
entry.flags.set(Ship::Exit_Flags::Red_alert_carry);
}
if (sp->flags[Ship_Flags::From_player_wing]) {
entry.flags.set(Ship::Exit_Flags::From_player_wing);
}
entry.time = Missiontime;
entry.hull_strength = int(Objects[sp->objnum].hull_strength);

Expand Down Expand Up @@ -6473,7 +6477,6 @@ vec3d get_submodel_offset(int model, int submodel){
// Reset all ship values to empty/unused.
void ship::clear()
{

objnum = -1;
ai_index = -1;
ship_info_index = -1;
Expand Down
1 change: 1 addition & 0 deletions code/ship/ship.h
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ typedef struct exited_ship {
int obj_signature;
int ship_class;
int team;
int wingnum;
flagset<Ship::Exit_Flags> flags;
fix time;
int hull_strength;
Expand Down
1 change: 1 addition & 0 deletions code/ship/ship_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ namespace Ship {
Player_deleted,
Been_tagged,
Red_alert_carry,
From_player_wing,

NUM_VALUES
};
Expand Down
4 changes: 2 additions & 2 deletions freespace2/freespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1351,9 +1351,9 @@ void game_post_level_init()
(The_mission.ambient_light_level >> 8) & 0xff,
(The_mission.ambient_light_level >> 16) & 0xff);

// If this is a red alert mission in campaign mode, bash wingman status
// If this is a red alert mission in campaign mode, bash status
if ( (Game_mode & GM_CAMPAIGN_MODE) && red_alert_mission() ) {
red_alert_bash_wingman_status();
red_alert_bash_ship_status();
}

freespace_mission_load_stuff();
Expand Down

0 comments on commit 7f4d78f

Please sign in to comment.