Skip to content

Conversation

@bibizu
Copy link
Contributor

@bibizu bibizu commented Nov 27, 2025

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

Description:

Nuke preview trajectory now calculates when the nuke becomes invulnerable to SAM defense and displays accordingly.

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:

bibizu

@bibizu bibizu requested a review from a team as a code owner November 27, 2025 06:51
@CLAassistant
Copy link

CLAassistant commented Nov 27, 2025

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 27, 2025

Walkthrough

Adds logic and rendering to NukeTrajectoryPreviewLayer to detect two indices where the bomb's targetability flips and draws the trajectory with distinct styles/colors and arc markers at those switch points. Also introduces a private field to store the untargetable segment bounds.

Changes

Cohort / File(s) Summary
Trajectory targetability visualization
src/client/graphics/layers/NukeTrajectoryPreviewLayer.ts
Adds private field untargetableSegmentBounds: [number, number] = [-1, -1]. Updates updateTrajectoryPath to scan trajectory points and compute two switch indices where targetability changes. Modifies drawTrajectoryPreview to use untargetableLineColor and targetableLineColor, draw arcs at switch indices, and conditionally stroke segments with different styles/dash patterns around those indices.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review switch-point detection in updateTrajectoryPath for off-by-one and distance-squared comparisons.
  • Verify stroke/dash/arc rendering math in drawTrajectoryPreview for correct visual alignment and state transitions.

Possibly related PRs

Suggested labels

UI/UX

Suggested reviewers

  • evanpelle
  • scottanderson

Poem

✨ A path once plain now wears two hues,
Arcs mark the moments the target rules,
Lines switch their song from safe to fraught,
A quiet map of danger, thoughtfully wrought.

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding SAM targetability visualization to the nuke preview trajectory.
Description check ✅ Passed The description is directly related to the changeset, explaining that the nuke preview trajectory now calculates and displays when the nuke becomes invulnerable to SAM defense.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between feebc6f and f9de1fd.

📒 Files selected for processing (1)
  • src/client/graphics/layers/NukeTrajectoryPreviewLayer.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/client/graphics/layers/NukeTrajectoryPreviewLayer.ts

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
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: 0

🧹 Nitpick comments (4)
src/client/graphics/layers/NukeTrajectoryPreviewLayer.ts (4)

18-18: Clarify what the two indices represent.

The field name targetableSwitchPointIndex doesn't clearly indicate what each index in the tuple represents. Consider renaming to untargetableSegmentBounds or adding a JSDoc comment explaining that [0] marks where the bomb becomes untargetable (leaves spawn range) and [1] marks where it becomes targetable again (enters target range).


215-242: Document the switch point algorithm.

The logic computes two critical boundaries but lacks explanation. The algorithm handles three trajectory segments:

  1. Near spawn (targetable by SAMs)
  2. Middle flight (untargetable - invulnerable)
  3. Near target (targetable by SAMs)

The break at line 231 handles trajectories where spawn and target ranges overlap (no untargetable segment), but this isn't obvious from the code. Add comments explaining:

  • What each index represents
  • Why the break occurs when tile is beyond spawn range AND within target range
  • That -1 means "no switch point found"

Consider adding comments like:

