From fc2da5e077ea4ae49b8082de16fca495d0c7918a Mon Sep 17 00:00:00 2001 From: evanpelle Date: Fri, 4 Jul 2025 13:13:38 -0700 Subject: [PATCH] Disable trains in public games (#1342) ## Description: 1. Disable trains in public games 2. add more checks so people can't build trains by bypass the UI. ## 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: evan --- src/core/execution/ConstructionExecution.ts | 9 +++++++++ src/core/execution/TrainStationExecution.ts | 9 ++++++++- src/server/MapPlaylist.ts | 9 ++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/core/execution/ConstructionExecution.ts b/src/core/execution/ConstructionExecution.ts index c37c802fe..eddd3f85c 100644 --- a/src/core/execution/ConstructionExecution.ts +++ b/src/core/execution/ConstructionExecution.ts @@ -37,6 +37,15 @@ export class ConstructionExecution implements Execution { init(mg: Game, ticks: number): void { this.mg = mg; + + if (this.mg.config().isUnitDisabled(this.constructionType)) { + console.warn( + `cannot build construction ${this.constructionType} because it is disabled`, + ); + this.active = false; + return; + } + if (this.tileOrCell instanceof Cell) { if (!this.mg.isValidCoord(this.tileOrCell.x, this.tileOrCell.y)) { console.warn( diff --git a/src/core/execution/TrainStationExecution.ts b/src/core/execution/TrainStationExecution.ts index 81008e3ef..358899ca7 100644 --- a/src/core/execution/TrainStationExecution.ts +++ b/src/core/execution/TrainStationExecution.ts @@ -1,4 +1,4 @@ -import { Execution, Game, Player, Unit } from "../game/Game"; +import { Execution, Game, Player, Unit, UnitType } from "../game/Game"; import { TrainStation } from "../game/TrainStation"; import { PseudoRandom } from "../PseudoRandom"; import { TrainExecution } from "./TrainExecution"; @@ -21,6 +21,13 @@ export class TrainStationExecution implements Execution { init(mg: Game, ticks: number): void { this.mg = mg; + + if (this.mg.config().isUnitDisabled(UnitType.Train)) { + this.active = false; + console.warn(`train station is disabled`); + return; + } + this.random = new PseudoRandom(mg.ticks()); this.unit = this.player.units().find((unit) => unit.id() === this.unitId); diff --git a/src/server/MapPlaylist.ts b/src/server/MapPlaylist.ts index c6c07c0ce..6c5c85f3f 100644 --- a/src/server/MapPlaylist.ts +++ b/src/server/MapPlaylist.ts @@ -1,5 +1,11 @@ import { getServerConfigFromServer } from "../core/configuration/ConfigLoader"; -import { Difficulty, GameMapType, GameMode, GameType } from "../core/game/Game"; +import { + Difficulty, + GameMapType, + GameMode, + GameType, + UnitType, +} from "../core/game/Game"; import { PseudoRandom } from "../core/PseudoRandom"; import { GameConfig } from "../core/Schemas"; import { logger } from "./Logger"; @@ -61,6 +67,7 @@ export class MapPlaylist { gameMode: mode, playerTeams: numPlayerTeams, bots: 400, + disabledUnits: [UnitType.Train, UnitType.Factory], } satisfies GameConfig; }