diff --git a/src/core/execution/PortExecution.ts b/src/core/execution/PortExecution.ts index bc5674ff6..a2c226936 100644 --- a/src/core/execution/PortExecution.ts +++ b/src/core/execution/PortExecution.ts @@ -40,27 +40,13 @@ export class PortExecution implements Execution { if (this.port == null) { const tile = this.tile; const player = this.mg.player(this._owner); - if (!player.canBuild(UnitType.Port, tile)) { + const spawn = player.canBuild(UnitType.Port, tile); + if (spawn === false) { consolex.warn(`player ${player} cannot build port at ${this.tile}`); this.active = false; return; } - const spawns = Array.from( - this.mg.bfs( - tile, - manhattanDistFN(tile, this.mg.config().radiusPortSpawn()), - ), - ).sort( - (a, b) => - this.mg.manhattanDist(a, tile) - this.mg.manhattanDist(b, tile), - ); - - if (spawns.length == 0) { - consolex.warn(`cannot find spawn for port`); - this.active = false; - return; - } - this.port = player.buildUnit(UnitType.Port, 0, spawns[0]); + this.port = player.buildUnit(UnitType.Port, 0, spawn); } if (!this.port.isActive()) { diff --git a/src/core/game/PlayerImpl.ts b/src/core/game/PlayerImpl.ts index b5f7edcd4..56cd55fce 100644 --- a/src/core/game/PlayerImpl.ts +++ b/src/core/game/PlayerImpl.ts @@ -730,7 +730,12 @@ export class PlayerImpl implements Player { } portSpawn(tile: TileRef): TileRef | false { - const spawns = Array.from(this.mg.bfs(tile, manhattanDistFN(tile, 20))) + const spawns = Array.from( + this.mg.bfs( + tile, + manhattanDistFN(tile, this.mg.config().radiusPortSpawn()), + ), + ) .filter((t) => this.mg.owner(t) == this && this.mg.isOceanShore(t)) .sort( (a, b) =>