Skip to content

Remove the MAX_MISSIONS and MAX_CAMPAIGNS limits - #7824

Draft
Goober5000 wants to merge 3 commits into
scp-fs2open:masterfrom
Goober5000:feature/max_missions_bump
Draft

Goober5000 wants to merge 3 commits into
scp-fs2open:masterfrom
Goober5000:feature/max_missions_bump

Conversation

@Goober5000

@Goober5000 Goober5000 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

This PR builds on #7823 and is in draft until it is merged.

Remove the MAX_MISSIONS limit

The sim room built its standalone and campaign mission lists in fixed arrays of MAX_MISSIONS (1024) entries. A mod with more mission files, or a campaign with more missions, overflowed Campaign_mission_flags.

  • All of these arrays are now SCP_vectors, and their sizes replace the separate Num_standalone_missions and Num_campaign_missions counts.
  • mission_campaign_get_mission_list now appends to an SCP_vector<SCP_string> instead of filling a char* array sized by the caller.
  • The sim room's mission-name vectors now own their strings through SCP_vm_unique_ptr and are cleared unconditionally. Before, the names leaked in two cases:
    • the listing was cancelled partway through, before the *_inited flags were set
    • api_sim_room_build_mission_list ran, because it reset those flags before freeing
  • The standalone and campaign mission flag arrays are removed; they were written but never read, back to the original source release.

Remove the MAX_CAMPAIGNS limit

The campaign list was held in fixed arrays of MAX_CAMPAIGNS (128) char* strings, and the filters wrote into them without checking the bound.

  • Campaign_names, Campaign_file_names and Campaign_descs are now SCP_vector<SCP_string>, filled through the vector overload of cf_get_file_list. Num_campaigns is gone.
  • An empty name or description now means "absent", as nullptr did before. ui.CampaignRoom.getCampaignList still returns "" for a campaign without a description.
  • mission_campaign_get_info now returns the description and first mission through SCP_string* out-parameters, which fixes a leak of the description when parsing failed partway.
  • pilot_set_start_campaign used to write into the global Campaign_names with a counter that was never reset. It also never freed its file list, and sorted the file names by names that didn't match them. It now checks the default campaign first, and only if that fails does it pick the single-player campaign whose title sorts first.
  • The debug mission load menu now builds its campaign filter list from vectors, which also fixes an off-by-one between the displayed names and the Campaign_filter_index-2 lookup.

🤖 Generated with Claude Code

@Goober5000 Goober5000 added the feature A totally new sort of functionality label Oct 5, 2026
@Goober5000 Goober5000 added this to the Release 27.0 milestone Oct 5, 2026
@Goober5000
Goober5000 force-pushed the feature/max_missions_bump branch from 052217e to 46dc010 Compare October 5, 2026 07:07
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>
@Goober5000
Goober5000 force-pushed the feature/max_missions_bump branch 2 times, most recently from 9255280 to 7ba172c Compare October 7, 2026 20:17
Goober5000 and others added 2 commits October 7, 2026 16:47
The sim room listed standalone and campaign missions through fixed
arrays of 1024 entries.  These arrays are now vectors, and the
separate Num_standalone_missions and Num_campaign_missions counts
are replaced by the vectors' sizes.

mission_campaign_get_mission_list now appends to an SCP_vector of
strings instead of filling a caller-sized char* array.

The sim room's mission name vectors now own their strings through
SCP_vm_unique_ptr and are cleared unconditionally.  Previously they
were freed only when the *_inited flags were set, which leaked the
names when a listing was cancelled partway and in
api_sim_room_build_mission_list, which reset the flags before freeing.

The standalone and campaign mission flag arrays are removed; they
were written but never read, back to the original source release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The campaign list (Campaign_names, Campaign_file_names, and
Campaign_descs) was held in fixed arrays of 128 owned char* strings.
These are now SCP_vector<SCP_string>, filled through the SCP_vector
overload of cf_get_file_list, and Num_campaigns is replaced by the
vectors' size.  An empty name or description now means absent.

mission_campaign_get_info returns the description and first mission
through SCP_string out-parameters, which also fixes a leak of the
description when parsing failed partway.

pilot_set_start_campaign no longer writes into the global
Campaign_names with a counter that was never reset.  It now checks
the default campaign first, and only if that is missing or not a
valid single-player campaign does it parse the rest and pick the one
whose title sorts first, replacing the file list filter, its static
name list, and the shell sort.  The debug mission load menu builds
its campaign filter list from vectors, which also lines the names up
with the Campaign_filter_index-2 lookup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant