Skip to content

refactor: Remove all remaining unit parallel arrays - #1414

Merged
OH296 merged 93 commits into
Adeptus-Dominus:mainfrom
OH296:reove_final_paras
Aug 7, 2026
Merged

refactor: Remove all remaining unit parallel arrays#1414
OH296 merged 93 commits into
Adeptus-Dominus:mainfrom
OH296:reove_final_paras

Conversation

@OH296

@OH296 OH296 commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Summary by cubic

Finishes the migration to struct-based units and roles by removing the last parallel arrays and name checks. Boarding, events, shaders, and saves now pass real unit structs; artifacts persist bearer by unit UID and safely re-link on load.

  • Refactors

    • Deleted legacy scripts: scr_master_loc, scr_move_unit_info, scr_bionics_count, scr_marine_count; Chapter Master now via ChapterMaster; location checks use .get_struct().is_at_location(...).
    • Replaced remaining parallel arrays (role/race/wep/armour/gear/mobi/age/specialty/god) with struct fields; loops use company_length(...) and fetch_unit(...); removed obj_ini.name usage.
    • Standardized role access with role_compare(...), active_roles(), and get_department_head(...); applied across UI, dialogue, AI, management, fleets, boarding, combat, and apothecarion/librarium.
    • Creation/UI read from player_role_data; added default_role_data, setup_default_gears, and global.role_data_keys; Librarian auto-hidden if Psyker Intolerant; custom role names edit player_role_data.
    • Centralized death and movement: _unit.kill(...), _unit.move_to_company(...), _unit.update_role(...); used in ship loss, crusade, garrison, inspections, events, perils, promotions, and transfers.
    • Artifacts: bearer saved as unit UID in ArtifactStruct; restored via fetch_unit_uid(...); gossip/events inspect equipment structs.
    • Squads/UI: bulk equip respects squad coherency; promotions/moves use helpers; added tally_marines(); UnitGroup gained push(...), tally_attr(...), and batch-kill.
    • Events/Missions: festival/event targets use -1; Mechanicus bionics mission counts via UnitGroup.tally_attr("bionics").
    • Boarding: replaced board_* arrays with obj_p_ship.board_marine and obj_p_assra.occupants; flows pass struct refs.
    • Data/cleanups: unit_stats.json base_group fixed to "eldar"; livery shader uses active_roles() with bounds checks to prevent OOB; minor indexing fixes and lingering legacy removals.
  • Migration

    • Build creation/management UIs from player_role_data (available_to_player); update role radios and livery preview.
    • Replace movement/location/killing helpers with _unit.move_to_company(...), ChapterMaster.is_at_location(...), and _unit.kill(...).
    • Remove any name == "" checks and array reads; rely on fetch_unit(...), company_length(...), active_roles(), and role_compare(...).
    • Use UnitGroup.tally_attr(...) for mission tallies; use obj_p_ship.board_marine and obj_p_assra.occupants for boarding; use -1 sentinel for unset event targets.

Written for commit cbc2c05. Summary will update on new commits.

Review in cubic

@github-actions github-actions Bot added Area: JSON Changes to external JSON files or their under-the-hood functionality Size: Warning labels Aug 2, 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 across 11 files (changes from recent commits).

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

Re-trigger cubic

Comment thread scripts/scr_kill_unit/scr_kill_unit.gml
Comment thread objects/obj_p_assra/Step_0.gml Outdated
Comment thread objects/obj_p_assra/Step_0.gml Outdated
Comment thread scripts/scr_boarding_actions/scr_boarding_actions.gml
Comment thread scripts/scr_company_order/scr_company_order.gml
Comment thread objects/obj_p_assra/Alarm_0.gml Outdated
Comment thread objects/obj_p_assra/Alarm_0.gml Outdated
@OH296

OH296 commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@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 8 files (changes from recent commits).

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

Re-trigger cubic

