mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 11:00:43 +00:00
49 lines
1.1 KiB
TypeScript
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));
|
|
}
|
|
}
|
|
}
|
|
}
|