Files
OpenFrontIO/src/core/execution/MissileSiloExecution.ts
T
Scott Anderson 51519b0b9d Enable strictPropertyInitialization (#1909)
## Description:

Enable the tsconfig option `strictPropertyInitialization`.

Fixes #1907

## 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
2025-08-23 19:21:40 -04:00

58 lines
1.4 KiB
TypeScript

import { Execution, Game, Player, Unit, UnitType } from "../game/Game";
import { TileRef } from "../game/GameMap";
export class MissileSiloExecution implements Execution {
private active = true;
private mg: Game | undefined;
private silo: Unit | null = null;
constructor(
private player: Player,
private readonly tile: TileRef,
) {}
init(mg: Game, ticks: number): void {
this.mg = mg;
}
tick(ticks: number): void {
if (this.silo === null) {
const spawn = this.player.canBuild(UnitType.MissileSilo, this.tile);
if (spawn === false) {
console.warn(
`player ${this.player} cannot build missile silo at ${this.tile}`,
);
this.active = false;
return;
}
this.silo = this.player.buildUnit(UnitType.MissileSilo, spawn, {});
if (this.player !== this.silo.owner()) {
this.player = this.silo.owner();
}
}
// frontTime is the time the earliest missile fired.
const frontTime = this.silo.missileTimerQueue()[0];
if (frontTime === undefined) {
return;
}
if (this.mg === undefined) throw new Error("Not initialized");
const cooldown =
this.mg.config().SiloCooldown() - (this.mg.ticks() - frontTime);
if (cooldown <= 0) {
this.silo.reloadMissile();
}
}
isActive(): boolean {
return this.active;
}
activeDuringSpawnPhase(): boolean {
return false;
}
}