Files
FloPinguin 7f7cbba12f Water-Nukes 💧 (#3604)
## Description:

Adds a new `waterNukes` game config option that causes nuclear
detonations to convert land tiles into water instead of just leaving
fallout. When enabled, nuked land tiles are batched and converted to
water each tick, with full terrain metadata updates including:

- Ocean bit propagation from adjacent ocean tiles (BFS flood fill)
- Magnitude recomputation via BFS from remaining coastlines
- Shoreline bit fix-up in a 2-ring neighborhood around converted tiles
- Minimap terrain sync (majority-rule downsampling)
- Throttled water navigation graph rebuild (every 20 ticks) for ship
pathfinding
- Ship executions detect graph rebuilds and refresh their pathfinders
- TransportShips auto-retreat if their destination becomes water
- Water nuke craters use a smoothed angular noise ring with a
bounding-box scan instead of the regular per-tile random coin flip with
BFS, producing clean blob-shaped craters without scattered land pixels
that players would have to boat to individually

The `TerrainLayer` now incrementally repaints tiles that changed terrain
type, and tile update packets encode the terrain byte alongside tile
state so clients can reflect water conversions in real time.

When `waterNukes` is disabled, behavior is unchanged (fallout only).

Includes a new test suite (WaterNukes.test.ts) covering the conversion
pipeline, ocean propagation, magnitude recalculation, shoreline updates,
and minimap sync.

Also adds a new public game modifier for the special rotation.

### The only problem
A bit of lag on impact. But otherwise it works great and is fun. Maybe
needs some followup improvements if it gets merged.
I think its very cool in baikal / four islands team games. Chip away the
territory of your opponents.
Its also fun to turn The Box / Alps into a water map (its actually
possible to boat-trade then)

### Media

Video does not show the updated craters


https://github.com/user-attachments/assets/aed8bf08-0e94-4484-b997-4de11ae313d9

Updated craters (no tiny islands after impact):

<img width="1920" height="1080" alt="image"
src="https://github.com/user-attachments/assets/e896870b-bc9d-493d-8bc8-b3a5427d69d3"
/>

<img width="1472" height="920" alt="image"
src="https://github.com/user-attachments/assets/677065aa-0159-48cd-af44-a91b0f57adfc"
/>

<img width="1296" height="892" alt="image"
src="https://github.com/user-attachments/assets/886ffaba-541f-4e46-97c6-ce963f632fe0"
/>

## Please complete the following:

- [X] I have added screenshots for all UI updates
- [X] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [X] I have added relevant tests to the test directory
- [X] 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:

FloPinguin
2026-04-08 20:56:02 -07:00
..
2026-01-08 13:34:18 -08:00
2026-04-08 20:56:02 -07:00

Pathfinding Tests

This directory contains benchmarking tools, scenario generators, and an interactive playground for testing and optimizing pathfinding algorithms in OpenFrontIO.

TLDR

npx tsx tests/pathfinding/benchmark/run.ts --synthetic --all
npx tsx tests/pathfinding/playground/server.ts

Directory Structure

tests/pathfinding/
├── benchmark.ts          # Benchmarking tool
├── scenarios/            # Scenarios for benchmarks
│   ├── default.ts        # Hand-picked scenario
│   └── synthetic/        # Auto-generated synthetic scenarios
└── playground/           # Interactive web-based visualization

Available algorithms

  • NavSat - future implementation - NavigationSatellite (HPA*)
  • PF.Mini - current implementation - PathFinder.Mini (A*)

Benchmarking

Running a Single Scenario

# Run default scenario with default adapter (NavSat)
npx tsx tests/pathfinding/benchmark/run.ts

# Run specific scenario
npx tsx tests/pathfinding/benchmark/run.ts default

# Run with specific adapter
npx tsx tests/pathfinding/benchmark/run.ts default legacy

Running Synthetic Scenarios

Synthetic scenarios are auto-generated from maps with random port selections and routes.

# Run single synthetic scenario
npx tsx tests/pathfinding/benchmark/run.ts --synthetic iceland

# Run single synthetic scenario with specific adapter
npx tsx tests/pathfinding/benchmark/run.ts --synthetic iceland legacy

# Run ALL synthetic scenarios (comprehensive benchmark)
npx tsx tests/pathfinding/benchmark/run.ts --synthetic --all

# Run all with specific adapter
npx tsx tests/pathfinding/benchmark/run.ts --synthetic --all legacy

Benchmark Metrics

The benchmark measures three key metrics:

  1. Initialization Time - How long it takes to preprocess the map
  2. Path Distance - Total distance across all routes (quality metric)
  3. Pathfinding Time - How long it takes to compute paths (performance metric)

Example Output

================================================================================
METRIC 1: INITIALIZATION TIME
================================================================================

Initialization time: 45.32ms

================================================================================
METRIC 2: PATH DISTANCE
================================================================================

Route                                    Path Length
Miami → Boston                           346 tiles
Miami → Houston                          212 tiles
...

Total distance: 52432 tiles
Routes completed: 22 / 22

================================================================================
METRIC 3: PATHFINDING TIME
================================================================================

Route                                    Time
Miami → Boston                           2.45ms
Miami → Houston                          1.82ms
...

Total time: 156.34ms
Average time: 7.11ms
Routes benchmarked: 22 / 22

================================================================================
SUMMARY
================================================================================

Adapter: default
Scenario: default

Scores:
  Initialization: 45.32ms
  Pathfinding: 156.34ms
  Distance: 52432 tiles

Generating Scenarios

Generate Synthetic Scenarios

Synthetic scenarios are generated by:

  1. Finding all water shoreline tiles on a map
  2. Randomly selecting 200 ports
  3. Creating 1000 routes connecting nearby ports
# Generate scenario for a single map
npx tsx tests/pathfinding/benchmark/generate.ts iceland

# Generate scenarios for all maps
npx tsx tests/pathfinding/benchmark/generate.ts --all

# Force overwrite existing scenarios
npx tsx tests/pathfinding/benchmark/generate.ts iceland --force
npx tsx tests/pathfinding/benchmark/generate.ts --all --force

Interactive Playground

The playground provides a web-based UI for visualizing pathfinding results, comparing algorithms, and debugging.

Starting the Playground

# Start with path caching enabled (default)
npx tsx tests/pathfinding/playground/server.ts

# Start without path caching (to measure uncached performance)
npx tsx tests/pathfinding/playground/server.ts --no-cache

Then open http://localhost:5555 in your browser.