Skip to content

refactor: Remove static company sizes and KILL parallel arrays - #1405

Open
OH296 wants to merge 13 commits into
Adeptus-Dominus:mainfrom
OH296:static_array_lengths
Open

refactor: Remove static company sizes and KILL parallel arrays#1405
OH296 wants to merge 13 commits into
Adeptus-Dominus:mainfrom
OH296:static_array_lengths

Conversation

@OH296

@OH296 OH296 commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Summary by cubic

Replaced static 501-slot arrays and parallel fields with per-unit properties and dynamic per-company rosters. Loops, serialization, and UI now respect actual roster sizes; ascension/gene-seed logic and ship occupant summaries are corrected.

  • Refactors

    • Removed obj_ini.age/spe/god; use unit.age, unit.specials, unit.god_status across recruiting, moving, exports, Reclusiam, dialogue/events, AI, combat, and helpers.
    • Rosters resize to exact company size; scr_company_order rebuilds visible mirrors only (race/name/role/wep1/2/armour/gear/mobi).
    • find_company_open_slot grows per-company arrays and returns the new index; most loops now use array_length(obj_ini.TTRPG[c]) from 0.
    • Serialization iterates companies and each company’s TTRPG length (no 11×501 scan).
    • TTRPG_stats: age, specials, god_status are fields; roll_age sets age; marine_ascension is turn-based; armour/XP calculations read age.
    • Rewrote ship occupant listing to build pluralized role strings from a gathered unit list and vehicle roles.
  • Bug Fixes

    • Reclusiam/jail and role counts read unit.god_status; UI toggles work with dynamic rosters.
    • Gene-seed recovery uses unit.age in after-combat and marine_ascension thresholds in kill-and-recover.
    • Detail panel shows rounded unit.age and ascension year.
    • Force counting, crusade, equipment checks, and exports iterate by per-company roster length.

Written for commit 44e9a25. Summary will update on new commits.

Review in cubic

@github-actions github-actions Bot added Size: Medium Type: Refactor Rewriting/restructuring code, while keeping general behavior labels Jul 28, 2026

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread objects/obj_ini/Create_0.gml
Comment thread scripts/scr_company_view/scr_company_view.gml Outdated
Comment thread objects/obj_controller/Alarm_5.gml Outdated
Comment thread scripts/scr_company_view/scr_company_view.gml Outdated
Comment thread scripts/scr_add_man/scr_add_man.gml
Comment thread objects/obj_ini/Create_0.gml
Comment thread scripts/scr_chapter_managent_events/scr_chapter_managent_events.gml Outdated
Comment thread scripts/scr_company_order/scr_company_order.gml
Comment thread scripts/scr_marine_struct/scr_marine_struct.gml

@cubic-dev-ai cubic-dev-ai Bot 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.

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 20 unresolved issues from previous reviews.

Re-trigger cubic

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 4 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread objects/obj_controller/Alarm_5.gml
Comment thread scripts/scr_company_view/scr_company_view.gml Outdated
Comment thread scripts/scr_company_view/scr_company_view.gml

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 5 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread scripts/scr_unit_detail_text/scr_unit_detail_text.gml Outdated
Comment thread scripts/scr_company_view/scr_company_view.gml Outdated
Comment thread scripts/scr_marine_struct/scr_marine_struct.gml
Comment thread scripts/scr_kill_unit/scr_kill_unit.gml
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

@cubic-dev-ai cubic-dev-ai Bot 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.

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 17 unresolved issues from previous reviews.

Re-trigger cubic

@OH296

OH296 commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

/oc
Please, review this pull request:

Check for code quality issues of the newly added/changed code (docs/CODE_STYLE.md)
Look for potential bugs and regressions
Suggest improvements
Response style: you're the main maintainer of this codebase.

@opencode-agent

Copy link
Copy Markdown
Contributor

Here's my review as the project maintainer.


Overview

This PR removes the fixed-size 501-slot arrays and parallel age/spe/god fields in favor of dynamic per-company rosters and per-unit properties. The direction is correct, but there are several critical bugs still unresolved and some code quality concerns.


P0 — Will crash at runtime

1. obj_ini/Create_0.gml:121race is not a 2D array, will crash on any company > 0 access

race = array_create(11, 501);

This creates [501, 501, 501, ...] — each element is the integer 501, not a sub-array. race[c][i] for c=1..10 indexes an integer and throws.

scr_initialize_custom at line 1482 only replaces race[0] with a real array via _init_marine_row(0, ...). Companies 1–10 are left as bare integers.

Fix: Same pattern as the other arrays — use array_create(11, []) and let scr_initialize_custom populate them, or revert to array_create_2d. But note issue #2 first.

2. obj_ini/Create_0.gml:123-137 — Shared array references for companies 1–10

name = array_create(11, []);
role = array_create(11, []);
// ... wep1, wep2, armour, gear, mobi, TTRPG

array_create(11, []) gives all 11 rows the same empty array reference. Companies 1–10 share a single array for name, role, TTRPG, etc. Writing to name[1][i] overwrites name[2][i] through name[10][i].

scr_initialize_custom only replaces company 0's array. Companies 1–10 remain aliased.

This is the exact bug cubic flagged three reviews ago and suggested array_create_ext for.

