Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/core/execution/NukeExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,17 @@ export class NukeExecution implements Execution {
// The launch tile can be overridden by the caller (e.g. MIRV warheads
// launch from the MIRV separation point, not a silo).
this.src ??= spawn;
// Nuke trajectories cannot pass over impassable terrain, just as they
// Nuke trajectories cannot pass over impassable terrain unless they are MIRV warheads, just as they
// cannot exceed the map border. Check the full parabola path before
// launching; if any tile is impassable, abort the launch.
const path = this.pathFinder.findPath(this.src, this.dst) ?? [];
for (const tile of path) {
if (this.mg.isImpassable(tile)) {
console.warn(`nuke trajectory crosses impassable terrain`);
this.active = false;
return;
if (this.nukeType !== UnitType.MIRVWarhead) {
const path = this.pathFinder.findPath(this.src, this.dst) ?? [];
for (const tile of path) {
if (this.mg.isImpassable(tile)) {
console.warn(`nuke trajectory crosses impassable terrain`);
this.active = false;
return;
}
Comment thread
TKTK123456 marked this conversation as resolved.
}
}
this.nuke = this.player.buildUnit(this.nukeType, this.src, {
Expand Down
12 changes: 12 additions & 0 deletions tests/ImpassableTerrain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@ describe("Impassable Terrain", () => {
expect(nuke.isActive()).toBe(false);
});

test("MIRV warhead not blocked by impassable terrain", () => {
player.conquer(game.ref(20, 100));
player.buildUnit(UnitType.MissileSilo, game.ref(20, 100), {});
// Target is on the right side of the wall — trajectory must cross it.
const target = game.ref(150, 100);
expect(game.isImpassable(target)).toBe(false);

const nuke = new NukeExecution(UnitType.MIRVWarhead, player, target);
game.addExecution(nuke);
executeTicks(game, 2);
expect(nuke.isActive()).toBe(true);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
});
// ── Water conversion guard ────────────────────────────────────────────

test("setWater does not convert impassable tiles", () => {
Expand Down
Loading