Comment thread scripts/scr_boarding_actions/scr_boarding_actions.gml Outdated
Comment thread scripts/scr_boarding_actions/scr_boarding_actions.gml Outdated
Comment thread scripts/scr_kill_unit/scr_kill_unit.gml
Comment thread scripts/scr_boarding_actions/scr_boarding_actions.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 2 files (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 38 unresolved issues from previous reviews.

Re-trigger cubic

@OH296

OH296 commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@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 11 files (changes from recent commits).

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

Re-trigger cubic

Comment thread objects/obj_ini/Create_0.gml
Comment thread objects/obj_ini/Create_0.gml
Comment thread scripts/ArtifactStruct/ArtifactStruct.gml
Comment thread scripts/ArtifactStruct/ArtifactStruct.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 40 unresolved issues from previous reviews.

Re-trigger cubic

@opencode-agent

opencode-agent Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Here's where we stand. I was verifying the chaos-meeting force scan because there are two copies of the same logic, and both have unsafe derefs:

What we found

  1. scr_enemy_ai_e.gml:745-768 (chaos_meeting branch) — at line 748 _unit.planet_location and 749 _unit.is_dreadnought() are dereferenced with no is_struct(_unit) guard. fetch_unit returns undefined for any dead/empty slot (common after save/load where undefined fills persist, scripts/...deserialize fills dead slots with undefined). So any empty slot crashes the whole scan. Also line 748 is computed every iteration even though it's only used later, and master_present is only detected at co==0 && i==0 (line 763).

  2. obj_ncombat/Alarm_7.gml:53-84 — the same duplicated scan after cs_meeting battles. This copy has a partial guardrail: it guards the chapter-master fetch (is_struct(_fetched_chaos), line 58), but the loop body still derefs _unit.location_string, _unit.planet_location, _unit.is_dreadnought() at lines 67-74 with no per-_unit guard. Same undefined crash is reachable.

Next steps offered

  • Add an if (!is_struct(_unit)) continue; guard at the top of both loops.
  • Fix the wasteful _is_at_chaos_meeting precompute + master_present detection (currently only [0,0]; a CM elsewhere is missed).
  • Optionally unify the two copies (the Alarm_7.gml copy is near-identical to scr_enemy_ai_e's) to avoid drift.

Nothing has been edited yet — this was verification only. Want me to apply the guardrail fix to both locations now?

github run

@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.

1 issue found across 4 files (changes from recent commits).

Confidence score: 2/5

  • In scripts/scr_UnitGroup/scr_UnitGroup.gml (kill_percent), the loop direction was changed to backward but the chapter-master skip still increments i, which can drive the index past valid bounds before _kill_numb is reached; this risks out-of-range access or incorrect unit removal when kill_percent < 100 — align the skip step with backward iteration (or add explicit bounds guards) and retest partial-kill paths.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="scripts/scr_UnitGroup/scr_UnitGroup.gml">

<violation number="1" location="scripts/scr_UnitGroup/scr_UnitGroup.gml:180">
P1: kill_percent now iterates backward but the chapter-master skip still increments i, so when kill_percent < 100 and the chapter master is reached before _kill_numb is met, i advances up past the array end (or back over already-deleted slots), producing an out-of-bounds unit read and a crash on `_unit.role()`. Make the skip decrement: `i--; continue;` (or only skip when i > 0).</violation>
</file>

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

Re-trigger cubic

var _killed = 0;
var i = 0;
while (_killed < _kill_numb && i < number()) {
var i = number() - 1;

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.

P1: kill_percent now iterates backward but the chapter-master skip still increments i, so when kill_percent < 100 and the chapter master is reached before _kill_numb is met, i advances up past the array end (or back over already-deleted slots), producing an out-of-bounds unit read and a crash on _unit.role(). Make the skip decrement: i--; continue; (or only skip when i > 0).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scripts/scr_UnitGroup/scr_UnitGroup.gml, line 180:

<comment>kill_percent now iterates backward but the chapter-master skip still increments i, so when kill_percent < 100 and the chapter master is reached before _kill_numb is met, i advances up past the array end (or back over already-deleted slots), producing an out-of-bounds unit read and a crash on `_unit.role()`. Make the skip decrement: `i--; continue;` (or only skip when i > 0).</comment>

<file context>
@@ -166,19 +167,26 @@ function UnitGroup(units = []) constructor {
         var _killed = 0;
-        var i = 0;
-        while (_killed < _kill_numb && i < number()) {
+        var i = number() - 1;
+        while (_killed < _kill_numb && i >= 0) {
             var _unit = units[i];
</file context>

Comment thread scripts/ArtifactStruct/ArtifactStruct.gml Outdated
Comment thread scripts/scr_complex_colour_kit/scr_complex_colour_kit.gml Outdated
Comment thread scripts/scr_UnitGroup/scr_UnitGroup.gml
OH296 and others added 2 commits August 7, 2026 15:26
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
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 39 unresolved issues from previous reviews.

Re-trigger cubic

@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 2 files (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 39 unresolved issues from previous reviews.

Re-trigger cubic

@OH296
OH296 merged commit 34409de into Adeptus-Dominus:main Aug 7, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: JSON Changes to external JSON files or their under-the-hood functionality Size: Warning Type: Docs Changes to documentation files Type: Refactor Rewriting/restructuring code, while keeping general behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant