mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 10:53:31 +00:00
7f7cbba12f
## 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
151 lines
4.8 KiB
TypeScript
151 lines
4.8 KiB
TypeScript
import { Game } from "../game/Game";
|
|
import { GameMap, TileRef } from "../game/GameMap";
|
|
import { TrainStation } from "../game/TrainStation";
|
|
import { AStarRail } from "./algorithms/AStar.Rail";
|
|
import { AStarWater } from "./algorithms/AStar.Water";
|
|
import { AirPathFinder } from "./PathFinder.Air";
|
|
import {
|
|
ParabolaOptions,
|
|
ParabolaUniversalPathFinder,
|
|
} from "./PathFinder.Parabola";
|
|
import { StationPathFinder } from "./PathFinder.Station";
|
|
import { PathFinderBuilder } from "./PathFinderBuilder";
|
|
import { StepperConfig } from "./PathFinderStepper";
|
|
import { ComponentCheckTransformer } from "./transformers/ComponentCheckTransformer";
|
|
import { MiniMapTransformer } from "./transformers/MiniMapTransformer";
|
|
import { ShoreCoercingTransformer } from "./transformers/ShoreCoercingTransformer";
|
|
import { SmoothingWaterTransformer } from "./transformers/SmoothingWaterTransformer";
|
|
import { PathResult, PathStatus, SteppingPathFinder } from "./types";
|
|
|
|
/**
|
|
* Pathfinders that work with GameMap - usable in both simulation and UI layers
|
|
*/
|
|
export class UniversalPathFinding {
|
|
static Parabola(
|
|
gameMap: GameMap,
|
|
options?: ParabolaOptions,
|
|
): ParabolaUniversalPathFinder {
|
|
return new ParabolaUniversalPathFinder(gameMap, options);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Pathfinders that require Game - simulation layer only
|
|
*/
|
|
export class PathFinding {
|
|
static Water(game: Game): SteppingPathFinder<TileRef> {
|
|
const pf = game.miniWaterHPA();
|
|
const graph = game.miniWaterGraph();
|
|
|
|
if (!pf || !graph || graph.nodeCount < 100) {
|
|
return PathFinding.WaterSimple(game);
|
|
}
|
|
|
|
const miniMap = game.miniMap();
|
|
const componentCheckFn = (t: TileRef) => graph.getComponentId(t);
|
|
|
|
return PathFinderBuilder.create(pf)
|
|
.wrap((pf) => new ComponentCheckTransformer(pf, componentCheckFn))
|
|
.wrap((pf) => new SmoothingWaterTransformer(pf, miniMap))
|
|
.wrap((pf) => new ShoreCoercingTransformer(pf, miniMap))
|
|
.wrap((pf) => new MiniMapTransformer(pf, game.map(), miniMap))
|
|
.buildWithStepper(tileStepperConfig(game));
|
|
}
|
|
|
|
static WaterSimple(game: Game): SteppingPathFinder<TileRef> {
|
|
const miniMap = game.miniMap();
|
|
const pf = new AStarWater(miniMap);
|
|
|
|
return PathFinderBuilder.create(pf)
|
|
.wrap((pf) => new ShoreCoercingTransformer(pf, miniMap))
|
|
.wrap((pf) => new MiniMapTransformer(pf, game.map(), miniMap))
|
|
.buildWithStepper(tileStepperConfig(game));
|
|
}
|
|
|
|
static Rail(game: Game): SteppingPathFinder<TileRef> {
|
|
const miniMap = game.miniMap();
|
|
const pf = new AStarRail(miniMap);
|
|
|
|
return PathFinderBuilder.create(pf)
|
|
.wrap((pf) => new MiniMapTransformer(pf, game.map(), miniMap))
|
|
.buildWithStepper(tileStepperConfig(game));
|
|
}
|
|
|
|
static Stations(game: Game): SteppingPathFinder<TrainStation> {
|
|
const pf = new StationPathFinder(game);
|
|
|
|
return PathFinderBuilder.create(pf).buildWithStepper({
|
|
equals: (a, b) => a.id === b.id,
|
|
distance: (a, b) => game.manhattanDist(a.tile(), b.tile()),
|
|
});
|
|
}
|
|
|
|
static Air(game: Game): SteppingPathFinder<TileRef> {
|
|
const pf = new AirPathFinder(game);
|
|
|
|
return PathFinderBuilder.create(pf).buildWithStepper({
|
|
equals: (a, b) => a === b,
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Water pathfinder that auto-rebuilds when the water graph changes.
|
|
* Wraps SteppingPathFinder and tracks waterGraphVersion internally.
|
|
*/
|
|
export class WaterPathFinder implements SteppingPathFinder<TileRef> {
|
|
private inner: SteppingPathFinder<TileRef>;
|
|
private _waterGraphVersion: number;
|
|
private _rebuilt = false;
|
|
|
|
constructor(private game: Game) {
|
|
this.inner = PathFinding.Water(game);
|
|
this._waterGraphVersion = game.waterGraphVersion();
|
|
}
|
|
|
|
/** True if the pathfinder was rebuilt since the last call to `rebuilt`. Resets on read. */
|
|
get rebuilt(): boolean {
|
|
this.ensureFresh();
|
|
const v = this._rebuilt;
|
|
this._rebuilt = false;
|
|
return v;
|
|
}
|
|
|
|
private ensureFresh(): void {
|
|
const v = this.game.waterGraphVersion();
|
|
if (v !== this._waterGraphVersion) {
|
|
this._waterGraphVersion = v;
|
|
this.inner = PathFinding.Water(this.game);
|
|
this._rebuilt = true;
|
|
}
|
|
}
|
|
|
|
next(from: TileRef, to: TileRef, dist?: number): PathResult<TileRef> {
|
|
this.ensureFresh();
|
|
return this.inner.next(from, to, dist);
|
|
}
|
|
|
|
findPath(from: TileRef | TileRef[], to: TileRef): TileRef[] | null {
|
|
this.ensureFresh();
|
|
return this.inner.findPath(from, to);
|
|
}
|
|
|
|
invalidate(): void {
|
|
this.inner.invalidate();
|
|
}
|
|
}
|
|
|
|
function tileStepperConfig(game: Game): StepperConfig<TileRef> {
|
|
return {
|
|
equals: (a, b) => a === b,
|
|
distance: (a, b) => game.manhattanDist(a, b),
|
|
preCheck: (from, to) =>
|
|
typeof from !== "number" ||
|
|
typeof to !== "number" ||
|
|
!game.isValidRef(from) ||
|
|
!game.isValidRef(to)
|
|
? { status: PathStatus.NOT_FOUND }
|
|
: null,
|
|
};
|
|
}
|