Skip to content

fix: remove double x() dereference in MIRV separation point calc#3940

Merged
evanpelle merged 1 commit into
openfrontio:mainfrom
berkelmali:fix/mirv-double-x-dereference
May 17, 2026
Merged

fix: remove double x() dereference in MIRV separation point calc#3940
evanpelle merged 1 commit into
openfrontio:mainfrom
berkelmali:fix/mirv-double-x-dereference

Conversation

@berkelmali
Copy link
Copy Markdown
Contributor

@berkelmali berkelmali commented May 16, 2026

mg.x() takes a TileRef and returns a number (x coordinate). The code was calling mg.x(mg.x(tile)), feeding the numeric result back into x() which expects a TileRef. This produces an incorrect midpoint for MIRV warhead separation, causing warheads to spread from a wrong position on the map.

If this PR fixes an issue, link it below. If not, delete these two lines.
Resolves #(issue number)

Description:

Describe the PR.

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory
  • I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced

Please put your Discord username so you can be contacted if a bug or regression is found:

barfires

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 16, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8787eb3a-68ac-4503-862e-d8aab1b13f82

📥 Commits

Reviewing files that changed from the base of the PR and between e31b2e3 and 5b98b27.

📒 Files selected for processing (1)
  • src/core/execution/MIRVExecution.ts
✅ Files skipped from review due to trivial changes (1)
  • src/core/execution/MIRVExecution.ts

Walkthrough

This PR fixes a calculation error in MIRVExecution.tick: the separation midpoint X was computed with a duplicate map-grid transform; the extra this.mg.x(...) call was removed so the nuke tile’s X is used directly before averaging with the destination X.

Changes

MIRV Separation

Layer / File(s) Summary
Midpoint X calculation fix
src/core/execution/MIRVExecution.ts
Line 85 corrects the separation destination X coordinate by computing this.mg.x(this.nuke.tile()) directly instead of nesting the call twice, eliminating the duplicate transformation.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

Double transforms caused a twist,
Two calls became just one—
MIRV midpoints no longer missed,
Separation aim is done. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main fix: removing a double x() dereference in MIRV separation point calculation.
Description check ✅ Passed The description explains the bug (double x() dereference causing incorrect MIRV warhead separation) and relates directly to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/core/execution/MIRVExecution.ts`:
- Line 85: Add a deterministic unit test for MirvExecution.tick() that
constructs a MirvExecution with a controllable map/manager mock (mock mg.x to
return known integers for the dst and nuke.tile()), set dst and nuke.tile()
values so the midpoint is non-trivial, call MirvExecution.tick(), and assert the
computed separation midpoint X equals floor((x(dst) + x(nuke.tile())) / 2)
(i.e., Math.floor((dstX + nukeTileX) / 2)). Target the MirvExecution class and
its tick() behavior and assert the exact numeric midpoint to prevent regressions
in the single-dereference midpoint calculation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6170a842-6079-4a44-b274-a96da8c63f33

📥 Commits

Reviewing files that changed from the base of the PR and between b813792 and e31b2e3.

📒 Files selected for processing (1)
  • src/core/execution/MIRVExecution.ts

this.mg.stats().bombLaunch(this.player, this.targetPlayer, UnitType.MIRV);
const x = Math.floor(
(this.mg.x(this.dst) + this.mg.x(this.mg.x(this.nuke.tile()))) / 2,
(this.mg.x(this.dst) + this.mg.x(this.nuke.tile())) / 2,
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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add a regression test for the midpoint X fix.

Line 85 fixes the bug, but this src/core/ logic change ships without a test in the provided diff. Please add a deterministic test that exercises MirvExecution.tick() and asserts the separation midpoint uses a single dereference (x = floor((x(dst)+x(nukeTile))/2)), so this regression does not return.

As per coding guidelines, “All changes to src/core/ must include tests”.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core/execution/MIRVExecution.ts` at line 85, Add a deterministic unit
test for MirvExecution.tick() that constructs a MirvExecution with a
controllable map/manager mock (mock mg.x to return known integers for the dst
and nuke.tile()), set dst and nuke.tile() values so the midpoint is non-trivial,
call MirvExecution.tick(), and assert the computed separation midpoint X equals
floor((x(dst) + x(nuke.tile())) / 2) (i.e., Math.floor((dstX + nukeTileX) / 2)).
Target the MirvExecution class and its tick() behavior and assert the exact
numeric midpoint to prevent regressions in the single-dereference midpoint
calculation.

@github-project-automation github-project-automation Bot moved this from Triage to Development in OpenFront Release Management May 16, 2026
mg.x() takes a TileRef and returns a number (x coordinate). The code
was calling mg.x(mg.x(tile)), feeding the numeric result back into
x() which expects a TileRef. This produces an incorrect midpoint
for MIRV warhead separation, causing warheads to spread from a wrong
position on the map.
@berkelmali berkelmali force-pushed the fix/mirv-double-x-dereference branch from e31b2e3 to 5b98b27 Compare May 16, 2026 14:18
@evanpelle evanpelle added this to the v32 milestone May 17, 2026
@evanpelle evanpelle merged commit 2e17fb5 into openfrontio:main May 17, 2026
9 of 12 checks passed
@github-project-automation github-project-automation Bot moved this from Development to Complete in OpenFront Release Management May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

2 participants