Files
OpenFrontIO/src/core/execution/CityExecution.ts
T
Readixyee 665a8c3823 Executions dont switch owner (#326)
when an building is taken over by another player the execution for it
doesnt change its owner this makes it so when a sam is captured it tries
to intercept your own nukes and doesnt intercept the ones by the
previous player

this change makes executions of buildings automaticly switch their owner
2025-03-27 16:03:15 -07:00

61 lines
1.3 KiB
TypeScript

import { consolex } from "../Consolex";
import {
Execution,
Game,
Player,
Unit,
PlayerID,
UnitType,
} from "../game/Game";
import { TileRef } from "../game/GameMap";
export class CityExecution implements Execution {
private player: Player;
private mg: Game;
private city: Unit;
private active: boolean = true;
constructor(
private ownerId: PlayerID,
private tile: TileRef,
) {}
init(mg: Game, ticks: number): void {
this.mg = mg;
if (!mg.hasPlayer(this.ownerId)) {
console.warn(`CityExecution: player ${this.ownerId} not found`);
this.active = false;
return;
}
this.player = mg.player(this.ownerId);
}
tick(ticks: number): void {
if (this.city == null) {
const spawnTile = this.player.canBuild(UnitType.City, this.tile);
if (spawnTile == false) {
consolex.warn("cannot build city");
this.active = false;
return;
}
this.city = this.player.buildUnit(UnitType.City, 0, spawnTile);
}
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;
}
}