mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 06:12:19 +00:00
713db43f42
## Description: Bug fix: cities and ports would only connect to factories owned by the current player, ignoring those belonging to other players. This update makes the player ID optional when searching for nearby units: if no player ID is provided, unit ownership is disregarded, allowing connections to all factories regardless of ownership. ## 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: IngloriousTom
61 lines
1.4 KiB
TypeScript
61 lines
1.4 KiB
TypeScript
import { Execution, Game, Player, Unit, UnitType } from "../game/Game";
|
|
import { TileRef } from "../game/GameMap";
|
|
import { TrainStationExecution } from "./TrainStationExecution";
|
|
|
|
export class CityExecution implements Execution {
|
|
private mg: Game;
|
|
private city: Unit | null = null;
|
|
private active: boolean = true;
|
|
|
|
constructor(
|
|
private player: Player,
|
|
private tile: TileRef,
|
|
) {}
|
|
|
|
init(mg: Game, ticks: number): void {
|
|
this.mg = mg;
|
|
}
|
|
|
|
tick(ticks: number): void {
|
|
if (this.city === null) {
|
|
const spawnTile = this.player.canBuild(UnitType.City, this.tile);
|
|
if (spawnTile === false) {
|
|
console.warn("cannot build city");
|
|
this.active = false;
|
|
return;
|
|
}
|
|
this.city = this.player.buildUnit(UnitType.City, spawnTile, {});
|
|
this.createStation();
|
|
}
|
|
if (!this.city.isActive()) {
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
if (this.player !== this.city.owner()) {
|
|
this.player = this.city.owner();
|
|
}
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
|
|
createStation(): void {
|
|
if (this.city !== null) {
|
|
const nearbyFactory = this.mg.hasUnitNearby(
|
|
this.city.tile()!,
|
|
this.mg.config().trainStationMaxRange(),
|
|
UnitType.Factory,
|
|
);
|
|
if (nearbyFactory) {
|
|
this.mg.addExecution(new TrainStationExecution(this.city));
|
|
}
|
|
}
|
|
}
|
|
}
|