diff --git a/src/core/PathFinding.ts b/src/core/PathFinding.ts index 157697500..d1aecd9ed 100644 --- a/src/core/PathFinding.ts +++ b/src/core/PathFinding.ts @@ -126,6 +126,7 @@ export class PathFinder { private dst: Tile = null private path: Tile[] private aStar: AStar + private inProgress = false constructor(private iterations: number) { @@ -133,20 +134,32 @@ export class PathFinder { nextTile(curr: Tile, dst: Tile): Tile { if (this.shouldRecompute(curr, dst)) { - this.curr = curr - this.dst = dst - this.path = null - this.aStar = new AStar(curr, dst) - if (this.aStar.compute(this.iterations)) { - this.path = this.aStar.reconstructPath() + if (this.inProgress) { + if (this.aStar.compute(this.iterations)) { + this.path = this.aStar.reconstructPath() + this.inProgress = false + } else { + return null + } } else { - return null - } - if (this.path.length > 0) { - this.path.shift() + this.curr = curr + this.dst = dst + this.path = null + this.aStar = new AStar(curr, dst) + if (this.aStar.compute(this.iterations)) { + this.inProgress = false + this.path = this.aStar.reconstructPath() + } else { + this.inProgress = true + return null + } + if (this.path.length > 0) { + this.path.shift() + } } + } else { + return this.path.shift() } - return this.path.shift() } private shouldRecompute(curr: Tile, dst: Tile) { diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts index 22007c4ca..329de537d 100644 --- a/src/core/configuration/DevConfig.ts +++ b/src/core/configuration/DevConfig.ts @@ -22,4 +22,7 @@ export const devConfig = new class extends DefaultConfig { return 400 } + boatMaxDistance(): number { + return 2000 + } } \ No newline at end of file diff --git a/src/core/execution/TransportShipExecution.ts b/src/core/execution/TransportShipExecution.ts index 64c3e18d0..58eec10e3 100644 --- a/src/core/execution/TransportShipExecution.ts +++ b/src/core/execution/TransportShipExecution.ts @@ -25,7 +25,7 @@ export class TransportShipExecution implements Execution { private boat: MutableUnit - private pathFinder: PathFinder = new PathFinder(100_000) + private pathFinder: PathFinder = new PathFinder(10_000) constructor( private attackerID: PlayerID, @@ -118,10 +118,7 @@ export class TransportShipExecution implements Execution { const nextTile = this.pathFinder.nextTile(this.boat.tile(), this.dst) if (nextTile == null) { - console.warn('path not found') - this.attacker.addTroops(this.boat.troops()) - this.boat.delete() - this.active = false + console.warn('boat computing') return } this.boat.move(nextTile) diff --git a/src/core/game/TileImpl.ts b/src/core/game/TileImpl.ts index fffae8f6d..e60838d40 100644 --- a/src/core/game/TileImpl.ts +++ b/src/core/game/TileImpl.ts @@ -1,8 +1,8 @@ -import {Tile, Cell, TerrainType, Player, TerraNullius, MutablePlayer} from "./Game"; -import {Terrain} from "./TerrainMapLoader"; -import {GameImpl} from "./GameImpl"; -import {PlayerImpl} from "./PlayerImpl"; -import {TerraNulliusImpl} from "./TerraNulliusImpl"; +import { Tile, Cell, TerrainType, Player, TerraNullius, MutablePlayer } from "./Game"; +import { Terrain } from "./TerrainMapLoader"; +import { GameImpl } from "./GameImpl"; +import { PlayerImpl } from "./PlayerImpl"; +import { TerraNulliusImpl } from "./TerraNulliusImpl"; export class TileImpl implements Tile { @@ -25,15 +25,11 @@ export class TileImpl implements Tile { // Check top neighbor if (y > 0) { ns.push(this.gs.map[x][y - 1]); - } else { - ns.push(this.gs.map[x][this.gs.height() - 1]); } // Check bottom neighbor if (y < this.gs.height() - 1) { ns.push(this.gs.map[x][y + 1]); - } else { - ns.push(this.gs.map[x][0]); } // Check left neighbor (wrap around) @@ -94,11 +90,11 @@ export class TileImpl implements Tile { .length > 0; } - hasOwner(): boolean {return this._owner != this.gs._terraNullius;} - owner(): MutablePlayer | TerraNullius {return this._owner;} - isBorder(): boolean {return this._isBorder;} - isInterior(): boolean {return this.hasOwner() && !this.isBorder();} - cell(): Cell {return this._cell;} + hasOwner(): boolean { return this._owner != this.gs._terraNullius; } + owner(): MutablePlayer | TerraNullius { return this._owner; } + isBorder(): boolean { return this._isBorder; } + isInterior(): boolean { return this.hasOwner() && !this.isBorder(); } + cell(): Cell { return this._cell; } neighbors(): Tile[] { if (this._neighbors == null) {