Sam anti nuke missile launcher (#176)

now with better name

---------

Co-authored-by: evanpelle <evanpelle@gmail.com>
This commit is contained in:
Readixyee
2025-03-09 21:25:51 +01:00
committed by GitHub
parent fe9a73c967
commit 84951fed9f
10 changed files with 313 additions and 0 deletions
+6
View File
@@ -61,6 +61,12 @@ const buildTable: BuildItemDisplay[][] = [
icon: missileSiloIcon,
description: "Used to launch nukes",
},
// needs new icon
{
unitType: UnitType.SAMLauncher,
icon: shieldIcon,
description: "Defends against incoming nukes",
},
{
unitType: UnitType.DefensePost,
icon: shieldIcon,
@@ -5,6 +5,7 @@ import { EventBus } from "../../../core/EventBus";
import anchorIcon from "../../../../resources/images/buildings/port1.png";
import missileSiloIcon from "../../../../resources/images/buildings/silo1.png";
import SAMMissileIcon from "../../../../resources/images/buildings/extra/silo4.png";
import shieldIcon from "../../../../resources/images/buildings/fortAlt2.png";
import cityIcon from "../../../../resources/images/buildings/cityAlt1.png";
import { GameView, UnitView } from "../../../core/game/GameView";
@@ -48,6 +49,11 @@ export class StructureLayer implements Layer {
borderRadius: 8,
territoryRadius: 6,
},
[UnitType.SAMLauncher]: {
icon: SAMMissileIcon,
borderRadius: 8,
territoryRadius: 6,
},
};
constructor(
+39
View File
@@ -215,6 +215,9 @@ export class UnitLayer implements Layer {
case UnitType.Shell:
this.handleShellEvent(unit);
break;
case UnitType.SAMMissile:
this.handleMissileEvent(unit);
break;
case UnitType.TradeShip:
this.handleTradeShipEvent(unit);
break;
@@ -324,6 +327,42 @@ export class UnitLayer implements Layer {
);
}
// interception missle from SAM
private handleMissileEvent(unit: UnitView) {
const rel = this.relationship(unit);
const range = 2;
for (const t of this.game.bfs(
unit.lastTile(),
euclDistFN(unit.lastTile(), range),
)) {
this.clearCell(this.game.x(t), this.game.y(t));
}
if (unit.isActive()) {
for (const t of this.game.bfs(
unit.tile(),
euclDistFN(unit.tile(), range),
)) {
this.paintCell(
this.game.x(t),
this.game.y(t),
rel,
this.theme.spawnHighlightColor(),
255,
);
}
this.paintCell(
this.game.x(unit.tile()),
this.game.y(unit.tile()),
rel,
this.theme.borderColor(unit.owner().info()),
255,
);
}
}
private handleNuke(unit: UnitView) {
const rel = this.relationship(unit);
let range = 0;