mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 13:30:43 +00:00
destroyer spawns from port
This commit is contained in:
@@ -4,6 +4,7 @@ import DOMPurify from 'dompurify';
|
||||
|
||||
|
||||
import { Cell, Game, Player, TerraNullius, Tile } from "./game/Game";
|
||||
import { number } from 'zod';
|
||||
|
||||
export function manhattanDist(c1: Cell, c2: Cell): number {
|
||||
return Math.abs(c1.x - c2.x) + Math.abs(c1.y - c2.y);
|
||||
@@ -38,6 +39,12 @@ export function dist(root: Tile, dist: number): (tile: Tile) => boolean {
|
||||
return (n: Tile) => manhattanDist(root.cell(), n.cell()) <= dist;
|
||||
}
|
||||
|
||||
export function distSort(target: Tile): (a: Tile, b: Tile) => number {
|
||||
return (a: Tile, b: Tile) => {
|
||||
return manhattanDist(a.cell(), target.cell()) - manhattanDist(b.cell(), target.cell());
|
||||
}
|
||||
}
|
||||
|
||||
export function and(x: (tile: Tile) => boolean, y: (tile: Tile) => boolean): (tile: Tile) => boolean {
|
||||
return (tile: Tile) => x(tile) && y(tile)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Cell, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, Tile, UnitType } from "../game/Game";
|
||||
import { AStar, PathFinder } from "../PathFinding";
|
||||
import { manhattanDist } from "../Util";
|
||||
import { distSort, manhattanDist } from "../Util";
|
||||
|
||||
export class DestroyerExecution implements Execution {
|
||||
|
||||
@@ -32,7 +32,13 @@ export class DestroyerExecution implements Execution {
|
||||
tick(ticks: number): void {
|
||||
// TODO: remove gold from player
|
||||
if (this.destroyer == null) {
|
||||
this.destroyer = this._owner.addUnit(UnitType.Destroyer, 0, this.mg.tile(this.cell))
|
||||
const spawns = this._owner.units(UnitType.Port).map(u => u.tile()).sort(distSort(this.patrolTile))
|
||||
if (spawns.length == 0) {
|
||||
console.warn(`no ports found for destoryer for player ${this._owner}`)
|
||||
this.active = false
|
||||
return
|
||||
}
|
||||
this.destroyer = this._owner.addUnit(UnitType.Destroyer, 0, spawns[0])
|
||||
return
|
||||
}
|
||||
if (!this.destroyer.isActive()) {
|
||||
|
||||
Reference in New Issue
Block a user