diff --git a/src/client/graphics/layers/EventsDisplay.ts b/src/client/graphics/layers/EventsDisplay.ts index 7986c3230..b109c2900 100644 --- a/src/client/graphics/layers/EventsDisplay.ts +++ b/src/client/graphics/layers/EventsDisplay.ts @@ -142,8 +142,13 @@ export class EventsDisplay extends LitElement implements Layer { if (!targetTile || boat.reachedTarget() || !boat.isActive()) { return null; } - const distance = this.game.manhattanDist(boat.tile(), targetTile); - return Math.ceil(distance / 10); + const tilesRemaining = boat.pathRemaining(); + if (tilesRemaining === undefined || tilesRemaining === 0) { + // Fallback to manhattan distance if pathRemaining is not available + const distance = this.game.manhattanDist(boat.tile(), targetTile); + return Math.ceil(distance / 10); + } + return Math.ceil(tilesRemaining / 10); } /** diff --git a/src/core/execution/TransportShipExecution.ts b/src/core/execution/TransportShipExecution.ts index 64045ba8e..7bca7931d 100644 --- a/src/core/execution/TransportShipExecution.ts +++ b/src/core/execution/TransportShipExecution.ts @@ -182,6 +182,11 @@ export class TransportShipExecution implements Execution { } const result = this.pathFinder.nextTile(this.boat.tile(), this.dst); + + // Update path remaining tiles for the boat + const tilesRemaining = this.pathFinder.tileRemaining(); + this.boat.setPathRemaining(tilesRemaining); + switch (result.type) { case PathFindResultType.Completed: if (this.mg.owner(this.dst) === this.attacker) { diff --git a/src/core/game/Game.ts b/src/core/game/Game.ts index 8ce4822b3..95ab6c716 100644 --- a/src/core/game/Game.ts +++ b/src/core/game/Game.ts @@ -495,6 +495,10 @@ export interface Unit { setSafeFromPirates(): void; // Only for trade ships isSafeFromPirates(): boolean; // Only for trade ships + // Transport Ships + setPathRemaining(tiles: number | undefined): void; // Only for transport ships + pathRemaining(): number | undefined; // Only for transport ships + // Construction constructionType(): UnitType | null; setConstructionType(type: UnitType): void; diff --git a/src/core/game/GameUpdates.ts b/src/core/game/GameUpdates.ts index 706be36d8..12be736f0 100644 --- a/src/core/game/GameUpdates.ts +++ b/src/core/game/GameUpdates.ts @@ -134,6 +134,7 @@ export interface UnitUpdate { hasTrainStation: boolean; trainType?: TrainType; // Only for trains loaded?: boolean; // Only for trains + pathRemaining?: number; // Only for transport ships } export interface AttackUpdate { diff --git a/src/core/game/GameView.ts b/src/core/game/GameView.ts index ccceacef9..f79c73805 100644 --- a/src/core/game/GameView.ts +++ b/src/core/game/GameView.ts @@ -103,6 +103,12 @@ export class UnitView { } return this.data.retreating; } + pathRemaining(): number | undefined { + if (this.type() !== UnitType.TransportShip) { + return undefined; + } + return this.data.pathRemaining; + } tile(): TileRef { return this.data.pos; } diff --git a/src/core/game/UnitImpl.ts b/src/core/game/UnitImpl.ts index 2403c6af8..680efcd33 100644 --- a/src/core/game/UnitImpl.ts +++ b/src/core/game/UnitImpl.ts @@ -40,6 +40,7 @@ export class UnitImpl implements Unit { private _trajectoryIndex: number = 0; private _trajectory: TrajectoryTile[]; private _deletionAt: number | null = null; + private _pathRemaining: number | undefined; // Only for transport ships constructor( private _type: UnitType, @@ -139,6 +140,7 @@ export class UnitImpl implements Unit { hasTrainStation: this._hasTrainStation, trainType: this._trainType, loaded: this._loaded, + pathRemaining: this._pathRemaining, }; } @@ -464,4 +466,15 @@ export class UnitImpl implements Unit { this.mg.addUpdate(this.toUpdate()); } } + + setPathRemaining(tiles: number | undefined): void { + if (this._pathRemaining !== tiles) { + this._pathRemaining = tiles; + this.mg.addUpdate(this.toUpdate()); + } + } + + pathRemaining(): number | undefined { + return this._pathRemaining; + } } diff --git a/src/core/pathfinding/PathFinding.ts b/src/core/pathfinding/PathFinding.ts index 2050cc162..5a53df582 100644 --- a/src/core/pathfinding/PathFinding.ts +++ b/src/core/pathfinding/PathFinding.ts @@ -207,4 +207,18 @@ export class PathFinder { } return false; } + + /** + * Returns the number of tiles remaining in the path. + * Returns 0 if path is not computed, completed, or not found. + */ + tileRemaining(): number { + if (this.path === null || !this.computeFinished) { + return 0; + } + if (this.path_idx >= this.path.length) { + return 0; + } + return this.path.length - this.path_idx; + } }