Files
OpenFrontIO/src/core/execution/OilRigExecution.ts
T
Restart2008 db4a815390 oil oil baby
2026-02-20 15:55:44 -08:00

49 lines
1.1 KiB
TypeScript

import { Execution, Game, Unit, UnitType } from "../game/Game";
import { TrainStationExecution } from "./TrainStationExecution";
export class OilRigExecution implements Execution {
private active: boolean = true;
private game: Game;
private stationCreated = false;
constructor(private oilRig: Unit) {}
init(mg: Game, ticks: number): void {
this.game = mg;
}
tick(ticks: number): void {
if (!this.stationCreated) {
this.createStation();
this.stationCreated = true;
}
if (!this.oilRig.isActive()) {
this.active = false;
return;
}
}
isActive(): boolean {
return this.active;
}
activeDuringSpawnPhase(): boolean {
return false;
}
private createStation(): void {
const structures = this.game.nearbyUnits(
this.oilRig.tile()!,
this.game.config().trainStationMaxRange(),
[UnitType.City, UnitType.Port, UnitType.OilRig],
);
this.game.addExecution(new TrainStationExecution(this.oilRig, true));
for (const { unit } of structures) {
if (!unit.hasTrainStation()) {
this.game.addExecution(new TrainStationExecution(unit));
}
}
}
}