mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 03:53:49 +00:00
8f53785a80
## Description: - Removed the temporary UnitType.Construction and embedded construction state into real units via isUnderConstruction(). - Centralized non-structure spawning to perform a single validation right before unit creation/launch. - Updated UI layers to render construction state without relying on the removed enum. - Adjusted and created tests to match the new flow and to cover the no-refundscenarios. # Tests updated - tests/economy/ConstructionGold.test.ts: covers structure cost deduction and income, tolerant of passive income; ensures no refunds during construction. - tests/nukes/HydrogenAndMirv.test.ts: accounts for single-check launch flow; MIRV test targets a player-owned tile; ensures launch after payment. - tests/client/graphics/UILayer.test.ts: mocks now provide isUnderConstruction and real type strings; ## 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 ## Please put your Discord username so you can be contacted if a bug or regression is found: CrackeRR1 --------- Co-authored-by: Evan <evanpelle@gmail.com>
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 FactoryExecution implements Execution {
|
|
private active: boolean = true;
|
|
private game: Game;
|
|
private stationCreated = false;
|
|
|
|
constructor(private factory: Unit) {}
|
|
|
|
init(mg: Game, ticks: number): void {
|
|
this.game = mg;
|
|
}
|
|
|
|
tick(ticks: number): void {
|
|
if (!this.stationCreated) {
|
|
this.createStation();
|
|
this.stationCreated = true;
|
|
}
|
|
if (!this.factory.isActive()) {
|
|
this.active = false;
|
|
return;
|
|
}
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
|
|
private createStation(): void {
|
|
const structures = this.game.nearbyUnits(
|
|
this.factory.tile()!,
|
|
this.game.config().trainStationMaxRange(),
|
|
[UnitType.City, UnitType.Port, UnitType.Factory],
|
|
);
|
|
|
|
this.game.addExecution(new TrainStationExecution(this.factory, true));
|
|
for (const { unit } of structures) {
|
|
if (!unit.hasTrainStation()) {
|
|
this.game.addExecution(new TrainStationExecution(unit));
|
|
}
|
|
}
|
|
}
|
|
}
|