Skip to content

Commit 6375627

Browse files
committed
fix: re-add toDestroy cache
1 parent 4f2740a commit 6375627

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/core/execution/NukeExecution.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class NukeExecution implements Execution {
2020
private active = true;
2121
private mg: Game;
2222
private nuke: Unit | null = null;
23+
private tilesToDestroyCache: Set<TileRef> | undefined;
2324
private pathFinder: ParabolaPathFinder;
2425

2526
constructor(
@@ -62,17 +63,21 @@ export class NukeExecution implements Execution {
6263
}
6364

6465
private tilesToDestroy(): Set<TileRef> {
66+
if (this.tilesToDestroyCache !== undefined) {
67+
return this.tilesToDestroyCache;
68+
}
6569
if (this.nuke === null) {
6670
throw new Error("Not initialized");
6771
}
6872
const magnitude = this.mg.config().nukeMagnitudes(this.nuke.type());
6973
const rand = new PseudoRandom(this.mg.ticks());
7074
const inner2 = magnitude.inner * magnitude.inner;
7175
const outer2 = magnitude.outer * magnitude.outer;
72-
return this.mg.bfs(this.dst, (_, n: TileRef) => {
76+
this.tilesToDestroyCache = this.mg.bfs(this.dst, (_, n: TileRef) => {
7377
const d2 = this.mg?.euclideanDistSquared(this.dst, n) ?? 0;
7478
return d2 <= outer2 && (d2 <= inner2 || rand.chance(2));
7579
});
80+
return this.tilesToDestroyCache;
7681
}
7782

7883
/**

0 commit comments

Comments
 (0)