Automatic train stations (#1353)

## Description:

Train stations are now built automatically when a factory is
constructed.

Changes:
- When a factory is built, nearby structures are connected to the rail
network
- When a city is built near a factory, it is connected to the rail
network
    - All structures behave the same when a train stops: to be defined
    - Removed station badge
    - Gold income is now related to the structure's level

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

## Please put your Discord username so you can be contacted if a bug or
regression is found:

IngloriousTom
This commit is contained in:
DevelopingTom
2025-07-06 22:15:49 +02:00
committed by GitHub
parent 3108921637
commit 6353a5d6f7
23 changed files with 105 additions and 185 deletions
+1 -4
View File
@@ -39,10 +39,7 @@ export class HostLobbyModal extends LitElement {
@state() private copySuccess = false;
@state() private players: string[] = [];
@state() private useRandomMap: boolean = false;
@state() private disabledUnits: UnitType[] = [
UnitType.Factory,
UnitType.Train,
];
@state() private disabledUnits: UnitType[] = [UnitType.Factory];
private playersInterval: NodeJS.Timeout | null = null;
// Add a new timer for debouncing bot changes
+1 -4
View File
@@ -40,10 +40,7 @@ export class SinglePlayerModal extends LitElement {
@state() private gameMode: GameMode = GameMode.FFA;
@state() private teamCount: number | typeof Duos = 2;
@state() private disabledUnits: UnitType[] = [
UnitType.Factory,
UnitType.Train,
];
@state() private disabledUnits: UnitType[] = [UnitType.Factory];
private userSettings: UserSettings = new UserSettings();
-17
View File
@@ -54,10 +54,6 @@ export class SendUpgradeStructureIntentEvent implements GameEvent {
) {}
}
export class SendCreateTrainStationIntentEvent implements GameEvent {
constructor(public readonly unitId: number) {}
}
export class SendAllianceReplyIntentEvent implements GameEvent {
constructor(
// The original alliance requestor
@@ -211,9 +207,6 @@ export class Transport {
this.eventBus.on(SendUpgradeStructureIntentEvent, (e) =>
this.onSendUpgradeStructureIntent(e),
);
this.eventBus.on(SendCreateTrainStationIntentEvent, (e) =>
this.onSendCreateTrainStationIntent(e),
);
this.eventBus.on(SendBoatAttackIntentEvent, (e) =>
this.onSendBoatAttackIntent(e),
);
@@ -478,16 +471,6 @@ export class Transport {
});
}
private onSendCreateTrainStationIntent(
event: SendCreateTrainStationIntentEvent,
) {
this.sendIntent({
type: "create_station",
clientID: this.lobbyConfig.clientID,
unitId: event.unitId,
});
}
private onSendTargetPlayerIntent(event: SendTargetPlayerIntentEvent) {
this.sendIntent({
type: "targetPlayer",
-43
View File
@@ -10,8 +10,6 @@ import { ProgressBar } from "../ProgressBar";
import { TransformHandler } from "../TransformHandler";
import { Layer } from "./Layer";
import trainStationBadge from "../../../../resources/images/buildings/badges/trainStationBadge.png";
const COLOR_PROGRESSION = [
"rgb(232, 25, 25)",
"rgb(240, 122, 25)",
@@ -49,7 +47,6 @@ export class UILayer implements Layer {
// Visual settings for selection
private readonly SELECTION_BOX_SIZE = 6; // Size of the selection box (should be larger than the warship)
private badges: Map<string, HTMLImageElement> = new Map();
constructor(
private game: GameView,
@@ -57,23 +54,6 @@ export class UILayer implements Layer {
private transformHandler: TransformHandler,
) {
this.theme = game.config().theme();
this.loadBadges();
}
private loadBadge(badge: string): Promise<HTMLImageElement> {
return new Promise((resolve, reject) => {
const img = new Image();
img.src = badge;
img.onload = () => {
this.badges.set(badge, img);
resolve(img);
};
img.onerror = reject;
});
}
private async loadBadges() {
await Promise.all([this.loadBadge(trainStationBadge)]);
}
shouldTransform(): boolean {
@@ -165,35 +145,12 @@ export class UILayer implements Layer {
const endTick = this.game.config().SAMCooldown();
this.drawLoadingBar(unit, endTick);
}
this.drawBadges(unit);
break;
case UnitType.City:
case UnitType.Port:
case UnitType.Factory:
this.drawBadges(unit);
break;
default:
return;
}
}
private drawBadges(unit: UnitView) {
if (unit.hasTrainStation()) {
const icon = this.badges.get(trainStationBadge);
if (icon === undefined) {
return;
}
const startX = this.game.x(unit.tile()) - Math.floor(icon.width / 2) + 6;
const startY = this.game.y(unit.tile()) - Math.floor(icon.height / 2) - 6;
if (unit.isActive()) {
this.drawIcon(icon, unit, startX, startY);
} else {
this.clearIcon(icon, startX, startY);
}
}
}
private clearIcon(icon: HTMLImageElement, startX: number, startY: number) {
if (this.context !== null) {
this.context.clearRect(startX, startY, icon.width, icon.height);
@@ -18,7 +18,6 @@ const unitOptions: { type: UnitType; translationKey: string }[] = [
{ type: UnitType.AtomBomb, translationKey: "unit_type.atom_bomb" },
{ type: UnitType.HydrogenBomb, translationKey: "unit_type.hydrogen_bomb" },
{ type: UnitType.MIRV, translationKey: "unit_type.mirv" },
{ type: UnitType.Train, translationKey: "unit_type.train" },
{ type: UnitType.Factory, translationKey: "unit_type.factory" },
];