mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 01:20:42 +00:00
port spawns on coast
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { AllPlayers, Cell, Execution, MutableGame, MutablePlayer, PlayerID, UnitType } from "../game/Game";
|
||||
import { BuildValidator } from "../game/BuildValidator";
|
||||
import { AllPlayers, BuildItem, BuildItems, Cell, Execution, MutableGame, MutablePlayer, PlayerID, UnitType } from "../game/Game";
|
||||
import { bfs, dist, manhattanDist } from "../Util";
|
||||
|
||||
export class PortExecution implements Execution {
|
||||
|
||||
@@ -18,7 +20,23 @@ export class PortExecution implements Execution {
|
||||
}
|
||||
|
||||
tick(ticks: number): void {
|
||||
this.player.addUnit(UnitType.Port, 0, this.mg.tile(this.cell))
|
||||
const tile = this.mg.tile(this.cell)
|
||||
if (!new BuildValidator(this.mg).canBuild(this.player, tile, BuildItems.Port)) {
|
||||
console.warn(`player ${this.player} cannot build port at ${this.cell}`)
|
||||
this.active = false
|
||||
return
|
||||
}
|
||||
const spawns = Array.from(bfs(tile, dist(tile, 20)))
|
||||
.filter(t => t.isOceanShore() && t.owner() == this.player)
|
||||
.sort((a, b) => manhattanDist(a.cell(), tile.cell()) - manhattanDist(b.cell(), tile.cell()))
|
||||
|
||||
if (spawns.length == 0) {
|
||||
console.warn(`cannot find spawn for port`)
|
||||
this.active = false
|
||||
return
|
||||
}
|
||||
|
||||
this.player.addUnit(UnitType.Port, 0, spawns[0])
|
||||
this.active = false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user