diff --git a/src/core/execution/SAMLauncherExecution.ts b/src/core/execution/SAMLauncherExecution.ts index c723df0d8..d7d55aafa 100644 --- a/src/core/execution/SAMLauncherExecution.ts +++ b/src/core/execution/SAMLauncherExecution.ts @@ -26,8 +26,8 @@ type InterceptionTile = { */ class SAMTargetingSystem { // Interception tiles are computed a single time, but it may not be reachable yet. - // Store the result so it can be intercepted at the proper time, rather than recomputing each ticks - // Null interception tile means there are no interception tiles in range. Store it to + // Store the result so it can be intercepted at the proper time, rather than recomputing each tick. + // Null interception tile means there are no interception tiles in range. Store it to avoid recomputing. private readonly precomputedNukes: Map = new Map(); private readonly missileSpeed: number; @@ -91,7 +91,8 @@ class SAMTargetingSystem { return ( isUnit(unit) && unit.owner() !== this.sam.owner() && - !this.sam.owner().isFriendly(unit.owner()) + !this.sam.owner().isFriendly(unit.owner()) && + !unit.targetedBySAM() ); }, ); @@ -105,7 +106,7 @@ class SAMTargetingSystem { const cached = this.precomputedNukes.get(nukeId); if (cached !== undefined) { if (cached === null) { - // Known unreachable, skip. + // Already computed as unreachable, skip continue; } if (cached.tick === ticks) { @@ -259,8 +260,8 @@ export class SAMLauncherExecution implements Execution { } } - const isSingleTarget = target && !target.unit.targetedBySAM(); - if (isSingleTarget || mirvWarheadTargets.length > 0) { + // target is already filtered to exclude nukes targeted by other SAMs + if (target || mirvWarheadTargets.length > 0) { this.sam.launch(); const type = mirvWarheadTargets.length > 0 diff --git a/src/core/execution/SAMMissileExecution.ts b/src/core/execution/SAMMissileExecution.ts index 7fb4346ce..657166a80 100644 --- a/src/core/execution/SAMMissileExecution.ts +++ b/src/core/execution/SAMMissileExecution.ts @@ -50,6 +50,10 @@ export class SAMMissileExecution implements Execution { this.target.owner() === this.SAMMissile.owner() || !nukesWhitelist.includes(this.target.type()) ) { + // Clear the flag so other SAMs can re-target this nuke + if (this.target.isActive()) { + this.target.setTargetedBySAM(false); + } this.SAMMissile.delete(false); this.active = false; return;