mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-23 08:10:28 +00:00
updated using Unit.pathRemaining()
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user