Skip to content

remove the MAX_CAMPAIGN_MISSIONS limit - #7823

Open
Goober5000 wants to merge 2 commits into
scp-fs2open:masterfrom
Goober5000:feature/campaign_missions_bump
Open

Goober5000 wants to merge 2 commits into
scp-fs2open:masterfrom
Goober5000:feature/campaign_missions_bump

Conversation

@Goober5000

@Goober5000 Goober5000 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Campaigns were limited to 100 missions by a fixed-size array in the campaign struct, and the campaign parser did not check that limit, so a campaign file with more missions overflowed the array into the vectors that follow it. Campaign.missions is now an SCP_vector sized by the parser, and the separate num_missions count is replaced by the vector's size. cmission members now have default initializers so that resized entries start out valid.

The other arrays sized by MAX_CAMPAIGN_MISSIONS are vectors as well: the mission name lists in the mission load menu and the ready room, and the retail promotion voice table. In FRED2, the campaign tree's Sorted, Elements, Level_counts, and Links arrays are vectors too, which removes the MAX_LEVELS and MAX_CAMPAIGN_TREE_LINKS limits and the separate Total_links count. Removing a mission from the tree now pops the vacated last slot.

The multiplayer client sizes its mission list from the count the server sends. Multiplayer campaigns are still limited to 255 missions, since the protocol sends the count as a ubyte.

When reading a campaign save file, data for a stored mission index that is out of range is now discarded, where it was previously written into the array without a check. The Lua campaign mission accessors, the loop brief stage handle, the debriefing persona lookup, and the main hall lookups also check the index against the mission list, and the main hall falls back to its defaults when the campaign has no missions.

Since a save file's mission data is stored by index, it only applies to the campaign it was saved from. The barracks and pilot selection screens can load a pilot's save file while a different campaign is loaded, so mission data from a save file for another campaign is now discarded, and saving is skipped until a matching save file is loaded or the save data is cleared, so that the mixed data is not written to the campaign's save file.

@Goober5000 Goober5000 added this to the Release 27.0 milestone Oct 4, 2026
@Goober5000 Goober5000 added the feature A totally new sort of functionality label Oct 4, 2026
@Goober5000
Goober5000 marked this pull request as draft October 4, 2026 21:53
@Goober5000
Goober5000 force-pushed the feature/campaign_missions_bump branch from 06261ac to 13263ed Compare October 5, 2026 00:13
@Goober5000
Goober5000 marked this pull request as ready for review October 5, 2026 00:14
@Goober5000
Goober5000 force-pushed the feature/campaign_missions_bump branch 5 times, most recently from 1faae27 to af0db17 Compare October 5, 2026 03:01
Campaigns were limited to 100 missions by a fixed-size array in the
campaign struct, and the campaign parser did not check that limit, so a
campaign file with more missions overflowed the array into the vectors
that follow it.  Campaign.missions is now an SCP_vector sized by the
parser, and the separate num_missions count is replaced by the vector's
size.  cmission members now have default initializers so that resized
entries start out valid.

The other arrays sized by MAX_CAMPAIGN_MISSIONS are vectors as well: the
mission name lists in the mission load menu and the ready room.  In FRED2,
the campaign tree's Sorted, Elements, Level_counts, and Links arrays are
vectors too, which removes the MAX_LEVELS and MAX_CAMPAIGN_TREE_LINKS
limits and the separate Total_links count.  Removing a mission from the
tree now pops the vacated last slot.

The multiplayer client sizes its mission list from the count the server
sends.  Multiplayer campaigns are still limited to 255 missions, since
the protocol sends the count as a ubyte.

When reading a campaign save file, data for a stored mission index that
is out of range is now discarded, where it was previously written into
the array without a check.  The Lua campaign mission accessors, the loop
brief stage handle, the debriefing persona lookup, and the main hall
lookups also check the index against the mission list, and the main hall
falls back to its defaults when the campaign has no missions.

