diff --git a/src/client/graphics/SpriteLoader.ts b/src/client/graphics/SpriteLoader.ts index 8d71d7d53..36c4aca54 100644 --- a/src/client/graphics/SpriteLoader.ts +++ b/src/client/graphics/SpriteLoader.ts @@ -80,11 +80,18 @@ export const loadAllSprites = async (): Promise => { * The train sprites rely on the train attributes and not only on its type */ function trainTypeToSpriteType(unit: UnitView): TrainTypeSprite { - return unit.trainType() === TrainType.Engine - ? TrainTypeSprite.Engine - : unit.isLoaded() - ? TrainTypeSprite.LoadedCarriage - : TrainTypeSprite.Carriage; + const trainType = unit.trainType(); + + switch (trainType) { + case TrainType.Engine: + case TrainType.TailEngine: + return TrainTypeSprite.Engine; + case TrainType.Carriage: + default: + return unit.isLoaded() + ? TrainTypeSprite.LoadedCarriage + : TrainTypeSprite.Carriage; + } } const getSpriteForUnit = (unit: UnitView): ImageBitmap | null => { diff --git a/src/core/execution/TrainExecution.ts b/src/core/execution/TrainExecution.ts index 5e165067a..4872885e8 100644 --- a/src/core/execution/TrainExecution.ts +++ b/src/core/execution/TrainExecution.ts @@ -14,8 +14,8 @@ import { TrainStation } from "../game/TrainStation"; export class TrainExecution implements Execution { private active = true; private mg: Game | null = null; - private train: Unit | null = null; - private cars: Unit[] = []; + private train: Unit | null = null; // primary unit + private cars: Unit[] = []; // stored back to front private hasCargo: boolean = false; private currentTile: number = 0; private spacing = 2; @@ -69,6 +69,7 @@ export class TrainExecution implements Execution { if (this.train === null) { throw new Error("Not initialized"); } + if (!this.train.isActive() || !this.activeSourceOrDestination()) { this.deleteTrain(); return; @@ -113,7 +114,7 @@ export class TrainExecution implements Execution { this.cars.push( this.player.buildUnit(UnitType.Train, tile, { targetUnit: this.destination.unit, - trainType: TrainType.Engine, + trainType: TrainType.TailEngine, }), ); for (let i = 0; i < this.numCars; i++) { diff --git a/src/core/game/Game.ts b/src/core/game/Game.ts index a51f42723..c38b00300 100644 --- a/src/core/game/Game.ts +++ b/src/core/game/Game.ts @@ -217,6 +217,7 @@ export enum UnitType { export enum TrainType { Engine = "Engine", + TailEngine = "TailEngine", Carriage = "Carriage", } diff --git a/src/core/game/UnitImpl.ts b/src/core/game/UnitImpl.ts index 98344ec4b..fad1f02f0 100644 --- a/src/core/game/UnitImpl.ts +++ b/src/core/game/UnitImpl.ts @@ -265,13 +265,11 @@ export class UnitImpl implements Unit { this._active = false; this.mg.addUpdate(this.toUpdate()); this.mg.removeUnit(this); - if (displayMessage !== false && this._type !== UnitType.MIRVWarhead) { - this.mg.displayMessage( - `Your ${this._type} was destroyed`, - MessageType.UNIT_DESTROYED, - this.owner().id(), - ); + + if (displayMessage !== false) { + this.displayMessageOnDeleted(); } + if (destroyer !== undefined) { switch (this._type) { case UnitType.TransportShip: @@ -296,6 +294,22 @@ export class UnitImpl implements Unit { } } + private displayMessageOnDeleted(): void { + if (this._type === UnitType.MIRVWarhead) { + return; + } + + if (this._type === UnitType.Train && this._trainType !== TrainType.Engine) { + return; + } + + this.mg.displayMessage( + `Your ${this._type} was destroyed`, + MessageType.UNIT_DESTROYED, + this.owner().id(), + ); + } + isActive(): boolean { return this._active; }