bugfix: ports not spawning on coastline

This commit is contained in:
Evan
2025-03-27 19:08:46 -07:00
parent 099dc74a36
commit 9ed1fe865c
2 changed files with 9 additions and 18 deletions
+3 -17
View File
@@ -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()) {
+6 -1
View File
@@ -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) =>