+    // Find two switch points where bomb transitions:
+    // [0]: leaves spawn range, enters untargetable zone
+    // [1]: enters target range, becomes targetable again
     this.targetableSwitchPointIndex = [-1, -1];
     for (let i = 0; i < this.trajectoryPoints.length; i++) {
       const tile = this.trajectoryPoints[i];
       if (this.targetableSwitchPointIndex[0] === -1) {
         if (
           this.game.euclideanDistSquared(tile, this.cachedSpawnTile) >
           targetRangeSquared
         ) {
           if (
             this.game.euclideanDistSquared(tile, targetTile) <
             targetRangeSquared
           ) {
+            // Spawn and target ranges overlap - trajectory stays targetable
             break;
           } else {
             this.targetableSwitchPointIndex[0] = i;
           }

264-271: Consider extracting color parameters as constants.

The alpha and saturation values (0.8, 0.5) are magic numbers. If these visual parameters need tuning later, extracting them as named constants would improve maintainability:

const TRAJECTORY_ALPHA = 0.8;
const UNTARGETABLE_SATURATION = 0.8;
const TARGETABLE_SATURATION = 0.5;

278-316: LGTM with minor refinement suggestions.

The rendering logic correctly visualizes the three trajectory segments with distinct styles. The arc markers at transition points provide clear visual feedback.

Minor refinements to consider:

  1. Extract magic numbers: Arc radius 4 and dash patterns [8, 4], [2, 6] could be constants
  2. Simplify state changes: The multiple beginPath(), stroke(), setLineDash() calls work correctly but make the loop harder to follow

If simplification is desired:

const ARC_RADIUS = 4;
const TARGETABLE_DASH = [8, 4];
const UNTARGETABLE_DASH = [2, 6];
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab53ee6 and feebc6f.

📒 Files selected for processing (1)
  • src/client/graphics/layers/NukeTrajectoryPreviewLayer.ts (4 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: DevelopingTom
Repo: openfrontio/OpenFrontIO PR: 1900
File: src/core/execution/SAMLauncherExecution.ts:103-111
Timestamp: 2025-08-24T11:13:08.495Z
Learning: In SAMLauncherExecution.ts, the cached target bug can only occur if: 1) SAM is not on cooldown when nuke is in range, 2) SAM goes on cooldown right after computing trajectory, 3) SAM becomes available again before nuke explodes. This is not possible with current cooldown values but the fix is still valuable for robustness.
📚 Learning: 2025-06-22T21:51:14.990Z
Learnt from: devalnor
Repo: openfrontio/OpenFrontIO PR: 1248
File: src/client/graphics/layers/TerritoryInfoLayer.ts:20-20
Timestamp: 2025-06-22T21:51:14.990Z
Learning: In TerritoryInfoLayer.ts, the highlightedTerritory field uses both null and undefined intentionally: undefined represents initial state or inactive layer (Ctrl released), while null represents active layer with no territory being highlighted at cursor position. This distinction is important for proper state change detection.

Applied to files:

  • src/client/graphics/layers/NukeTrajectoryPreviewLayer.ts
📚 Learning: 2025-08-24T11:13:08.495Z
Learnt from: DevelopingTom
Repo: openfrontio/OpenFrontIO PR: 1900
File: src/core/execution/SAMLauncherExecution.ts:103-111
Timestamp: 2025-08-24T11:13:08.495Z
Learning: In SAMLauncherExecution.ts, the cached target bug can only occur if: 1) SAM is not on cooldown when nuke is in range, 2) SAM goes on cooldown right after computing trajectory, 3) SAM becomes available again before nuke explodes. This is not possible with current cooldown values but the fix is still valuable for robustness.

Applied to files:

  • src/client/graphics/layers/NukeTrajectoryPreviewLayer.ts
📚 Learning: 2025-10-27T09:47:26.395Z
Learnt from: sambokai
Repo: openfrontio/OpenFrontIO PR: 2225
File: src/core/execution/FakeHumanExecution.ts:770-795
Timestamp: 2025-10-27T09:47:26.395Z
Learning: In src/core/execution/FakeHumanExecution.ts, the selectSteamrollStopTarget() method intentionally allows MIRV targeting when secondHighest city count is 0 (e.g., nuclear endgame scenarios where structures are destroyed). This is valid game design—"if you can afford it, you're good to go"—and should not be flagged as requiring a guard condition.

Applied to files:

  • src/client/graphics/layers/NukeTrajectoryPreviewLayer.ts

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 27, 2025
@ryanbarlow97
Copy link
Contributor

I like it but for v28 I believe we are removing all bomb invincibility so I’m not sure if this will be approved

If you want, I can assign it to you?

@bibizu
Copy link
Contributor Author

bibizu commented Nov 27, 2025

What's the argument for removing bomb invincibility?

My biggest gripe is that it would remove from what little influence you have on players on the other side of the map, and therefore helps players on the edge of the map even more than they already are.

If it's a sure, agreed upon change, you can assign it to me (I am also working on showing which SAMs will shoot down the bomb in the preview) but I believe it's a good game mechanic and would like to have some input on the discussion if possible!

@ryanbarlow97
Copy link
Contributor

What's the argument for removing bomb invincibility?

My biggest gripe is that it would remove from what little influence you have on players on the other side of the map, and therefore helps players on the edge of the map even more than they already are.

If it's a sure, agreed upon change, you can assign it to me (I am also working on showing which SAMs will shoot down the bomb in the preview) but I believe it's a good game mechanic and would like to have some input on the discussion if possible!

#2472 (comment)

@bibizu
Copy link
Contributor Author

bibizu commented Nov 29, 2025

Closing in favor for #2541

@bibizu bibizu closed this Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants