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:
FloPinguin
2026-04-09 05:56:02 +02:00
committed by GitHub
parent f3cbca059f
commit 7f7cbba12f
28 changed files with 1113 additions and 129 deletions
+11
View File
@@ -72,6 +72,7 @@ export class HostLobbyModal extends BaseModal {
@state() private startingGold: boolean = false;
@state() private startingGoldValue: number | undefined = undefined;
@state() private disableAlliances: boolean = false;
@state() private waterNukes: boolean = false;
@state() private lobbyId = "";
@state() private lobbyUrlSuffix = "";
@state() private clients: ClientInfo[] = [];
@@ -299,6 +300,10 @@ export class HostLobbyModal extends BaseModal {
labelKey: "host_modal.disable_alliances",
checked: this.disableAlliances,
},
{
labelKey: "host_modal.water_nukes",
checked: this.waterNukes,
},
],
inputCards,
},
@@ -463,6 +468,7 @@ export class HostLobbyModal extends BaseModal {
this.startingGold = false;
this.startingGoldValue = undefined;
this.disableAlliances = false;
this.waterNukes = false;
this.leaveLobbyOnClose = true;
}
@@ -543,6 +549,10 @@ export class HostLobbyModal extends BaseModal {
this.disableAlliances = checked;
this.putGameConfig();
break;
case "host_modal.water_nukes":
this.waterNukes = checked;
this.putGameConfig();
break;
default:
break;
}
@@ -803,6 +813,7 @@ export class HostLobbyModal extends BaseModal {
? Math.round(this.startingGoldValue * 1_000_000)
: null,
disableAlliances: this.disableAlliances || null,
waterNukes: this.waterNukes ? true : null,
} satisfies Partial<GameConfig>,
},
bubbles: true,
+7
View File
@@ -552,6 +552,13 @@ export class JoinLobbyModal extends BaseModal {
.value=${translateText("common.disabled")}
></lobby-config-item>`,
);
if (c.waterNukes)
cards.push(
html`<lobby-config-item
.label=${translateText("public_game_modifier.water_nukes_label")}
.value=${translateText("common.enabled")}
></lobby-config-item>`,
);
if ((isTeam && !c.donateGold) || (!isTeam && c.donateGold))
cards.push(
html`<lobby-config-item
+12
View File
@@ -58,6 +58,7 @@ const DEFAULT_OPTIONS = {
startingGoldValue: undefined as number | undefined,
disabledUnits: [] as UnitType[],
disableAlliances: false,
waterNukes: false,
} as const;
@customElement("single-player-modal")
@@ -93,6 +94,7 @@ export class SinglePlayerModal extends BaseModal {
...DEFAULT_OPTIONS.disabledUnits,
];
@state() private disableAlliances: boolean = DEFAULT_OPTIONS.disableAlliances;
@state() private waterNukes: boolean = DEFAULT_OPTIONS.waterNukes;
private mapLoader = terrainMapFileLoader;
@@ -313,6 +315,10 @@ export class SinglePlayerModal extends BaseModal {
labelKey: "single_modal.disable_alliances",
checked: this.disableAlliances,
},
{
labelKey: "single_modal.water_nukes",
checked: this.waterNukes,
},
],
inputCards,
},
@@ -384,6 +390,7 @@ export class SinglePlayerModal extends BaseModal {
this.goldMultiplier !== DEFAULT_OPTIONS.goldMultiplier ||
this.startingGold !== DEFAULT_OPTIONS.startingGold ||
this.disableAlliances !== DEFAULT_OPTIONS.disableAlliances ||
this.waterNukes !== DEFAULT_OPTIONS.waterNukes ||
this.disabledUnits.length > 0
);
}
@@ -411,6 +418,7 @@ export class SinglePlayerModal extends BaseModal {
this.startingGold = DEFAULT_OPTIONS.startingGold;
this.startingGoldValue = DEFAULT_OPTIONS.startingGoldValue;
this.disableAlliances = DEFAULT_OPTIONS.disableAlliances;
this.waterNukes = DEFAULT_OPTIONS.waterNukes;
}
protected onOpen(): void {
@@ -493,6 +501,9 @@ export class SinglePlayerModal extends BaseModal {
case "single_modal.disable_alliances":
this.disableAlliances = checked;
break;
case "single_modal.water_nukes":
this.waterNukes = checked;
break;
default:
break;
}
@@ -700,6 +711,7 @@ export class SinglePlayerModal extends BaseModal {
}
: {}),
...(this.disableAlliances ? { disableAlliances: true } : {}),
...(this.waterNukes ? { waterNukes: true } : {}),
},
lobbyCreatedAt: Date.now(), // ms; server should be authoritative in MP
},
+6
View File
@@ -210,6 +210,12 @@ export function getActiveModifiers(
badgeKey: "public_game_modifier.peace_time",
});
}
if (modifiers.isWaterNukes) {
result.push({
labelKey: "public_game_modifier.water_nukes_label",
badgeKey: "public_game_modifier.water_nukes",
});
}
return result;
}
@@ -22,6 +22,33 @@ export class TerrainLayer implements Layer {
tick() {
if (this.config.theme() !== this.theme) {
this.redraw();
return;
}
// Repaint terrain for tiles whose terrain changed (e.g. nuke
// turning land to water).
const updatedTiles = this.game.recentlyUpdatedTerrainTiles();
if (updatedTiles.length > 0) {
let dirty = false;
for (const tile of updatedTiles) {
const terrainColor = this.theme.terrainColor(this.game, tile);
const offset = tile * 4;
const r = terrainColor.rgba.r;
const g = terrainColor.rgba.g;
const b = terrainColor.rgba.b;
if (
this.imageData.data[offset] !== r ||
this.imageData.data[offset + 1] !== g ||
this.imageData.data[offset + 2] !== b
) {
this.imageData.data[offset] = r;
this.imageData.data[offset + 1] = g;
this.imageData.data[offset + 2] = b;
dirty = true;
}
}
if (dirty) {
this.context.putImageData(this.imageData, 0, 0);
}
}
}
+8 -1
View File
@@ -81,7 +81,14 @@ export class TerritoryLayer implements Layer {
this.spawnHighlight();
}
this.game.recentlyUpdatedTiles().forEach((t) => this.enqueueTile(t));
this.game.recentlyUpdatedTiles().forEach((t) => {
this.enqueueTile(t);
// Immediately clear territory overlay for water tiles so old
// borders/territory don't persist visually (e.g. after nuke turns land to water)
if (this.game.isWater(t)) {
this.clearTile(t);
}
});
const updates = this.game.updatesSinceLastTick();
const unitUpdates = updates !== null ? updates[GameUpdateType.Unit] : [];
unitUpdates.forEach((update) => {