Fix sam targetting everything (#1280)

## Description:

There was a regression on how sam targets nukes.
This fixes it

## 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:

Vivacious Box
This commit is contained in:
Vivacious Box
2025-06-27 01:47:16 +02:00
committed by GitHub
parent dfbafd014a
commit ad42dc0ee8
8 changed files with 58 additions and 22 deletions
+2
View File
@@ -153,6 +153,8 @@ export interface Config {
traitorDuration(): number;
nukeMagnitudes(unitType: UnitType): NukeMagnitude;
defaultNukeSpeed(): number;
defaultNukeTargetableRange(): number;
defaultSamRange(): number;
nukeDeathFactor(humans: number, tilesOwned: number): number;
structureMinDist(): number;
isReplay(): boolean;
+8
View File
@@ -790,6 +790,14 @@ export class DefaultConfig implements Config {
return 6;
}
defaultNukeTargetableRange(): number {
return 120;
}
defaultSamRange(): number {
return 80;
}
// Humans can be population, soldiers attacking, soldiers in boat etc.
nukeDeathFactor(humans: number, tilesOwned: number): number {
return (5 * humans) / Math.max(1, tilesOwned);
+3 -3
View File
@@ -13,8 +13,6 @@ import { ParabolaPathFinder } from "../pathfinding/PathFinding";
import { PseudoRandom } from "../PseudoRandom";
import { NukeType } from "../StatsSchemas";
const NUKE_TARGETABLE_RADIUS = 120;
const SPRITE_RADIUS = 16;
export class NukeExecution implements Execution {
@@ -179,7 +177,9 @@ export class NukeExecution implements Execution {
if (this.nuke === null || this.nuke.targetTile() === undefined) {
return;
}
const targetRangeSquared = NUKE_TARGETABLE_RADIUS * NUKE_TARGETABLE_RADIUS;
const targetRangeSquared =
this.mg.config().defaultNukeTargetableRange() *
this.mg.config().defaultNukeTargetableRange();
const targetTile = this.nuke.targetTile();
this.nuke.setTargetable(
this.mg.euclideanDistSquared(this.nuke.tile(), targetTile!) <
+1 -3
View File
@@ -14,8 +14,6 @@ export class SAMLauncherExecution implements Execution {
private mg: Game;
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;
@@ -41,7 +39,7 @@ export class SAMLauncherExecution implements Execution {
if (this.sam === null) return null;
const nukes = this.mg.nearbyUnits(
this.sam.tile(),
this.searchRangeRadius,
this.mg.config().defaultSamRange(),
[UnitType.AtomBomb, UnitType.HydrogenBomb],
({ unit }) =>
unit.owner() !== this.player &&
+7 -1
View File
@@ -684,8 +684,14 @@ export class GameImpl implements Game {
tile: TileRef,
searchRange: number,
types: UnitType | UnitType[],
predicate?: (value: { unit: Unit; distSquared: number }) => boolean,
): Array<{ unit: Unit; distSquared: number }> {
return this.unitGrid.nearbyUnits(tile, searchRange, types) as Array<{
return this.unitGrid.nearbyUnits(
tile,
searchRange,
types,
predicate,
) as Array<{
unit: Unit;
distSquared: number;
}>;