mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-27 23:50:07 +00:00
oil oil baby
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user