Skip to content

refactor team loadout data structures in preparation for lifting the ship class limit - #7737

Open
Goober5000 wants to merge 2 commits into
scp-fs2open:masterfrom
Goober5000:refactor/team_data
Open

refactor team loadout data structures in preparation for lifting the ship class limit#7737
Goober5000 wants to merge 2 commits into
scp-fs2open:masterfrom
Goober5000:refactor/team_data

Conversation

@Goober5000

Copy link
Copy Markdown
Contributor

team_data was the last persistence-adjacent structure sized by MAX_SHIP_CLASSES: four parallel ship arrays plus four parallel weapon arrays (one slot per mission-file loadout line, holding a class or a sexp variable name, and a count or a sexp variable name) with manual num_*_choices counters, plus a dense per-class weapon_required flag array. Convert all of it to the sparse-container family:

ship_list / ship_list_variables / ship_count / ship_count_variables
-> SCP_vector<loadout_entry> ship_choices
weaponry_pool / weaponry_count / weaponry_pool_variable /
weaponry_amount_variable
-> SCP_vector<loadout_entry> weapon_choices
bool weapon_required[MAX_WEAPON_TYPES]
-> SCP_set required_weapons

where loadout_entry is {class_index, count, class_variable, count_variable}, with empty variable strings meaning the value was given literally. num_ship_choices / num_weapon_choices become .size().

Intentional behavior fixes, all previously latent memory errors or
data bugs:

  • is_ship_assignable stored an alt ship CLASS in a variable used as a
    loadout list INDEX when default_to_this_class was false, then
    swapped to ship_list[class] - garbage for any mission where the two
    domains diverge. It now swaps to the alt class itself, per the
    evident intent.

  • The default-ship fallback read ship_list[0] even when a team had
    zero ship choices; it now leaves default_ship at -1, and
    ss_fixup_team_data guards its append of the default ship accordingly.

  • FRED2's dumpstats indexed Ships[] with a ship class when printing
    loadout entries; it now prints the entry's class or variable name
    directly.

  • Team parse now clears the previous mission's entries explicitly
    rather than relying on overwrite-in-place.

This clears the largest remaining cluster of MAX_SHIP_CLASSES references on the way to lifting the ship class limit.

@Goober5000 Goober5000 added this to the Release 26.2 milestone Aug 24, 2026
@Goober5000 Goober5000 added refactor A cleanup/restructure of a feature for speed, simplicity, and/or maintainability Requested by Active Mod A feature request that has been requested by a mod that is actively in development. labels Aug 24, 2026
@Goober5000
Goober5000 requested a review from BMagnu August 24, 2026 06:31
@Goober5000
Goober5000 force-pushed the refactor/team_data branch 3 times, most recently from 17f79eb to efda428 Compare August 24, 2026 15:43
@Kestrellius Kestrellius self-assigned this Aug 24, 2026
Comment thread code/missioneditor/missionsave.cpp Outdated
Goober5000 and others added 2 commits August 24, 2026 20:04
team_data was the last persistence-adjacent structure sized by MAX_SHIP_CLASSES: four parallel ship arrays plus four parallel weapon arrays (one slot per mission-file loadout line, holding a class or a sexp variable name, and a count or a sexp variable name) with manual num_*_choices counters, plus a dense per-class weapon_required flag array.  Convert all of it to the sparse-container family:

  ship_list / ship_list_variables / ship_count / ship_count_variables
    -> SCP_vector<loadout_entry> ship_choices
  weaponry_pool / weaponry_count / weaponry_pool_variable /
  weaponry_amount_variable
    -> SCP_vector<loadout_entry> weapon_choices
  bool weapon_required[MAX_WEAPON_TYPES]
    -> SCP_set<int> required_weapons

where loadout_entry is {class_index, count, class_variable, count_variable}, with empty variable strings meaning the value was given literally.  num_ship_choices / num_weapon_choices become .size().

Intentional behavior fixes, all previously latent memory errors or
data bugs:

 * is_ship_assignable stored an alt ship CLASS in a variable used as a
   loadout list INDEX when default_to_this_class was false, then
   swapped to ship_list[class] - garbage for any mission where the two
   domains diverge.  It now swaps to the alt class itself, per the
   evident intent.

 * The default-ship fallback read ship_list[0] even when a team had
   zero ship choices; it now leaves default_ship at -1, and
   ss_fixup_team_data guards its append of the default ship accordingly.

 * FRED2's dumpstats indexed Ships[] with a ship class when printing
   loadout entries; it now prints the entry's class or variable name
   directly.

 * Team parse now clears the previous mission's entries explicitly
   rather than relying on overwrite-in-place.

This clears the largest remaining cluster of MAX_SHIP_CLASSES references on the way to lifting the ship class limit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
FRED2, qtFRED, and the shared mission save code each carried their own copy of the loadout usage builders.  The weaponry pair already had shared versions in missioneditor/common; this converts those to the SCP_map<int,int> signature the editors now use, adds the missing ship builder alongside them, and deletes both editors' private copies.

FRED2's playerstarteditor/freddoc and qtFRED's Editor/ErrorChecker all call the shared functions now, following the update_custom_wing_indexes consolidation precedent.  missionsave's used_pool becomes a map as well, which removes its MAX_WEAPON_TYPES stack array.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor A cleanup/restructure of a feature for speed, simplicity, and/or maintainability Requested by Active Mod A feature request that has been requested by a mod that is actively in development.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants