SAM not working against MIRV warhead (#818)

## Description:

The nukes are setting a `detonationDst` that is never used in UnitImpl.

Without the target tile, SAM launchers ignore the MIRV warheads.

Illustration with 50 SAM vs 2 warhead:

![image](https://github.com/user-attachments/assets/cac20dc6-9a28-4801-a834-364fa36b612d)



The nuke icon is also staying white while being nuked:

![image](https://github.com/user-attachments/assets/badf6630-9a5e-4491-b1b7-1008d32f5efc)


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

## 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-05-23 05:47:06 +02:00
committed by GitHub
parent 7a78e0c5a2
commit 256ac3b1b8
4 changed files with 16 additions and 9 deletions
+1 -1
View File
@@ -119,7 +119,7 @@ export class NukeExecution implements Execution {
this.type !== UnitType.MIRVWarhead,
);
this.nuke = this.player.buildUnit(this.type, spawn, {
detonationDst: this.dst,
targetTile: this.dst,
});
if (this.mg.hasOwner(this.dst)) {
const target = this.mg.owner(this.dst);
+9 -3
View File
@@ -164,9 +164,13 @@ export interface UnitParamsMap {
[UnitType.Port]: {};
[UnitType.AtomBomb]: {};
[UnitType.AtomBomb]: {
targetTile?: number;
};
[UnitType.HydrogenBomb]: {};
[UnitType.HydrogenBomb]: {
targetTile?: number;
};
[UnitType.TradeShip]: {
dstPort: Unit;
@@ -185,7 +189,9 @@ export interface UnitParamsMap {
[UnitType.MIRV]: {};
[UnitType.MIRVWarhead]: {};
[UnitType.MIRVWarhead]: {
targetTile?: number;
};
[UnitType.Construction]: {};
}
+2 -1
View File
@@ -39,7 +39,8 @@ export class UnitImpl implements Unit {
) {
this._lastTile = _tile;
this._health = toInt(this.mg.unitInfo(_type).maxHealth ?? 1);
this._targetTile =
"targetTile" in params ? (params.targetTile ?? undefined) : undefined;
this._troops = "troops" in params ? (params.troops ?? 0) : 0;
this._lastSetSafeFromPirates =
"lastSetSafeFromPirates" in params
+4 -4
View File
@@ -63,10 +63,10 @@ describe("SAM", () => {
const sam = defender.buildUnit(UnitType.SAMLauncher, game.ref(1, 1), {});
game.addExecution(new SAMLauncherExecution(defender.id(), null, sam));
attacker.buildUnit(UnitType.AtomBomb, game.ref(2, 1), {
detonationDst: game.ref(2, 1),
targetTile: game.ref(2, 1),
});
attacker.buildUnit(UnitType.AtomBomb, game.ref(1, 2), {
detonationDst: game.ref(1, 2),
targetTile: game.ref(1, 2),
});
expect(attacker.units(UnitType.AtomBomb)).toHaveLength(2);
@@ -80,7 +80,7 @@ describe("SAM", () => {
game.addExecution(new SAMLauncherExecution(defender.id(), null, sam));
expect(sam.isInCooldown()).toBeFalsy();
const nuke = attacker.buildUnit(UnitType.AtomBomb, game.ref(1, 2), {
detonationDst: game.ref(1, 2),
targetTile: game.ref(1, 2),
});
executeTicks(game, 3);
@@ -104,7 +104,7 @@ describe("SAM", () => {
const sam2 = defender.buildUnit(UnitType.SAMLauncher, game.ref(1, 2), {});
game.addExecution(new SAMLauncherExecution(defender.id(), null, sam2));
const nuke = attacker.buildUnit(UnitType.AtomBomb, game.ref(2, 2), {
detonationDst: game.ref(2, 2),
targetTile: game.ref(2, 2),
});
executeTicks(game, 3);