mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-05 03:12:04 +00:00
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
This commit is contained in:
@@ -283,6 +283,9 @@ export class AttackExecution implements Execution {
|
||||
if (this.mg.owner(tileToConquer) !== this.target || !onBorder) {
|
||||
continue;
|
||||
}
|
||||
if (!this.mg.isLand(tileToConquer)) {
|
||||
continue;
|
||||
}
|
||||
this.addNeighbors(tileToConquer);
|
||||
const { attackerTroopLoss, defenderTroopLoss, tilesPerTickUsed } = this.mg
|
||||
.config()
|
||||
|
||||
@@ -63,10 +63,60 @@ export class NukeExecution implements Execution {
|
||||
const rand = new PseudoRandom(this.mg.ticks());
|
||||
const inner2 = magnitude.inner * magnitude.inner;
|
||||
const outer2 = magnitude.outer * magnitude.outer;
|
||||
this.tilesToDestroyCache = this.mg.bfs(this.dst, (_, n: TileRef) => {
|
||||
const d2 = this.mg?.euclideanDistSquared(this.dst, n) ?? 0;
|
||||
return d2 <= outer2 && (d2 <= inner2 || rand.chance(2));
|
||||
});
|
||||
|
||||
if (this.mg.config().waterNukes()) {
|
||||
// Smooth irregular boundary for water nukes.
|
||||
// Generate random radii at angular samples, then smooth them so the
|
||||
// boundary undulates gently instead of creating spiky flower shapes.
|
||||
// This avoids scattered land pixels that players would have to boat
|
||||
// to individually in order to reclaim.
|
||||
const NUM_SAMPLES = 16;
|
||||
const radiiSq: number[] = new Array(NUM_SAMPLES);
|
||||
for (let i = 0; i < NUM_SAMPLES; i++) {
|
||||
radiiSq[i] = rand.nextFloat(inner2, outer2);
|
||||
}
|
||||
// Smooth the ring: 1 light pass (60% original, 20% each neighbour)
|
||||
const prev = [...radiiSq];
|
||||
for (let i = 0; i < NUM_SAMPLES; i++) {
|
||||
const l = (i - 1 + NUM_SAMPLES) % NUM_SAMPLES;
|
||||
const r = (i + 1) % NUM_SAMPLES;
|
||||
radiiSq[i] = prev[i] * 0.6 + prev[l] * 0.2 + prev[r] * 0.2;
|
||||
}
|
||||
|
||||
const cx = this.mg.x(this.dst);
|
||||
const cy = this.mg.y(this.dst);
|
||||
const outer = magnitude.outer;
|
||||
|
||||
const result = new Set<TileRef>();
|
||||
const x0 = Math.max(0, cx - outer);
|
||||
const y0 = Math.max(0, cy - outer);
|
||||
const x1 = Math.min(this.mg.width() - 1, cx + outer);
|
||||
const y1 = Math.min(this.mg.height() - 1, cy + outer);
|
||||
for (let py = y0; py <= y1; py++) {
|
||||
for (let px = x0; px <= x1; px++) {
|
||||
const dx = px - cx;
|
||||
const dy = py - cy;
|
||||
const d2 = dx * dx + dy * dy;
|
||||
if (d2 > outer2) continue;
|
||||
if (d2 > inner2) {
|
||||
const angle = Math.atan2(dy, dx) + Math.PI; // [0, 2π]
|
||||
const t = (angle / (2 * Math.PI)) * NUM_SAMPLES;
|
||||
const i0 = Math.floor(t) % NUM_SAMPLES;
|
||||
const i1 = (i0 + 1) % NUM_SAMPLES;
|
||||
const frac = t - Math.floor(t);
|
||||
const threshold = radiiSq[i0] * (1 - frac) + radiiSq[i1] * frac;
|
||||
if (d2 > threshold) continue;
|
||||
}
|
||||
result.add(this.mg.ref(px, py));
|
||||
}
|
||||
}
|
||||
this.tilesToDestroyCache = result;
|
||||
} else {
|
||||
this.tilesToDestroyCache = this.mg.bfs(this.dst, (_, n: TileRef) => {
|
||||
const d2 = this.mg?.euclideanDistSquared(this.dst, n) ?? 0;
|
||||
return d2 <= outer2 && (d2 <= inner2 || rand.chance(2));
|
||||
});
|
||||
}
|
||||
return this.tilesToDestroyCache;
|
||||
}
|
||||
|
||||
@@ -266,8 +316,9 @@ export class NukeExecution implements Execution {
|
||||
tilesPerPlayers.set(owner, (tilesPerPlayers.get(owner) ?? 0) + 1);
|
||||
}
|
||||
|
||||
// Queue land tiles for batched water conversion
|
||||
if (mg.isLand(tile)) {
|
||||
mg.setFallout(tile, true);
|
||||
mg.queueWaterConversion(tile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ import {
|
||||
UnitType,
|
||||
} from "../game/Game";
|
||||
import { TileRef } from "../game/GameMap";
|
||||
import { PathFinding } from "../pathfinding/PathFinder";
|
||||
import { PathStatus, SteppingPathFinder } from "../pathfinding/types";
|
||||
import { WaterPathFinder } from "../pathfinding/PathFinder";
|
||||
import { PathStatus } from "../pathfinding/types";
|
||||
import { findClosestBy } from "../Util";
|
||||
|
||||
export class TradeShipExecution implements Execution {
|
||||
@@ -17,7 +17,7 @@ export class TradeShipExecution implements Execution {
|
||||
private mg: Game;
|
||||
private tradeShip: Unit | undefined;
|
||||
private wasCaptured = false;
|
||||
private pathFinder: SteppingPathFinder<TileRef>;
|
||||
private pathFinder: WaterPathFinder;
|
||||
private tilesTraveled = 0;
|
||||
private motionPlanId = 1;
|
||||
private motionPlanDst: TileRef | null = null;
|
||||
@@ -30,10 +30,14 @@ export class TradeShipExecution implements Execution {
|
||||
|
||||
init(mg: Game, ticks: number): void {
|
||||
this.mg = mg;
|
||||
this.pathFinder = PathFinding.Water(mg);
|
||||
this.pathFinder = new WaterPathFinder(mg);
|
||||
}
|
||||
|
||||
tick(ticks: number): void {
|
||||
if (this.pathFinder.rebuilt) {
|
||||
this.motionPlanDst = null; // Force motion plan re-recording
|
||||
}
|
||||
|
||||
if (this.tradeShip === undefined) {
|
||||
const spawn = this.origOwner.canBuild(
|
||||
UnitType.TradeShip,
|
||||
|
||||
@@ -12,8 +12,8 @@ import {
|
||||
import { TileRef } from "../game/GameMap";
|
||||
import { MotionPlanRecord } from "../game/MotionPlans";
|
||||
import { targetTransportTile } from "../game/TransportShipUtils";
|
||||
import { PathFinding } from "../pathfinding/PathFinder";
|
||||
import { PathStatus, SteppingPathFinder } from "../pathfinding/types";
|
||||
import { WaterPathFinder } from "../pathfinding/PathFinder";
|
||||
import { PathStatus } from "../pathfinding/types";
|
||||
import { AttackExecution } from "./AttackExecution";
|
||||
|
||||
const malusForRetreat = 25;
|
||||
@@ -27,7 +27,7 @@ export class TransportShipExecution implements Execution {
|
||||
|
||||
private mg: Game;
|
||||
private target: Player | TerraNullius;
|
||||
private pathFinder: SteppingPathFinder<TileRef>;
|
||||
private pathFinder: WaterPathFinder;
|
||||
|
||||
private dst: TileRef | null;
|
||||
private src: TileRef | null;
|
||||
@@ -60,7 +60,7 @@ export class TransportShipExecution implements Execution {
|
||||
this.lastMove = ticks;
|
||||
this.mg = mg;
|
||||
this.target = mg.owner(this.ref);
|
||||
this.pathFinder = PathFinding.Water(mg);
|
||||
this.pathFinder = new WaterPathFinder(mg);
|
||||
|
||||
if (
|
||||
this.attacker.unitCount(UnitType.TransportShip) >=
|
||||
@@ -186,6 +186,21 @@ export class TransportShipExecution implements Execution {
|
||||
this.originalOwner = boatOwner; // for when this owner disconnects too
|
||||
}
|
||||
|
||||
if (this.pathFinder.rebuilt) {
|
||||
this.motionPlanDst = null; // Force motion plan re-recording
|
||||
}
|
||||
|
||||
// Auto-retreat if destination was destroyed by nuke (turned to water)
|
||||
// Checked every tick (not just on graph rebuild) because graph rebuilds
|
||||
// are throttled and the tile may already be water before the version bumps.
|
||||
if (this.dst !== null && this.mg.isWater(this.dst)) {
|
||||
if (!this.boat.retreating()) {
|
||||
this.boat.orderBoatRetreat();
|
||||
}
|
||||
// Reset cached retreat destination so it's recomputed from current position
|
||||
this.retreatDst = null;
|
||||
}
|
||||
|
||||
if (this.boat.retreating()) {
|
||||
// Resolve retreat destination once, based on current boat location when retreat begins.
|
||||
this.retreatDst ??= this.attacker.bestTransportShipSpawn(
|
||||
|
||||
@@ -8,8 +8,8 @@ import {
|
||||
UnitType,
|
||||
} from "../game/Game";
|
||||
import { TileRef } from "../game/GameMap";
|
||||
import { PathFinding } from "../pathfinding/PathFinder";
|
||||
import { PathStatus, SteppingPathFinder } from "../pathfinding/types";
|
||||
import { WaterPathFinder } from "../pathfinding/PathFinder";
|
||||
import { PathStatus } from "../pathfinding/types";
|
||||
import { PseudoRandom } from "../PseudoRandom";
|
||||
import { ShellExecution } from "./ShellExecution";
|
||||
|
||||
@@ -17,7 +17,7 @@ export class WarshipExecution implements Execution {
|
||||
private random: PseudoRandom;
|
||||
private warship: Unit;
|
||||
private mg: Game;
|
||||
private pathfinder: SteppingPathFinder<TileRef>;
|
||||
private pathfinder: WaterPathFinder;
|
||||
private lastShellAttack = 0;
|
||||
private alreadySentShell = new Set<Unit>();
|
||||
|
||||
@@ -27,7 +27,7 @@ export class WarshipExecution implements Execution {
|
||||
|
||||
init(mg: Game, ticks: number): void {
|
||||
this.mg = mg;
|
||||
this.pathfinder = PathFinding.Water(mg);
|
||||
this.pathfinder = new WaterPathFinder(mg);
|
||||
this.random = new PseudoRandom(mg.ticks());
|
||||
if (isUnit(this.input)) {
|
||||
this.warship = this.input;
|
||||
|
||||
Reference in New Issue
Block a user