Fix nuke cancellation on alliance to use blast radius

cancelNukesBetweenAlliedPlayers previously only cancelled a nuke if its exact target tile was owned by the new ally. This meant nukes aimed at neutral or own tiles near allied territory would survive alliance formation and still land (and break the alliance).

Now uses wouldNukeBreakAlliance — the same blast-radius logic used by maybeBreakAlliances on impact — so a nuke is cancelled if its blast would have meaningfully hit the ally's tiles or structures. Also switches from the exhaustive listNukeBreakAlliance (scans all players) to wouldNukeBreakAlliance with a single-player allySmallIds set for early-exit performance.
This commit is contained in:
evanpelle
2026-04-30 17:17:28 -06:00
parent 8a638a3842
commit 02353cf77d
@@ -7,6 +7,7 @@ import {
PlayerID,
UnitType,
} from "../../game/Game";
import { wouldNukeBreakAlliance } from "../Util";
export class AllianceRequestExecution implements Execution {
private req: AllianceRequest | null = null;
@@ -100,12 +101,19 @@ export class AllianceRequestExecution implements Execution {
const targetTile = unit.targetTile();
if (!targetTile) continue;
const targetOwner = this.mg.owner(targetTile);
if (!targetOwner.isPlayer()) continue;
const other = launcher === this.requestor ? recipient : this.requestor;
if (targetOwner !== other) continue;
const magnitude = this.mg.config().nukeMagnitudes(unit.type());
if (
!wouldNukeBreakAlliance({
game: this.mg,
targetTile,
magnitude,
allySmallIds: new Set([other.smallID()]),
threshold: this.mg.config().nukeAllianceBreakThreshold(),
})
) {
continue;
}
unit.delete(false);
neutralized.set(launcher, (neutralized.get(launcher) ?? 0) + 1);
}