3. objects/obj_controller/Alarm_5.gml:293-296 — Null guard after property access

var _unit = fetch_unit([c,e]);
if (_unit.god_status == 10) {       // CRASH if _unit is undefined
    if (!is_struct(_unit)) {         // guard is too late
        continue;
    }

fetch_unit returns undefined for empty slots. The is_struct check needs to come before the property access.

4. scripts/scr_add_man/scr_add_man.gml:19-77 — Writes to undefined unit on normal recruitment path

Flow for other_gear == false:

  1. Line 17: _company_slot = find_company_open_slot(...)
  2. Line 19: scr_wipe_unit(...) — clears the slot to undefined
  3. Line 20: _unit = fetch_unit(...)undefined
  4. Line 77: _unit.age = ...CRASH on undefined
  5. Line 116: _unit = new TTRPG_stats(...) — reassignment happens too late

The other_gear == true path is fine (switch blocks reassign _unit before line 77). The normal path is not.

5. scripts/scr_company_order/scr_company_order.gml:20 — Array index syntax error

function company_length(company){
    return obj_ini.TTRPG(company)
}

This calls TTRPG as a function, not indexing it as an array. Should be obj_ini.TTRPG[company].

This also means scr_ship_occupants at line 6 (for i <= company_length(co)) will crash on any ship occupant listing.


P1 — Will silently produce wrong results

6. scripts/scr_enemy_ai_d/scr_enemy_ai_d.gml:170 — Wrong property name

if (string_count("0", _unit.special) > 0) {

_unit.special (singular) doesn't exist. The field is specials (plural), used correctly everywhere else. The Warp Shadow psyker detection always fails as a result.

7. scripts/scr_random_event/scr_random_event.gml:712 — Same typo

if (_unit.role() == obj_ini.role[100][eROLE.CHAPTERMASTER] && string_count("0", _unit.special) > 0) {

Same _unit.special_unit.specials fix needed.

8. scripts/scr_kill_unit/scr_kill_unit.gml:56-61 — Gene-seed recovery uses wrong time comparison

if (unit.marine_ascension > 30 && !obj_ini.zygote && !obj_ini.doomed) {
    obj_controller.gene_seed += 1;
}
if (unit.marine_ascension > 100 && !obj_ini.doomed) {
    obj_controller.gene_seed += 1;
}

marine_ascension is now obj_controller.turn at creation. A marine created on turn 5 is forever ineligible (5 > 30 is false). Previously this checked the calendar age (in years). The intent is an elapsed-time check, so these should use obj_controller.turn - unit.marine_ascension.

9. scripts/scr_marine_struct/scr_marine_struct.gml:259 — Turn number displayed as calendar year

marine_ascension = obj_controller.turn;

Previously this stored millenium * 1000 + year (a calendar year like 41735). Now it stores a turn count like 101. The detail panel at scr_unit_detail_text.gml:52 renders "{round(age)} years old. Ascended to an Astartes in the {ascension_date} year." — which will display "101 year". Either the display needs converting, or the field needs both values.


P2 — Design & code quality

10. scripts/scr_initialize_custom/scr_initialize_custom.gml:1482-1489 — Only initializes company 0

_init_marine_row(0, ...) and TTRPG[0] = array_create(501) only set up company 0. Companies 1–10 are left with bare integers (race) or shared arrays (everything else). The deserialize at Create_0.gml:303-306 also hardcodes for _mar <= 500 with TTRPG[_coy][_mar] — which will crash on integer race and corrupt the shared arrays.

This needs to be consistent — either initialize all companies at startup or ensure the dynamic-resize path is universally reliable.

11. scripts/scr_company_order/scr_company_order.gml:122-131 — Compaction resizes arrays but other consumers don't know

The company ordering function truncates arrays to _new_length (the number of actual marines). Other consumers like scr_max_marine, scr_check_equip, scr_crusade previously iterated to 501 and may now index out of bounds. Need to verify they all use array_length() dynamically.

12. scripts/scr_chapter_managent_events/scr_chapter_managent_events.gml:276 — No struct guard

for (var i = 0; i < array_length(obj_ini.TTRPG[0]); i++) {
    scr_move_unit_info(pick.company, 0, pick.marine_number, i);
    break;

Missing is_struct(obj_ini.TTRPG[0][i]) before the move. Also this loop always breaks after the first iteration — is that intentional?


Summary

Must fix before merge:

  1. race = array_create(11, 501) → crash on any company > 0
  2. Shared [] references for name/role/wep1/wep2/armour/gear/mobi/TTRPG → data corruption across companies 1–10
  3. _unit.god_status accessed before is_struct guard in Alarm_5.gml
  4. _unit.age assignment on undefined in scr_add_man normal path
  5. TTRPG(company) instead of TTRPG[company] in company_length → crashes scr_ship_occupants

Should fix:
6-7. _unit.special_unit.specials in two files
8-9. Gene-seed elapsed-time check, marine_ascension display units

This is a substantial refactor with a lot of moving parts. The shared-array initialization and the race 1D-vs-2D issue are the most concerning because they corrupt data silently or crash immediately on any interaction with companies 1–10.

github run

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

Labels

Size: Big Type: Refactor Rewriting/restructuring code, while keeping general behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant