Skip to content

Fix Water Nukes Pathfinding 🚢 - #4975

Merged
evanpelle merged 2 commits into
mainfrom
fix-water-nuke-minimap-magnitude
Aug 12, 2026
Merged

Fix Water Nukes Pathfinding 🚢#4975
evanpelle merged 2 commits into
mainfrom
fix-water-nuke-minimap-magnitude

Conversation

@FloPinguin

Copy link
Copy Markdown
Contributor

Description:

Fixes #4760. Check the images there. Pathfinding in water-nuked areas was sometimes weird.
Performance seems to be similar.

World map, Canada to Madagascar, Africa is waternuked

PROD situation:

Screenshot 2026-08-12 171341

This PR fixes the path:

Screenshot 2026-08-12 171302

Technical

After water nukes convert minimap tiles to water, setWater() zeros the terrain byte, leaving magnitude at 0 and clearing the ocean bit. The existing full-map magnitude recomputation (step 2 of finalizeWaterChanges) never runs on the minimap, so all nuked minimap tiles get stuck with magnitude 0 permanently.

This causes two pathfinding issues:

  1. AStarWaterBounded applies a 3x cost penalty per step through magnitude < 3 tiles (cost 400 vs 100), making the pathfinder strongly avoid routing through nuked water
  2. SmoothingWaterTransformer rejects LOS shortcuts through magnitude < 2 tiles (pass 1) and < 3 tiles (pass 2), preventing path smoothing through crater areas

Additionally, existing minimap water tiles at the edge of a nuke crater retain stale pre-computed magnitudes from the terrain file. When a nuke creates a new coastline nearby, these tiles should have lower magnitude (closer to the new coast) but keep their old high values.

The fix adds step 4b in finalizeWaterChanges():

  • Ocean propagation: BFS from existing ocean minimap tiles into newly converted tiles, so nuked water connecting to the ocean is correctly marked
  • Magnitude BFS on minimap: Mirrors the full-map magnitude BFS (step 2) but runs on the minimap. Seeds from all minimap coastlines (including the new crater edges), BFS outward through water, and updates magnitudes for ALL affected minimap water tiles in the dirty box. Uses separate stamp/dist arrays to avoid conflicts with the full-map BFS.

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

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

FloPinguin

@FloPinguin FloPinguin added this to the v34 milestone Aug 12, 2026
@FloPinguin
FloPinguin requested a review from a team as a code owner August 12, 2026 15:23
@FloPinguin FloPinguin added the Bugfix Fixes a bug label Aug 12, 2026
@FloPinguin FloPinguin changed the title fix: recompute minimap magnitude and ocean after water nukes Fix Water Nukes Pathfinding 🚢 Aug 12, 2026
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

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 Plus

Run ID: 42cffb5e-5d9e-4877-bf0e-f890c7ceeea0

📥 Commits

Reviewing files that changed from the base of the PR and between 5143912 and 01ced8e.

📒 Files selected for processing (2)
  • src/core/game/WaterManager.ts
  • tests/nukes/WaterNukes.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/nukes/WaterNukes.test.ts
  • src/core/game/WaterManager.ts

Walkthrough

Water nuke finalization now propagates ocean status through connected minimap water and recomputes affected water magnitudes with bounded BFS operations. Integration tests validate coastal and interior-water results.

Changes

Water minimap updates

Layer / File(s) Summary
Minimap ocean and magnitude recalculation
src/core/game/WaterManager.ts
Water conversion propagates ocean status through connected minimap water. Bounded BFS recalculates affected magnitudes with reusable distance and visitation buffers.
Water nuke minimap validation
tests/nukes/WaterNukes.test.ts
Integration tests validate magnitude bounds, interior-water magnitudes, and ocean designation after water nukes.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WaterNuke
  participant WaterManager
  participant MinimapWater
  participant BFSBuffers
  WaterNuke->>WaterManager: finalize converted tiles
  WaterManager->>MinimapWater: propagate ocean status
  WaterManager->>BFSBuffers: recompute affected magnitudes
  BFSBuffers->>MinimapWater: update bounded water distances
Loading

Possibly related PRs

Suggested reviewers: evanpelle

Poem

Water shifts across the map,
BFS marks each connected gap.
Coastal bits now flow in line,
Tests confirm the bounds are fine.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing pathfinding after water nukes.
Description check ✅ Passed The description explains the water-nuke pathfinding problem, the minimap fix, and the added tests.
Linked Issues check ✅ Passed The changes address issue #4760 by updating minimap ocean connectivity and water magnitudes after water nukes.
Out of Scope Changes check ✅ Passed The implementation and integration tests are directly related to the water-nuke pathfinding objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/core/game/WaterManager.ts (1)

604-678: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Optional: reuse one minimap neighbour helper.

The block unrolls the four cardinal neighbours by hand three times (ocean BFS, coast seeding, magnitude BFS). The full-map path already uses the local pushNeighbors helper at Lines 222-233. A matching pushMiniNeighbors helper keeps the allocation-free style and removes many repeated branches, which makes the clipping conditions easier to check.

🤖 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/game/WaterManager.ts` around lines 604 - 678, Optionally add a local
allocation-free pushMiniNeighbors helper near the minimap processing code,
modeled on pushNeighbors, and use it for coast seeding and both minimap BFS
neighbor traversals. Preserve the existing water, coast, stamp, distance, and
seed-box clipping behavior while removing the repeated cardinal-neighbor
branches.
🤖 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/game/WaterManager.ts`:
- Around line 566-599: Update the minimap bounds in the water conversion method
around MINI_MAX_MAG so box radii use hop units: define or use MINI_MAX_MAG_DIST
as MINI_MAX_MAG * 2 for the dirty box, and use MINI_MAX_MAG_DIST * 2 for the
seed box. Preserve the existing clamping, and update the related comment near
the magnitude calculation to reference MINI_MAX_MAG_DIST * 2.

In `@tests/nukes/WaterNukes.test.ts`:
- Around line 169-196: Update tests/nukes/WaterNukes.test.ts:169-196 to assert
miniMap.isWater(mt) directly, then assert the exact expected magnitude rather
than only the 0–31 range; retain the interior-water validation. At
tests/nukes/WaterNukes.test.ts:230-270, replace guarded branches with direct
assertions for oceanMiniX >= 0, fullMap.isLand(nukeTarget), and
miniMap.isWater(nukeMini), and use the fixed target tile guaranteed by the map
data so both tests always verify the WaterManager BFS result.

---

Nitpick comments:
In `@src/core/game/WaterManager.ts`:
- Around line 604-678: Optionally add a local allocation-free pushMiniNeighbors
helper near the minimap processing code, modeled on pushNeighbors, and use it
for coast seeding and both minimap BFS neighbor traversals. Preserve the
existing water, coast, stamp, distance, and seed-box clipping behavior while
removing the repeated cardinal-neighbor branches.
🪄 Autofix

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 Plus

Run ID: 762343eb-b861-4d64-98aa-416b8f919595

📥 Commits

Reviewing files that changed from the base of the PR and between 8e1d2fd and 5143912.

📒 Files selected for processing (2)
  • src/core/game/WaterManager.ts
  • tests/nukes/WaterNukes.test.ts

Comment thread src/core/game/WaterManager.ts Outdated
Comment thread tests/nukes/WaterNukes.test.ts Outdated
@evanpelle
evanpelle merged commit c5c7d74 into main Aug 12, 2026
14 checks passed
@evanpelle
evanpelle deleted the fix-water-nuke-minimap-magnitude branch August 12, 2026 17:46
@github-project-automation github-project-automation Bot moved this from Development to Complete in OpenFront Release Management Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugfix Fixes a bug

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

Improve Water Nukes Pathfinding

2 participants