Since a save file's mission data is stored by index, it only applies to
the campaign it was saved from.  The barracks and pilot selection screens
can load a pilot's save file while a different campaign is loaded, so
mission data from a save file for another campaign is now discarded, and
saving is skipped until a matching save file is loaded or the save data
is cleared, so that the mixed data is not written to the campaign's save
file.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@dustinspace217 dustinspace217 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read through this one; the conversion looks complete and I didn't find any cmission pointer that a resize could invalidate. A few spots where the old 100 spare slots used to hide an out-of-range index:

  1. csg_read_info doesn't range-check prev_mission or loop_reentry, so a mod update that shortens a campaign under an existing save makes Continue read past the end at readyroom.cpp:841. The new !Csg_campaign_mismatch at csg.cpp:151 also lets another campaign's next_mission through, which a script calling loadCampaignSavefile mid-mission can reach via exit-loop or jump-to-mission. Clamping all three always, and only skipping m_data_invalid on a mismatch, would cover both. (Our #7906 adds the prev/loop clamps against the old array; I'll rebase it onto this.)
  2. FRED2 remove_mission: if the last mission is selected and an earlier one is removed, Cur_campaign_mission still points at the popped slot (campaigntreeview.cpp:1292), and the main hall and persona edits write there. Remapping it from the last slot to m should fix it. I couldn't run FRED2 here, so this is from reading.
  3. Campaign_mission_flags[MAX_MISSIONS] (readyroom.cpp:206) overflows above 1024 missions and nothing reads it, so it could just go.
  4. Discarded records still count in num_missions_completed, so the next save declares more records than it writes. The section read cap catches it, so it's only a warning on each load, but subtracting the discards would keep the count right.
  5. When saving is skipped for a mismatch (csg.cpp:1904), release builds show nothing, and settings and control changes are dropped too. Would a ReleaseWarning and a note in the loadCampaignSavefile doc make sense?

Smaller: getMainHallIndex returns -1 with no missions where the engine uses hall 0; sort_links and correct_position index missions[-1] for end-of-campaign links (older, but now outside the vector); the sim room list stops at 200 lines; the promotion voice table is still a fixed [35]; and a few whitespace-only edits on untouched lines.

I haven't playtested this yet; this is from reading and a clean Debug build.

@Goober5000

Copy link
Copy Markdown
Contributor Author

@dustinspace217 can you review this while keeping #7824 in mind? Some of them may be addressed there

@dustinspace217

Copy link
Copy Markdown
Contributor

Went through each point again with #7824 (4281b92) open next to it. Its first commit is the same patch as this PR, and its other two commits only touch readyroom.cpp, missioncampaign.cpp/.h, missionload.cpp, multiui.cpp, managepilot.cpp and the scripting ui.cpp. So:

This is still from reading, not a playtest.

Comment thread code/menuui/readyroom.cpp
static int Standalone_mission_flags[MAX_MISSIONS];
static char *Campaign_missions[MAX_MISSIONS] = { NULL };
static char *Campaign_mission_names[MAX_CAMPAIGN_MISSIONS] = { NULL };
static SCP_vector<char*> Campaign_mission_names;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decidedly not a fan of SCP_vector<char*> over SCP_vector<SCP_string>, especially since quite some code is destroying the allocated strings which degrades to an automatic destruction with a real string

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are converted in PR #7825

char * recent_missions[MAX_RECENT_MISSIONS];
char * campaign_names[MAX_CAMPAIGNS+2];
char * campaign_missions[MAX_CAMPAIGN_MISSIONS];
SCP_vector<char*> campaign_missions;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@Goober5000 Goober5000 Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also #7825 Actually not #7825, but I can do it when that PR comes out of draft

EDIT: actually no:

  • missionload.cpp:163 (campaign_missions): this one can't be SCP_string. The listbox's set_new_list(int, char**) needs an array of char*. The names themselves are already stored in SCP_vector<SCP_string> Campaign_missions; campaign_missions is only the char* view of them that the listbox takes.

When reading a campaign save file, prev_mission and loop_reentry are
now checked against the mission list as well as next_mission.  An
out-of-range prev_mission is reset to -1, and an out-of-range
next_mission or loop_reentry is reset to 0, since for those -1 means
the campaign ends there.  The invalid-data warning is shown only when
the save file is for the loaded campaign.  Mission records discarded
for an out-of-range index no longer count toward
num_missions_completed, so the next save declares as many records as
it writes.

In FRED2, removing a mission now keeps the selection on the mission
that is moved into the vacated slot, and deleting a link clears or
shifts the selected link index so that it doesn't run past the end of
the link list.  End-of-campaign links, whose target is -1, are skipped
when correcting mission levels and are sorted after the other links,
instead of indexing the mission list with -1.

The Lua documentation for getMainHallIndex now says that it returns a
0-based index, and loadCampaignSavefile documents that loading a save
file for another campaign blocks saving.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Goober5000

Copy link
Copy Markdown
Contributor Author

@dustinspace217 addressed

@dustinspace217 dustinspace217 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked at bf530ad. All three save indexes are now clamped whatever the campaign, the warning only shows for the loaded campaign, and discarded records no longer count toward num_missions_completed. In FRED2 the selection follows the mission moved into the removed slot, the link selection is kept in range after a delete, and end-of-campaign links are skipped in sort_links and correct_position. Fine by me to leave Campaign_mission_flags to #7825.

From reading only; FRED2 doesn't build here, so the MSVC jobs are the compile check for that part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature A totally new sort of functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants