SAMs should target only nukes aimed at nearby targets (#1038)

## Description:

Currently, SAMs target any nuke within range. This can be frustrating
when a random SAM from another player intercepts your nuke, especially
since nukes follow a curved trajectory, leaving little room to adjust
their path.

This change modifies how SAMs intercept nukes: they will now only target
those whose impact points are near the SAM.
The “target range” is still generous, allowing players to defend against
Hydrogen bombs, while preventing random SAMs to intercept your valued
nukes.

In this example, the target was the opponent missile silo:


https://github.com/user-attachments/assets/0d8be2ac-e04d-44a4-a67e-54836cce8899



## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [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

## Please put your Discord username so you can be contacted if a bug or
regression is found:

IngloriousTom
This commit is contained in:
DevelopingTom
2025-06-04 19:18:51 +02:00
committed by evanpelle
parent 5adeb8ab17
commit cff708c0b4
2 changed files with 68 additions and 4 deletions
+16 -1
View File
@@ -17,6 +17,7 @@ export class SAMLauncherExecution implements Execution {
private active: boolean = true;
private searchRangeRadius = 80;
private targetRangeRadius = 120; // Nuke's target should be in this range to be focusable
// As MIRV go very fast we have to detect them very early but we only
// shoot the one targeting very close (MIRVWarheadProtectionRadius)
private MIRVWarheadSearchRadius = 400;
@@ -44,6 +45,18 @@ export class SAMLauncherExecution implements Execution {
this.player = mg.player(this.ownerId);
}
private nukeTargetInRange(nuke: Unit) {
const targetTile = nuke.targetTile();
if (this.sam === null || targetTile === undefined) {
return false;
}
const targetRangeSquared = this.targetRangeRadius * this.targetRangeRadius;
return (
this.mg.euclideanDistSquared(this.sam.tile(), targetTile) <
targetRangeSquared
);
}
private getSingleTarget(): Unit | null {
if (this.sam === null) return null;
const nukes = this.mg
@@ -53,7 +66,9 @@ export class SAMLauncherExecution implements Execution {
])
.filter(
({ unit }) =>
unit.owner() !== this.player && !this.player.isFriendly(unit.owner()),
unit.owner() !== this.player &&
!this.player.isFriendly(unit.owner()) &&
this.nukeTargetInRange(unit),
);
return (