From e298eafc5aff78dcacd7a5b01b60ed78ded407b6 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Fri, 16 May 2025 20:03:51 -0400 Subject: [PATCH] Break alliance on launch (#775) ## Description: - Break alliances on launch based on speculative damage. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Summary by CodeRabbit - **Behavior Changes** - Alliances are now immediately broken when a nuke is launched and its incoming message is displayed, rather than only at detonation. --------- Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> --- src/core/execution/NukeExecution.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/execution/NukeExecution.ts b/src/core/execution/NukeExecution.ts index 43e216ad6..0b13941a1 100644 --- a/src/core/execution/NukeExecution.ts +++ b/src/core/execution/NukeExecution.ts @@ -19,6 +19,7 @@ export class NukeExecution implements Execution { private player: Player | null = null; private mg: Game | null = null; private nuke: Unit | null = null; + private tilesToDestroyCache: Set | undefined; private random: PseudoRandom; private pathFinder: ParabolaPathFinder; @@ -56,6 +57,9 @@ export class NukeExecution implements Execution { } private tilesToDestroy(): Set { + if (this.tilesToDestroyCache !== undefined) { + return this.tilesToDestroyCache; + } if (this.mg === null || this.nuke === null) { throw new Error("Not initialized"); } @@ -63,10 +67,11 @@ export class NukeExecution implements Execution { const rand = new PseudoRandom(this.mg.ticks()); const inner2 = magnitude.inner * magnitude.inner; const outer2 = magnitude.outer * magnitude.outer; - return this.mg.bfs(this.dst, (_, n: TileRef) => { + 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; } private breakAlliances(toDestroy: Set) { @@ -125,6 +130,7 @@ export class NukeExecution implements Execution { MessageType.ERROR, target.id(), ); + this.breakAlliances(this.tilesToDestroy()); } if (this.type === UnitType.HydrogenBomb) { this.mg.displayIncomingUnit( @@ -133,6 +139,7 @@ export class NukeExecution implements Execution { MessageType.ERROR, target.id(), ); + this.breakAlliances(this.tilesToDestroy()); } this.mg